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