CellIdentityCdma.java revision 3caf66d2ea63c75039daf43af30d3727e5ce6b58
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 CDMA cell
25 */
26public final class CellIdentityCdma extends CellIdentity implements Parcelable {
27
28    private static final String LOG_TAG = "CellSignalStrengthCdma";
29    private static final boolean DBG = false;
30
31    // Network Id 0..65535
32    private final int mNetworkId;
33    // CDMA System Id 0..32767
34    private final int mSystemId;
35    // Base Station Id 0..65535
36    private final int mBasestationId;
37    /**
38     * Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
39     * It is represented in units of 0.25 seconds and ranges from -2592000
40     * to 2592000, both values inclusive (corresponding to a range of -180
41     * to +180 degrees).
42     */
43    private final int mLongitude;
44    /**
45     * Latitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
46     * It is represented in units of 0.25 seconds and ranges from -1296000
47     * to 1296000, both values inclusive (corresponding to a range of -90
48     * to +90 degrees).
49     */
50    private final int mLatitude;
51
52    /**
53     * @hide
54     */
55    public CellIdentityCdma() {
56        mNetworkId = Integer.MAX_VALUE;
57        mSystemId = Integer.MAX_VALUE;
58        mBasestationId = Integer.MAX_VALUE;
59        mLongitude = Integer.MAX_VALUE;
60        mLatitude = Integer.MAX_VALUE;
61    }
62
63    /**
64     * public constructor
65     * @param nid Network Id 0..65535
66     * @param sid CDMA System Id 0..32767
67     * @param bid Base Station Id 0..65535
68     * @param lon Longitude is a decimal number ranges from -2592000
69     *        to 2592000
70     * @param lat Latitude is a decimal number ranges from -1296000
71     *        to 1296000
72     *
73     * @hide
74     */
75    public CellIdentityCdma (int nid, int sid, int bid, int lon, int lat) {
76        mNetworkId = nid;
77        mSystemId = sid;
78        mBasestationId = bid;
79        mLongitude = lon;
80        mLatitude = lat;
81    }
82
83    private CellIdentityCdma(CellIdentityCdma cid) {
84        super(cid);
85        mNetworkId = cid.mNetworkId;
86        mSystemId = cid.mSystemId;
87        mBasestationId = cid.mBasestationId;
88        mLongitude = cid.mLongitude;
89        mLatitude = cid.mLatitude;
90    }
91
92    @Override
93    CellIdentityCdma copy() {
94        return new CellIdentityCdma(this);
95    }
96
97    /**
98     * @return Network Id 0..65535
99     */
100    public int getNetworkId() {
101        return mNetworkId;
102    }
103
104    /**
105     * @return System Id 0..32767
106     */
107    public int getSystemId() {
108        return mSystemId;
109    }
110
111    /**
112     * @return Base Station Id 0..65535
113     */
114    public int getBasestationId() {
115        return mBasestationId;
116    }
117
118    /**
119     * @return Base station longitude, which is a decimal number as
120     * specified in 3GPP2 C.S0005-A v6.0. It is represented in units
121     * of 0.25 seconds and ranges from -2592000 to 2592000, both
122     * values inclusive (corresponding to a range of -180
123     * to +180 degrees).
124     */
125    public int getLongitude() {
126        return mLongitude;
127    }
128
129    /**
130     * @return Base station latitude, which is a decimal number as
131     * specified in 3GPP2 C.S0005-A v6.0. It is represented in units
132     * of 0.25 seconds and ranges from -1296000 to 1296000, both
133     * values inclusive (corresponding to a range of -90
134     * to +90 degrees).
135     */
136    public int getLatitude() {
137        return mLatitude;
138    }
139
140    @Override
141    public int hashCode() {
142        int primeNum = 31;
143        return (mNetworkId * primeNum) + (mSystemId * primeNum) + (mBasestationId * primeNum) +
144                (mLatitude * primeNum) + (mLongitude * primeNum);
145    }
146
147    @Override
148    public boolean equals(Object other) {
149        if (super.equals(other)) {
150            try {
151                CellIdentityCdma o = (CellIdentityCdma)other;
152                return mNetworkId == o.mNetworkId &&
153                        mSystemId == o.mSystemId &&
154                        mBasestationId == o.mBasestationId &&
155                        mLatitude == o.mLatitude &&
156                        mLongitude == o.mLongitude;
157            } catch (ClassCastException e) {
158                return false;
159            }
160        } else {
161            return false;
162        }
163    }
164
165    @Override
166    public String toString() {
167        StringBuilder sb = new StringBuilder("CdmaCellIdentitiy:");
168        sb.append(super.toString());
169        sb.append(" mNetworkId="); sb.append(mNetworkId);
170        sb.append(" mSystemId="); sb.append(mSystemId);
171        sb.append(" mBasestationId="); sb.append(mBasestationId);
172        sb.append(" mLongitude="); sb.append(mLongitude);
173        sb.append(" mLatitude="); sb.append(mLatitude);
174
175        return sb.toString();
176    }
177
178    /** Implement the Parcelable interface */
179    @Override
180    public int describeContents() {
181        return 0;
182    }
183
184    /** Implement the Parcelable interface */
185    @Override
186    public void writeToParcel(Parcel dest, int flags) {
187        if (DBG) log("writeToParcel(Parcel, int): " + toString());
188        dest.writeInt(TYPE_CDMA);
189        super.writeToParcel(dest, flags);
190        dest.writeInt(mNetworkId);
191        dest.writeInt(mSystemId);
192        dest.writeInt(mBasestationId);
193        dest.writeInt(mLongitude);
194        dest.writeInt(mLatitude);
195    }
196
197    /** Construct from Parcel, type has already been processed */
198    private CellIdentityCdma(Parcel in) {
199        super(in);
200        mNetworkId = in.readInt();
201        mSystemId = in.readInt();
202        mBasestationId = in.readInt();
203        mLongitude = in.readInt();
204        mLatitude = in.readInt();
205        if (DBG) log("CellIdentityCdma(Parcel): " + toString());
206    }
207
208    /** Implement the Parcelable interface */
209    @SuppressWarnings("hiding")
210    public static final Creator<CellIdentityCdma> CREATOR =
211            new Creator<CellIdentityCdma>() {
212        @Override
213        public CellIdentityCdma createFromParcel(Parcel in) {
214            in.readInt(); // Skip past token, we know what it is
215            return createFromParcelBody(in);
216        }
217
218        @Override
219        public CellIdentityCdma[] newArray(int size) {
220            return new CellIdentityCdma[size];
221        }
222    };
223
224    /** @hide */
225    static CellIdentityCdma createFromParcelBody(Parcel in) {
226        return new CellIdentityCdma(in);
227    }
228
229    /**
230     * log
231     */
232    private static void log(String s) {
233        Log.w(LOG_TAG, s);
234    }
235}
236