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