Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0b490b4 authored by Ling Ma's avatar Ling Ma Committed by Automerger Merge Worker
Browse files

Reset sim load on active radio unavailable am: e457c677

parents 27aa3414 e457c677
Loading
Loading
Loading
Loading
+25 −12
Original line number Diff line number Diff line
@@ -83,7 +83,8 @@ 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_MULTI_SIM_CONFIG_CHANGED          = 8;
    @VisibleForTesting
    public static final int EVENT_MULTI_SIM_CONFIG_CHANGED          = 8;
    @VisibleForTesting
    public static final int EVENT_RADIO_STATE_CHANGED                = 9;

@@ -150,6 +151,8 @@ public class MultiSimSettingController extends Handler {

    // The number of existing DataSettingsControllerCallback
    private int mCallbacksCount;
    /** The number of active modem count. */
    private int mActiveModemCount;

    private static final String SETTING_USER_PREF_DATA_SUB = "user_preferred_data_sub";

@@ -215,11 +218,14 @@ public class MultiSimSettingController extends Handler {
        mSubscriptionManagerService = SubscriptionManagerService.getInstance();

        // Initialize mCarrierConfigLoadedSubIds and register to listen to carrier config change.
        final int phoneCount = ((TelephonyManager) mContext.getSystemService(
                Context.TELEPHONY_SERVICE)).getSupportedModemCount();
        TelephonyManager telephonyManager = ((TelephonyManager) mContext.getSystemService(
                TelephonyManager.class));
        final int phoneCount = telephonyManager.getSupportedModemCount();
        mCarrierConfigLoadedSubIds = new int[phoneCount];
        Arrays.fill(mCarrierConfigLoadedSubIds, SubscriptionManager.INVALID_SUBSCRIPTION_ID);

        mActiveModemCount = telephonyManager.getActiveModemCount();

        PhoneConfigurationManager.registerForMultiSimConfigChange(
                this, EVENT_MULTI_SIM_CONFIG_CHANGED, null);

@@ -314,9 +320,14 @@ public class MultiSimSettingController extends Handler {
                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.");
                for (int phoneId = 0; phoneId < mActiveModemCount; phoneId++) {
                    Phone phone = PhoneFactory.getPhone(phoneId);
                    if (phone != null && phone.mCi.getRadioState()
                            == TelephonyManager.RADIO_POWER_UNAVAILABLE) {
                        if (DBG) {
                            log("Radio unavailable on phone " + phoneId
                                    + ", clearing sub info initialized flag");
                        }
                        mSubInfoInitialized = false;
                        break;
                    }
@@ -451,6 +462,8 @@ public class MultiSimSettingController extends Handler {
    }

    private void onMultiSimConfigChanged(int activeModems) {
        mActiveModemCount = activeModems;
        log("onMultiSimConfigChanged: current ActiveModemCount=" + mActiveModemCount);
        // Clear mCarrierConfigLoadedSubIds. Other actions will responds to active
        // subscription change.
        for (int phoneId = activeModems; phoneId < mCarrierConfigLoadedSubIds.length; phoneId++) {
@@ -599,8 +612,7 @@ public class MultiSimSettingController extends Handler {
        // opportunistic subscription active (activeSubInfos.size() > 1), we automatically
        // set the primary to be default SIM and return.
        if (mPrimarySubList.size() == 1 && (change != PRIMARY_SUB_REMOVED
                || ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE))
                .getActiveModemCount() == 1)) {
                || mActiveModemCount == 1)) {
            int subId = mPrimarySubList.get(0);
            if (DBG) log("updateDefaultValues: to only primary sub " + subId);
            mSubscriptionManagerService.setDefaultDataSubId(subId);
@@ -1056,10 +1068,11 @@ public class MultiSimSettingController extends Handler {
    }

    private boolean isRadioAvailableOnAllSubs() {
        for (Phone phone : PhoneFactory.getPhones()) {
            if ((phone.mCi != null &&
                    phone.mCi.getRadioState() == TelephonyManager.RADIO_POWER_UNAVAILABLE) ||
                    phone.isShuttingDown()) {
        for (int phoneId = 0; phoneId < mActiveModemCount; phoneId++) {
            Phone phone = PhoneFactory.getPhone(phoneId);
            if (phone != null
                    && (phone.mCi.getRadioState() == TelephonyManager.RADIO_POWER_UNAVAILABLE
                    || phone.isShuttingDown())) {
                return false;
            }
        }
+29 −4
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.verify;

import android.content.Intent;
import android.content.res.Resources;
import android.os.AsyncResult;
import android.os.HandlerThread;
import android.os.ParcelUuid;
import android.os.PersistableBundle;
@@ -59,6 +60,7 @@ import androidx.test.InstrumentationRegistry;

import com.android.internal.telephony.data.DataSettingsManager;
import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
import com.android.internal.telephony.test.SimulatedCommands;

import org.junit.After;
import org.junit.Assert;
@@ -302,9 +304,18 @@ public class MultiSimSettingControllerTest extends TelephonyTest {

    @Test
    public void testSubInfoChangeAfterRadioUnavailable() throws Exception {
        int phone1SubId = 1;
        int phone2SubId = 2;
        // Mock DSDS, mock Phone 2
        SimulatedCommands simulatedCommands2 = mock(SimulatedCommands.class);
        mPhone2.mCi = simulatedCommands2;
        doReturn(mDataSettingsManagerMock2).when(mPhone2).getDataSettingsManager();
        mPhones = new Phone[]{mPhone, mPhone2};
        replaceInstance(PhoneFactory.class, "sPhones", null, mPhones);
        // Load carrier config for all subs
        mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded();
        sendCarrierConfigChanged(0, 1);
        sendCarrierConfigChanged(1, 2);
        sendCarrierConfigChanged(0, phone1SubId);
        sendCarrierConfigChanged(1, phone2SubId);
        processAllMessages();

        // Ensure all subscription loaded only updates state once
@@ -315,7 +326,22 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        verify(mSubscriptionManagerService, never()).setDefaultVoiceSubId(anyInt());
        verify(mSubscriptionManagerService, never()).setDefaultSmsSubId(anyInt());

        // Notify radio unavailable.
        // DSDS -> single active modem, radio available on phone 0 but unavailable on phone 1
        doReturn(TelephonyManager.RADIO_POWER_UNAVAILABLE).when(simulatedCommands2).getRadioState();
        markSubscriptionInactive(phone2SubId);
        AsyncResult result = new AsyncResult(null, 1/*activeModemCount*/, null);
        clearInvocations(mSubscriptionManagerService);
        mMultiSimSettingControllerUT.obtainMessage(
                MultiSimSettingController.EVENT_MULTI_SIM_CONFIG_CHANGED, result).sendToTarget();
        mMultiSimSettingControllerUT.notifySubscriptionInfoChanged();
        processAllMessages();

        // Should still set defaults to the only remaining sub
        verify(mSubscriptionManagerService).setDefaultDataSubId(phone1SubId);
        verify(mSubscriptionManagerService).setDefaultVoiceSubId(phone1SubId);
        verify(mSubscriptionManagerService).setDefaultSmsSubId(phone1SubId);

        // Notify radio unavailable on all subs.
        replaceInstance(BaseCommands.class, "mState", mSimulatedCommands,
                TelephonyManager.RADIO_POWER_UNAVAILABLE);
        mMultiSimSettingControllerUT.obtainMessage(
@@ -323,7 +349,6 @@ public class MultiSimSettingControllerTest extends TelephonyTest {

        // Mark all subs as inactive.
        markSubscriptionInactive(1);
        markSubscriptionInactive(2);
        clearInvocations(mSubscriptionManagerService);

        // The below sub info change should be ignored.