diff options
| -rw-r--r-- | api/current.txt | 26 | ||||
| -rw-r--r-- | telephony/java/android/telephony/CellIdentity.aidl | 20 | ||||
| -rw-r--r-- | telephony/java/android/telephony/CellIdentity.java | 173 | ||||
| -rw-r--r-- | telephony/java/android/telephony/CellIdentityCdma.java | 79 | ||||
| -rw-r--r-- | telephony/java/android/telephony/CellIdentityGsm.java | 120 | ||||
| -rw-r--r-- | telephony/java/android/telephony/CellIdentityLte.java | 120 | ||||
| -rw-r--r-- | telephony/java/android/telephony/CellIdentityTdscdma.aidl | 20 | ||||
| -rw-r--r-- | telephony/java/android/telephony/CellIdentityTdscdma.java | 196 | ||||
| -rw-r--r-- | telephony/java/android/telephony/CellIdentityWcdma.java | 111 |
9 files changed, 585 insertions, 280 deletions
diff --git a/api/current.txt b/api/current.txt index 87c16c151f2d..6702b94d6fdf 100644 --- a/api/current.txt +++ b/api/current.txt @@ -40093,8 +40093,13 @@ package android.telephony { field public static final java.lang.String KEY_WORLD_PHONE_BOOL = "world_phone_bool"; } - public final class CellIdentityCdma implements android.os.Parcelable { + public abstract class CellIdentity implements android.os.Parcelable { method public int describeContents(); + method public void writeToParcel(android.os.Parcel, int); + field public static final android.os.Parcelable.Creator<android.telephony.CellIdentity> CREATOR; + } + + public final class CellIdentityCdma extends android.telephony.CellIdentity { method public int getBasestationId(); method public int getLatitude(); method public int getLongitude(); @@ -40106,8 +40111,7 @@ package android.telephony { field public static final android.os.Parcelable.Creator<android.telephony.CellIdentityCdma> CREATOR; } - public final class CellIdentityGsm implements android.os.Parcelable { - method public int describeContents(); + public final class CellIdentityGsm extends android.telephony.CellIdentity { method public int getArfcn(); method public int getBsic(); method public int getCid(); @@ -40124,8 +40128,7 @@ package android.telephony { field public static final android.os.Parcelable.Creator<android.telephony.CellIdentityGsm> CREATOR; } - public final class CellIdentityLte implements android.os.Parcelable { - method public int describeContents(); + public final class CellIdentityLte extends android.telephony.CellIdentity { method public int getCi(); method public int getEarfcn(); method public deprecated int getMcc(); @@ -40141,8 +40144,17 @@ package android.telephony { field public static final android.os.Parcelable.Creator<android.telephony.CellIdentityLte> CREATOR; } - public final class CellIdentityWcdma implements android.os.Parcelable { - method public int describeContents(); + public final class CellIdentityTdscdma extends android.telephony.CellIdentity { + method public int getCid(); + method public int getCpid(); + method public int getLac(); + method public java.lang.String getMccStr(); + method public java.lang.String getMncStr(); + method public void writeToParcel(android.os.Parcel, int); + field public static final android.os.Parcelable.Creator<android.telephony.CellIdentityTdscdma> CREATOR; + } + + public final class CellIdentityWcdma extends android.telephony.CellIdentity { method public int getCid(); method public int getLac(); method public deprecated int getMcc(); diff --git a/telephony/java/android/telephony/CellIdentity.aidl b/telephony/java/android/telephony/CellIdentity.aidl new file mode 100644 index 000000000000..aeee769edab2 --- /dev/null +++ b/telephony/java/android/telephony/CellIdentity.aidl @@ -0,0 +1,20 @@ +/* + * Copyright 2017 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. + */ + +/** @hide */ +package android.telephony; + +parcelable CellIdentity; diff --git a/telephony/java/android/telephony/CellIdentity.java b/telephony/java/android/telephony/CellIdentity.java new file mode 100644 index 000000000000..e092d52d91bc --- /dev/null +++ b/telephony/java/android/telephony/CellIdentity.java @@ -0,0 +1,173 @@ +/* + * Copyright 2017 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.annotation.CallSuper; +import android.annotation.IntDef; +import android.os.Parcel; +import android.os.Parcelable; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * CellIdentity represents the identity of a unique cell. This is the base class for + * CellIdentityXxx which represents cell identity for specific network access technology. + */ +public abstract class CellIdentity implements Parcelable { + /** + * Cell identity type + * @hide + */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = "TYPE_", value = {TYPE_GSM, TYPE_CDMA, TYPE_LTE, TYPE_WCDMA, TYPE_TDSCDMA}) + public @interface Type {} + + /** + * Unknown cell identity type + * @hide + */ + public static final int TYPE_UNKNOWN = 0; + /** + * GSM cell identity type + * @hide + */ + public static final int TYPE_GSM = 1; + /** + * CDMA cell identity type + * @hide + */ + public static final int TYPE_CDMA = 2; + /** + * LTE cell identity type + * @hide + */ + public static final int TYPE_LTE = 3; + /** + * WCDMA cell identity type + * @hide + */ + public static final int TYPE_WCDMA = 4; + /** + * TDS-CDMA cell identity type + * @hide + */ + public static final int TYPE_TDSCDMA = 5; + + // Log tag + /** @hide */ + protected final String mTag; + // Cell identity type + /** @hide */ + protected final int mType; + // 3-digit Mobile Country Code in string format. Null for CDMA cell identity. + /** @hide */ + protected final String mMccStr; + // 2 or 3-digit Mobile Network Code in string format. Null for CDMA cell identity. + /** @hide */ + protected final String mMncStr; + + /** @hide */ + protected CellIdentity(String tag, int type, String mcc, String mnc) { + mTag = tag; + mType = type; + + // Only allow INT_MAX if unknown string mcc/mnc + if (mcc == null || mcc.matches("^[0-9]{3}$")) { + mMccStr = mcc; + } else if (mcc.isEmpty() || mcc.equals(String.valueOf(Integer.MAX_VALUE))) { + // If the mccStr is empty or unknown, set it as null. + mMccStr = null; + } else { + // TODO: b/69384059 Should throw IllegalArgumentException for the invalid MCC format + // after the bug got fixed. + mMccStr = null; + log("invalid MCC format: " + mcc); + } + + if (mnc == null || mnc.matches("^[0-9]{2,3}$")) { + mMncStr = mnc; + } else if (mnc.isEmpty() || mnc.equals(String.valueOf(Integer.MAX_VALUE))) { + // If the mncStr is empty or unknown, set it as null. + mMncStr = null; + } else { + // TODO: b/69384059 Should throw IllegalArgumentException for the invalid MNC format + // after the bug got fixed. + mMncStr = null; + log("invalid MNC format: " + mnc); + } + } + + /** Implement the Parcelable interface */ + @Override + public int describeContents() { + return 0; + } + + /** + * @hide + * @return The type of the cell identity + */ + public @Type int getType() { return mType; } + + /** + * Used by child classes for parceling. + * + * @hide + */ + @CallSuper + public void writeToParcel(Parcel dest, int type) { + dest.writeInt(type); + dest.writeString(mMccStr); + dest.writeString(mMncStr); + } + + /** + * Construct from Parcel + * @hide + */ + protected CellIdentity(String tag, int type, Parcel source) { + this(tag, type, source.readString(), source.readString()); + } + + /** 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_WCDMA: return CellIdentityWcdma.createFromParcelBody(in); + case TYPE_CDMA: return CellIdentityCdma.createFromParcelBody(in); + case TYPE_LTE: return CellIdentityLte.createFromParcelBody(in); + case TYPE_TDSCDMA: return CellIdentityTdscdma.createFromParcelBody(in); + default: throw new IllegalArgumentException("Bad Cell identity Parcel"); + } + } + + @Override + public CellIdentity[] newArray(int size) { + return new CellIdentity[size]; + } + }; + + /** @hide */ + protected void log(String s) { + Rlog.w(mTag, s); + } +}
\ No newline at end of file diff --git a/telephony/java/android/telephony/CellIdentityCdma.java b/telephony/java/android/telephony/CellIdentityCdma.java index ddc938e64841..2e1d1dc343cd 100644 --- a/telephony/java/android/telephony/CellIdentityCdma.java +++ b/telephony/java/android/telephony/CellIdentityCdma.java @@ -17,8 +17,6 @@ package android.telephony; import android.os.Parcel; -import android.os.Parcelable; -import android.telephony.Rlog; import android.text.TextUtils; import java.util.Objects; @@ -26,9 +24,8 @@ import java.util.Objects; /** * CellIdentity is to represent a unique CDMA cell */ -public final class CellIdentityCdma implements Parcelable { - - private static final String LOG_TAG = "CellSignalStrengthCdma"; +public final class CellIdentityCdma extends CellIdentity { + private static final String TAG = CellIdentityCdma.class.getSimpleName(); private static final boolean DBG = false; // Network Id 0..65535 @@ -60,6 +57,7 @@ public final class CellIdentityCdma implements Parcelable { * @hide */ public CellIdentityCdma() { + super(TAG, TYPE_CDMA, null, null); mNetworkId = Integer.MAX_VALUE; mSystemId = Integer.MAX_VALUE; mBasestationId = Integer.MAX_VALUE; @@ -81,7 +79,7 @@ public final class CellIdentityCdma implements Parcelable { * * @hide */ - public CellIdentityCdma (int nid, int sid, int bid, int lon, int lat) { + public CellIdentityCdma(int nid, int sid, int bid, int lon, int lat) { this(nid, sid, bid, lon, lat, null, null); } @@ -99,8 +97,9 @@ public final class CellIdentityCdma implements Parcelable { * * @hide */ - public CellIdentityCdma (int nid, int sid, int bid, int lon, int lat, String alphal, + public CellIdentityCdma(int nid, int sid, int bid, int lon, int lat, String alphal, String alphas) { + super(TAG, TYPE_CDMA, null, null); mNetworkId = nid; mSystemId = sid; mBasestationId = bid; @@ -196,40 +195,33 @@ public final class CellIdentityCdma implements Parcelable { CellIdentityCdma o = (CellIdentityCdma) other; - return mNetworkId == o.mNetworkId && - mSystemId == o.mSystemId && - mBasestationId == o.mBasestationId && - mLatitude == o.mLatitude && - mLongitude == o.mLongitude && - TextUtils.equals(mAlphaLong, o.mAlphaLong) && - TextUtils.equals(mAlphaShort, o.mAlphaShort); + return mNetworkId == o.mNetworkId + && mSystemId == o.mSystemId + && mBasestationId == o.mBasestationId + && mLatitude == o.mLatitude + && mLongitude == o.mLongitude + && TextUtils.equals(mAlphaLong, o.mAlphaLong) + && TextUtils.equals(mAlphaShort, o.mAlphaShort); } @Override public String toString() { - StringBuilder sb = new StringBuilder("CellIdentityCdma:{"); - 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); - sb.append(" mAlphaLong="); sb.append(mAlphaLong); - sb.append(" mAlphaShort="); sb.append(mAlphaShort); - sb.append("}"); - - return sb.toString(); - } - - /** Implement the Parcelable interface */ - @Override - public int describeContents() { - return 0; + return new StringBuilder(TAG) + .append(":{ mNetworkId=").append(mNetworkId) + .append(" mSystemId=").append(mSystemId) + .append(" mBasestationId=").append(mBasestationId) + .append(" mLongitude=").append(mLongitude) + .append(" mLatitude=").append(mLatitude) + .append(" mAlphaLong=").append(mAlphaLong) + .append(" mAlphaShort=").append(mAlphaShort) + .append("}").toString(); } /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); + super.writeToParcel(dest, TYPE_CDMA); dest.writeInt(mNetworkId); dest.writeInt(mSystemId); dest.writeInt(mBasestationId); @@ -241,10 +233,16 @@ public final class CellIdentityCdma implements Parcelable { /** Construct from Parcel, type has already been processed */ private CellIdentityCdma(Parcel in) { - this(in.readInt(), in.readInt(), in.readInt(), in.readInt(), in.readInt(), - in.readString(), in.readString()); - - if (DBG) log("CellIdentityCdma(Parcel): " + toString()); + super(TAG, TYPE_CDMA, in); + mNetworkId = in.readInt(); + mSystemId = in.readInt(); + mBasestationId = in.readInt(); + mLongitude = in.readInt(); + mLatitude = in.readInt(); + mAlphaLong = in.readString(); + mAlphaShort = in.readString(); + + if (DBG) log(toString()); } /** Implement the Parcelable interface */ @@ -253,7 +251,8 @@ public final class CellIdentityCdma implements Parcelable { new Creator<CellIdentityCdma>() { @Override public CellIdentityCdma createFromParcel(Parcel in) { - return new CellIdentityCdma(in); + in.readInt(); // skip + return createFromParcelBody(in); } @Override @@ -262,10 +261,8 @@ public final class CellIdentityCdma implements Parcelable { } }; - /** - * log - */ - private static void log(String s) { - Rlog.w(LOG_TAG, s); + /** @hide */ + protected static CellIdentityCdma createFromParcelBody(Parcel in) { + return new CellIdentityCdma(in); } } diff --git a/telephony/java/android/telephony/CellIdentityGsm.java b/telephony/java/android/telephony/CellIdentityGsm.java index 376e6aa77155..f948f812676f 100644 --- a/telephony/java/android/telephony/CellIdentityGsm.java +++ b/telephony/java/android/telephony/CellIdentityGsm.java @@ -17,8 +17,6 @@ package android.telephony; import android.os.Parcel; -import android.os.Parcelable; -import android.telephony.Rlog; import android.text.TextUtils; import java.util.Objects; @@ -26,9 +24,8 @@ import java.util.Objects; /** * CellIdentity to represent a unique GSM cell */ -public final class CellIdentityGsm implements Parcelable { - - private static final String LOG_TAG = "CellIdentityGsm"; +public final class CellIdentityGsm extends CellIdentity { + private static final String TAG = CellIdentityGsm.class.getSimpleName(); private static final boolean DBG = false; // 16-bit Location Area Code, 0..65535 @@ -39,10 +36,6 @@ public final class CellIdentityGsm implements Parcelable { private final int mArfcn; // 6-bit Base Station Identity Code private final int mBsic; - // 3-digit Mobile Country Code in string format - private final String mMccStr; - // 2 or 3-digit Mobile Network Code in string format - private final String mMncStr; // long alpha Operator Name String or Enhanced Operator Name String private final String mAlphaLong; // short alpha Operator Name String or Enhanced Operator Name String @@ -52,12 +45,11 @@ public final class CellIdentityGsm implements Parcelable { * @hide */ public CellIdentityGsm() { + super(TAG, TYPE_GSM, null, null); mLac = Integer.MAX_VALUE; mCid = Integer.MAX_VALUE; mArfcn = Integer.MAX_VALUE; mBsic = Integer.MAX_VALUE; - mMccStr = null; - mMncStr = null; mAlphaLong = null; mAlphaShort = null; } @@ -70,7 +62,7 @@ public final class CellIdentityGsm implements Parcelable { * * @hide */ - public CellIdentityGsm (int mcc, int mnc, int lac, int cid) { + public CellIdentityGsm(int mcc, int mnc, int lac, int cid) { this(lac, cid, Integer.MAX_VALUE, Integer.MAX_VALUE, String.valueOf(mcc), String.valueOf(mnc), null, null); } @@ -86,7 +78,7 @@ public final class CellIdentityGsm implements Parcelable { * * @hide */ - public CellIdentityGsm (int mcc, int mnc, int lac, int cid, int arfcn, int bsic) { + public CellIdentityGsm(int mcc, int mnc, int lac, int cid, int arfcn, int bsic) { this(lac, cid, arfcn, bsic, String.valueOf(mcc), String.valueOf(mnc), null, null); } @@ -103,8 +95,9 @@ public final class CellIdentityGsm implements Parcelable { * * @hide */ - public CellIdentityGsm (int lac, int cid, int arfcn, int bsic, String mccStr, + public CellIdentityGsm(int lac, int cid, int arfcn, int bsic, String mccStr, String mncStr, String alphal, String alphas) { + super(TAG, TYPE_GSM, mccStr, mncStr); mLac = lac; mCid = cid; mArfcn = arfcn; @@ -112,31 +105,6 @@ public final class CellIdentityGsm implements Parcelable { // for inbound parcels mBsic = (bsic == 0xFF) ? Integer.MAX_VALUE : bsic; - // Only allow INT_MAX if unknown string mcc/mnc - if (mccStr == null || mccStr.matches("^[0-9]{3}$")) { - mMccStr = mccStr; - } else if (mccStr.isEmpty() || mccStr.equals(String.valueOf(Integer.MAX_VALUE))) { - // If the mccStr is empty or unknown, set it as null. - mMccStr = null; - } else { - // TODO: b/69384059 Should throw IllegalArgumentException for the invalid MCC format - // after the bug got fixed. - mMccStr = null; - log("invalid MCC format: " + mccStr); - } - - if (mncStr == null || mncStr.matches("^[0-9]{2,3}$")) { - mMncStr = mncStr; - } else if (mncStr.isEmpty() || mncStr.equals(String.valueOf(Integer.MAX_VALUE))) { - // If the mncStr is empty or unknown, set it as null. - mMncStr = null; - } else { - // TODO: b/69384059 Should throw IllegalArgumentException for the invalid MNC format - // after the bug got fixed. - mMncStr = null; - log("invalid MNC format: " + mncStr); - } - mAlphaLong = alphal; mAlphaShort = alphas; } @@ -237,6 +205,7 @@ public final class CellIdentityGsm implements Parcelable { /** + * @deprecated Primary Scrambling Code is not applicable to GSM. * @return Integer.MAX_VALUE, undefined for GSM */ @Deprecated @@ -260,58 +229,54 @@ public final class CellIdentityGsm implements Parcelable { } CellIdentityGsm o = (CellIdentityGsm) other; - return mLac == o.mLac && - mCid == o.mCid && - mArfcn == o.mArfcn && - mBsic == o.mBsic && - TextUtils.equals(mMccStr, o.mMccStr) && - TextUtils.equals(mMncStr, o.mMncStr) && - TextUtils.equals(mAlphaLong, o.mAlphaLong) && - TextUtils.equals(mAlphaShort, o.mAlphaShort); + return mLac == o.mLac + && mCid == o.mCid + && mArfcn == o.mArfcn + && mBsic == o.mBsic + && TextUtils.equals(mMccStr, o.mMccStr) + && TextUtils.equals(mMncStr, o.mMncStr) + && TextUtils.equals(mAlphaLong, o.mAlphaLong) + && TextUtils.equals(mAlphaShort, o.mAlphaShort); } @Override public String toString() { - StringBuilder sb = new StringBuilder("CellIdentityGsm:{"); - sb.append(" mLac=").append(mLac); - sb.append(" mCid=").append(mCid); - sb.append(" mArfcn=").append(mArfcn); - sb.append(" mBsic=").append("0x").append(Integer.toHexString(mBsic)); - sb.append(" mMcc=").append(mMccStr); - sb.append(" mMnc=").append(mMncStr); - sb.append(" mAlphaLong=").append(mAlphaLong); - sb.append(" mAlphaShort=").append(mAlphaShort); - sb.append("}"); - - return sb.toString(); - } - - /** Implement the Parcelable interface */ - @Override - public int describeContents() { - return 0; + return new StringBuilder(TAG) + .append(":{ mLac=").append(mLac) + .append(" mCid=").append(mCid) + .append(" mArfcn=").append(mArfcn) + .append(" mBsic=").append("0x").append(Integer.toHexString(mBsic)) + .append(" mMcc=").append(mMccStr) + .append(" mMnc=").append(mMncStr) + .append(" mAlphaLong=").append(mAlphaLong) + .append(" mAlphaShort=").append(mAlphaShort) + .append("}").toString(); } /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); + super.writeToParcel(dest, TYPE_GSM); dest.writeInt(mLac); dest.writeInt(mCid); dest.writeInt(mArfcn); dest.writeInt(mBsic); - dest.writeString(mMccStr); - dest.writeString(mMncStr); dest.writeString(mAlphaLong); dest.writeString(mAlphaShort); } /** Construct from Parcel, type has already been processed */ private CellIdentityGsm(Parcel in) { - this(in.readInt(), in.readInt(), in.readInt(), in.readInt(), in.readString(), - in.readString(), in.readString(), in.readString()); - - if (DBG) log("CellIdentityGsm(Parcel): " + toString()); + super(TAG, TYPE_GSM, in); + mLac = in.readInt(); + mCid = in.readInt(); + mArfcn = in.readInt(); + mBsic = in.readInt(); + mAlphaLong = in.readString(); + mAlphaShort = in.readString(); + + if (DBG) log(toString()); } /** Implement the Parcelable interface */ @@ -320,7 +285,8 @@ public final class CellIdentityGsm implements Parcelable { new Creator<CellIdentityGsm>() { @Override public CellIdentityGsm createFromParcel(Parcel in) { - return new CellIdentityGsm(in); + in.readInt(); // skip + return createFromParcelBody(in); } @Override @@ -329,10 +295,8 @@ public final class CellIdentityGsm implements Parcelable { } }; - /** - * log - */ - private static void log(String s) { - Rlog.w(LOG_TAG, s); + /** @hide */ + protected static CellIdentityGsm createFromParcelBody(Parcel in) { + return new CellIdentityGsm(in); } -}
\ No newline at end of file +} diff --git a/telephony/java/android/telephony/CellIdentityLte.java b/telephony/java/android/telephony/CellIdentityLte.java index 6ca5daf63375..7f20c8ae5f45 100644 --- a/telephony/java/android/telephony/CellIdentityLte.java +++ b/telephony/java/android/telephony/CellIdentityLte.java @@ -17,8 +17,6 @@ package android.telephony; import android.os.Parcel; -import android.os.Parcelable; -import android.telephony.Rlog; import android.text.TextUtils; import java.util.Objects; @@ -26,9 +24,8 @@ import java.util.Objects; /** * CellIdentity is to represent a unique LTE cell */ -public final class CellIdentityLte implements Parcelable { - - private static final String LOG_TAG = "CellIdentityLte"; +public final class CellIdentityLte extends CellIdentity { + private static final String TAG = CellIdentityLte.class.getSimpleName(); private static final boolean DBG = false; // 28-bit cell identity @@ -39,10 +36,6 @@ public final class CellIdentityLte implements Parcelable { private final int mTac; // 18-bit Absolute RF Channel Number private final int mEarfcn; - // 3-digit Mobile Country Code in string format - private final String mMccStr; - // 2 or 3-digit Mobile Network Code in string format - private final String mMncStr; // long alpha Operator Name String or Enhanced Operator Name String private final String mAlphaLong; // short alpha Operator Name String or Enhanced Operator Name String @@ -52,12 +45,11 @@ public final class CellIdentityLte implements Parcelable { * @hide */ public CellIdentityLte() { + super(TAG, TYPE_LTE, null, null); mCi = Integer.MAX_VALUE; mPci = Integer.MAX_VALUE; mTac = Integer.MAX_VALUE; mEarfcn = Integer.MAX_VALUE; - mMccStr = null; - mMncStr = null; mAlphaLong = null; mAlphaShort = null; } @@ -72,7 +64,7 @@ public final class CellIdentityLte implements Parcelable { * * @hide */ - public CellIdentityLte (int mcc, int mnc, int ci, int pci, int tac) { + public CellIdentityLte(int mcc, int mnc, int ci, int pci, int tac) { this(ci, pci, tac, Integer.MAX_VALUE, String.valueOf(mcc), String.valueOf(mnc), null, null); } @@ -87,7 +79,7 @@ public final class CellIdentityLte implements Parcelable { * * @hide */ - public CellIdentityLte (int mcc, int mnc, int ci, int pci, int tac, int earfcn) { + public CellIdentityLte(int mcc, int mnc, int ci, int pci, int tac, int earfcn) { this(ci, pci, tac, earfcn, String.valueOf(mcc), String.valueOf(mnc), null, null); } @@ -104,38 +96,13 @@ public final class CellIdentityLte implements Parcelable { * * @hide */ - public CellIdentityLte (int ci, int pci, int tac, int earfcn, String mccStr, + public CellIdentityLte(int ci, int pci, int tac, int earfcn, String mccStr, String mncStr, String alphal, String alphas) { + super(TAG, TYPE_LTE, mccStr, mncStr); mCi = ci; mPci = pci; mTac = tac; mEarfcn = earfcn; - - // Only allow INT_MAX if unknown string mcc/mnc - if (mccStr == null || mccStr.matches("^[0-9]{3}$")) { - mMccStr = mccStr; - } else if (mccStr.isEmpty() || mccStr.equals(String.valueOf(Integer.MAX_VALUE))) { - // If the mccStr is empty or unknown, set it as null. - mMccStr = null; - } else { - // TODO: b/69384059 Should throw IllegalArgumentException for the invalid MCC format - // after the bug got fixed. - mMccStr = null; - log("invalid MCC format: " + mccStr); - } - - if (mncStr == null || mncStr.matches("^[0-9]{2,3}$")) { - mMncStr = mncStr; - } else if (mncStr.isEmpty() || mncStr.equals(String.valueOf(Integer.MAX_VALUE))) { - // If the mncStr is empty or unknown, set it as null. - mMncStr = null; - } else { - // TODO: b/69384059 Should throw IllegalArgumentException for the invalid MNC format - // after the bug got fixed. - mMncStr = null; - log("invalid MNC format: " + mncStr); - } - mAlphaLong = alphal; mAlphaShort = alphas; } @@ -248,58 +215,54 @@ public final class CellIdentityLte implements Parcelable { } CellIdentityLte o = (CellIdentityLte) other; - return mCi == o.mCi && - mPci == o.mPci && - mTac == o.mTac && - mEarfcn == o.mEarfcn && - TextUtils.equals(mMccStr, o.mMccStr) && - TextUtils.equals(mMncStr, o.mMncStr) && - TextUtils.equals(mAlphaLong, o.mAlphaLong) && - TextUtils.equals(mAlphaShort, o.mAlphaShort); + return mCi == o.mCi + && mPci == o.mPci + && mTac == o.mTac + && mEarfcn == o.mEarfcn + && TextUtils.equals(mMccStr, o.mMccStr) + && TextUtils.equals(mMncStr, o.mMncStr) + && TextUtils.equals(mAlphaLong, o.mAlphaLong) + && TextUtils.equals(mAlphaShort, o.mAlphaShort); } @Override public String toString() { - StringBuilder sb = new StringBuilder("CellIdentityLte:{"); - sb.append(" mCi="); sb.append(mCi); - sb.append(" mPci="); sb.append(mPci); - sb.append(" mTac="); sb.append(mTac); - sb.append(" mEarfcn="); sb.append(mEarfcn); - sb.append(" mMcc="); sb.append(mMccStr); - sb.append(" mMnc="); sb.append(mMncStr); - sb.append(" mAlphaLong="); sb.append(mAlphaLong); - sb.append(" mAlphaShort="); sb.append(mAlphaShort); - sb.append("}"); - - return sb.toString(); - } - - /** Implement the Parcelable interface */ - @Override - public int describeContents() { - return 0; + return new StringBuilder(TAG) + .append(":{ mCi=").append(mCi) + .append(" mPci=").append(mPci) + .append(" mTac=").append(mTac) + .append(" mEarfcn=").append(mEarfcn) + .append(" mMcc=").append(mMccStr) + .append(" mMnc=").append(mMncStr) + .append(" mAlphaLong=").append(mAlphaLong) + .append(" mAlphaShort=").append(mAlphaShort) + .append("}").toString(); } /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); + super.writeToParcel(dest, TYPE_LTE); dest.writeInt(mCi); dest.writeInt(mPci); dest.writeInt(mTac); dest.writeInt(mEarfcn); - dest.writeString(mMccStr); - dest.writeString(mMncStr); dest.writeString(mAlphaLong); dest.writeString(mAlphaShort); } /** Construct from Parcel, type has already been processed */ private CellIdentityLte(Parcel in) { - this(in.readInt(), in.readInt(), in.readInt(), in.readInt(), in.readString(), - in.readString(), in.readString(), in.readString()); - - if (DBG) log("CellIdentityLte(Parcel): " + toString()); + super(TAG, TYPE_LTE, in); + mCi = in.readInt(); + mPci = in.readInt(); + mTac = in.readInt(); + mEarfcn = in.readInt(); + mAlphaLong = in.readString(); + mAlphaShort = in.readString(); + + if (DBG) log(toString()); } /** Implement the Parcelable interface */ @@ -308,7 +271,8 @@ public final class CellIdentityLte implements Parcelable { new Creator<CellIdentityLte>() { @Override public CellIdentityLte createFromParcel(Parcel in) { - return new CellIdentityLte(in); + in.readInt(); // skip; + return createFromParcelBody(in); } @Override @@ -317,10 +281,8 @@ public final class CellIdentityLte implements Parcelable { } }; - /** - * log - */ - private static void log(String s) { - Rlog.w(LOG_TAG, s); + /** @hide */ + protected static CellIdentityLte createFromParcelBody(Parcel in) { + return new CellIdentityLte(in); } -}
\ No newline at end of file +} diff --git a/telephony/java/android/telephony/CellIdentityTdscdma.aidl b/telephony/java/android/telephony/CellIdentityTdscdma.aidl new file mode 100644 index 000000000000..2a182cdfe176 --- /dev/null +++ b/telephony/java/android/telephony/CellIdentityTdscdma.aidl @@ -0,0 +1,20 @@ +/* + * Copyright 2017 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. + */ + +/** @hide */ +package android.telephony; + +parcelable CellIdentityTdscdma; diff --git a/telephony/java/android/telephony/CellIdentityTdscdma.java b/telephony/java/android/telephony/CellIdentityTdscdma.java new file mode 100644 index 000000000000..001d19f777fd --- /dev/null +++ b/telephony/java/android/telephony/CellIdentityTdscdma.java @@ -0,0 +1,196 @@ +/* + * Copyright 2017 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.text.TextUtils; + +import java.util.Objects; + +/** + * CellIdentity is to represent a unique TD-SCDMA cell + */ +public final class CellIdentityTdscdma extends CellIdentity { + private static final String TAG = CellIdentityTdscdma.class.getSimpleName(); + private static final boolean DBG = false; + + // 16-bit Location Area Code, 0..65535, INT_MAX if unknown. + private final int mLac; + // 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown. + private final int mCid; + // 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown. + private final int mCpid; + + /** + * @hide + */ + public CellIdentityTdscdma() { + super(TAG, TYPE_TDSCDMA, null, null); + mLac = Integer.MAX_VALUE; + mCid = Integer.MAX_VALUE; + mCpid = Integer.MAX_VALUE; + } + + /** + * @param mcc 3-digit Mobile Country Code, 0..999 + * @param mnc 2 or 3-digit Mobile Network Code, 0..999 + * @param lac 16-bit Location Area Code, 0..65535, INT_MAX if unknown + * @param cid 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown + * @param cpid 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown + * + * @hide + */ + public CellIdentityTdscdma(int mcc, int mnc, int lac, int cid, int cpid) { + this(String.valueOf(mcc), String.valueOf(mnc), lac, cid, cpid); + } + + /** + * @param mcc 3-digit Mobile Country Code in string format + * @param mnc 2 or 3-digit Mobile Network Code in string format + * @param lac 16-bit Location Area Code, 0..65535, INT_MAX if unknown + * @param cid 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown + * @param cpid 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown + * + * @hide + */ + public CellIdentityTdscdma(String mcc, String mnc, int lac, int cid, int cpid) { + super(TAG, TYPE_TDSCDMA, mcc, mnc); + mLac = lac; + mCid = cid; + mCpid = cpid; + } + + private CellIdentityTdscdma(CellIdentityTdscdma cid) { + this(cid.mMccStr, cid.mMncStr, cid.mLac, cid.mCid, cid.mCpid); + } + + CellIdentityTdscdma copy() { + return new CellIdentityTdscdma(this); + } + + /** + * Get Mobile Country Code in string format + * @return Mobile Country Code in string format, null if unknown + */ + public String getMccStr() { + return mMccStr; + } + + /** + * Get Mobile Network Code in string format + * @return Mobile Network Code in string format, null if unknown + */ + public String getMncStr() { + return mMncStr; + } + + /** + * @return 16-bit Location Area Code, 0..65535, INT_MAX if unknown + */ + public int getLac() { + return mLac; + } + + /** + * @return 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown + */ + public int getCid() { + return mCid; + } + + /** + * @return 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown + */ + public int getCpid() { + return mCpid; + } + + @Override + public int hashCode() { + return Objects.hash(mMccStr, mMncStr, mLac, mCid, mCpid); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + + if (!(other instanceof CellIdentityTdscdma)) { + return false; + } + + CellIdentityTdscdma o = (CellIdentityTdscdma) other; + return TextUtils.equals(mMccStr, o.mMccStr) + && TextUtils.equals(mMncStr, o.mMncStr) + && mLac == o.mLac + && mCid == o.mCid + && mCpid == o.mCpid; + } + + @Override + public String toString() { + return new StringBuilder(TAG) + .append(":{ mMcc=").append(mMccStr) + .append(" mMnc=").append(mMncStr) + .append(" mLac=").append(mLac) + .append(" mCid=").append(mCid) + .append(" mCpid=").append(mCpid) + .append("}").toString(); + } + + /** Implement the Parcelable interface */ + @Override + public void writeToParcel(Parcel dest, int flags) { + if (DBG) log("writeToParcel(Parcel, int): " + toString()); + super.writeToParcel(dest, TYPE_TDSCDMA); + dest.writeInt(mLac); + dest.writeInt(mCid); + dest.writeInt(mCpid); + } + + /** Construct from Parcel, type has already been processed */ + private CellIdentityTdscdma(Parcel in) { + super(TAG, TYPE_TDSCDMA, in); + mLac = in.readInt(); + mCid = in.readInt(); + mCpid = in.readInt(); + + if (DBG) log(toString()); + } + + /** Implement the Parcelable interface */ + @SuppressWarnings("hiding") + public static final Creator<CellIdentityTdscdma> CREATOR = + new Creator<CellIdentityTdscdma>() { + @Override + public CellIdentityTdscdma createFromParcel(Parcel in) { + in.readInt(); // skip + return createFromParcelBody(in); + } + + @Override + public CellIdentityTdscdma[] newArray(int size) { + return new CellIdentityTdscdma[size]; + } + }; + + /** @hide */ + protected static CellIdentityTdscdma createFromParcelBody(Parcel in) { + return new CellIdentityTdscdma(in); + } +} diff --git a/telephony/java/android/telephony/CellIdentityWcdma.java b/telephony/java/android/telephony/CellIdentityWcdma.java index e4bb4f297a3f..1aa1715ee3e8 100644 --- a/telephony/java/android/telephony/CellIdentityWcdma.java +++ b/telephony/java/android/telephony/CellIdentityWcdma.java @@ -17,8 +17,6 @@ package android.telephony; import android.os.Parcel; -import android.os.Parcelable; -import android.telephony.Rlog; import android.text.TextUtils; import java.util.Objects; @@ -26,9 +24,8 @@ import java.util.Objects; /** * CellIdentity to represent a unique UMTS cell */ -public final class CellIdentityWcdma implements Parcelable { - - private static final String LOG_TAG = "CellIdentityWcdma"; +public final class CellIdentityWcdma extends CellIdentity { + private static final String TAG = CellIdentityWcdma.class.getSimpleName(); private static final boolean DBG = false; // 16-bit Location Area Code, 0..65535 @@ -39,10 +36,6 @@ public final class CellIdentityWcdma implements Parcelable { private final int mPsc; // 16-bit UMTS Absolute RF Channel Number private final int mUarfcn; - // 3-digit Mobile Country Code in string format - private final String mMccStr; - // 2 or 3-digit Mobile Network Code in string format - private final String mMncStr; // long alpha Operator Name String or Enhanced Operator Name String private final String mAlphaLong; // short alpha Operator Name String or Enhanced Operator Name String @@ -52,12 +45,11 @@ public final class CellIdentityWcdma implements Parcelable { * @hide */ public CellIdentityWcdma() { + super(TAG, TYPE_TDSCDMA, null, null); mLac = Integer.MAX_VALUE; mCid = Integer.MAX_VALUE; mPsc = Integer.MAX_VALUE; mUarfcn = Integer.MAX_VALUE; - mMccStr = null; - mMncStr = null; mAlphaLong = null; mAlphaShort = null; } @@ -106,36 +98,11 @@ public final class CellIdentityWcdma implements Parcelable { */ public CellIdentityWcdma (int lac, int cid, int psc, int uarfcn, String mccStr, String mncStr, String alphal, String alphas) { + super(TAG, TYPE_WCDMA, mccStr, mncStr); mLac = lac; mCid = cid; mPsc = psc; mUarfcn = uarfcn; - - // Only allow INT_MAX if unknown string mcc/mnc - if (mccStr == null || mccStr.matches("^[0-9]{3}$")) { - mMccStr = mccStr; - } else if (mccStr.isEmpty() || mccStr.equals(String.valueOf(Integer.MAX_VALUE))) { - // If the mccStr is empty or unknown, set it as null. - mMccStr = null; - } else { - // TODO: b/69384059 Should throw IllegalArgumentException for the invalid MCC format - // after the bug got fixed. - mMccStr = null; - log("invalid MCC format: " + mccStr); - } - - if (mncStr == null || mncStr.matches("^[0-9]{2,3}$")) { - mMncStr = mncStr; - } else if (mncStr.isEmpty() || mncStr.equals(String.valueOf(Integer.MAX_VALUE))) { - // If the mncStr is empty or unknown, set it as null. - mMncStr = null; - } else { - // TODO: b/69384059 Should throw IllegalArgumentException for the invalid MNC format - // after the bug got fixed. - mMncStr = null; - log("invalid MNC format: " + mncStr); - } - mAlphaLong = alphal; mAlphaShort = alphas; } @@ -250,58 +217,53 @@ public final class CellIdentityWcdma implements Parcelable { } CellIdentityWcdma o = (CellIdentityWcdma) other; - return mLac == o.mLac && - mCid == o.mCid && - mPsc == o.mPsc && - mUarfcn == o.mUarfcn && - TextUtils.equals(mMccStr, o.mMccStr) && - TextUtils.equals(mMncStr, o.mMncStr) && - TextUtils.equals(mAlphaLong, o.mAlphaLong) && - TextUtils.equals(mAlphaShort, o.mAlphaShort); + return mLac == o.mLac + && mCid == o.mCid + && mPsc == o.mPsc + && mUarfcn == o.mUarfcn + && TextUtils.equals(mMccStr, o.mMccStr) + && TextUtils.equals(mMncStr, o.mMncStr) + && TextUtils.equals(mAlphaLong, o.mAlphaLong) + && TextUtils.equals(mAlphaShort, o.mAlphaShort); } @Override public String toString() { - StringBuilder sb = new StringBuilder("CellIdentityWcdma:{"); - sb.append(" mLac=").append(mLac); - sb.append(" mCid=").append(mCid); - sb.append(" mPsc=").append(mPsc); - sb.append(" mUarfcn=").append(mUarfcn); - sb.append(" mMcc=").append(mMccStr); - sb.append(" mMnc=").append(mMncStr); - sb.append(" mAlphaLong=").append(mAlphaLong); - sb.append(" mAlphaShort=").append(mAlphaShort); - sb.append("}"); - - return sb.toString(); - } - - /** Implement the Parcelable interface */ - @Override - public int describeContents() { - return 0; + return new StringBuilder(TAG) + .append(":{ mLac=").append(mLac) + .append(" mCid=").append(mCid) + .append(" mPsc=").append(mPsc) + .append(" mUarfcn=").append(mUarfcn) + .append(" mMcc=").append(mMccStr) + .append(" mMnc=").append(mMncStr) + .append(" mAlphaLong=").append(mAlphaLong) + .append(" mAlphaShort=").append(mAlphaShort) + .append("}").toString(); } /** Implement the Parcelable interface */ @Override public void writeToParcel(Parcel dest, int flags) { if (DBG) log("writeToParcel(Parcel, int): " + toString()); + super.writeToParcel(dest, TYPE_WCDMA); dest.writeInt(mLac); dest.writeInt(mCid); dest.writeInt(mPsc); dest.writeInt(mUarfcn); - dest.writeString(mMccStr); - dest.writeString(mMncStr); dest.writeString(mAlphaLong); dest.writeString(mAlphaShort); } /** Construct from Parcel, type has already been processed */ private CellIdentityWcdma(Parcel in) { - this(in.readInt(), in.readInt(), in.readInt(), in.readInt(), in.readString(), - in.readString(), in.readString(), in.readString()); - - if (DBG) log("CellIdentityWcdma(Parcel): " + toString()); + super(TAG, TYPE_WCDMA, in); + mLac = in.readInt(); + mCid = in.readInt(); + mPsc = in.readInt(); + mUarfcn = in.readInt(); + mAlphaLong = in.readString(); + mAlphaShort = in.readString(); + if (DBG) log(toString()); } /** Implement the Parcelable interface */ @@ -310,7 +272,8 @@ public final class CellIdentityWcdma implements Parcelable { new Creator<CellIdentityWcdma>() { @Override public CellIdentityWcdma createFromParcel(Parcel in) { - return new CellIdentityWcdma(in); + in.readInt(); // skip + return createFromParcelBody(in); } @Override @@ -319,10 +282,8 @@ public final class CellIdentityWcdma implements Parcelable { } }; - /** - * log - */ - private static void log(String s) { - Rlog.w(LOG_TAG, s); + /** @hide */ + protected static CellIdentityWcdma createFromParcelBody(Parcel in) { + return new CellIdentityWcdma(in); } }
\ No newline at end of file |