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

Commit 09e6ba44 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed inactive SIM removal not updated issue

When removal an inactive SIM, the settings page
was not updated properly. Also it's still inactive
after re-insertion.

Fixed by properly enabling the UICC application bit
in the subscription when SIM is removal.

Test: Manually deactivate the SIM and remove it.
Test: atest SubscriptionManagerServiceTest
Fix: 275048938
Change-Id: I84864f5b402941755a59dc1065f62aecd7af0056
parent dab3190c
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -1265,15 +1265,25 @@ public class SubscriptionManagerService extends ISub.Stub {
        }

        if (simState == TelephonyManager.SIM_STATE_ABSENT) {
            if (mSlotIndexToSubId.containsKey(phoneId)) {
                int subId = mSlotIndexToSubId.get(phoneId);
                // Re-enable the SIM when it's removed, so it will be in enabled state when it gets
            // Re-enable the pSIM when it's removed, so it will be in enabled state when it gets
            // re-inserted again. (pre-U behavior)
            List<String> iccIds = getIccIdsOfInsertedPhysicalSims();
            mSubscriptionDatabaseManager.getAllSubscriptions().stream()
                    // All the removed pSIMs (Note this could include some erased eSIM that has
                    // embedded bit removed).
                    .filter(subInfo -> !iccIds.contains(subInfo.getIccId())
                            && !subInfo.isEmbedded())
                    .forEach(subInfo -> {
                        int subId = subInfo.getSubscriptionId();
                        log("updateSubscription: Re-enable Uicc application on sub " + subId);
                        mSubscriptionDatabaseManager.setUiccApplicationsEnabled(subId, true);
                // When sim is absent, set the port index to invalid port index. (pre-U behavior)
                        // When sim is absent, set the port index to invalid port index.
                        // (pre-U behavior)
                        mSubscriptionDatabaseManager.setPortIndex(subId,
                                TelephonyManager.INVALID_PORT_INDEX);
                    });

            if (mSlotIndexToSubId.containsKey(phoneId)) {
                markSubscriptionsInactive(phoneId);
            }
        } else if (simState == TelephonyManager.SIM_STATE_NOT_READY) {
+36 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ import com.android.internal.telephony.euicc.EuiccController;
import com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.SubscriptionProvider;
import com.android.internal.telephony.subscription.SubscriptionManagerService.SubscriptionManagerServiceCallback;
import com.android.internal.telephony.subscription.SubscriptionManagerService.SubscriptionMap;
import com.android.internal.telephony.uicc.IccCardStatus;
import com.android.internal.telephony.uicc.UiccSlot;

import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;
@@ -2195,4 +2196,39 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {

        assertThat(mSubscriptionManagerServiceUT.getActiveSubIdList(false)).isEmpty();
    }

    @Test
    public void testInactiveSimRemoval() {
        insertSubscription(FAKE_SUBSCRIPTION_INFO2);

        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
        doReturn(FAKE_ICCID2).when(mUiccSlot).getIccId(0);
        doReturn(IccCardStatus.CardState.CARDSTATE_PRESENT).when(mUiccSlot).getCardState();

        mSubscriptionManagerServiceUT.setUiccApplicationsEnabled(false, 1);
        mSubscriptionManagerServiceUT.updateSimState(
                1, TelephonyManager.SIM_STATE_NOT_READY, null, null);
        processAllMessages();

        assertThat(mSubscriptionManagerServiceUT.getActiveSubIdList(false)).isEmpty();
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(1)
                .areUiccApplicationsEnabled()).isFalse();
        assertThat(mSubscriptionManagerServiceUT.getAvailableSubscriptionInfoList(
                CALLING_PACKAGE, CALLING_FEATURE)).hasSize(1);

        // Now remove the SIM
        doReturn(null).when(mUiccSlot).getIccId(0);
        doReturn(IccCardStatus.CardState.CARDSTATE_ABSENT).when(mUiccSlot).getCardState();
        mSubscriptionManagerServiceUT.updateSimState(
                1, TelephonyManager.SIM_STATE_ABSENT, null, null);
        processAllMessages();

        assertThat(mSubscriptionManagerServiceUT.getActiveSubIdList(false)).isEmpty();
        // UICC should be re-enabled again for next re-insertion.
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(1)
                .areUiccApplicationsEnabled()).isTrue();
        assertThat(mSubscriptionManagerServiceUT.getAvailableSubscriptionInfoList(
                CALLING_PACKAGE, CALLING_FEATURE)).isEmpty();
    }
}