Loading src/java/com/android/internal/telephony/SubscriptionController.java +10 −2 Original line number Diff line number Diff line Loading @@ -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); } Loading tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); } } Loading
src/java/com/android/internal/telephony/SubscriptionController.java +10 −2 Original line number Diff line number Diff line Loading @@ -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); } Loading
tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); } }