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

Commit ac534e40 authored by Vlad Popa's avatar Vlad Popa Committed by Android (Google) Code Review
Browse files

Merge "Fix the contextual volume when the assistant is active" into main

parents f2f7fd6a fe493727
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -4452,6 +4452,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) {
@@ -4462,7 +4463,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;
            }
@@ -5299,12 +5302,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;
@@ -5312,6 +5320,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() {
@@ -5327,6 +5336,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()) {
@@ -5340,8 +5350,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) {
@@ -5629,7 +5649,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,