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

Commit 26067425 authored by Jiashen Wang's avatar Jiashen Wang
Browse files

Change SubscriptionController to make subscription unique by ICCID

We found that as a consequence of b/170682350, the siminfo table
maintained by SubscriptionController has actually somehow gotten multiple
rows with the same ICCID inserted. Thus, we exam the ICCID before
inserting a subscription info record.

Test: atest SubscriptionControllerTest#testInsertEmptySubInfoRecord_returnsNull_ifRecordExists
Bug: 170994576
Change-Id: I0e486e08735707a23c2ece66b2c6b6db356b6a55
Merged-In: I0e486e08735707a23c2ece66b2c6b6db356b6a55
parent 8d7db4a0
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -1627,12 +1627,20 @@ public class SubscriptionController extends ISub.Stub {
     * Insert an empty SubInfo record into the database.
     *
     * <p>NOTE: This is not accessible to external processes, so it does not need a permission
     * check. It is only intended for use by {@link SubscriptionInfoUpdater}.
     * check. It is only intended for use by {@link SubscriptionInfoUpdater}. If there is a
     * subscription record exist with the same ICCID, no new empty record will be created.
     *
     * <p>Precondition: No record exists with this iccId.
     * @return the URL of the newly created row. Return <code>null</code> if no new empty record is
     * created.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    @Nullable
    public Uri insertEmptySubInfoRecord(String iccId, int slotIndex) {
        if (getSubInfoForIccId(iccId) != null) {
            loge("insertEmptySubInfoRecord: Found existing record by ICCID. Do not create a "
                    + "new empty entry.");
            return null;
        }
        return insertEmptySubInfoRecord(iccId, null, slotIndex,
                SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);
    }
+18 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
@@ -1914,4 +1915,21 @@ public class SubscriptionControllerTest extends TelephonyTest {
        assertFalse(mSubscriptionControllerUT.getActiveSubscriptionInfo(
                1, mContext.getOpPackageName(), null).areUiccApplicationsEnabled());
    }

    @Test
    @SmallTest
    public void testInsertEmptySubInfoRecord_returnsNull_ifRecordExists() {
        final String mockedIccid = "123456789";
        final int mockedSlotIndex = 1;

        assertNotNull(mSubscriptionControllerUT.insertEmptySubInfoRecord(
                mockedIccid, mockedSlotIndex));
        // Insert second time with the same iccid should result in no-op and return null.
        assertNull(mSubscriptionControllerUT.insertEmptySubInfoRecord(
                mockedIccid, mockedSlotIndex));
        assertEquals(
                1,
                mSubscriptionControllerUT
                        .getAllSubInfoList(mCallingPackage, mCallingFeature).size());
    }
}