Loading src/java/com/android/internal/telephony/MultiSimSettingController.java +6 −31 Original line number Diff line number Diff line Loading @@ -33,10 +33,8 @@ import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.AsyncResult; import android.os.Handler; import android.os.Looper; Loading Loading @@ -85,7 +83,6 @@ public class MultiSimSettingController extends Handler { private static final int EVENT_SUBSCRIPTION_INFO_CHANGED = 4; private static final int EVENT_SUBSCRIPTION_GROUP_CHANGED = 5; private static final int EVENT_DEFAULT_DATA_SUBSCRIPTION_CHANGED = 6; private static final int EVENT_CARRIER_CONFIG_CHANGED = 7; private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 8; @VisibleForTesting public static final int EVENT_RADIO_STATE_CHANGED = 9; Loading Loading @@ -162,19 +159,6 @@ public class MultiSimSettingController extends Handler { private static final String SETTING_USER_PREF_DATA_SUB = "user_preferred_data_sub"; private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(intent.getAction())) { int phoneId = intent.getIntExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, SubscriptionManager.INVALID_SIM_SLOT_INDEX); int subId = intent.getIntExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, SubscriptionManager.INVALID_SUBSCRIPTION_ID); notifyCarrierConfigChanged(phoneId, subId); } } }; private static class DataSettingsControllerCallback extends DataSettingsManagerCallback { private final Phone mPhone; Loading Loading @@ -250,8 +234,12 @@ public class MultiSimSettingController extends Handler { mIsAskEverytimeSupportedForSms = mContext.getResources() .getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support); context.registerReceiver(mIntentReceiver, new IntentFilter( CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); CarrierConfigManager ccm = mContext.getSystemService(CarrierConfigManager.class); // Listener callback is executed on handler thread to directly handle config change ccm.registerCarrierConfigChangeListener(this::post, (slotIndex, subId, carrierId, specificCarrierId) -> onCarrierConfigChanged(slotIndex, subId)); } /** Loading Loading @@ -330,11 +318,6 @@ public class MultiSimSettingController extends Handler { case EVENT_DEFAULT_DATA_SUBSCRIPTION_CHANGED: onDefaultDataSettingChanged(); break; case EVENT_CARRIER_CONFIG_CHANGED: int phoneId = msg.arg1; int subId = msg.arg2; onCarrierConfigChanged(phoneId, subId); break; case EVENT_MULTI_SIM_CONFIG_CHANGED: int activeModems = (int) ((AsyncResult) msg.obj).result; onMultiSimConfigChanged(activeModems); Loading Loading @@ -444,14 +427,6 @@ public class MultiSimSettingController extends Handler { reEvaluateAll(); } /** * Called when carrier config changes on any phone. */ @VisibleForTesting public void notifyCarrierConfigChanged(int phoneId, int subId) { obtainMessage(EVENT_CARRIER_CONFIG_CHANGED, phoneId, subId).sendToTarget(); } private void onCarrierConfigChanged(int phoneId, int subId) { log("onCarrierConfigChanged phoneId " + phoneId + " subId " + subId); if (!SubscriptionManager.isValidPhoneId(phoneId)) { Loading tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java +57 −45 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; Loading Loading @@ -82,6 +83,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { private MultiSimSettingController mMultiSimSettingControllerUT; private Phone[] mPhones; private ParcelUuid mGroupUuid1 = new ParcelUuid(UUID.randomUUID()); private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener; // Mocked classes private Phone mPhoneMock1; Loading Loading @@ -134,6 +136,10 @@ public class MultiSimSettingControllerTest extends TelephonyTest { mSubInfo[subId] = new SubscriptionInfoInternal.Builder(mSubInfo[subId]) .setSimSlotIndex(simSlotIndex).build(); } private void sendCarrierConfigChanged(int phoneId, int subId) { mCarrierConfigChangeListener.onCarrierConfigChanged(phoneId, subId, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); } @Before public void setUp() throws Exception { Loading Loading @@ -237,9 +243,17 @@ public class MultiSimSettingControllerTest extends TelephonyTest { }).when(mPhoneMock2).getSubId(); replaceInstance(PhoneFactory.class, "sPhones", null, mPhones); mMultiSimSettingControllerUT = new MultiSimSettingController( mContext, mSubscriptionController); // Capture listener to emulate the carrier config change notification used later ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class); mMultiSimSettingControllerUT = new MultiSimSettingController(mContext, mSubscriptionController); processAllMessages(); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); assertNotNull(mCarrierConfigChangeListener); } @After Loading Loading @@ -275,7 +289,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { verify(mSubscriptionManagerService, never()).setDefaultSmsSubId(anyInt()); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -288,8 +302,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { @Test public void testSubInfoChangeAfterRadioUnavailable() throws Exception { mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); // Ensure all subscription loaded only updates state once Loading Loading @@ -345,7 +359,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { markSubscriptionInactive(2); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); verifyDismissIntentSent(); clearInvocations(mContext); Loading @@ -356,7 +370,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { setSimSlotIndex(2, 0); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 2); sendCarrierConfigChanged(0, 2); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -373,7 +387,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { markSubscriptionInactive(2); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -389,7 +403,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { mSubInfo[2] = new SubscriptionInfoInternal.Builder().setId(2).setSimSlotIndex(1).build(); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(1, 2); processAllMessages(); // Intent should be broadcast to ask default data selection. Loading @@ -405,7 +419,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { setSimSlotIndex(3, 1); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); // Intent should be broadcast to ask default data selection. Loading @@ -422,8 +436,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(mPhoneMock2).isUserDataEnabled(); // After initialization, sub 2 should have mobile data off. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mDataSettingsManagerMock2).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); Loading @@ -448,8 +462,6 @@ public class MultiSimSettingControllerTest extends TelephonyTest { clearInvocations(mSubscriptionManagerService); markSubscriptionInactive(1); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged( 1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); verify(mSubscriptionManagerService).setDefaultDataSubId( SubscriptionManager.INVALID_SUBSCRIPTION_ID); Loading @@ -457,6 +469,9 @@ public class MultiSimSettingControllerTest extends TelephonyTest { SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubscriptionManagerService, never()).setDefaultVoiceSubId(anyInt()); sendCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); // Verify intent sent to select sub 2 as default for all types. Intent intent = captureBroadcastIntent(); assertEquals(ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED, intent.getAction()); Loading @@ -475,8 +490,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(mPhoneMock2).isUserDataEnabled(); // After initialization, sub 2 should have mobile data off. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mDataSettingsManagerMock1).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); Loading Loading @@ -516,8 +531,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { Settings.Global.DEVICE_PROVISIONED, 0); // After initialization, sub 2 should have mobile data off. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mDataSettingsManagerMock1).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); Loading @@ -541,8 +556,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { GlobalSettingsHelper.setBoolean(mContext, Settings.Global.MOBILE_DATA, 2, true); GlobalSettingsHelper.setBoolean(mContext, Settings.Global.DATA_ROAMING, 2, false); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); // Create subscription grouping. Loading Loading @@ -589,7 +604,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { markSubscriptionInactive(2); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); verify(mSubscriptionManagerService).setDefaultDataSubId(3); Loading @@ -611,8 +626,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { // Notify subscriptions ready. Sub 2 should become the default. But shouldn't turn off // data of oppt sub 1. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mSubscriptionManagerService).setDefaultDataSubId(2); verify(mDataSettingsManagerMock1, never()).setDataEnabled( Loading Loading @@ -658,8 +673,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { // Notify subscriptions ready. Sub 2 should become the default, as sub 1 is opportunistic. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mSubscriptionManagerService).setDefaultDataSubId(2); Loading Loading @@ -697,8 +712,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifySubscriptionGroupChanged(mGroupUuid1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); // Defaults not touched, sub 1 is already default. Loading @@ -708,8 +723,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { clearInvocations(mSubscriptionManagerService); markSubscriptionInactive(1); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged( 0, SubscriptionManager.INVALID_SUBSCRIPTION_ID); sendCarrierConfigChanged(0, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); // Sub 2 should be made the default sub silently. Loading @@ -734,8 +748,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { GlobalSettingsHelper.setBoolean(mContext, Settings.Global.MOBILE_DATA, 1, true); GlobalSettingsHelper.setBoolean(mContext, Settings.Global.DATA_ROAMING, 1, false); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); // Create subscription grouping. Loading Loading @@ -774,11 +788,11 @@ public class MultiSimSettingControllerTest extends TelephonyTest { processAllMessages(); verify(mDataSettingsManagerMock2, never()).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); verify(mDataSettingsManagerMock2, never()).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mDataSettingsManagerMock2).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); Loading @@ -793,7 +807,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { processAllMessages(); verify(mContext, never()).sendBroadcast(any()); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); // Intent should be broadcast to ask default data selection. Intent intent = captureBroadcastIntent(); Loading Loading @@ -823,8 +837,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { // Sub 2 should have mobile data off, but it shouldn't happen until carrier configs are // loaded on both subscriptions. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 3); processAllMessages(); // Mark sub3 as oppt and notify grouping Loading @@ -845,10 +859,9 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(mPhoneMock2).isUserDataEnabled(); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); processAllMessages(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); // Notify carrier config change on phone1 without specifying subId. mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); sendCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); // Nothing should happen as carrier config is not ready for sub 2. verify(mDataSettingsManagerMock2, never()).setDataEnabled( Loading @@ -860,8 +873,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { CarrierConfigManager cm = (CarrierConfigManager) mContext.getSystemService( mContext.CARRIER_CONFIG_SERVICE); doReturn(new PersistableBundle()).when(cm).getConfigForSubId(2); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); sendCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); // This time user data should be disabled on phone1. verify(mDataSettingsManagerMock2).setDataEnabled( Loading Loading @@ -910,8 +922,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { public void testVoiceDataSmsAutoFallback() throws Exception { doReturn(1).when(mSubscriptionManagerService).getDefaultDataSubId(); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0,1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(2, 3); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(2, 2); processAllMessages(); verify(mSubscriptionManagerService, never()).setDefaultDataSubId(anyInt()); verify(mSubscriptionManagerService, never()).getActiveSubInfoCountMax(); Loading @@ -927,8 +939,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(resources).getBoolean( com.android.internal.R.bool.config_voice_data_sms_auto_fallback); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0,1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mSubscriptionManagerService).getActiveSubInfoCountMax(); verify(mSubscriptionManagerService).setDefaultDataSubId(anyInt()); Loading Loading
src/java/com/android/internal/telephony/MultiSimSettingController.java +6 −31 Original line number Diff line number Diff line Loading @@ -33,10 +33,8 @@ import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.AsyncResult; import android.os.Handler; import android.os.Looper; Loading Loading @@ -85,7 +83,6 @@ public class MultiSimSettingController extends Handler { private static final int EVENT_SUBSCRIPTION_INFO_CHANGED = 4; private static final int EVENT_SUBSCRIPTION_GROUP_CHANGED = 5; private static final int EVENT_DEFAULT_DATA_SUBSCRIPTION_CHANGED = 6; private static final int EVENT_CARRIER_CONFIG_CHANGED = 7; private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 8; @VisibleForTesting public static final int EVENT_RADIO_STATE_CHANGED = 9; Loading Loading @@ -162,19 +159,6 @@ public class MultiSimSettingController extends Handler { private static final String SETTING_USER_PREF_DATA_SUB = "user_preferred_data_sub"; private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(intent.getAction())) { int phoneId = intent.getIntExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, SubscriptionManager.INVALID_SIM_SLOT_INDEX); int subId = intent.getIntExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, SubscriptionManager.INVALID_SUBSCRIPTION_ID); notifyCarrierConfigChanged(phoneId, subId); } } }; private static class DataSettingsControllerCallback extends DataSettingsManagerCallback { private final Phone mPhone; Loading Loading @@ -250,8 +234,12 @@ public class MultiSimSettingController extends Handler { mIsAskEverytimeSupportedForSms = mContext.getResources() .getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support); context.registerReceiver(mIntentReceiver, new IntentFilter( CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); CarrierConfigManager ccm = mContext.getSystemService(CarrierConfigManager.class); // Listener callback is executed on handler thread to directly handle config change ccm.registerCarrierConfigChangeListener(this::post, (slotIndex, subId, carrierId, specificCarrierId) -> onCarrierConfigChanged(slotIndex, subId)); } /** Loading Loading @@ -330,11 +318,6 @@ public class MultiSimSettingController extends Handler { case EVENT_DEFAULT_DATA_SUBSCRIPTION_CHANGED: onDefaultDataSettingChanged(); break; case EVENT_CARRIER_CONFIG_CHANGED: int phoneId = msg.arg1; int subId = msg.arg2; onCarrierConfigChanged(phoneId, subId); break; case EVENT_MULTI_SIM_CONFIG_CHANGED: int activeModems = (int) ((AsyncResult) msg.obj).result; onMultiSimConfigChanged(activeModems); Loading Loading @@ -444,14 +427,6 @@ public class MultiSimSettingController extends Handler { reEvaluateAll(); } /** * Called when carrier config changes on any phone. */ @VisibleForTesting public void notifyCarrierConfigChanged(int phoneId, int subId) { obtainMessage(EVENT_CARRIER_CONFIG_CHANGED, phoneId, subId).sendToTarget(); } private void onCarrierConfigChanged(int phoneId, int subId) { log("onCarrierConfigChanged phoneId " + phoneId + " subId " + subId); if (!SubscriptionManager.isValidPhoneId(phoneId)) { Loading
tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java +57 −45 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; Loading Loading @@ -82,6 +83,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { private MultiSimSettingController mMultiSimSettingControllerUT; private Phone[] mPhones; private ParcelUuid mGroupUuid1 = new ParcelUuid(UUID.randomUUID()); private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener; // Mocked classes private Phone mPhoneMock1; Loading Loading @@ -134,6 +136,10 @@ public class MultiSimSettingControllerTest extends TelephonyTest { mSubInfo[subId] = new SubscriptionInfoInternal.Builder(mSubInfo[subId]) .setSimSlotIndex(simSlotIndex).build(); } private void sendCarrierConfigChanged(int phoneId, int subId) { mCarrierConfigChangeListener.onCarrierConfigChanged(phoneId, subId, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); } @Before public void setUp() throws Exception { Loading Loading @@ -237,9 +243,17 @@ public class MultiSimSettingControllerTest extends TelephonyTest { }).when(mPhoneMock2).getSubId(); replaceInstance(PhoneFactory.class, "sPhones", null, mPhones); mMultiSimSettingControllerUT = new MultiSimSettingController( mContext, mSubscriptionController); // Capture listener to emulate the carrier config change notification used later ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class); mMultiSimSettingControllerUT = new MultiSimSettingController(mContext, mSubscriptionController); processAllMessages(); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); assertNotNull(mCarrierConfigChangeListener); } @After Loading Loading @@ -275,7 +289,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { verify(mSubscriptionManagerService, never()).setDefaultSmsSubId(anyInt()); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -288,8 +302,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { @Test public void testSubInfoChangeAfterRadioUnavailable() throws Exception { mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); // Ensure all subscription loaded only updates state once Loading Loading @@ -345,7 +359,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { markSubscriptionInactive(2); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); verifyDismissIntentSent(); clearInvocations(mContext); Loading @@ -356,7 +370,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { setSimSlotIndex(2, 0); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 2); sendCarrierConfigChanged(0, 2); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -373,7 +387,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { markSubscriptionInactive(2); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -389,7 +403,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { mSubInfo[2] = new SubscriptionInfoInternal.Builder().setId(2).setSimSlotIndex(1).build(); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(1, 2); processAllMessages(); // Intent should be broadcast to ask default data selection. Loading @@ -405,7 +419,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { setSimSlotIndex(3, 1); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); // Intent should be broadcast to ask default data selection. Loading @@ -422,8 +436,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(mPhoneMock2).isUserDataEnabled(); // After initialization, sub 2 should have mobile data off. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mDataSettingsManagerMock2).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); Loading @@ -448,8 +462,6 @@ public class MultiSimSettingControllerTest extends TelephonyTest { clearInvocations(mSubscriptionManagerService); markSubscriptionInactive(1); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged( 1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); verify(mSubscriptionManagerService).setDefaultDataSubId( SubscriptionManager.INVALID_SUBSCRIPTION_ID); Loading @@ -457,6 +469,9 @@ public class MultiSimSettingControllerTest extends TelephonyTest { SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubscriptionManagerService, never()).setDefaultVoiceSubId(anyInt()); sendCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); // Verify intent sent to select sub 2 as default for all types. Intent intent = captureBroadcastIntent(); assertEquals(ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED, intent.getAction()); Loading @@ -475,8 +490,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(mPhoneMock2).isUserDataEnabled(); // After initialization, sub 2 should have mobile data off. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mDataSettingsManagerMock1).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); Loading Loading @@ -516,8 +531,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { Settings.Global.DEVICE_PROVISIONED, 0); // After initialization, sub 2 should have mobile data off. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mDataSettingsManagerMock1).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); Loading @@ -541,8 +556,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { GlobalSettingsHelper.setBoolean(mContext, Settings.Global.MOBILE_DATA, 2, true); GlobalSettingsHelper.setBoolean(mContext, Settings.Global.DATA_ROAMING, 2, false); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); // Create subscription grouping. Loading Loading @@ -589,7 +604,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { markSubscriptionInactive(2); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); verify(mSubscriptionManagerService).setDefaultDataSubId(3); Loading @@ -611,8 +626,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { // Notify subscriptions ready. Sub 2 should become the default. But shouldn't turn off // data of oppt sub 1. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mSubscriptionManagerService).setDefaultDataSubId(2); verify(mDataSettingsManagerMock1, never()).setDataEnabled( Loading Loading @@ -658,8 +673,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { // Notify subscriptions ready. Sub 2 should become the default, as sub 1 is opportunistic. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mSubscriptionManagerService).setDefaultDataSubId(2); Loading Loading @@ -697,8 +712,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifySubscriptionGroupChanged(mGroupUuid1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); // Defaults not touched, sub 1 is already default. Loading @@ -708,8 +723,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { clearInvocations(mSubscriptionManagerService); markSubscriptionInactive(1); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged( 0, SubscriptionManager.INVALID_SUBSCRIPTION_ID); sendCarrierConfigChanged(0, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); // Sub 2 should be made the default sub silently. Loading @@ -734,8 +748,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { GlobalSettingsHelper.setBoolean(mContext, Settings.Global.MOBILE_DATA, 1, true); GlobalSettingsHelper.setBoolean(mContext, Settings.Global.DATA_ROAMING, 1, false); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); // Create subscription grouping. Loading Loading @@ -774,11 +788,11 @@ public class MultiSimSettingControllerTest extends TelephonyTest { processAllMessages(); verify(mDataSettingsManagerMock2, never()).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); verify(mDataSettingsManagerMock2, never()).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mDataSettingsManagerMock2).setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, PHONE_PACKAGE); Loading @@ -793,7 +807,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { processAllMessages(); verify(mContext, never()).sendBroadcast(any()); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); // Intent should be broadcast to ask default data selection. Intent intent = captureBroadcastIntent(); Loading Loading @@ -823,8 +837,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { // Sub 2 should have mobile data off, but it shouldn't happen until carrier configs are // loaded on both subscriptions. mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 3); processAllMessages(); // Mark sub3 as oppt and notify grouping Loading @@ -845,10 +859,9 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(mPhoneMock2).isUserDataEnabled(); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); processAllMessages(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); // Notify carrier config change on phone1 without specifying subId. mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); sendCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); // Nothing should happen as carrier config is not ready for sub 2. verify(mDataSettingsManagerMock2, never()).setDataEnabled( Loading @@ -860,8 +873,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { CarrierConfigManager cm = (CarrierConfigManager) mContext.getSystemService( mContext.CARRIER_CONFIG_SERVICE); doReturn(new PersistableBundle()).when(cm).getConfigForSubId(2); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); sendCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); // This time user data should be disabled on phone1. verify(mDataSettingsManagerMock2).setDataEnabled( Loading Loading @@ -910,8 +922,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { public void testVoiceDataSmsAutoFallback() throws Exception { doReturn(1).when(mSubscriptionManagerService).getDefaultDataSubId(); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0,1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(2, 3); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(2, 2); processAllMessages(); verify(mSubscriptionManagerService, never()).setDefaultDataSubId(anyInt()); verify(mSubscriptionManagerService, never()).getActiveSubInfoCountMax(); Loading @@ -927,8 +939,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(resources).getBoolean( com.android.internal.R.bool.config_voice_data_sms_auto_fallback); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0,1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(1, 2); processAllMessages(); verify(mSubscriptionManagerService).getActiveSubInfoCountMax(); verify(mSubscriptionManagerService).setDefaultDataSubId(anyInt()); Loading