Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 31fb2c6a authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Don't store sPhones in SubscriptionInfoUpdater.

Replace sPhones[phoneId] with PhoneFactory.getPhone(phoneId). Because
the array / list may change size upon ss <-> ds switch.

Bug: 142514392
Test: manual and unittest
Change-Id: I750aa18be1ebbc5675278069b2bc1a65e0efdc07
parent 0dbd403c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ public class PhoneFactory {

                Rlog.i(LOG_TAG, "Creating SubInfoRecordUpdater ");
                sSubInfoRecordUpdater = new SubscriptionInfoUpdater(
                        BackgroundThread.get().getLooper(), context, sPhones, sCommandsInterfaces);
                        BackgroundThread.get().getLooper(), context, sCommandsInterfaces);
                sc.updatePhonesAvailability(sPhones);

                // Only bring up IMS if the device supports having an IMS stack.
+16 −23
Original line number Diff line number Diff line
@@ -103,8 +103,6 @@ public class SubscriptionInfoUpdater extends Handler {
    // Key used to read/write the current IMSI. Updated on SIM_STATE_CHANGED - LOADED.
    public static final String CURR_SUBID = "curr_subid";

    @UnsupportedAppUsage
    private static Phone[] sPhones;
    @UnsupportedAppUsage
    private static Context sContext = null;
    @UnsupportedAppUsage
@@ -140,22 +138,17 @@ public class SubscriptionInfoUpdater extends Handler {

    // TODO: The SubscriptionController instance should be passed in here from PhoneFactory
    // rather than invoking the static getter all over the place.
    public SubscriptionInfoUpdater(
            Looper looper, Context context, Phone[] phone, CommandsInterface[] ci) {
        this(looper, context, phone, ci,
                IPackageManager.Stub.asInterface(ServiceManager.getService("package")),
                AppGlobals.getPermissionManager());
    public SubscriptionInfoUpdater(Looper looper, Context context, CommandsInterface[] ci) {
        this(looper, context, ci, IPackageManager.Stub.asInterface(
                ServiceManager.getService("package")), AppGlobals.getPermissionManager());
    }

    @VisibleForTesting public SubscriptionInfoUpdater(
            Looper looper, Context context, Phone[] phone,
            CommandsInterface[] ci, IPackageManager packageMgr,
            IPermissionManager permissionMgr) {
    @VisibleForTesting public SubscriptionInfoUpdater(Looper looper, Context context,
            CommandsInterface[] ci, IPackageManager packageMgr, IPermissionManager permissionMgr) {
        logd("Constructor invoked");
        mBackgroundHandler = new Handler(looper);

        sContext = context;
        sPhones = phone;
        mSubscriptionManager = SubscriptionManager.from(sContext);
        mEuiccManager = (EuiccManager) sContext.getSystemService(Context.EUICC_SERVICE);
        mPackageManager = packageMgr;
@@ -260,7 +253,7 @@ public class SubscriptionInfoUpdater extends Handler {
                if (ar.exception == null && ar.result != null) {
                    int[] modes = (int[])ar.result;
                    if (modes[0] == 1) {  // Manual mode.
                        sPhones[slotId].setNetworkSelectionModeAutomatic(null);
                        PhoneFactory.getPhone(slotId).setNetworkSelectionModeAutomatic(null);
                    }
                } else {
                    logd("EVENT_GET_NETWORK_SELECTION_MODE_DONE: error getting network mode.");
@@ -371,7 +364,7 @@ public class SubscriptionInfoUpdater extends Handler {

        String iccId = sIccId[slotId];
        if (iccId == null) {
            IccCard iccCard = sPhones[slotId].getIccCard();
            IccCard iccCard = PhoneFactory.getPhone(slotId).getIccCard();
            if (iccCard == null) {
                logd("handleSimLocked: IccCard null");
                return;
@@ -418,7 +411,7 @@ public class SubscriptionInfoUpdater extends Handler {
    private void handleSimNotReady(int slotId) {
        logd("handleSimNotReady: slotId: " + slotId);

        IccCard iccCard = sPhones[slotId].getIccCard();
        IccCard iccCard = PhoneFactory.getPhone(slotId).getIccCard();
        if (iccCard.isEmptyProfile()) {
            // ICC_NOT_READY is a terminal state for an eSIM on the boot profile. At this
            // phase, the subscription list is accessible. Treating NOT_READY
@@ -440,7 +433,7 @@ public class SubscriptionInfoUpdater extends Handler {
        // removed or a refresh RESET that the IccRecords could be null. The right behavior is to
        // not broadcast the SIM loaded.
        int loadedSlotId = slotId;
        IccCard iccCard = sPhones[slotId].getIccCard();
        IccCard iccCard = PhoneFactory.getPhone(slotId).getIccCard();
        if (iccCard == null) {  // Possibly a race condition.
            logd("handleSimLoaded: IccCard null");
            return;
@@ -510,7 +503,7 @@ public class SubscriptionInfoUpdater extends Handler {

                if (storedSubId != subId) {
                    int networkType = Settings.Global.getInt(
                            sPhones[slotId].getContext().getContentResolver(),
                            PhoneFactory.getPhone(slotId).getContext().getContentResolver(),
                            Settings.Global.PREFERRED_NETWORK_MODE + subId,
                            -1 /* invalid network mode */);

@@ -525,16 +518,16 @@ public class SubscriptionInfoUpdater extends Handler {
                                    + "Settings.Global.PREFERRED_NETWORK_MODE");
                        }
                        Settings.Global.putInt(
                                sPhones[slotId].getContext().getContentResolver(),
                                PhoneFactory.getPhone(slotId).getContext().getContentResolver(),
                                Global.PREFERRED_NETWORK_MODE + subId,
                                networkType);
                    }

                    // Set the modem network mode
                    sPhones[slotId].setPreferredNetworkType(networkType, null);
                    PhoneFactory.getPhone(slotId).setPreferredNetworkType(networkType, null);

                    // Only support automatic selection mode on SIM change.
                    sPhones[slotId].getNetworkSelectionMode(
                    PhoneFactory.getPhone(slotId).getNetworkSelectionMode(
                            obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE,
                                    new Integer(slotId)));

@@ -574,8 +567,8 @@ public class SubscriptionInfoUpdater extends Handler {
    }

    private void updateSubscriptionCarrierId(int slotId, String simState) {
        if (sPhones != null && sPhones[slotId] != null) {
            sPhones[slotId].resolveSubscriptionCarrierId(simState);
        if (PhoneFactory.getPhone(slotId) != null) {
            PhoneFactory.getPhone(slotId).resolveSubscriptionCarrierId(simState);
        }
    }

@@ -1104,7 +1097,7 @@ public class SubscriptionInfoUpdater extends Handler {
        boolean isUnknownToNotReady =
                (sSimApplicationState[phoneId] == TelephonyManager.SIM_STATE_UNKNOWN
                        && state == TelephonyManager.SIM_STATE_NOT_READY);
        IccCard iccCard = sPhones[phoneId].getIccCard();
        IccCard iccCard = PhoneFactory.getPhone(phoneId).getIccCard();
        boolean emptyProfile = iccCard != null && iccCard.isEmptyProfile();
        if (state != sSimApplicationState[phoneId] && (!isUnknownToNotReady || emptyProfile)) {
            sSimApplicationState[phoneId] = state;
+3 −5
Original line number Diff line number Diff line
@@ -158,9 +158,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
                .getActiveSubIdList(/*visibleOnly*/false);
        mIccRecord = mUiccProfile.getIccRecords();

        mUpdater = new SubscriptionInfoUpdater(Looper.myLooper(), mContext, new Phone[]{mPhone},
            new CommandsInterface[]{mSimulatedCommands}, mPackageManager,
            mPermissionManager);
        mUpdater = new SubscriptionInfoUpdater(Looper.myLooper(), mContext,
            new CommandsInterface[]{mSimulatedCommands}, mPackageManager, mPermissionManager);
        processAllMessages();

        assertFalse(mUpdater.isSubInfoInitialized());
@@ -390,11 +389,10 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
    @SmallTest
    public void testDualSimLoaded() throws Exception {
        // Mock there is two sim cards
        replaceInstance(PhoneFactory.class, "sPhones", null, new Phone[]{mPhone, mPhone});
        replaceInstance(SubscriptionInfoUpdater.class, "sIccId", null,
                new String[]{null, null});
        replaceInstance(SubscriptionInfoUpdater.class, "PROJECT_SIM_NUM", null, 2);
        replaceInstance(SubscriptionInfoUpdater.class, "sPhones", null,
                new Phone[]{mPhone, mPhone});
        replaceInstance(SubscriptionInfoUpdater.class, "sSimCardState", null,
                new int[]{0, 0});
        replaceInstance(SubscriptionInfoUpdater.class, "sSimApplicationState", null,