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

Commit 57badc2a authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Triggering notifications when dual CDMA SIM combinations are detected

In Settings, catch the intent from Telephony about SIM combination
warning and show a notification about it.

Bug: 132631355
Test: manual - have two cdma capable subscriptions active, make sure
the notification is sent, and tapping on it leads to the helper page.

Change-Id: Ifd0e13781e4afc3bfd82415b3e51fd10176d9f9d
parent b731f4d5
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -7014,6 +7014,8 @@
    <string name="help_uri_wifi_scanning_required" translatable="false"></string>
    <!-- url for the bluetooth toggle required dialog help page -->
    <string name="help_uri_bluetooth_screen" translatable="false"></string>
    <!-- url for the SIM combination warning required dialog help page -->
    <string name="help_uri_sim_combination_warning" translatable="false"></string>
    <!-- User account title [CHAR LIMIT=30] -->
    <string name="user_account_title">Account for content</string>
@@ -11254,4 +11256,12 @@
    <!-- Title for enable MMS notification channel.  [CHAR LIMIT=40] -->
    <string name="enable_mms_notification_channel_title">MMS message</string>
    <!-- Title for SIM combination warning. [CHAR LIMIT=80] -->
    <string name="sim_combination_warning_notification_title">Issue with SIM combination</string>
    <!-- Message for DSDS dual CDMA SIM combination warning. [CHAR LIMIT=100] -->
    <string name="dual_cdma_sim_warning_notification_summary">Using <xliff:g id="operator_names" example="T-Mobile &amp; Verizon">%1$s</xliff:g> may limit functionality. Tap to learn more.</string>
    <!-- Title for enable MMS notification channel.  [CHAR LIMIT=40] -->
    <string name="dual_cdma_sim_warning_notification_channel_title">SIM combination</string>
</resources>
+86 −4
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@ import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELE
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_NONE;
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_NAMES;
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE;
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA;
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE;
import static android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID;
import static android.telephony.data.ApnSetting.TYPE_MMS;

@@ -43,6 +47,7 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.network.telephony.MobileNetworkActivity;
import com.android.settingslib.HelpUtils;

public class SimSelectNotification extends BroadcastReceiver {
    private static final String TAG = "SimSelectNotification";
@@ -50,6 +55,8 @@ public class SimSelectNotification extends BroadcastReceiver {
    public static final int SIM_SELECT_NOTIFICATION_ID = 1;
    @VisibleForTesting
    public static final int ENABLE_MMS_NOTIFICATION_ID = 2;
    @VisibleForTesting
    public static final int SIM_WARNING_NOTIFICATION_ID = 3;

    @VisibleForTesting
    public static final String SIM_SELECT_NOTIFICATION_CHANNEL =
@@ -59,6 +66,10 @@ public class SimSelectNotification extends BroadcastReceiver {
    public static final String ENABLE_MMS_NOTIFICATION_CHANNEL =
            "enable_mms_notification_channel";

    @VisibleForTesting
    public static final String SIM_WARNING_NOTIFICATION_CHANNEL =
            "sim_warning_notification_channel";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
@@ -125,13 +136,23 @@ public class SimSelectNotification extends BroadcastReceiver {
    }

    private void onPrimarySubscriptionListChanged(Context context, Intent intent) {
        startSimSelectDialogIfNeeded(context, intent);
        sendSimCombinationWarningIfNeeded(context, intent);
    }

    private void startSimSelectDialogIfNeeded(Context context, Intent intent) {
        int dialogType = intent.getIntExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE,
                EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE);

        if (dialogType == EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE) {
            return;
        }

        // Cancel any previous notifications
        cancelSimSelectNotification(context);
        // Create a notification to tell the user that some defaults are missing
        createSimSelectNotification(context);

        int dialogType = intent.getIntExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE,
                EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE);
        if (dialogType == EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL) {
            int subId = intent.getIntExtra(EXTRA_SUBSCRIPTION_ID,
                    SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
@@ -139,11 +160,12 @@ public class SimSelectNotification extends BroadcastReceiver {
            // If there is only one subscription, ask if user wants to use if for everything
            Intent newIntent = new Intent(context, SimDialogActivity.class);
            newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.PREFERRED_PICK);
            newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY,
                    SimDialogActivity.PREFERRED_PICK);
            newIntent.putExtra(SimDialogActivity.PREFERRED_SIM, slotIndex);
            context.startActivity(newIntent);
        } else if (dialogType == EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA) {
            // If there are mulitple, ensure they pick default data
            // If there are multiple, ensure they pick default data
            Intent newIntent = new Intent(context, SimDialogActivity.class);
            newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.DATA_PICK);
@@ -151,6 +173,18 @@ public class SimSelectNotification extends BroadcastReceiver {
        }
    }

