From b43455a1583795f86b5fdea19fc1ed0d0276f960 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Thu, 11 May 2023 22:57:13 -0700 Subject: [PATCH] AudioService: fix NOTIFICATION unmuted while in silent/vibrate mode Fix support of AudioManager.FLAG_ALLOW_RINGER_MODES which enables the change of ringer mode in response to the unmuting of a stream currently muted by the ringer mode. When this flag is not present, the unmuting of a muted stream is not allowed, and that call shouldn't change the ringer mode. This prevents entering situations where NOTIFICATION is unmuted but the ringer mode is VIBRATE or SILENT. Bug: 278661956 Test: atest CtsMediaAudioTestCases:android.media.audio.cts.AudioManagerTest#testAdjustUnmuteNotificationInSilent Test: atest CtsMediaAudioTestCases:android.media.audio.cts.AudioManagerTest#testAdjustUnmuteNotificationInVibrate Change-Id: Ib1306be48ba61a0294e12e3bf7ac74fb54a0bd6c --- .../com/android/server/audio/AudioService.java | 18 +++++++++++++++--- .../server/audio/AudioServiceEvents.java | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index a72187399acd9..808b6480204d8 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -3373,8 +3373,13 @@ public class AudioService extends IAudioService.Stub return; } - sVolumeLogger.enqueue(new VolumeEvent(VolumeEvent.VOL_ADJUST_STREAM_VOL, streamType, - direction/*val1*/, flags/*val2*/, callingPackage)); + final VolumeEvent evt = new VolumeEvent(VolumeEvent.VOL_ADJUST_STREAM_VOL, streamType, + direction/*val1*/, flags/*val2*/, callingPackage); + sVolumeLogger.enqueue(evt); + // also logging mute/unmute calls to the dedicated logger + if (isMuteAdjust(direction)) { + sMuteLogger.enqueue(evt); + } adjustStreamVolume(streamType, direction, flags, callingPackage, callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), attributionTag, callingHasAudioSettingsPermission(), AudioDeviceVolumeManager.ADJUST_MODE_NORMAL); @@ -3475,7 +3480,7 @@ public class AudioService extends IAudioService.Stub } // If either the client forces allowing ringer modes for this adjustment, - // or the stream type is one that is affected by ringer modes + // or stream is used for UI sonification if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) || (isUiSoundsStreamType(streamTypeAlias))) { int ringerMode = getRingerModeInternal(); @@ -3496,6 +3501,13 @@ public class AudioService extends IAudioService.Stub if ((result & AudioManager.FLAG_SHOW_VIBRATE_HINT) != 0) { flags |= AudioManager.FLAG_SHOW_VIBRATE_HINT; } + } else if (isStreamMutedByRingerOrZenMode(streamTypeAlias) && streamState.mIsMuted) { + // if the stream is currently muted streams by ringer/zen mode + // then it cannot be unmuted (without FLAG_ALLOW_RINGER_MODES) + if (direction == AudioManager.ADJUST_TOGGLE_MUTE + || direction == AudioManager.ADJUST_UNMUTE) { + adjustVolume = false; + } } // If the ringer mode or zen is muting the stream, do not change stream unless diff --git a/services/core/java/com/android/server/audio/AudioServiceEvents.java b/services/core/java/com/android/server/audio/AudioServiceEvents.java index 6ad9390ef3663..6ebb42e08ade0 100644 --- a/services/core/java/com/android/server/audio/AudioServiceEvents.java +++ b/services/core/java/com/android/server/audio/AudioServiceEvents.java @@ -609,7 +609,7 @@ public class AudioServiceEvents { (mStreamType <= AudioSystem.getNumStreamTypes() && mStreamType >= 0) ? AudioSystem.STREAM_NAMES[mStreamType] : ("stream " + mStreamType); - return new StringBuilder("Error trying to unmute ") + return new StringBuilder("Invalid call to unmute ") .append(streamName) .append(" despite muted streams 0x") .append(Integer.toHexString(mRingerZenMutedStreams))