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