    private void sendSimCombinationWarningIfNeeded(Context context, Intent intent) {
        final int warningType = intent.getIntExtra(EXTRA_SIM_COMBINATION_WARNING_TYPE,
                EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE);

        if (warningType == EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA) {
            // Cancel any previous notifications
            cancelSimCombinationWarningNotification(context);
            // Create a notification to tell the user that some defaults are missing
            createSimCombinationWarningNotification(context, intent);
        }
    }

    private void createSimSelectNotification(Context context){
        final Resources resources = context.getResources();

@@ -222,4 +256,52 @@ public class SimSelectNotification extends BroadcastReceiver {
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(ENABLE_MMS_NOTIFICATION_ID);
    }

    private void createSimCombinationWarningNotification(Context context, Intent intent){
        final Resources resources = context.getResources();
        final String simNames = intent.getStringExtra(EXTRA_SIM_COMBINATION_NAMES);

        if (simNames == null) {
            return;
        }

        CharSequence dualCdmaSimWarningSummary = resources.getString(
                R.string.dual_cdma_sim_warning_notification_summary, simNames);

        NotificationChannel notificationChannel = new NotificationChannel(
                SIM_WARNING_NOTIFICATION_CHANNEL,
                resources.getText(R.string.dual_cdma_sim_warning_notification_channel_title),
                NotificationManager.IMPORTANCE_HIGH);

        Notification.Builder builder =
                new Notification.Builder(context, SIM_WARNING_NOTIFICATION_CHANNEL)
                        .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp)
                        .setColor(context.getColor(R.color.sim_noitification))
                        .setContentTitle(resources.getText(
                                R.string.sim_combination_warning_notification_title))
                        .setContentText(dualCdmaSimWarningSummary)
                        .setStyle(new Notification.BigTextStyle().bigText(
                                dualCdmaSimWarningSummary))
                        .setAutoCancel(true);

        // Create the pending intent that will lead to the helper page.
        Intent resultIntent = HelpUtils.getHelpIntent(
                context,
                context.getString(R.string.help_uri_sim_combination_warning),
                context.getClass().getName());
        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        builder.setContentIntent(resultPendingIntent);

        NotificationManager notificationManager =
                context.getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(notificationChannel);
        notificationManager.notify(SIM_WARNING_NOTIFICATION_ID, builder.build());
    }

    public static void cancelSimCombinationWarningNotification(Context context) {
        NotificationManager notificationManager =
                context.getSystemService(NotificationManager.class);
        notificationManager.cancel(SIM_WARNING_NOTIFICATION_ID);
    }
}
+62 −4
Original line number Diff line number Diff line
@@ -21,10 +21,15 @@ import static android.provider.Settings.ENABLE_MMS_DATA_REQUEST_REASON_INCOMING_
import static android.provider.Settings.ENABLE_MMS_DATA_REQUEST_REASON_OUTGOING_MMS;
import static android.provider.Settings.EXTRA_ENABLE_MMS_DATA_REQUEST_REASON;
import static android.provider.Settings.EXTRA_SUB_ID;
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_NAMES;
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE;
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA;
import static android.telephony.data.ApnSetting.TYPE_MMS;

import static com.android.settings.sim.SimSelectNotification.ENABLE_MMS_NOTIFICATION_CHANNEL;
import static com.android.settings.sim.SimSelectNotification.ENABLE_MMS_NOTIFICATION_ID;
import static com.android.settings.sim.SimSelectNotification.SIM_WARNING_NOTIFICATION_CHANNEL;
import static com.android.settings.sim.SimSelectNotification.SIM_WARNING_NOTIFICATION_ID;

import static com.google.common.truth.Truth.assertThat;

