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