CellIdentityLte.java revision b208a24cf521401912cfce16fce550a995cf1250
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.util.Log;
22
23/**
24 * CellIdentity is to represent a unique LTE cell
25 *
26 * @hide
27 */
28public final class CellIdentityLte extends CellIdentity 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        super(cid);
75        mMcc = cid.mMcc;
76        mMnc = cid.mMnc;
77        mCi = cid.mCi;
78        mPci = cid.mPci;
79        mTac = cid.mTac;
80    }
81
82    @Override
83    CellIdentityLte copy() {
84        return new CellIdentityLte(this);
85    }
86
87    /**
88     * @return 3-digit Mobile Country Code, 0..999
89     */
90    public int getMcc() {
91        return mMcc;
92    }
93
94    /**
95     * @return 2 or 3-digit Mobile Network Code, 0..999
96     */
97    public int getMnc() {
98        return mMnc;
99    }
100
101    /**
102     * @return 28-bit Cell Identity
103     */
104    public int getCi() {
105        return mCi;
106    }
107
108    /**
109     * @return Physical Cell Id 0..503
110     */
111    public int getPci() {
112        return mPci;
113    }
114
115    /**
116     * @return 16-bit Tracking Area Code
117     */
118    public int getTac() {
119        return mTac;
120    }
121
122    @Override
123    public int hashCode() {
124        int primeNum = 31;
125        return (mMcc * primeNum) + (mMnc * primeNum) + (mCi * primeNum) + (mPci * primeNum) +
126                (mTac * primeNum);
127    }
128
129    @Override
130    public boolean equals(Object other) {
131        if (super.equals(other)) {
132            try {
133                CellIdentityLte o = (CellIdentityLte)other;
134                return mMcc == o.mMcc &&
135                        mMnc == o.mMnc &&
136                        mCi == o.mCi &&
137                        mPci == o.mCi &&
138                        mTac == o.mTac;
139            } catch (ClassCastException e) {
140                return false;
141            }
142        } else {
143            return false;
144        }
145    }
146
147    @Override
148    public String toString() {
149        StringBuilder sb = new StringBuilder("LteCellIdentitiy:");
150        sb.append(super.toString());
151        sb.append(" mMcc="); sb.append(mMcc);
152        sb.append(" mMnc="); sb.append(mMnc);
153        sb.append(" mCi="); sb.append(mCi);
154        sb.append(" mPci="); sb.append(mPci);
155        sb.append(" mTac="); sb.append(mTac);
156
157        return sb.toString();
158    }
159
160    /** Implement the Parcelable interface */
161    @Override
162    public int describeContents() {
163        return 0;
164    }
165
166    /** Implement the Parcelable interface */
167    @Override
168    public void writeToParcel(Parcel dest, int flags) {
169        if (DBG) log("writeToParcel(Parcel, int): " + toString());
170        dest.writeInt(TYPE_LTE);
171        super.writeToParcel(dest, flags);
172        dest.writeInt(mMcc);
173        dest.writeInt(mMnc);
174        dest.writeInt(mCi);
175        dest.writeInt(mPci);
176        dest.writeInt(mTac);
177    }
178
179    /** Construct from Parcel, type has already been processed */
180    private CellIdentityLte(Parcel in) {
181        super(in);
182        mMcc = in.readInt();
183        mMnc = in.readInt();
184        mCi = in.readInt();
185        mPci = in.readInt();
186        mTac = in.readInt();
187        if (DBG) log("CellIdentityLte(Parcel): " + toString());
188    }
189
190    /** Implement the Parcelable interface */
191    @SuppressWarnings("hiding")
192    public static final Creator<CellIdentityLte> CREATOR =
193            new Creator<CellIdentityLte>() {
194        @Override
195        public CellIdentityLte createFromParcel(Parcel in) {
196            in.readInt(); // Skip past token, we know what it is
197            return createFromParcelBody(in);
198        }
199
200        @Override
201        public CellIdentityLte[] newArray(int size) {
202            return new CellIdentityLte[size];
203        }
204    };
205
206    /** @hide */
207    static CellIdentityLte createFromParcelBody(Parcel in) {
208        return new CellIdentityLte(in);
209    }
210
211    /**
212     * log
213     */
214    private static void log(String s) {
215        Log.w(LOG_TAG, s);
216    }
217}
218