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

Commit 9fc82a2e authored by Jiashen Wang's avatar Jiashen Wang Committed by Gerrit Code Review
Browse files

Merge "Change SubscriptionController to make subscription unique by ICCID"

parents 66aef20f 26067425
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());
    }
}