1 /* 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 17 package android.telephony; 18 19 import android.annotation.Nullable; 20 import android.os.Parcel; 21 import android.text.TextUtils; 22 23 import java.util.Objects; 24 25 /** 26 * CellIdentity is to represent a unique LTE cell 27 */ 28 public final class CellIdentityLte extends CellIdentity { 29 private static final String TAG = CellIdentityLte.class.getSimpleName(); 30 private static final boolean DBG = false; 31 32 // 28-bit cell identity 33 private final int mCi; 34 // physical cell id 0..503 35 private final int mPci; 36 // 16-bit tracking area code 37 private final int mTac; 38 // 18-bit Absolute RF Channel Number 39 private final int mEarfcn; 40 // cell bandwidth, in kHz 41 private final int mBandwidth; 42 43 /** 44 * @hide 45 */ 46 public CellIdentityLte() { 47 super(TAG, TYPE_LTE, null, null, null, null); 48 mCi = Integer.MAX_VALUE; 49 mPci = Integer.MAX_VALUE; 50 mTac = Integer.MAX_VALUE; 51 mEarfcn = Integer.MAX_VALUE; 52 mBandwidth = Integer.MAX_VALUE; 53 } 54 55 /** 56 * 57 * @param mcc 3-digit Mobile Country Code, 0..999 58 * @param mnc 2 or 3-digit Mobile Network Code, 0..999 59 * @param ci 28-bit Cell Identity 60 * @param pci Physical Cell Id 0..503 61 * @param tac 16-bit Tracking Area Code 62 * 63 * @hide 64 */ 65 public CellIdentityLte(int mcc, int mnc, int ci, int pci, int tac) { 66 this(ci, pci, tac, Integer.MAX_VALUE, Integer.MAX_VALUE, String.valueOf(mcc), 67 String.valueOf(mnc), null, null); 68 } 69 70 /** 71 * 72 * @param mcc 3-digit Mobile Country Code, 0..999 73 * @param mnc 2 or 3-digit Mobile Network Code, 0..999 74 * @param ci 28-bit Cell Identity 75 * @param pci Physical Cell Id 0..503 76 * @param tac 16-bit Tracking Area Code 77 * @param earfcn 18-bit LTE Absolute RF Channel Number 78 * 79 * @hide 80 */ 81 public CellIdentityLte(int mcc, int mnc, int ci, int pci, int tac, int earfcn) { 82 this(ci, pci, tac, earfcn, Integer.MAX_VALUE, String.valueOf(mcc), String.valueOf(mnc), 83 null, null); 84 } 85 86 /** 87 * 88 * @param ci 28-bit Cell Identity 89 * @param pci Physical Cell Id 0..503 90 * @param tac 16-bit Tracking Area Code 91 * @param earfcn 18-bit LTE Absolute RF Channel Number 92 * @param bandwidth cell bandwidth in kHz 93 * @param mccStr 3-digit Mobile Country Code in string format 94 * @param mncStr 2 or 3-digit Mobile Network Code in string format 95 * @param alphal long alpha Operator Name String or Enhanced Operator Name String 96 * @param alphas short alpha Operator Name String or Enhanced Operator Name String 97 * 98 * @hide 99 */ 100 public CellIdentityLte(int ci, int pci, int tac, int earfcn, int bandwidth, String mccStr, 101 String mncStr, String alphal, String alphas) { 102 super(TAG, TYPE_LTE, mccStr, mncStr, alphal, alphas); 103 mCi = ci; 104 mPci = pci; 105 mTac = tac; 106 mEarfcn = earfcn; 107 mBandwidth = bandwidth; 108 } 109 110 private CellIdentityLte(CellIdentityLte cid) { 111 this(cid.mCi, cid.mPci, cid.mTac, cid.mEarfcn, cid.mBandwidth, cid.mMccStr, 112 cid.mMncStr, cid.mAlphaLong, cid.mAlphaShort); 113 } 114 115 CellIdentityLte copy() { 116 return new CellIdentityLte(this); 117 } 118 119 /** 120 * @return 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown 121 * @deprecated Use {@link #getMccString} instead. 122 */ 123 @Deprecated 124 public int getMcc() { 125 return (mMccStr != null) ? Integer.valueOf(mMccStr) : Integer.MAX_VALUE; 126 } 127 128 /** 129 * @return 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown 130 * @deprecated Use {@link #getMncString} instead. 131 */ 132 @Deprecated 133 public int getMnc() { 134 return (mMncStr != null) ? Integer.valueOf(mMncStr) : Integer.MAX_VALUE; 135 } 136 137 /** 138 * @return 28-bit Cell Identity, Integer.MAX_VALUE if unknown 139 */ 140 public int getCi() { 141 return mCi; 142 } 143 144 /** 145 * @return Physical Cell Id 0..503, Integer.MAX_VALUE if unknown 146 */ 147 public int getPci() { 148 return mPci; 149 } 150 151 /** 152 * @return 16-bit Tracking Area Code, Integer.MAX_VALUE if unknown 153 */ 154 public int getTac() { 155 return mTac; 156 } 157 158 /** 159 * @return 18-bit Absolute RF Channel Number, Integer.MAX_VALUE if unknown 160 */ 161 public int getEarfcn() { 162 return mEarfcn; 163 } 164 165 /** 166 * @return Cell bandwidth in kHz, Integer.MAX_VALUE if unknown 167 */ 168 public int getBandwidth() { 169 return mBandwidth; 170 } 171 172 /** 173 * @return Mobile Country Code in string format, null if unknown 174 */ 175 public String getMccString() { 176 return mMccStr; 177 } 178 179 /** 180 * @return Mobile Network Code in string format, null if unknown 181 */ 182 public String getMncString() { 183 return mMncStr; 184 } 185 186 /** 187 * @return a 5 or 6 character string (MCC+MNC), null if any field is unknown 188 */ 189 public String getMobileNetworkOperator() { 190 return (mMccStr == null || mMncStr == null) ? null : mMccStr + mMncStr; 191 } 192 193 /** @hide */ 194 @Override 195 public int getChannelNumber() { 196 return mEarfcn; 197 } 198 199 @Override 200 public int hashCode() { 201 return Objects.hash(mCi, mPci, mTac, super.hashCode()); 202 } 203 204 @Override 205 public boolean equals(Object other) { 206 if (this == other) { 207 return true; 208 } 209 210 if (!(other instanceof CellIdentityLte)) { 211 return false; 212 } 213 214 CellIdentityLte o = (CellIdentityLte) other; 215 return mCi == o.mCi 216 && mPci == o.mPci 217 && mTac == o.mTac 218 && mEarfcn == o.mEarfcn 219 && mBandwidth == o.mBandwidth 220 && TextUtils.equals(mMccStr, o.mMccStr) 221 && TextUtils.equals(mMncStr, o.mMncStr) 222 && super.equals(other); 223 } 224 225 @Override 226 public String toString() { 227 return new StringBuilder(TAG) 228 .append(":{ mCi=").append(mCi) 229 .append(" mPci=").append(mPci) 230 .append(" mTac=").append(mTac) 231 .append(" mEarfcn=").append(mEarfcn) 232 .append(" mBandwidth=").append(mBandwidth) 233 .append(" mMcc=").append(mMccStr) 234 .append(" mMnc=").append(mMncStr) 235 .append(" mAlphaLong=").append(mAlphaLong) 236 .append(" mAlphaShort=").append(mAlphaShort) 237 .append("}").toString(); 238 } 239 240 /** Implement the Parcelable interface */ 241 @Override 242 public void writeToParcel(Parcel dest, int flags) { 243 if (DBG) log("writeToParcel(Parcel, int): " + toString()); 244 super.writeToParcel(dest, TYPE_LTE); 245 dest.writeInt(mCi); 246 dest.writeInt(mPci); 247 dest.writeInt(mTac); 248 dest.writeInt(mEarfcn); 249 dest.writeInt(mBandwidth); 250 } 251 252 /** Construct from Parcel, type has already been processed */ 253 private CellIdentityLte(Parcel in) { 254 super(TAG, TYPE_LTE, in); 255 mCi = in.readInt(); 256 mPci = in.readInt(); 257 mTac = in.readInt(); 258 mEarfcn = in.readInt(); 259 mBandwidth = in.readInt(); 260 261 if (DBG) log(toString()); 262 } 263 264 /** Implement the Parcelable interface */ 265 @SuppressWarnings("hiding") 266 public static final Creator<CellIdentityLte> CREATOR = 267 new Creator<CellIdentityLte>() { 268 @Override 269 public CellIdentityLte createFromParcel(Parcel in) { 270 in.readInt(); // skip; 271 return createFromParcelBody(in); 272 } 273 274 @Override 275 public CellIdentityLte[] newArray(int size) { 276 return new CellIdentityLte[size]; 277 } 278 }; 279 280 /** @hide */ 281 protected static CellIdentityLte createFromParcelBody(Parcel in) { 282 return new CellIdentityLte(in); 283 } 284 } 285