Skip to content
Snippets Groups Projects
Commit f411c022 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I1731e65e,I2df84427 into main

* changes:
  Factorize CarrierPrivilegeAuthenticator constructors
  Change mCarrierServiceUid from int[] to SparseIntArray
parents 8a88d851 21869454
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment