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

Commit 2efbc184 authored by Daniel Chapin's avatar Daniel Chapin
Browse files

Revert^2 "Revert "Fix mute issue when changing audio routes""

Reason for revert: SC blocking bug: 163642647

668745be

Change-Id: Id1ee584fdaf66a551e70c80a8779dd4c6bf693bb
parent 82b16fed
Loading
Loading
Loading
Loading
+19 −57
Original line number Original line Diff line number Diff line
@@ -1282,6 +1282,7 @@ public class AudioService extends IAudioService.Stub
            }
            }


            if (isPlatformTelevision()) {
            if (isPlatformTelevision()) {
                checkAddAllFixedVolumeDevices(AudioSystem.DEVICE_OUT_HDMI, caller);
                synchronized (mHdmiClientLock) {
                synchronized (mHdmiClientLock) {
                    if (mHdmiManager != null && mHdmiPlaybackClient != null) {
                    if (mHdmiManager != null && mHdmiPlaybackClient != null) {
                        updateHdmiCecSinkLocked(mHdmiCecSink | false);
                        updateHdmiCecSinkLocked(mHdmiCecSink | false);
@@ -1301,33 +1302,9 @@ public class AudioService extends IAudioService.Stub
        }
        }
    }
    }


    /**
    private void checkAddAllFixedVolumeDevices(int device, String caller) {
     * Update volume states for the given device.
     *
     * This will initialize the volume index if no volume index is available.
     * If the device is the currently routed device, fixed/full volume policies will be applied.
     *
     * @param device a single audio device, ensure that this is not a devices bitmask
     * @param caller caller of this method
     */
    private void updateVolumeStatesForAudioDevice(int device, String caller) {
        final int numStreamTypes = AudioSystem.getNumStreamTypes();
        final int numStreamTypes = AudioSystem.getNumStreamTypes();
        for (int streamType = 0; streamType < numStreamTypes; streamType++) {
        for (int streamType = 0; streamType < numStreamTypes; streamType++) {
            updateVolumeStates(device, streamType, caller);
        }
    }

    /**
     * Update volume states for the given device and given stream.
     *
     * This will initialize the volume index if no volume index is available.
     * If the device is the currently routed device, fixed/full volume policies will be applied.
     *
     * @param device a single audio device, ensure that this is not a devices bitmask
     * @param streamType streamType to be updated
     * @param caller caller of this method
     */
    private void updateVolumeStates(int device, int streamType, String caller) {
            if (!mStreamStates[streamType].hasIndexForDevice(device)) {
            if (!mStreamStates[streamType].hasIndexForDevice(device)) {
                // set the default value, if device is affected by a full/fix/abs volume rule, it
                // set the default value, if device is affected by a full/fix/abs volume rule, it
                // will taken into account in checkFixedVolumeDevices()
                // will taken into account in checkFixedVolumeDevices()
@@ -1336,22 +1313,14 @@ public class AudioService extends IAudioService.Stub
                                .getIndex(AudioSystem.DEVICE_OUT_DEFAULT),
                                .getIndex(AudioSystem.DEVICE_OUT_DEFAULT),
                        device, caller, true /*hasModifyAudioSettings*/);
                        device, caller, true /*hasModifyAudioSettings*/);
            }
            }

        // Check if device to be updated is routed for the given audio stream
        List<AudioDeviceAttributes> devicesForAttributes = getDevicesForAttributes(
                new AudioAttributes.Builder().setInternalLegacyStreamType(streamType).build());
        for (AudioDeviceAttributes deviceAttributes : devicesForAttributes) {
            if (deviceAttributes.getType() == AudioDeviceInfo.convertInternalDeviceToDeviceType(
                    device)) {
            mStreamStates[streamType].checkFixedVolumeDevices();
            mStreamStates[streamType].checkFixedVolumeDevices();


                // Unmute streams if required if device is full volume
            // Unmute streams if device is full volume
                if (isStreamMute(streamType) && mFullVolumeDevices.contains(device)) {
            if (mFullVolumeDevices.contains(device)) {
                mStreamStates[streamType].mute(false);
                mStreamStates[streamType].mute(false);
            }
            }
        }
        }
    }
    }
    }


    private void checkAllFixedVolumeDevices()
    private void checkAllFixedVolumeDevices()
    {
    {
@@ -4932,15 +4901,7 @@ public class AudioService extends IAudioService.Stub
        synchronized (VolumeStreamState.class) {
        synchronized (VolumeStreamState.class) {
            for (int stream = 0; stream < mStreamStates.length; stream++) {
            for (int stream = 0; stream < mStreamStates.length; stream++) {
                if (stream != skipStream) {
                if (stream != skipStream) {
                    int devices = mStreamStates[stream].observeDevicesForStream_syncVSS(
                    mStreamStates[stream].observeDevicesForStream_syncVSS(false /*checkOthers*/);
                            false /*checkOthers*/);

                    Set<Integer> devicesSet = AudioSystem.generateAudioDeviceTypesSet(devices);
                    for (Integer device : devicesSet) {
                        // Update volume states for devices routed for the stream
                        updateVolumeStates(device, stream,
                                "AudioService#observeDevicesForStreams");
                    }
                }
                }
            }
            }
        }
        }
@@ -5009,7 +4970,7 @@ public class AudioService extends IAudioService.Stub
                      + Integer.toHexString(audioSystemDeviceOut) + " from:" + caller));
                      + Integer.toHexString(audioSystemDeviceOut) + " from:" + caller));
        // make sure we have a volume entry for this device, and that volume is updated according
        // make sure we have a volume entry for this device, and that volume is updated according
        // to volume behavior
        // to volume behavior
        updateVolumeStatesForAudioDevice(audioSystemDeviceOut, "setDeviceVolumeBehavior:" + caller);
        checkAddAllFixedVolumeDevices(audioSystemDeviceOut, "setDeviceVolumeBehavior:" + caller);
    }
    }


    /**
    /**
@@ -7231,9 +7192,10 @@ public class AudioService extends IAudioService.Stub
                // HDMI output
                // HDMI output
                removeAudioSystemDeviceOutFromFullVolumeDevices(AudioSystem.DEVICE_OUT_HDMI);
                removeAudioSystemDeviceOutFromFullVolumeDevices(AudioSystem.DEVICE_OUT_HDMI);
            }
            }
            updateVolumeStatesForAudioDevice(AudioSystem.DEVICE_OUT_HDMI,
                    "HdmiPlaybackClient.DisplayStatusCallback");
        }
        }

        checkAddAllFixedVolumeDevices(AudioSystem.DEVICE_OUT_HDMI,
                "HdmiPlaybackClient.DisplayStatusCallback");
    }
    }


    private class MyHdmiControlStatusChangeListenerCallback
    private class MyHdmiControlStatusChangeListenerCallback