From 3fe3e8195a1e47980eb071b4c24e6288d08f84c2 Mon Sep 17 00:00:00 2001 From: Beverly Date: Thu, 24 Oct 2019 13:35:03 -0400 Subject: [PATCH] Update equals and hashCode methods of NoMan.Policy Test: atest AudioManagerTest#testPriorityOnlyChannelsCanBypassDnd Fixes: 142643922 Change-Id: I15835f784ba73b40eccf92a0a430905d28647669 Merged-In: I15835f784ba73b40eccf92a0a430905d28647669 (cherry picked from commit 4f8b0224e12037f5c41200722d689e1c8e0d8e1e) --- .../java/android/app/NotificationManager.java | 6 +++--- .../android/server/audio/AudioService.java | 20 ++++++++++++------- .../notification/ZenModeConfigTest.java | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index dd39376f80caa..903dd493d1876 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -1638,7 +1638,7 @@ public class NotificationManager { @Override public int hashCode() { return Objects.hash(priorityCategories, priorityCallSenders, priorityMessageSenders, - suppressedVisualEffects); + suppressedVisualEffects, state); } @Override @@ -1650,10 +1650,10 @@ public class NotificationManager { && other.priorityCallSenders == priorityCallSenders && other.priorityMessageSenders == priorityMessageSenders && suppressedVisualEffectsEqual(suppressedVisualEffects, - other.suppressedVisualEffects); + other.suppressedVisualEffects) + && other.state == this.state; } - private boolean suppressedVisualEffectsEqual(int suppressedEffects, int otherSuppressedVisualEffects) { if (suppressedEffects == otherSuppressedVisualEffects) { diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 1f1e8a5b38686..48f08e3226e36 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -3911,8 +3911,7 @@ public class AudioService extends IAudioService.Stub final boolean muteSystem = (zenPolicy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM) == 0; final boolean muteNotificationAndRing = ZenModeConfig - .areAllPriorityOnlyNotificationZenSoundsMuted( - mNm.getConsolidatedNotificationPolicy()); + .areAllPriorityOnlyNotificationZenSoundsMuted(zenPolicy); return muteAlarms && isAlarm(streamType) || muteMedia && isMedia(streamType) || muteSystem && isSystem(streamType) @@ -3924,11 +3923,13 @@ public class AudioService extends IAudioService.Stub } /** - * DND total silence: media and alarms streams are tied to the muted ringer - * {@link ZenModeHelper.RingerModeDelegate#getRingerModeAffectedStreams(int)} - * DND alarms only: notification, ringer + system muted (by default tied to muted ringer mode) - * DND priority only: alarms, media, system streams can be muted separate from ringer based on - * zenPolicy (this method determines which streams) + * Notifications, ringer and system sounds are controlled by the ringer: + * {@link ZenModeHelper.RingerModeDelegate#getRingerModeAffectedStreams(int)} but can + * also be muted by DND based on the DND mode: + * DND total silence: media and alarms streams can be muted by DND + * DND alarms only: no streams additionally controlled by DND + * DND priority only: alarms, media, system, ringer and notification streams can be muted by + * DND. The current applied zenPolicy determines which streams will be muted by DND. * @return true if changed, else false */ private boolean updateZenModeAffectedStreams() { @@ -3949,6 +3950,11 @@ public class AudioService extends IAudioService.Stub & NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM) == 0) { zenModeAffectedStreams |= 1 << AudioManager.STREAM_SYSTEM; } + + if (ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted(zenPolicy)) { + zenModeAffectedStreams |= 1 << AudioManager.STREAM_NOTIFICATION; + zenModeAffectedStreams |= 1 << AudioManager.STREAM_RING; + } } if (mZenModeAffectedStreams != zenModeAffectedStreams) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java index dcab78ede2876..8cd6ef9c132fb 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java @@ -98,7 +98,7 @@ public class ZenModeConfigTest extends UiServiceTestCase { suppressedVisualEffects |= Policy.SUPPRESSED_EFFECT_AMBIENT; Policy expectedPolicy = new Policy(priorityCategories, priorityCallSenders, - priorityMessageSenders, suppressedVisualEffects); + priorityMessageSenders, suppressedVisualEffects, 0); assertEquals(expectedPolicy, config.toNotificationPolicy(zenPolicy)); }