diff --git a/src/com/android/settings/sim/SimSelectNotification.java b/src/com/android/settings/sim/SimSelectNotification.java index 3d9d41cb6bf..44fd43f7d19 100644 --- a/src/com/android/settings/sim/SimSelectNotification.java +++ b/src/com/android/settings/sim/SimSelectNotification.java @@ -42,6 +42,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.res.Resources; +import android.os.UserManager; import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; @@ -91,6 +92,11 @@ public class SimSelectNotification extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + UserManager userManager = context.getSystemService(UserManager.class); + if (userManager != null && !userManager.isMainUser()) { + Log.d(TAG, "The userId is not the main user"); + return; + } if (!SubscriptionUtil.isSimHardwareVisible(context)) { Log.w(TAG, "Received unexpected intent with null action."); return; diff --git a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java index 36f6cd4058e..0171dc402f5 100644 --- a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java +++ b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java @@ -54,6 +54,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; +import android.os.UserManager; import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; @@ -103,6 +104,8 @@ public class SimSelectNotificationTest { private DisplayMetrics mDisplayMetrics; @Mock private SimDialogActivity mActivity; + @Mock + private UserManager mUserManager; private final String mFakeDisplayName = "fake_display_name"; private final CharSequence mFakeNotificationChannelTitle = "fake_notification_channel_title"; @@ -128,6 +131,8 @@ public class SimSelectNotificationTest { .thenReturn(mNotificationManager); when(mContext.getSystemService(Context.TELEPHONY_SERVICE)) .thenReturn(mTelephonyManager); + when(mContext.getSystemService(UserManager.class)) + .thenReturn(mUserManager); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); when(mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)) .thenReturn(mSubscriptionManager); @@ -135,6 +140,7 @@ public class SimSelectNotificationTest { when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mPackageManager.checkPermission(any(), any())) .thenReturn(PackageManager.PERMISSION_GRANTED); + when(mUserManager.isMainUser()).thenReturn(true); when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager); when(mTelephonyManager.isDataEnabledForApn(TYPE_MMS)).thenReturn(false); @@ -217,6 +223,18 @@ public class SimSelectNotificationTest { verify(mNotificationManager, never()).createNotificationChannel(any()); } + @Test + public void onReceivePrimarySubListChange_userIdIsNotMain_notificationShouldNotSend() { + when(mUserManager.isMainUser()).thenReturn(false); + Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED); + intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE, + EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA); + + // If MMS data is already enabled, there's no need to trigger the notification. + 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);