blob: 5f467991899827ef327230cbbdd00ad4e60fcc13 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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
johnwang9c118c82009-09-11 19:17:29 -070019import static android.telephony.TelephonyManager.NETWORK_TYPE_EDGE;
20import static android.telephony.TelephonyManager.NETWORK_TYPE_GPRS;
johnwang9c118c82009-09-11 19:17:29 -070021import static android.telephony.TelephonyManager.NETWORK_TYPE_HSDPA;
johnwang9c118c82009-09-11 19:17:29 -070022import static android.telephony.TelephonyManager.NETWORK_TYPE_HSPA;
Nathan Harold45fb1052017-12-04 09:55:56 -080023import static android.telephony.TelephonyManager.NETWORK_TYPE_HSUPA;
24import static android.telephony.TelephonyManager.NETWORK_TYPE_UMTS;
25import static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN;
johnwang9c118c82009-09-11 19:17:29 -070026
Artur Satayev74cb7192019-12-10 17:47:56 +000027import android.compat.annotation.UnsupportedAppUsage;
Mathew Inwood31755f92018-12-20 13:53:36 +000028import android.os.Build;
Nathan Harold45fb1052017-12-04 09:55:56 -080029import android.os.Parcel;
30import android.os.Parcelable;
johnwang9c118c82009-09-11 19:17:29 -070031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
33/**
Wink Saville2563a3a2009-06-09 10:30:03 -070034 * Represents the neighboring cell information, including
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 * Received Signal Strength and Cell ID location.
Nathan Harold493223b2018-08-09 17:10:42 -070036 *
Nathan Harold3d850a72018-10-02 15:55:36 -070037 * @deprecated This class should not be used by any app targeting
Tor Norbyef8dc2d22018-10-03 09:28:21 +020038 * {@link android.os.Build.VERSION_CODES#Q Android Q} or higher. Instead callers should use
39 * {@link android.telephony.CellInfo CellInfo}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 */
Nathan Harold493223b2018-08-09 17:10:42 -070041@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042public class NeighboringCellInfo implements Parcelable
43{
44 /**
45 * Signal strength is not available
46 */
47 static final public int UNKNOWN_RSSI = 99;
48 /**
49 * Cell location is not available
50 */
51 static final public int UNKNOWN_CID = -1;
52
johnwang9c118c82009-09-11 19:17:29 -070053 /**
54 * In GSM, mRssi is the Received RSSI;
55 * In UMTS, mRssi is the Level index of CPICH Received Signal Code Power
56 */
Mathew Inwood31755f92018-12-20 13:53:36 +000057 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 private int mRssi;
johnwang9c118c82009-09-11 19:17:29 -070059 /**
60 * CID in 16 bits format in GSM. Return UNKNOWN_CID in UMTS and CMDA.
61 */
Mathew Inwood31755f92018-12-20 13:53:36 +000062 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 private int mCid;
johnwang9c118c82009-09-11 19:17:29 -070064 /**
65 * LAC in 16 bits format in GSM. Return UNKNOWN_CID in UMTS and CMDA.
66 */
Mathew Inwood31755f92018-12-20 13:53:36 +000067 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
johnwang9c118c82009-09-11 19:17:29 -070068 private int mLac;
69 /**
70 * Primary Scrambling Code in 9 bits format in UMTS
71 * Return UNKNOWN_CID in GSM and CMDA.
72 */
Mathew Inwood31755f92018-12-20 13:53:36 +000073 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
johnwang9c118c82009-09-11 19:17:29 -070074 private int mPsc;
75 /**
76 * Radio network type, value is one of following
77 * TelephonyManager.NETWORK_TYPE_XXXXXX.
78 */
Mathew Inwood31755f92018-12-20 13:53:36 +000079 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
johnwang9c118c82009-09-11 19:17:29 -070080 private int mNetworkType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
82 /**
83 * Empty constructor. Initializes the RSSI and CID.
johnwang9c118c82009-09-11 19:17:29 -070084 *
85 * NeighboringCellInfo is one time shot for the neighboring cells based on
86 * the radio network type at that moment. Its constructor needs radio network
87 * type.
Wink Savillecc6ff2b2009-12-02 09:46:38 -080088 *
89 * @deprecated by {@link #NeighboringCellInfo(int, String, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 */
Dianne Hackborn29e4a3c2009-09-30 22:35:40 -070091 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 public NeighboringCellInfo() {
93 mRssi = UNKNOWN_RSSI;
johnwang9c118c82009-09-11 19:17:29 -070094 mLac = UNKNOWN_CID;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 mCid = UNKNOWN_CID;
johnwang9c118c82009-09-11 19:17:29 -070096 mPsc = UNKNOWN_CID;
97 mNetworkType = NETWORK_TYPE_UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 }
99
100 /**
101 * Initialize the object from rssi and cid.
johnwang9c118c82009-09-11 19:17:29 -0700102 *
103 * NeighboringCellInfo is one time shot for the neighboring cells based on
104 * the radio network type at that moment. Its constructor needs radio network
105 * type.
Wink Savillecc6ff2b2009-12-02 09:46:38 -0800106 *
107 * @deprecated by {@link #NeighboringCellInfo(int, String, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 */
Dianne Hackborn29e4a3c2009-09-30 22:35:40 -0700109 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 public NeighboringCellInfo(int rssi, int cid) {
111 mRssi = rssi;
112 mCid = cid;
113 }
Wink Saville2563a3a2009-06-09 10:30:03 -0700114
Nathan Harold45fb1052017-12-04 09:55:56 -0800115 /** @hide */
116 public NeighboringCellInfo(final CellInfoGsm info) {
117 mNetworkType = TelephonyManager.NETWORK_TYPE_GPRS;
118
119 mRssi = info.getCellSignalStrength().getAsuLevel();
120 if (mRssi == Integer.MAX_VALUE) mRssi = UNKNOWN_RSSI;
121
122 mLac = info.getCellIdentity().getLac();
123 if (mLac == Integer.MAX_VALUE) mLac = UNKNOWN_CID;
124
125 mCid = info.getCellIdentity().getCid();
126 if (mCid == Integer.MAX_VALUE) mCid = UNKNOWN_CID;
127
128 mPsc = UNKNOWN_CID;
129 }
130
131 /** @hide */
132 public NeighboringCellInfo(final CellInfoWcdma info) {
133 mNetworkType = TelephonyManager.NETWORK_TYPE_UMTS;
134
135 mRssi = info.getCellSignalStrength().getAsuLevel();
136 if (mRssi == Integer.MAX_VALUE) mRssi = UNKNOWN_RSSI;
137
138 mLac = info.getCellIdentity().getLac();
139 if (mLac == Integer.MAX_VALUE) mLac = UNKNOWN_CID;
140
141 mCid = info.getCellIdentity().getCid();
142 if (mCid == Integer.MAX_VALUE) mCid = UNKNOWN_CID;
143
144 mPsc = info.getCellIdentity().getPsc();
145 if (mPsc == Integer.MAX_VALUE) mPsc = UNKNOWN_CID;
146 }
147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 /**
johnwang9c118c82009-09-11 19:17:29 -0700149 * Initialize the object from rssi, location string, and radioType
150 * radioType is one of following
151 * {@link TelephonyManager#NETWORK_TYPE_GPRS TelephonyManager.NETWORK_TYPE_GPRS},
152 * {@link TelephonyManager#NETWORK_TYPE_EDGE TelephonyManager.NETWORK_TYPE_EDGE},
153 * {@link TelephonyManager#NETWORK_TYPE_UMTS TelephonyManager.NETWORK_TYPE_UMTS},
154 * {@link TelephonyManager#NETWORK_TYPE_HSDPA TelephonyManager.NETWORK_TYPE_HSDPA},
155 * {@link TelephonyManager#NETWORK_TYPE_HSUPA TelephonyManager.NETWORK_TYPE_HSUPA},
156 * and {@link TelephonyManager#NETWORK_TYPE_HSPA TelephonyManager.NETWORK_TYPE_HSPA}.
157 */
158 public NeighboringCellInfo(int rssi, String location, int radioType) {
159 // set default value
160 mRssi = rssi;
161 mNetworkType = NETWORK_TYPE_UNKNOWN;
162 mPsc = UNKNOWN_CID;
163 mLac = UNKNOWN_CID;
164 mCid = UNKNOWN_CID;
165
166
167 // pad location string with leading "0"
168 int l = location.length();
169 if (l > 8) return;
170 if (l < 8) {
171 for (int i = 0; i < (8-l); i++) {
172 location = "0" + location;
173 }
174 }
Robert Greenwalt962a9902010-11-02 11:10:25 -0700175 // TODO - handle LTE and eHRPD (or find they can't be supported)
johnwang9c118c82009-09-11 19:17:29 -0700176 try {// set LAC/CID or PSC based on radioType
177 switch (radioType) {
178 case NETWORK_TYPE_GPRS:
179 case NETWORK_TYPE_EDGE:
180 mNetworkType = radioType;
Naveen Kallac6dd77d2010-04-07 17:54:33 -0700181 // check if 0xFFFFFFFF for UNKNOWN_CID
182 if (!location.equalsIgnoreCase("FFFFFFFF")) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +0100183 mCid = Integer.parseInt(location.substring(4), 16);
184 mLac = Integer.parseInt(location.substring(0, 4), 16);
Naveen Kallac6dd77d2010-04-07 17:54:33 -0700185 }
johnwang9c118c82009-09-11 19:17:29 -0700186 break;
187 case NETWORK_TYPE_UMTS:
188 case NETWORK_TYPE_HSDPA:
189 case NETWORK_TYPE_HSUPA:
190 case NETWORK_TYPE_HSPA:
191 mNetworkType = radioType;
Narayan Kamatha09b4d22016-04-15 18:32:45 +0100192 mPsc = Integer.parseInt(location, 16);
johnwang9c118c82009-09-11 19:17:29 -0700193 break;
194 }
195 } catch (NumberFormatException e) {
196 // parsing location error
197 mPsc = UNKNOWN_CID;
198 mLac = UNKNOWN_CID;
199 mCid = UNKNOWN_CID;
200 mNetworkType = NETWORK_TYPE_UNKNOWN;
201 }
202 }
203
204 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 * Initialize the object from a parcel.
206 */
207 public NeighboringCellInfo(Parcel in) {
208 mRssi = in.readInt();
johnwang9c118c82009-09-11 19:17:29 -0700209 mLac = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 mCid = in.readInt();
johnwang9c118c82009-09-11 19:17:29 -0700211 mPsc = in.readInt();
212 mNetworkType = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 }
Wink Saville2563a3a2009-06-09 10:30:03 -0700214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 /**
johnwang9c118c82009-09-11 19:17:29 -0700216 * @return received signal strength or UNKNOWN_RSSI if unknown
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 *
johnwang9c118c82009-09-11 19:17:29 -0700218 * For GSM, it is in "asu" ranging from 0 to 31 (dBm = -113 + 2*asu)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 * 0 means "-113 dBm or less" and 31 means "-51 dBm or greater"
johnwang9c118c82009-09-11 19:17:29 -0700220 * For UMTS, it is the Level index of CPICH RSCP defined in TS 25.125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 */
222 public int getRssi() {
223 return mRssi;
224 }
225
226 /**
johnwang9c118c82009-09-11 19:17:29 -0700227 * @return LAC in GSM, 0xffff max legal value
228 * UNKNOWN_CID if in UMTS or CMDA or unknown
229 */
230 public int getLac() {
231 return mLac;
232 }
233
234 /**
235 * @return cell id in GSM, 0xffff max legal value
236 * UNKNOWN_CID if in UMTS or CDMA or unknown
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 */
238 public int getCid() {
239 return mCid;
240 }
241
242 /**
johnwang9c118c82009-09-11 19:17:29 -0700243 * @return Primary Scrambling Code in 9 bits format in UMTS, 0x1ff max value
244 * UNKNOWN_CID if in GSM or CMDA or unknown
245 */
246 public int getPsc() {
247 return mPsc;
248 }
249
250 /**
251 * @return Radio network type while neighboring cell location is stored.
252 *
253 * Return {@link TelephonyManager#NETWORK_TYPE_UNKNOWN TelephonyManager.NETWORK_TYPE_UNKNOWN}
254 * means that the location information is unavailable.
255 *
256 * Return {@link TelephonyManager#NETWORK_TYPE_GPRS TelephonyManager.NETWORK_TYPE_GPRS} or
257 * {@link TelephonyManager#NETWORK_TYPE_EDGE TelephonyManager.NETWORK_TYPE_EDGE}
258 * means that Neighboring Cell information is stored for GSM network, in
259 * which {@link NeighboringCellInfo#getLac NeighboringCellInfo.getLac} and
260 * {@link NeighboringCellInfo#getCid NeighboringCellInfo.getCid} should be
261 * called to access location.
262 *
263 * Return {@link TelephonyManager#NETWORK_TYPE_UMTS TelephonyManager.NETWORK_TYPE_UMTS},
264 * {@link TelephonyManager#NETWORK_TYPE_HSDPA TelephonyManager.NETWORK_TYPE_HSDPA},
265 * {@link TelephonyManager#NETWORK_TYPE_HSUPA TelephonyManager.NETWORK_TYPE_HSUPA},
266 * or {@link TelephonyManager#NETWORK_TYPE_HSPA TelephonyManager.NETWORK_TYPE_HSPA}
267 * means that Neighboring Cell information is stored for UMTS network, in
268 * which {@link NeighboringCellInfo#getPsc NeighboringCellInfo.getPsc}
269 * should be called to access location.
270 */
271 public int getNetworkType() {
272 return mNetworkType;
273 }
274 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 * Set the cell id.
johnwang9c118c82009-09-11 19:17:29 -0700276 *
277 * NeighboringCellInfo is a one time shot for the neighboring cells based on
278 * the radio network type at that moment. It shouldn't be changed after
279 * creation.
Wink Savillecc6ff2b2009-12-02 09:46:38 -0800280 *
281 * @deprecated cid value passed as in location parameter passed to constructor
282 * {@link #NeighboringCellInfo(int, String, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 */
Dianne Hackborn29e4a3c2009-09-30 22:35:40 -0700284 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 public void setCid(int cid) {
286 mCid = cid;
287 }
288
289 /**
290 * Set the signal strength of the cell.
johnwang9c118c82009-09-11 19:17:29 -0700291 *
292 * NeighboringCellInfo is a one time shot for the neighboring cells based on
293 * the radio network type at that moment. It shouldn't be changed after
294 * creation.
Wink Savillecc6ff2b2009-12-02 09:46:38 -0800295 *
296 * @deprecated initial rssi value passed as parameter to constructor
297 * {@link #NeighboringCellInfo(int, String, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 */
Dianne Hackborn29e4a3c2009-09-30 22:35:40 -0700299 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 public void setRssi(int rssi) {
301 mRssi = rssi;
302 }
303
304 @Override
305 public String toString() {
johnwang9c118c82009-09-11 19:17:29 -0700306 StringBuilder sb = new StringBuilder();
307
308 sb.append("[");
309 if (mPsc != UNKNOWN_CID) {
310 sb.append(Integer.toHexString(mPsc))
311 .append("@").append(((mRssi == UNKNOWN_RSSI)? "-" : mRssi));
312 } else if(mLac != UNKNOWN_CID && mCid != UNKNOWN_CID) {
313 sb.append(Integer.toHexString(mLac))
314 .append(Integer.toHexString(mCid))
315 .append("@").append(((mRssi == UNKNOWN_RSSI)? "-" : mRssi));
316 }
317 sb.append("]");
318
319 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 }
321
322 public int describeContents() {
323 return 0;
324 }
325
326 public void writeToParcel(Parcel dest, int flags) {
327 dest.writeInt(mRssi);
johnwang9c118c82009-09-11 19:17:29 -0700328 dest.writeInt(mLac);
Wink Saville2563a3a2009-06-09 10:30:03 -0700329 dest.writeInt(mCid);
johnwang9c118c82009-09-11 19:17:29 -0700330 dest.writeInt(mPsc);
331 dest.writeInt(mNetworkType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 }
333
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700334 public static final @android.annotation.NonNull Parcelable.Creator<NeighboringCellInfo> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 = new Parcelable.Creator<NeighboringCellInfo>() {
336 public NeighboringCellInfo createFromParcel(Parcel in) {
337 return new NeighboringCellInfo(in);
338 }
339
340 public NeighboringCellInfo[] newArray(int size) {
341 return new NeighboringCellInfo[size];
342 }
343 };
Naveen Kallac6dd77d2010-04-07 17:54:33 -0700344}