Merge changes I1731e65e,I2df84427 into main am: f411c02294

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2405722

Change-Id: I1ae06341d1422c65ac846cf1f3abe16c29a0e079
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2023-09-25 23:40:51 +00:00 • committed by Automerger Merge Worker
commit fa03800d1e

View file

@ -35,6 +35,7 @@ import android.os.Process;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.util.SparseIntArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@ -63,7 +64,7 @@ public class CarrierPrivilegeAuthenticator extends BroadcastReceiver {
private final TelephonyManagerShim mTelephonyManagerShim;
private final TelephonyManager mTelephonyManager;
@GuardedBy("mLock")
private int[] mCarrierServiceUid;
private final SparseIntArray mCarrierServiceUid = new SparseIntArray(2 /* initialCapacity */);
@GuardedBy("mLock")
private int mModemCount = 0;
private final Object mLock = new Object();
@ -75,7 +76,7 @@ public class CarrierPrivilegeAuthenticator extends BroadcastReceiver {
public CarrierPrivilegeAuthenticator(@NonNull final Context c,
@NonNull final TelephonyManager t,
@NonNull final TelephonyManagerShimImpl telephonyManagerShim) {
@NonNull final TelephonyManagerShim telephonyManagerShim) {
mContext = c;
mTelephonyManager = t;
mTelephonyManagerShim = telephonyManagerShim;
@ -91,17 +92,7 @@ public class CarrierPrivilegeAuthenticator extends BroadcastReceiver {
public CarrierPrivilegeAuthenticator(@NonNull final Context c,
@NonNull final TelephonyManager t) {
mContext = c;
mTelephonyManager = t;
mTelephonyManagerShim = TelephonyManagerShimImpl.newInstance(mTelephonyManager);
mThread = new HandlerThread(TAG);
mThread.start();
mHandler = new Handler(mThread.getLooper()) {};
synchronized (mLock) {
mModemCount = mTelephonyManager.getActiveModemCount();
registerForCarrierChanges();
updateCarrierServiceUid();
}
this(c, t, TelephonyManagerShimImpl.newInstance(t));
}
/**
@ -233,9 +224,9 @@ public class CarrierPrivilegeAuthenticator extends BroadcastReceiver {
@VisibleForTesting
void updateCarrierServiceUid() {
synchronized (mLock) {
mCarrierServiceUid = new int[mModemCount];
mCarrierServiceUid.clear();
for (int i = 0; i < mModemCount; i++) {
mCarrierServiceUid[i] = getCarrierServicePackageUidForSlot(i);
mCarrierServiceUid.put(i, getCarrierServicePackageUidForSlot(i));
}
}
}
@ -244,11 +235,8 @@ public class CarrierPrivilegeAuthenticator extends BroadcastReceiver {
int getCarrierServiceUidForSubId(int subId) {
final int slotId = getSlotIndex(subId);
synchronized (mLock) {
if (slotId != SubscriptionManager.INVALID_SIM_SLOT_INDEX && slotId < mModemCount) {
return mCarrierServiceUid[slotId];
}
return mCarrierServiceUid.get(slotId, Process.INVALID_UID);
}
return Process.INVALID_UID;
}
@VisibleForTesting