From c6e4917adda19beb780386bcc26b652748b8ab13 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Fri, 21 Sep 2012 13:54:05 -0700 Subject: Refactor Cell Location public API. Bug: 7189651 Change-Id: I173412095a5f7ae6116ee65b5315782f1c0c7688 --- telephony/java/android/telephony/CellIdentity.java | 102 --------------------- .../java/android/telephony/CellIdentityCdma.java | 15 +-- .../java/android/telephony/CellIdentityGsm.java | 15 +-- .../java/android/telephony/CellIdentityLte.java | 15 +-- telephony/java/android/telephony/CellInfo.java | 22 ++++- telephony/java/android/telephony/CellInfoCdma.java | 4 +- telephony/java/android/telephony/CellInfoGsm.java | 3 +- telephony/java/android/telephony/CellInfoLte.java | 9 +- .../java/android/telephony/CellSignalStrength.java | 41 +-------- .../android/telephony/CellSignalStrengthCdma.java | 13 +-- .../android/telephony/CellSignalStrengthGsm.java | 13 +-- .../android/telephony/CellSignalStrengthLte.java | 13 +-- 12 files changed, 39 insertions(+), 226 deletions(-) delete mode 100644 telephony/java/android/telephony/CellIdentity.java (limited to 'telephony') diff --git a/telephony/java/android/telephony/CellIdentity.java b/telephony/java/android/telephony/CellIdentity.java deleted file mode 100644 index a3f7860..0000000 --- a/telephony/java/android/telephony/CellIdentity.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.telephony; - -import android.os.Parcel; -import android.os.Parcelable; - -/** - * CellIdentity is immutable and represents ONE unique cell in the world - * it contains all levels of info to identity country, carrier, etc. - */ -public abstract class CellIdentity implements Parcelable { - - // Type fields for parceling - /** @hide */ - protected static final int TYPE_GSM = 1; - /** @hide */ - protected static final int TYPE_CDMA = 2; - /** @hide */ - protected static final int TYPE_LTE = 3; - - /** @hide */ - protected CellIdentity() { - } - - /** @hide */ - protected CellIdentity(Parcel in) { - } - - /** @hide */ - protected CellIdentity(CellIdentity cid) { - } - - /** - * @return a copy of this object with package visibility. - */ - abstract CellIdentity copy(); - - @Override - public abstract int hashCode(); - - @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 */ - @Override - public int describeContents() { - return 0; - } - - /** Implement the Parcelable interface */ - @Override - public void writeToParcel(Parcel dest, int flags) { - } - - /** Implement the Parcelable interface */ - public static final Creator CREATOR = - new Creator() { - @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]; - } - }; -} diff --git a/telephony/java/android/telephony/CellIdentityCdma.java b/telephony/java/android/telephony/CellIdentityCdma.java index fccf98c..9579b91 100644 --- a/telephony/java/android/telephony/CellIdentityCdma.java +++ b/telephony/java/android/telephony/CellIdentityCdma.java @@ -23,7 +23,7 @@ import android.util.Log; /** * CellIdentity is to represent a unique CDMA cell */ -public final class CellIdentityCdma extends CellIdentity implements Parcelable { +public final class CellIdentityCdma implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthCdma"; private static final boolean DBG = false; @@ -81,7 +81,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { } private CellIdentityCdma(CellIdentityCdma cid) { - super(cid); mNetworkId = cid.mNetworkId; mSystemId = cid.mSystemId; mBasestationId = cid.mBasestationId; @@ -89,7 +88,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { mLatitude = cid.mLatitude; } - @Override CellIdentityCdma copy() { return new CellIdentityCdma(this); } @@ -185,8 +183,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { @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); dest.writeInt(mBasestationId); @@ -196,7 +192,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { /** Construct from Parcel, type has already been processed */ private CellIdentityCdma(Parcel in) { - super(in); mNetworkId = in.readInt(); mSystemId = in.readInt(); mBasestationId = in.readInt(); @@ -211,8 +206,7 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { new Creator() { @Override public CellIdentityCdma createFromParcel(Parcel in) { - in.readInt(); // Skip past token, we know what it is - return createFromParcelBody(in); + return new CellIdentityCdma(in); } @Override @@ -221,11 +215,6 @@ public final class CellIdentityCdma extends CellIdentity implements Parcelable { } }; - /** @hide */ - static CellIdentityCdma createFromParcelBody(Parcel in) { - return new CellIdentityCdma(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellIdentityGsm.java b/telephony/java/android/telephony/CellIdentityGsm.java index dead049..21cb790 100644 --- a/telephony/java/android/telephony/CellIdentityGsm.java +++ b/telephony/java/android/telephony/CellIdentityGsm.java @@ -23,7 +23,7 @@ import android.util.Log; /** * CellIdentity to represent a unique GSM or UMTS cell */ -public final class CellIdentityGsm extends CellIdentity implements Parcelable { +public final class CellIdentityGsm implements Parcelable { private static final String LOG_TAG = "CellIdentityGsm"; private static final boolean DBG = false; @@ -69,7 +69,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { } private CellIdentityGsm(CellIdentityGsm cid) { - super(cid); mMcc = cid.mMcc; mMnc = cid.mMnc; mLac = cid.mLac; @@ -77,7 +76,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { mPsc = cid.mPsc; } - @Override CellIdentityGsm copy() { return new CellIdentityGsm(this); } @@ -170,8 +168,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { @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); dest.writeInt(mLac); @@ -181,7 +177,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { /** Construct from Parcel, type has already been processed */ private CellIdentityGsm(Parcel in) { - super(in); mMcc = in.readInt(); mMnc = in.readInt(); mLac = in.readInt(); @@ -196,8 +191,7 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { new Creator() { @Override public CellIdentityGsm createFromParcel(Parcel in) { - in.readInt(); // Skip past token, we know what it is - return createFromParcelBody(in); + return new CellIdentityGsm(in); } @Override @@ -206,11 +200,6 @@ public final class CellIdentityGsm extends CellIdentity implements Parcelable { } }; - /** @hide */ - static CellIdentityGsm createFromParcelBody(Parcel in) { - return new CellIdentityGsm(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellIdentityLte.java b/telephony/java/android/telephony/CellIdentityLte.java index 832cbe1..ad822bb 100644 --- a/telephony/java/android/telephony/CellIdentityLte.java +++ b/telephony/java/android/telephony/CellIdentityLte.java @@ -23,7 +23,7 @@ import android.util.Log; /** * CellIdentity is to represent a unique LTE cell */ -public final class CellIdentityLte extends CellIdentity implements Parcelable { +public final class CellIdentityLte implements Parcelable { private static final String LOG_TAG = "CellIdentityLte"; private static final boolean DBG = false; @@ -69,7 +69,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { } private CellIdentityLte(CellIdentityLte cid) { - super(cid); mMcc = cid.mMcc; mMnc = cid.mMnc; mCi = cid.mCi; @@ -77,7 +76,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { mTac = cid.mTac; } - @Override CellIdentityLte copy() { return new CellIdentityLte(this); } @@ -165,8 +163,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { @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); dest.writeInt(mCi); @@ -176,7 +172,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { /** Construct from Parcel, type has already been processed */ private CellIdentityLte(Parcel in) { - super(in); mMcc = in.readInt(); mMnc = in.readInt(); mCi = in.readInt(); @@ -191,8 +186,7 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { new Creator() { @Override public CellIdentityLte createFromParcel(Parcel in) { - in.readInt(); // Skip past token, we know what it is - return createFromParcelBody(in); + return new CellIdentityLte(in); } @Override @@ -201,11 +195,6 @@ public final class CellIdentityLte extends CellIdentity implements Parcelable { } }; - /** @hide */ - static CellIdentityLte createFromParcelBody(Parcel in) { - return new CellIdentityLte(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellInfo.java b/telephony/java/android/telephony/CellInfo.java index 1946b5d..f367f99 100644 --- a/telephony/java/android/telephony/CellInfo.java +++ b/telephony/java/android/telephony/CellInfo.java @@ -22,7 +22,7 @@ import android.os.Parcelable; /** * Immutable cell information from a point in time. */ -public class CellInfo implements Parcelable { +public abstract class CellInfo implements Parcelable { // Type fields for parceling /** @hide */ @@ -157,7 +157,9 @@ public class CellInfo implements Parcelable { return sb.toString(); } - /** Implement the Parcelable interface */ + /** + * Implement the Parcelable interface + */ @Override public int describeContents() { return 0; @@ -165,13 +167,25 @@ public class CellInfo implements Parcelable { /** Implement the Parcelable interface */ @Override - public void writeToParcel(Parcel dest, int flags) { + public abstract void writeToParcel(Parcel dest, int flags); + + /** + * Used by child classes for parceling. + * + * @hide + */ + protected void writeToParcel(Parcel dest, int flags, int type) { + dest.writeInt(type); dest.writeInt(mRegistered ? 1 : 0); dest.writeInt(mTimeStampType); dest.writeLong(mTimeStamp); } - /** @hide */ + /** + * Used by child classes for parceling + * + * @hide + */ protected CellInfo(Parcel in) { mRegistered = (in.readInt() == 1) ? true : false; mTimeStampType = in.readInt(); diff --git a/telephony/java/android/telephony/CellInfoCdma.java b/telephony/java/android/telephony/CellInfoCdma.java index 1c41ba4..ea48e2e 100644 --- a/telephony/java/android/telephony/CellInfoCdma.java +++ b/telephony/java/android/telephony/CellInfoCdma.java @@ -104,9 +104,7 @@ public final class CellInfoCdma extends CellInfo implements Parcelable { /** 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); + super.writeToParcel(dest, flags, TYPE_CDMA); mCellIdentityCdma.writeToParcel(dest, flags); mCellSignalStrengthCdma.writeToParcel(dest, flags); } diff --git a/telephony/java/android/telephony/CellInfoGsm.java b/telephony/java/android/telephony/CellInfoGsm.java index c644cb3..bd14d45 100644 --- a/telephony/java/android/telephony/CellInfoGsm.java +++ b/telephony/java/android/telephony/CellInfoGsm.java @@ -104,8 +104,7 @@ public final class CellInfoGsm extends CellInfo implements Parcelable { /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(TYPE_LTE); - super.writeToParcel(dest, flags); + super.writeToParcel(dest, flags, TYPE_GSM); mCellIdentityGsm.writeToParcel(dest, flags); mCellSignalStrengthGsm.writeToParcel(dest, flags); } diff --git a/telephony/java/android/telephony/CellInfoLte.java b/telephony/java/android/telephony/CellInfoLte.java index 8921db2..2f81b65 100644 --- a/telephony/java/android/telephony/CellInfoLte.java +++ b/telephony/java/android/telephony/CellInfoLte.java @@ -26,7 +26,7 @@ import android.util.Log; public final class CellInfoLte extends CellInfo implements Parcelable { private static final String LOG_TAG = "CellInfoLte"; - private static final boolean DBG = false; + private static final boolean DBG = true; private CellIdentityLte mCellIdentityLte; private CellSignalStrengthLte mCellSignalStrengthLte; @@ -46,18 +46,22 @@ public final class CellInfoLte extends CellInfo implements Parcelable { } public CellIdentityLte getCellIdentity() { + if (DBG) log("getCellIdentity: " + mCellIdentityLte); return mCellIdentityLte; } /** @hide */ public void setCellIdentity(CellIdentityLte cid) { + if (DBG) log("setCellIdentity: " + cid); mCellIdentityLte = cid; } public CellSignalStrengthLte getCellSignalStrength() { + if (DBG) log("getCellSignalStrength: " + mCellSignalStrengthLte); return mCellSignalStrengthLte; } /** @hide */ public void setCellSignalStrength(CellSignalStrengthLte css) { + if (DBG) log("setCellSignalStrength: " + css); mCellSignalStrengthLte = css; } @@ -105,8 +109,7 @@ public final class CellInfoLte extends CellInfo implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(TYPE_LTE); - super.writeToParcel(dest, flags); + super.writeToParcel(dest, flags, TYPE_LTE); mCellIdentityLte.writeToParcel(dest, flags); mCellSignalStrengthLte.writeToParcel(dest, flags); } diff --git a/telephony/java/android/telephony/CellSignalStrength.java b/telephony/java/android/telephony/CellSignalStrength.java index 581efc2..3b470fc 100644 --- a/telephony/java/android/telephony/CellSignalStrength.java +++ b/telephony/java/android/telephony/CellSignalStrength.java @@ -22,16 +22,7 @@ import android.os.Parcelable; /** * Abstract base class for cell phone signal strength related information. */ -public abstract class CellSignalStrength implements Parcelable { - - // Type fields for parceling - /** @hide */ - protected static final int TYPE_GSM = 1; - /** @hide */ - protected static final int TYPE_CDMA = 2; - /** @hide */ - protected static final int TYPE_LTE = 3; - +public abstract class CellSignalStrength { /** @hide */ public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0; @@ -85,34 +76,4 @@ public abstract class CellSignalStrength implements Parcelable { @Override public abstract boolean equals (Object o); - - /** Implement the Parcelable interface */ - @Override - public int describeContents() { - return 0; - } - - /** Implement the Parcelable interface */ - @Override - public abstract void writeToParcel(Parcel dest, int flags); - - /** Implement the Parcelable interface */ - public static final Creator CREATOR = - new Creator() { - @Override - public CellSignalStrength createFromParcel(Parcel in) { - int type = in.readInt(); - switch (type) { - case TYPE_GSM: return CellSignalStrengthGsm.createFromParcelBody(in); - case TYPE_CDMA: return CellSignalStrengthCdma.createFromParcelBody(in); - case TYPE_LTE: return CellSignalStrengthLte.createFromParcelBody(in); - default: throw new RuntimeException("Bad CellSignalStrength Parcel"); - } - } - - @Override - public CellSignalStrength[] newArray(int size) { - return new CellSignalStrength[size]; - } - }; } diff --git a/telephony/java/android/telephony/CellSignalStrengthCdma.java b/telephony/java/android/telephony/CellSignalStrengthCdma.java index 3912629..660326c 100644 --- a/telephony/java/android/telephony/CellSignalStrengthCdma.java +++ b/telephony/java/android/telephony/CellSignalStrengthCdma.java @@ -23,7 +23,7 @@ import android.util.Log; /** * LTE signal strength related information. */ -public class CellSignalStrengthCdma extends CellSignalStrength implements Parcelable { +public final class CellSignalStrengthCdma extends CellSignalStrength implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthCdma"; private static final boolean DBG = false; @@ -331,7 +331,6 @@ public class CellSignalStrengthCdma extends CellSignalStrength implements Parcel @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(CellSignalStrength.TYPE_CDMA); dest.writeInt(mCdmaDbm); dest.writeInt(mCdmaEcio); dest.writeInt(mEvdoDbm); @@ -364,10 +363,7 @@ public class CellSignalStrengthCdma extends CellSignalStrength implements Parcel new Parcelable.Creator() { @Override public CellSignalStrengthCdma createFromParcel(Parcel in) { - if (in.readInt() != CellSignalStrength.TYPE_CDMA) { - throw new RuntimeException("Expecting TYPE_CDMA"); - } - return createFromParcelBody(in); + return new CellSignalStrengthCdma(in); } @Override @@ -376,11 +372,6 @@ public class CellSignalStrengthCdma extends CellSignalStrength implements Parcel } }; - /** @hide */ - public static CellSignalStrengthCdma createFromParcelBody(Parcel in) { - return new CellSignalStrengthCdma(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellSignalStrengthGsm.java b/telephony/java/android/telephony/CellSignalStrengthGsm.java index 30b444b..4108f61 100644 --- a/telephony/java/android/telephony/CellSignalStrengthGsm.java +++ b/telephony/java/android/telephony/CellSignalStrengthGsm.java @@ -23,7 +23,7 @@ import android.util.Log; /** * LTE signal strength related information. */ -public class CellSignalStrengthGsm extends CellSignalStrength implements Parcelable { +public final class CellSignalStrengthGsm extends CellSignalStrength implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthGsm"; private static final boolean DBG = false; @@ -190,7 +190,6 @@ public class CellSignalStrengthGsm extends CellSignalStrength implements Parcela @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(CellSignalStrength.TYPE_GSM); dest.writeInt(mSignalStrength); dest.writeInt(mBitErrorRate); } @@ -217,10 +216,7 @@ public class CellSignalStrengthGsm extends CellSignalStrength implements Parcela new Parcelable.Creator() { @Override public CellSignalStrengthGsm createFromParcel(Parcel in) { - if (in.readInt() != CellSignalStrength.TYPE_GSM) { - throw new RuntimeException("Expecting TYPE_GSM"); - } - return createFromParcelBody(in); + return new CellSignalStrengthGsm(in); } @Override @@ -229,11 +225,6 @@ public class CellSignalStrengthGsm extends CellSignalStrength implements Parcela } }; - /** @hide */ - public static CellSignalStrengthGsm createFromParcelBody(Parcel in) { - return new CellSignalStrengthGsm(in); - } - /** * log */ diff --git a/telephony/java/android/telephony/CellSignalStrengthLte.java b/telephony/java/android/telephony/CellSignalStrengthLte.java index 7a4d626..925f4d4 100644 --- a/telephony/java/android/telephony/CellSignalStrengthLte.java +++ b/telephony/java/android/telephony/CellSignalStrengthLte.java @@ -23,7 +23,7 @@ import android.util.Log; /** * LTE signal strength related information. */ -public class CellSignalStrengthLte extends CellSignalStrength implements Parcelable { +public final class CellSignalStrengthLte extends CellSignalStrength implements Parcelable { private static final String LOG_TAG = "CellSignalStrengthLte"; private static final boolean DBG = false; @@ -246,7 +246,6 @@ public class CellSignalStrengthLte extends CellSignalStrength implements Parcela @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); - dest.writeInt(CellSignalStrength.TYPE_LTE); dest.writeInt(mSignalStrength); dest.writeInt(mRsrp); dest.writeInt(mRsrq); @@ -281,10 +280,7 @@ public class CellSignalStrengthLte extends CellSignalStrength implements Parcela new Parcelable.Creator() { @Override public CellSignalStrengthLte createFromParcel(Parcel in) { - if (in.readInt() != CellSignalStrength.TYPE_LTE) { - throw new RuntimeException("Expecting TYPE_LTE"); - } - return createFromParcelBody(in); + return new CellSignalStrengthLte(in); } @Override @@ -293,11 +289,6 @@ public class CellSignalStrengthLte extends CellSignalStrength implements Parcela } }; - /** @hide */ - public static CellSignalStrengthLte createFromParcelBody(Parcel in) { - return new CellSignalStrengthLte(in); - } - /** * log */ -- cgit v1.1