2 * Copyright (C) 2006 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 static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN;
22 import static android.telephony.TelephonyManager.NETWORK_TYPE_EDGE;
23 import static android.telephony.TelephonyManager.NETWORK_TYPE_GPRS;
24 import static android.telephony.TelephonyManager.NETWORK_TYPE_UMTS;
25 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSDPA;
26 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSUPA;
27 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSPA;
32 * Represents the neighboring cell information, including
33 * Received Signal Strength and Cell ID location.
35 public class NeighboringCellInfo implements Parcelable
38 * Signal strength is not available
40 static final public int UNKNOWN_RSSI = 99;
42 * Cell location is not available
44 static final public int UNKNOWN_CID = -1;
47 * In GSM, mRssi is the Received RSSI;
48 * In UMTS, mRssi is the Level index of CPICH Received Signal Code Power
52 * CID in 16 bits format in GSM. Return UNKNOWN_CID in UMTS and CMDA.
56 * LAC in 16 bits format in GSM. Return UNKNOWN_CID in UMTS and CMDA.
60 * Primary Scrambling Code in 9 bits format in UMTS
61 * Return UNKNOWN_CID in GSM and CMDA.
65 * Radio network type, value is one of following
66 * TelephonyManager.NETWORK_TYPE_XXXXXX.
68 private int mNetworkType;
71 * Empty constructor. Initializes the RSSI and CID.
73 * NeighboringCellInfo is one time shot for the neighboring cells based on
74 * the radio network type at that moment. Its constructor needs radio network
77 * @deprecated by {@link #NeighboringCellInfo(int, String, int)}
80 public NeighboringCellInfo() {
85 mNetworkType = NETWORK_TYPE_UNKNOWN;
89 * Initialize the object from rssi and cid.
91 * NeighboringCellInfo is one time shot for the neighboring cells based on
92 * the radio network type at that moment. Its constructor needs radio network
95 * @deprecated by {@link #NeighboringCellInfo(int, String, int)}
98 public NeighboringCellInfo(int rssi, int cid) {
104 * Initialize the object from rssi, location string, and radioType
105 * radioType is one of following
106 * {@link TelephonyManager#NETWORK_TYPE_GPRS TelephonyManager.NETWORK_TYPE_GPRS},
107 * {@link TelephonyManager#NETWORK_TYPE_EDGE TelephonyManager.NETWORK_TYPE_EDGE},
108 * {@link TelephonyManager#NETWORK_TYPE_UMTS TelephonyManager.NETWORK_TYPE_UMTS},
109 * {@link TelephonyManager#NETWORK_TYPE_HSDPA TelephonyManager.NETWORK_TYPE_HSDPA},
110 * {@link TelephonyManager#NETWORK_TYPE_HSUPA TelephonyManager.NETWORK_TYPE_HSUPA},
111 * and {@link TelephonyManager#NETWORK_TYPE_HSPA TelephonyManager.NETWORK_TYPE_HSPA}.
113 public NeighboringCellInfo(int rssi, String location, int radioType) {
116 mNetworkType = NETWORK_TYPE_UNKNOWN;
122 // pad location string with leading "0"
123 int l = location.length();
126 for (int i = 0; i < (8-l); i++) {
127 location = "0" + location;
130 // TODO - handle LTE and eHRPD (or find they can't be supported)
131 try {// set LAC/CID or PSC based on radioType
133 case NETWORK_TYPE_GPRS:
134 case NETWORK_TYPE_EDGE:
135 mNetworkType = radioType;
136 // check if 0xFFFFFFFF for UNKNOWN_CID
137 if (!location.equalsIgnoreCase("FFFFFFFF")) {
138 mCid = Integer.valueOf(location.substring(4), 16);
139 mLac = Integer.valueOf(location.substring(0, 4), 16);
142 case NETWORK_TYPE_UMTS:
143 case NETWORK_TYPE_HSDPA:
144 case NETWORK_TYPE_HSUPA:
145 case NETWORK_TYPE_HSPA:
146 mNetworkType = radioType;
147 mPsc = Integer.valueOf(location, 16);
150 } catch (NumberFormatException e) {
151 // parsing location error
155 mNetworkType = NETWORK_TYPE_UNKNOWN;
160 * Initialize the object from a parcel.
162 public NeighboringCellInfo(Parcel in) {
163 mRssi = in.readInt();
167 mNetworkType = in.readInt();
171 * @return received signal strength or UNKNOWN_RSSI if unknown
173 * For GSM, it is in "asu" ranging from 0 to 31 (dBm = -113 + 2*asu)
174 * 0 means "-113 dBm or less" and 31 means "-51 dBm or greater"
175 * For UMTS, it is the Level index of CPICH RSCP defined in TS 25.125
177 public int getRssi() {
182 * @return LAC in GSM, 0xffff max legal value
183 * UNKNOWN_CID if in UMTS or CMDA or unknown
185 public int getLac() {
190 * @return cell id in GSM, 0xffff max legal value
191 * UNKNOWN_CID if in UMTS or CDMA or unknown
193 public int getCid() {
198 * @return Primary Scrambling Code in 9 bits format in UMTS, 0x1ff max value
199 * UNKNOWN_CID if in GSM or CMDA or unknown
201 public int getPsc() {
206 * @return Radio network type while neighboring cell location is stored.
208 * Return {@link TelephonyManager#NETWORK_TYPE_UNKNOWN TelephonyManager.NETWORK_TYPE_UNKNOWN}
209 * means that the location information is unavailable.
211 * Return {@link TelephonyManager#NETWORK_TYPE_GPRS TelephonyManager.NETWORK_TYPE_GPRS} or
212 * {@link TelephonyManager#NETWORK_TYPE_EDGE TelephonyManager.NETWORK_TYPE_EDGE}
213 * means that Neighboring Cell information is stored for GSM network, in
214 * which {@link NeighboringCellInfo#getLac NeighboringCellInfo.getLac} and
215 * {@link NeighboringCellInfo#getCid NeighboringCellInfo.getCid} should be
216 * called to access location.
218 * Return {@link TelephonyManager#NETWORK_TYPE_UMTS TelephonyManager.NETWORK_TYPE_UMTS},
219 * {@link TelephonyManager#NETWORK_TYPE_HSDPA TelephonyManager.NETWORK_TYPE_HSDPA},
220 * {@link TelephonyManager#NETWORK_TYPE_HSUPA TelephonyManager.NETWORK_TYPE_HSUPA},
221 * or {@link TelephonyManager#NETWORK_TYPE_HSPA TelephonyManager.NETWORK_TYPE_HSPA}
222 * means that Neighboring Cell information is stored for UMTS network, in
223 * which {@link NeighboringCellInfo#getPsc NeighboringCellInfo.getPsc}
224 * should be called to access location.
226 public int getNetworkType() {
232 * NeighboringCellInfo is a one time shot for the neighboring cells based on
233 * the radio network type at that moment. It shouldn't be changed after
236 * @deprecated cid value passed as in location parameter passed to constructor
237 * {@link #NeighboringCellInfo(int, String, int)}
240 public void setCid(int cid) {
245 * Set the signal strength of the cell.
247 * NeighboringCellInfo is a one time shot for the neighboring cells based on
248 * the radio network type at that moment. It shouldn't be changed after
251 * @deprecated initial rssi value passed as parameter to constructor
252 * {@link #NeighboringCellInfo(int, String, int)}
255 public void setRssi(int rssi) {
260 public String toString() {
261 StringBuilder sb = new StringBuilder();
264 if (mPsc != UNKNOWN_CID) {
265 sb.append(Integer.toHexString(mPsc))
266 .append("@").append(((mRssi == UNKNOWN_RSSI)? "-" : mRssi));
267 } else if(mLac != UNKNOWN_CID && mCid != UNKNOWN_CID) {
268 sb.append(Integer.toHexString(mLac))
269 .append(Integer.toHexString(mCid))
270 .append("@").append(((mRssi == UNKNOWN_RSSI)? "-" : mRssi));
274 return sb.toString();
277 public int describeContents() {
281 public void writeToParcel(Parcel dest, int flags) {
282 dest.writeInt(mRssi);
286 dest.writeInt(mNetworkType);
289 public static final Parcelable.Creator<NeighboringCellInfo> CREATOR
290 = new Parcelable.Creator<NeighboringCellInfo>() {
291 public NeighboringCellInfo createFromParcel(Parcel in) {
292 return new NeighboringCellInfo(in);
295 public NeighboringCellInfo[] newArray(int size) {
296 return new NeighboringCellInfo[size];