blob: e74b70939d140a7fe3c1bc7d7c72ffdd4610591f [file] [log] [blame]
Jack Yu6cd44732017-12-28 14:41:12 -08001/*
2 * Copyright 2017 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
Nathan Haroldb2bfb292019-03-19 13:20:17 -070019import android.annotation.NonNull;
Nathan Harold13d6b112018-12-18 13:40:08 -080020import android.annotation.Nullable;
Jack Yu6cd44732017-12-28 14:41:12 -080021import android.os.Parcel;
Nathan Harold7590fee2018-07-19 10:18:23 -070022import android.telephony.gsm.GsmCellLocation;
Nathan Harold5522de1a2020-02-13 19:50:51 -080023import android.util.ArraySet;
Jack Yu6cd44732017-12-28 14:41:12 -080024
Nathan Harold5522de1a2020-02-13 19:50:51 -080025import java.util.Collection;
Nathan Haroldac37b632020-01-20 19:04:40 -080026import java.util.Collections;
Jack Yu6cd44732017-12-28 14:41:12 -080027import java.util.Objects;
Nathan Harold5522de1a2020-02-13 19:50:51 -080028import java.util.Set;
Jack Yu6cd44732017-12-28 14:41:12 -080029
30/**
31 * CellIdentity is to represent a unique TD-SCDMA cell
32 */
33public final class CellIdentityTdscdma extends CellIdentity {
34 private static final String TAG = CellIdentityTdscdma.class.getSimpleName();
35 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 = 268435455;
39 private static final int MAX_CPID = 127;
40 private static final int MAX_UARFCN = 65535;
41
Nathan Harolda629ea32018-10-24 11:35:53 -070042 // 16-bit Location Area Code, 0..65535, CellInfo.UNAVAILABLE if unknown.
Jack Yu6cd44732017-12-28 14:41:12 -080043 private final int mLac;
Nathan Harolda629ea32018-10-24 11:35:53 -070044 // 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, CellInfo.UNAVAILABLE
45 // if unknown.
Jack Yu6cd44732017-12-28 14:41:12 -080046 private final int mCid;
Nathan Harold251d0a92019-04-10 17:39:27 -070047 // 8-bit Cell Parameters ID described in TS 25.331 sec 10.3.6.9,
48 // 0..127, CellInfo.UNAVAILABLE if unknown.
Jack Yu6cd44732017-12-28 14:41:12 -080049 private final int mCpid;
Nathan Harold054b79d2018-03-28 08:39:43 -070050 // 16-bit UMTS Absolute RF Channel Number described in TS 25.101 sec. 5.4.3
51 private final int mUarfcn;
Jack Yu6cd44732017-12-28 14:41:12 -080052
Nathan Haroldac37b632020-01-20 19:04:40 -080053 // a list of additional PLMN-IDs reported for this cell
Nathan Harold5522de1a2020-02-13 19:50:51 -080054 private final ArraySet<String> mAdditionalPlmns;
Nathan Haroldac37b632020-01-20 19:04:40 -080055
56 private ClosedSubscriberGroupInfo mCsgInfo;
57
Jack Yu6cd44732017-12-28 14:41:12 -080058 /**
59 * @hide
60 */
61 public CellIdentityTdscdma() {
Nathan Harold65c4b152018-07-30 16:10:50 -070062 super(TAG, CellInfo.TYPE_TDSCDMA, null, null, null, null);
Nathan Harolda629ea32018-10-24 11:35:53 -070063 mLac = CellInfo.UNAVAILABLE;
64 mCid = CellInfo.UNAVAILABLE;
65 mCpid = CellInfo.UNAVAILABLE;
66 mUarfcn = CellInfo.UNAVAILABLE;
Nathan Harold5522de1a2020-02-13 19:50:51 -080067 mAdditionalPlmns = new ArraySet<>();
Nathan Haroldac37b632020-01-20 19:04:40 -080068 mCsgInfo = null;
Mingming Caic78abaa2020-03-13 11:17:46 -070069 mGlobalCellId = null;
Jack Yu6cd44732017-12-28 14:41:12 -080070 }
71
72 /**
Jack Yu6cd44732017-12-28 14:41:12 -080073 * @param mcc 3-digit Mobile Country Code in string format
74 * @param mnc 2 or 3-digit Mobile Network Code in string format
Nathan Harolda629ea32018-10-24 11:35:53 -070075 * @param lac 16-bit Location Area Code, 0..65535, CellInfo.UNAVAILABLE if unknown
76 * @param cid 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455,
77 * CellInfo.UNAVAILABLE if unknown
78 * @param cpid 8-bit Cell Parameters ID described in TS 25.331, 0..127,
79 * CellInfo.UNAVAILABLE if unknown
Nathan Harold054b79d2018-03-28 08:39:43 -070080 * @param uarfcn 16-bit UMTS Absolute RF Channel Number described in TS 25.101 sec. 5.4.3
Nathan Harolda7b147e2018-03-19 16:59:40 -070081 * @param alphal long alpha Operator Name String or Enhanced Operator Name String
82 * @param alphas short alpha Operator Name String or Enhanced Operator Name String
Nathan Haroldac37b632020-01-20 19:04:40 -080083 * @param additionalPlmns a list of additional PLMN IDs broadcast by the cell
84 * @param csgInfo info about the closed subscriber group broadcast by the cell
Nathan Harolda7b147e2018-03-19 16:59:40 -070085 *
86 * @hide
87 */
Rambo Wang33f62a02020-01-29 14:37:05 -080088 public CellIdentityTdscdma(@Nullable String mcc, @Nullable String mnc, int lac, int cid,
89 int cpid, int uarfcn, @Nullable String alphal, @Nullable String alphas,
Nathan Harold5522de1a2020-02-13 19:50:51 -080090 @NonNull Collection<String> additionalPlmns,
91 @Nullable ClosedSubscriberGroupInfo csgInfo) {
Nathan Harold65c4b152018-07-30 16:10:50 -070092 super(TAG, CellInfo.TYPE_TDSCDMA, mcc, mnc, alphal, alphas);
Nathan Harold251d0a92019-04-10 17:39:27 -070093 mLac = inRangeOrUnavailable(lac, 0, MAX_LAC);
94 mCid = inRangeOrUnavailable(cid, 0, MAX_CID);
95 mCpid = inRangeOrUnavailable(cpid, 0, MAX_CPID);
96 mUarfcn = inRangeOrUnavailable(uarfcn, 0, MAX_UARFCN);
Nathan Harold5522de1a2020-02-13 19:50:51 -080097 mAdditionalPlmns = new ArraySet<>(additionalPlmns.size());
Rambo Wang33f62a02020-01-29 14:37:05 -080098 for (String plmn : additionalPlmns) {
99 if (isValidPlmn(plmn)) {
100 mAdditionalPlmns.add(plmn);
101 }
102 }
Nathan Haroldac37b632020-01-20 19:04:40 -0800103 mCsgInfo = csgInfo;
Mingming Caic78abaa2020-03-13 11:17:46 -0700104 updateGlobalCellId();
Jack Yu6cd44732017-12-28 14:41:12 -0800105 }
106
Rambo Wang33f62a02020-01-29 14:37:05 -0800107 private CellIdentityTdscdma(@NonNull CellIdentityTdscdma cid) {
Nathan Harolda7b147e2018-03-19 16:59:40 -0700108 this(cid.mMccStr, cid.mMncStr, cid.mLac, cid.mCid,
Nathan Haroldac37b632020-01-20 19:04:40 -0800109 cid.mCpid, cid.mUarfcn, cid.mAlphaLong,
110 cid.mAlphaShort, cid.mAdditionalPlmns, cid.mCsgInfo);
Jack Yu6cd44732017-12-28 14:41:12 -0800111 }
112
Nathan Harold7ce5baf2018-12-10 13:39:40 -0800113 /** @hide */
Rambo Wang33f62a02020-01-29 14:37:05 -0800114 public CellIdentityTdscdma(@NonNull android.hardware.radio.V1_0.CellIdentityTdscdma cid) {
Nathan Haroldac37b632020-01-20 19:04:40 -0800115 this(cid.mcc, cid.mnc, cid.lac, cid.cid, cid.cpid, CellInfo.UNAVAILABLE, "", "",
116 Collections.emptyList(), null);
Nathan Harold7ce5baf2018-12-10 13:39:40 -0800117 }
118
119 /** @hide */
Rambo Wang33f62a02020-01-29 14:37:05 -0800120 public CellIdentityTdscdma(@NonNull android.hardware.radio.V1_2.CellIdentityTdscdma cid) {
Nathan Harold7ce5baf2018-12-10 13:39:40 -0800121 this(cid.base.mcc, cid.base.mnc, cid.base.lac, cid.base.cid, cid.base.cpid,
Nathan Haroldac37b632020-01-20 19:04:40 -0800122 cid.uarfcn, cid.operatorNames.alphaLong, cid.operatorNames.alphaShort,
123 Collections.emptyList(), null);
124 }
125
126 /** @hide */
Rambo Wang33f62a02020-01-29 14:37:05 -0800127 public CellIdentityTdscdma(@NonNull android.hardware.radio.V1_5.CellIdentityTdscdma cid) {
Nathan Haroldac37b632020-01-20 19:04:40 -0800128 this(cid.base.base.mcc, cid.base.base.mnc, cid.base.base.lac, cid.base.base.cid,
129 cid.base.base.cpid, cid.base.uarfcn, cid.base.operatorNames.alphaLong,
130 cid.base.operatorNames.alphaShort,
Nathan Haroldb3cefba2020-03-26 13:08:32 -0700131 cid.additionalPlmns,
132 cid.optionalCsgInfo.getDiscriminator()
133 == android.hardware.radio.V1_5.OptionalCsgInfo.hidl_discriminator.csgInfo
134 ? new ClosedSubscriberGroupInfo(cid.optionalCsgInfo.csgInfo())
135 : null);
Nathan Harold7ce5baf2018-12-10 13:39:40 -0800136 }
137
Hall Liuc9d74302019-02-28 15:29:19 -0800138 /** @hide */
Nathan Harold5e6e9832019-12-17 13:06:54 -0800139 @Override
140 public @NonNull CellIdentityTdscdma sanitizeLocationInfo() {
Hall Liuc9d74302019-02-28 15:29:19 -0800141 return new CellIdentityTdscdma(mMccStr, mMncStr, CellInfo.UNAVAILABLE, CellInfo.UNAVAILABLE,
Nathan Haroldac37b632020-01-20 19:04:40 -0800142 CellInfo.UNAVAILABLE, CellInfo.UNAVAILABLE, mAlphaLong, mAlphaShort,
143 mAdditionalPlmns, null);
Hall Liuc9d74302019-02-28 15:29:19 -0800144 }
145
Rambo Wang33f62a02020-01-29 14:37:05 -0800146 @NonNull CellIdentityTdscdma copy() {
Jack Yu6cd44732017-12-28 14:41:12 -0800147 return new CellIdentityTdscdma(this);
148 }
149
Mingming Caic78abaa2020-03-13 11:17:46 -0700150 /** @hide */
151 @Override
152 protected void updateGlobalCellId() {
153 mGlobalCellId = null;
154 String plmn = getPlmn();
155 if (plmn == null) return;
156
157 if (mLac == CellInfo.UNAVAILABLE || mCid == CellInfo.UNAVAILABLE) return;
158
159 mGlobalCellId = plmn + String.format("%04x%04x", mLac, mCid);
160 }
161
Jack Yu6cd44732017-12-28 14:41:12 -0800162 /**
163 * Get Mobile Country Code in string format
164 * @return Mobile Country Code in string format, null if unknown
165 */
Nathan Harold4f414752019-04-08 19:21:02 -0700166 @Nullable
Cassied062c3222018-02-28 11:45:29 -0800167 public String getMccString() {
Jack Yu6cd44732017-12-28 14:41:12 -0800168 return mMccStr;
169 }
170
171 /**
172 * Get Mobile Network Code in string format
173 * @return Mobile Network Code in string format, null if unknown
174 */
Nathan Harold4f414752019-04-08 19:21:02 -0700175 @Nullable
Cassied062c3222018-02-28 11:45:29 -0800176 public String getMncString() {
Jack Yu6cd44732017-12-28 14:41:12 -0800177 return mMncStr;
178 }
179
180 /**
Nathan Haroldd285c8e2018-10-22 15:07:06 -0700181 * @return a 5 or 6 character string (MCC+MNC), null if any field is unknown
182 */
Nathan Harold13d6b112018-12-18 13:40:08 -0800183 @Nullable
Nathan Haroldd285c8e2018-10-22 15:07:06 -0700184 public String getMobileNetworkOperator() {
185 return (mMccStr == null || mMncStr == null) ? null : mMccStr + mMncStr;
186 }
187
188 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700189 * @return 16-bit Location Area Code, 0..65535,
190 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Jack Yu6cd44732017-12-28 14:41:12 -0800191 */
192 public int getLac() {
193 return mLac;
194 }
195
196 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700197 * @return 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455,
198 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Jack Yu6cd44732017-12-28 14:41:12 -0800199 */
200 public int getCid() {
201 return mCid;
202 }
203
204 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700205 * @return 8-bit Cell Parameters ID described in TS 25.331, 0..127,
206 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Jack Yu6cd44732017-12-28 14:41:12 -0800207 */
208 public int getCpid() {
209 return mCpid;
210 }
211
Nathan Haroldda59b532019-02-12 10:20:46 -0800212 /**
213 * @return 16-bit UMTS Absolute RF Channel Number,
214 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
215 */
216 public int getUarfcn() {
217 return mUarfcn;
218 }
219
Nathan Harold054b79d2018-03-28 08:39:43 -0700220 /** @hide */
Jack Yu6cd44732017-12-28 14:41:12 -0800221 @Override
Nathan Harold054b79d2018-03-28 08:39:43 -0700222 public int getChannelNumber() {
223 return mUarfcn;
224 }
225
Nathan Haroldac37b632020-01-20 19:04:40 -0800226 /**
227 * @return a list of additional PLMN IDs supported by this cell.
228 */
229 @NonNull
Nathan Harold5522de1a2020-02-13 19:50:51 -0800230 public Set<String> getAdditionalPlmns() {
231 return Collections.unmodifiableSet(mAdditionalPlmns);
Nathan Haroldac37b632020-01-20 19:04:40 -0800232 }
233
234 /**
235 * @return closed subscriber group information about the cell if available, otherwise null.
236 */
237 @Nullable
238 public ClosedSubscriberGroupInfo getClosedSubscriberGroupInfo() {
239 return mCsgInfo;
240 }
241
Nathan Harold7590fee2018-07-19 10:18:23 -0700242 /** @hide */
Meng Wangd75f97d2019-12-06 18:27:38 -0800243 @NonNull
Nathan Harold7590fee2018-07-19 10:18:23 -0700244 @Override
245 public GsmCellLocation asCellLocation() {
246 GsmCellLocation cl = new GsmCellLocation();
Nathan Harolda629ea32018-10-24 11:35:53 -0700247 int lac = mLac != CellInfo.UNAVAILABLE ? mLac : -1;
248 int cid = mCid != CellInfo.UNAVAILABLE ? mCid : -1;
Nathan Harold7590fee2018-07-19 10:18:23 -0700249 cl.setLacAndCid(lac, cid);
250 cl.setPsc(-1); // There is no PSC for TD-SCDMA; not using this for CPI to stem shenanigans
251 return cl;
252 }
253
Jack Yu6cd44732017-12-28 14:41:12 -0800254 @Override
255 public boolean equals(Object other) {
256 if (this == other) {
257 return true;
258 }
259
260 if (!(other instanceof CellIdentityTdscdma)) {
261 return false;
262 }
263
264 CellIdentityTdscdma o = (CellIdentityTdscdma) other;
Nathan Harold054b79d2018-03-28 08:39:43 -0700265 return mLac == o.mLac
Jack Yu6cd44732017-12-28 14:41:12 -0800266 && mCid == o.mCid
Nathan Harolda7b147e2018-03-19 16:59:40 -0700267 && mCpid == o.mCpid
Nathan Harold054b79d2018-03-28 08:39:43 -0700268 && mUarfcn == o.mUarfcn
Nathan Haroldac37b632020-01-20 19:04:40 -0800269 && mAdditionalPlmns.equals(o.mAdditionalPlmns)
270 && Objects.equals(mCsgInfo, o.mCsgInfo)
Cassieae2b65a2018-03-21 16:20:34 -0700271 && super.equals(other);
Jack Yu6cd44732017-12-28 14:41:12 -0800272 }
273
274 @Override
Nathan Harold054b79d2018-03-28 08:39:43 -0700275 public int hashCode() {
Nathan Haroldac37b632020-01-20 19:04:40 -0800276 return Objects.hash(mLac, mCid, mCpid, mUarfcn,
277 mAdditionalPlmns.hashCode(), mCsgInfo, super.hashCode());
Nathan Harold054b79d2018-03-28 08:39:43 -0700278 }
279
280 @Override
Jack Yu6cd44732017-12-28 14:41:12 -0800281 public String toString() {
282 return new StringBuilder(TAG)
283 .append(":{ mMcc=").append(mMccStr)
284 .append(" mMnc=").append(mMncStr)
Nathan Harold054b79d2018-03-28 08:39:43 -0700285 .append(" mAlphaLong=").append(mAlphaLong)
286 .append(" mAlphaShort=").append(mAlphaShort)
Jack Yu6cd44732017-12-28 14:41:12 -0800287 .append(" mLac=").append(mLac)
288 .append(" mCid=").append(mCid)
289 .append(" mCpid=").append(mCpid)
Nathan Harold054b79d2018-03-28 08:39:43 -0700290 .append(" mUarfcn=").append(mUarfcn)
Nathan Haroldac37b632020-01-20 19:04:40 -0800291 .append(" mAdditionalPlmns=").append(mAdditionalPlmns)
292 .append(" mCsgInfo=").append(mCsgInfo)
Jack Yu6cd44732017-12-28 14:41:12 -0800293 .append("}").toString();
294 }
295
296 /** Implement the Parcelable interface */
297 @Override
Nathan Haroldb2bfb292019-03-19 13:20:17 -0700298 public int describeContents() {
299 return 0;
300 }
301
302 /** Implement the Parcelable interface */
303 @Override
Jack Yu6cd44732017-12-28 14:41:12 -0800304 public void writeToParcel(Parcel dest, int flags) {
305 if (DBG) log("writeToParcel(Parcel, int): " + toString());
Nathan Harold65c4b152018-07-30 16:10:50 -0700306 super.writeToParcel(dest, CellInfo.TYPE_TDSCDMA);
Jack Yu6cd44732017-12-28 14:41:12 -0800307 dest.writeInt(mLac);
308 dest.writeInt(mCid);
309 dest.writeInt(mCpid);
Nathan Harold054b79d2018-03-28 08:39:43 -0700310 dest.writeInt(mUarfcn);
Nathan Harold5522de1a2020-02-13 19:50:51 -0800311 dest.writeArraySet(mAdditionalPlmns);
Nathan Haroldac37b632020-01-20 19:04:40 -0800312 dest.writeParcelable(mCsgInfo, flags);
Jack Yu6cd44732017-12-28 14:41:12 -0800313 }
314
315 /** Construct from Parcel, type has already been processed */
316 private CellIdentityTdscdma(Parcel in) {
Nathan Harold65c4b152018-07-30 16:10:50 -0700317 super(TAG, CellInfo.TYPE_TDSCDMA, in);
Jack Yu6cd44732017-12-28 14:41:12 -0800318 mLac = in.readInt();
319 mCid = in.readInt();
320 mCpid = in.readInt();
Nathan Harold054b79d2018-03-28 08:39:43 -0700321 mUarfcn = in.readInt();
Nathan Harold5522de1a2020-02-13 19:50:51 -0800322 mAdditionalPlmns = (ArraySet<String>) in.readArraySet(null);
Nathan Haroldac37b632020-01-20 19:04:40 -0800323 mCsgInfo = in.readParcelable(null);
Nathan Harold3f7dfb82020-04-24 18:34:33 -0700324
325 updateGlobalCellId();
Jack Yu6cd44732017-12-28 14:41:12 -0800326 if (DBG) log(toString());
327 }
328
329 /** Implement the Parcelable interface */
330 @SuppressWarnings("hiding")
Nathan Haroldb2bfb292019-03-19 13:20:17 -0700331 @NonNull
Jack Yu6cd44732017-12-28 14:41:12 -0800332 public static final Creator<CellIdentityTdscdma> CREATOR =
333 new Creator<CellIdentityTdscdma>() {
334 @Override
Nathan Haroldb2bfb292019-03-19 13:20:17 -0700335 public @NonNull CellIdentityTdscdma createFromParcel(Parcel in) {
Jack Yu6cd44732017-12-28 14:41:12 -0800336 in.readInt(); // skip
337 return createFromParcelBody(in);
338 }
339
340 @Override
Nathan Haroldb2bfb292019-03-19 13:20:17 -0700341 public @NonNull CellIdentityTdscdma[] newArray(int size) {
Jack Yu6cd44732017-12-28 14:41:12 -0800342 return new CellIdentityTdscdma[size];
343 }
344 };
345
346 /** @hide */
347 protected static CellIdentityTdscdma createFromParcelBody(Parcel in) {
348 return new CellIdentityTdscdma(in);
349 }
350}