OSDN Git Service

Ensure Notification re-post with setOnlyAlertOnce(true) silences sound.
authorTyler Gunn <tgunn@google.com>
Tue, 3 Jul 2018 19:38:49 +0000 (12:38 -0700)
committerTyler Gunn <tgunn@google.com>
Mon, 16 Jul 2018 20:58:21 +0000 (13:58 -0700)
Where a notification channel has an associated looping sound, it should
be possible to re-post the notification with setOnlyAlertOnce(true) to
cause the notification channel's sound to silence.

When re-posting the notification, this CL fixes an issue where
NotificationManagerService wouldn't call clearSoundLocked to stop playing
the sound, resulting in the notification continuing to playing the sound
associated with the notification channel.

Test: Manual testing, updated unit test
Bug: 110348674
Change-Id: I3ec26f0804bcf59f7356a2329b73ba8ed8f7ea51

services/core/java/com/android/server/notification/NotificationManagerService.java
services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java

index dcdc203..9b2deed 100644 (file)
@@ -4844,6 +4844,8 @@ public class NotificationManagerService extends SystemService {
 
                         buzz = playVibration(record, vibration, hasValidSound);
                     }
+                } else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) {
+                    hasValidSound = false;
                 }
             }
         }
index bdba3d5..dbba2b2 100644 (file)
@@ -195,6 +195,11 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase {
                 true /* noisy */, false /* buzzy*/, false /* lights */);
     }
 
+    private NotificationRecord getInsistentBeepyOnceNotification() {
+        return getNotificationRecord(mId, true /* insistent */, true /* once */,
+                true /* noisy */, false /* buzzy*/, false /* lights */);
+    }
+
     private NotificationRecord getInsistentBeepyLeanbackNotification() {
         return getLeanbackNotificationRecord(mId, true /* insistent */, false /* once */,
                 true /* noisy */, false /* buzzy*/, false /* lights */);
@@ -527,6 +532,24 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase {
         assertFalse(s.isInterruptive());
     }
 
+    /**
+     * Tests the case where the user re-posts a {@link Notification} with looping sound where
+     * {@link Notification.Builder#setOnlyAlertOnce(true)} has been called.  This should silence
+     * the sound associated with the notification.
+     * @throws Exception
+     */
+    @Test
+    public void testNoisyOnceUpdateDoesCancelAudio() throws Exception {
+        NotificationRecord r = getInsistentBeepyNotification();
+        NotificationRecord s = getInsistentBeepyOnceNotification();
+        s.isUpdate = true;
+
+        mService.buzzBeepBlinkLocked(r);
+        mService.buzzBeepBlinkLocked(s);
+
+        verifyStopAudio();
+    }
+
     @Test
     public void testQuietUpdateDoesNotCancelAudioFromOther() throws Exception {
         NotificationRecord r = getBeepyNotification();