Skip the notification when the userId is not main

Fix: 381585049
Test: atest SimSelectNotificationTest
Flag: EXEMPT bugfix

Change-Id: I9a08a1c28948051cbf5a316b8cc5c676f25ff8cc
This commit is contained in:
songferngwang
2024-12-03 10:12:02 +00:00
committed by SongFerng Wang
parent 0496fc2de5
commit 178befee5e
2 changed files with 24 additions and 0 deletions

View File

@@ -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;

View File

@@ -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);