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 +55 −43 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 @@ -80,6 +81,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 SubscriptionController mSubControllerMock; Loading Loading @@ -122,6 +124,11 @@ public class MultiSimSettingControllerTest extends TelephonyTest { .setGroupUuid(mGroupUuid1.toString()) .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 @@ -187,8 +194,15 @@ public class MultiSimSettingControllerTest extends TelephonyTest { replaceInstance(PhoneFactory.class, "sPhones", null, mPhones); replaceInstance(SubscriptionController.class, "sInstance", null, mSubControllerMock); // Capture listener to emulate the carrier config change notification used later ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class); mMultiSimSettingControllerUT = new MultiSimSettingController(mContext, mSubControllerMock); processAllMessages(); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); assertNotNull(mCarrierConfigChangeListener); } @After Loading Loading @@ -229,7 +243,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { verify(mSubControllerMock, never()).setDefaultSmsSubId(anyInt()); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -242,8 +256,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 @@ -319,7 +333,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); verifyDismissIntentSent(); clearInvocations(mContext); Loading @@ -343,7 +357,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{2}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 2); sendCarrierConfigChanged(0, 2); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -369,7 +383,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -393,7 +407,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1, 2}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(1, 2); processAllMessages(); // Intent should be broadcast to ask default data selection. Loading Loading @@ -421,7 +435,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1, 3}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); // Intent should be broadcast to ask default data selection. Loading @@ -438,8 +452,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 Loading @@ -471,9 +485,10 @@ public class MultiSimSettingControllerTest extends TelephonyTest { nullable(String.class)); doReturn(new int[]{2}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged( 1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); sendCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); verify(mSubControllerMock).setDefaultDataSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubControllerMock).setDefaultSmsSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubControllerMock, never()).setDefaultVoiceSubId(anyInt()); Loading @@ -497,8 +512,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 @@ -539,8 +554,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 @@ -564,8 +579,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 @@ -623,7 +638,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1, 3}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); verify(mSubControllerMock).setDefaultDataSubId(3); Loading @@ -647,8 +662,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(mSubControllerMock).setDefaultDataSubId(2); verify(mDataSettingsManagerMock1, never()).setDataEnabled( Loading Loading @@ -698,8 +713,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(mSubControllerMock).setDefaultDataSubId(2); Loading Loading @@ -739,8 +754,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 @@ -759,8 +774,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { nullable(String.class)); doReturn(new int[]{2}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); 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 @@ -786,8 +800,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 @@ -822,11 +836,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 Loading @@ -854,7 +868,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 @@ -896,8 +910,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 @@ -919,10 +933,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 @@ -935,8 +948,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 @@ -986,8 +998,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(1).when(mSubControllerMock).getDefaultDataSubId(); doReturn(1).when(mMockedIsub).getDefaultDataSubId(); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0,1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(2, 3); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(2, 2); processAllMessages(); verify(mSubControllerMock, never()).setDefaultDataSubId(anyInt()); verify(mSubControllerMock, never()).getActiveSubInfoCountMax(); Loading @@ -1003,8 +1015,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(mSubControllerMock).getActiveSubInfoCountMax(); verify(mSubControllerMock).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 +55 −43 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 @@ -80,6 +81,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 SubscriptionController mSubControllerMock; Loading Loading @@ -122,6 +124,11 @@ public class MultiSimSettingControllerTest extends TelephonyTest { .setGroupUuid(mGroupUuid1.toString()) .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 @@ -187,8 +194,15 @@ public class MultiSimSettingControllerTest extends TelephonyTest { replaceInstance(PhoneFactory.class, "sPhones", null, mPhones); replaceInstance(SubscriptionController.class, "sInstance", null, mSubControllerMock); // Capture listener to emulate the carrier config change notification used later ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class); mMultiSimSettingControllerUT = new MultiSimSettingController(mContext, mSubControllerMock); processAllMessages(); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); assertNotNull(mCarrierConfigChangeListener); } @After Loading Loading @@ -229,7 +243,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { verify(mSubControllerMock, never()).setDefaultSmsSubId(anyInt()); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -242,8 +256,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 @@ -319,7 +333,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); verifyDismissIntentSent(); clearInvocations(mContext); Loading @@ -343,7 +357,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{2}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 2); sendCarrierConfigChanged(0, 2); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -369,7 +383,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); sendCarrierConfigChanged(0, 1); processAllMessages(); // Sub 1 should be default sub silently. Loading @@ -393,7 +407,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1, 2}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); sendCarrierConfigChanged(1, 2); processAllMessages(); // Intent should be broadcast to ask default data selection. Loading Loading @@ -421,7 +435,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1, 3}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); // Intent should be broadcast to ask default data selection. Loading @@ -438,8 +452,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 Loading @@ -471,9 +485,10 @@ public class MultiSimSettingControllerTest extends TelephonyTest { nullable(String.class)); doReturn(new int[]{2}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged( 1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); sendCarrierConfigChanged(1, SubscriptionManager.INVALID_SUBSCRIPTION_ID); processAllMessages(); verify(mSubControllerMock).setDefaultDataSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubControllerMock).setDefaultSmsSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubControllerMock, never()).setDefaultVoiceSubId(anyInt()); Loading @@ -497,8 +512,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 @@ -539,8 +554,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 @@ -564,8 +579,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 @@ -623,7 +638,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(new int[]{1, 3}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 3); sendCarrierConfigChanged(1, 3); processAllMessages(); verify(mSubControllerMock).setDefaultDataSubId(3); Loading @@ -647,8 +662,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(mSubControllerMock).setDefaultDataSubId(2); verify(mDataSettingsManagerMock1, never()).setDataEnabled( Loading Loading @@ -698,8 +713,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(mSubControllerMock).setDefaultDataSubId(2); Loading Loading @@ -739,8 +754,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 @@ -759,8 +774,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { nullable(String.class)); doReturn(new int[]{2}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); 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 @@ -786,8 +800,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 @@ -822,11 +836,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 Loading @@ -854,7 +868,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 @@ -896,8 +910,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 @@ -919,10 +933,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 @@ -935,8 +948,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 @@ -986,8 +998,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(1).when(mSubControllerMock).getDefaultDataSubId(); doReturn(1).when(mMockedIsub).getDefaultDataSubId(); mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0,1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(2, 3); sendCarrierConfigChanged(0, 1); sendCarrierConfigChanged(2, 2); processAllMessages(); verify(mSubControllerMock, never()).setDefaultDataSubId(anyInt()); verify(mSubControllerMock, never()).getActiveSubInfoCountMax(); Loading @@ -1003,8 +1015,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(mSubControllerMock).getActiveSubInfoCountMax(); verify(mSubControllerMock).setDefaultDataSubId(anyInt()); Loading