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
23/**
24 * CellIdentity is to represent a unique LTE cell
25 */
26public final class CellIdentityLte implements Parcelable {
27
28    private static final String LOG_TAG = "CellIdentityLte";
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    // 28-bit cell identity
36    private final int mCi;
37    // physical cell id 0..503
38    private final int mPci;
39    // 16-bit tracking area code
40    private final int mTac;
41
42    /**
43     * @hide
44     */
45    public CellIdentityLte() {
46        mMcc = Integer.MAX_VALUE;
47        mMnc = Integer.MAX_VALUE;
48        mCi = Integer.MAX_VALUE;
49        mPci = Integer.MAX_VALUE;
50        mTac = Integer.MAX_VALUE;
51    }
52
53    /**
54     *
55     * @param mcc 3-digit Mobile Country Code, 0..999
56     * @param mnc 2 or 3-digit Mobile Network Code, 0..999
57     * @param ci 28-bit Cell Identity
58     * @param pci Physical Cell Id 0..503
59     * @param tac 16-bit Tracking Area Code
60     *
61     * @hide
62     */
63    public CellIdentityLte (int mcc, int mnc, int ci, int pci, int tac) {
64        mMcc = mcc;
65        mMnc = mnc;
66        mCi = ci;
67        mPci = pci;
68        mTac = tac;
69    }
70
71    private CellIdentityLte(CellIdentityLte cid) {
72        mMcc = cid.mMcc;
73        mMnc = cid.mMnc;
74        mCi = cid.mCi;
75        mPci = cid.mPci;
76        mTac = cid.mTac;
77    }
78
79    CellIdentityLte copy() {
80        return new CellIdentityLte(this);
81    }
82
83    /**
84     * @return 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
85     */
86    public int getMcc() {
87        return mMcc;
88    }
89
90    /**
91     * @return 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
92     */
93    public int getMnc() {
94        return mMnc;
95    }
96
97    /**
98     * @return 28-bit Cell Identity, Integer.MAX_VALUE if unknown
99     */
100    public int getCi() {
101        return mCi;
102    }
103
104    /**
105     * @return Physical Cell Id 0..503, Integer.MAX_VALUE if unknown
106     */
107    public int getPci() {
108        return mPci;
109    }
110
111    /**
112     * @return 16-bit Tracking Area Code, Integer.MAX_VALUE if unknown
113     */
114    public int getTac() {
115        return mTac;
116    }
117
118    @Override
119    public int hashCode() {
120        int primeNum = 31;
121        return (mMcc * primeNum) + (mMnc * primeNum) + (mCi * primeNum) + (mPci * primeNum) +
122                (mTac * primeNum);
123    }
124
125    @Override
126    public boolean equals(Object other) {
127        if (super.equals(other)) {
128            try {
129                CellIdentityLte o = (CellIdentityLte)other;
130                return mMcc == o.mMcc &&
131                        mMnc == o.mMnc &&
132                        mCi == o.mCi &&
133                        mPci == o.mPci &&
134                        mTac == o.mTac;
135            } catch (ClassCastException e) {
136                return false;
137            }
138        } else {
139            return false;
140        }
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