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

Commit fbb50bc4 authored by Shuichi.Noguchi's avatar Shuichi.Noguchi Committed by Shuichi Noguchi
Browse files

Fix illegal volume value issue

Ignore volume change if the value reported
in <Report Audio Status> as "reserved value (0x65<=N<=0x7E)"
or "status is unknown (0x7F)" (HDMI spec.).

When TV device receives <Report Audio Status>
as volume:0x7F (more than 0x64), HdmiControlService
notify the status to audio manager as "unknown volume"
without "FLAG_SHOW_UII"

Test: Connect old AVR to TV device, then press Play button of AVR.
      Should not show the volume UI.

Change-Id: Icc4cfff5cfb46d075b45258210109c975a85c1d1
parent 9c1279d2
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -698,10 +698,9 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    protected boolean handleReportAudioStatus(HdmiCecMessage message) {
        assertRunOnServiceThread();

        byte params[] = message.getParams();
        int mute = params[0] & 0x80;
        int volume = params[0] & 0x7F;
        setAudioStatus(mute == 0x80, volume);
        boolean mute = HdmiUtils.isAudioStatusMute(message);
        int volume = HdmiUtils.getAudioStatusVolume(message);
        setAudioStatus(mute, volume);
        return true;
    }

+6 −2
Original line number Diff line number Diff line
@@ -989,8 +989,12 @@ public final class HdmiControlService extends SystemService {
            }
            // 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);
            int flag = AudioManager.FLAG_HDMI_SYSTEM_AUDIO_VOLUME;
            if (0 <= volume && volume <= 100) {
                Slog.i(TAG, "volume: " + volume);
                flag |= AudioManager.FLAG_SHOW_UI;
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, flag);
            }
        }
    }

+26 −0
Original line number Diff line number Diff line
@@ -151,6 +151,32 @@ final class HdmiUtils {
        return cmd.getParams()[0] == Constants.SYSTEM_AUDIO_STATUS_ON;
    }

    /**
     * Parse the <Report Audio Status> message and check if it is mute
     *
     * @param cmd the CEC message to parse
     * @return true if the given parameter has [MUTE]
     */
    static boolean isAudioStatusMute(HdmiCecMessage cmd) {
        byte params[] = cmd.getParams();
        return (params[0] & 0x80) == 0x80;
    }

    /**
     * Parse the <Report Audio Status> message and extract the volume
     *
     * @param cmd the CEC message to parse
     * @return device's volume. Constants.UNKNOWN_VOLUME in case it is out of range
     */
    static int getAudioStatusVolume(HdmiCecMessage cmd) {
        byte params[] = cmd.getParams();
        int volume = params[0] & 0x7F;
        if (volume < 0x00 || 0x64 < volume) {
            volume = Constants.UNKNOWN_VOLUME;
        }
        return volume;
    }

    /**
     * Convert integer array to list of {@link Integer}.
     *
+2 −2
Original line number Diff line number Diff line
@@ -92,8 +92,8 @@ final class SystemAudioStatusAction extends HdmiCecFeatureAction {

    private void handleReportAudioStatus(HdmiCecMessage cmd) {
        byte[] params = cmd.getParams();
        boolean mute = (params[0] & 0x80) == 0x80;
        int volume = params[0] & 0x7F;
        boolean mute = HdmiUtils.isAudioStatusMute(cmd);
        int volume = HdmiUtils.getAudioStatusVolume(cmd);
        tv().setAudioStatus(mute, volume);

        if (!(tv().isSystemAudioActivated() ^ mute)) {
+2 −2
Original line number Diff line number Diff line
@@ -139,8 +139,8 @@ final class VolumeControlAction extends HdmiCecFeatureAction {

    private boolean handleReportAudioStatus(HdmiCecMessage cmd) {
        byte params[] = cmd.getParams();
        boolean mute = (params[0] & 0x80) == 0x80;
        int volume = params[0] & 0x7F;
        boolean mute = HdmiUtils.isAudioStatusMute(cmd);
        int volume = HdmiUtils.getAudioStatusVolume(cmd);
        mLastAvrVolume = volume;
        mLastAvrMute = mute;
        if (shouldUpdateAudioVolume(mute)) {