diff options
2 files changed, 48 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index e03b423bf83e..1e86d0291edf 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1445,6 +1445,11 @@ public class NotificationManagerService extends SystemService { } if (flags != data.getFlags()) { + int changedFlags = data.getFlags() ^ flags; + if ((changedFlags & FLAG_SUPPRESS_NOTIFICATION) != 0) { + // Suppress notification flag changed, clear any effects + clearEffectsLocked(key); + } data.setFlags(flags); // Shouldn't alert again just because of a flag change. r.getNotification().flags |= FLAG_ONLY_ALERT_ONCE; @@ -1596,6 +1601,20 @@ public class NotificationManagerService extends SystemService { updateLightsLocked(); } + @GuardedBy("mNotificationLock") + private void clearEffectsLocked(String key) { + if (key.equals(mSoundNotificationKey)) { + clearSoundLocked(); + } + if (key.equals(mVibrateNotificationKey)) { + clearVibrateLocked(); + } + boolean removed = mLights.remove(key); + if (removed) { + updateLightsLocked(); + } + } + protected final BroadcastReceiver mLocaleChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 44ca9f432a46..40cda34f1272 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -150,6 +150,7 @@ import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Icon; import android.media.AudioManager; +import android.media.IRingtonePlayer; import android.media.session.MediaSession; import android.net.Uri; import android.os.Binder; @@ -7738,6 +7739,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test + public void testOnBubbleMetadataChangedToSuppressNotification_soundStopped() + throws RemoteException { + IRingtonePlayer mockPlayer = mock(IRingtonePlayer.class); + when(mAudioManager.getRingtonePlayer()).thenReturn(mockPlayer); + // Set up volume to be above 0 for the sound to actually play + when(mAudioManager.getStreamVolume(anyInt())).thenReturn(10); + + setUpPrefsForBubbles(PKG, mUid, + true /* global */, + BUBBLE_PREFERENCE_ALL /* app */, + true /* channel */); + + // Post a bubble notification + NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "tag"); + mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); + waitForIdle(); + + // Test: suppress notification via bubble metadata update + mService.mNotificationDelegate.onBubbleMetadataFlagChanged(nr.getKey(), + Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION); + waitForIdle(); + + // Check audio is stopped + verify(mockPlayer).stopAsync(); + } + + @Test public void testGrantInlineReplyUriPermission_recordExists() throws Exception { int userId = UserManager.isHeadlessSystemUserMode() ? UserHandle.getUserId(UID_HEADLESS) |