blob: 79298fd54c5000559aa40d92eab554c10ea856b0 [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
Mathew Inwooda8382062018-08-16 17:01:12 +010027import android.annotation.UnsupportedAppUsage;
Nathan Harold45fb1052017-12-04 09:55:56 -080028import android.os.Parcel;
29import android.os.Parcelable;
johnwang9c118c82009-09-11 19:17:29 -070030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
32/**
Wink Saville2563a3a2009-06-09 10:30:03 -070033 * Represents the neighboring cell information, including
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 * Received Signal Strength and Cell ID location.
Nathan Harold493223b2018-08-09 17:10:42 -070035 *
Nathan Harold3d850a72018-10-02 15:55:36 -070036 * @deprecated This class should not be used by any app targeting
37 * {@link Build.VERSION_CODES.Q Android Q} or higher. Instead callers should use
38 * {@Link android.telephony.CellInfo CellInfo}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 */
Nathan Harold493223b2018-08-09 17:10:42 -070040@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041public class NeighboringCellInfo implements Parcelable
42{
43 /**
44 * Signal strength is not available
45 */
46 static final public int UNKNOWN_RSSI = 99;
47 /**
48 * Cell location is not available
49 */
50 static final public int UNKNOWN_CID = -1;
51
johnwang9c118c82009-09-11 19:17:29 -070052 /**
53 * In GSM, mRssi is the Received RSSI;
54 * In UMTS, mRssi is the Level index of CPICH Received Signal Code Power
55 */
Mathew Inwooda8382062018-08-16 17:01:12 +010056 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 private int mRssi;
johnwang9c118c82009-09-11 19:17:29 -070058 /**
59 * CID in 16 bits format in GSM. Return UNKNOWN_CID in UMTS and CMDA.
60 */
Mathew Inwooda8382062018-08-16 17:01:12 +010061 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 private int mCid;
johnwang9c118c82009-09-11 19:17:29 -070063 /**
64 * LAC in 16 bits format in GSM. Return UNKNOWN_CID in UMTS and CMDA.
65 */
Mathew Inwooda8382062018-08-16 17:01:12 +010066 @UnsupportedAppUsage
johnwang9c118c82009-09-11 19:17:29 -070067 private int mLac;
68 /**
69 * Primary Scrambling Code in 9 bits format in UMTS
70 * Return UNKNOWN_CID in GSM and CMDA.
71 */
Mathew Inwooda8382062018-08-16 17:01:12 +010072 @UnsupportedAppUsage
johnwang9c118c82009-09-11 19:17:29 -070073 private int mPsc;
74 /**
75 * Radio network type, value is one of following
76 * TelephonyManager.NETWORK_TYPE_XXXXXX.
77 */
Mathew Inwooda8382062018-08-16 17:01:12 +010078 @UnsupportedAppUsage
johnwang9c118c82009-09-11 19:17:29 -070079 private int mNetworkType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
81 /**
82 * Empty constructor. Initializes the RSSI and CID.
johnwang9c118c82009-09-11 19:17:29 -070083 *
84 * NeighboringCellInfo is one time shot for the neighboring cells based on
85 * the radio network type at that moment. Its constructor needs radio network
86 * type.
Wink Savillecc6ff2b2009-12-02 09:46:38 -080087 *
88 * @deprecated by {@link #NeighboringCellInfo(int, String, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 */
Dianne Hackborn29e4a3c2009-09-30 22:35:40 -070090 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 public NeighboringCellInfo() {
92 mRssi = UNKNOWN_RSSI;
johnwang9c118c82009-09-11 19:17:29 -070093 mLac = UNKNOWN_CID;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 mCid = UNKNOWN_CID;
johnwang9c118c82009-09-11 19:17:29 -070095 mPsc = UNKNOWN_CID;
96 mNetworkType = NETWORK_TYPE_UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 }
98
99 /**
100 * Initialize the object from rssi and cid.
johnwang9c118c82009-09-11 19:17:29 -0700101 *
102 * NeighboringCellInfo is one time shot for the neighboring cells based on
103 * the radio network type at that moment. Its constructor needs radio network
104 * type.
Wink Savillecc6ff2b2009-12-02 09:46:38 -0800105 *
106 * @deprecated by {@link #NeighboringCellInfo(int, String, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 */
Dianne Hackborn29e4a3c2009-09-30 22:35:40 -0700108 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 public NeighboringCellInfo(int rssi, int cid) {
110 mRssi = rssi;
111 mCid = cid;
112 }
Wink Saville2563a3a2009-06-09 10:30:03 -0700113
Nathan Harold45fb1052017-12-04 09:55:56 -0800114 /** @hide */
115 public NeighboringCellInfo(final CellInfoGsm info) {
116 mNetworkType = TelephonyManager.NETWORK_TYPE_GPRS;
117
118 mRssi = info.getCellSignalStrength().getAsuLevel();
119 if (mRssi == Integer.MAX_VALUE) mRssi = UNKNOWN_RSSI;
120
121 mLac = info.getCellIdentity().getLac();
122 if (mLac == Integer.MAX_VALUE) mLac = UNKNOWN_CID;
123
124 mCid = info.getCellIdentity().getCid();
125 if (mCid == Integer.MAX_VALUE) mCid = UNKNOWN_CID;
126
127 mPsc = UNKNOWN_CID;
128 }
129
130 /** @hide */
131 public NeighboringCellInfo(final CellInfoWcdma info) {
132 mNetworkType = TelephonyManager.NETWORK_TYPE_UMTS;
133
134 mRssi = info.getCellSignalStrength().getAsuLevel();
135 if (mRssi == Integer.MAX_VALUE) mRssi = UNKNOWN_RSSI;
136
137 mLac = info.getCellIdentity().getLac();
138 if (mLac == Integer.MAX_VALUE) mLac = UNKNOWN_CID;
139
140 mCid = info.getCellIdentity().getCid();
141 if (mCid == Integer.MAX_VALUE) mCid = UNKNOWN_CID;
142
143 mPsc = info.getCellIdentity().getPsc();
144 if (mPsc == Integer.MAX_VALUE) mPsc = UNKNOWN_CID;
145 }
146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 /**
johnwang9c118c82009-09-11 19:17:29 -0700148 * Initialize the object from rssi, location string, and radioType
149 * radioType is one of following
150 * {@link TelephonyManager#NETWORK_TYPE_GPRS TelephonyManager.NETWORK_TYPE_GPRS},
151 * {@link TelephonyManager#NETWORK_TYPE_EDGE TelephonyManager.NETWORK_TYPE_EDGE},
152 * {@link TelephonyManager#NETWORK_TYPE_UMTS TelephonyManager.NETWORK_TYPE_UMTS},
153 * {@link TelephonyManager#NETWORK_TYPE_HSDPA TelephonyManager.NETWORK_TYPE_HSDPA},
154 * {@link TelephonyManager#NETWORK_TYPE_HSUPA TelephonyManager.NETWORK_TYPE_HSUPA},
155 * and {@link TelephonyManager#NETWORK_TYPE_HSPA TelephonyManager.NETWORK_TYPE_HSPA}.
156 */
157 public NeighboringCellInfo(int rssi, String location, int radioType) {
158 // set default value
159 mRssi = rssi;
160 mNetworkType = NETWORK_TYPE_UNKNOWN;
161 mPsc = UNKNOWN_CID;
162 mLac = UNKNOWN_CID;
163 mCid = UNKNOWN_CID;
164
165
166 // pad location string with leading "0"
167 int l = location.length();
168 if (l > 8) return;
169 if (l < 8) {
170 for (int i = 0; i < (8-l); i++) {
171 location = "0" + location;
172 }
173 }
Robert Greenwalt962a9902010-11-02 11:10:25 -0700174 // TODO - handle LTE and eHRPD (or find they can't be supported)
johnwang9c118c82009-09-11 19:17:29 -0700175 try {// set LAC/CID or PSC based on radioType
176 switch (radioType) {
177 case NETWORK_TYPE_GPRS:
178 case NETWORK_TYPE_EDGE:
179 mNetworkType = radioType;
Naveen Kallac6dd77d2010-04-07 17:54:33 -0700180 // check if 0xFFFFFFFF for UNKNOWN_CID
181 if (!location.equalsIgnoreCase("FFFFFFFF")) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +0100182 mCid = Integer.parseInt(location.substring(4), 16);
183 mLac = Integer.parseInt(location.substring(0, 4), 16);
Naveen Kallac6dd77d2010-04-07 17:54:33 -0700184 }
johnwang9c118c82009-09-11 19:17:29 -0700185 break;
186 case NETWORK_TYPE_UMTS:
187 case NETWORK_TYPE_HSDPA:
188 case NETWORK_TYPE_HSUPA:
189 case NETWORK_TYPE_HSPA:
190 mNetworkType = radioType;
Narayan Kamatha09b4d22016-04-15 18:32:45 +0100191 mPsc = Integer.parseInt(location, 16);
johnwang9c118c82009-09-11 19:17:29 -0700192 break;
193 }
194 } catch (NumberFormatException e) {
195 // parsing location error
196 mPsc = UNKNOWN_CID;
197 mLac = UNKNOWN_CID;
198 mCid = UNKNOWN_CID;
199 mNetworkType = NETWORK_TYPE_UNKNOWN;
200 }
201 }
202
203 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 * Initialize the object from a parcel.
205 */
206 public NeighboringCellInfo(Parcel in) {
207 mRssi = in.readInt();
johnwang9c118c82009-09-11 19:17:29 -0700208 mLac = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 mCid = in.readInt();
johnwang9c118c82009-09-11 19:17:29 -0700210 mPsc = in.readInt();
211 mNetworkType = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 }
Wink Saville2563a3a2009-06-09 10:30:03 -0700213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 /**
johnwang9c118c82009-09-11 19:17:29 -0700215 * @return received signal strength or UNKNOWN_RSSI if unknown
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 *
johnwang9c118c82009-09-11 19:17:29 -0700217 * 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 -0800218 * 0 means "-113 dBm or less" and 31 means "-51 dBm or greater"
johnwang9c118c82009-09-11 19:17:29 -0700219 * 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 -0800220 */
221 public int getRssi() {
222 return mRssi;
223 }
224
225 /**
johnwang9c118c82009-09-11 19:17:29 -0700226 * @return LAC in GSM, 0xffff max legal value
227 * UNKNOWN_CID if in UMTS or CMDA or unknown
228 */
229 public int getLac() {
230 return mLac;
231 }
232
233 /**
234 * @return cell id in GSM, 0xffff max legal value
235 * UNKNOWN_CID if in UMTS or CDMA or unknown
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 */
237 public int getCid() {
238 return mCid;
239 }
240
241 /**
johnwang9c118c82009-09-11 19:17:29 -0700242 * @return Primary Scrambling Code in 9 bits format in UMTS, 0x1ff max value
243 * UNKNOWN_CID if in GSM or CMDA or unknown
244 */
245 public int getPsc() {
246 return mPsc;
247 }
248
249 /**
250 * @return Radio network type while neighboring cell location is stored.
251 *
252 * Return {@link TelephonyManager#NETWORK_TYPE_UNKNOWN TelephonyManager.NETWORK_TYPE_UNKNOWN}
253 * means that the location information is unavailable.
254 *
255 * Return {@link TelephonyManager#NETWORK_TYPE_GPRS TelephonyManager.NETWORK_TYPE_GPRS} or
256 * {@link TelephonyManager#NETWORK_TYPE_EDGE TelephonyManager.NETWORK_TYPE_EDGE}
257 * means that Neighboring Cell information is stored for GSM network, in
258 * which {@link NeighboringCellInfo#getLac NeighboringCellInfo.getLac} and
259 * {@link NeighboringCellInfo#getCid NeighboringCellInfo.getCid} should be
260 * called to access location.
261 *
262 * Return {@link TelephonyManager#NETWORK_TYPE_UMTS TelephonyManager.NETWORK_TYPE_UMTS},
263 * {@link TelephonyManager#NETWORK_TYPE_HSDPA TelephonyManager.NETWORK_TYPE_HSDPA},
264 * {@link TelephonyManager#NETWORK_TYPE_HSUPA TelephonyManager.NETWORK_TYPE_HSUPA},
265 * or {@link TelephonyManager#NETWORK_TYPE_HSPA TelephonyManager.NETWORK_TYPE_HSPA}
266 * means that Neighboring Cell information is stored for UMTS network, in
267 * which {@link NeighboringCellInfo#getPsc NeighboringCellInfo.getPsc}
268 * should be called to access location.
269 */
270 public int getNetworkType() {
271 return mNetworkType;
272 }
273 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 * Set the cell id.
johnwang9c118c82009-09-11 19:17:29 -0700275 *
276 * NeighboringCellInfo is a one time shot for the neighboring cells based on
277 * the radio network type at that moment. It shouldn't be changed after
278 * creation.
Wink Savillecc6ff2b2009-12-02 09:46:38 -0800279 *
280 * @deprecated cid value passed as in location parameter passed to constructor
281 * {@link #NeighboringCellInfo(int, String, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 */
Dianne Hackborn29e4a3c2009-09-30 22:35:40 -0700283 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 public void setCid(int cid) {
285 mCid = cid;
286 }
287
288 /**
289 * Set the signal strength of the cell.
johnwang9c118c82009-09-11 19:17:29 -0700290 *
291 * NeighboringCellInfo is a one time shot for the neighboring cells based on
292 * the radio network type at that moment. It shouldn't be changed after
293 * creation.
Wink Savillecc6ff2b2009-12-02 09:46:38 -0800294 *
295 * @deprecated initial rssi value passed as parameter to constructor
296 * {@link #NeighboringCellInfo(int, String, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 */
Dianne Hackborn29e4a3c2009-09-30 22:35:40 -0700298 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 public void setRssi(int rssi) {
300 mRssi = rssi;
301 }
302
303 @Override
304 public String toString() {
johnwang9c118c82009-09-11 19:17:29 -0700305 StringBuilder sb = new StringBuilder();
306
307 sb.append("[");
308 if (mPsc != UNKNOWN_CID) {
309 sb.append(Integer.toHexString(mPsc))
310 .append("@").append(((mRssi == UNKNOWN_RSSI)? "-" : mRssi));
311 } else if(mLac != UNKNOWN_CID && mCid != UNKNOWN_CID) {
312 sb.append(Integer.toHexString(mLac))
313 .append(Integer.toHexString(mCid))
314 .append("@").append(((mRssi == UNKNOWN_RSSI)? "-" : mRssi));
315 }
316 sb.append("]");
317
318 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 }
320
321 public int describeContents() {
322 return 0;
323 }
324
325 public void writeToParcel(Parcel dest, int flags) {
326 dest.writeInt(mRssi);
johnwang9c118c82009-09-11 19:17:29 -0700327 dest.writeInt(mLac);
Wink Saville2563a3a2009-06-09 10:30:03 -0700328 dest.writeInt(mCid);
johnwang9c118c82009-09-11 19:17:29 -0700329 dest.writeInt(mPsc);
330 dest.writeInt(mNetworkType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 }
332
333 public static final Parcelable.Creator<NeighboringCellInfo> CREATOR
334 = new Parcelable.Creator<NeighboringCellInfo>() {
335 public NeighboringCellInfo createFromParcel(Parcel in) {
336 return new NeighboringCellInfo(in);
337 }
338
339 public NeighboringCellInfo[] newArray(int size) {
340 return new NeighboringCellInfo[size];
341 }
342 };
Naveen Kallac6dd77d2010-04-07 17:54:33 -0700343}