blob: dc73cbf735b09cb7e3c7871de311cc51fc6d0409 [file] [log] [blame]
Wink Savilleb208a242012-07-25 14:08:09 -07001/*
2 * Copyright (C) 2012 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
Meng Wangd75f97d2019-12-06 18:27:38 -080019import android.annotation.NonNull;
Nathan Harold13d6b112018-12-18 13:40:08 -080020import android.annotation.Nullable;
Artur Satayev2ebb31c2020-01-08 12:24:36 +000021import android.compat.annotation.UnsupportedAppUsage;
Wink Savilleb208a242012-07-25 14:08:09 -070022import android.os.Parcel;
Nathan Harold7590fee2018-07-19 10:18:23 -070023import android.telephony.gsm.GsmCellLocation;
Cassie933b78d2017-09-20 14:02:13 -070024import android.text.TextUtils;
Wink Savilleb208a242012-07-25 14:08:09 -070025
Nathan Haroldac37b632020-01-20 19:04:40 -080026import java.util.Collections;
27import java.util.List;
Brian Williammee7d1d2e32014-08-29 17:31:22 -070028import java.util.Objects;
29
Wink Savilleb208a242012-07-25 14:08:09 -070030/**
Wink Savillee3a9cbc2013-04-17 16:40:17 -070031 * CellIdentity to represent a unique GSM cell
Wink Savilleb208a242012-07-25 14:08:09 -070032 */
Jack Yu6cd44732017-12-28 14:41:12 -080033public final class CellIdentityGsm extends CellIdentity {
34 private static final String TAG = CellIdentityGsm.class.getSimpleName();
Wink Savilleb208a242012-07-25 14:08:09 -070035 private static final boolean DBG = false;
36
Nathan Harold251d0a92019-04-10 17:39:27 -070037 private static final int MAX_LAC = 65535;
38 private static final int MAX_CID = 65535;
39 private static final int MAX_ARFCN = 65535;
40 private static final int MAX_BSIC = 63;
41
Wink Savilleb208a242012-07-25 14:08:09 -070042 // 16-bit Location Area Code, 0..65535
43 private final int mLac;
44 // 16-bit GSM Cell Identity described in TS 27.007, 0..65535
Wink Savilleb208a242012-07-25 14:08:09 -070045 private final int mCid;
Sanket Padawe0c86efd2016-01-26 18:42:47 -080046 // 16-bit GSM Absolute RF Channel Number
47 private final int mArfcn;
48 // 6-bit Base Station Identity Code
49 private final int mBsic;
Wink Savilleb208a242012-07-25 14:08:09 -070050
Nathan Haroldac37b632020-01-20 19:04:40 -080051 // a list of additional PLMN-IDs reported for this cell
52 private final List<String> mAdditionalPlmns;
53
Wink Savilleb208a242012-07-25 14:08:09 -070054 /**
55 * @hide
56 */
Mathew Inwooda8382062018-08-16 17:01:12 +010057 @UnsupportedAppUsage
Wink Savilleb208a242012-07-25 14:08:09 -070058 public CellIdentityGsm() {
Nathan Harold65c4b152018-07-30 16:10:50 -070059 super(TAG, CellInfo.TYPE_GSM, null, null, null, null);
Nathan Harolda629ea32018-10-24 11:35:53 -070060 mLac = CellInfo.UNAVAILABLE;
61 mCid = CellInfo.UNAVAILABLE;
62 mArfcn = CellInfo.UNAVAILABLE;
63 mBsic = CellInfo.UNAVAILABLE;
Nathan Haroldac37b632020-01-20 19:04:40 -080064 mAdditionalPlmns = Collections.emptyList();
Wink Savilleb208a242012-07-25 14:08:09 -070065 }
Cassie933b78d2017-09-20 14:02:13 -070066
67 /**
68 * public constructor
69 * @param lac 16-bit Location Area Code, 0..65535
70 * @param cid 16-bit GSM Cell Identity or 28-bit UMTS Cell Identity
71 * @param arfcn 16-bit GSM Absolute RF Channel Number
72 * @param bsic 6-bit Base Station Identity Code
73 * @param mccStr 3-digit Mobile Country Code in string format
74 * @param mncStr 2 or 3-digit Mobile Network Code in string format
75 * @param alphal long alpha Operator Name String or Enhanced Operator Name String
76 * @param alphas short alpha Operator Name String or Enhanced Operator Name String
Nathan Haroldac37b632020-01-20 19:04:40 -080077 * @param additionalPlmns a list of additional PLMN IDs broadcast by the cell
Cassie933b78d2017-09-20 14:02:13 -070078 *
Cassie933b78d2017-09-20 14:02:13 -070079 * @hide
80 */
Jack Yu6cd44732017-12-28 14:41:12 -080081 public CellIdentityGsm(int lac, int cid, int arfcn, int bsic, String mccStr,
Nathan Haroldac37b632020-01-20 19:04:40 -080082 String mncStr, String alphal, String alphas,
83 List<String> additionalPlmns) {
Nathan Harold65c4b152018-07-30 16:10:50 -070084 super(TAG, CellInfo.TYPE_GSM, mccStr, mncStr, alphal, alphas);
Nathan Harold251d0a92019-04-10 17:39:27 -070085 mLac = inRangeOrUnavailable(lac, 0, MAX_LAC);
86 mCid = inRangeOrUnavailable(cid, 0, MAX_CID);
87 mArfcn = inRangeOrUnavailable(arfcn, 0, MAX_ARFCN);
88 mBsic = inRangeOrUnavailable(bsic, 0, MAX_BSIC);
Nathan Haroldac37b632020-01-20 19:04:40 -080089 mAdditionalPlmns = additionalPlmns;
Nathan Harold7ce5baf2018-12-10 13:39:40 -080090 }
91
92 /** @hide */
93 public CellIdentityGsm(android.hardware.radio.V1_0.CellIdentityGsm cid) {
94 this(cid.lac, cid.cid, cid.arfcn,
Nathan Haroldb635fb82018-12-26 17:14:25 -080095 cid.bsic == (byte) 0xFF ? CellInfo.UNAVAILABLE : cid.bsic,
Nathan Haroldac37b632020-01-20 19:04:40 -080096 cid.mcc, cid.mnc, "", "", Collections.emptyList());
Nathan Harold7ce5baf2018-12-10 13:39:40 -080097 }
98
99 /** @hide */
100 public CellIdentityGsm(android.hardware.radio.V1_2.CellIdentityGsm cid) {
101 this(cid.base.lac, cid.base.cid, cid.base.arfcn,
Nathan Haroldb635fb82018-12-26 17:14:25 -0800102 cid.base.bsic == (byte) 0xFF ? CellInfo.UNAVAILABLE : cid.base.bsic, cid.base.mcc,
Nathan Haroldac37b632020-01-20 19:04:40 -0800103 cid.base.mnc, cid.operatorNames.alphaLong, cid.operatorNames.alphaShort,
104 Collections.emptyList());
105 }
106
107 /** @hide */
108 public CellIdentityGsm(android.hardware.radio.V1_5.CellIdentityGsm cid) {
109 this(cid.base.base.lac, cid.base.base.cid, cid.base.base.arfcn,
110 cid.base.base.bsic == (byte) 0xFF ? CellInfo.UNAVAILABLE
111 : cid.base.base.bsic, cid.base.base.mcc,
112 cid.base.base.mnc, cid.base.operatorNames.alphaLong,
113 cid.base.operatorNames.alphaShort, cid.additionalPlmns);
Wink Savilleb208a242012-07-25 14:08:09 -0700114 }
115
116 private CellIdentityGsm(CellIdentityGsm cid) {
Cassie933b78d2017-09-20 14:02:13 -0700117 this(cid.mLac, cid.mCid, cid.mArfcn, cid.mBsic, cid.mMccStr,
Nathan Haroldac37b632020-01-20 19:04:40 -0800118 cid.mMncStr, cid.mAlphaLong, cid.mAlphaShort, cid.mAdditionalPlmns);
Wink Savilleb208a242012-07-25 14:08:09 -0700119 }
120
Wink Savilleb208a242012-07-25 14:08:09 -0700121 CellIdentityGsm copy() {
Cassie933b78d2017-09-20 14:02:13 -0700122 return new CellIdentityGsm(this);
Wink Savilleb208a242012-07-25 14:08:09 -0700123 }
124
Hall Liuc9d74302019-02-28 15:29:19 -0800125 /** @hide */
Nathan Harold5e6e9832019-12-17 13:06:54 -0800126 @Override
127 public @NonNull CellIdentityGsm sanitizeLocationInfo() {
Hall Liuc9d74302019-02-28 15:29:19 -0800128 return new CellIdentityGsm(CellInfo.UNAVAILABLE, CellInfo.UNAVAILABLE, CellInfo.UNAVAILABLE,
Nathan Haroldac37b632020-01-20 19:04:40 -0800129 CellInfo.UNAVAILABLE, mMccStr, mMncStr, mAlphaLong, mAlphaShort, mAdditionalPlmns);
Hall Liuc9d74302019-02-28 15:29:19 -0800130 }
131
Wink Savilleb208a242012-07-25 14:08:09 -0700132 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700133 * @return 3-digit Mobile Country Code, 0..999,
134 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Cassied062c3222018-02-28 11:45:29 -0800135 * @deprecated Use {@link #getMccString} instead.
Wink Savilleb208a242012-07-25 14:08:09 -0700136 */
Cassie933b78d2017-09-20 14:02:13 -0700137 @Deprecated
Wink Savilleb208a242012-07-25 14:08:09 -0700138 public int getMcc() {
Nathan Harolda629ea32018-10-24 11:35:53 -0700139 return (mMccStr != null) ? Integer.valueOf(mMccStr) : CellInfo.UNAVAILABLE;
Wink Savilleb208a242012-07-25 14:08:09 -0700140 }
141
142 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700143 * @return 2 or 3-digit Mobile Network Code, 0..999,
144 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Cassied062c3222018-02-28 11:45:29 -0800145 * @deprecated Use {@link #getMncString} instead.
Wink Savilleb208a242012-07-25 14:08:09 -0700146 */
Cassie933b78d2017-09-20 14:02:13 -0700147 @Deprecated
Wink Savilleb208a242012-07-25 14:08:09 -0700148 public int getMnc() {
Nathan Harolda629ea32018-10-24 11:35:53 -0700149 return (mMncStr != null) ? Integer.valueOf(mMncStr) : CellInfo.UNAVAILABLE;
Wink Savilleb208a242012-07-25 14:08:09 -0700150 }
151
152 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700153 * @return 16-bit Location Area Code, 0..65535,
154 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Wink Savilleb208a242012-07-25 14:08:09 -0700155 */
156 public int getLac() {
157 return mLac;
158 }
159
160 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700161 * @return 16-bit GSM Cell Identity described in TS 27.007, 0..65535,
162 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Wink Savilleb208a242012-07-25 14:08:09 -0700163 */
164 public int getCid() {
165 return mCid;
166 }
167
168 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700169 * @return 16-bit GSM Absolute RF Channel Number,
170 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Sanket Padawe0c86efd2016-01-26 18:42:47 -0800171 */
172 public int getArfcn() {
173 return mArfcn;
174 }
175
176 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700177 * @return 6-bit Base Station Identity Code,
178 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Sanket Padawe0c86efd2016-01-26 18:42:47 -0800179 */
180 public int getBsic() {
181 return mBsic;
182 }
183
Cassie933b78d2017-09-20 14:02:13 -0700184 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700185 * @return a 5 or 6 character string (MCC+MNC), null if any field is unknown.
Cassie933b78d2017-09-20 14:02:13 -0700186 */
Nathan Harold13d6b112018-12-18 13:40:08 -0800187 @Nullable
Cassie933b78d2017-09-20 14:02:13 -0700188 public String getMobileNetworkOperator() {
Cassieb799fcd2017-11-30 15:54:51 -0800189 return (mMccStr == null || mMncStr == null) ? null : mMccStr + mMncStr;
Cassie933b78d2017-09-20 14:02:13 -0700190 }
191
192 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700193 * @return Mobile Country Code in string format, null if unavailable.
Cassie933b78d2017-09-20 14:02:13 -0700194 */
Nathan Harold78cf8ac2019-04-08 19:21:02 -0700195 @Nullable
Cassied062c3222018-02-28 11:45:29 -0800196 public String getMccString() {
Cassie933b78d2017-09-20 14:02:13 -0700197 return mMccStr;
198 }
199
200 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700201 * @return Mobile Network Code in string format, null if unavailable.
Cassie933b78d2017-09-20 14:02:13 -0700202 */
Nathan Harold78cf8ac2019-04-08 19:21:02 -0700203 @Nullable
Cassied062c3222018-02-28 11:45:29 -0800204 public String getMncString() {
Cassie933b78d2017-09-20 14:02:13 -0700205 return mMncStr;
206 }
207
Eric Schwarzenbach2c1a1772018-03-02 17:47:13 -0800208 /** @hide */
209 @Override
210 public int getChannelNumber() {
211 return mArfcn;
212 }
Sanket Padawe0c86efd2016-01-26 18:42:47 -0800213
214 /**
Nathan Haroldac37b632020-01-20 19:04:40 -0800215 * @return a list of additional PLMN IDs supported by this cell.
216 */
217 @NonNull
218 public List<String> getAdditionalPlmns() {
219 return mAdditionalPlmns;
220 }
221
222 /**
Jack Yu6cd44732017-12-28 14:41:12 -0800223 * @deprecated Primary Scrambling Code is not applicable to GSM.
Nathan Harolda629ea32018-10-24 11:35:53 -0700224 * @return {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} - undefined for GSM
Wink Savilleb208a242012-07-25 14:08:09 -0700225 */
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700226 @Deprecated
Wink Savilleb208a242012-07-25 14:08:09 -0700227 public int getPsc() {
Nathan Harolda629ea32018-10-24 11:35:53 -0700228 return CellInfo.UNAVAILABLE;
Wink Savilleb208a242012-07-25 14:08:09 -0700229 }
230
Nathan Harold7590fee2018-07-19 10:18:23 -0700231 /** @hide */
Meng Wangd75f97d2019-12-06 18:27:38 -0800232 @NonNull
Nathan Harold7590fee2018-07-19 10:18:23 -0700233 @Override
234 public GsmCellLocation asCellLocation() {
235 GsmCellLocation cl = new GsmCellLocation();
Nathan Harolda629ea32018-10-24 11:35:53 -0700236 int lac = mLac != CellInfo.UNAVAILABLE ? mLac : -1;
237 int cid = mCid != CellInfo.UNAVAILABLE ? mCid : -1;
Nathan Harold7590fee2018-07-19 10:18:23 -0700238 cl.setLacAndCid(lac, cid);
239 cl.setPsc(-1);
240 return cl;
241 }
242
Wink Savilleb208a242012-07-25 14:08:09 -0700243 @Override
244 public int hashCode() {
Nathan Haroldac37b632020-01-20 19:04:40 -0800245 return Objects.hash(mLac, mCid, mAdditionalPlmns.hashCode(), super.hashCode());
Wink Savilleb208a242012-07-25 14:08:09 -0700246 }
247
248 @Override
249 public boolean equals(Object other) {
Brian Williammee7d1d2e32014-08-29 17:31:22 -0700250 if (this == other) {
251 return true;
252 }
253
254 if (!(other instanceof CellIdentityGsm)) {
Wink Savilleb208a242012-07-25 14:08:09 -0700255 return false;
256 }
Brian Williammee7d1d2e32014-08-29 17:31:22 -0700257
258 CellIdentityGsm o = (CellIdentityGsm) other;
Jack Yu6cd44732017-12-28 14:41:12 -0800259 return mLac == o.mLac
260 && mCid == o.mCid
261 && mArfcn == o.mArfcn
262 && mBsic == o.mBsic
263 && TextUtils.equals(mMccStr, o.mMccStr)
264 && TextUtils.equals(mMncStr, o.mMncStr)
Nathan Haroldac37b632020-01-20 19:04:40 -0800265 && mAdditionalPlmns.equals(o.mAdditionalPlmns)
Cassie21ed3c52018-03-21 16:20:34 -0700266 && super.equals(other);
Wink Savilleb208a242012-07-25 14:08:09 -0700267 }
268
269 @Override
270 public String toString() {
Jack Yu6cd44732017-12-28 14:41:12 -0800271 return new StringBuilder(TAG)
272 .append(":{ mLac=").append(mLac)
273 .append(" mCid=").append(mCid)
274 .append(" mArfcn=").append(mArfcn)
275 .append(" mBsic=").append("0x").append(Integer.toHexString(mBsic))
276 .append(" mMcc=").append(mMccStr)
277 .append(" mMnc=").append(mMncStr)
278 .append(" mAlphaLong=").append(mAlphaLong)
279 .append(" mAlphaShort=").append(mAlphaShort)
Nathan Haroldac37b632020-01-20 19:04:40 -0800280 .append(" mAdditionalPlmns=").append(mAdditionalPlmns)
Jack Yu6cd44732017-12-28 14:41:12 -0800281 .append("}").toString();
Wink Savilleb208a242012-07-25 14:08:09 -0700282 }
283
284 /** Implement the Parcelable interface */
285 @Override
286 public void writeToParcel(Parcel dest, int flags) {
287 if (DBG) log("writeToParcel(Parcel, int): " + toString());
Nathan Harold65c4b152018-07-30 16:10:50 -0700288 super.writeToParcel(dest, CellInfo.TYPE_GSM);
Wink Savilleb208a242012-07-25 14:08:09 -0700289 dest.writeInt(mLac);
290 dest.writeInt(mCid);
Sanket Padawe0c86efd2016-01-26 18:42:47 -0800291 dest.writeInt(mArfcn);
292 dest.writeInt(mBsic);
Nathan Haroldac37b632020-01-20 19:04:40 -0800293 dest.writeList(mAdditionalPlmns);
Wink Savilleb208a242012-07-25 14:08:09 -0700294 }
295
296 /** Construct from Parcel, type has already been processed */
297 private CellIdentityGsm(Parcel in) {
Nathan Harold65c4b152018-07-30 16:10:50 -0700298 super(TAG, CellInfo.TYPE_GSM, in);
Jack Yu6cd44732017-12-28 14:41:12 -0800299 mLac = in.readInt();
300 mCid = in.readInt();
301 mArfcn = in.readInt();
302 mBsic = in.readInt();
Nathan Haroldac37b632020-01-20 19:04:40 -0800303 mAdditionalPlmns = in.readArrayList(null);
Nathan Harolda326a482016-05-05 12:27:10 -0700304
Jack Yu6cd44732017-12-28 14:41:12 -0800305 if (DBG) log(toString());
Wink Savilleb208a242012-07-25 14:08:09 -0700306 }
307
308 /** Implement the Parcelable interface */
309 @SuppressWarnings("hiding")
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700310 public static final @android.annotation.NonNull Creator<CellIdentityGsm> CREATOR =
Wink Savilleb208a242012-07-25 14:08:09 -0700311 new Creator<CellIdentityGsm>() {
Cassie933b78d2017-09-20 14:02:13 -0700312 @Override
313 public CellIdentityGsm createFromParcel(Parcel in) {
Jack Yu6cd44732017-12-28 14:41:12 -0800314 in.readInt(); // skip
315 return createFromParcelBody(in);
Cassie933b78d2017-09-20 14:02:13 -0700316 }
Wink Savilleb208a242012-07-25 14:08:09 -0700317
Cassie933b78d2017-09-20 14:02:13 -0700318 @Override
319 public CellIdentityGsm[] newArray(int size) {
320 return new CellIdentityGsm[size];
321 }
322 };
Wink Savilleb208a242012-07-25 14:08:09 -0700323
Jack Yu6cd44732017-12-28 14:41:12 -0800324 /** @hide */
325 protected static CellIdentityGsm createFromParcelBody(Parcel in) {
326 return new CellIdentityGsm(in);
Wink Savilleb208a242012-07-25 14:08:09 -0700327 }
Jack Yu6cd44732017-12-28 14:41:12 -0800328}