diff options
| -rw-r--r-- | services/core/java/com/android/server/notification/NotificationManagerService.java | 22 | ||||
| -rw-r--r-- | services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java | 16 |
2 files changed, 33 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index e2cb75e96882..85a8d938d693 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -5258,22 +5258,25 @@ public class NotificationManagerService extends SystemService { } if (DBG) Slog.v(TAG, "Interrupting!"); if (hasValidSound) { - mSoundNotificationKey = key; if (mInCall) { playInCallNotification(); beep = true; } else { beep = playSound(record, soundUri); } + if(beep) { + mSoundNotificationKey = key; + } } final boolean ringerModeSilent = mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT; if (!mInCall && hasValidVibrate && !ringerModeSilent) { - mVibrateNotificationKey = key; - buzz = playVibration(record, vibration, hasValidSound); + if(buzz) { + mVibrateNotificationKey = key; + } } } else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) { hasValidSound = false; @@ -5454,8 +5457,17 @@ public class NotificationManagerService extends SystemService { try { Thread.sleep(waitMs); } catch (InterruptedException e) { } - mVibrator.vibrate(record.sbn.getUid(), record.sbn.getPackageName(), - effect, "Notification (delayed)", 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, "Notification (delayed)", record.getAudioAttributes()); + } else { + Slog.e(TAG, "No vibration for canceled notification : " + record.getKey()); + } + } }).start(); } else { mVibrator.vibrate(record.sbn.getUid(), record.sbn.getPackageName(), diff --git a/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java b/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java index afbe6bc21d0d..9d847514435e 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java @@ -1015,6 +1015,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); |