1 /* 2 * Copyright (C) 2006 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.cdma; 18 19 import android.compat.annotation.UnsupportedAppUsage; 20 import android.os.Build; 21 import android.os.Bundle; 22 import android.telephony.CellLocation; 23 24 /** 25 * Represents the cell location on a CDMA phone. 26 * 27 * @deprecated use {@link android.telephony.CellIdentity CellIdentity}. 28 */ 29 @Deprecated 30 public class CdmaCellLocation extends CellLocation { 31 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 32 private int mBaseStationId = -1; 33 34 /** 35 * @hide 36 */ 37 public final static int INVALID_LAT_LONG = Integer.MAX_VALUE; 38 39 /** 40 * Latitude 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 -1296000 42 * to 1296000, both values inclusive (corresponding to a range of -90 43 * to +90 degrees). Integer.MAX_VALUE is considered invalid value. 44 */ 45 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 46 private int mBaseStationLatitude = INVALID_LAT_LONG; 47 48 /** 49 * Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. 50 * It is represented in units of 0.25 seconds and ranges from -2592000 51 * to 2592000, both values inclusive (corresponding to a range of -180 52 * to +180 degrees). Integer.MAX_VALUE is considered invalid value. 53 */ 54 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 55 private int mBaseStationLongitude = INVALID_LAT_LONG; 56 57 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 58 private int mSystemId = -1; 59 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 60 private int mNetworkId = -1; 61 62 /** 63 * Empty constructor. 64 * Initializes the BID, SID, NID and base station latitude and longitude 65 * to invalid values. 66 */ CdmaCellLocation()67 public CdmaCellLocation() { 68 this.mBaseStationId = -1; 69 this.mBaseStationLatitude = INVALID_LAT_LONG; 70 this.mBaseStationLongitude = INVALID_LAT_LONG; 71 this.mSystemId = -1; 72 this.mNetworkId = -1; 73 } 74 75 /** 76 * Initialize the object from a bundle. 77 */ CdmaCellLocation(Bundle bundle)78 public CdmaCellLocation(Bundle bundle) { 79 this.mBaseStationId = bundle.getInt("baseStationId", mBaseStationId); 80 this.mBaseStationLatitude = bundle.getInt("baseStationLatitude", mBaseStationLatitude); 81 this.mBaseStationLongitude = bundle.getInt("baseStationLongitude", mBaseStationLongitude); 82 this.mSystemId = bundle.getInt("systemId", mSystemId); 83 this.mNetworkId = bundle.getInt("networkId", mNetworkId); 84 } 85 86 /** 87 * @return cdma base station identification number, -1 if unknown 88 */ getBaseStationId()89 public int getBaseStationId() { 90 return this.mBaseStationId; 91 } 92 93 /** 94 * Latitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. 95 * (http://www.3gpp2.org/public_html/specs/C.S0005-A_v6.0.pdf) 96 * It is represented in units of 0.25 seconds and ranges from -1296000 97 * to 1296000, both values inclusive (corresponding to a range of -90 98 * to +90 degrees). Integer.MAX_VALUE is considered invalid value. 99 * 100 * @return cdma base station latitude in units of 0.25 seconds, Integer.MAX_VALUE if unknown 101 */ getBaseStationLatitude()102 public int getBaseStationLatitude() { 103 return this.mBaseStationLatitude; 104 } 105 106 /** 107 * Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. 108 * (http://www.3gpp2.org/public_html/specs/C.S0005-A_v6.0.pdf) 109 * It is represented in units of 0.25 seconds and ranges from -2592000 110 * to 2592000, both values inclusive (corresponding to a range of -180 111 * to +180 degrees). Integer.MAX_VALUE is considered invalid value. 112 * 113 * @return cdma base station longitude in units of 0.25 seconds, Integer.MAX_VALUE if unknown 114 */ getBaseStationLongitude()115 public int getBaseStationLongitude() { 116 return this.mBaseStationLongitude; 117 } 118 119 /** 120 * @return cdma system identification number, -1 if unknown 121 */ getSystemId()122 public int getSystemId() { 123 return this.mSystemId; 124 } 125 126 /** 127 * @return cdma network identification number, -1 if unknown 128 */ getNetworkId()129 public int getNetworkId() { 130 return this.mNetworkId; 131 } 132 133 /** 134 * Invalidate this object. The cell location data is set to invalid values. 135 */ 136 @Override setStateInvalid()137 public void setStateInvalid() { 138 this.mBaseStationId = -1; 139 this.mBaseStationLatitude = INVALID_LAT_LONG; 140 this.mBaseStationLongitude = INVALID_LAT_LONG; 141 this.mSystemId = -1; 142 this.mNetworkId = -1; 143 } 144 145 /** 146 * Set the cell location data. 147 */ setCellLocationData(int baseStationId, int baseStationLatitude, int baseStationLongitude)148 public void setCellLocationData(int baseStationId, int baseStationLatitude, 149 int baseStationLongitude) { 150 // The following values have to be written in the correct sequence 151 this.mBaseStationId = baseStationId; 152 this.mBaseStationLatitude = baseStationLatitude; //values[2]; 153 this.mBaseStationLongitude = baseStationLongitude; //values[3]; 154 } 155 156 /** 157 * Set the cell location data. 158 */ setCellLocationData(int baseStationId, int baseStationLatitude, int baseStationLongitude, int systemId, int networkId)159 public void setCellLocationData(int baseStationId, int baseStationLatitude, 160 int baseStationLongitude, int systemId, int networkId) { 161 // The following values have to be written in the correct sequence 162 this.mBaseStationId = baseStationId; 163 this.mBaseStationLatitude = baseStationLatitude; //values[2]; 164 this.mBaseStationLongitude = baseStationLongitude; //values[3]; 165 this.mSystemId = systemId; 166 this.mNetworkId = networkId; 167 } 168 169 @Override hashCode()170 public int hashCode() { 171 return this.mBaseStationId ^ this.mBaseStationLatitude ^ this.mBaseStationLongitude 172 ^ this.mSystemId ^ this.mNetworkId; 173 } 174 175 @Override equals(Object o)176 public boolean equals(Object o) { 177 CdmaCellLocation s; 178 179 try { 180 s = (CdmaCellLocation)o; 181 } catch (ClassCastException ex) { 182 return false; 183 } 184 185 if (o == null) { 186 return false; 187 } 188 189 return (equalsHandlesNulls(this.mBaseStationId, s.mBaseStationId) && 190 equalsHandlesNulls(this.mBaseStationLatitude, s.mBaseStationLatitude) && 191 equalsHandlesNulls(this.mBaseStationLongitude, s.mBaseStationLongitude) && 192 equalsHandlesNulls(this.mSystemId, s.mSystemId) && 193 equalsHandlesNulls(this.mNetworkId, s.mNetworkId) 194 ); 195 } 196 197 @Override toString()198 public String toString() { 199 return "[" + this.mBaseStationId + "," 200 + this.mBaseStationLatitude + "," 201 + this.mBaseStationLongitude + "," 202 + this.mSystemId + "," 203 + this.mNetworkId + "]"; 204 } 205 206 /** 207 * Test whether two objects hold the same data values or both are null 208 * 209 * @param a first obj 210 * @param b second obj 211 * @return true if two objects equal or both are null 212 */ 213 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) equalsHandlesNulls(Object a, Object b)214 private static boolean equalsHandlesNulls(Object a, Object b) { 215 return (a == null) ? (b == null) : a.equals (b); 216 } 217 218 /** 219 * Fill the cell location data into the intent notifier Bundle based on service state 220 * 221 * @param bundleToFill intent notifier Bundle 222 */ fillInNotifierBundle(Bundle bundleToFill)223 public void fillInNotifierBundle(Bundle bundleToFill) { 224 bundleToFill.putInt("baseStationId", this.mBaseStationId); 225 bundleToFill.putInt("baseStationLatitude", this.mBaseStationLatitude); 226 bundleToFill.putInt("baseStationLongitude", this.mBaseStationLongitude); 227 bundleToFill.putInt("systemId", this.mSystemId); 228 bundleToFill.putInt("networkId", this.mNetworkId); 229 } 230 231 /** 232 * @hide 233 */ isEmpty()234 public boolean isEmpty() { 235 return (this.mBaseStationId == -1 && 236 this.mBaseStationLatitude == INVALID_LAT_LONG && 237 this.mBaseStationLongitude == INVALID_LAT_LONG && 238 this.mSystemId == -1 && 239 this.mNetworkId == -1); 240 } 241 242 /** 243 * Converts latitude or longitude from 0.25 seconds (as defined in the 244 * 3GPP2 C.S0005-A v6.0 standard) to decimal degrees 245 * 246 * @param quartSec latitude or longitude in 0.25 seconds units 247 * @return latitude or longitude in decimal degrees units 248 * @throws IllegalArgumentException if value is less than -2592000, 249 * greater than 2592000, or is not a number. 250 */ convertQuartSecToDecDegrees(int quartSec)251 public static double convertQuartSecToDecDegrees(int quartSec) { 252 if(Double.isNaN(quartSec) || quartSec < -2592000 || quartSec > 2592000){ 253 // Invalid value 254 throw new IllegalArgumentException("Invalid coordiante value:" + quartSec); 255 } 256 return ((double)quartSec) / (3600 * 4); 257 } 258 259 } 260 261 262