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