2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.telephony;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.telephony.Rlog;
24 * GSM signal strength related information.
26 public final class CellSignalStrengthGsm extends CellSignalStrength implements Parcelable {
28 private static final String LOG_TAG = "CellSignalStrengthGsm";
29 private static final boolean DBG = false;
31 private static final int GSM_SIGNAL_STRENGTH_GREAT = 12;
32 private static final int GSM_SIGNAL_STRENGTH_GOOD = 8;
33 private static final int GSM_SIGNAL_STRENGTH_MODERATE = 5;
35 private int mSignalStrength; // Valid values are (0-31, 99) as defined in TS 27.007 8.5
36 private int mBitErrorRate; // bit error rate (0-7, 99) as defined in TS 27.007 8.5
43 public CellSignalStrengthGsm() {
52 public CellSignalStrengthGsm(int ss, int ber) {
59 * @param s Source SignalStrength
63 public CellSignalStrengthGsm(CellSignalStrengthGsm s) {
68 * Initialize all the values
70 * @param ss SignalStrength as ASU value
71 * @param ber is Bit Error Rate
75 public void initialize(int ss, int ber) {
83 protected void copyFrom(CellSignalStrengthGsm s) {
84 mSignalStrength = s.mSignalStrength;
85 mBitErrorRate = s.mBitErrorRate;
92 public CellSignalStrengthGsm copy() {
93 return new CellSignalStrengthGsm(this);
98 public void setDefaultValues() {
99 mSignalStrength = Integer.MAX_VALUE;
100 mBitErrorRate = Integer.MAX_VALUE;
104 * Get signal level as an int from 0..4
107 public int getLevel() {
110 // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
111 // asu = 0 (-113dB or less) is very weak
112 // signal, its better to show 0 bars to the user in such cases.
113 // asu = 99 is a special case, where the signal strength is unknown.
114 int asu = mSignalStrength;
115 if (asu <= 2 || asu == 99) level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
116 else if (asu >= GSM_SIGNAL_STRENGTH_GREAT) level = SIGNAL_STRENGTH_GREAT;
117 else if (asu >= GSM_SIGNAL_STRENGTH_GOOD) level = SIGNAL_STRENGTH_GOOD;
118 else if (asu >= GSM_SIGNAL_STRENGTH_MODERATE) level = SIGNAL_STRENGTH_MODERATE;
119 else level = SIGNAL_STRENGTH_POOR;
120 if (DBG) log("getLevel=" + level);
125 * Get the signal strength as dBm
128 public int getDbm() {
131 int level = mSignalStrength;
132 int asu = (level == 99 ? Integer.MAX_VALUE : level);
133 if (asu != Integer.MAX_VALUE) {
134 dBm = -113 + (2 * asu);
136 dBm = Integer.MAX_VALUE;
138 if (DBG) log("getDbm=" + dBm);
143 * Get the signal level as an asu value between 0..31, 99 is unknown
144 * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
147 public int getAsuLevel() {
148 // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
149 // asu = 0 (-113dB or less) is very weak
150 // signal, its better to show 0 bars to the user in such cases.
151 // asu = 99 is a special case, where the signal strength is unknown.
152 int level = mSignalStrength;
153 if (DBG) log("getAsuLevel=" + level);
158 public int hashCode() {
160 return (mSignalStrength * primeNum) + (mBitErrorRate * primeNum);
164 public boolean equals (Object o) {
165 CellSignalStrengthGsm s;
168 s = (CellSignalStrengthGsm) o;
169 } catch (ClassCastException ex) {
177 return mSignalStrength == s.mSignalStrength && mBitErrorRate == s.mBitErrorRate;
181 * @return string representation.
184 public String toString() {
185 return "CellSignalStrengthGsm:"
186 + " ss=" + mSignalStrength
187 + " ber=" + mBitErrorRate;
190 /** Implement the Parcelable interface */
192 public void writeToParcel(Parcel dest, int flags) {
193 if (DBG) log("writeToParcel(Parcel, int): " + toString());
194 dest.writeInt(mSignalStrength);
195 dest.writeInt(mBitErrorRate);
199 * Construct a SignalStrength object from the given parcel
200 * where the token is already been processed.
202 private CellSignalStrengthGsm(Parcel in) {
203 mSignalStrength = in.readInt();
204 mBitErrorRate = in.readInt();
205 if (DBG) log("CellSignalStrengthGsm(Parcel): " + toString());
208 /** Implement the Parcelable interface */
210 public int describeContents() {
214 /** Implement the Parcelable interface */
215 @SuppressWarnings("hiding")
216 public static final Parcelable.Creator<CellSignalStrengthGsm> CREATOR =
217 new Parcelable.Creator<CellSignalStrengthGsm>() {
219 public CellSignalStrengthGsm createFromParcel(Parcel in) {
220 return new CellSignalStrengthGsm(in);
224 public CellSignalStrengthGsm[] newArray(int size) {
225 return new CellSignalStrengthGsm[size];
232 private static void log(String s) {