Skip to content

Commit

Permalink
Don't convert all sounds to vibrations in vibrate mode
Browse files Browse the repository at this point in the history
Only those that are on the notification/ringer stream.

Change-Id: Id99c613a6de42ac8ed1d674b4c6e05067d9cf52c
Fixes: 65815310
Test: runtest systemui-notification
  • Loading branch information
Julia Reynolds committed Sep 22, 2017
1 parent d3293ab commit 8589657
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3996,19 +3996,19 @@ void buzzBeepBlinkLocked(NotificationRecord record) {
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) {
Expand Down Expand Up @@ -4105,8 +4105,9 @@ private boolean playSound(final NotificationRecord record, Uri soundUri) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ public void testNoDemoteSoundToVibrateIfVibrateGiven() throws Exception {

// the phone is quiet
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0);

mService.buzzBeepBlinkLocked(r);

Expand All @@ -567,6 +568,22 @@ public void testNoDemoteSoundToVibrateIfVibrateGiven() throws Exception {
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();
Expand All @@ -575,6 +592,7 @@ public void testDemoteSoundToVibrate() throws Exception {

// the phone is quiet
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0);

mService.buzzBeepBlinkLocked(r);

Expand Down

0 comments on commit 8589657

Please sign in to comment.