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

Commit d0c5462c authored by David van Tonder's avatar David van Tonder Committed by Gerrit Code Review
Browse files

Merge "Restore correct volumes when headset is plugged" into jellybean

parents 7b8002a7 87eefecf
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)) {