11/*
2- * Copyright (C) 2008 The Android Open Source Project
2+ * Copyright (C) 2012 The Android Open Source Project
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1818
1919import android .os .Parcel ;
2020import android .os .Parcelable ;
21+ import android .util .Log ;
2122
2223/**
2324 * CellIdentity is to represent a unique CDMA cell
2425 *
25- * @hide pending API review
26+ * @hide
2627 */
27- public final class CdmaCellIdentity extends CellIdentity implements Parcelable {
28+ public final class CellIdentityCdma extends CellIdentity implements Parcelable {
29+
30+ private static final String LOG_TAG = "CellSignalStrengthCdma" ;
31+ private static final boolean DBG = false ;
32+
2833 // Network Id 0..65535
2934 private final int mNetworkId ;
3035 // CDMA System Id 0..32767
@@ -46,6 +51,17 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable {
4651 */
4752 private final int mLatitude ;
4853
54+ /**
55+ * @hide
56+ */
57+ public CellIdentityCdma () {
58+ mNetworkId = Integer .MAX_VALUE ;
59+ mSystemId = Integer .MAX_VALUE ;
60+ mBasestationId = Integer .MAX_VALUE ;
61+ mLongitude = Integer .MAX_VALUE ;
62+ mLatitude = Integer .MAX_VALUE ;
63+ }
64+
4965 /**
5066 * public constructor
5167 * @param nid Network Id 0..65535
@@ -55,28 +71,18 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable {
5571 * to 2592000
5672 * @param lat Latitude is a decimal number ranges from -1296000
5773 * to 1296000
58- * @param attr is comma separated “key=value” attribute pairs.
74+ *
75+ * @hide
5976 */
60- public CdmaCellIdentity (int nid , int sid ,
61- int bid , int lon , int lat , String attr ) {
62- super (CELLID_TYPE_CDMA , attr );
77+ public CellIdentityCdma (int nid , int sid , int bid , int lon , int lat ) {
6378 mNetworkId = nid ;
6479 mSystemId = sid ;
6580 mBasestationId = bid ;
6681 mLongitude = lon ;
6782 mLatitude = lat ;
6883 }
6984
70- private CdmaCellIdentity (Parcel in ) {
71- super (in );
72- mNetworkId = in .readInt ();
73- mSystemId = in .readInt ();
74- mBasestationId = in .readInt ();
75- mLongitude = in .readInt ();
76- mLatitude = in .readInt ();
77- }
78-
79- CdmaCellIdentity (CdmaCellIdentity cid ) {
85+ private CellIdentityCdma (CellIdentityCdma cid ) {
8086 super (cid );
8187 mNetworkId = cid .mNetworkId ;
8288 mSystemId = cid .mSystemId ;
@@ -85,6 +91,11 @@ private CdmaCellIdentity(Parcel in) {
8591 mLatitude = cid .mLatitude ;
8692 }
8793
94+ @ Override
95+ CellIdentityCdma copy () {
96+ return new CellIdentityCdma (this );
97+ }
98+
8899 /**
89100 * @return Network Id 0..65535
90101 */
@@ -117,9 +128,6 @@ public int getLongitude() {
117128 return mLongitude ;
118129 }
119130
120- /**
121- * @return Base station
122- */
123131 /**
124132 * @return Base station latitude, which is a decimal number as
125133 * specified in 3GPP2 C.S0005-A v6.0. It is represented in units
@@ -131,15 +139,55 @@ public int getLatitude() {
131139 return mLatitude ;
132140 }
133141
134- /** Implement the Parcelable interface {@hide} */
142+ @ Override
143+ public int hashCode () {
144+ int primeNum = 31 ;
145+ return (mNetworkId * primeNum ) + (mSystemId * primeNum ) + (mBasestationId * primeNum ) +
146+ (mLatitude * primeNum ) + (mLongitude * primeNum );
147+ }
148+
149+ @ Override
150+ public boolean equals (Object other ) {
151+ if (super .equals (other )) {
152+ try {
153+ CellIdentityCdma o = (CellIdentityCdma )other ;
154+ return mNetworkId == o .mNetworkId &&
155+ mSystemId == o .mSystemId &&
156+ mBasestationId == o .mBasestationId &&
157+ mLatitude == o .mLatitude &&
158+ mLongitude == o .mLongitude ;
159+ } catch (ClassCastException e ) {
160+ return false ;
161+ }
162+ } else {
163+ return false ;
164+ }
165+ }
166+
167+ @ Override
168+ public String toString () {
169+ StringBuilder sb = new StringBuilder ("CdmaCellIdentitiy:" );
170+ sb .append (super .toString ());
171+ sb .append (" mNetworkId=" ); sb .append (mNetworkId );
172+ sb .append (" mSystemId=" ); sb .append (mSystemId );
173+ sb .append (" mBasestationId=" ); sb .append (mBasestationId );
174+ sb .append (" mLongitude=" ); sb .append (mLongitude );
175+ sb .append (" mLatitude=" ); sb .append (mLatitude );
176+
177+ return sb .toString ();
178+ }
179+
180+ /** Implement the Parcelable interface */
135181 @ Override
136182 public int describeContents () {
137183 return 0 ;
138184 }
139185
140- /** Implement the Parcelable interface {@hide} */
186+ /** Implement the Parcelable interface */
141187 @ Override
142188 public void writeToParcel (Parcel dest , int flags ) {
189+ if (DBG ) log ("writeToParcel(Parcel, int): " + toString ());
190+ dest .writeInt (TYPE_CDMA );
143191 super .writeToParcel (dest , flags );
144192 dest .writeInt (mNetworkId );
145193 dest .writeInt (mSystemId );
@@ -148,17 +196,42 @@ public void writeToParcel(Parcel dest, int flags) {
148196 dest .writeInt (mLatitude );
149197 }
150198
151- /** Implement the Parcelable interface {@hide} */
152- public static final Creator <CdmaCellIdentity > CREATOR =
153- new Creator <CdmaCellIdentity >() {
199+ /** Construct from Parcel, type has already been processed */
200+ private CellIdentityCdma (Parcel in ) {
201+ super (in );
202+ mNetworkId = in .readInt ();
203+ mSystemId = in .readInt ();
204+ mBasestationId = in .readInt ();
205+ mLongitude = in .readInt ();
206+ mLatitude = in .readInt ();
207+ if (DBG ) log ("CellIdentityCdma(Parcel): " + toString ());
208+ }
209+
210+ /** Implement the Parcelable interface */
211+ @ SuppressWarnings ("hiding" )
212+ public static final Creator <CellIdentityCdma > CREATOR =
213+ new Creator <CellIdentityCdma >() {
154214 @ Override
155- public CdmaCellIdentity createFromParcel (Parcel in ) {
156- return new CdmaCellIdentity (in );
215+ public CellIdentityCdma createFromParcel (Parcel in ) {
216+ in .readInt (); // Skip past token, we know what it is
217+ return createFromParcelBody (in );
157218 }
158219
159220 @ Override
160- public CdmaCellIdentity [] newArray (int size ) {
161- return new CdmaCellIdentity [size ];
221+ public CellIdentityCdma [] newArray (int size ) {
222+ return new CellIdentityCdma [size ];
162223 }
163224 };
225+
226+ /** @hide */
227+ static CellIdentityCdma createFromParcelBody (Parcel in ) {
228+ return new CellIdentityCdma (in );
229+ }
230+
231+ /**
232+ * log
233+ */
234+ private static void log (String s ) {
235+ Log .w (LOG_TAG , s );
236+ }
164237}
0 commit comments