Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.telephony; |
| 18 | |
Nathan Harold | 13d6b11 | 2018-12-18 13:40:08 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Mathew Inwood | a838206 | 2018-08-16 17:01:12 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
Nathan Harold | 7590fee | 2018-07-19 10:18:23 -0700 | [diff] [blame] | 22 | import android.telephony.gsm.GsmCellLocation; |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 23 | import android.text.TextUtils; |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 24 | |
Brian Williammee | 7d1d2e3 | 2014-08-29 17:31:22 -0700 | [diff] [blame] | 25 | import java.util.Objects; |
| 26 | |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 27 | /** |
| 28 | * CellIdentity to represent a unique UMTS cell |
| 29 | */ |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 30 | public final class CellIdentityWcdma extends CellIdentity { |
| 31 | private static final String TAG = CellIdentityWcdma.class.getSimpleName(); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 32 | private static final boolean DBG = false; |
| 33 | |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 34 | // 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 Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 40 | // 16-bit UMTS Absolute RF Channel Number described in TS 25.101 sec. 5.4.4 |
Mathew Inwood | a838206 | 2018-08-16 17:01:12 +0100 | [diff] [blame] | 41 | @UnsupportedAppUsage |
Sanket Padawe | 0c86efd | 2016-01-26 18:42:47 -0800 | [diff] [blame] | 42 | private final int mUarfcn; |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * @hide |
| 46 | */ |
| 47 | public CellIdentityWcdma() { |
Nathan Harold | 65c4b15 | 2018-07-30 16:10:50 -0700 | [diff] [blame] | 48 | super(TAG, CellInfo.TYPE_WCDMA, null, null, null, null); |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 49 | mLac = CellInfo.UNAVAILABLE; |
| 50 | mCid = CellInfo.UNAVAILABLE; |
| 51 | mPsc = CellInfo.UNAVAILABLE; |
| 52 | mUarfcn = CellInfo.UNAVAILABLE; |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 53 | } |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 54 | |
| 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 Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 60 | * @param uarfcn 16-bit UMTS Absolute RF Channel Number described in TS 25.101 sec. 5.4.3 |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 61 | * @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 | * |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 66 | * @hide |
| 67 | */ |
| 68 | public CellIdentityWcdma (int lac, int cid, int psc, int uarfcn, |
| 69 | String mccStr, String mncStr, String alphal, String alphas) { |
Nathan Harold | 65c4b15 | 2018-07-30 16:10:50 -0700 | [diff] [blame] | 70 | super(TAG, CellInfo.TYPE_WCDMA, mccStr, mncStr, alphal, alphas); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 71 | mLac = lac; |
| 72 | mCid = cid; |
| 73 | mPsc = psc; |
Sanket Padawe | 0c86efd | 2016-01-26 18:42:47 -0800 | [diff] [blame] | 74 | mUarfcn = uarfcn; |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 75 | } |
Cassie Han | 2200da1 | 2017-11-15 17:27:31 +0000 | [diff] [blame] | 76 | |
Nathan Harold | 7ce5baf | 2018-12-10 13:39:40 -0800 | [diff] [blame] | 77 | /** @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 Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 89 | private CellIdentityWcdma(CellIdentityWcdma cid) { |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 90 | this(cid.mLac, cid.mCid, cid.mPsc, cid.mUarfcn, cid.mMccStr, |
| 91 | cid.mMncStr, cid.mAlphaLong, cid.mAlphaShort); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | CellIdentityWcdma copy() { |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 95 | return new CellIdentityWcdma(this); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 99 | * @return 3-digit Mobile Country Code, 0..999, |
| 100 | * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable. |
Cassie | d062c322 | 2018-02-28 11:45:29 -0800 | [diff] [blame] | 101 | * @deprecated Use {@link #getMccString} instead. |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 102 | */ |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 103 | @Deprecated |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 104 | public int getMcc() { |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 105 | return (mMccStr != null) ? Integer.valueOf(mMccStr) : CellInfo.UNAVAILABLE; |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 109 | * @return 2 or 3-digit Mobile Network Code, 0..999, |
| 110 | * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable. |
Cassie | d062c322 | 2018-02-28 11:45:29 -0800 | [diff] [blame] | 111 | * @deprecated Use {@link #getMncString} instead. |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 112 | */ |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 113 | @Deprecated |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 114 | public int getMnc() { |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 115 | return (mMncStr != null) ? Integer.valueOf(mMncStr) : CellInfo.UNAVAILABLE; |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /** |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 119 | * @return 16-bit Location Area Code, 0..65535, |
| 120 | * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable. |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 121 | */ |
| 122 | public int getLac() { |
| 123 | return mLac; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @return CID |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 128 | * 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, |
| 129 | * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable. |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 130 | */ |
| 131 | public int getCid() { |
| 132 | return mCid; |
| 133 | } |
| 134 | |
| 135 | /** |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 136 | * @return 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511, |
| 137 | * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable. |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 138 | */ |
| 139 | public int getPsc() { |
| 140 | return mPsc; |
| 141 | } |
| 142 | |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 143 | /** |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 144 | * @return Mobile Country Code in string version, null if unavailable. |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 145 | */ |
Cassie | d062c322 | 2018-02-28 11:45:29 -0800 | [diff] [blame] | 146 | public String getMccString() { |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 147 | return mMccStr; |
| 148 | } |
| 149 | |
| 150 | /** |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 151 | * @return Mobile Network Code in string version, null if unavailable. |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 152 | */ |
Cassie | d062c322 | 2018-02-28 11:45:29 -0800 | [diff] [blame] | 153 | public String getMncString() { |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 154 | return mMncStr; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * @return a 5 or 6 character string (MCC+MNC), null if any field is unknown |
| 159 | */ |
Nathan Harold | 13d6b11 | 2018-12-18 13:40:08 -0800 | [diff] [blame] | 160 | @Nullable |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 161 | public String getMobileNetworkOperator() { |
Cassie | b799fcd | 2017-11-30 15:54:51 -0800 | [diff] [blame] | 162 | return (mMccStr == null || mMncStr == null) ? null : mMccStr + mMncStr; |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 165 | @Override |
| 166 | public int hashCode() { |
Cassie | 21ed3c5 | 2018-03-21 16:20:34 -0700 | [diff] [blame] | 167 | return Objects.hash(mLac, mCid, mPsc, super.hashCode()); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Sanket Padawe | 0c86efd | 2016-01-26 18:42:47 -0800 | [diff] [blame] | 170 | /** |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 171 | * @return 16-bit UMTS Absolute RF Channel Number, |
| 172 | * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable. |
Sanket Padawe | 0c86efd | 2016-01-26 18:42:47 -0800 | [diff] [blame] | 173 | */ |
| 174 | public int getUarfcn() { |
| 175 | return mUarfcn; |
| 176 | } |
| 177 | |
Eric Schwarzenbach | 2c1a177 | 2018-03-02 17:47:13 -0800 | [diff] [blame] | 178 | /** @hide */ |
| 179 | @Override |
| 180 | public int getChannelNumber() { |
| 181 | return mUarfcn; |
| 182 | } |
| 183 | |
Nathan Harold | 7590fee | 2018-07-19 10:18:23 -0700 | [diff] [blame] | 184 | /** @hide */ |
| 185 | @Override |
| 186 | public GsmCellLocation asCellLocation() { |
| 187 | GsmCellLocation cl = new GsmCellLocation(); |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 188 | int lac = mLac != CellInfo.UNAVAILABLE ? mLac : -1; |
| 189 | int cid = mCid != CellInfo.UNAVAILABLE ? mCid : -1; |
| 190 | int psc = mPsc != CellInfo.UNAVAILABLE ? mPsc : -1; |
Nathan Harold | 7590fee | 2018-07-19 10:18:23 -0700 | [diff] [blame] | 191 | cl.setLacAndCid(lac, cid); |
| 192 | cl.setPsc(psc); |
| 193 | |
| 194 | return cl; |
| 195 | } |
| 196 | |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 197 | @Override |
| 198 | public boolean equals(Object other) { |
Brian Williammee | 7d1d2e3 | 2014-08-29 17:31:22 -0700 | [diff] [blame] | 199 | if (this == other) { |
| 200 | return true; |
| 201 | } |
| 202 | |
| 203 | if (!(other instanceof CellIdentityWcdma)) { |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 204 | return false; |
| 205 | } |
Brian Williammee | 7d1d2e3 | 2014-08-29 17:31:22 -0700 | [diff] [blame] | 206 | |
| 207 | CellIdentityWcdma o = (CellIdentityWcdma) other; |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 208 | 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) |
Cassie | 21ed3c5 | 2018-03-21 16:20:34 -0700 | [diff] [blame] | 214 | && super.equals(other); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public String toString() { |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 219 | 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 Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 229 | } |
| 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 Harold | 65c4b15 | 2018-07-30 16:10:50 -0700 | [diff] [blame] | 235 | super.writeToParcel(dest, CellInfo.TYPE_WCDMA); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 236 | dest.writeInt(mLac); |
| 237 | dest.writeInt(mCid); |
| 238 | dest.writeInt(mPsc); |
Sanket Padawe | 0c86efd | 2016-01-26 18:42:47 -0800 | [diff] [blame] | 239 | dest.writeInt(mUarfcn); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /** Construct from Parcel, type has already been processed */ |
| 243 | private CellIdentityWcdma(Parcel in) { |
Nathan Harold | 65c4b15 | 2018-07-30 16:10:50 -0700 | [diff] [blame] | 244 | super(TAG, CellInfo.TYPE_WCDMA, in); |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 245 | mLac = in.readInt(); |
| 246 | mCid = in.readInt(); |
| 247 | mPsc = in.readInt(); |
| 248 | mUarfcn = in.readInt(); |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 249 | if (DBG) log(toString()); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /** Implement the Parcelable interface */ |
| 253 | @SuppressWarnings("hiding") |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 254 | public static final @android.annotation.NonNull Creator<CellIdentityWcdma> CREATOR = |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 255 | new Creator<CellIdentityWcdma>() { |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 256 | @Override |
| 257 | public CellIdentityWcdma createFromParcel(Parcel in) { |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 258 | in.readInt(); // skip |
| 259 | return createFromParcelBody(in); |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 260 | } |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 261 | |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 262 | @Override |
| 263 | public CellIdentityWcdma[] newArray(int size) { |
| 264 | return new CellIdentityWcdma[size]; |
| 265 | } |
| 266 | }; |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 267 | |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 268 | /** @hide */ |
| 269 | protected static CellIdentityWcdma createFromParcelBody(Parcel in) { |
| 270 | return new CellIdentityWcdma(in); |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 271 | } |
Nathan Harold | a629ea3 | 2018-10-24 11:35:53 -0700 | [diff] [blame] | 272 | } |