From 830817c3869c282af6620caa2139312349941bfa Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Wed, 1 Feb 2023 16:33:27 +0100 Subject: [PATCH] AudioService: fix muting of aliased volume streams When muting a stream, only mute the aliased stream if they can be muted. Bug: 266551079 Test: atest AudioManagerTest Test: atest AccessibilityVolumeTest Change-Id: I0c5376f746acb0d7c28c77442f2eeb9b53968841 --- .../com/android/server/audio/AudioService.java | 15 +++++++++++---- 1 file changed, 11 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 fa3a3bf851844..716ebd97e88c4 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -3507,11 +3507,12 @@ public class AudioService extends IAudioService.Stub synchronized (VolumeStreamState.class) { List streamsToMute = new ArrayList<>(); for (int stream = 0; stream < mStreamStates.length; stream++) { - if (streamAlias == mStreamVolumeAlias[stream]) { + VolumeStreamState vss = mStreamStates[stream]; + if (streamAlias == mStreamVolumeAlias[stream] && vss.isMutable()) { if (!(readCameraSoundForced() - && (mStreamStates[stream].getStreamType() + && (vss.getStreamType() == AudioSystem.STREAM_SYSTEM_ENFORCED))) { - boolean changed = mStreamStates[stream].mute(state, /* apply= */ false); + boolean changed = vss.mute(state, /* apply= */ false); if (changed) { streamsToMute.add(stream); } @@ -8384,7 +8385,7 @@ public class AudioService extends IAudioService.Stub } mVolumeGroupState.updateVolumeIndex(groupIndex, device); // Only propage mute of stream when applicable - if (mIndexMin == 0 || isCallStream(mStreamType)) { + if (isMutable()) { // For call stream, align mute only when muted, not when index is set to 0 mVolumeGroupState.mute(forceMuteState ? mIsMuted : groupIndex == 0); } @@ -8435,6 +8436,12 @@ public class AudioService extends IAudioService.Stub return mIsMuted || mIsMutedInternally; } + + private boolean isMutable() { + return isStreamAffectedByMute(mStreamType) + && (mIndexMin == 0 || isCallStream(mStreamType)); + } + /** * Mute/unmute the stream * @param state the new mute state