@@ -76,10 +81,16 @@ public class SimSelectNotificationTest {
    @Mock
    private Resources mResources;

    private String mFakeOperatorName = "fake_operator_name";
    private CharSequence mFakeNotificationChannelTitle = "fake_notification_channel_title";
    private CharSequence mFakeNotificationTitle = "fake_notification_title";
    private String mFakeNotificationSummary = "fake_notification_Summary";
    private final String mFakeOperatorName = "fake_operator_name";
    private final CharSequence mFakeNotificationChannelTitle = "fake_notification_channel_title";
    private final CharSequence mFakeNotificationTitle = "fake_notification_title";
    private final String mFakeNotificationSummary = "fake_notification_Summary";

    // Dual CDMA combination notification.
    private final String mFakeDualCdmaWarningChannelTitle = "fake_dual_cdma_warning_channel_title";
    private final String mFakeDualCdmaWarningTitle = "fake_dual_cdma_warning_title";
    private final String mFakeDualCdmaWarningSummary = "fake_dual_cdma_warning_summary";
    private final String mSimCombinationName = " carrier1 & carrier 2";

    private int mSubId = 1;

@@ -90,6 +101,8 @@ public class SimSelectNotificationTest {
        MockitoAnnotations.initMocks(this);
        when(mContext.getSystemService(Context.NOTIFICATION_SERVICE))
                .thenReturn(mNotificationManager);
        when(mContext.getSystemService(NotificationManager.class))
                .thenReturn(mNotificationManager);
        when(mContext.getSystemService(Context.TELEPHONY_SERVICE))
                .thenReturn(mTelephonyManager);
        when(mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE))
@@ -111,6 +124,13 @@ public class SimSelectNotificationTest {
                .thenReturn(mFakeNotificationChannelTitle);
        when(mResources.getString(R.string.enable_mms_notification_summary,
                mFakeOperatorName)).thenReturn(mFakeNotificationSummary);

        when(mResources.getText(R.string.dual_cdma_sim_warning_notification_channel_title))
                .thenReturn(mFakeDualCdmaWarningChannelTitle);
        when(mResources.getText(R.string.sim_combination_warning_notification_title))
                .thenReturn(mFakeDualCdmaWarningTitle);
        when(mResources.getString(R.string.dual_cdma_sim_warning_notification_summary,
                mSimCombinationName)).thenReturn(mFakeDualCdmaWarningSummary);
    }

    @Test
@@ -162,5 +182,43 @@ public class SimSelectNotificationTest {
        mSimSelectNotification.onReceive(mContext, intent);
        verify(mNotificationManager, never()).createNotificationChannel(any());
    }

    @Test
    public void onReceivePrimarySubListChange_NoExtra_notificationShouldNotSend() {
        Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);

        // EXTRA_SUB_ID and EXTRA_ENABLE_MMS_DATA_REQUEST_REASON are required.
        mSimSelectNotification.onReceive(mContext, intent);
        verify(mNotificationManager, never()).createNotificationChannel(any());
    }

    @Test
    public void onReceivePrimarySubListChange_DualCdmaWarning_notificationShouldSend() {
        Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);

        intent.putExtra(EXTRA_SIM_COMBINATION_NAMES, mSimCombinationName);
        intent.putExtra(EXTRA_SIM_COMBINATION_WARNING_TYPE,
                EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA);

        mSimSelectNotification.onReceive(mContext, intent);

        // Capture the notification channel created and verify its fields.
        ArgumentCaptor<NotificationChannel> nc = ArgumentCaptor.forClass(NotificationChannel.class);
        verify(mNotificationManager).createNotificationChannel(nc.capture());

        assertThat(nc.getValue().getId()).isEqualTo(SIM_WARNING_NOTIFICATION_CHANNEL);
        assertThat(nc.getValue().getName()).isEqualTo(mFakeDualCdmaWarningChannelTitle);
        assertThat(nc.getValue().getImportance()).isEqualTo(IMPORTANCE_HIGH);

        // Capture the notification it notifies and verify its fields.
        ArgumentCaptor<Notification> notification = ArgumentCaptor.forClass(Notification.class);
        verify(mNotificationManager).notify(
                eq(SIM_WARNING_NOTIFICATION_ID), notification.capture());
        assertThat(notification.getValue().extras.getCharSequence(Notification.EXTRA_TITLE))
                .isEqualTo(mFakeDualCdmaWarningTitle);
        assertThat(notification.getValue().extras.getCharSequence(Notification.EXTRA_BIG_TEXT))
                .isEqualTo(mFakeDualCdmaWarningSummary);
        assertThat(notification.getValue().contentIntent).isNotNull();
    }
}