diff options
author | johnwang <johnwang@google.com> | 2009-09-11 19:17:29 -0700 |
---|---|---|
committer | johnwang <johnwang@google.com> | 2009-09-25 12:17:46 -0700 |
commit | 9c118c80fd0a5416051f2a49f515301f2cf3fd6f (patch) | |
tree | e84d65f2236b2e4e8064a3385a6556fcd8f28e37 /telephony/java/android | |
parent | a0cad2f5d19d95cfe496ebb82f3227dd4ed7c169 (diff) | |
download | frameworks_base-9c118c80fd0a5416051f2a49f515301f2cf3fd6f.zip frameworks_base-9c118c80fd0a5416051f2a49f515301f2cf3fd6f.tar.gz frameworks_base-9c118c80fd0a5416051f2a49f515301f2cf3fd6f.tar.bz2 |
Update CID in NeighboringCellInfo
NeighboringCellInfo works in GSM and UMTS network.
In GSM network, the locaiton value is the combination of LAC and CID.
In UMTS network, the locaiton value is PSC code.
NeighboringCellInfo should access and store those two values seperately.
It involves the change of Public API.
1. Add new API getRadioType(), getLac(), and getPsc() to get location info in GSM and UMTS.
2. Deprecate setCid() and NeighboringCellInfo(int cid) because cid is set by interpreting network type.
Diffstat (limited to 'telephony/java/android')
-rw-r--r-- | telephony/java/android/telephony/NeighboringCellInfo.java | 182 | ||||
-rw-r--r-- | telephony/java/android/telephony/TelephonyManager.java | 14 |
2 files changed, 180 insertions, 16 deletions
diff --git a/telephony/java/android/telephony/NeighboringCellInfo.java b/telephony/java/android/telephony/NeighboringCellInfo.java index f492abd..d698169 100644 --- a/telephony/java/android/telephony/NeighboringCellInfo.java +++ b/telephony/java/android/telephony/NeighboringCellInfo.java @@ -18,6 +18,15 @@ package android.telephony; import android.os.Parcel; import android.os.Parcelable; +import static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN; +import static android.telephony.TelephonyManager.NETWORK_TYPE_EDGE; +import static android.telephony.TelephonyManager.NETWORK_TYPE_GPRS; +import static android.telephony.TelephonyManager.NETWORK_TYPE_UMTS; +import static android.telephony.TelephonyManager.NETWORK_TYPE_HSDPA; +import static android.telephony.TelephonyManager.NETWORK_TYPE_HSUPA; +import static android.telephony.TelephonyManager.NETWORK_TYPE_HSPA; + + /** * Represents the neighboring cell information, including @@ -34,19 +43,53 @@ public class NeighboringCellInfo implements Parcelable */ static final public int UNKNOWN_CID = -1; + /** + * In GSM, mRssi is the Received RSSI; + * In UMTS, mRssi is the Level index of CPICH Received Signal Code Power + */ private int mRssi; + /** + * CID in 16 bits format in GSM. Return UNKNOWN_CID in UMTS and CMDA. + */ private int mCid; + /** + * LAC in 16 bits format in GSM. Return UNKNOWN_CID in UMTS and CMDA. + */ + private int mLac; + /** + * Primary Scrambling Code in 9 bits format in UMTS + * Return UNKNOWN_CID in GSM and CMDA. + */ + private int mPsc; + /** + * Radio network type, value is one of following + * TelephonyManager.NETWORK_TYPE_XXXXXX. + */ + private int mNetworkType; /** + * @deprecated * Empty constructor. Initializes the RSSI and CID. + * + * NeighboringCellInfo is one time shot for the neighboring cells based on + * the radio network type at that moment. Its constructor needs radio network + * type. */ public NeighboringCellInfo() { mRssi = UNKNOWN_RSSI; + mLac = UNKNOWN_CID; mCid = UNKNOWN_CID; + mPsc = UNKNOWN_CID; + mNetworkType = NETWORK_TYPE_UNKNOWN; } /** + * @deprecated * Initialize the object from rssi and cid. + * + * NeighboringCellInfo is one time shot for the neighboring cells based on + * the radio network type at that moment. Its constructor needs radio network + * type. */ public NeighboringCellInfo(int rssi, int cid) { mRssi = rssi; @@ -54,40 +97,148 @@ public class NeighboringCellInfo implements Parcelable } /** + * @hide + * Initialize the object from rssi, location string, and radioType + * radioType is one of following + * {@link TelephonyManager#NETWORK_TYPE_GPRS TelephonyManager.NETWORK_TYPE_GPRS}, + * {@link TelephonyManager#NETWORK_TYPE_EDGE TelephonyManager.NETWORK_TYPE_EDGE}, + * {@link TelephonyManager#NETWORK_TYPE_UMTS TelephonyManager.NETWORK_TYPE_UMTS}, + * {@link TelephonyManager#NETWORK_TYPE_HSDPA TelephonyManager.NETWORK_TYPE_HSDPA}, + * {@link TelephonyManager#NETWORK_TYPE_HSUPA TelephonyManager.NETWORK_TYPE_HSUPA}, + * and {@link TelephonyManager#NETWORK_TYPE_HSPA TelephonyManager.NETWORK_TYPE_HSPA}. + */ + public NeighboringCellInfo(int rssi, String location, int radioType) { + // set default value + mRssi = rssi; + mNetworkType = NETWORK_TYPE_UNKNOWN; + mPsc = UNKNOWN_CID; + mLac = UNKNOWN_CID; + mCid = UNKNOWN_CID; + + + // pad location string with leading "0" + int l = location.length(); + if (l > 8) return; + if (l < 8) { + for (int i = 0; i < (8-l); i++) { + location = "0" + location; + } + } + + try {// set LAC/CID or PSC based on radioType + switch (radioType) { + case NETWORK_TYPE_GPRS: + case NETWORK_TYPE_EDGE: + mNetworkType = radioType; + mLac = Integer.valueOf(location.substring(0, 4), 16); + mCid = Integer.valueOf(location.substring(4), 16); + break; + case NETWORK_TYPE_UMTS: + case NETWORK_TYPE_HSDPA: + case NETWORK_TYPE_HSUPA: + case NETWORK_TYPE_HSPA: + mNetworkType = radioType; + mPsc = Integer.valueOf(location, 16); + break; + } + } catch (NumberFormatException e) { + // parsing location error + mPsc = UNKNOWN_CID; + mLac = UNKNOWN_CID; + mCid = UNKNOWN_CID; + mNetworkType = NETWORK_TYPE_UNKNOWN; + } + } + + /** * Initialize the object from a parcel. */ public NeighboringCellInfo(Parcel in) { mRssi = in.readInt(); + mLac = in.readInt(); mCid = in.readInt(); + mPsc = in.readInt(); + mNetworkType = in.readInt(); } /** - * @return received signal strength in "asu", ranging from 0 - 31, - * or UNKNOWN_RSSI if unknown + * @return received signal strength or UNKNOWN_RSSI if unknown * - * For GSM, dBm = -113 + 2*asu, + * For GSM, it is in "asu" ranging from 0 to 31 (dBm = -113 + 2*asu) * 0 means "-113 dBm or less" and 31 means "-51 dBm or greater" + * For UMTS, it is the Level index of CPICH RSCP defined in TS 25.125 */ public int getRssi() { return mRssi; } /** - * @return cell id, UNKNOWN_CID if unknown, 0xffffffff max legal value + * @return LAC in GSM, 0xffff max legal value + * UNKNOWN_CID if in UMTS or CMDA or unknown + */ + public int getLac() { + return mLac; + } + + /** + * @return cell id in GSM, 0xffff max legal value + * UNKNOWN_CID if in UMTS or CDMA or unknown */ public int getCid() { return mCid; } /** + * @return Primary Scrambling Code in 9 bits format in UMTS, 0x1ff max value + * UNKNOWN_CID if in GSM or CMDA or unknown + */ + public int getPsc() { + return mPsc; + } + + /** + * @return Radio network type while neighboring cell location is stored. + * + * Return {@link TelephonyManager#NETWORK_TYPE_UNKNOWN TelephonyManager.NETWORK_TYPE_UNKNOWN} + * means that the location information is unavailable. + * + * Return {@link TelephonyManager#NETWORK_TYPE_GPRS TelephonyManager.NETWORK_TYPE_GPRS} or + * {@link TelephonyManager#NETWORK_TYPE_EDGE TelephonyManager.NETWORK_TYPE_EDGE} + * means that Neighboring Cell information is stored for GSM network, in + * which {@link NeighboringCellInfo#getLac NeighboringCellInfo.getLac} and + * {@link NeighboringCellInfo#getCid NeighboringCellInfo.getCid} should be + * called to access location. + * + * Return {@link TelephonyManager#NETWORK_TYPE_UMTS TelephonyManager.NETWORK_TYPE_UMTS}, + * {@link TelephonyManager#NETWORK_TYPE_HSDPA TelephonyManager.NETWORK_TYPE_HSDPA}, + * {@link TelephonyManager#NETWORK_TYPE_HSUPA TelephonyManager.NETWORK_TYPE_HSUPA}, + * or {@link TelephonyManager#NETWORK_TYPE_HSPA TelephonyManager.NETWORK_TYPE_HSPA} + * means that Neighboring Cell information is stored for UMTS network, in + * which {@link NeighboringCellInfo#getPsc NeighboringCellInfo.getPsc} + * should be called to access location. + */ + public int getNetworkType() { + return mNetworkType; + } + /** + * @deprecated * Set the cell id. + * + * NeighboringCellInfo is a one time shot for the neighboring cells based on + * the radio network type at that moment. It shouldn't be changed after + * creation. */ public void setCid(int cid) { mCid = cid; } /** + * @deprecated * Set the signal strength of the cell. + * + * NeighboringCellInfo is a one time shot for the neighboring cells based on + * the radio network type at that moment. It shouldn't be changed after + * creation. */ public void setRssi(int rssi) { mRssi = rssi; @@ -95,8 +246,20 @@ public class NeighboringCellInfo implements Parcelable @Override public String toString() { - return "["+ ((mCid == UNKNOWN_CID) ? "/" : Integer.toHexString(mCid)) - + " at " + ((mRssi == UNKNOWN_RSSI)? "/" : mRssi) + "]"; + StringBuilder sb = new StringBuilder(); + + sb.append("["); + if (mPsc != UNKNOWN_CID) { + sb.append(Integer.toHexString(mPsc)) + .append("@").append(((mRssi == UNKNOWN_RSSI)? "-" : mRssi)); + } else if(mLac != UNKNOWN_CID && mCid != UNKNOWN_CID) { + sb.append(Integer.toHexString(mLac)) + .append(Integer.toHexString(mCid)) + .append("@").append(((mRssi == UNKNOWN_RSSI)? "-" : mRssi)); + } + sb.append("]"); + + return sb.toString(); } public int describeContents() { @@ -105,7 +268,10 @@ public class NeighboringCellInfo implements Parcelable public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mRssi); + dest.writeInt(mLac); dest.writeInt(mCid); + dest.writeInt(mPsc); + dest.writeInt(mNetworkType); } public static final Parcelable.Creator<NeighboringCellInfo> CREATOR @@ -118,6 +284,4 @@ public class NeighboringCellInfo implements Parcelable return new NeighboringCellInfo[size]; } }; -} - - +}
\ No newline at end of file diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 6664b08..fb96b2a 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -254,13 +254,13 @@ public class TelephonyManager { * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES} */ public List<NeighboringCellInfo> getNeighboringCellInfo() { - try { - return getITelephony().getNeighboringCellInfo(); - } catch (RemoteException ex) { - return null; - } catch (NullPointerException ex) { - return null; - } + try { + return getITelephony().getNeighboringCellInfo(); + } catch (RemoteException ex) { + return null; + } catch (NullPointerException ex) { + return null; + } } /** No phone radio. */ |