2 * Copyright (C) 2009 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 * Copyright (C) 2009 The Android Open Source Project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package android.telephony;
20 import android.os.Bundle;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.util.Log;
26 * Contains phone signal strength related information.
28 public class SignalStrength implements Parcelable {
30 static final String LOG_TAG = "PHONE";
32 private int mGsmSignalStrength; // Valid values are (0-31, 99) as defined in TS 27.007 8.5
33 private int mGsmBitErrorRate; // bit error rate (0-7, 99) as defined in TS 27.007 8.5
34 private int mCdmaDbm; // This value is the RSSI value
35 private int mCdmaEcio; // This value is the Ec/Io
36 private int mEvdoDbm; // This value is the EVDO RSSI value
37 private int mEvdoEcio; // This value is the EVDO Ec/Io
38 private int mEvdoSnr; // Valid values are 0-8. 8 is the highest signal to noise ratio
40 private boolean isGsm; // This value is set by the ServiceStateTracker onSignalStrengthResult
43 * Create a new SignalStrength from a intent notifier Bundle
45 * This method is used by PhoneStateIntentReceiver and maybe by
46 * external applications.
48 * @param m Bundle from intent notifier
49 * @return newly created SignalStrength
53 public static SignalStrength newFromBundle(Bundle m) {
55 ret = new SignalStrength();
56 ret.setFromNotifierBundle(m);
65 public SignalStrength() {
66 mGsmSignalStrength = 99;
67 mGsmBitErrorRate = -1;
81 public SignalStrength(int gsmSignalStrength, int gsmBitErrorRate,
82 int cdmaDbm, int cdmaEcio,
83 int evdoDbm, int evdoEcio, int evdoSnr, boolean gsm) {
84 mGsmSignalStrength = gsmSignalStrength;
85 mGsmBitErrorRate = gsmBitErrorRate;
97 * @param s Source SignalStrength
101 public SignalStrength(SignalStrength s) {
108 protected void copyFrom(SignalStrength s) {
109 mGsmSignalStrength = s.mGsmSignalStrength;
110 mGsmBitErrorRate = s.mGsmBitErrorRate;
111 mCdmaDbm = s.mCdmaDbm;
112 mCdmaEcio = s.mCdmaEcio;
113 mEvdoDbm = s.mEvdoDbm;
114 mEvdoEcio = s.mEvdoEcio;
115 mEvdoSnr = s.mEvdoSnr;
120 * Construct a SignalStrength object from the given parcel.
124 public SignalStrength(Parcel in) {
125 mGsmSignalStrength = in.readInt();
126 mGsmBitErrorRate = in.readInt();
127 mCdmaDbm = in.readInt();
128 mCdmaEcio = in.readInt();
129 mEvdoDbm = in.readInt();
130 mEvdoEcio = in.readInt();
131 mEvdoSnr = in.readInt();
132 isGsm = (in.readInt() != 0);
136 * {@link Parcelable#writeToParcel}
138 public void writeToParcel(Parcel out, int flags) {
139 out.writeInt(mGsmSignalStrength);
140 out.writeInt(mGsmBitErrorRate);
141 out.writeInt(mCdmaDbm);
142 out.writeInt(mCdmaEcio);
143 out.writeInt(mEvdoDbm);
144 out.writeInt(mEvdoEcio);
145 out.writeInt(mEvdoSnr);
146 out.writeInt(isGsm ? 1 : 0);
150 * {@link Parcelable#describeContents}
152 public int describeContents() {
157 * {@link Parcelable.Creator}
161 public static final Parcelable.Creator<SignalStrength> CREATOR = new Parcelable.Creator() {
162 public SignalStrength createFromParcel(Parcel in) {
163 return new SignalStrength(in);
166 public SignalStrength[] newArray(int size) {
167 return new SignalStrength[size];
172 * Get the GSM Signal Strength, valid values are (0-31, 99) as defined in TS 27.007 8.5
174 public int getGsmSignalStrength() {
175 return this.mGsmSignalStrength;
179 * Get the GSM bit error rate (0-7, 99) as defined in TS 27.007 8.5
181 public int getGsmBitErrorRate() {
182 return this.mGsmBitErrorRate;
186 * Get the CDMA RSSI value in dBm
188 public int getCdmaDbm() {
189 return this.mCdmaDbm;
193 * Get the CDMA Ec/Io value in dB*10
195 public int getCdmaEcio() {
196 return this.mCdmaEcio;
200 * Get the EVDO RSSI value in dBm
202 public int getEvdoDbm() {
203 return this.mEvdoDbm;
207 * Get the EVDO Ec/Io value in dB*10
209 public int getEvdoEcio() {
210 return this.mEvdoEcio;
214 * Get the signal to noise ratio. Valid values are 0-8. 8 is the highest.
216 public int getEvdoSnr() {
217 return this.mEvdoSnr;
221 * @return true if this is for GSM
223 public boolean isGsm() {
231 public int hashCode() {
232 return ((mGsmSignalStrength * 0x1234)
234 + mCdmaDbm + mCdmaEcio
235 + mEvdoDbm + mEvdoEcio + mEvdoSnr
240 * @return true if the signal strengths are the same
243 public boolean equals (Object o) {
247 s = (SignalStrength) o;
248 } catch (ClassCastException ex) {
256 return (mGsmSignalStrength == s.mGsmSignalStrength
257 && mGsmBitErrorRate == s.mGsmBitErrorRate
258 && mCdmaDbm == s.mCdmaDbm
259 && mCdmaEcio == s.mCdmaEcio
260 && mEvdoDbm == s.mEvdoDbm
261 && mEvdoEcio == s.mEvdoEcio
262 && mEvdoSnr == s.mEvdoSnr
263 && isGsm == s.isGsm);
267 * @return string representation.
270 public String toString() {
271 return ("SignalStrength:"
272 + " " + mGsmSignalStrength
273 + " " + mGsmBitErrorRate
279 + " " + (isGsm ? "gsm" : "cdma"));
283 * Test whether two objects hold the same data values or both are null
286 * @param b second obj
287 * @return true if two objects equal or both are null
290 private static boolean equalsHandlesNulls (Object a, Object b) {
291 return (a == null) ? (b == null) : a.equals (b);
295 * Set SignalStrength based on intent notifier map
297 * @param m intent notifier map
300 private void setFromNotifierBundle(Bundle m) {
301 mGsmSignalStrength = m.getInt("GsmSignalStrength");
302 mGsmBitErrorRate = m.getInt("GsmBitErrorRate");
303 mCdmaDbm = m.getInt("CdmaDbm");
304 mCdmaEcio = m.getInt("CdmaEcio");
305 mEvdoDbm = m.getInt("EvdoDbm");
306 mEvdoEcio = m.getInt("EvdoEcio");
307 mEvdoSnr = m.getInt("EvdoSnr");
308 isGsm = m.getBoolean("isGsm");
312 * Set intent notifier Bundle based on SignalStrength
314 * @param m intent notifier Bundle
317 public void fillInNotifierBundle(Bundle m) {
318 m.putInt("GsmSignalStrength", mGsmSignalStrength);
319 m.putInt("GsmBitErrorRate", mGsmBitErrorRate);
320 m.putInt("CdmaDbm", mCdmaDbm);
321 m.putInt("CdmaEcio", mCdmaEcio);
322 m.putInt("EvdoDbm", mEvdoDbm);
323 m.putInt("EvdoEcio", mEvdoEcio);
324 m.putInt("EvdoSnr", mEvdoSnr);
325 m.putBoolean("isGsm", Boolean.valueOf(isGsm));