Loading src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java +27 −16 Original line number Diff line number Diff line Loading @@ -523,6 +523,13 @@ public class SubscriptionManagerService extends ISub.Stub { } }); // Broadcast sub Id on service initialized. broadcastSubId(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED, getDefaultDataSubId()); broadcastSubId(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED, getDefaultVoiceSubId()); broadcastSubId(SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED, getDefaultSmsSubId()); updateDefaultSubId(); TelephonyServiceManager.ServiceRegisterer subscriptionServiceRegisterer = Loading Loading @@ -2714,7 +2721,7 @@ public class SubscriptionManagerService extends ISub.Stub { Intent intent = new Intent(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); mContext.sendBroadcastAsUser(intent, UserHandle.ALL); } } Loading Loading @@ -2784,11 +2791,8 @@ public class SubscriptionManagerService extends ISub.Stub { if (mDefaultDataSubId.set(subId)) { MultiSimSettingController.getInstance().notifyDefaultDataSubChanged(); Intent intent = new Intent( TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putSubscriptionIdExtra(intent, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); broadcastSubId(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED, subId); updateDefaultSubId(); } Loading Loading @@ -2824,11 +2828,8 @@ public class SubscriptionManagerService extends ISub.Stub { final long token = Binder.clearCallingIdentity(); try { if (mDefaultVoiceSubId.set(subId)) { Intent intent = new Intent( TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putSubscriptionIdExtra(intent, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); broadcastSubId(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED, subId); PhoneAccountHandle newHandle = subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID ? null : mTelephonyManager.getPhoneAccountHandleForSubscriptionId(subId); Loading Loading @@ -2873,11 +2874,8 @@ public class SubscriptionManagerService extends ISub.Stub { final long token = Binder.clearCallingIdentity(); try { if (mDefaultSmsSubId.set(subId)) { Intent intent = new Intent( SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putSubscriptionIdExtra(intent, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); broadcastSubId(SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED, subId); } } finally { Loading @@ -2885,6 +2883,19 @@ public class SubscriptionManagerService extends ISub.Stub { } } /** * Broadcast a sub Id with the given action. * @param action The intent action. * @param newSubId The sub Id to broadcast. */ private void broadcastSubId(@NonNull String action, int newSubId) { Intent intent = new Intent(action); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putSubscriptionIdExtra(intent, newSubId); mContext.sendBroadcastAsUser(intent, UserHandle.ALL); log("broadcastSubId action: " + action + " subId= " + newSubId); } /** * Get the active subscription id list. * Loading tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java +18 −3 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; Loading Loading @@ -297,6 +298,17 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { return SubscriptionManager.INVALID_SUBSCRIPTION_ID; } @Test public void testBroadcastOnInitialization() { ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(3)).sendBroadcastAsUser( captorIntent.capture(), eq(UserHandle.ALL)); assertThat(captorIntent.getAllValues().stream().map(Intent::getAction).toList()) .containsExactly(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED, TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED, SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED); } @Test public void testAddSubInfo() { mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE); Loading Loading @@ -568,6 +580,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { @Test public void testSetDefaultVoiceSubId() throws Exception { clearInvocations(mContext); insertSubscription(FAKE_SUBSCRIPTION_INFO1); insertSubscription(FAKE_SUBSCRIPTION_INFO2); Loading @@ -585,7 +598,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { assertThat(Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION)).isEqualTo(1); ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(2)).sendStickyBroadcastAsUser( verify(mContext, times(2)).sendBroadcastAsUser( captorIntent.capture(), eq(UserHandle.ALL)); Intent intent = captorIntent.getAllValues().get(0); Loading @@ -609,6 +622,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { @Test public void testSetDefaultDataSubId() throws Exception { clearInvocations(mContext); doReturn(false).when(mTelephonyManager).isVoiceCapable(); insertSubscription(FAKE_SUBSCRIPTION_INFO1); insertSubscription(FAKE_SUBSCRIPTION_INFO2); Loading @@ -627,7 +641,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { assertThat(Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION)).isEqualTo(1); ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(2)).sendStickyBroadcastAsUser( verify(mContext, times(2)).sendBroadcastAsUser( captorIntent.capture(), eq(UserHandle.ALL)); Intent intent = captorIntent.getAllValues().get(0); Loading @@ -651,6 +665,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { @Test public void testSetDefaultSmsSubId() throws Exception { clearInvocations(mContext); insertSubscription(FAKE_SUBSCRIPTION_INFO1); insertSubscription(FAKE_SUBSCRIPTION_INFO2); Loading @@ -667,7 +682,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { assertThat(Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION)).isEqualTo(1); ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class); verify(mContext).sendStickyBroadcastAsUser(captorIntent.capture(), eq(UserHandle.ALL)); verify(mContext).sendBroadcastAsUser(captorIntent.capture(), eq(UserHandle.ALL)); Intent intent = captorIntent.getValue(); assertThat(intent.getAction()).isEqualTo( Loading Loading
src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java +27 −16 Original line number Diff line number Diff line Loading @@ -523,6 +523,13 @@ public class SubscriptionManagerService extends ISub.Stub { } }); // Broadcast sub Id on service initialized. broadcastSubId(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED, getDefaultDataSubId()); broadcastSubId(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED, getDefaultVoiceSubId()); broadcastSubId(SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED, getDefaultSmsSubId()); updateDefaultSubId(); TelephonyServiceManager.ServiceRegisterer subscriptionServiceRegisterer = Loading Loading @@ -2714,7 +2721,7 @@ public class SubscriptionManagerService extends ISub.Stub { Intent intent = new Intent(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); mContext.sendBroadcastAsUser(intent, UserHandle.ALL); } } Loading Loading @@ -2784,11 +2791,8 @@ public class SubscriptionManagerService extends ISub.Stub { if (mDefaultDataSubId.set(subId)) { MultiSimSettingController.getInstance().notifyDefaultDataSubChanged(); Intent intent = new Intent( TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putSubscriptionIdExtra(intent, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); broadcastSubId(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED, subId); updateDefaultSubId(); } Loading Loading @@ -2824,11 +2828,8 @@ public class SubscriptionManagerService extends ISub.Stub { final long token = Binder.clearCallingIdentity(); try { if (mDefaultVoiceSubId.set(subId)) { Intent intent = new Intent( TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putSubscriptionIdExtra(intent, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); broadcastSubId(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED, subId); PhoneAccountHandle newHandle = subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID ? null : mTelephonyManager.getPhoneAccountHandleForSubscriptionId(subId); Loading Loading @@ -2873,11 +2874,8 @@ public class SubscriptionManagerService extends ISub.Stub { final long token = Binder.clearCallingIdentity(); try { if (mDefaultSmsSubId.set(subId)) { Intent intent = new Intent( SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putSubscriptionIdExtra(intent, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); broadcastSubId(SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED, subId); } } finally { Loading @@ -2885,6 +2883,19 @@ public class SubscriptionManagerService extends ISub.Stub { } } /** * Broadcast a sub Id with the given action. * @param action The intent action. * @param newSubId The sub Id to broadcast. */ private void broadcastSubId(@NonNull String action, int newSubId) { Intent intent = new Intent(action); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); SubscriptionManager.putSubscriptionIdExtra(intent, newSubId); mContext.sendBroadcastAsUser(intent, UserHandle.ALL); log("broadcastSubId action: " + action + " subId= " + newSubId); } /** * Get the active subscription id list. * Loading
tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java +18 −3 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; Loading Loading @@ -297,6 +298,17 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { return SubscriptionManager.INVALID_SUBSCRIPTION_ID; } @Test public void testBroadcastOnInitialization() { ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(3)).sendBroadcastAsUser( captorIntent.capture(), eq(UserHandle.ALL)); assertThat(captorIntent.getAllValues().stream().map(Intent::getAction).toList()) .containsExactly(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED, TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED, SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED); } @Test public void testAddSubInfo() { mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE); Loading Loading @@ -568,6 +580,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { @Test public void testSetDefaultVoiceSubId() throws Exception { clearInvocations(mContext); insertSubscription(FAKE_SUBSCRIPTION_INFO1); insertSubscription(FAKE_SUBSCRIPTION_INFO2); Loading @@ -585,7 +598,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { assertThat(Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION)).isEqualTo(1); ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(2)).sendStickyBroadcastAsUser( verify(mContext, times(2)).sendBroadcastAsUser( captorIntent.capture(), eq(UserHandle.ALL)); Intent intent = captorIntent.getAllValues().get(0); Loading @@ -609,6 +622,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { @Test public void testSetDefaultDataSubId() throws Exception { clearInvocations(mContext); doReturn(false).when(mTelephonyManager).isVoiceCapable(); insertSubscription(FAKE_SUBSCRIPTION_INFO1); insertSubscription(FAKE_SUBSCRIPTION_INFO2); Loading @@ -627,7 +641,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { assertThat(Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION)).isEqualTo(1); ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(2)).sendStickyBroadcastAsUser( verify(mContext, times(2)).sendBroadcastAsUser( captorIntent.capture(), eq(UserHandle.ALL)); Intent intent = captorIntent.getAllValues().get(0); Loading @@ -651,6 +665,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { @Test public void testSetDefaultSmsSubId() throws Exception { clearInvocations(mContext); insertSubscription(FAKE_SUBSCRIPTION_INFO1); insertSubscription(FAKE_SUBSCRIPTION_INFO2); Loading @@ -667,7 +682,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { assertThat(Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION)).isEqualTo(1); ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class); verify(mContext).sendStickyBroadcastAsUser(captorIntent.capture(), eq(UserHandle.ALL)); verify(mContext).sendBroadcastAsUser(captorIntent.capture(), eq(UserHandle.ALL)); Intent intent = captorIntent.getValue(); assertThat(intent.getAction()).isEqualTo( Loading