From: Julia Reynolds Date: Wed, 20 Sep 2017 16:54:52 +0000 (-0400) Subject: Don't convert all sounds to vibrations in vibrate mode X-Git-Tag: android-x86-8.1-r1~67^2~6^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=85896573a8916331e8b204fc98a6ed13860175b1;p=android-x86%2Fframeworks-base.git Don't convert all sounds to vibrations in vibrate mode Only those that are on the notification/ringer stream. Change-Id: Id99c613a6de42ac8ed1d674b4c6e05067d9cf52c Fixes: 65815310 Test: runtest systemui-notification --- diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 92b360bdf8f7..994519a9aea4 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3996,19 +3996,19 @@ public class NotificationManagerService extends SystemService { if (mSystemReady && mAudioManager != null) { Uri soundUri = record.getSound(); hasValidSound = soundUri != null && !Uri.EMPTY.equals(soundUri); - long[] vibration = record.getVibration(); // Demote sound to vibration if vibration missing & phone in vibration mode. if (vibration == null && hasValidSound && (mAudioManager.getRingerModeInternal() - == AudioManager.RINGER_MODE_VIBRATE)) { + == AudioManager.RINGER_MODE_VIBRATE) + && mAudioManager.getStreamVolume( + AudioAttributes.toLegacyStreamType(record.getAudioAttributes())) == 0) { vibration = mFallbackVibrationPattern; } hasValidVibrate = vibration != null; boolean hasAudibleAlert = hasValidSound || hasValidVibrate; - if (hasAudibleAlert && !shouldMuteNotificationLocked(record)) { if (DBG) Slog.v(TAG, "Interrupting!"); if (hasValidSound) { @@ -4105,8 +4105,9 @@ public class NotificationManagerService extends SystemService { boolean looping = (record.getNotification().flags & Notification.FLAG_INSISTENT) != 0; // do not play notifications if there is a user of exclusive audio focus // or the device is in vibrate mode - if (!mAudioManager.isAudioFocusExclusive() && mAudioManager.getRingerModeInternal() - != AudioManager.RINGER_MODE_VIBRATE) { + if (!mAudioManager.isAudioFocusExclusive() && (mAudioManager.getRingerModeInternal() + != AudioManager.RINGER_MODE_VIBRATE || mAudioManager.getStreamVolume( + AudioAttributes.toLegacyStreamType(record.getAudioAttributes())) != 0)) { final long identity = Binder.clearCallingIdentity(); try { final IRingtonePlayer player = mAudioManager.getRingtonePlayer(); diff --git a/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java b/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java index 529ac3a192ae..9fa1d68b8628 100644 --- a/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java +++ b/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java @@ -558,6 +558,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { // the phone is quiet when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); + when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0); mService.buzzBeepBlinkLocked(r); @@ -568,6 +569,22 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { } @Test + public void testNoDemoteSoundToVibrateIfNonNotificationStream() throws Exception { + NotificationRecord r = getBeepyNotification(); + assertTrue(r.getSound() != null); + assertNull(r.getVibration()); + + // the phone is quiet + when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); + when(mAudioManager.getStreamVolume(anyInt())).thenReturn(1); + + mService.buzzBeepBlinkLocked(r); + + verifyNeverVibrate(); + verifyBeepLooped(); + } + + @Test public void testDemoteSoundToVibrate() throws Exception { NotificationRecord r = getBeepyNotification(); assertTrue(r.getSound() != null); @@ -575,6 +592,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { // the phone is quiet when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); + when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0); mService.buzzBeepBlinkLocked(r);