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 17package android.telephony; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21import android.telephony.Rlog; 22 23import java.util.Objects; 24 25/** 26 * CellIdentity to represent a unique UMTS cell 27 */ 28public final class CellIdentityWcdma implements Parcelable { 29 30 private static final String LOG_TAG = "CellIdentityWcdma"; 31 private static final boolean DBG = false; 32 33 // 3-digit Mobile Country Code, 0..999 34 private final int mMcc; 35 // 2 or 3-digit Mobile Network Code, 0..999 36 private final int mMnc; 37 // 16-bit Location Area Code, 0..65535 38 private final int mLac; 39 // 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455 40 private final int mCid; 41 // 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511 42 private final int mPsc; 43 // 16-bit UMTS Absolute RF Channel Number 44 private final int mUarfcn; 45 46 /** 47 * @hide 48 */ 49 public CellIdentityWcdma() { 50 mMcc = Integer.MAX_VALUE; 51 mMnc = Integer.MAX_VALUE; 52 mLac = Integer.MAX_VALUE; 53 mCid = Integer.MAX_VALUE; 54 mPsc = Integer.MAX_VALUE; 55 mUarfcn = Integer.MAX_VALUE; 56 } 57 /** 58 * public constructor 59 * @param mcc 3-digit Mobile Country Code, 0..999 60 * @param mnc 2 or 3-digit Mobile Network Code, 0..999 61 * @param lac 16-bit Location Area Code, 0..65535 62 * @param cid 28-bit UMTS Cell Identity 63 * @param psc 9-bit UMTS Primary Scrambling Code 64 * 65 * @hide 66 */ 67 public CellIdentityWcdma (int mcc, int mnc, int lac, int cid, int psc) { 68 this(mcc, mnc, lac, cid, psc, Integer.MAX_VALUE); 69 } 70 71 /** 72 * public constructor 73 * @param mcc 3-digit Mobile Country Code, 0..999 74 * @param mnc 2 or 3-digit Mobile Network Code, 0..999 75 * @param lac 16-bit Location Area Code, 0..65535 76 * @param cid 28-bit UMTS Cell Identity 77 * @param psc 9-bit UMTS Primary Scrambling Code 78 * @param uarfcn 16-bit UMTS Absolute RF Channel Number 79 * 80 * @hide 81 */ 82 public CellIdentityWcdma (int mcc, int mnc, int lac, int cid, int psc, int uarfcn) { 83 mMcc = mcc; 84 mMnc = mnc; 85 mLac = lac; 86 mCid = cid; 87 mPsc = psc; 88 mUarfcn = uarfcn; 89 } 90 91 private CellIdentityWcdma(CellIdentityWcdma cid) { 92 mMcc = cid.mMcc; 93 mMnc = cid.mMnc; 94 mLac = cid.mLac; 95 mCid = cid.mCid; 96 mPsc = cid.mPsc; 97 mUarfcn = cid.mUarfcn; 98 } 99 100 CellIdentityWcdma copy() { 101 return new CellIdentityWcdma(this); 102 } 103 104 /** 105 * @return 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown 106 */ 107 public int getMcc() { 108 return mMcc; 109 } 110 111 /** 112 * @return 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown 113 */ 114 public int getMnc() { 115 return mMnc; 116 } 117 118 /** 119 * @return 16-bit Location Area Code, 0..65535, Integer.MAX_VALUE if unknown 120 */ 121 public int getLac() { 122 return mLac; 123 } 124 125 /** 126 * @return CID 127 * 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, Integer.MAX_VALUE if unknown 128 */ 129 public int getCid() { 130 return mCid; 131 } 132 133 /** 134 * @return 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511, Integer.MAX_VALUE 135 * if unknown 136 */ 137 public int getPsc() { 138 return mPsc; 139 } 140 141 @Override 142 public int hashCode() { 143 return Objects.hash(mMcc, mMnc, mLac, mCid, mPsc); 144 } 145 146 /** 147 * @return 16-bit UMTS Absolute RF Channel Number, Integer.MAX_VALUE if unknown 148 */ 149 public int getUarfcn() { 150 return mUarfcn; 151 } 152 153 @Override 154 public boolean equals(Object other) { 155 if (this == other) { 156 return true; 157 } 158 159 if (!(other instanceof CellIdentityWcdma)) { 160 return false; 161 } 162 163 CellIdentityWcdma o = (CellIdentityWcdma) other; 164 return mMcc == o.mMcc && 165 mMnc == o.mMnc && 166 mLac == o.mLac && 167 mCid == o.mCid && 168 mPsc == o.mPsc && 169 mUarfcn == o.mUarfcn; 170 } 171 172 @Override 173 public String toString() { 174 StringBuilder sb = new StringBuilder("CellIdentityWcdma:{"); 175 sb.append(" mMcc=").append(mMcc); 176 sb.append(" mMnc=").append(mMnc); 177 sb.append(" mLac=").append(mLac); 178 sb.append(" mCid=").append(mCid); 179 sb.append(" mPsc=").append(mPsc); 180 sb.append(" mUarfcn=").append(mUarfcn); 181 sb.append("}"); 182 183 return sb.toString(); 184 } 185 186 /** Implement the Parcelable interface */ 187 @Override 188 public int describeContents() { 189 return 0; 190 } 191 192 /** Implement the Parcelable interface */ 193 @Override 194 public void writeToParcel(Parcel dest, int flags) { 195 if (DBG) log("writeToParcel(Parcel, int): " + toString()); 196 dest.writeInt(mMcc); 197 dest.writeInt(mMnc); 198 dest.writeInt(mLac); 199 dest.writeInt(mCid); 200 dest.writeInt(mPsc); 201 dest.writeInt(mUarfcn); 202 } 203 204 /** Construct from Parcel, type has already been processed */ 205 private CellIdentityWcdma(Parcel in) { 206 mMcc = in.readInt(); 207 mMnc = in.readInt(); 208 mLac = in.readInt(); 209 mCid = in.readInt(); 210 mPsc = in.readInt(); 211 mUarfcn = in.readInt(); 212 if (DBG) log("CellIdentityWcdma(Parcel): " + toString()); 213 } 214 215 /** Implement the Parcelable interface */ 216 @SuppressWarnings("hiding") 217 public static final Creator<CellIdentityWcdma> CREATOR = 218 new Creator<CellIdentityWcdma>() { 219 @Override 220 public CellIdentityWcdma createFromParcel(Parcel in) { 221 return new CellIdentityWcdma(in); 222 } 223 224 @Override 225 public CellIdentityWcdma[] newArray(int size) { 226 return new CellIdentityWcdma[size]; 227 } 228 }; 229 230 /** 231 * log 232 */ 233 private static void log(String s) { 234 Rlog.w(LOG_TAG, s); 235 } 236} 237