• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.os.Bundle;
20 import android.telephony.CellLocation;
21 
22 /**
23  * Represents the cell location on a CDMA phone.
24  */
25 public class CdmaCellLocation extends CellLocation {
26     private int mBaseStationId = -1;
27 
28     /**
29      * Latitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
30      * It is represented in units of 0.25 seconds and ranges from -1296000
31      * to 1296000, both values inclusive (corresponding to a range of -90
32      * to +90 degrees). Integer.MAX_VALUE is considered invalid value.
33      */
34     private int mBaseStationLatitude = Integer.MAX_VALUE;
35 
36     /**
37      * Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
38      * It is represented in units of 0.25 seconds and ranges from -2592000
39      * to 2592000, both values inclusive (corresponding to a range of -180
40      * to +180 degrees). Integer.MAX_VALUE is considered invalid value.
41      */
42     private int mBaseStationLongitude = Integer.MAX_VALUE;
43 
44     private int mSystemId = -1;
45     private int mNetworkId = -1;
46 
47     /**
48      * Empty constructor.
49      * Initializes the BID, SID, NID and base station latitude and longitude
50      * to invalid values.
51      */
CdmaCellLocation()52     public CdmaCellLocation() {
53         this.mBaseStationId = -1;
54         this.mBaseStationLatitude = Integer.MAX_VALUE;
55         this.mBaseStationLongitude = Integer.MAX_VALUE;
56         this.mSystemId = -1;
57         this.mNetworkId = -1;
58     }
59 
60     /**
61      * Initialize the object from a bundle.
62      */
CdmaCellLocation(Bundle bundleWithValues)63     public CdmaCellLocation(Bundle bundleWithValues) {
64         this.mBaseStationId = bundleWithValues.getInt("baseStationId");
65         this.mBaseStationLatitude = bundleWithValues.getInt("baseStationLatitude");
66         this.mBaseStationLongitude = bundleWithValues.getInt("baseStationLongitude");
67         this.mSystemId = bundleWithValues.getInt("systemId");
68         this.mNetworkId = bundleWithValues.getInt("networkId");
69     }
70 
71     /**
72      * @return cdma base station identification number, -1 if unknown
73      */
getBaseStationId()74     public int getBaseStationId() {
75         return this.mBaseStationId;
76     }
77 
78     /**
79      * @return cdma base station latitude, Integer.MAX_VALUE if unknown
80      */
getBaseStationLatitude()81     public int getBaseStationLatitude() {
82         return this.mBaseStationLatitude;
83     }
84 
85     /**
86      * @return cdma base station longitude, Integer.MAX_VALUE if unknown
87      */
getBaseStationLongitude()88     public int getBaseStationLongitude() {
89         return this.mBaseStationLongitude;
90     }
91 
92     /**
93      * @return cdma system identification number, -1 if unknown
94      */
getSystemId()95     public int getSystemId() {
96         return this.mSystemId;
97     }
98 
99     /**
100      * @return cdma network identification number, -1 if unknown
101      */
getNetworkId()102     public int getNetworkId() {
103         return this.mNetworkId;
104     }
105 
106     /**
107      * Invalidate this object.  The cell location data is set to invalid values.
108      */
setStateInvalid()109     public void setStateInvalid() {
110         this.mBaseStationId = -1;
111         this.mBaseStationLatitude = Integer.MAX_VALUE;
112         this.mBaseStationLongitude = Integer.MAX_VALUE;
113         this.mSystemId = -1;
114         this.mNetworkId = -1;
115     }
116 
117     /**
118      * Set the cell location data.
119      */
setCellLocationData(int baseStationId, int baseStationLatitude, int baseStationLongitude)120      public void setCellLocationData(int baseStationId, int baseStationLatitude,
121          int baseStationLongitude) {
122          // The following values have to be written in the correct sequence
123          this.mBaseStationId = baseStationId;
124          this.mBaseStationLatitude = baseStationLatitude;   //values[2];
125          this.mBaseStationLongitude = baseStationLongitude; //values[3];
126     }
127 
128     /**
129      * Set the cell location data.
130      */
setCellLocationData(int baseStationId, int baseStationLatitude, int baseStationLongitude, int systemId, int networkId)131      public void setCellLocationData(int baseStationId, int baseStationLatitude,
132          int baseStationLongitude, int systemId, int networkId) {
133          // The following values have to be written in the correct sequence
134          this.mBaseStationId = baseStationId;
135          this.mBaseStationLatitude = baseStationLatitude;   //values[2];
136          this.mBaseStationLongitude = baseStationLongitude; //values[3];
137          this.mSystemId = systemId;
138          this.mNetworkId = networkId;
139     }
140 
141     @Override
hashCode()142     public int hashCode() {
143         return this.mBaseStationId ^ this.mBaseStationLatitude ^ this.mBaseStationLongitude
144                 ^ this.mSystemId ^ this.mNetworkId;
145     }
146 
147     @Override
equals(Object o)148     public boolean equals(Object o) {
149         CdmaCellLocation s;
150 
151         try {
152             s = (CdmaCellLocation)o;
153         } catch (ClassCastException ex) {
154             return false;
155         }
156 
157         if (o == null) {
158             return false;
159         }
160 
161         return (equalsHandlesNulls(this.mBaseStationId, s.mBaseStationId) &&
162                 equalsHandlesNulls(this.mBaseStationLatitude, s.mBaseStationLatitude) &&
163                 equalsHandlesNulls(this.mBaseStationLongitude, s.mBaseStationLongitude) &&
164                 equalsHandlesNulls(this.mSystemId, s.mSystemId) &&
165                 equalsHandlesNulls(this.mNetworkId, s.mNetworkId)
166         );
167     }
168 
169     @Override
toString()170     public String toString() {
171         return "[" + this.mBaseStationId + ","
172                    + this.mBaseStationLatitude + ","
173                    + this.mBaseStationLongitude + ","
174                    + this.mSystemId + ","
175                    + this.mNetworkId + "]";
176     }
177 
178     /**
179      * Test whether two objects hold the same data values or both are null
180      *
181      * @param a first obj
182      * @param b second obj
183      * @return true if two objects equal or both are null
184      */
equalsHandlesNulls(Object a, Object b)185     private static boolean equalsHandlesNulls(Object a, Object b) {
186         return (a == null) ? (b == null) : a.equals (b);
187     }
188 
189     /**
190      * Fill the cell location data into the intent notifier Bundle based on service state
191      *
192      * @param bundleToFill intent notifier Bundle
193      */
fillInNotifierBundle(Bundle bundleToFill)194     public void fillInNotifierBundle(Bundle bundleToFill) {
195         bundleToFill.putInt("baseStationId", this.mBaseStationId);
196         bundleToFill.putInt("baseStationLatitude", this.mBaseStationLatitude);
197         bundleToFill.putInt("baseStationLongitude", this.mBaseStationLongitude);
198         bundleToFill.putInt("systemId", this.mSystemId);
199         bundleToFill.putInt("networkId", this.mNetworkId);
200     }
201 
202 }
203 
204 
205