Loading services/java/com/android/server/TelephonyRegistry.java +5 −4 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.text.TextUtils; import android.util.Slog; import java.util.ArrayList; import java.util.List; import java.io.FileDescriptor; import java.io.PrintWriter; import java.net.NetworkInterface; Loading Loading @@ -109,7 +110,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN; private CellInfo mCellInfo = null; private List<CellInfo> mCellInfo = null; static final int PHONE_STATE_PERMISSION_MASK = PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR | Loading Loading @@ -242,7 +243,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { try { r.callback.onCellInfoChanged(new CellInfo(mCellInfo)); r.callback.onCellInfoChanged(mCellInfo); } catch (RemoteException ex) { remove(r.binder); } Loading Loading @@ -336,7 +337,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { broadcastSignalStrengthChanged(signalStrength); } public void notifyCellInfo(CellInfo cellInfo) { public void notifyCellInfo(List<CellInfo> cellInfo) { if (!checkNotifyPermission("notifyCellInfo()")) { return; } Loading @@ -346,7 +347,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { for (Record r : mRecords) { if ((r.events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { try { r.callback.onCellInfoChanged(new CellInfo(cellInfo)); r.callback.onCellInfoChanged(cellInfo); } catch (RemoteException ex) { mRemoveList.add(r.binder); } Loading telephony/java/android/telephony/CellIdentity.java +47 −38 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -20,70 +20,79 @@ import android.os.Parcel; import android.os.Parcelable; /** * CellIdentity is to represent ONE unique cell in the world * CellIdentity is immutable and represents ONE unique cell in the world * it contains all levels of info to identity country, carrier, etc. * * @hide pending API review * @hide */ public abstract class CellIdentity implements Parcelable { // Cell is a GSM Cell {@link GsmCellIdentity} public static final int CELLID_TYPE_GSM = 1; // Cell is a CMDA Cell {@link CdmaCellIdentity} public static final int CELLID_TYPE_CDMA = 2; // Cell is a LTE Cell {@link LteCellIdentity} public static final int CELLID_TYPE_LTE = 3; // Type fields for parceling protected static final int TYPE_GSM = 1; protected static final int TYPE_CDMA = 2; protected static final int TYPE_LTE = 3; private int mCellIdType; private String mCellIdAttributes; protected CellIdentity(int type, String attr) { this.mCellIdType = type; this.mCellIdAttributes = new String(attr); protected CellIdentity() { } protected CellIdentity(Parcel in) { this.mCellIdType = in.readInt(); this.mCellIdAttributes = new String(in.readString()); } protected CellIdentity(CellIdentity cid) { this.mCellIdType = cid.mCellIdType; this.mCellIdAttributes = new String(cid.mCellIdAttributes); } /** * @return Cell Identity type as one of CELLID_TYPE_XXXX * @return a copy of this object with package visibility. */ public int getCellIdType() { return mCellIdType; } abstract CellIdentity copy(); @Override public abstract int hashCode(); /** * @return Cell identity attribute pairs * Comma separated “key=value” pairs. * key := must must an single alpha-numeric word * value := “quoted value string” * * Current list of keys and values: * type = fixed | mobile */ public String getCellIdAttributes() { return mCellIdAttributes; @Override public boolean equals(Object other) { if (other == null) { return false; } if (this == other) { return true; } return (other instanceof CellIdentity); } @Override public String toString() { return ""; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public int describeContents() { return 0; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mCellIdType); dest.writeString(mCellIdAttributes); } /** Implement the Parcelable interface */ public static final Creator<CellIdentity> CREATOR = new Creator<CellIdentity>() { @Override public CellIdentity createFromParcel(Parcel in) { int type = in.readInt(); switch (type) { case TYPE_GSM: return CellIdentityGsm.createFromParcelBody(in); case TYPE_CDMA: return CellIdentityCdma.createFromParcelBody(in); case TYPE_LTE: return CellIdentityLte.createFromParcelBody(in); default: throw new RuntimeException("Bad CellIdentity Parcel"); } } @Override public CellIdentity[] newArray(int size) { return new CellIdentity[size]; } }; } telephony/java/android/telephony/CdmaCellIdentity.java→telephony/java/android/telephony/CellIdentityCdma.java +102 −29 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -18,13 +18,18 @@ package android.telephony; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; /** * CellIdentity is to represent a unique CDMA cell * * @hide pending API review * @hide */ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { public final class CellIdentityCdma extends CellIdentity implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthCdma"; private static final boolean DBG = false; // Network Id 0..65535 private final int mNetworkId; // CDMA System Id 0..32767 Loading @@ -46,6 +51,17 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { */ private final int mLatitude; /** * @hide */ public CellIdentityCdma() { mNetworkId = Integer.MAX_VALUE; mSystemId = Integer.MAX_VALUE; mBasestationId = Integer.MAX_VALUE; mLongitude = Integer.MAX_VALUE; mLatitude = Integer.MAX_VALUE; } /** * public constructor * @param nid Network Id 0..65535 Loading @@ -55,11 +71,10 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { * to 2592000 * @param lat Latitude is a decimal number ranges from -1296000 * to 1296000 * @param attr is comma separated “key=value” attribute pairs. * * @hide */ public CdmaCellIdentity (int nid, int sid, int bid, int lon, int lat, String attr) { super(CELLID_TYPE_CDMA, attr); public CellIdentityCdma (int nid, int sid, int bid, int lon, int lat) { mNetworkId = nid; mSystemId = sid; mBasestationId = bid; Loading @@ -67,16 +82,7 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { mLatitude = lat; } private CdmaCellIdentity(Parcel in) { super(in); mNetworkId = in.readInt(); mSystemId = in.readInt(); mBasestationId = in.readInt(); mLongitude = in.readInt(); mLatitude = in.readInt(); } CdmaCellIdentity(CdmaCellIdentity cid) { private CellIdentityCdma(CellIdentityCdma cid) { super(cid); mNetworkId = cid.mNetworkId; mSystemId = cid.mSystemId; Loading @@ -85,6 +91,11 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { mLatitude = cid.mLatitude; } @Override CellIdentityCdma copy() { return new CellIdentityCdma(this); } /** * @return Network Id 0..65535 */ Loading Loading @@ -117,9 +128,6 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { return mLongitude; } /** * @return Base station */ /** * @return Base station latitude, which is a decimal number as * specified in 3GPP2 C.S0005-A v6.0. It is represented in units Loading @@ -131,15 +139,55 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { return mLatitude; } /** Implement the Parcelable interface {@hide} */ @Override public int hashCode() { int primeNum = 31; return (mNetworkId * primeNum) + (mSystemId * primeNum) + (mBasestationId * primeNum) + (mLatitude * primeNum) + (mLongitude * primeNum); } @Override public boolean equals(Object other) { if (super.equals(other)) { try { CellIdentityCdma o = (CellIdentityCdma)other; return mNetworkId == o.mNetworkId && mSystemId == o.mSystemId && mBasestationId == o.mBasestationId && mLatitude == o.mLatitude && mLongitude == o.mLongitude; } catch (ClassCastException e) { return false; } } else { return false; } } @Override public String toString() { StringBuilder sb = new StringBuilder("CdmaCellIdentitiy:"); sb.append(super.toString()); sb.append(" mNetworkId="); sb.append(mNetworkId); sb.append(" mSystemId="); sb.append(mSystemId); sb.append(" mBasestationId="); sb.append(mBasestationId); sb.append(" mLongitude="); sb.append(mLongitude); sb.append(" mLatitude="); sb.append(mLatitude); return sb.toString(); } /** Implement the Parcelable interface */ @Override public int describeContents() { return 0; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); dest.writeInt(TYPE_CDMA); super.writeToParcel(dest, flags); dest.writeInt(mNetworkId); dest.writeInt(mSystemId); Loading @@ -148,17 +196,42 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { dest.writeInt(mLatitude); } /** Implement the Parcelable interface {@hide} */ public static final Creator<CdmaCellIdentity> CREATOR = new Creator<CdmaCellIdentity>() { /** Construct from Parcel, type has already been processed */ private CellIdentityCdma(Parcel in) { super(in); mNetworkId = in.readInt(); mSystemId = in.readInt(); mBasestationId = in.readInt(); mLongitude = in.readInt(); mLatitude = in.readInt(); if (DBG) log("CellIdentityCdma(Parcel): " + toString()); } /** Implement the Parcelable interface */ @SuppressWarnings("hiding") public static final Creator<CellIdentityCdma> CREATOR = new Creator<CellIdentityCdma>() { @Override public CdmaCellIdentity createFromParcel(Parcel in) { return new CdmaCellIdentity(in); public CellIdentityCdma createFromParcel(Parcel in) { in.readInt(); // Skip past token, we know what it is return createFromParcelBody(in); } @Override public CdmaCellIdentity[] newArray(int size) { return new CdmaCellIdentity[size]; public CellIdentityCdma[] newArray(int size) { return new CellIdentityCdma[size]; } }; /** @hide */ static CellIdentityCdma createFromParcelBody(Parcel in) { return new CellIdentityCdma(in); } /** * log */ private static void log(String s) { Log.w(LOG_TAG, s); } } telephony/java/android/telephony/GsmCellIdentity.java→telephony/java/android/telephony/CellIdentityGsm.java +100 −26 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -18,13 +18,17 @@ package android.telephony; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; /** * CellIdentity to represent a unique GSM or UMTS cell * * @hide pending API review * @hide */ public final class GsmCellIdentity extends CellIdentity implements Parcelable { public final class CellIdentityGsm extends CellIdentity implements Parcelable { private static final String LOG_TAG = "CellIdentityGsm"; private static final boolean DBG = false; // 3-digit Mobile Country Code, 0..999 private final int mMcc; Loading @@ -38,6 +42,16 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { // 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511 private final int mPsc; /** * @hide */ public CellIdentityGsm() { mMcc = Integer.MAX_VALUE; mMnc = Integer.MAX_VALUE; mLac = Integer.MAX_VALUE; mCid = Integer.MAX_VALUE; mPsc = Integer.MAX_VALUE; } /** * public constructor * @param mcc 3-digit Mobile Country Code, 0..999 Loading @@ -45,11 +59,10 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { * @param lac 16-bit Location Area Code, 0..65535 * @param cid 16-bit GSM Cell Identity or 28-bit UMTS Cell Identity * @param psc 9-bit UMTS Primary Scrambling Code * @param attr is comma separated “key=value” attribute pairs. * * @hide */ public GsmCellIdentity (int mcc, int mnc, int lac, int cid, int psc, String attr) { super(CELLID_TYPE_GSM, attr); public CellIdentityGsm (int mcc, int mnc, int lac, int cid, int psc) { mMcc = mcc; mMnc = mnc; mLac = lac; Loading @@ -57,16 +70,7 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { mPsc = psc; } private GsmCellIdentity(Parcel in) { super(in); mMcc = in.readInt(); mMnc = in.readInt(); mLac = in.readInt(); mCid = in.readInt(); mPsc = in.readInt(); } GsmCellIdentity(GsmCellIdentity cid) { private CellIdentityGsm(CellIdentityGsm cid) { super(cid); mMcc = cid.mMcc; mMnc = cid.mMnc; Loading @@ -75,6 +79,11 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { mPsc = cid.mPsc; } @Override CellIdentityGsm copy() { return new CellIdentityGsm(this); } /** * @return 3-digit Mobile Country Code, 0..999 */ Loading Loading @@ -115,15 +124,55 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { return mPsc; } /** Implement the Parcelable interface {@hide} */ @Override public int hashCode() { int primeNum = 31; return (mMcc * primeNum) + (mMnc * primeNum) + (mLac * primeNum) + (mCid * primeNum) + (mPsc * primeNum); } @Override public boolean equals(Object other) { if (super.equals(other)) { try { CellIdentityGsm o = (CellIdentityGsm)other; return mMcc == o.mMcc && mMnc == o.mMnc && mLac == o.mLac && mCid == o.mCid && mPsc == o.mPsc; } catch (ClassCastException e) { return false; } } else { return false; } } @Override public String toString() { StringBuilder sb = new StringBuilder("GsmCellIdentitiy:"); sb.append(super.toString()); sb.append(" mMcc=").append(mMcc); sb.append(" mMnc=").append(mMcc); sb.append(" mLac=").append(mLac); sb.append(" mCid=").append(mCid); sb.append(" mPsc=").append(mPsc); return sb.toString(); } /** Implement the Parcelable interface */ @Override public int describeContents() { return 0; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); dest.writeInt(TYPE_GSM); super.writeToParcel(dest, flags); dest.writeInt(mMcc); dest.writeInt(mMnc); Loading @@ -132,17 +181,42 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { dest.writeInt(mPsc); } /** Implement the Parcelable interface {@hide} */ public static final Creator<GsmCellIdentity> CREATOR = new Creator<GsmCellIdentity>() { /** Construct from Parcel, type has already been processed */ private CellIdentityGsm(Parcel in) { super(in); mMcc = in.readInt(); mMnc = in.readInt(); mLac = in.readInt(); mCid = in.readInt(); mPsc = in.readInt(); if (DBG) log("CellIdentityGsm(Parcel): " + toString()); } /** Implement the Parcelable interface */ @SuppressWarnings("hiding") public static final Creator<CellIdentityGsm> CREATOR = new Creator<CellIdentityGsm>() { @Override public GsmCellIdentity createFromParcel(Parcel in) { return new GsmCellIdentity(in); public CellIdentityGsm createFromParcel(Parcel in) { in.readInt(); // Skip past token, we know what it is return createFromParcelBody(in); } @Override public GsmCellIdentity[] newArray(int size) { return new GsmCellIdentity[size]; public CellIdentityGsm[] newArray(int size) { return new CellIdentityGsm[size]; } }; /** @hide */ static CellIdentityGsm createFromParcelBody(Parcel in) { return new CellIdentityGsm(in); } /** * log */ private static void log(String s) { Log.w(LOG_TAG, s); } } telephony/java/android/telephony/LteCellIdentity.java→telephony/java/android/telephony/CellIdentityLte.java +217 −0 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -18,13 +18,17 @@ package android.telephony; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; /** * CellIdentity is to represent a unique LTE cell * * @hide pending API review * @hide */ public final class LteCellIdentity extends CellIdentity implements Parcelable { public final class CellIdentityLte extends CellIdentity implements Parcelable { private static final String LOG_TAG = "CellIdentityLte"; private static final boolean DBG = false; // 3-digit Mobile Country Code, 0..999 private final int mMcc; Loading @@ -37,6 +41,17 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { // 16-bit tracking area code private final int mTac; /** * @hide */ public CellIdentityLte() { mMcc = Integer.MAX_VALUE; mMnc = Integer.MAX_VALUE; mCi = Integer.MAX_VALUE; mPci = Integer.MAX_VALUE; mTac = Integer.MAX_VALUE; } /** * * @param mcc 3-digit Mobile Country Code, 0..999 Loading @@ -44,11 +59,10 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { * @param ci 28-bit Cell Identity * @param pci Physical Cell Id 0..503 * @param tac 16-bit Tracking Area Code * @param attr is comma separated “key=value” attribute pairs. * * @hide */ public LteCellIdentity (int mcc, int mnc, int ci, int pci, int tac, String attr) { super(CELLID_TYPE_CDMA, attr); public CellIdentityLte (int mcc, int mnc, int ci, int pci, int tac) { mMcc = mcc; mMnc = mnc; mCi = ci; Loading @@ -56,16 +70,7 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { mTac = tac; } private LteCellIdentity(Parcel in) { super(in); mMcc = in.readInt(); mMnc = in.readInt(); mCi = in.readInt(); mPci = in.readInt(); mTac = in.readInt(); } LteCellIdentity(LteCellIdentity cid) { private CellIdentityLte(CellIdentityLte cid) { super(cid); mMcc = cid.mMcc; mMnc = cid.mMnc; Loading @@ -74,6 +79,11 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { mTac = cid.mTac; } @Override CellIdentityLte copy() { return new CellIdentityLte(this); } /** * @return 3-digit Mobile Country Code, 0..999 */ Loading Loading @@ -109,15 +119,55 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { return mTac; } /** Implement the Parcelable interface {@hide} */ @Override public int hashCode() { int primeNum = 31; return (mMcc * primeNum) + (mMnc * primeNum) + (mCi * primeNum) + (mPci * primeNum) + (mTac * primeNum); } @Override public boolean equals(Object other) { if (super.equals(other)) { try { CellIdentityLte o = (CellIdentityLte)other; return mMcc == o.mMcc && mMnc == o.mMnc && mCi == o.mCi && mPci == o.mCi && mTac == o.mTac; } catch (ClassCastException e) { return false; } } else { return false; } } @Override public String toString() { StringBuilder sb = new StringBuilder("LteCellIdentitiy:"); sb.append(super.toString()); sb.append(" mMcc="); sb.append(mMcc); sb.append(" mMnc="); sb.append(mMnc); sb.append(" mCi="); sb.append(mCi); sb.append(" mPci="); sb.append(mPci); sb.append(" mTac="); sb.append(mTac); return sb.toString(); } /** Implement the Parcelable interface */ @Override public int describeContents() { return 0; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); dest.writeInt(TYPE_LTE); super.writeToParcel(dest, flags); dest.writeInt(mMcc); dest.writeInt(mMnc); Loading @@ -126,17 +176,42 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { dest.writeInt(mTac); } /** Implement the Parcelable interface {@hide} */ public static final Creator<LteCellIdentity> CREATOR = new Creator<LteCellIdentity>() { /** Construct from Parcel, type has already been processed */ private CellIdentityLte(Parcel in) { super(in); mMcc = in.readInt(); mMnc = in.readInt(); mCi = in.readInt(); mPci = in.readInt(); mTac = in.readInt(); if (DBG) log("CellIdentityLte(Parcel): " + toString()); } /** Implement the Parcelable interface */ @SuppressWarnings("hiding") public static final Creator<CellIdentityLte> CREATOR = new Creator<CellIdentityLte>() { @Override public LteCellIdentity createFromParcel(Parcel in) { return new LteCellIdentity(in); public CellIdentityLte createFromParcel(Parcel in) { in.readInt(); // Skip past token, we know what it is return createFromParcelBody(in); } @Override public LteCellIdentity[] newArray(int size) { return new LteCellIdentity[size]; public CellIdentityLte[] newArray(int size) { return new CellIdentityLte[size]; } }; /** @hide */ static CellIdentityLte createFromParcelBody(Parcel in) { return new CellIdentityLte(in); } /** * log */ private static void log(String s) { Log.w(LOG_TAG, s); } } Loading
services/java/com/android/server/TelephonyRegistry.java +5 −4 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.text.TextUtils; import android.util.Slog; import java.util.ArrayList; import java.util.List; import java.io.FileDescriptor; import java.io.PrintWriter; import java.net.NetworkInterface; Loading Loading @@ -109,7 +110,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN; private CellInfo mCellInfo = null; private List<CellInfo> mCellInfo = null; static final int PHONE_STATE_PERMISSION_MASK = PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR | Loading Loading @@ -242,7 +243,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { try { r.callback.onCellInfoChanged(new CellInfo(mCellInfo)); r.callback.onCellInfoChanged(mCellInfo); } catch (RemoteException ex) { remove(r.binder); } Loading Loading @@ -336,7 +337,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { broadcastSignalStrengthChanged(signalStrength); } public void notifyCellInfo(CellInfo cellInfo) { public void notifyCellInfo(List<CellInfo> cellInfo) { if (!checkNotifyPermission("notifyCellInfo()")) { return; } Loading @@ -346,7 +347,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { for (Record r : mRecords) { if ((r.events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { try { r.callback.onCellInfoChanged(new CellInfo(cellInfo)); r.callback.onCellInfoChanged(cellInfo); } catch (RemoteException ex) { mRemoveList.add(r.binder); } Loading
telephony/java/android/telephony/CellIdentity.java +47 −38 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -20,70 +20,79 @@ import android.os.Parcel; import android.os.Parcelable; /** * CellIdentity is to represent ONE unique cell in the world * CellIdentity is immutable and represents ONE unique cell in the world * it contains all levels of info to identity country, carrier, etc. * * @hide pending API review * @hide */ public abstract class CellIdentity implements Parcelable { // Cell is a GSM Cell {@link GsmCellIdentity} public static final int CELLID_TYPE_GSM = 1; // Cell is a CMDA Cell {@link CdmaCellIdentity} public static final int CELLID_TYPE_CDMA = 2; // Cell is a LTE Cell {@link LteCellIdentity} public static final int CELLID_TYPE_LTE = 3; // Type fields for parceling protected static final int TYPE_GSM = 1; protected static final int TYPE_CDMA = 2; protected static final int TYPE_LTE = 3; private int mCellIdType; private String mCellIdAttributes; protected CellIdentity(int type, String attr) { this.mCellIdType = type; this.mCellIdAttributes = new String(attr); protected CellIdentity() { } protected CellIdentity(Parcel in) { this.mCellIdType = in.readInt(); this.mCellIdAttributes = new String(in.readString()); } protected CellIdentity(CellIdentity cid) { this.mCellIdType = cid.mCellIdType; this.mCellIdAttributes = new String(cid.mCellIdAttributes); } /** * @return Cell Identity type as one of CELLID_TYPE_XXXX * @return a copy of this object with package visibility. */ public int getCellIdType() { return mCellIdType; } abstract CellIdentity copy(); @Override public abstract int hashCode(); /** * @return Cell identity attribute pairs * Comma separated “key=value” pairs. * key := must must an single alpha-numeric word * value := “quoted value string” * * Current list of keys and values: * type = fixed | mobile */ public String getCellIdAttributes() { return mCellIdAttributes; @Override public boolean equals(Object other) { if (other == null) { return false; } if (this == other) { return true; } return (other instanceof CellIdentity); } @Override public String toString() { return ""; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public int describeContents() { return 0; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mCellIdType); dest.writeString(mCellIdAttributes); } /** Implement the Parcelable interface */ public static final Creator<CellIdentity> CREATOR = new Creator<CellIdentity>() { @Override public CellIdentity createFromParcel(Parcel in) { int type = in.readInt(); switch (type) { case TYPE_GSM: return CellIdentityGsm.createFromParcelBody(in); case TYPE_CDMA: return CellIdentityCdma.createFromParcelBody(in); case TYPE_LTE: return CellIdentityLte.createFromParcelBody(in); default: throw new RuntimeException("Bad CellIdentity Parcel"); } } @Override public CellIdentity[] newArray(int size) { return new CellIdentity[size]; } }; }
telephony/java/android/telephony/CdmaCellIdentity.java→telephony/java/android/telephony/CellIdentityCdma.java +102 −29 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -18,13 +18,18 @@ package android.telephony; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; /** * CellIdentity is to represent a unique CDMA cell * * @hide pending API review * @hide */ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { public final class CellIdentityCdma extends CellIdentity implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthCdma"; private static final boolean DBG = false; // Network Id 0..65535 private final int mNetworkId; // CDMA System Id 0..32767 Loading @@ -46,6 +51,17 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { */ private final int mLatitude; /** * @hide */ public CellIdentityCdma() { mNetworkId = Integer.MAX_VALUE; mSystemId = Integer.MAX_VALUE; mBasestationId = Integer.MAX_VALUE; mLongitude = Integer.MAX_VALUE; mLatitude = Integer.MAX_VALUE; } /** * public constructor * @param nid Network Id 0..65535 Loading @@ -55,11 +71,10 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { * to 2592000 * @param lat Latitude is a decimal number ranges from -1296000 * to 1296000 * @param attr is comma separated “key=value” attribute pairs. * * @hide */ public CdmaCellIdentity (int nid, int sid, int bid, int lon, int lat, String attr) { super(CELLID_TYPE_CDMA, attr); public CellIdentityCdma (int nid, int sid, int bid, int lon, int lat) { mNetworkId = nid; mSystemId = sid; mBasestationId = bid; Loading @@ -67,16 +82,7 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { mLatitude = lat; } private CdmaCellIdentity(Parcel in) { super(in); mNetworkId = in.readInt(); mSystemId = in.readInt(); mBasestationId = in.readInt(); mLongitude = in.readInt(); mLatitude = in.readInt(); } CdmaCellIdentity(CdmaCellIdentity cid) { private CellIdentityCdma(CellIdentityCdma cid) { super(cid); mNetworkId = cid.mNetworkId; mSystemId = cid.mSystemId; Loading @@ -85,6 +91,11 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { mLatitude = cid.mLatitude; } @Override CellIdentityCdma copy() { return new CellIdentityCdma(this); } /** * @return Network Id 0..65535 */ Loading Loading @@ -117,9 +128,6 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { return mLongitude; } /** * @return Base station */ /** * @return Base station latitude, which is a decimal number as * specified in 3GPP2 C.S0005-A v6.0. It is represented in units Loading @@ -131,15 +139,55 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { return mLatitude; } /** Implement the Parcelable interface {@hide} */ @Override public int hashCode() { int primeNum = 31; return (mNetworkId * primeNum) + (mSystemId * primeNum) + (mBasestationId * primeNum) + (mLatitude * primeNum) + (mLongitude * primeNum); } @Override public boolean equals(Object other) { if (super.equals(other)) { try { CellIdentityCdma o = (CellIdentityCdma)other; return mNetworkId == o.mNetworkId && mSystemId == o.mSystemId && mBasestationId == o.mBasestationId && mLatitude == o.mLatitude && mLongitude == o.mLongitude; } catch (ClassCastException e) { return false; } } else { return false; } } @Override public String toString() { StringBuilder sb = new StringBuilder("CdmaCellIdentitiy:"); sb.append(super.toString()); sb.append(" mNetworkId="); sb.append(mNetworkId); sb.append(" mSystemId="); sb.append(mSystemId); sb.append(" mBasestationId="); sb.append(mBasestationId); sb.append(" mLongitude="); sb.append(mLongitude); sb.append(" mLatitude="); sb.append(mLatitude); return sb.toString(); } /** Implement the Parcelable interface */ @Override public int describeContents() { return 0; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); dest.writeInt(TYPE_CDMA); super.writeToParcel(dest, flags); dest.writeInt(mNetworkId); dest.writeInt(mSystemId); Loading @@ -148,17 +196,42 @@ public final class CdmaCellIdentity extends CellIdentity implements Parcelable { dest.writeInt(mLatitude); } /** Implement the Parcelable interface {@hide} */ public static final Creator<CdmaCellIdentity> CREATOR = new Creator<CdmaCellIdentity>() { /** Construct from Parcel, type has already been processed */ private CellIdentityCdma(Parcel in) { super(in); mNetworkId = in.readInt(); mSystemId = in.readInt(); mBasestationId = in.readInt(); mLongitude = in.readInt(); mLatitude = in.readInt(); if (DBG) log("CellIdentityCdma(Parcel): " + toString()); } /** Implement the Parcelable interface */ @SuppressWarnings("hiding") public static final Creator<CellIdentityCdma> CREATOR = new Creator<CellIdentityCdma>() { @Override public CdmaCellIdentity createFromParcel(Parcel in) { return new CdmaCellIdentity(in); public CellIdentityCdma createFromParcel(Parcel in) { in.readInt(); // Skip past token, we know what it is return createFromParcelBody(in); } @Override public CdmaCellIdentity[] newArray(int size) { return new CdmaCellIdentity[size]; public CellIdentityCdma[] newArray(int size) { return new CellIdentityCdma[size]; } }; /** @hide */ static CellIdentityCdma createFromParcelBody(Parcel in) { return new CellIdentityCdma(in); } /** * log */ private static void log(String s) { Log.w(LOG_TAG, s); } }
telephony/java/android/telephony/GsmCellIdentity.java→telephony/java/android/telephony/CellIdentityGsm.java +100 −26 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -18,13 +18,17 @@ package android.telephony; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; /** * CellIdentity to represent a unique GSM or UMTS cell * * @hide pending API review * @hide */ public final class GsmCellIdentity extends CellIdentity implements Parcelable { public final class CellIdentityGsm extends CellIdentity implements Parcelable { private static final String LOG_TAG = "CellIdentityGsm"; private static final boolean DBG = false; // 3-digit Mobile Country Code, 0..999 private final int mMcc; Loading @@ -38,6 +42,16 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { // 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511 private final int mPsc; /** * @hide */ public CellIdentityGsm() { mMcc = Integer.MAX_VALUE; mMnc = Integer.MAX_VALUE; mLac = Integer.MAX_VALUE; mCid = Integer.MAX_VALUE; mPsc = Integer.MAX_VALUE; } /** * public constructor * @param mcc 3-digit Mobile Country Code, 0..999 Loading @@ -45,11 +59,10 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { * @param lac 16-bit Location Area Code, 0..65535 * @param cid 16-bit GSM Cell Identity or 28-bit UMTS Cell Identity * @param psc 9-bit UMTS Primary Scrambling Code * @param attr is comma separated “key=value” attribute pairs. * * @hide */ public GsmCellIdentity (int mcc, int mnc, int lac, int cid, int psc, String attr) { super(CELLID_TYPE_GSM, attr); public CellIdentityGsm (int mcc, int mnc, int lac, int cid, int psc) { mMcc = mcc; mMnc = mnc; mLac = lac; Loading @@ -57,16 +70,7 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { mPsc = psc; } private GsmCellIdentity(Parcel in) { super(in); mMcc = in.readInt(); mMnc = in.readInt(); mLac = in.readInt(); mCid = in.readInt(); mPsc = in.readInt(); } GsmCellIdentity(GsmCellIdentity cid) { private CellIdentityGsm(CellIdentityGsm cid) { super(cid); mMcc = cid.mMcc; mMnc = cid.mMnc; Loading @@ -75,6 +79,11 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { mPsc = cid.mPsc; } @Override CellIdentityGsm copy() { return new CellIdentityGsm(this); } /** * @return 3-digit Mobile Country Code, 0..999 */ Loading Loading @@ -115,15 +124,55 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { return mPsc; } /** Implement the Parcelable interface {@hide} */ @Override public int hashCode() { int primeNum = 31; return (mMcc * primeNum) + (mMnc * primeNum) + (mLac * primeNum) + (mCid * primeNum) + (mPsc * primeNum); } @Override public boolean equals(Object other) { if (super.equals(other)) { try { CellIdentityGsm o = (CellIdentityGsm)other; return mMcc == o.mMcc && mMnc == o.mMnc && mLac == o.mLac && mCid == o.mCid && mPsc == o.mPsc; } catch (ClassCastException e) { return false; } } else { return false; } } @Override public String toString() { StringBuilder sb = new StringBuilder("GsmCellIdentitiy:"); sb.append(super.toString()); sb.append(" mMcc=").append(mMcc); sb.append(" mMnc=").append(mMcc); sb.append(" mLac=").append(mLac); sb.append(" mCid=").append(mCid); sb.append(" mPsc=").append(mPsc); return sb.toString(); } /** Implement the Parcelable interface */ @Override public int describeContents() { return 0; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); dest.writeInt(TYPE_GSM); super.writeToParcel(dest, flags); dest.writeInt(mMcc); dest.writeInt(mMnc); Loading @@ -132,17 +181,42 @@ public final class GsmCellIdentity extends CellIdentity implements Parcelable { dest.writeInt(mPsc); } /** Implement the Parcelable interface {@hide} */ public static final Creator<GsmCellIdentity> CREATOR = new Creator<GsmCellIdentity>() { /** Construct from Parcel, type has already been processed */ private CellIdentityGsm(Parcel in) { super(in); mMcc = in.readInt(); mMnc = in.readInt(); mLac = in.readInt(); mCid = in.readInt(); mPsc = in.readInt(); if (DBG) log("CellIdentityGsm(Parcel): " + toString()); } /** Implement the Parcelable interface */ @SuppressWarnings("hiding") public static final Creator<CellIdentityGsm> CREATOR = new Creator<CellIdentityGsm>() { @Override public GsmCellIdentity createFromParcel(Parcel in) { return new GsmCellIdentity(in); public CellIdentityGsm createFromParcel(Parcel in) { in.readInt(); // Skip past token, we know what it is return createFromParcelBody(in); } @Override public GsmCellIdentity[] newArray(int size) { return new GsmCellIdentity[size]; public CellIdentityGsm[] newArray(int size) { return new CellIdentityGsm[size]; } }; /** @hide */ static CellIdentityGsm createFromParcelBody(Parcel in) { return new CellIdentityGsm(in); } /** * log */ private static void log(String s) { Log.w(LOG_TAG, s); } }
telephony/java/android/telephony/LteCellIdentity.java→telephony/java/android/telephony/CellIdentityLte.java +217 −0 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -18,13 +18,17 @@ package android.telephony; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; /** * CellIdentity is to represent a unique LTE cell * * @hide pending API review * @hide */ public final class LteCellIdentity extends CellIdentity implements Parcelable { public final class CellIdentityLte extends CellIdentity implements Parcelable { private static final String LOG_TAG = "CellIdentityLte"; private static final boolean DBG = false; // 3-digit Mobile Country Code, 0..999 private final int mMcc; Loading @@ -37,6 +41,17 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { // 16-bit tracking area code private final int mTac; /** * @hide */ public CellIdentityLte() { mMcc = Integer.MAX_VALUE; mMnc = Integer.MAX_VALUE; mCi = Integer.MAX_VALUE; mPci = Integer.MAX_VALUE; mTac = Integer.MAX_VALUE; } /** * * @param mcc 3-digit Mobile Country Code, 0..999 Loading @@ -44,11 +59,10 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { * @param ci 28-bit Cell Identity * @param pci Physical Cell Id 0..503 * @param tac 16-bit Tracking Area Code * @param attr is comma separated “key=value” attribute pairs. * * @hide */ public LteCellIdentity (int mcc, int mnc, int ci, int pci, int tac, String attr) { super(CELLID_TYPE_CDMA, attr); public CellIdentityLte (int mcc, int mnc, int ci, int pci, int tac) { mMcc = mcc; mMnc = mnc; mCi = ci; Loading @@ -56,16 +70,7 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { mTac = tac; } private LteCellIdentity(Parcel in) { super(in); mMcc = in.readInt(); mMnc = in.readInt(); mCi = in.readInt(); mPci = in.readInt(); mTac = in.readInt(); } LteCellIdentity(LteCellIdentity cid) { private CellIdentityLte(CellIdentityLte cid) { super(cid); mMcc = cid.mMcc; mMnc = cid.mMnc; Loading @@ -74,6 +79,11 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { mTac = cid.mTac; } @Override CellIdentityLte copy() { return new CellIdentityLte(this); } /** * @return 3-digit Mobile Country Code, 0..999 */ Loading Loading @@ -109,15 +119,55 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { return mTac; } /** Implement the Parcelable interface {@hide} */ @Override public int hashCode() { int primeNum = 31; return (mMcc * primeNum) + (mMnc * primeNum) + (mCi * primeNum) + (mPci * primeNum) + (mTac * primeNum); } @Override public boolean equals(Object other) { if (super.equals(other)) { try { CellIdentityLte o = (CellIdentityLte)other; return mMcc == o.mMcc && mMnc == o.mMnc && mCi == o.mCi && mPci == o.mCi && mTac == o.mTac; } catch (ClassCastException e) { return false; } } else { return false; } } @Override public String toString() { StringBuilder sb = new StringBuilder("LteCellIdentitiy:"); sb.append(super.toString()); sb.append(" mMcc="); sb.append(mMcc); sb.append(" mMnc="); sb.append(mMnc); sb.append(" mCi="); sb.append(mCi); sb.append(" mPci="); sb.append(mPci); sb.append(" mTac="); sb.append(mTac); return sb.toString(); } /** Implement the Parcelable interface */ @Override public int describeContents() { return 0; } /** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); dest.writeInt(TYPE_LTE); super.writeToParcel(dest, flags); dest.writeInt(mMcc); dest.writeInt(mMnc); Loading @@ -126,17 +176,42 @@ public final class LteCellIdentity extends CellIdentity implements Parcelable { dest.writeInt(mTac); } /** Implement the Parcelable interface {@hide} */ public static final Creator<LteCellIdentity> CREATOR = new Creator<LteCellIdentity>() { /** Construct from Parcel, type has already been processed */ private CellIdentityLte(Parcel in) { super(in); mMcc = in.readInt(); mMnc = in.readInt(); mCi = in.readInt(); mPci = in.readInt(); mTac = in.readInt(); if (DBG) log("CellIdentityLte(Parcel): " + toString()); } /** Implement the Parcelable interface */ @SuppressWarnings("hiding") public static final Creator<CellIdentityLte> CREATOR = new Creator<CellIdentityLte>() { @Override public LteCellIdentity createFromParcel(Parcel in) { return new LteCellIdentity(in); public CellIdentityLte createFromParcel(Parcel in) { in.readInt(); // Skip past token, we know what it is return createFromParcelBody(in); } @Override public LteCellIdentity[] newArray(int size) { return new LteCellIdentity[size]; public CellIdentityLte[] newArray(int size) { return new CellIdentityLte[size]; } }; /** @hide */ static CellIdentityLte createFromParcelBody(Parcel in) { return new CellIdentityLte(in); } /** * log */ private static void log(String s) { Log.w(LOG_TAG, s); } }