Loading src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java +12 −6 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -1922,10 +1923,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(); Loading Loading @@ -1980,6 +1982,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 Loading @@ -1992,6 +1997,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 { Loading tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionDatabaseManagerTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -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) Loading tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java +45 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -250,8 +252,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); Loading @@ -261,7 +264,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); } Loading Loading @@ -1754,6 +1757,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 Loading Loading @@ -2055,4 +2060,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); } } Loading
src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java +12 −6 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -1922,10 +1923,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(); Loading Loading @@ -1980,6 +1982,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 Loading @@ -1992,6 +1997,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 { Loading
tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionDatabaseManagerTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -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) Loading
tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java +45 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -250,8 +252,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); Loading @@ -261,7 +264,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); } Loading Loading @@ -1754,6 +1757,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 Loading Loading @@ -2055,4 +2060,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); } }