blob: b1944af18abc5c01770cd7ccc92d3d81c2d0063e [file] [log] [blame]
Wink Savillee3a9cbc2013-04-17 16:40:17 -07001/*
2 * Copyright (C) 2013 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 Harold13d6b112018-12-18 13:40:08 -080019import android.annotation.Nullable;
Mathew Inwooda8382062018-08-16 17:01:12 +010020import android.annotation.UnsupportedAppUsage;
Wink Savillee3a9cbc2013-04-17 16:40:17 -070021import android.os.Parcel;
Nathan Harold7590fee2018-07-19 10:18:23 -070022import android.telephony.gsm.GsmCellLocation;
Cassie933b78d2017-09-20 14:02:13 -070023import android.text.TextUtils;
Wink Savillee3a9cbc2013-04-17 16:40:17 -070024
Brian Williammee7d1d2e32014-08-29 17:31:22 -070025import java.util.Objects;
26
Wink Savillee3a9cbc2013-04-17 16:40:17 -070027/**
28 * CellIdentity to represent a unique UMTS cell
29 */
Jack Yu6cd44732017-12-28 14:41:12 -080030public final class CellIdentityWcdma extends CellIdentity {
31 private static final String TAG = CellIdentityWcdma.class.getSimpleName();
Wink Savillee3a9cbc2013-04-17 16:40:17 -070032 private static final boolean DBG = false;
33
Wink Savillee3a9cbc2013-04-17 16:40:17 -070034 // 16-bit Location Area Code, 0..65535
35 private final int mLac;
36 // 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455
37 private final int mCid;
38 // 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511
39 private final int mPsc;
Nathan Harold054b79d2018-03-28 08:39:43 -070040 // 16-bit UMTS Absolute RF Channel Number described in TS 25.101 sec. 5.4.4
Mathew Inwooda8382062018-08-16 17:01:12 +010041 @UnsupportedAppUsage
Sanket Padawe0c86efd2016-01-26 18:42:47 -080042 private final int mUarfcn;
Wink Savillee3a9cbc2013-04-17 16:40:17 -070043
44 /**
45 * @hide
46 */
47 public CellIdentityWcdma() {
Nathan Harold65c4b152018-07-30 16:10:50 -070048 super(TAG, CellInfo.TYPE_WCDMA, null, null, null, null);
Nathan Harolda629ea32018-10-24 11:35:53 -070049 mLac = CellInfo.UNAVAILABLE;
50 mCid = CellInfo.UNAVAILABLE;
51 mPsc = CellInfo.UNAVAILABLE;
52 mUarfcn = CellInfo.UNAVAILABLE;
Wink Savillee3a9cbc2013-04-17 16:40:17 -070053 }
Cassie933b78d2017-09-20 14:02:13 -070054
55 /**
56 * public constructor
57 * @param lac 16-bit Location Area Code, 0..65535
58 * @param cid 28-bit UMTS Cell Identity
59 * @param psc 9-bit UMTS Primary Scrambling Code
Nathan Harold054b79d2018-03-28 08:39:43 -070060 * @param uarfcn 16-bit UMTS Absolute RF Channel Number described in TS 25.101 sec. 5.4.3
Cassie933b78d2017-09-20 14:02:13 -070061 * @param mccStr 3-digit Mobile Country Code in string format
62 * @param mncStr 2 or 3-digit Mobile Network Code in string format
63 * @param alphal long alpha Operator Name String or Enhanced Operator Name String
64 * @param alphas short alpha Operator Name String or Enhanced Operator Name String
65 *
Cassie933b78d2017-09-20 14:02:13 -070066 * @hide
67 */
68 public CellIdentityWcdma (int lac, int cid, int psc, int uarfcn,
69 String mccStr, String mncStr, String alphal, String alphas) {
Nathan Harold65c4b152018-07-30 16:10:50 -070070 super(TAG, CellInfo.TYPE_WCDMA, mccStr, mncStr, alphal, alphas);
Wink Savillee3a9cbc2013-04-17 16:40:17 -070071 mLac = lac;
72 mCid = cid;
73 mPsc = psc;
Sanket Padawe0c86efd2016-01-26 18:42:47 -080074 mUarfcn = uarfcn;
Wink Savillee3a9cbc2013-04-17 16:40:17 -070075 }
Cassie Han2200da12017-11-15 17:27:31 +000076
Nathan Harold7ce5baf2018-12-10 13:39:40 -080077 /** @hide */
78 public CellIdentityWcdma(android.hardware.radio.V1_0.CellIdentityWcdma cid) {
79 this(cid.lac, cid.cid, cid.psc, cid.uarfcn, cid.mcc, cid.mnc, "", "");
80 }
81
82 /** @hide */
83 public CellIdentityWcdma(android.hardware.radio.V1_2.CellIdentityWcdma cid) {
84 this(cid.base.lac, cid.base.cid, cid.base.psc, cid.base.uarfcn,
85 cid.base.mcc, cid.base.mnc, cid.operatorNames.alphaLong,
86 cid.operatorNames.alphaShort);
87 }
88
Wink Savillee3a9cbc2013-04-17 16:40:17 -070089 private CellIdentityWcdma(CellIdentityWcdma cid) {
Cassie933b78d2017-09-20 14:02:13 -070090 this(cid.mLac, cid.mCid, cid.mPsc, cid.mUarfcn, cid.mMccStr,
91 cid.mMncStr, cid.mAlphaLong, cid.mAlphaShort);
Wink Savillee3a9cbc2013-04-17 16:40:17 -070092 }
93
94 CellIdentityWcdma copy() {
Cassie933b78d2017-09-20 14:02:13 -070095 return new CellIdentityWcdma(this);
Wink Savillee3a9cbc2013-04-17 16:40:17 -070096 }
97
98 /**
Nathan Harolda629ea32018-10-24 11:35:53 -070099 * @return 3-digit Mobile Country Code, 0..999,
100 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Cassied062c3222018-02-28 11:45:29 -0800101 * @deprecated Use {@link #getMccString} instead.
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700102 */
Cassie933b78d2017-09-20 14:02:13 -0700103 @Deprecated
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700104 public int getMcc() {
Nathan Harolda629ea32018-10-24 11:35:53 -0700105 return (mMccStr != null) ? Integer.valueOf(mMccStr) : CellInfo.UNAVAILABLE;
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700106 }
107
108 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700109 * @return 2 or 3-digit Mobile Network Code, 0..999,
110 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Cassied062c3222018-02-28 11:45:29 -0800111 * @deprecated Use {@link #getMncString} instead.
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700112 */
Cassie933b78d2017-09-20 14:02:13 -0700113 @Deprecated
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700114 public int getMnc() {
Nathan Harolda629ea32018-10-24 11:35:53 -0700115 return (mMncStr != null) ? Integer.valueOf(mMncStr) : CellInfo.UNAVAILABLE;
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700116 }
117
118 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700119 * @return 16-bit Location Area Code, 0..65535,
120 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700121 */
122 public int getLac() {
123 return mLac;
124 }
125
126 /**
127 * @return CID
Nathan Harolda629ea32018-10-24 11:35:53 -0700128 * 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455,
129 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700130 */
131 public int getCid() {
132 return mCid;
133 }
134
135 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700136 * @return 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511,
137 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700138 */
139 public int getPsc() {
140 return mPsc;
141 }
142
Cassie933b78d2017-09-20 14:02:13 -0700143 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700144 * @return Mobile Country Code in string version, null if unavailable.
Cassie933b78d2017-09-20 14:02:13 -0700145 */
Cassied062c3222018-02-28 11:45:29 -0800146 public String getMccString() {
Cassie933b78d2017-09-20 14:02:13 -0700147 return mMccStr;
148 }
149
150 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700151 * @return Mobile Network Code in string version, null if unavailable.
Cassie933b78d2017-09-20 14:02:13 -0700152 */
Cassied062c3222018-02-28 11:45:29 -0800153 public String getMncString() {
Cassie933b78d2017-09-20 14:02:13 -0700154 return mMncStr;
155 }
156
157 /**
158 * @return a 5 or 6 character string (MCC+MNC), null if any field is unknown
159 */
Nathan Harold13d6b112018-12-18 13:40:08 -0800160 @Nullable
Cassie933b78d2017-09-20 14:02:13 -0700161 public String getMobileNetworkOperator() {
Cassieb799fcd2017-11-30 15:54:51 -0800162 return (mMccStr == null || mMncStr == null) ? null : mMccStr + mMncStr;
Cassie933b78d2017-09-20 14:02:13 -0700163 }
164
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700165 @Override
166 public int hashCode() {
Cassie21ed3c52018-03-21 16:20:34 -0700167 return Objects.hash(mLac, mCid, mPsc, super.hashCode());
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700168 }
169
Sanket Padawe0c86efd2016-01-26 18:42:47 -0800170 /**
Nathan Harolda629ea32018-10-24 11:35:53 -0700171 * @return 16-bit UMTS Absolute RF Channel Number,
172 * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
Sanket Padawe0c86efd2016-01-26 18:42:47 -0800173 */
174 public int getUarfcn() {
175 return mUarfcn;
176 }
177
Eric Schwarzenbach2c1a1772018-03-02 17:47:13 -0800178 /** @hide */
179 @Override
180 public int getChannelNumber() {
181 return mUarfcn;
182 }
183
Nathan Harold7590fee2018-07-19 10:18:23 -0700184 /** @hide */
185 @Override
186 public GsmCellLocation asCellLocation() {
187 GsmCellLocation cl = new GsmCellLocation();
Nathan Harolda629ea32018-10-24 11:35:53 -0700188 int lac = mLac != CellInfo.UNAVAILABLE ? mLac : -1;
189 int cid = mCid != CellInfo.UNAVAILABLE ? mCid : -1;
190 int psc = mPsc != CellInfo.UNAVAILABLE ? mPsc : -1;
Nathan Harold7590fee2018-07-19 10:18:23 -0700191 cl.setLacAndCid(lac, cid);
192 cl.setPsc(psc);
193
194 return cl;
195 }
196
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700197 @Override
198 public boolean equals(Object other) {
Brian Williammee7d1d2e32014-08-29 17:31:22 -0700199 if (this == other) {
200 return true;
201 }
202
203 if (!(other instanceof CellIdentityWcdma)) {
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700204 return false;
205 }
Brian Williammee7d1d2e32014-08-29 17:31:22 -0700206
207 CellIdentityWcdma o = (CellIdentityWcdma) other;
Jack Yu6cd44732017-12-28 14:41:12 -0800208 return mLac == o.mLac
209 && mCid == o.mCid
210 && mPsc == o.mPsc
211 && mUarfcn == o.mUarfcn
212 && TextUtils.equals(mMccStr, o.mMccStr)
213 && TextUtils.equals(mMncStr, o.mMncStr)
Cassie21ed3c52018-03-21 16:20:34 -0700214 && super.equals(other);
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700215 }
216
217 @Override
218 public String toString() {
Jack Yu6cd44732017-12-28 14:41:12 -0800219 return new StringBuilder(TAG)
220 .append(":{ mLac=").append(mLac)
221 .append(" mCid=").append(mCid)
222 .append(" mPsc=").append(mPsc)
223 .append(" mUarfcn=").append(mUarfcn)
224 .append(" mMcc=").append(mMccStr)
225 .append(" mMnc=").append(mMncStr)
226 .append(" mAlphaLong=").append(mAlphaLong)
227 .append(" mAlphaShort=").append(mAlphaShort)
228 .append("}").toString();
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700229 }
230
231 /** Implement the Parcelable interface */
232 @Override
233 public void writeToParcel(Parcel dest, int flags) {
234 if (DBG) log("writeToParcel(Parcel, int): " + toString());
Nathan Harold65c4b152018-07-30 16:10:50 -0700235 super.writeToParcel(dest, CellInfo.TYPE_WCDMA);
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700236 dest.writeInt(mLac);
237 dest.writeInt(mCid);
238 dest.writeInt(mPsc);
Sanket Padawe0c86efd2016-01-26 18:42:47 -0800239 dest.writeInt(mUarfcn);
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700240 }
241
242 /** Construct from Parcel, type has already been processed */
243 private CellIdentityWcdma(Parcel in) {
Nathan Harold65c4b152018-07-30 16:10:50 -0700244 super(TAG, CellInfo.TYPE_WCDMA, in);
Jack Yu6cd44732017-12-28 14:41:12 -0800245 mLac = in.readInt();
246 mCid = in.readInt();
247 mPsc = in.readInt();
248 mUarfcn = in.readInt();
Jack Yu6cd44732017-12-28 14:41:12 -0800249 if (DBG) log(toString());
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700250 }
251
252 /** Implement the Parcelable interface */
253 @SuppressWarnings("hiding")
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700254 public static final @android.annotation.NonNull Creator<CellIdentityWcdma> CREATOR =
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700255 new Creator<CellIdentityWcdma>() {
Cassie933b78d2017-09-20 14:02:13 -0700256 @Override
257 public CellIdentityWcdma createFromParcel(Parcel in) {
Jack Yu6cd44732017-12-28 14:41:12 -0800258 in.readInt(); // skip
259 return createFromParcelBody(in);
Cassie933b78d2017-09-20 14:02:13 -0700260 }
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700261
Cassie933b78d2017-09-20 14:02:13 -0700262 @Override
263 public CellIdentityWcdma[] newArray(int size) {
264 return new CellIdentityWcdma[size];
265 }
266 };
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700267
Jack Yu6cd44732017-12-28 14:41:12 -0800268 /** @hide */
269 protected static CellIdentityWcdma createFromParcelBody(Parcel in) {
270 return new CellIdentityWcdma(in);
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700271 }
Nathan Harolda629ea32018-10-24 11:35:53 -0700272}