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 to represent a unique GSM cell 27 */ 28 public final class CellIdentityGsm extends CellIdentity { 29 private static final String TAG = CellIdentityGsm.class.getSimpleName(); 30 private static final boolean DBG = false; 31 32 // 16-bit Location Area Code, 0..65535 33 private final int mLac; 34 // 16-bit GSM Cell Identity described in TS 27.007, 0..65535 35 private final int mCid; 36 // 16-bit GSM Absolute RF Channel Number 37 private final int mArfcn; 38 // 6-bit Base Station Identity Code 39 private final int mBsic; 40 41 /** 42 * @hide 43 */ 44 public CellIdentityGsm() { 45 super(TAG, TYPE_GSM, null, null, null, null); 46 mLac = Integer.MAX_VALUE; 47 mCid = Integer.MAX_VALUE; 48 mArfcn = Integer.MAX_VALUE; 49 mBsic = Integer.MAX_VALUE; 50 } 51 /** 52 * public constructor 53 * @param mcc 3-digit Mobile Country Code, 0..999 54 * @param mnc 2 or 3-digit Mobile Network Code, 0..999 55 * @param lac 16-bit Location Area Code, 0..65535 56 * @param cid 16-bit GSM Cell Identity or 28-bit UMTS Cell Identity 57 * 58 * @hide 59 */ 60 public CellIdentityGsm(int mcc, int mnc, int lac, int cid) { 61 this(lac, cid, Integer.MAX_VALUE, Integer.MAX_VALUE, 62 String.valueOf(mcc), String.valueOf(mnc), null, null); 63 } 64 65 /** 66 * public constructor 67 * @param mcc 3-digit Mobile Country Code, 0..999 68 * @param mnc 2 or 3-digit Mobile Network Code, 0..999 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 * 74 * @hide 75 */ 76 public CellIdentityGsm(int mcc, int mnc, int lac, int cid, int arfcn, int bsic) { 77 this(lac, cid, arfcn, bsic, String.valueOf(mcc), String.valueOf(mnc), null, null); 78 } 79 80 /** 81 * public constructor 82 * @param lac 16-bit Location Area Code, 0..65535 83 * @param cid 16-bit GSM Cell Identity or 28-bit UMTS Cell Identity 84 * @param arfcn 16-bit GSM Absolute RF Channel Number 85 * @param bsic 6-bit Base Station Identity Code 86 * @param mccStr 3-digit Mobile Country Code in string format 87 * @param mncStr 2 or 3-digit Mobile Network Code in string format 88 * @param alphal long alpha Operator Name String or Enhanced Operator Name String 89 * @param alphas short alpha Operator Name String or Enhanced Operator Name String 90 * 91 * @hide 92 */ 93 public CellIdentityGsm(int lac, int cid, int arfcn, int bsic, String mccStr, 94 String mncStr, String alphal, String alphas) { 95 super(TAG, TYPE_GSM, mccStr, mncStr, alphal, alphas); 96 mLac = lac; 97 mCid = cid; 98 mArfcn = arfcn; 99 // In RIL BSIC is a UINT8, so 0xFF is the 'INVALID' designator 100 // for inbound parcels 101 mBsic = (bsic == 0xFF) ? Integer.MAX_VALUE : bsic; 102 } 103 104 private CellIdentityGsm(CellIdentityGsm cid) { 105 this(cid.mLac, cid.mCid, cid.mArfcn, cid.mBsic, cid.mMccStr, 106 cid.mMncStr, cid.mAlphaLong, cid.mAlphaShort); 107 } 108 109 CellIdentityGsm copy() { 110 return new CellIdentityGsm(this); 111 } 112 113 /** 114 * @return 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown 115 * @deprecated Use {@link #getMccString} instead. 116 */ 117 @Deprecated 118 public int getMcc() { 119 return (mMccStr != null) ? Integer.valueOf(mMccStr) : Integer.MAX_VALUE; 120 } 121 122 /** 123 * @return 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown 124 * @deprecated Use {@link #getMncString} instead. 125 */ 126 @Deprecated 127 public int getMnc() { 128 return (mMncStr != null) ? Integer.valueOf(mMncStr) : Integer.MAX_VALUE; 129 } 130 131 /** 132 * @return 16-bit Location Area Code, 0..65535, Integer.MAX_VALUE if unknown 133 */ 134 public int getLac() { 135 return mLac; 136 } 137 138 /** 139 * @return CID 140 * Either 16-bit GSM Cell Identity described 141 * in TS 27.007, 0..65535, Integer.MAX_VALUE if unknown 142 */ 143 public int getCid() { 144 return mCid; 145 } 146 147 /** 148 * @return 16-bit GSM Absolute RF Channel Number, Integer.MAX_VALUE if unknown 149 */ 150 public int getArfcn() { 151 return mArfcn; 152 } 153 154 /** 155 * @return 6-bit Base Station Identity Code, Integer.MAX_VALUE if unknown 156 */ 157 public int getBsic() { 158 return mBsic; 159 } 160 161 /** 162 * @return a 5 or 6 character string (MCC+MNC), null if any field is unknown 163 */ 164 public String getMobileNetworkOperator() { 165 return (mMccStr == null || mMncStr == null) ? null : mMccStr + mMncStr; 166 } 167 168 /** 169 * @return Mobile Country Code in string format, null if unknown 170 */ 171 public String getMccString() { 172 return mMccStr; 173 } 174 175 /** 176 * @return Mobile Network Code in string format, null if unknown 177 */ 178 public String getMncString() { 179 return mMncStr; 180 } 181 182 /** @hide */ 183 @Override 184 public int getChannelNumber() { 185 return mArfcn; 186 } 187 188 /** 189 * @deprecated Primary Scrambling Code is not applicable to GSM. 190 * @return Integer.MAX_VALUE, undefined for GSM 191 */ 192 @Deprecated 193 public int getPsc() { 194 return Integer.MAX_VALUE; 195 } 196 197 @Override 198 public int hashCode() { 199 return Objects.hash(mLac, mCid, super.hashCode()); 200 } 201 202 @Override 203 public boolean equals(Object other) { 204 if (this == other) { 205 return true; 206 } 207 208 if (!(other instanceof CellIdentityGsm)) { 209 return false; 210 } 211 212 CellIdentityGsm o = (CellIdentityGsm) other; 213 return mLac == o.mLac 214 && mCid == o.mCid 215 && mArfcn == o.mArfcn 216 && mBsic == o.mBsic 217 && TextUtils.equals(mMccStr, o.mMccStr) 218 && TextUtils.equals(mMncStr, o.mMncStr) 219 && super.equals(other); 220 } 221 222 @Override 223 public String toString() { 224 return new StringBuilder(TAG) 225 .append(":{ mLac=").append(mLac) 226 .append(" mCid=").append(mCid) 227 .append(" mArfcn=").append(mArfcn) 228 .append(" mBsic=").append("0x").append(Integer.toHexString(mBsic)) 229 .append(" mMcc=").append(mMccStr) 230 .append(" mMnc=").append(mMncStr) 231 .append(" mAlphaLong=").append(mAlphaLong) 232 .append(" mAlphaShort=").append(mAlphaShort) 233 .append("}").toString(); 234 } 235 236 /** Implement the Parcelable interface */ 237 @Override 238 public void writeToParcel(Parcel dest, int flags) { 239 if (DBG) log("writeToParcel(Parcel, int): " + toString()); 240 super.writeToParcel(dest, TYPE_GSM); 241 dest.writeInt(mLac); 242 dest.writeInt(mCid); 243 dest.writeInt(mArfcn); 244 dest.writeInt(mBsic); 245 } 246 247 /** Construct from Parcel, type has already been processed */ 248 private CellIdentityGsm(Parcel in) { 249 super(TAG, TYPE_GSM, in); 250 mLac = in.readInt(); 251 mCid = in.readInt(); 252 mArfcn = in.readInt(); 253 mBsic = in.readInt(); 254 255 if (DBG) log(toString()); 256 } 257 258 /** Implement the Parcelable interface */ 259 @SuppressWarnings("hiding") 260 public static final Creator<CellIdentityGsm> CREATOR = 261 new Creator<CellIdentityGsm>() { 262 @Override 263 public CellIdentityGsm createFromParcel(Parcel in) { 264 in.readInt(); // skip 265 return createFromParcelBody(in); 266 } 267 268 @Override 269 public CellIdentityGsm[] newArray(int size) { 270 return new CellIdentityGsm[size]; 271 } 272 }; 273 274 /** @hide */ 275 protected static CellIdentityGsm createFromParcelBody(Parcel in) { 276 return new CellIdentityGsm(in); 277 } 278 } 279