support notification channel for non owner users
Telephony only runs under perimary users, we wont create a separate
stack for managed users or other secondary users but we still want to
show notifications if for other users to avoid missing any important
event. Today we loop through all users and call notifyAsUser for all
non-managed users one by one. But this has the issue has we dont have
separate notification channels for each user. The solution is call
notifyAsUser with UserHandle.ALL. this methods guarantees 1.no
notification mismatch for different users 2. single notification for all
users.
Bug: 64875812
Test: Manual test on managed user account/guest account and owner
account
Change-Id: I4a24d2c229614c46d4eb324742e18f6bbbbd6a80
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index 8e1faa8..f3c9ad3 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -504,23 +504,13 @@
intent.setClassName("com.android.phone", "com.android.phone.CallFeaturesSetting");
SubscriptionInfoHelper.addExtrasToIntent(
intent, mSubscriptionManager.getActiveSubscriptionInfo(subId));
- PendingIntent contentIntent =
- PendingIntent.getActivity(mContext, subId /* requestCode */, intent, 0);
-
- List<UserInfo> users = mUserManager.getUsers(true);
- for (int i = 0; i < users.size(); i++) {
- final UserInfo user = users.get(i);
- if (user.isManagedProfile()) {
- continue;
- }
- UserHandle userHandle = user.getUserHandle();
- builder.setContentIntent(user.isAdmin() ? contentIntent : null);
- mNotificationManager.notifyAsUser(
- Integer.toString(subId) /* tag */,
- CALL_FORWARD_NOTIFICATION,
- builder.build(),
- userHandle);
- }
+ builder.setContentIntent(PendingIntent.getActivity(mContext, subId /* requestCode */,
+ intent, 0));
+ mNotificationManager.notifyAsUser(
+ Integer.toString(subId) /* tag */,
+ CALL_FORWARD_NOTIFICATION,
+ builder.build(),
+ UserHandle.ALL);
} else {
mNotificationManager.cancelAsUser(
Integer.toString(subId) /* tag */,
@@ -548,21 +538,12 @@
.setContentTitle(mContext.getText(R.string.roaming))
.setColor(mContext.getResources().getColor(R.color.dialer_theme_color))
.setContentText(contentText)
- .setChannel(NotificationChannelController.CHANNEL_ID_MOBILE_DATA_STATUS);
-
- List<UserInfo> users = mUserManager.getUsers(true);
- for (int i = 0; i < users.size(); i++) {
- final UserInfo user = users.get(i);
- if (user.isManagedProfile()) {
- continue;
- }
- UserHandle userHandle = user.getUserHandle();
- builder.setContentIntent(user.isAdmin() ? contentIntent : null);
- final Notification notif =
- new Notification.BigTextStyle(builder).bigText(contentText).build();
- mNotificationManager.notifyAsUser(
- null /* tag */, DATA_DISCONNECTED_ROAMING_NOTIFICATION, notif, userHandle);
- }
+ .setChannel(NotificationChannelController.CHANNEL_ID_MOBILE_DATA_STATUS)
+ .setContentIntent(contentIntent);
+ final Notification notif =
+ new Notification.BigTextStyle(builder).bigText(contentText).build();
+ mNotificationManager.notifyAsUser(
+ null /* tag */, DATA_DISCONNECTED_ROAMING_NOTIFICATION, notif, UserHandle.ALL);
}
/**
@@ -599,22 +580,12 @@
mContext.getString(R.string.mobile_network_settings_package),
mContext.getString(R.string.mobile_network_settings_class)));
intent.putExtra(GsmUmtsOptions.EXTRA_SUB_ID, subId);
- PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
-
- List<UserInfo> users = mUserManager.getUsers(true);
- for (int i = 0; i < users.size(); i++) {
- final UserInfo user = users.get(i);
- if (user.isManagedProfile()) {
- continue;
- }
- UserHandle userHandle = user.getUserHandle();
- builder.setContentIntent(user.isAdmin() ? contentIntent : null);
- mNotificationManager.notifyAsUser(
- null /* tag */,
- SELECTED_OPERATOR_FAIL_NOTIFICATION,
- builder.build(),
- userHandle);
- }
+ builder.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0));
+ mNotificationManager.notifyAsUser(
+ null /* tag */,
+ SELECTED_OPERATOR_FAIL_NOTIFICATION,
+ builder.build(),
+ UserHandle.ALL);
}
/**