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

Commit 12485d1f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adding more cec commands builder methods."

parents 980c7f2d 3c161d45
Loading
Loading
Loading
Loading
+84 −0
Original line number Diff line number Diff line
@@ -210,6 +210,28 @@ public class HdmiCecMessageBuilder {
        return buildCommand(src, dest, Constants.MESSAGE_REQUEST_ARC_INITIATION);
    }

    /**
     * Build <Initiate Arc>
     *
     * @param src source address of command
     * @param dest destination address of command
     * @return newly created {@link HdmiCecMessage}
     */
    static HdmiCecMessage buildInitiateArc(int src, int dest) {
        return buildCommand(src, dest, Constants.MESSAGE_INITIATE_ARC);
    }

    /**
     * Build <Terminate Arc>
     *
     * @param src source address of command
     * @param dest destination address of command
     * @return newly created {@link HdmiCecMessage}
     */
    static HdmiCecMessage buildTerminateArc(int src, int dest) {
        return buildCommand(src, dest, Constants.MESSAGE_TERMINATE_ARC);
    }

    /**
     * Build <Request Arc Termination>
     *
@@ -371,6 +393,34 @@ public class HdmiCecMessageBuilder {
        }
    }

    /**
     * Build <Set System Audio Mode> command.
     *
     * @param src source address of command
     * @param des destination address of command
     * @param systemAudioStatus whether to set System Audio Mode on or off
     * @return newly created {@link HdmiCecMessage}
     */
    static HdmiCecMessage buildSetSystemAudioMode(int src, int des, boolean systemAudioStatus) {
        return buildCommandWithBooleanParam(src, des, Constants.MESSAGE_SET_SYSTEM_AUDIO_MODE,
            systemAudioStatus
        );
    }

    /**
     * Build <Report System Audio Mode> command.
     *
     * @param src source address of command
     * @param des destination address of command
     * @param systemAudioStatus whether System Audio Mode is on or off
     * @return newly created {@link HdmiCecMessage}
     */
    static HdmiCecMessage buildReportSystemAudioMode(int src, int des, boolean systemAudioStatus) {
        return buildCommandWithBooleanParam(src, des, Constants.MESSAGE_SYSTEM_AUDIO_MODE_STATUS,
            systemAudioStatus
        );
    }

    /**
     * Build <Give Audio Status> command.
     *
@@ -382,6 +432,23 @@ public class HdmiCecMessageBuilder {
        return buildCommand(src, dest, Constants.MESSAGE_GIVE_AUDIO_STATUS);
    }

    /**
     * Build <Report Audio Status> command.
     *
     * @param src source address of command
     * @param dest destination address of command
     * @param volume volume level of current device in param
     * @param mute mute status of current device in param
     * @return newly created {@link HdmiCecMessage}
     */
    static HdmiCecMessage buildReportAudioStatus(int src, int dest, int volume, boolean mute) {
        byte[] params = new byte[] {
            mute ? (byte) (1 & 0xFF) : (byte) (0 & 0xFF),
            (byte) (volume & 0xFF)
        };
        return buildCommand(src, dest, Constants.MESSAGE_REPORT_AUDIO_STATUS, params);
    }

    /**
     * Build <User Control Pressed> command.
     *
@@ -592,6 +659,23 @@ public class HdmiCecMessageBuilder {
        return new HdmiCecMessage(src, dest, opcode, params);
    }

    /**
     * Build a {@link HdmiCecMessage} with a boolean param and other given values.
     *
     * @param src source address of command
     * @param des destination address of command
     * @param opcode opcode for a message
     * @param param boolean param for building the command
     * @return newly created {@link HdmiCecMessage}
     */
    private static HdmiCecMessage buildCommandWithBooleanParam(int src, int des,
        int opcode, boolean param) {
        byte[] params = new byte[]{
            param ? (byte) 0b1 : 0b0
        };
        return buildCommand(src, des, opcode, params);
    }

    private static byte[] physicalAddressToParam(int physicalAddress) {
        return new byte[] {
                (byte) ((physicalAddress >> 8) & 0xFF),