CellSignalStrength.java revision 3caf66d2ea63c75039daf43af30d3727e5ce6b58
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.telephony; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21 22/** 23 * Abstract base class for cell phone signal strength related information. 24 */ 25public abstract class CellSignalStrength implements Parcelable { 26 27 // Type fields for parceling 28 /** @hide */ 29 protected static final int TYPE_GSM = 1; 30 /** @hide */ 31 protected static final int TYPE_CDMA = 2; 32 /** @hide */ 33 protected static final int TYPE_LTE = 3; 34 35 36 /** @hide */ 37 public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0; 38 /** @hide */ 39 public static final int SIGNAL_STRENGTH_POOR = 1; 40 /** @hide */ 41 public static final int SIGNAL_STRENGTH_MODERATE = 2; 42 /** @hide */ 43 public static final int SIGNAL_STRENGTH_GOOD = 3; 44 /** @hide */ 45 public static final int SIGNAL_STRENGTH_GREAT = 4; 46 /** @hide */ 47 public static final int NUM_SIGNAL_STRENGTH_BINS = 5; 48 /** @hide */ 49 public static final String[] SIGNAL_STRENGTH_NAMES = { 50 "none", "poor", "moderate", "good", "great" 51 }; 52 53 /** @hide */ 54 protected CellSignalStrength() { 55 } 56 57 /** @hide */ 58 public abstract void setDefaultValues(); 59 60 /** 61 * Get signal level as an int from 0..4 62 * 63 * @hide 64 */ 65 public abstract int getLevel(); 66 67 /** 68 * Get the signal level as an asu value between 0..31, 99 is unknown 69 * 70 * @hide 71 */ 72 public abstract int getAsuLevel(); 73 74 /** 75 * Get the signal strength as dBm 76 * 77 * @hide 78 */ 79 public abstract int getDbm(); 80 81 /** 82 * Copies the CellSignalStrength. 83 * 84 * @return A deep copy of this class. 85 * @hide 86 */ 87 public abstract CellSignalStrength copy(); 88 89 @Override 90 public abstract int hashCode(); 91 92 @Override 93 public abstract boolean equals (Object o); 94 95 /** Implement the Parcelable interface */ 96 @Override 97 public int describeContents() { 98 return 0; 99 } 100 101 /** Implement the Parcelable interface */ 102 @Override 103 public abstract void writeToParcel(Parcel dest, int flags); 104 105 /** Implement the Parcelable interface */ 106 public static final Creator<CellSignalStrength> CREATOR = 107 new Creator<CellSignalStrength>() { 108 @Override 109 public CellSignalStrength createFromParcel(Parcel in) { 110 int type = in.readInt(); 111 switch (type) { 112 case TYPE_GSM: return CellSignalStrengthGsm.createFromParcelBody(in); 113 case TYPE_CDMA: return CellSignalStrengthCdma.createFromParcelBody(in); 114 case TYPE_LTE: return CellSignalStrengthLte.createFromParcelBody(in); 115 default: throw new RuntimeException("Bad CellSignalStrength Parcel"); 116 } 117 } 118 119 @Override 120 public CellSignalStrength[] newArray(int size) { 121 return new CellSignalStrength[size]; 122 } 123 }; 124} 125