Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 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 | |
| 17 | package android.telephony; |
| 18 | |
Cassie | 9ba450d | 2018-03-20 10:15:50 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Bill Peckham | a74879d | 2018-09-08 10:06:40 -0700 | [diff] [blame^] | 20 | import android.annotation.UnsupportedAppUsage; |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 22 | import android.text.TextUtils; |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 23 | |
Brian Williammee | 7d1d2e3 | 2014-08-29 17:31:22 -0700 | [diff] [blame] | 24 | import java.util.Objects; |
| 25 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 26 | /** |
| 27 | * CellIdentity is to represent a unique CDMA cell |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 28 | */ |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 29 | public final class CellIdentityCdma extends CellIdentity { |
| 30 | private static final String TAG = CellIdentityCdma.class.getSimpleName(); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 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() { |
Bill Peckham | a74879d | 2018-09-08 10:06:40 -0700 | [diff] [blame^] | 58 | super(TAG, CellInfo.TYPE_CDMA, null, null, null, null); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 59 | 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 Peckham | a74879d | 2018-09-08 10:06:40 -0700 | [diff] [blame^] | 78 | @UnsupportedAppUsage |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 79 | public CellIdentityCdma(int nid, int sid, int bid, int lon, int lat) { |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 80 | 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 Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 97 | public CellIdentityCdma(int nid, int sid, int bid, int lon, int lat, String alphal, |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 98 | String alphas) { |
Bill Peckham | a74879d | 2018-09-08 10:06:40 -0700 | [diff] [blame^] | 99 | super(TAG, CellInfo.TYPE_CDMA, null, null, alphal, alphas); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 100 | mNetworkId = nid; |
| 101 | mSystemId = sid; |
| 102 | mBasestationId = bid; |
Nathan Harold | 78eb48e | 2018-02-26 20:31:04 -0800 | [diff] [blame] | 103 | if (!isNullIsland(lat, lon)) { |
| 104 | mLongitude = lon; |
| 105 | mLatitude = lat; |
| 106 | } else { |
| 107 | mLongitude = mLatitude = Integer.MAX_VALUE; |
| 108 | } |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | private CellIdentityCdma(CellIdentityCdma cid) { |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 112 | this(cid.mNetworkId, cid.mSystemId, cid.mBasestationId, cid.mLongitude, cid.mLatitude, |
| 113 | cid.mAlphaLong, cid.mAlphaShort); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 116 | CellIdentityCdma copy() { |
| 117 | return new CellIdentityCdma(this); |
| 118 | } |
| 119 | |
| 120 | /** |
Nathan Harold | 78eb48e | 2018-02-26 20:31:04 -0800 | [diff] [blame] | 121 | * 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 Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 133 | * @return Network Id 0..65535, Integer.MAX_VALUE if unknown |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 134 | */ |
| 135 | public int getNetworkId() { |
| 136 | return mNetworkId; |
| 137 | } |
| 138 | |
| 139 | /** |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 140 | * @return System Id 0..32767, Integer.MAX_VALUE if unknown |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 141 | */ |
| 142 | public int getSystemId() { |
| 143 | return mSystemId; |
| 144 | } |
| 145 | |
| 146 | /** |
Wink Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 147 | * @return Base Station Id 0..65535, Integer.MAX_VALUE if unknown |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 148 | */ |
| 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 Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 158 | * to +180 degrees). Integer.MAX_VALUE if unknown. |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 159 | */ |
| 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 Saville | e3a9cbc | 2013-04-17 16:40:17 -0700 | [diff] [blame] | 169 | * to +90 degrees). Integer.MAX_VALUE if unknown. |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 170 | */ |
| 171 | public int getLatitude() { |
| 172 | return mLatitude; |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public int hashCode() { |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 177 | return Objects.hash(mNetworkId, mSystemId, mBasestationId, mLatitude, mLongitude, |
Cassie | 21ed3c5 | 2018-03-21 16:20:34 -0700 | [diff] [blame] | 178 | super.hashCode()); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public boolean equals(Object other) { |
Brian Williammee | 7d1d2e3 | 2014-08-29 17:31:22 -0700 | [diff] [blame] | 183 | if (this == other) { |
| 184 | return true; |
| 185 | } |
| 186 | |
| 187 | if (!(other instanceof CellIdentityCdma)) { |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 188 | return false; |
| 189 | } |
Brian Williammee | 7d1d2e3 | 2014-08-29 17:31:22 -0700 | [diff] [blame] | 190 | |
| 191 | CellIdentityCdma o = (CellIdentityCdma) other; |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 192 | |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 193 | return mNetworkId == o.mNetworkId |
| 194 | && mSystemId == o.mSystemId |
| 195 | && mBasestationId == o.mBasestationId |
| 196 | && mLatitude == o.mLatitude |
| 197 | && mLongitude == o.mLongitude |
Cassie | 21ed3c5 | 2018-03-21 16:20:34 -0700 | [diff] [blame] | 198 | && super.equals(other); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public String toString() { |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 203 | 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 Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 212 | } |
| 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 Peckham | a74879d | 2018-09-08 10:06:40 -0700 | [diff] [blame^] | 218 | super.writeToParcel(dest, CellInfo.TYPE_CDMA); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 219 | 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 Peckham | a74879d | 2018-09-08 10:06:40 -0700 | [diff] [blame^] | 228 | super(TAG, CellInfo.TYPE_CDMA, in); |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 229 | mNetworkId = in.readInt(); |
| 230 | mSystemId = in.readInt(); |
| 231 | mBasestationId = in.readInt(); |
| 232 | mLongitude = in.readInt(); |
| 233 | mLatitude = in.readInt(); |
Cassie | 933b78d | 2017-09-20 14:02:13 -0700 | [diff] [blame] | 234 | |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 235 | if (DBG) log(toString()); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 236 | } |
| 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 Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 244 | in.readInt(); // skip |
| 245 | return createFromParcelBody(in); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public CellIdentityCdma[] newArray(int size) { |
| 250 | return new CellIdentityCdma[size]; |
| 251 | } |
| 252 | }; |
| 253 | |
Jack Yu | 6cd4473 | 2017-12-28 14:41:12 -0800 | [diff] [blame] | 254 | /** @hide */ |
| 255 | protected static CellIdentityCdma createFromParcelBody(Parcel in) { |
| 256 | return new CellIdentityCdma(in); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 257 | } |
| 258 | } |