Loading services/core/java/com/android/server/notification/NotificationManagerService.java +19 −0 Original line number Diff line number Diff line Loading @@ -1444,6 +1444,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; Loading Loading @@ -1595,6 +1600,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) { Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -7737,6 +7738,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(0, n.getBubbleMetadata().getFlags()); } @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() Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +19 −0 Original line number Diff line number Diff line Loading @@ -1444,6 +1444,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; Loading Loading @@ -1595,6 +1600,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) { Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -7737,6 +7738,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(0, n.getBubbleMetadata().getFlags()); } @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() Loading