From aebfc4e7a3e3b66382e9004d5ed141b50e26a71b Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Fri, 6 Jan 2017 11:44:03 -0500 Subject: [PATCH] Cannot have badge only channels Test: runtest systemui-notification & cts Change-Id: I256e35a79400c1d25b3d2f1c7c5f8c513242a2aa --- api/current.txt | 1 - api/system-current.txt | 1 - api/test-current.txt | 1 - .../java/android/app/NotificationChannel.java | 19 ----------------- .../NotificationManagerService.java | 6 +++--- .../server/notification/RankingHelper.java | 4 ---- .../NotificationManagerServiceTest.java | 2 +- .../notification/RankingHelperTest.java | 21 ------------------- 8 files changed, 4 insertions(+), 51 deletions(-) diff --git a/api/current.txt b/api/current.txt index b58947d36c0b3..b84626d6563cd 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5393,7 +5393,6 @@ package android.app { method public android.net.Uri getSound(); method public long[] getVibrationPattern(); method public boolean isAllowed(); - method public void setAllowed(boolean); method public void setBypassDnd(boolean); method public void setImportance(int); method public void setLights(boolean); diff --git a/api/system-current.txt b/api/system-current.txt index 7a0f24c3c9f92..7b41b3080980d 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -5555,7 +5555,6 @@ package android.app { method public boolean isAllowed(); method public void lockFields(int); method public void populateFromXml(org.xmlpull.v1.XmlPullParser); - method public void setAllowed(boolean); method public void setBypassDnd(boolean); method public void setImportance(int); method public void setLights(boolean); diff --git a/api/test-current.txt b/api/test-current.txt index 4118053af2f7b..c12cc74903da8 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -5403,7 +5403,6 @@ package android.app { method public android.net.Uri getSound(); method public long[] getVibrationPattern(); method public boolean isAllowed(); - method public void setAllowed(boolean); method public void setBypassDnd(boolean); method public void setImportance(int); method public void setLights(boolean); diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java index 6273917640692..bdccb8a9620c6 100644 --- a/core/java/android/app/NotificationChannel.java +++ b/core/java/android/app/NotificationChannel.java @@ -55,7 +55,6 @@ public final class NotificationChannel implements Parcelable { private static final String ATT_AUDIO_ATTRIBUTES = "audio_attributes"; private static final String ATT_SHOW_BADGE = "show_badge"; private static final String ATT_USER_LOCKED = "locked"; - private static final String ATT_ALLOWED = "allowed"; private static final String DELIMITER = ","; /** @@ -243,18 +242,6 @@ public final class NotificationChannel implements Parcelable { this.mImportance = importance; } - /** - * Sets whether notifications are allowed to be posted to this channel. - * - * Only modifiable by the system and notification ranker. - * - * @param allowed true if notifications are not allowed from this channel. - */ - public void setAllowed(boolean allowed) { - this.mAllowed = allowed; - } - - // Modifiable by apps on channel creation. /** @@ -406,7 +393,6 @@ public final class NotificationChannel implements Parcelable { enableVibration(safeBool(parser, ATT_VIBRATION_ENABLED, false)); setVibrationPattern(safeLongArray(parser, ATT_VIBRATION, null)); setShowBadge(safeBool(parser, ATT_SHOW_BADGE, false)); - setAllowed(safeBool(parser, ATT_ALLOWED, true)); lockFields(safeInt(parser, ATT_USER_LOCKED, 0)); } @@ -448,9 +434,6 @@ public final class NotificationChannel implements Parcelable { if (canShowBadge()) { out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(canShowBadge())); } - if (!isAllowed()) { - out.attribute(null, ATT_ALLOWED, Boolean.toString(isAllowed())); - } out.endTag(null, TAG_CHANNEL); } @@ -481,8 +464,6 @@ public final class NotificationChannel implements Parcelable { record.put(ATT_USER_LOCKED, Integer.toString(getUserLockedFields())); record.put(ATT_VIBRATION, longArrayToString(getVibrationPattern())); record.put(ATT_SHOW_BADGE, Boolean.toString(canShowBadge())); - record.put(ATT_ALLOWED, Boolean.toString(isAllowed())); - return record; } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 4d8e26f6955ba..dffe86ab47b4c 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1552,7 +1552,7 @@ public class NotificationManagerService extends SystemService { public void updateNotificationChannelForPackage(String pkg, int uid, NotificationChannel channel) { enforceSystemOrSystemUI("Caller not system or systemui"); - if (!channel.isAllowed()) { + if (channel.getImportance() == NotificationManager.IMPORTANCE_NONE) { // cancel cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channel.getId(), 0, 0, true, UserHandle.getUserId(Binder.getCallingUid()), REASON_CHANNEL_BANNED, @@ -2441,7 +2441,7 @@ public class NotificationManagerService extends SystemService { public void updateNotificationChannelFromAssistant(INotificationListener token, String pkg, NotificationChannel channel) throws RemoteException { ManagedServiceInfo info = mNotificationAssistants.checkServiceTokenLocked(token); - if (!channel.isAllowed()) { + if (channel.getImportance() == NotificationManager.IMPORTANCE_NONE) { // cancel cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channel.getId(), 0, 0, true, info.userid, REASON_CHANNEL_BANNED, null); @@ -2985,7 +2985,7 @@ public class NotificationManagerService extends SystemService { } final boolean isBlocked = r.getImportance() == NotificationManager.IMPORTANCE_NONE - || !r.getChannel().isAllowed() + || r.getChannel().getImportance() == NotificationManager.IMPORTANCE_NONE || !noteNotificationOp(pkg, callingUid); if (isBlocked) { Slog.e(TAG, "Suppressing notification from package by user request."); diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 0c9e4b82189ea..598ac2edf5b1c 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -445,7 +445,6 @@ public class RankingHelper implements RankingConfig { channel.setBypassDnd(r.priority == Notification.PRIORITY_MAX); channel.setLockscreenVisibility(r.visibility); } - channel.setAllowed(true); clearLockedFields(channel); if (channel.getLockscreenVisibility() == Notification.VISIBILITY_PUBLIC) { channel.setLockscreenVisibility(Ranking.VISIBILITY_NO_OVERRIDE); @@ -516,9 +515,6 @@ public class RankingHelper implements RankingConfig { channel.setLockscreenVisibility(updatedChannel.getLockscreenVisibility()); } } - if ((channel.getUserLockedFields() & NotificationChannel.USER_LOCKED_ALLOWED) == 0) { - channel.setAllowed(updatedChannel.isAllowed()); - } if ((channel.getUserLockedFields() & NotificationChannel.USER_LOCKED_SHOW_BADGE) == 0) { channel.setShowBadge(updatedChannel.canShowBadge()); } diff --git a/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java index e1c0166ee39bb..ef61ec242a4cb 100644 --- a/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -126,7 +126,7 @@ public class NotificationManagerServiceTest { NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_HIGH); - channel.setAllowed(false); + channel.setImportance(NotificationManager.IMPORTANCE_NONE); NotificationRecord r = generateNotificationRecord(channel); NotificationManagerService.EnqueueNotificationRunnable enqueue = mNotificationManagerService.new EnqueueNotificationRunnable(UserHandle.USER_SYSTEM, diff --git a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java index eb1021d9b6f3c..f8061f6feb009 100644 --- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java @@ -487,25 +487,6 @@ public class RankingHelperTest { assertEquals(channel, mHelper.getNotificationChannel(pkg, uid, channel.getId())); } - @Test - public void testUpdate_userLockedAllowed() throws Exception { - final NotificationChannel channel = - new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_LOW); - channel.setAllowed(true); - channel.lockFields(NotificationChannel.USER_LOCKED_ALLOWED); - - mHelper.createNotificationChannel(pkg, uid, channel, false); - - final NotificationChannel channel2 = - new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_HIGH); - channel2.setAllowed(false); - - mHelper.updateNotificationChannelFromAssistant(pkg, uid, channel2); - - // no fields should be changed - assertEquals(channel, mHelper.getNotificationChannel(pkg, uid, channel.getId())); - } - @Test public void testUpdate_userLockedBadge() throws Exception { final NotificationChannel channel = @@ -567,7 +548,6 @@ public class RankingHelperTest { channel.setBypassDnd(true); channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET); channel.setShowBadge(true); - channel.setAllowed(false); int lockMask = 0; for (int i = 0; i < NotificationChannel.LOCKABLE_FIELDS.length; i++) { lockMask |= NotificationChannel.LOCKABLE_FIELDS[i]; @@ -595,7 +575,6 @@ public class RankingHelperTest { channel.setBypassDnd(true); channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET); channel.setShowBadge(true); - channel.setAllowed(false); int lockMask = 0; for (int i = 0; i < NotificationChannel.LOCKABLE_FIELDS.length; i++) { lockMask |= NotificationChannel.LOCKABLE_FIELDS[i];