summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Reynolds <juliacr@google.com> 2019-01-03 17:24:10 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-01-03 17:24:10 +0000
commit478fac748539df78e6c714c39c8c9dd225e78049 (patch)
tree2d0eea21acc90e730c75f013d20c50839f736929
parentf15c48160431e4b55a0d08cfe8d5e06b74cac1c2 (diff)
parentde93388430b25225033dbe7dc8f5d02a8c1307e5 (diff)
Merge changes Ia21f45c1,I208797f3
* changes: Check if notification is valid before it finally vibrates because it can be canceled as soon as enqeued Update sound/vibrate notification key only when it actually buzz/beep.
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java22
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java16
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);