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

Commit bcaf327f authored by Malcolm Chen's avatar Malcolm Chen Committed by Xiangyu/Malcolm Chen
Browse files

Automatically dismiss SIM combination warnings and selection dialogs.

When configuring CBRS profiles this dialog / notification will be
dismissed after configuration is done, to avoid confusion.

Bug: 142092510
Test: manual and unittest
Change-Id: Ia6e93d13009a773ede3bfcb02e82dbbfb4c437cc
parent 48e91cc9
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.telephony.TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIS
import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE;
import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL;
import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA;
import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS;
import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE;
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_NAMES;
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE;
@@ -542,6 +543,7 @@ public class MultiSimSettingController extends Handler {
            mSubController.setDefaultDataSubId(subId);
            mSubController.setDefaultVoiceSubId(subId);
            mSubController.setDefaultSmsSubId(subId);
            sendDefaultSubConfirmedNotification(subId);
            return;
        }

@@ -616,6 +618,19 @@ public class MultiSimSettingController extends Handler {
        }
    }

    private void sendDefaultSubConfirmedNotification(int defaultSubId) {
        Intent intent = new Intent();
        intent.setAction(ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);
        intent.setClassName("com.android.settings",
                "com.android.settings.sim.SimSelectNotification");

        intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE,
                EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS);
        intent.putExtra(EXTRA_SUBSCRIPTION_ID, defaultSubId);

        mContext.sendBroadcast(intent);
    }

    private void sendSubChangeNotificationIfNeeded(int change, boolean dataSelected,
            boolean voiceSelected, boolean smsSelected) {
        @TelephonyManager.DefaultSubscriptionSelectType
+16 −12
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.telephony.TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIS
import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE;
import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL;
import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA;
import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS;
import static android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID;

import static org.junit.Assert.assertEquals;
@@ -191,8 +192,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        verify(mSubControllerMock).setDefaultDataSubId(1);
        verify(mSubControllerMock).setDefaultVoiceSubId(1);
        verify(mSubControllerMock).setDefaultSmsSubId(1);
        // No dialog or notification is needed. So no intent is expected to be broadcast.
        verify(mContext, never()).sendBroadcast(any());
        verifyDismissIntentSent();
    }

    @Test
@@ -217,6 +217,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded();
        mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1);
        processAllMessages();
        verifyDismissIntentSent();
        clearInvocations(mContext);

        // Sub 1 should be default sub silently.
        // Sub 1 switches to sub 2 in the same slot.
@@ -238,8 +240,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        verify(mSubControllerMock).setDefaultDataSubId(2);
        verify(mSubControllerMock).setDefaultVoiceSubId(2);
        verify(mSubControllerMock).setDefaultSmsSubId(2);
        // No dialog or notification is needed. So no intent is expected to be broadcast.
        verify(mContext, never()).sendBroadcast(any());
        verifyDismissIntentSent();
    }

    @Test
@@ -262,11 +263,11 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        verify(mSubControllerMock).setDefaultDataSubId(1);
        verify(mSubControllerMock).setDefaultVoiceSubId(1);
        verify(mSubControllerMock).setDefaultSmsSubId(1);
        // No dialog or notification is needed. So no intent is expected to be broadcast.
        verify(mContext, never()).sendBroadcast(any());
        verifyDismissIntentSent();

        // Mark sub 2 as active in phone[1].
        clearInvocations(mSubControllerMock);
        clearInvocations(mContext);
        doReturn(true).when(mSubControllerMock).isActiveSubId(2);
        doReturn(1).when(mSubControllerMock).getPhoneId(2);
        doReturn(2).when(mPhoneMock2).getSubId();
@@ -485,8 +486,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        verify(mSubControllerMock).setDefaultDataSubId(2);
        verify(mDataEnabledSettingsMock1, never()).setDataEnabled(
                anyInt(), anyBoolean());
        // No user selection needed, no intent should be sent.
        verify(mContext, never()).sendBroadcast(any());
        verifyDismissIntentSent();

        clearInvocations(mSubControllerMock);
        clearInvocations(mDataEnabledSettingsMock1);
@@ -507,6 +507,13 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
    }

    private void verifyDismissIntentSent() {
        Intent intentSent = captureBroadcastIntent();
        assertEquals(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS,
                intentSent.getIntExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE, -1));
        assertEquals(ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED, intentSent.getAction());
    }

    @Test
    @SmallTest
    public void testGroupedCbrs() throws Exception {
@@ -525,8 +532,6 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2);
        processAllMessages();
        verify(mSubControllerMock).setDefaultDataSubId(2);
        // No user selection needed, no intent should be sent.
        verify(mContext, never()).sendBroadcast(any());

        // Mark sub 2 as data off.
        doReturn(false).when(mPhoneMock2).isUserDataEnabled();
@@ -547,8 +552,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        mMultiSimSettingControllerUT.notifyUserDataEnabled(2, true);
        processAllMessages();
        verify(mDataEnabledSettingsMock1).setUserDataEnabled(true, false);
        // No user selection needed, no intent should be sent.
        verify(mContext, never()).sendBroadcast(any());
        verifyDismissIntentSent();
    }

    private Intent captureBroadcastIntent() {