Loading services/core/java/com/android/server/notification/NotificationManagerService.java +6 −5 Original line number Diff line number Diff line Loading @@ -4019,19 +4019,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) { Loading Loading @@ -4128,8 +4128,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(); Loading services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -567,6 +568,22 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { eq(effect), (AudioAttributes) anyObject()); } @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(); Loading @@ -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); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +6 −5 Original line number Diff line number Diff line Loading @@ -4019,19 +4019,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) { Loading Loading @@ -4128,8 +4128,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(); Loading
services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -567,6 +568,22 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { eq(effect), (AudioAttributes) anyObject()); } @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(); Loading @@ -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); Loading