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