blob: 5b67dc44fe3c23a2cbe919578a493f622efd0f17 [file] [log] [blame]
Wink Savilleb208a242012-07-25 14:08:09 -07001/*
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
Cassie9ba450d2018-03-20 10:15:50 -070019import android.annotation.Nullable;
Bill Peckhama74879d2018-09-08 10:06:40 -070020import android.annotation.UnsupportedAppUsage;
Wink Savilleb208a242012-07-25 14:08:09 -070021import android.os.Parcel;
Cassie933b78d2017-09-20 14:02:13 -070022import android.text.TextUtils;
Wink Savilleb208a242012-07-25 14:08:09 -070023
Brian Williammee7d1d2e32014-08-29 17:31:22 -070024import java.util.Objects;
25
Wink Savilleb208a242012-07-25 14:08:09 -070026/**
27 * CellIdentity is to represent a unique CDMA cell
Wink Savilleb208a242012-07-25 14:08:09 -070028 */
Jack Yu6cd44732017-12-28 14:41:12 -080029public final class CellIdentityCdma extends CellIdentity {
30 private static final String TAG = CellIdentityCdma.class.getSimpleName();
Wink Savilleb208a242012-07-25 14:08:09 -070031 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() {
Bill Peckhama74879d2018-09-08 10:06:40 -070058 super(TAG, CellInfo.TYPE_CDMA, null, null, null, null);
Wink Savilleb208a242012-07-25 14:08:09 -070059 mNetworkId = Integer.MAX_VALUE;
60 mSystemId = Integer.MAX_VALUE;
61 mBasestationId = Integer.MAX_VALUE;
62 mLongitude = Integer.MAX_VALUE;
63 mLatitude = Integer.MAX_VALUE;
64 }
65
66 /**
67 * public constructor
68 * @param nid Network Id 0..65535
69 * @param sid CDMA System Id 0..32767
70 * @param bid Base Station Id 0..65535
71 * @param lon Longitude is a decimal number ranges from -2592000
72 * to 2592000
73 * @param lat Latitude is a decimal number ranges from -1296000
74 * to 1296000
75 *
76 * @hide
77 */
Bill Peckhama74879d2018-09-08 10:06:40 -070078 @UnsupportedAppUsage
Jack Yu6cd44732017-12-28 14:41:12 -080079 public CellIdentityCdma(int nid, int sid, int bid, int lon, int lat) {
Cassie933b78d2017-09-20 14:02:13 -070080 this(nid, sid, bid, lon, lat, null, null);
81 }
82
83 /**
84 * public constructor
85 * @param nid Network Id 0..65535
86 * @param sid CDMA System Id 0..32767
87 * @param bid Base Station Id 0..65535
88 * @param lon Longitude is a decimal number ranges from -2592000
89 * to 2592000
90 * @param lat Latitude is a decimal number ranges from -1296000
91 * to 1296000
92 * @param alphal long alpha Operator Name String or Enhanced Operator Name String
93 * @param alphas short alpha Operator Name String or Enhanced Operator Name String
94 *
95 * @hide
96 */
Jack Yu6cd44732017-12-28 14:41:12 -080097 public CellIdentityCdma(int nid, int sid, int bid, int lon, int lat, String alphal,
Cassie933b78d2017-09-20 14:02:13 -070098 String alphas) {
Bill Peckhama74879d2018-09-08 10:06:40 -070099 super(TAG, CellInfo.TYPE_CDMA, null, null, alphal, alphas);
Wink Savilleb208a242012-07-25 14:08:09 -0700100 mNetworkId = nid;
101 mSystemId = sid;
102 mBasestationId = bid;
Nathan Harold78eb48e2018-02-26 20:31:04 -0800103 if (!isNullIsland(lat, lon)) {
104 mLongitude = lon;
105 mLatitude = lat;
106 } else {
107 mLongitude = mLatitude = Integer.MAX_VALUE;
108 }
Wink Savilleb208a242012-07-25 14:08:09 -0700109 }
110
111 private CellIdentityCdma(CellIdentityCdma cid) {
Cassie933b78d2017-09-20 14:02:13 -0700112 this(cid.mNetworkId, cid.mSystemId, cid.mBasestationId, cid.mLongitude, cid.mLatitude,
113 cid.mAlphaLong, cid.mAlphaShort);
Wink Savilleb208a242012-07-25 14:08:09 -0700114 }
115
Wink Savilleb208a242012-07-25 14:08:09 -0700116 CellIdentityCdma copy() {
117 return new CellIdentityCdma(this);
118 }
119
120 /**
Nathan Harold78eb48e2018-02-26 20:31:04 -0800121 * Take the latitude and longitude in 1/4 seconds and see if
122 * the reported location is on Null Island.
123 *
124 * @return whether the reported Lat/Long are for Null Island
125 *
126 * @hide
127 */
128 private boolean isNullIsland(int lat, int lon) {
129 return Math.abs(lat) <= 1 && Math.abs(lon) <= 1;
130 }
131
132 /**
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700133 * @return Network Id 0..65535, Integer.MAX_VALUE if unknown
Wink Savilleb208a242012-07-25 14:08:09 -0700134 */
135 public int getNetworkId() {
136 return mNetworkId;
137 }
138
139 /**
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700140 * @return System Id 0..32767, Integer.MAX_VALUE if unknown
Wink Savilleb208a242012-07-25 14:08:09 -0700141 */
142 public int getSystemId() {
143 return mSystemId;
144 }
145
146 /**
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700147 * @return Base Station Id 0..65535, Integer.MAX_VALUE if unknown
Wink Savilleb208a242012-07-25 14:08:09 -0700148 */
149 public int getBasestationId() {
150 return mBasestationId;
151 }
152
153 /**
154 * @return Base station longitude, which is a decimal number as
155 * specified in 3GPP2 C.S0005-A v6.0. It is represented in units
156 * of 0.25 seconds and ranges from -2592000 to 2592000, both
157 * values inclusive (corresponding to a range of -180
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700158 * to +180 degrees). Integer.MAX_VALUE if unknown.
Wink Savilleb208a242012-07-25 14:08:09 -0700159 */
160 public int getLongitude() {
161 return mLongitude;
162 }
163
164 /**
165 * @return Base station latitude, which is a decimal number as
166 * specified in 3GPP2 C.S0005-A v6.0. It is represented in units
167 * of 0.25 seconds and ranges from -1296000 to 1296000, both
168 * values inclusive (corresponding to a range of -90
Wink Savillee3a9cbc2013-04-17 16:40:17 -0700169 * to +90 degrees). Integer.MAX_VALUE if unknown.
Wink Savilleb208a242012-07-25 14:08:09 -0700170 */
171 public int getLatitude() {
172 return mLatitude;
173 }
174
175 @Override
176 public int hashCode() {
Cassie933b78d2017-09-20 14:02:13 -0700177 return Objects.hash(mNetworkId, mSystemId, mBasestationId, mLatitude, mLongitude,
Cassie21ed3c52018-03-21 16:20:34 -0700178 super.hashCode());
Wink Savilleb208a242012-07-25 14:08:09 -0700179 }
180
181 @Override
182 public boolean equals(Object other) {
Brian Williammee7d1d2e32014-08-29 17:31:22 -0700183 if (this == other) {
184 return true;
185 }
186
187 if (!(other instanceof CellIdentityCdma)) {
Wink Savilleb208a242012-07-25 14:08:09 -0700188 return false;
189 }
Brian Williammee7d1d2e32014-08-29 17:31:22 -0700190
191 CellIdentityCdma o = (CellIdentityCdma) other;
Cassie933b78d2017-09-20 14:02:13 -0700192
Jack Yu6cd44732017-12-28 14:41:12 -0800193 return mNetworkId == o.mNetworkId
194 && mSystemId == o.mSystemId
195 && mBasestationId == o.mBasestationId
196 && mLatitude == o.mLatitude
197 && mLongitude == o.mLongitude
Cassie21ed3c52018-03-21 16:20:34 -0700198 && super.equals(other);
Wink Savilleb208a242012-07-25 14:08:09 -0700199 }
200
201 @Override
202 public String toString() {
Jack Yu6cd44732017-12-28 14:41:12 -0800203 return new StringBuilder(TAG)
204 .append(":{ mNetworkId=").append(mNetworkId)
205 .append(" mSystemId=").append(mSystemId)
206 .append(" mBasestationId=").append(mBasestationId)
207 .append(" mLongitude=").append(mLongitude)
208 .append(" mLatitude=").append(mLatitude)
209 .append(" mAlphaLong=").append(mAlphaLong)
210 .append(" mAlphaShort=").append(mAlphaShort)
211 .append("}").toString();
Wink Savilleb208a242012-07-25 14:08:09 -0700212 }
213
214 /** Implement the Parcelable interface */
215 @Override
216 public void writeToParcel(Parcel dest, int flags) {
217 if (DBG) log("writeToParcel(Parcel, int): " + toString());
Bill Peckhama74879d2018-09-08 10:06:40 -0700218 super.writeToParcel(dest, CellInfo.TYPE_CDMA);
Wink Savilleb208a242012-07-25 14:08:09 -0700219 dest.writeInt(mNetworkId);
220 dest.writeInt(mSystemId);
221 dest.writeInt(mBasestationId);
222 dest.writeInt(mLongitude);
223 dest.writeInt(mLatitude);
224 }
225
226 /** Construct from Parcel, type has already been processed */
227 private CellIdentityCdma(Parcel in) {
Bill Peckhama74879d2018-09-08 10:06:40 -0700228 super(TAG, CellInfo.TYPE_CDMA, in);
Jack Yu6cd44732017-12-28 14:41:12 -0800229 mNetworkId = in.readInt();
230 mSystemId = in.readInt();
231 mBasestationId = in.readInt();
232 mLongitude = in.readInt();
233 mLatitude = in.readInt();
Cassie933b78d2017-09-20 14:02:13 -0700234
Jack Yu6cd44732017-12-28 14:41:12 -0800235 if (DBG) log(toString());
Wink Savilleb208a242012-07-25 14:08:09 -0700236 }
237
238 /** Implement the Parcelable interface */
239 @SuppressWarnings("hiding")
240 public static final Creator<CellIdentityCdma> CREATOR =
241 new Creator<CellIdentityCdma>() {
242 @Override
243 public CellIdentityCdma createFromParcel(Parcel in) {
Jack Yu6cd44732017-12-28 14:41:12 -0800244 in.readInt(); // skip
245 return createFromParcelBody(in);
Wink Savilleb208a242012-07-25 14:08:09 -0700246 }
247
248 @Override
249 public CellIdentityCdma[] newArray(int size) {
250 return new CellIdentityCdma[size];
251 }
252 };
253
Jack Yu6cd44732017-12-28 14:41:12 -0800254 /** @hide */
255 protected static CellIdentityCdma createFromParcelBody(Parcel in) {
256 return new CellIdentityCdma(in);
Wink Savilleb208a242012-07-25 14:08:09 -0700257 }
258}