diff --git a/api/current.txt b/api/current.txt index 93ae5be665385..050ab43d925e2 100644 --- a/api/current.txt +++ b/api/current.txt @@ -45017,7 +45017,7 @@ package android.telephony { public final class CellIdentityLte extends android.telephony.CellIdentity { method @NonNull public java.util.Set getAdditionalPlmns(); - method @NonNull public java.util.List getBands(); + method @NonNull public int[] getBands(); method public int getBandwidth(); method public int getCi(); method @Nullable public android.telephony.ClosedSubscriberGroupInfo getClosedSubscriberGroupInfo(); @@ -45035,7 +45035,7 @@ package android.telephony { public final class CellIdentityNr extends android.telephony.CellIdentity { method @NonNull public java.util.Set getAdditionalPlmns(); - method @NonNull public java.util.List getBands(); + method @NonNull public int[] getBands(); method @Nullable public String getMccString(); method @Nullable public String getMncString(); method public long getNci(); diff --git a/telephony/java/android/telephony/CellIdentityLte.java b/telephony/java/android/telephony/CellIdentityLte.java index d672c77bed01d..b4ce162274fba 100644 --- a/telephony/java/android/telephony/CellIdentityLte.java +++ b/telephony/java/android/telephony/CellIdentityLte.java @@ -25,10 +25,9 @@ import android.telephony.gsm.GsmCellLocation; import android.text.TextUtils; import android.util.ArraySet; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Objects; import java.util.Set; @@ -56,7 +55,7 @@ public final class CellIdentityLte extends CellIdentity { // cell bandwidth, in kHz private final int mBandwidth; // cell bands - private final List mBands; + private final int[] mBands; // a list of additional PLMN-IDs reported for this cell private final ArraySet mAdditionalPlmns; @@ -73,7 +72,7 @@ public final class CellIdentityLte extends CellIdentity { mPci = CellInfo.UNAVAILABLE; mTac = CellInfo.UNAVAILABLE; mEarfcn = CellInfo.UNAVAILABLE; - mBands = Collections.emptyList(); + mBands = new int[] {}; mBandwidth = CellInfo.UNAVAILABLE; mAdditionalPlmns = new ArraySet<>(); mCsgInfo = null; @@ -91,7 +90,7 @@ public final class CellIdentityLte extends CellIdentity { */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) public CellIdentityLte(int mcc, int mnc, int ci, int pci, int tac) { - this(ci, pci, tac, CellInfo.UNAVAILABLE, Collections.emptyList(), CellInfo.UNAVAILABLE, + this(ci, pci, tac, CellInfo.UNAVAILABLE, new int[] {}, CellInfo.UNAVAILABLE, String.valueOf(mcc), String.valueOf(mnc), null, null, new ArraySet<>(), null); } @@ -112,16 +111,17 @@ public final class CellIdentityLte extends CellIdentity { * * @hide */ - public CellIdentityLte(int ci, int pci, int tac, int earfcn, List bands, int bandwidth, - @Nullable String mccStr, @Nullable String mncStr, @Nullable String alphal, - @Nullable String alphas, @NonNull Collection additionalPlmns, + public CellIdentityLte(int ci, int pci, int tac, int earfcn, @NonNull int[] bands, + int bandwidth, @Nullable String mccStr, @Nullable String mncStr, + @Nullable String alphal, @Nullable String alphas, + @NonNull Collection additionalPlmns, @Nullable ClosedSubscriberGroupInfo csgInfo) { super(TAG, CellInfo.TYPE_LTE, mccStr, mncStr, alphal, alphas); mCi = inRangeOrUnavailable(ci, 0, MAX_CI); mPci = inRangeOrUnavailable(pci, 0, MAX_PCI); mTac = inRangeOrUnavailable(tac, 0, MAX_TAC); mEarfcn = inRangeOrUnavailable(earfcn, 0, MAX_EARFCN); - mBands = new ArrayList<>(bands); + mBands = bands; mBandwidth = inRangeOrUnavailable(bandwidth, 0, MAX_BANDWIDTH); mAdditionalPlmns = new ArraySet<>(additionalPlmns.size()); for (String plmn : additionalPlmns) { @@ -134,13 +134,13 @@ public final class CellIdentityLte extends CellIdentity { /** @hide */ public CellIdentityLte(@NonNull android.hardware.radio.V1_0.CellIdentityLte cid) { - this(cid.ci, cid.pci, cid.tac, cid.earfcn, Collections.emptyList(), + this(cid.ci, cid.pci, cid.tac, cid.earfcn, new int[] {}, CellInfo.UNAVAILABLE, cid.mcc, cid.mnc, "", "", new ArraySet<>(), null); } /** @hide */ public CellIdentityLte(@NonNull android.hardware.radio.V1_2.CellIdentityLte cid) { - this(cid.base.ci, cid.base.pci, cid.base.tac, cid.base.earfcn, Collections.emptyList(), + this(cid.base.ci, cid.base.pci, cid.base.tac, cid.base.earfcn, new int[] {}, cid.bandwidth, cid.base.mcc, cid.base.mnc, cid.operatorNames.alphaLong, cid.operatorNames.alphaShort, new ArraySet<>(), null); } @@ -148,9 +148,10 @@ public final class CellIdentityLte extends CellIdentity { /** @hide */ public CellIdentityLte(@NonNull android.hardware.radio.V1_5.CellIdentityLte cid) { this(cid.base.base.ci, cid.base.base.pci, cid.base.base.tac, cid.base.base.earfcn, - cid.bands, cid.base.bandwidth, cid.base.base.mcc, cid.base.base.mnc, - cid.base.operatorNames.alphaLong, cid.base.operatorNames.alphaShort, - cid.additionalPlmns, cid.optionalCsgInfo.csgInfo() != null + cid.bands.stream().mapToInt(Integer::intValue).toArray(), cid.base.bandwidth, + cid.base.base.mcc, cid.base.base.mnc, cid.base.operatorNames.alphaLong, + cid.base.operatorNames.alphaShort, cid.additionalPlmns, + cid.optionalCsgInfo.csgInfo() != null ? new ClosedSubscriberGroupInfo(cid.optionalCsgInfo.csgInfo()) : null); } @@ -228,11 +229,11 @@ public final class CellIdentityLte extends CellIdentity { * * Reference: 3GPP TS 36.101 section 5.5 * - * @return List of band number or empty list if not available. + * @return Array of band number or empty array if not available. */ @NonNull - public List getBands() { - return Collections.unmodifiableList(mBands); + public int[] getBands() { + return Arrays.copyOf(mBands, mBands.length); } /** @@ -314,8 +315,8 @@ public final class CellIdentityLte extends CellIdentity { @Override public int hashCode() { - return Objects.hash(mCi, mPci, mTac, - mAdditionalPlmns.hashCode(), mCsgInfo, super.hashCode()); + return Objects.hash(mCi, mPci, mTac, mEarfcn, Arrays.hashCode(mBands), + mBandwidth, mAdditionalPlmns.hashCode(), mCsgInfo, super.hashCode()); } @Override @@ -333,6 +334,7 @@ public final class CellIdentityLte extends CellIdentity { && mPci == o.mPci && mTac == o.mTac && mEarfcn == o.mEarfcn + && Arrays.equals(mBands, o.mBands) && mBandwidth == o.mBandwidth && TextUtils.equals(mMccStr, o.mMccStr) && TextUtils.equals(mMncStr, o.mMncStr) @@ -368,7 +370,7 @@ public final class CellIdentityLte extends CellIdentity { dest.writeInt(mPci); dest.writeInt(mTac); dest.writeInt(mEarfcn); - dest.writeList(mBands); + dest.writeIntArray(mBands); dest.writeInt(mBandwidth); dest.writeArraySet(mAdditionalPlmns); dest.writeParcelable(mCsgInfo, flags); @@ -381,7 +383,7 @@ public final class CellIdentityLte extends CellIdentity { mPci = in.readInt(); mTac = in.readInt(); mEarfcn = in.readInt(); - mBands = in.readArrayList(null); + mBands = in.createIntArray(); mBandwidth = in.readInt(); mAdditionalPlmns = (ArraySet) in.readArraySet(null); mCsgInfo = in.readParcelable(null); diff --git a/telephony/java/android/telephony/CellIdentityNr.java b/telephony/java/android/telephony/CellIdentityNr.java index cba500a00d3a6..69cf7e7d4814c 100644 --- a/telephony/java/android/telephony/CellIdentityNr.java +++ b/telephony/java/android/telephony/CellIdentityNr.java @@ -24,10 +24,9 @@ import android.telephony.AccessNetworkConstants.NgranBands.NgranBand; import android.telephony.gsm.GsmCellLocation; import android.util.ArraySet; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Objects; import java.util.Set; @@ -46,7 +45,7 @@ public final class CellIdentityNr extends CellIdentity { private final int mPci; private final int mTac; private final long mNci; - private final List mBands; + private final int[] mBands; // a list of additional PLMN-IDs reported for this cell private final ArraySet mAdditionalPlmns; @@ -66,7 +65,7 @@ public final class CellIdentityNr extends CellIdentity { * * @hide */ - public CellIdentityNr(int pci, int tac, int nrArfcn, @NgranBand List bands, + public CellIdentityNr(int pci, int tac, int nrArfcn, @NonNull @NgranBand int[] bands, @Nullable String mccStr, @Nullable String mncStr, long nci, @Nullable String alphal, @Nullable String alphas, @NonNull Collection additionalPlmns) { @@ -74,7 +73,8 @@ public final class CellIdentityNr extends CellIdentity { mPci = inRangeOrUnavailable(pci, 0, MAX_PCI); mTac = inRangeOrUnavailable(tac, 0, MAX_TAC); mNrArfcn = inRangeOrUnavailable(nrArfcn, 0, MAX_NRARFCN); - mBands = new ArrayList<>(bands); + // TODO: input validation for bands + mBands = bands; mNci = inRangeOrUnavailable(nci, 0, MAX_NCI); mAdditionalPlmns = new ArraySet<>(additionalPlmns.size()); for (String plmn : additionalPlmns) { @@ -86,15 +86,16 @@ public final class CellIdentityNr extends CellIdentity { /** @hide */ public CellIdentityNr(@NonNull android.hardware.radio.V1_4.CellIdentityNr cid) { - this(cid.pci, cid.tac, cid.nrarfcn, Collections.emptyList(), cid.mcc, cid.mnc, cid.nci, + this(cid.pci, cid.tac, cid.nrarfcn, new int[] {}, cid.mcc, cid.mnc, cid.nci, cid.operatorNames.alphaLong, cid.operatorNames.alphaShort, new ArraySet<>()); } /** @hide */ public CellIdentityNr(@NonNull android.hardware.radio.V1_5.CellIdentityNr cid) { - this(cid.base.pci, cid.base.tac, cid.base.nrarfcn, cid.bands, cid.base.mcc, cid.base.mnc, - cid.base.nci, cid.base.operatorNames.alphaLong, + this(cid.base.pci, cid.base.tac, cid.base.nrarfcn, + cid.bands.stream().mapToInt(Integer::intValue).toArray(), cid.base.mcc, + cid.base.mnc, cid.base.nci, cid.base.operatorNames.alphaLong, cid.base.operatorNames.alphaShort, cid.additionalPlmns); } @@ -119,18 +120,22 @@ public final class CellIdentityNr extends CellIdentity { @Override public int hashCode() { return Objects.hash(super.hashCode(), mPci, mTac, - mNrArfcn, mBands.hashCode(), mNci, mAdditionalPlmns.hashCode()); + mNrArfcn, Arrays.hashCode(mBands), mNci, mAdditionalPlmns.hashCode()); } @Override public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof CellIdentityNr)) { return false; } CellIdentityNr o = (CellIdentityNr) other; return super.equals(o) && mPci == o.mPci && mTac == o.mTac && mNrArfcn == o.mNrArfcn - && mBands.equals(o.mBands) && mNci == o.mNci + && Arrays.equals(mBands, o.mBands) && mNci == o.mNci && mAdditionalPlmns.equals(o.mAdditionalPlmns); } @@ -163,12 +168,12 @@ public final class CellIdentityNr extends CellIdentity { * Reference: TS 38.101-1 table 5.2-1 * Reference: TS 38.101-2 table 5.2-1 * - * @return List of band number or empty list if not available. + * @return Array of band number or empty array if not available. */ @NgranBand @NonNull - public List getBands() { - return Collections.unmodifiableList(mBands); + public int[] getBands() { + return Arrays.copyOf(mBands, mBands.length); } /** @@ -242,7 +247,7 @@ public final class CellIdentityNr extends CellIdentity { dest.writeInt(mPci); dest.writeInt(mTac); dest.writeInt(mNrArfcn); - dest.writeList(mBands); + dest.writeIntArray(mBands); dest.writeLong(mNci); dest.writeArraySet(mAdditionalPlmns); } @@ -253,7 +258,7 @@ public final class CellIdentityNr extends CellIdentity { mPci = in.readInt(); mTac = in.readInt(); mNrArfcn = in.readInt(); - mBands = in.readArrayList(null); + mBands = in.createIntArray(); mNci = in.readLong(); mAdditionalPlmns = (ArraySet) in.readArraySet(null); }