OSDN Git Service

Check if notification is valid before it finally vibrates because it can be canceled...
authorSeungho Lee <shiny.lee@samsung.com>
Wed, 31 Oct 2018 12:49:09 +0000 (21:49 +0900)
committerJulia Reynolds <juliacr@google.com>
Fri, 21 Dec 2018 15:21:04 +0000 (15:21 +0000)
Test: Build and run StatusBarTest/_NotifyBuilder
Test: Set notification sound and vibration
Test: Make notification with + button, and cancel it with - button quickly
TEst: Check notification not vibrating

Change-Id: Ia21f45c165f863ed4143da3707b492c89e58387c
Merged-In: Ia21f45c165f863ed4143da3707b492c89e58387c
Signed-off-by: Seungho Lee <shiny.lee@samsung.com>
services/core/java/com/android/server/notification/NotificationManagerService.java
services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java

index 1284468..480f36e 100644 (file)
@@ -4992,8 +4992,17 @@ public class NotificationManagerService extends SystemService {
                     try {
                         Thread.sleep(waitMs);
                     } catch (InterruptedException e) { }
-                    mVibrator.vibrate(record.sbn.getUid(), record.sbn.getOpPkg(),
-                            effect, record.getAudioAttributes());
+
+                    // Notifications might be canceled before it actually vibrates due to waitMs,
+                    // so need to check the notification still valide for vibrate.
+                    synchronized (mNotificationLock) {
+                        if (mNotificationsByKey.get(record.getKey()) != null) {
+                            mVibrator.vibrate(record.sbn.getUid(), record.sbn.getOpPkg(),
+                                    effect, record.getAudioAttributes());
+                        } else {
+                            Slog.e(TAG, "No vibration for canceled notification : " + record.getKey());
+                        }
+                    }
                 }).start();
             } else {
                 mVibrator.vibrate(record.sbn.getUid(), record.sbn.getOpPkg(),
index bdba3d5..99d2b87 100644 (file)
@@ -918,6 +918,22 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase {
     }
 
     @Test
+    public void testCanceledNoisyNeverVibrate() throws Exception {
+        NotificationRecord r = getBuzzyBeepyNotification();
+
+        final int waitMs = mAudioManager.getFocusRampTimeMs(
+                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK,
+                r.getAudioAttributes());
+
+        mService.buzzBeepBlinkLocked(r);
+        mService.clearNotifications();
+
+        verifyNeverVibrate();
+        Thread.sleep(waitMs);
+        verifyNeverVibrate();
+    }
+    
+    @Test
     public void testEmptyUriSoundTreatedAsNoSound() throws Exception {
         NotificationChannel channel = new NotificationChannel("test", "test", IMPORTANCE_HIGH);
         channel.setSound(Uri.EMPTY, null);