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