Loading src/java/com/android/internal/telephony/PhoneConfigurationManager.java +26 −9 Original line number Diff line number Diff line Loading @@ -62,7 +62,9 @@ public class PhoneConfigurationManager { private PhoneCapability mStaticCapability; private final RadioConfig mRadioConfig; private final Handler mHandler; private final Phone[] mPhones; // mPhones is obtained from PhoneFactory and can have phones corresponding to inactive modems as // well. That is, the array size can be 2 even if num of active modems is 1. private Phone[] mPhones; private final Map<Integer, Boolean> mPhoneStatusMap; private MockableInterface mMi = new MockableInterface(); private TelephonyManager mTelephonyManager; Loading Loading @@ -101,16 +103,18 @@ public class PhoneConfigurationManager { mPhones = PhoneFactory.getPhones(); if (!StorageManager.inCryptKeeperBounce()) { for (Phone phone : mPhones) { phone.mCi.registerForAvailable(mHandler, Phone.EVENT_RADIO_AVAILABLE, phone); registerForRadioState(phone); } } private void registerForRadioState(Phone phone) { if (!StorageManager.inCryptKeeperBounce()) { phone.mCi.registerForAvailable(mHandler, Phone.EVENT_RADIO_AVAILABLE, phone); } else { for (Phone phone : mPhones) { phone.mCi.registerForOn(mHandler, Phone.EVENT_RADIO_ON, phone); } } } private PhoneCapability getDefaultCapability() { if (getPhoneCount() > 1) { Loading Loading @@ -347,6 +351,7 @@ public class PhoneConfigurationManager { } private void onMultiSimConfigChanged(int numOfActiveModems) { int oldNumOfActiveModems = getPhoneCount(); setMultiSimProperties(numOfActiveModems); if (isRebootRequiredForModemConfigChange()) { Loading @@ -357,9 +362,21 @@ public class PhoneConfigurationManager { log("onMultiSimConfigChanged: Rebooting is not required."); mMi.notifyPhoneFactoryOnMultiSimConfigChanged(mContext, numOfActiveModems); broadcastMultiSimConfigChange(numOfActiveModems); // Register to RIL service if needed. for (int i = 0; i < mPhones.length; i++) { // if numOfActiveModems is decreasing, deregister old RILs // eg if we are going from 2 phones to 1 phone, we need to deregister RIL for the // second phone. This loop does nothing if numOfActiveModems is increasing. for (int i = numOfActiveModems; i < oldNumOfActiveModems; i++) { mPhones[i].mCi.onSlotActiveStatusChange(SubscriptionManager.isValidPhoneId(i)); } // old phone objects are not needed now; mPhones can be updated mPhones = PhoneFactory.getPhones(); // if numOfActiveModems is increasing, register new RILs // eg if we are going from 1 phone to 2 phones, we need to register RIL for the second // phone. This loop does nothing if numOfActiveModems is decreasing. for (int i = oldNumOfActiveModems; i < numOfActiveModems; i++) { Phone phone = mPhones[i]; registerForRadioState(phone); phone.mCi.onSlotActiveStatusChange(SubscriptionManager.isValidPhoneId(i)); } } Loading tests/telephonytests/src/com/android/internal/telephony/PhoneConfigurationManagerTest.java +24 −6 Original line number Diff line number Diff line Loading @@ -21,12 +21,14 @@ import static android.telephony.TelephonyManager.EXTRA_ACTIVE_SIM_SUPPORTED_COUN import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.content.Intent; Loading @@ -51,7 +53,11 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { @Mock Handler mHandler; @Mock CommandsInterface mMockCi; CommandsInterface mMockCi0; @Mock CommandsInterface mMockCi1; @Mock private Phone mPhone1; // mPhone as phone 0 is already defined in TelephonyTest. @Mock PhoneConfigurationManager.MockableInterface mMi; Loading @@ -61,8 +67,9 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); mPhone.mCi = mMockCi; mCT.mCi = mMockCi; mPhone.mCi = mMockCi0; mCT.mCi = mMockCi0; mPhone1.mCi = mMockCi1; } @After Loading Loading @@ -105,7 +112,7 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { Message message = new Message(); mPcm.enablePhone(mPhone, false, message); verify(mMockCi).enableModem(eq(false), eq(message)); verify(mMockCi0).enableModem(eq(false), eq(message)); } @Test Loading Loading @@ -140,6 +147,8 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { @SmallTest public void testSwitchMultiSimConfig_dsdsCapable_noRebootRequired() throws Exception { init(1); verify(mMockCi0, times(1)).registerForAvailable(any(), anyInt(), any()); // Register for multi SIM config change. mPcm.registerForMultiSimConfigChange(mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null); verify(mHandler, never()).sendMessageAtTime(any(), anyLong()); Loading @@ -151,9 +160,13 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { // Send static capability back to indicate DSDS is supported. clearInvocations(mMockRadioConfig); testGetDsdsCapability(); // testGetDsdsCapability leads to another call to registerForAvailable() verify(mMockCi0, times(2)).registerForAvailable(any(), anyInt(), any()); // Try to switch to DSDS. setRebootRequiredForConfigSwitch(false); mPhones = new Phone[]{mPhone, mPhone1}; replaceInstance(PhoneFactory.class, "sPhones", null, mPhones); mPcm.switchMultiSimConfig(2); ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class); verify(mMockRadioConfig).setModemsConfig(eq(2), captor.capture()); Loading Loading @@ -182,7 +195,12 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { assertEquals(2, intent.getIntExtra( EXTRA_ACTIVE_SIM_SUPPORTED_COUNT, 0)); // Verify RIL notification. verify(mMockCi).onSlotActiveStatusChange(true); // Verify registerForAvailable() and onSlotActiveStatusChange() are called for the second // phone, and not for the first phone (registerForAvailable() was already called twice // earlier so verify that the count is still at 2) verify(mMockCi0, times(2)).registerForAvailable(any(), anyInt(), any()); verify(mMockCi0, never()).onSlotActiveStatusChange(anyBoolean()); verify(mMockCi1, times(1)).registerForAvailable(any(), anyInt(), any()); verify(mMockCi1, times(1)).onSlotActiveStatusChange(anyBoolean()); } } Loading
src/java/com/android/internal/telephony/PhoneConfigurationManager.java +26 −9 Original line number Diff line number Diff line Loading @@ -62,7 +62,9 @@ public class PhoneConfigurationManager { private PhoneCapability mStaticCapability; private final RadioConfig mRadioConfig; private final Handler mHandler; private final Phone[] mPhones; // mPhones is obtained from PhoneFactory and can have phones corresponding to inactive modems as // well. That is, the array size can be 2 even if num of active modems is 1. private Phone[] mPhones; private final Map<Integer, Boolean> mPhoneStatusMap; private MockableInterface mMi = new MockableInterface(); private TelephonyManager mTelephonyManager; Loading Loading @@ -101,16 +103,18 @@ public class PhoneConfigurationManager { mPhones = PhoneFactory.getPhones(); if (!StorageManager.inCryptKeeperBounce()) { for (Phone phone : mPhones) { phone.mCi.registerForAvailable(mHandler, Phone.EVENT_RADIO_AVAILABLE, phone); registerForRadioState(phone); } } private void registerForRadioState(Phone phone) { if (!StorageManager.inCryptKeeperBounce()) { phone.mCi.registerForAvailable(mHandler, Phone.EVENT_RADIO_AVAILABLE, phone); } else { for (Phone phone : mPhones) { phone.mCi.registerForOn(mHandler, Phone.EVENT_RADIO_ON, phone); } } } private PhoneCapability getDefaultCapability() { if (getPhoneCount() > 1) { Loading Loading @@ -347,6 +351,7 @@ public class PhoneConfigurationManager { } private void onMultiSimConfigChanged(int numOfActiveModems) { int oldNumOfActiveModems = getPhoneCount(); setMultiSimProperties(numOfActiveModems); if (isRebootRequiredForModemConfigChange()) { Loading @@ -357,9 +362,21 @@ public class PhoneConfigurationManager { log("onMultiSimConfigChanged: Rebooting is not required."); mMi.notifyPhoneFactoryOnMultiSimConfigChanged(mContext, numOfActiveModems); broadcastMultiSimConfigChange(numOfActiveModems); // Register to RIL service if needed. for (int i = 0; i < mPhones.length; i++) { // if numOfActiveModems is decreasing, deregister old RILs // eg if we are going from 2 phones to 1 phone, we need to deregister RIL for the // second phone. This loop does nothing if numOfActiveModems is increasing. for (int i = numOfActiveModems; i < oldNumOfActiveModems; i++) { mPhones[i].mCi.onSlotActiveStatusChange(SubscriptionManager.isValidPhoneId(i)); } // old phone objects are not needed now; mPhones can be updated mPhones = PhoneFactory.getPhones(); // if numOfActiveModems is increasing, register new RILs // eg if we are going from 1 phone to 2 phones, we need to register RIL for the second // phone. This loop does nothing if numOfActiveModems is decreasing. for (int i = oldNumOfActiveModems; i < numOfActiveModems; i++) { Phone phone = mPhones[i]; registerForRadioState(phone); phone.mCi.onSlotActiveStatusChange(SubscriptionManager.isValidPhoneId(i)); } } Loading
tests/telephonytests/src/com/android/internal/telephony/PhoneConfigurationManagerTest.java +24 −6 Original line number Diff line number Diff line Loading @@ -21,12 +21,14 @@ import static android.telephony.TelephonyManager.EXTRA_ACTIVE_SIM_SUPPORTED_COUN import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.content.Intent; Loading @@ -51,7 +53,11 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { @Mock Handler mHandler; @Mock CommandsInterface mMockCi; CommandsInterface mMockCi0; @Mock CommandsInterface mMockCi1; @Mock private Phone mPhone1; // mPhone as phone 0 is already defined in TelephonyTest. @Mock PhoneConfigurationManager.MockableInterface mMi; Loading @@ -61,8 +67,9 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); mPhone.mCi = mMockCi; mCT.mCi = mMockCi; mPhone.mCi = mMockCi0; mCT.mCi = mMockCi0; mPhone1.mCi = mMockCi1; } @After Loading Loading @@ -105,7 +112,7 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { Message message = new Message(); mPcm.enablePhone(mPhone, false, message); verify(mMockCi).enableModem(eq(false), eq(message)); verify(mMockCi0).enableModem(eq(false), eq(message)); } @Test Loading Loading @@ -140,6 +147,8 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { @SmallTest public void testSwitchMultiSimConfig_dsdsCapable_noRebootRequired() throws Exception { init(1); verify(mMockCi0, times(1)).registerForAvailable(any(), anyInt(), any()); // Register for multi SIM config change. mPcm.registerForMultiSimConfigChange(mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null); verify(mHandler, never()).sendMessageAtTime(any(), anyLong()); Loading @@ -151,9 +160,13 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { // Send static capability back to indicate DSDS is supported. clearInvocations(mMockRadioConfig); testGetDsdsCapability(); // testGetDsdsCapability leads to another call to registerForAvailable() verify(mMockCi0, times(2)).registerForAvailable(any(), anyInt(), any()); // Try to switch to DSDS. setRebootRequiredForConfigSwitch(false); mPhones = new Phone[]{mPhone, mPhone1}; replaceInstance(PhoneFactory.class, "sPhones", null, mPhones); mPcm.switchMultiSimConfig(2); ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class); verify(mMockRadioConfig).setModemsConfig(eq(2), captor.capture()); Loading Loading @@ -182,7 +195,12 @@ public class PhoneConfigurationManagerTest extends TelephonyTest { assertEquals(2, intent.getIntExtra( EXTRA_ACTIVE_SIM_SUPPORTED_COUNT, 0)); // Verify RIL notification. verify(mMockCi).onSlotActiveStatusChange(true); // Verify registerForAvailable() and onSlotActiveStatusChange() are called for the second // phone, and not for the first phone (registerForAvailable() was already called twice // earlier so verify that the count is still at 2) verify(mMockCi0, times(2)).registerForAvailable(any(), anyInt(), any()); verify(mMockCi0, never()).onSlotActiveStatusChange(anyBoolean()); verify(mMockCi1, times(1)).registerForAvailable(any(), anyInt(), any()); verify(mMockCi1, times(1)).onSlotActiveStatusChange(anyBoolean()); } }