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

Commit fe493727 authored by Vlad Popa's avatar Vlad Popa
Browse files

Fix the contextual volume when the assistant is active

Test: manual
Bug: 416329698
Flag: EXEMPT bugfix
Change-Id: Ie987ac0748bacb6fcc26d9c512689d5affa4e3b9
parent a31fe061
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -4448,6 +4448,7 @@ public class AudioService extends IAudioService.Stub
        boolean registeredAsAbsoluteVolume = false;
        boolean volumeHandled = false;
        int deviceType = ada.getInternalType();
        boolean isAbsoluteVolume = unifyAbsoluteVolumeManagement() ? isAbsoluteVolumeDevice(ada)
                : isAbsoluteVolumeDevice(deviceType);
        if (isAbsoluteVolume && (flags & AudioManager.FLAG_ABSOLUTE_VOLUME) == 0) {
@@ -4458,7 +4459,9 @@ public class AudioService extends IAudioService.Stub
                info = getAbsoluteVolumeDeviceInfo(deviceType);
            }
            if (info != null) {
                if (streamType == getBluetoothContextualVolumeStream()) {
                    dispatchAbsoluteVolumeChanged(streamType, info, newIndex, muted);
                }
                registeredAsAbsoluteVolume = true;
                volumeHandled = true;
            }
@@ -5295,12 +5298,17 @@ public class AudioService extends IAudioService.Stub
                break;
        }
        if (voiceActivityCanOverride && mVoicePlaybackActive.get()) {
        if (voiceActivityCanOverride && (mVoicePlaybackActive.get()
                || mAssistantPlaybackActive.get())) {
            // TODO(b/382704431): remove to allow STREAM_VOICE_CALL to drive abs volume over A2DP
            if (getDeviceForStream(AudioSystem.STREAM_VOICE_CALL)
                    == AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP) {
                return AudioSystem.STREAM_MUSIC;
            }
            if (mAssistantPlaybackActive.get() && !AudioSystem.DEVICE_OUT_ALL_SCO_SET.contains(
                    getDeviceForStream(AudioSystem.STREAM_ASSISTANT))) {
                return AudioSystem.STREAM_MUSIC;
            }
            return AudioSystem.STREAM_VOICE_CALL;
        }
        return AudioSystem.STREAM_MUSIC;
@@ -5308,6 +5316,7 @@ public class AudioService extends IAudioService.Stub
    private final AtomicBoolean mVoicePlaybackActive = new AtomicBoolean(false);
    private final AtomicBoolean mMediaPlaybackActive = new AtomicBoolean(false);
    private final AtomicBoolean mAssistantPlaybackActive = new AtomicBoolean(false);
    private final IPlaybackConfigDispatcher mPlaybackActivityMonitor =
            new IPlaybackConfigDispatcher.Stub() {
@@ -5323,6 +5332,7 @@ public class AudioService extends IAudioService.Stub
    private void onPlaybackConfigChange(List<AudioPlaybackConfiguration> configs) {
        boolean voiceActive = false;
        boolean mediaActive = false;
        boolean assistantActive = false;
        for (AudioPlaybackConfiguration config : configs) {
            final int usage = config.getAudioAttributes().getUsage();
            if (!config.isActive()) {
@@ -5336,8 +5346,18 @@ public class AudioService extends IAudioService.Stub
                    || usage == AudioAttributes.USAGE_UNKNOWN) {
                mediaActive = true;
            }
            if (usage == AudioAttributes.USAGE_ASSISTANT) {
                assistantActive = true;
            }
        }
        boolean updateContextualVolumes = false;
        if (mVoicePlaybackActive.getAndSet(voiceActive) != voiceActive) {
            updateContextualVolumes = true;
        }
        if (mAssistantPlaybackActive.getAndSet(assistantActive) != assistantActive) {
            updateContextualVolumes = true;
        }
        if (updateContextualVolumes) {
            postUpdateContextualVolumes();
        }
        if (mMediaPlaybackActive.getAndSet(mediaActive) != mediaActive && mediaActive) {
@@ -5625,7 +5645,8 @@ public class AudioService extends IAudioService.Stub
        }
        sVolumeLogger.enqueue(new VolumeEvent(VolumeEvent.VOL_VOICE_ACTIVITY_CONTEXTUAL_VOLUME,
                mVoicePlaybackActive.get(), streamType, index, device.getInternalType()));
                mVoicePlaybackActive.get() | mAssistantPlaybackActive.get(), streamType, index,
                device.getInternalType()));
    }
    private void setStreamVolume(int streamType, int index, int flags,