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
Merged-In: Ia6e93d13009a773ede3bfcb02e82dbbfb4c437cc
diff --git a/src/java/com/android/internal/telephony/MultiSimSettingController.java b/src/java/com/android/internal/telephony/MultiSimSettingController.java
index c69a115..e973f07 100644
--- a/src/java/com/android/internal/telephony/MultiSimSettingController.java
+++ b/src/java/com/android/internal/telephony/MultiSimSettingController.java
@@ -21,6 +21,7 @@
 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;
@@ -536,6 +537,7 @@
             mSubController.setDefaultDataSubId(subId);
             mSubController.setDefaultVoiceSubId(subId);
             mSubController.setDefaultSmsSubId(subId);
+            sendDefaultSubConfirmedNotification(subId);
             return;
         }
 
@@ -609,6 +611,19 @@
         }
     }
 
+    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
diff --git a/tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java
index 2033af5..e340033 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/MultiSimSettingControllerTest.java
@@ -20,6 +20,7 @@
 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;
@@ -190,8 +191,7 @@
         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
@@ -216,6 +216,8 @@
         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.
@@ -237,8 +239,7 @@
         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
@@ -261,11 +262,11 @@
         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();
@@ -445,8 +446,7 @@
         processAllMessages();
         verify(mSubControllerMock).setDefaultDataSubId(2);
         verify(mDataEnabledSettingsMock1, never()).setUserDataEnabled(anyBoolean());
-        // No user selection needed, no intent should be sent.
-        verify(mContext, never()).sendBroadcast(any());
+        verifyDismissIntentSent();
 
         clearInvocations(mSubControllerMock);
         clearInvocations(mDataEnabledSettingsMock1);
@@ -465,6 +465,13 @@
         verify(mDataEnabledSettingsMock2, never()).setUserDataEnabled(anyBoolean());
     }
 
+    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 {
@@ -483,8 +490,6 @@
         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();
@@ -505,8 +510,7 @@
         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() {