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(),
}
@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);