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