Merge "Rename getNotificationChannelsBypassingDnd argument to uid" into tm-dev

This commit is contained in:
Yuri Lin
2022-03-07 22:10:52 +00:00
committed by Android (Google) Code Review
4 changed files with 24 additions and 25 deletions

View File

@@ -116,7 +116,7 @@ interface INotificationManager
ParceledListSlice getNotificationChannelGroups(String pkg);
boolean onlyHasDefaultChannel(String pkg, int uid);
boolean areChannelsBypassingDnd();
ParceledListSlice getNotificationChannelsBypassingDnd(String pkg, int userId);
ParceledListSlice getNotificationChannelsBypassingDnd(String pkg, int uid);
boolean isPackagePaused(String pkg);
void deleteNotificationHistoryItem(String pkg, int uid, long postedTime);
boolean isPermissionFixed(String pkg, int userId);

View File

@@ -4060,13 +4060,12 @@ public class NotificationManagerService extends SystemService {
@Override
public ParceledListSlice<NotificationChannel> getNotificationChannelsBypassingDnd(
String pkg, int userId) {
String pkg, int uid) {
checkCallerIsSystem();
if (!areNotificationsEnabledForPackage(pkg,
mPackageManagerInternal.getPackageUid(pkg, 0, userId))) {
if (!areNotificationsEnabledForPackage(pkg, uid)) {
return ParceledListSlice.emptyList();
}
return mPreferencesHelper.getNotificationChannelsBypassingDnd(pkg, userId);
return mPreferencesHelper.getNotificationChannelsBypassingDnd(pkg, uid);
}
@Override

View File

@@ -1669,14 +1669,14 @@ public class PreferencesHelper implements RankingConfig {
}
/**
* Gets all notification channels associated with the given pkg and userId that can bypass dnd
* Gets all notification channels associated with the given pkg and uid that can bypass dnd
*/
public ParceledListSlice<NotificationChannel> getNotificationChannelsBypassingDnd(String pkg,
int userId) {
int uid) {
List<NotificationChannel> channels = new ArrayList<>();
synchronized (mPackagePreferences) {
final PackagePreferences r = mPackagePreferences.get(
packagePreferencesKey(pkg, userId));
packagePreferencesKey(pkg, uid));
if (r != null) {
for (NotificationChannel channel : r.channels.values()) {
if (channelIsLiveLocked(r, channel) && channel.canBypassDnd()) {

View File

@@ -1870,46 +1870,46 @@ public class PreferencesHelperTest extends UiServiceTestCase {
@Test
public void testGetChannelsBypassingDndCount_noChannelsBypassing() throws Exception {
assertEquals(0, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1,
USER.getIdentifier()).getList().size());
UID_N_MR1).getList().size());
}
@Test
public void testGetChannelsBypassingDnd_noChannelsForUserIdBypassing()
public void testGetChannelsBypassingDnd_noChannelsForUidBypassing()
throws Exception {
int user = 9;
int uid = 222;
NotificationChannel channel = new NotificationChannel("id", "name",
NotificationManager.IMPORTANCE_MAX);
channel.setBypassDnd(true);
mHelper.createNotificationChannel(PKG_N_MR1, 111, channel, true, true);
assertEquals(0, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1,
user).getList().size());
uid).getList().size());
}
@Test
public void testGetChannelsBypassingDndCount_oneChannelBypassing_groupBlocked() {
int user = USER.getIdentifier();
int uid = UID_N_MR1;
NotificationChannelGroup ncg = new NotificationChannelGroup("group1", "name1");
NotificationChannel channel1 = new NotificationChannel("id1", "name1",
NotificationManager.IMPORTANCE_MAX);
channel1.setBypassDnd(true);
channel1.setGroup(ncg.getId());
mHelper.createNotificationChannelGroup(PKG_N_MR1, user, ncg, /* fromTargetApp */ true);
mHelper.createNotificationChannel(PKG_N_MR1, user, channel1, true, /*has DND access*/ true);
mHelper.createNotificationChannelGroup(PKG_N_MR1, uid, ncg, /* fromTargetApp */ true);
mHelper.createNotificationChannel(PKG_N_MR1, uid, channel1, true, /*has DND access*/ true);
assertEquals(1, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1,
user).getList().size());
uid).getList().size());
// disable group
ncg.setBlocked(true);
mHelper.createNotificationChannelGroup(PKG_N_MR1, user, ncg, /* fromTargetApp */ false);
mHelper.createNotificationChannelGroup(PKG_N_MR1, uid, ncg, /* fromTargetApp */ false);
assertEquals(0, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1,
user).getList().size());
uid).getList().size());
}
@Test
public void testGetChannelsBypassingDndCount_multipleChannelsBypassing() {
int user = USER.getIdentifier();
int uid = UID_N_MR1;
NotificationChannel channel1 = new NotificationChannel("id1", "name1",
NotificationManager.IMPORTANCE_MAX);
NotificationChannel channel2 = new NotificationChannel("id2", "name2",
@@ -1920,22 +1920,22 @@ public class PreferencesHelperTest extends UiServiceTestCase {
channel2.setBypassDnd(true);
channel3.setBypassDnd(true);
// has DND access, so can set bypassDnd attribute
mHelper.createNotificationChannel(PKG_N_MR1, user, channel1, true, /*has DND access*/ true);
mHelper.createNotificationChannel(PKG_N_MR1, user, channel2, true, true);
mHelper.createNotificationChannel(PKG_N_MR1, user, channel3, true, true);
mHelper.createNotificationChannel(PKG_N_MR1, uid, channel1, true, /*has DND access*/ true);
mHelper.createNotificationChannel(PKG_N_MR1, uid, channel2, true, true);
mHelper.createNotificationChannel(PKG_N_MR1, uid, channel3, true, true);
assertEquals(3, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1,
user).getList().size());
uid).getList().size());
// setBypassDnd false for some channels
channel1.setBypassDnd(false);
channel2.setBypassDnd(false);
assertEquals(1, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1,
user).getList().size());
uid).getList().size());
// setBypassDnd false for rest of the channels
channel3.setBypassDnd(false);
assertEquals(0, mHelper.getNotificationChannelsBypassingDnd(PKG_N_MR1,
user).getList().size());
uid).getList().size());
}
@Test