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

Commit ed43bf51 authored by Phil Burk's avatar Phil Burk
Browse files

AudioService: update device info when ENCODED_SURROUND_OUTPUT changed



Fixes a bug with the ContentObserver not being registered.
Added code to also toggle the HDMI connection to force a broadcast.

Bug: 27434478
Bug: 24541671
Change-Id: If1644f4d08991ee27e3b6e10d244a704c25b5fa9
Signed-off-by: default avatarPhil Burk <philburk@google.com>
parent f571c472
Loading
Loading
Loading
Loading
+38 −4
Original line number Diff line number Diff line
@@ -849,7 +849,7 @@ public class AudioService extends IAudioService.Stub {
            AudioSystem.setForceUse(AudioSystem.FOR_DOCK,
                    mDockAudioMediaEnabled ?
                            AudioSystem.FORCE_ANALOG_DOCK : AudioSystem.FORCE_NONE);
            readEncodedSurroundMode(mContentResolver);
            sendEncodedSurroundMode(mContentResolver);
        }
        if (mHdmiManager != null) {
            synchronized (mHdmiManager) {
@@ -1023,7 +1023,7 @@ public class AudioService extends IAudioService.Stub {
        AudioSystem.setMasterMono(masterMono);
    }

    private void readEncodedSurroundMode(ContentResolver cr)
    private void sendEncodedSurroundMode(ContentResolver cr)
    {
        int encodedSurroundMode = Settings.Global.getInt(
                cr, Settings.Global.ENCODED_SURROUND_OUTPUT,
@@ -1102,7 +1102,7 @@ public class AudioService extends IAudioService.Stub {

            updateRingerModeAffectedStreams();
            readDockAudioSettings(cr);
            readEncodedSurroundMode(cr);
            sendEncodedSurroundMode(cr);
        }

        mMuteAffectedStreams = System.getIntForUser(cr,
@@ -4642,6 +4642,8 @@ public class AudioService extends IAudioService.Stub {

    private class SettingsObserver extends ContentObserver {

        private int mEncodedSurroundMode;

        SettingsObserver() {
            super(new Handler());
            mContentResolver.registerContentObserver(Settings.System.getUriFor(
@@ -4650,6 +4652,12 @@ public class AudioService extends IAudioService.Stub {
                Settings.Global.DOCK_AUDIO_MEDIA_ENABLED), false, this);
            mContentResolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.MASTER_MONO), false, this);

            mEncodedSurroundMode = Settings.Global.getInt(
                    mContentResolver, Settings.Global.ENCODED_SURROUND_OUTPUT,
                    Settings.Global.ENCODED_SURROUND_OUTPUT_AUTO);
            mContentResolver.registerContentObserver(Settings.Global.getUriFor(
                    Settings.Global.ENCODED_SURROUND_OUTPUT), false, this);
        }

        @Override
@@ -4669,7 +4677,33 @@ public class AudioService extends IAudioService.Stub {
                }
                readDockAudioSettings(mContentResolver);
                updateMasterMono(mContentResolver);
                readEncodedSurroundMode(mContentResolver);
                updateEncodedSurroundOutput();
            }
        }

        private void updateEncodedSurroundOutput() {
            int newSurroundMode = Settings.Global.getInt(
                mContentResolver, Settings.Global.ENCODED_SURROUND_OUTPUT,
                Settings.Global.ENCODED_SURROUND_OUTPUT_AUTO);
            // Did it change?
            if (mEncodedSurroundMode != newSurroundMode) {
                // Send to AudioPolicyManager
                sendEncodedSurroundMode(newSurroundMode);
                synchronized(mConnectedDevices) {
                    // Is HDMI connected?
                    String key = makeDeviceListKey(AudioSystem.DEVICE_OUT_HDMI, "");
                    DeviceListSpec deviceSpec = mConnectedDevices.get(key);
                    if (deviceSpec != null) {
                        // Toggle HDMI to retrigger broadcast with proper formats.
                        setWiredDeviceConnectionState(AudioSystem.DEVICE_OUT_HDMI,
                                AudioSystem.DEVICE_STATE_UNAVAILABLE, "", "",
                                "android"); // disconnect
                        setWiredDeviceConnectionState(AudioSystem.DEVICE_OUT_HDMI,
                                AudioSystem.DEVICE_STATE_AVAILABLE, "", "",
                                "android"); // reconnect
                    }
                }
                mEncodedSurroundMode = newSurroundMode;
            }
        }
    }