Loading src/com/android/settings/sim/SimSelectNotification.java +6 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"; Loading @@ -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); Loading @@ -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); Loading Loading @@ -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); Loading Loading
src/com/android/settings/sim/SimSelectNotification.java +6 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading
tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"; Loading @@ -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); Loading @@ -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); Loading Loading @@ -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); Loading