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

Commit b69aafbf authored by Jungshik Jang's avatar Jungshik Jang
Browse files

Hook up missing volume-change with AudioManager.

Whenever new volume change is notified from system audio,
hdmi control service should delegate it to AudioManager.
Note that, it should set FLAG_HDMI_SYSTEM_AUDIO_VOLUME,
which prevents audio manager from notifying volume-
change event back to hdmi control service.

Change-Id: I6621f517a4d20226aea9159bbae6b699e2c2ffd0
parent 4e357827
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Intent;
import android.hardware.hdmi.HdmiCecDeviceInfo;
import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.IHdmiControlCallback;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioPortUpdateListener;
import android.media.AudioPatch;
import android.media.AudioPort;
@@ -654,8 +655,10 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        synchronized (mLock) {
            mSystemAudioMute = mute;
            mSystemAudioVolume = volume;
            // TODO: pass volume to service (audio service) after scale it to local volume level.
            mService.setAudioStatus(mute, volume);
            int maxVolume = mService.getAudioManager().getStreamMaxVolume(
                    AudioManager.STREAM_MUSIC);
            mService.setAudioStatus(mute,
                    VolumeControlAction.scaleToCustomVolume(volume, maxVolume));
        }
    }

+16 −1
Original line number Diff line number Diff line
@@ -577,7 +577,22 @@ public final class HdmiControlService extends SystemService {
    }

    void setAudioStatus(boolean mute, int volume) {
        // TODO: Hook up with AudioManager.
        AudioManager audioManager = getAudioManager();
        boolean muted = audioManager.isStreamMute(AudioManager.STREAM_MUSIC);
        if (mute) {
            if (!muted) {
                audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
            }
        } else {
            if (muted) {
                audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
            }
            // FLAG_HDMI_SYSTEM_AUDIO_VOLUME prevents audio manager from announcing
            // volume change notification back to hdmi control service.
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume,
                    AudioManager.FLAG_SHOW_UI |
                    AudioManager.FLAG_HDMI_SYSTEM_AUDIO_VOLUME);
        }
    }

    void announceSystemAudioModeChange(boolean enabled) {