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

Commit 87eefecf authored by maxwen's avatar maxwen
Browse files

Restore correct volumes when headset is plugged

The correct volume levels for <device>_speaker and
<device>_headset are not restored when a headset device
is plugged in or out
parent 9c4942e9
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -3548,9 +3548,16 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                    // Volume restore capping
                    final boolean capVolumeRestore = Settings.System.getInt(mContentResolver,
                            Settings.System.SAFE_HEADSET_VOLUME_RESTORE, 1) == 1;
                    if (capVolumeRestore) {

                    for (int stream = 0; stream < AudioSystem.getNumStreamTypes(); stream++) {
                        if (stream == mStreamVolumeAlias[stream]) {
                            VolumeStreamState streamState = mStreamStates[mStreamVolumeAlias[stream]];
                            device = getDeviceForStream(stream);
                            // apply stored value for device
                            streamState.applyDeviceVolume(device);

                            // now reduce volume if required
                            if (capVolumeRestore) {
                                final int volume = getStreamVolume(stream);
                                final int restoreCap = rescaleIndex(HEADSET_VOLUME_RESTORE_CAP,
                                        AudioSystem.STREAM_MUSIC, stream);
@@ -3566,6 +3573,16 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                    if (noDelayInATwoDP) {
                        setBluetoothA2dpOnInt(true);
                    }

                    // Restore volumes
                    for (int stream = 0; stream < AudioSystem.getNumStreamTypes(); stream++) {
                        if (stream == mStreamVolumeAlias[stream]) {
                            VolumeStreamState streamState = mStreamStates[mStreamVolumeAlias[stream]];
                            device = getDeviceForStream(stream);
                            // apply stored value for device
                            streamState.applyDeviceVolume(device);
                        }
                    }
                }
            } else if (action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) ||
                           action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) {