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

Commit 2444b3c6 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed remote SIM removal not working

When remote SIM is removed, it should be also removed
from the slot/sub mapping table.

Fix: 271902906
Test: atest SubscriptionManagerServiceTest
Test: Basic phone functionality tests
Change-Id: I547024e1390fbc868bc7460bef1f19025a4d1cc5
parent 0d9e44be
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ public class SubscriptionManagerService extends ISub.Stub {

    /** The slot index subscription id map. Key is the slot index, and the value is sub id. */
    @NonNull
    private final WatchedMap<Integer, Integer> mSlotIndexToSubId = new WatchedMap<>();
    private final SubscriptionMap<Integer, Integer> mSlotIndexToSubId = new SubscriptionMap<>();

    /** Subscription manager service callbacks. */
    @NonNull
@@ -264,9 +264,10 @@ public class SubscriptionManagerService extends ISub.Stub {
    private final int[] mSimState;

    /**
     * Watched map that automatically invalidate cache in {@link SubscriptionManager}.
     * Slot index/subscription map that automatically invalidate cache in
     * {@link SubscriptionManager}.
     */
    private static class WatchedMap<K, V> extends ConcurrentHashMap<K, V> {
    private static class SubscriptionMap<K, V> extends ConcurrentHashMap<K, V> {
        @Override
        public void clear() {
            super.clear();
@@ -1946,10 +1947,11 @@ public class SubscriptionManagerService extends ISub.Stub {
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public int addSubInfo(@NonNull String iccId, @NonNull String displayName, int slotIndex,
            @SubscriptionType int subscriptionType) {
        log("addSubInfo: iccId=" + SubscriptionInfo.givePrintableIccid(iccId) + ", slotIndex="
                + slotIndex + ", displayName=" + displayName + ", type="
                + SubscriptionManager.subscriptionTypeToString(subscriptionType));
        enforcePermissions("addSubInfo", Manifest.permission.MODIFY_PHONE_STATE);
        logl("addSubInfo: iccId=" + SubscriptionInfo.givePrintableIccid(iccId) + ", slotIndex="
                + slotIndex + ", displayName=" + displayName + ", type="
                + SubscriptionManager.subscriptionTypeToString(subscriptionType) + ", "
                + getCallingPackage());

        // Now that all security checks passes, perform the operation as ourselves.
        final long identity = Binder.clearCallingIdentity();
@@ -2004,6 +2006,9 @@ public class SubscriptionManagerService extends ISub.Stub {
    public int removeSubInfo(@NonNull String uniqueId, int subscriptionType) {
        enforcePermissions("removeSubInfo", Manifest.permission.MODIFY_PHONE_STATE);

        logl("removeSubInfo: uniqueId=" + SubscriptionInfo.givePrintableIccid(uniqueId) + ", "
                + SubscriptionManager.subscriptionTypeToString(subscriptionType) + ", "
                + getCallingPackage());
        final long identity = Binder.clearCallingIdentity();
        try {
            SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager
@@ -2016,6 +2021,7 @@ public class SubscriptionManagerService extends ISub.Stub {
                loge("The subscription type does not match.");
                return -1;
            }
            mSlotIndexToSubId.remove(subInfo.getSimSlotIndex());
            mSubscriptionDatabaseManager.removeSubscriptionInfo(subInfo.getSubscriptionId());
            return 0;
        } finally {
+3 −0
Original line number Diff line number Diff line
@@ -114,6 +114,9 @@ public class SubscriptionDatabaseManagerTest extends TelephonyTest {
    static final int FAKE_USER_ID1 = 10;
    static final int FAKE_USER_ID2 = 11;

    static final String FAKE_MAC_ADDRESS1 = "DC:E5:5B:38:7D:40";
    static final String FAKE_MAC_ADDRESS2 = "DC:B5:4F:47:F3:4C";

    static final SubscriptionInfoInternal FAKE_SUBSCRIPTION_INFO1 =
            new SubscriptionInfoInternal.Builder()
                    .setId(1)
+45 −3
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import static com.android.internal.telephony.subscription.SubscriptionDatabaseMa
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID1;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID2;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_IMSI1;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_MAC_ADDRESS1;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_MAC_ADDRESS2;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_MCC1;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_MCC2;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_MNC1;
@@ -251,8 +253,9 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
            // Insertion is sync, but the onSubscriptionChanged callback is handled by the handler.
            processAllMessages();

            Class<?> WatchedMapClass = Class.forName("com.android.internal.telephony.subscription"
                    + ".SubscriptionManagerService$WatchedMap");
            Class<?> SubscriptionMapClass = Class.forName(
                    "com.android.internal.telephony.subscription"
                            + ".SubscriptionManagerService$SubscriptionMap");
            Field field = SubscriptionManagerService.class.getDeclaredField("mSlotIndexToSubId");
            field.setAccessible(true);
            Object map = field.get(mSubscriptionManagerServiceUT);
@@ -262,7 +265,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {

            if (subInfo.getSimSlotIndex() >= 0) {
                // Change the slot -> subId mapping
                Method method = WatchedMapClass.getDeclaredMethod("put", cArgs);
                Method method = SubscriptionMapClass.getDeclaredMethod("put", cArgs);
                method.setAccessible(true);
                method.invoke(map, subInfo.getSimSlotIndex(), subId);
            }
@@ -1745,6 +1748,8 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
        assertThat(mSubscriptionManagerServiceUT.getAllSubInfoList(
                CALLING_PACKAGE, CALLING_FEATURE).isEmpty()).isTrue();
        assertThat(mSubscriptionManagerServiceUT.getActiveSubscriptionInfoList(
                CALLING_PACKAGE, CALLING_FEATURE)).isEmpty();
    }

    @Test
@@ -2046,4 +2051,41 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        assertThat(subInfo.isActive()).isFalse();
        assertThat(subInfo.areUiccApplicationsEnabled()).isFalse();
    }

    @Test
    public void testRemoteSim() {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);

        mSubscriptionManagerServiceUT.addSubInfo(FAKE_MAC_ADDRESS1, FAKE_CARRIER_NAME1,
                0, SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);
        processAllMessages();

        verify(mMockedSubscriptionManagerServiceCallback).onSubscriptionChanged(eq(1));

        SubscriptionInfoInternal subInfo = mSubscriptionManagerServiceUT
                .getSubscriptionInfoInternal(1);
        assertThat(subInfo.getIccId()).isEqualTo(FAKE_MAC_ADDRESS1);
        assertThat(subInfo.getDisplayName()).isEqualTo(FAKE_CARRIER_NAME1);
        assertThat(subInfo.getSimSlotIndex()).isEqualTo(0);
        assertThat(subInfo.getSubscriptionType()).isEqualTo(
                SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);

        assertThat(mSubscriptionManagerServiceUT.removeSubInfo(FAKE_MAC_ADDRESS1,
                SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM)).isEqualTo(0);
        assertThat(mSubscriptionManagerServiceUT.getAllSubInfoList(
                CALLING_PACKAGE, CALLING_FEATURE)).isEmpty();
        assertThat(mSubscriptionManagerServiceUT.getActiveSubIdList(false)).isEmpty();
        assertThat(mSubscriptionManagerServiceUT.getActiveSubscriptionInfoList(
                CALLING_PACKAGE, CALLING_FEATURE)).isEmpty();

        setIdentifierAccess(true);
        mSubscriptionManagerServiceUT.addSubInfo(FAKE_MAC_ADDRESS2, FAKE_CARRIER_NAME2,
                0, SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);
        assertThat(mSubscriptionManagerServiceUT.getActiveSubIdList(false)).isNotEmpty();
        assertThat(mSubscriptionManagerServiceUT.getActiveSubscriptionInfoList(
                CALLING_PACKAGE, CALLING_FEATURE)).isNotEmpty();
        assertThat(mSubscriptionManagerServiceUT.getActiveSubscriptionInfoList(
                CALLING_PACKAGE, CALLING_FEATURE).get(0).getIccId()).isEqualTo(FAKE_MAC_ADDRESS2);
    }
}