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

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

Merge "AudioService: Restore volumes after boot and when a headset is plugged" into cm-10.1

parents 9e558b86 c1419e82
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -529,6 +529,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        intentFilter.addAction(Intent.ACTION_USER_BACKGROUND);
        intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
        intentFilter.addAction(Intent.ACTION_WIFI_DISPLAY_AUDIO);
        intentFilter.addAction(Intent.ACTION_HEADSET_PLUG);

        intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
        // Register a configuration change listener only if requested by system properties
@@ -3941,6 +3942,16 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                        }
                    }
                }
            } else if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
                state = intent.getIntExtra("state", 0);
                if (state == 1) {
                    // Headset plugged in
                    adjustCurrentStreamVolume();
                    // TODO: Cap volume at safe levels
                } else {
                    // Headset disconnected
                    adjustCurrentStreamVolume();
                }
            } else if (action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) ||
                           action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) {
                state = intent.getIntExtra("state", 0);
@@ -4031,6 +4042,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                        0,
                        null,
                        SAFE_VOLUME_CONFIGURE_TIMEOUT_MS);

                adjustCurrentStreamVolume();
            } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
                if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
                    // a package is being removed, not replaced
@@ -4084,6 +4097,20 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                }
            }
        }

        private void adjustCurrentStreamVolume() {
            VolumeStreamState streamState;
            int device;

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

    private void masterVolumeChanged(final int flags) {