1 /* 2 * Copyright (C) 2012 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; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 import android.telephony.Rlog; 22 23 /** 24 * CellIdentity is to represent a unique CDMA cell 25 */ 26 public final class CellIdentityCdma implements Parcelable { 27 28 private static final String LOG_TAG = "CellSignalStrengthCdma"; 29 private static final boolean DBG = false; 30 31 // Network Id 0..65535 32 private final int mNetworkId; 33 // CDMA System Id 0..32767 34 private final int mSystemId; 35 // Base Station Id 0..65535 36 private final int mBasestationId; 37 /** 38 * Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. 39 * It is represented in units of 0.25 seconds and ranges from -2592000 40 * to 2592000, both values inclusive (corresponding to a range of -180 41 * to +180 degrees). 42 */ 43 private final int mLongitude; 44 /** 45 * Latitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. 46 * It is represented in units of 0.25 seconds and ranges from -1296000 47 * to 1296000, both values inclusive (corresponding to a range of -90 48 * to +90 degrees). 49 */ 50 private final int mLatitude; 51 52 /** 53 * @hide 54 */ CellIdentityCdma()55 public CellIdentityCdma() { 56 mNetworkId = Integer.MAX_VALUE; 57 mSystemId = Integer.MAX_VALUE; 58 mBasestationId = Integer.MAX_VALUE; 59 mLongitude = Integer.MAX_VALUE; 60 mLatitude = Integer.MAX_VALUE; 61 } 62 63 /** 64 * public constructor 65 * @param nid Network Id 0..65535 66 * @param sid CDMA System Id 0..32767 67 * @param bid Base Station Id 0..65535 68 * @param lon Longitude is a decimal number ranges from -2592000 69 * to 2592000 70 * @param lat Latitude is a decimal number ranges from -1296000 71 * to 1296000 72 * 73 * @hide 74 */ CellIdentityCdma(int nid, int sid, int bid, int lon, int lat)75 public CellIdentityCdma (int nid, int sid, int bid, int lon, int lat) { 76 mNetworkId = nid; 77 mSystemId = sid; 78 mBasestationId = bid; 79 mLongitude = lon; 80 mLatitude = lat; 81 } 82 CellIdentityCdma(CellIdentityCdma cid)83 private CellIdentityCdma(CellIdentityCdma cid) { 84 mNetworkId = cid.mNetworkId; 85 mSystemId = cid.mSystemId; 86 mBasestationId = cid.mBasestationId; 87 mLongitude = cid.mLongitude; 88 mLatitude = cid.mLatitude; 89 } 90 copy()91 CellIdentityCdma copy() { 92 return new CellIdentityCdma(this); 93 } 94 95 /** 96 * @return Network Id 0..65535, Integer.MAX_VALUE if unknown 97 */ getNetworkId()98 public int getNetworkId() { 99 return mNetworkId; 100 } 101 102 /** 103 * @return System Id 0..32767, Integer.MAX_VALUE if unknown 104 */ getSystemId()105 public int getSystemId() { 106 return mSystemId; 107 } 108 109 /** 110 * @return Base Station Id 0..65535, Integer.MAX_VALUE if unknown 111 */ getBasestationId()112 public int getBasestationId() { 113 return mBasestationId; 114 } 115 116 /** 117 * @return Base station longitude, which is a decimal number as 118 * specified in 3GPP2 C.S0005-A v6.0. It is represented in units 119 * of 0.25 seconds and ranges from -2592000 to 2592000, both 120 * values inclusive (corresponding to a range of -180 121 * to +180 degrees). Integer.MAX_VALUE if unknown. 122 */ getLongitude()123 public int getLongitude() { 124 return mLongitude; 125 } 126 127 /** 128 * @return Base station latitude, which is a decimal number as 129 * specified in 3GPP2 C.S0005-A v6.0. It is represented in units 130 * of 0.25 seconds and ranges from -1296000 to 1296000, both 131 * values inclusive (corresponding to a range of -90 132 * to +90 degrees). Integer.MAX_VALUE if unknown. 133 */ getLatitude()134 public int getLatitude() { 135 return mLatitude; 136 } 137 138 @Override hashCode()139 public int hashCode() { 140 int primeNum = 31; 141 return (mNetworkId * primeNum) + (mSystemId * primeNum) + (mBasestationId * primeNum) + 142 (mLatitude * primeNum) + (mLongitude * primeNum); 143 } 144 145 @Override equals(Object other)146 public boolean equals(Object other) { 147 if (super.equals(other)) { 148 try { 149 CellIdentityCdma o = (CellIdentityCdma)other; 150 return mNetworkId == o.mNetworkId && 151 mSystemId == o.mSystemId && 152 mBasestationId == o.mBasestationId && 153 mLatitude == o.mLatitude && 154 mLongitude == o.mLongitude; 155 } catch (ClassCastException e) { 156 return false; 157 } 158 } else { 159 return false; 160 } 161 } 162 163 @Override toString()164 public String toString() { 165 StringBuilder sb = new StringBuilder("CellIdentityCdma:{"); 166 sb.append(" mNetworkId="); sb.append(mNetworkId); 167 sb.append(" mSystemId="); sb.append(mSystemId); 168 sb.append(" mBasestationId="); sb.append(mBasestationId); 169 sb.append(" mLongitude="); sb.append(mLongitude); 170 sb.append(" mLatitude="); sb.append(mLatitude); 171 sb.append("}"); 172 173 return sb.toString(); 174 } 175 176 /** Implement the Parcelable interface */ 177 @Override describeContents()178 public int describeContents() { 179 return 0; 180 } 181 182 /** Implement the Parcelable interface */ 183 @Override writeToParcel(Parcel dest, int flags)184 public void writeToParcel(Parcel dest, int flags) { 185 if (DBG) log("writeToParcel(Parcel, int): " + toString()); 186 dest.writeInt(mNetworkId); 187 dest.writeInt(mSystemId); 188 dest.writeInt(mBasestationId); 189 dest.writeInt(mLongitude); 190 dest.writeInt(mLatitude); 191 } 192 193 /** Construct from Parcel, type has already been processed */ CellIdentityCdma(Parcel in)194 private CellIdentityCdma(Parcel in) { 195 mNetworkId = in.readInt(); 196 mSystemId = in.readInt(); 197 mBasestationId = in.readInt(); 198 mLongitude = in.readInt(); 199 mLatitude = in.readInt(); 200 if (DBG) log("CellIdentityCdma(Parcel): " + toString()); 201 } 202 203 /** Implement the Parcelable interface */ 204 @SuppressWarnings("hiding") 205 public static final Creator<CellIdentityCdma> CREATOR = 206 new Creator<CellIdentityCdma>() { 207 @Override 208 public CellIdentityCdma createFromParcel(Parcel in) { 209 return new CellIdentityCdma(in); 210 } 211 212 @Override 213 public CellIdentityCdma[] newArray(int size) { 214 return new CellIdentityCdma[size]; 215 } 216 }; 217 218 /** 219 * log 220 */ log(String s)221 private static void log(String s) { 222 Rlog.w(LOG_TAG, s); 223 } 224 } 225