Loading src/java/com/android/internal/telephony/MultiSimSettingController.java +18 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,8 @@ public class MultiSimSettingController extends Handler { 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; @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"PRIMARY_SUB_"}, Loading Loading @@ -294,6 +296,16 @@ public class MultiSimSettingController extends Handler { case EVENT_MULTI_SIM_CONFIG_CHANGED: int activeModems = (int) ((AsyncResult) msg.obj).result; onMultiSimConfigChanged(activeModems); break; case EVENT_RADIO_STATE_CHANGED: for (Phone phone : PhoneFactory.getPhones()) { if (phone.mCi.getRadioState() == TelephonyManager.RADIO_POWER_UNAVAILABLE) { if (DBG) log("Radio unavailable. Clearing sub info initialized flag."); mSubInfoInitialized = false; break; } } break; } } Loading Loading @@ -335,6 +347,9 @@ public class MultiSimSettingController extends Handler { private void onAllSubscriptionsLoaded() { if (DBG) log("onAllSubscriptionsLoaded"); mSubInfoInitialized = true; for (Phone phone : PhoneFactory.getPhones()) { phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null); } reEvaluateAll(); } Loading Loading @@ -424,6 +439,9 @@ public class MultiSimSettingController extends Handler { for (int phoneId = activeModems; phoneId < mCarrierConfigLoadedSubIds.length; phoneId++) { mCarrierConfigLoadedSubIds[phoneId] = INVALID_SUBSCRIPTION_ID; } for (Phone phone : PhoneFactory.getPhones()) { phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null); } } /** Loading tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java +49 −1 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.telephony.TelephonyManager; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import androidx.test.InstrumentationRegistry; import com.android.internal.telephony.dataconnection.DataEnabledSettings; Loading @@ -62,6 +63,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.UUID; Loading Loading @@ -132,6 +134,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(mSubControllerMock).isOpportunistic(5); doReturn(1).when(mPhoneMock1).getSubId(); doReturn(2).when(mPhoneMock2).getSubId(); mPhoneMock1.mCi = mSimulatedCommands; mPhoneMock2.mCi = mSimulatedCommands; List<SubscriptionInfo> infoList = Arrays.asList(mSubInfo1, mSubInfo2); doReturn(infoList).when(mSubControllerMock) .getActiveSubscriptionInfoList(anyString(), nullable(String.class)); Loading Loading @@ -163,7 +167,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { @Test @SmallTest public void testTestSubInfoChangeBeforeAllSubReady() throws Exception { public void testSubInfoChangeBeforeAllSubReady() throws Exception { doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mSubControllerMock) .getDefaultDataSubId(); doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mSubControllerMock) Loading Loading @@ -198,6 +202,50 @@ public class MultiSimSettingControllerTest extends TelephonyTest { verifyDismissIntentSent(); } @Test public void testSubInfoChangeAfterRadioUnavailable() throws Exception { mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); processAllMessages(); // Notify radio unavailable. replaceInstance(BaseCommands.class, "mState", mSimulatedCommands, TelephonyManager.RADIO_POWER_UNAVAILABLE); mMultiSimSettingControllerUT.obtainMessage( MultiSimSettingController.EVENT_RADIO_STATE_CHANGED).sendToTarget(); // Mark all subs as inactive. doReturn(false).when(mSubControllerMock).isActiveSubId(1); doReturn(false).when(mSubControllerMock).isActiveSubId(2); doReturn(SubscriptionManager.INVALID_PHONE_INDEX).when(mSubControllerMock).getPhoneId(1); doReturn(SubscriptionManager.INVALID_PHONE_INDEX).when(mSubControllerMock).getPhoneId(2); doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mPhoneMock1).getSubId(); doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mPhoneMock2).getSubId(); List<SubscriptionInfo> infoList = new ArrayList<>(); doReturn(infoList).when(mSubControllerMock).getActiveSubscriptionInfoList(anyString(), nullable(String.class)); doReturn(new int[]{}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); clearInvocations(mSubControllerMock); // The below sub info change should be ignored. mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); processAllMessages(); verify(mSubControllerMock, never()).setDefaultDataSubId(anyInt()); verify(mSubControllerMock, never()).setDefaultVoiceSubId(anyInt()); verify(mSubControllerMock, never()).setDefaultSmsSubId(anyInt()); // Send all sub ready notification mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); processAllMessages(); // Everything should be set to invalid since nothing is active. verify(mSubControllerMock).setDefaultDataSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubControllerMock) .setDefaultVoiceSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubControllerMock).setDefaultSmsSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); } @Test @SmallTest public void testSingleActiveDsds() throws Exception { Loading Loading
src/java/com/android/internal/telephony/MultiSimSettingController.java +18 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,8 @@ public class MultiSimSettingController extends Handler { 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; @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"PRIMARY_SUB_"}, Loading Loading @@ -294,6 +296,16 @@ public class MultiSimSettingController extends Handler { case EVENT_MULTI_SIM_CONFIG_CHANGED: int activeModems = (int) ((AsyncResult) msg.obj).result; onMultiSimConfigChanged(activeModems); break; case EVENT_RADIO_STATE_CHANGED: for (Phone phone : PhoneFactory.getPhones()) { if (phone.mCi.getRadioState() == TelephonyManager.RADIO_POWER_UNAVAILABLE) { if (DBG) log("Radio unavailable. Clearing sub info initialized flag."); mSubInfoInitialized = false; break; } } break; } } Loading Loading @@ -335,6 +347,9 @@ public class MultiSimSettingController extends Handler { private void onAllSubscriptionsLoaded() { if (DBG) log("onAllSubscriptionsLoaded"); mSubInfoInitialized = true; for (Phone phone : PhoneFactory.getPhones()) { phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null); } reEvaluateAll(); } Loading Loading @@ -424,6 +439,9 @@ public class MultiSimSettingController extends Handler { for (int phoneId = activeModems; phoneId < mCarrierConfigLoadedSubIds.length; phoneId++) { mCarrierConfigLoadedSubIds[phoneId] = INVALID_SUBSCRIPTION_ID; } for (Phone phone : PhoneFactory.getPhones()) { phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null); } } /** Loading
tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java +49 −1 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.telephony.TelephonyManager; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import androidx.test.InstrumentationRegistry; import com.android.internal.telephony.dataconnection.DataEnabledSettings; Loading @@ -62,6 +63,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.UUID; Loading Loading @@ -132,6 +134,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest { doReturn(true).when(mSubControllerMock).isOpportunistic(5); doReturn(1).when(mPhoneMock1).getSubId(); doReturn(2).when(mPhoneMock2).getSubId(); mPhoneMock1.mCi = mSimulatedCommands; mPhoneMock2.mCi = mSimulatedCommands; List<SubscriptionInfo> infoList = Arrays.asList(mSubInfo1, mSubInfo2); doReturn(infoList).when(mSubControllerMock) .getActiveSubscriptionInfoList(anyString(), nullable(String.class)); Loading Loading @@ -163,7 +167,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest { @Test @SmallTest public void testTestSubInfoChangeBeforeAllSubReady() throws Exception { public void testSubInfoChangeBeforeAllSubReady() throws Exception { doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mSubControllerMock) .getDefaultDataSubId(); doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mSubControllerMock) Loading Loading @@ -198,6 +202,50 @@ public class MultiSimSettingControllerTest extends TelephonyTest { verifyDismissIntentSent(); } @Test public void testSubInfoChangeAfterRadioUnavailable() throws Exception { mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1); mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2); processAllMessages(); // Notify radio unavailable. replaceInstance(BaseCommands.class, "mState", mSimulatedCommands, TelephonyManager.RADIO_POWER_UNAVAILABLE); mMultiSimSettingControllerUT.obtainMessage( MultiSimSettingController.EVENT_RADIO_STATE_CHANGED).sendToTarget(); // Mark all subs as inactive. doReturn(false).when(mSubControllerMock).isActiveSubId(1); doReturn(false).when(mSubControllerMock).isActiveSubId(2); doReturn(SubscriptionManager.INVALID_PHONE_INDEX).when(mSubControllerMock).getPhoneId(1); doReturn(SubscriptionManager.INVALID_PHONE_INDEX).when(mSubControllerMock).getPhoneId(2); doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mPhoneMock1).getSubId(); doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mPhoneMock2).getSubId(); List<SubscriptionInfo> infoList = new ArrayList<>(); doReturn(infoList).when(mSubControllerMock).getActiveSubscriptionInfoList(anyString(), nullable(String.class)); doReturn(new int[]{}).when(mSubControllerMock).getActiveSubIdList(anyBoolean()); clearInvocations(mSubControllerMock); // The below sub info change should be ignored. mMultiSimSettingControllerUT.notifySubscriptionInfoChanged(); processAllMessages(); verify(mSubControllerMock, never()).setDefaultDataSubId(anyInt()); verify(mSubControllerMock, never()).setDefaultVoiceSubId(anyInt()); verify(mSubControllerMock, never()).setDefaultSmsSubId(anyInt()); // Send all sub ready notification mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded(); processAllMessages(); // Everything should be set to invalid since nothing is active. verify(mSubControllerMock).setDefaultDataSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubControllerMock) .setDefaultVoiceSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); verify(mSubControllerMock).setDefaultSmsSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID); } @Test @SmallTest public void testSingleActiveDsds() throws Exception { Loading