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 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 is to represent a unique LTE cell 27 */ 28public final class CellIdentityLte implements Parcelable { 29 30 private static final String LOG_TAG = "CellIdentityLte"; 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 // 28-bit cell identity 38 private final int mCi; 39 // physical cell id 0..503 40 private final int mPci; 41 // 16-bit tracking area code 42 private final int mTac; 43 44 /** 45 * @hide 46 */ 47 public CellIdentityLte() { 48 mMcc = Integer.MAX_VALUE; 49 mMnc = Integer.MAX_VALUE; 50 mCi = Integer.MAX_VALUE; 51 mPci = Integer.MAX_VALUE; 52 mTac = 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 mMcc = mcc; 67 mMnc = mnc; 68 mCi = ci; 69 mPci = pci; 70 mTac = tac; 71 } 72 73 private CellIdentityLte(CellIdentityLte cid) { 74 mMcc = cid.mMcc; 75 mMnc = cid.mMnc; 76 mCi = cid.mCi; 77 mPci = cid.mPci; 78 mTac = cid.mTac; 79 } 80 81 CellIdentityLte copy() { 82 return new CellIdentityLte(this); 83 } 84 85 /** 86 * @return 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown 87 */ 88 public int getMcc() { 89 return mMcc; 90 } 91 92 /** 93 * @return 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown 94 */ 95 public int getMnc() { 96 return mMnc; 97 } 98 99 /** 100 * @return 28-bit Cell Identity, Integer.MAX_VALUE if unknown 101 */ 102 public int getCi() { 103 return mCi; 104 } 105 106 /** 107 * @return Physical Cell Id 0..503, Integer.MAX_VALUE if unknown 108 */ 109 public int getPci() { 110 return mPci; 111 } 112 113 /** 114 * @return 16-bit Tracking Area Code, Integer.MAX_VALUE if unknown 115 */ 116 public int getTac() { 117 return mTac; 118 } 119 120 @Override 121 public int hashCode() { 122 return Objects.hash(mMcc, mMnc, mCi, mPci, mTac); 123 } 124 125 @Override 126 public boolean equals(Object other) { 127 if (this == other) { 128 return true; 129 } 130 131 if (!(other instanceof CellIdentityLte)) { 132 return false; 133 } 134 135 CellIdentityLte o = (CellIdentityLte) other; 136 return mMcc == o.mMcc && 137 mMnc == o.mMnc && 138 mCi == o.mCi && 139 mPci == o.mPci && 140 mTac == o.mTac; 141 } 142 143 @Override 144 public String toString() { 145 StringBuilder sb = new StringBuilder("CellIdentityLte:{"); 146 sb.append(" mMcc="); sb.append(mMcc); 147 sb.append(" mMnc="); sb.append(mMnc); 148 sb.append(" mCi="); sb.append(mCi); 149 sb.append(" mPci="); sb.append(mPci); 150 sb.append(" mTac="); sb.append(mTac); 151 sb.append("}"); 152 153 return sb.toString(); 154 } 155 156 /** Implement the Parcelable interface */ 157 @Override 158 public int describeContents() { 159 return 0; 160 } 161 162 /** Implement the Parcelable interface */ 163 @Override 164 public void writeToParcel(Parcel dest, int flags) { 165 if (DBG) log("writeToParcel(Parcel, int): " + toString()); 166 dest.writeInt(mMcc); 167 dest.writeInt(mMnc); 168 dest.writeInt(mCi); 169 dest.writeInt(mPci); 170 dest.writeInt(mTac); 171 } 172 173 /** Construct from Parcel, type has already been processed */ 174 private CellIdentityLte(Parcel in) { 175 mMcc = in.readInt(); 176 mMnc = in.readInt(); 177 mCi = in.readInt(); 178 mPci = in.readInt(); 179 mTac = in.readInt(); 180 if (DBG) log("CellIdentityLte(Parcel): " + toString()); 181 } 182 183 /** Implement the Parcelable interface */ 184 @SuppressWarnings("hiding") 185 public static final Creator<CellIdentityLte> CREATOR = 186 new Creator<CellIdentityLte>() { 187 @Override 188 public CellIdentityLte createFromParcel(Parcel in) { 189 return new CellIdentityLte(in); 190 } 191 192 @Override 193 public CellIdentityLte[] newArray(int size) { 194 return new CellIdentityLte[size]; 195 } 196 }; 197 198 /** 199 * log 200 */ 201 private static void log(String s) { 202 Rlog.w(LOG_TAG, s); 203 } 204} 205