Skip to content

Commit 3666dd8

Browse files
Wink SavilleAndroid (Google) Code Review
authored andcommitted
Merge "Revise and update CellInfo API's"
2 parents f40d5cf + b208a24 commit 3666dd8

19 files changed

+2192
-406
lines changed

services/java/com/android/server/TelephonyRegistry.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import android.util.Slog;
3636

3737
import java.util.ArrayList;
38+
import java.util.List;
3839
import java.io.FileDescriptor;
3940
import java.io.PrintWriter;
4041
import java.net.NetworkInterface;
@@ -109,7 +110,7 @@ private static class Record {
109110

110111
private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
111112

112-
private CellInfo mCellInfo = null;
113+
private List<CellInfo> mCellInfo = null;
113114

114115
static final int PHONE_STATE_PERMISSION_MASK =
115116
PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
@@ -242,7 +243,7 @@ public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
242243
}
243244
if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
244245
try {
245-
r.callback.onCellInfoChanged(new CellInfo(mCellInfo));
246+
r.callback.onCellInfoChanged(mCellInfo);
246247
} catch (RemoteException ex) {
247248
remove(r.binder);
248249
}
@@ -336,7 +337,7 @@ public void notifySignalStrength(SignalStrength signalStrength) {
336337
broadcastSignalStrengthChanged(signalStrength);
337338
}
338339

339-
public void notifyCellInfo(CellInfo cellInfo) {
340+
public void notifyCellInfo(List<CellInfo> cellInfo) {
340341
if (!checkNotifyPermission("notifyCellInfo()")) {
341342
return;
342343
}
@@ -346,7 +347,7 @@ public void notifyCellInfo(CellInfo cellInfo) {
346347
for (Record r : mRecords) {
347348
if ((r.events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
348349
try {
349-
r.callback.onCellInfoChanged(new CellInfo(cellInfo));
350+
r.callback.onCellInfoChanged(cellInfo);
350351
} catch (RemoteException ex) {
351352
mRemoveList.add(r.binder);
352353
}
Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -20,70 +20,79 @@
2020
import android.os.Parcelable;
2121

2222
/**
23-
* CellIdentity is to represent ONE unique cell in the world
23+
* CellIdentity is immutable and represents ONE unique cell in the world
2424
* it contains all levels of info to identity country, carrier, etc.
2525
*
26-
* @hide pending API review
26+
* @hide
2727
*/
2828
public abstract class CellIdentity implements Parcelable {
2929

30-
// Cell is a GSM Cell {@link GsmCellIdentity}
31-
public static final int CELLID_TYPE_GSM = 1;
32-
// Cell is a CMDA Cell {@link CdmaCellIdentity}
33-
public static final int CELLID_TYPE_CDMA = 2;
34-
// Cell is a LTE Cell {@link LteCellIdentity}
35-
public static final int CELLID_TYPE_LTE = 3;
30+
// Type fields for parceling
31+
protected static final int TYPE_GSM = 1;
32+
protected static final int TYPE_CDMA = 2;
33+
protected static final int TYPE_LTE = 3;
3634

37-
private int mCellIdType;
38-
private String mCellIdAttributes;
39-
40-
protected CellIdentity(int type, String attr) {
41-
this.mCellIdType = type;
42-
this.mCellIdAttributes = new String(attr);
35+
protected CellIdentity() {
4336
}
4437

4538
protected CellIdentity(Parcel in) {
46-
this.mCellIdType = in.readInt();
47-
this.mCellIdAttributes = new String(in.readString());
4839
}
4940

5041
protected CellIdentity(CellIdentity cid) {
51-
this.mCellIdType = cid.mCellIdType;
52-
this.mCellIdAttributes = new String(cid.mCellIdAttributes);
5342
}
5443

5544
/**
56-
* @return Cell Identity type as one of CELLID_TYPE_XXXX
45+
* @return a copy of this object with package visibility.
5746
*/
58-
public int getCellIdType() {
59-
return mCellIdType;
60-
}
47+
abstract CellIdentity copy();
6148

49+
@Override
50+
public abstract int hashCode();
6251

63-
/**
64-
* @return Cell identity attribute pairs
65-
* Comma separated “key=value” pairs.
66-
    *   key := must must an single alpha-numeric word
67-
*   value := “quoted value string”
68-
*
69-
    * Current list of keys and values:
70-
    *   type = fixed | mobile
71-
*/
72-
public String getCellIdAttributes() {
73-
return mCellIdAttributes;
52+
@Override
53+
public boolean equals(Object other) {
54+
if (other == null) {
55+
return false;
56+
}
57+
if (this == other) {
58+
return true;
59+
}
60+
return (other instanceof CellIdentity);
7461
}
7562

63+
@Override
64+
public String toString() {
65+
return "";
66+
}
7667

77-
/** Implement the Parcelable interface {@hide} */
68+
/** Implement the Parcelable interface */
7869
@Override
7970
public int describeContents() {
8071
return 0;
8172
}
8273

83-
/** Implement the Parcelable interface {@hide} */
74+
/** Implement the Parcelable interface */
8475
@Override
8576
public void writeToParcel(Parcel dest, int flags) {
86-
dest.writeInt(mCellIdType);
87-
dest.writeString(mCellIdAttributes);
8877
}
78+
79+
/** Implement the Parcelable interface */
80+
public static final Creator<CellIdentity> CREATOR =
81+
new Creator<CellIdentity>() {
82+
@Override
83+
public CellIdentity createFromParcel(Parcel in) {
84+
int type = in.readInt();
85+
switch (type) {
86+
case TYPE_GSM: return CellIdentityGsm.createFromParcelBody(in);
87+
case TYPE_CDMA: return CellIdentityCdma.createFromParcelBody(in);
88+
case TYPE_LTE: return CellIdentityLte.createFromParcelBody(in);
89+
default: throw new RuntimeException("Bad CellIdentity Parcel");
90+
}
91+
}
92+
93+
@Override
94+
public CellIdentity[] newArray(int size) {
95+
return new CellIdentity[size];
96+
}
97+
};
8998
}

telephony/java/android/telephony/CdmaCellIdentity.java renamed to telephony/java/android/telephony/CellIdentityCdma.java

Lines changed: 102 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -18,13 +18,18 @@
1818

1919
import android.os.Parcel;
2020
import 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

Comments
 (0)