Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ad88ff9 authored by Vlad Popa's avatar Vlad Popa
Browse files

Switch the order of calls in setStreamVolume

The setStreamVolume implementation has a different order of execution
than adjustStreamVolume. The postSetLeVolume is called first followed by
setting the index on the VSS and lastly the mute state is adjusted. This
could lead to a race condition when the LeService is checking the mute
state of the stream that is changing volume.

Adjusted the order of calls in setStreamVolume to match the one in
adjusStreamVolume. The calls into the BT stack are called after the
index and mute state is adjusted.

Test: adb shell device_config put media_audio
com.android.media.audio.volume_refactoring true
Test: manual & atest AudioManagerTests
Bug: 329202581

Change-Id: I66e2a9f390725a0cafca779436e507f5321a0ece
parent 202ac2fe
Loading
Loading
Loading
Loading
+45 −16
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility.PACK
import static com.android.media.audio.Flags.alarmMinVolumeZero;
import static com.android.media.audio.Flags.disablePrescaleAbsoluteVolume;
import static com.android.media.audio.Flags.ringerModeAffectsAlarm;
import static com.android.media.audio.Flags.setStreamVolumeOrder;
import static com.android.server.audio.SoundDoseHelper.ACTION_CHECK_MUSIC_ACTIVE;
import static com.android.server.utils.EventLogger.Event.ALOGE;
import static com.android.server.utils.EventLogger.Event.ALOGI;
@@ -4538,6 +4539,8 @@ public class AudioService extends IAudioService.Stub
                + focusFreezeTestApi());
        pw.println("\tcom.android.media.audio.disablePrescaleAbsoluteVolume:"
                + disablePrescaleAbsoluteVolume());
        pw.println("\tcom.android.media.audio.setStreamVolumeOrder:"
                + setStreamVolumeOrder());
        pw.println("\tandroid.media.audio.foregroundAudioControl:"
                + foregroundAudioControl());
    }
@@ -4705,6 +4708,30 @@ public class AudioService extends IAudioService.Stub
        index = rescaleIndex(index * 10, streamType, streamTypeAlias);
        if (setStreamVolumeOrder()) {
            flags &= ~AudioManager.FLAG_FIXED_VOLUME;
            if (streamTypeAlias == AudioSystem.STREAM_MUSIC && isFixedVolumeDevice(device)) {
                flags |= AudioManager.FLAG_FIXED_VOLUME;
                // volume is either 0 or max allowed for fixed volume devices
                if (index != 0) {
                    index = mSoundDoseHelper.getSafeMediaVolumeIndex(device);
                    if (index < 0) {
                        index = streamState.getMaxIndex();
                    }
                }
            }
            if (!mSoundDoseHelper.willDisplayWarningAfterCheckVolume(streamType, index, device,
                    flags)) {
                onSetStreamVolume(streamType, index, flags, device, caller, hasModifyAudioSettings,
                        // ada is non-null when called from setDeviceVolume,
                        // which shouldn't update the mute state
                        canChangeMuteAndUpdateController /*canChangeMute*/);
                index = mStreamStates[streamType].getIndex(device);
            }
        }
        if (streamTypeAlias == AudioSystem.STREAM_MUSIC
                && AudioSystem.DEVICE_OUT_ALL_A2DP_SET.contains(device)
                && (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
@@ -4738,6 +4765,7 @@ public class AudioService extends IAudioService.Stub
            mDeviceBroker.postSetHearingAidVolumeIndex(index, streamType);
        }
        if (!setStreamVolumeOrder()) {
            flags &= ~AudioManager.FLAG_FIXED_VOLUME;
            if (streamTypeAlias == AudioSystem.STREAM_MUSIC && isFixedVolumeDevice(device)) {
                flags |= AudioManager.FLAG_FIXED_VOLUME;
@@ -4759,6 +4787,7 @@ public class AudioService extends IAudioService.Stub
                        canChangeMuteAndUpdateController /*canChangeMute*/);
                index = mStreamStates[streamType].getIndex(device);
            }
        }
        synchronized (mHdmiClientLock) {
            if (streamTypeAlias == AudioSystem.STREAM_MUSIC