FileDocCategorySizeDatePackage
HdmiCecMessageBuilder.javaAPI DocAndroid 5.1 API22511Thu Mar 12 22:22:42 GMT 2015com.android.server.hdmi

HdmiCecMessageBuilder

public class HdmiCecMessageBuilder extends Object
A helper class to build {@link HdmiCecMessage} from various cec commands.

Fields Summary
private static final int
OSD_NAME_MAX_LENGTH
Constructors Summary
private HdmiCecMessageBuilder()


      
Methods Summary
static HdmiCecMessagebuildActiveSource(int src, int physicalAddress)
Build <Active Source> command.

param
src source address of command
param
physicalAddress physical address of the device to become active
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, Constants.ADDR_BROADCAST, Constants.MESSAGE_ACTIVE_SOURCE,
                physicalAddressToParam(physicalAddress));
    
static HdmiCecMessagebuildCecVersion(int src, int dest, int version)
Build <Device Vendor Id> command. It has one byte cec version as parameter.

param
src source address of command
param
dest destination address of command
param
version version of cec. Use 0x04 for "Version 1.3a" and 0x05 for "Version 1.4 or 1.4a or 1.4b
return
newly created {@link HdmiCecMessage}

        byte[] params = new byte[] {
                (byte) (version & 0xFF)
        };
        return buildCommand(src, dest, Constants.MESSAGE_CEC_VERSION, params);
    
static HdmiCecMessagebuildClearAnalogueTimer(int src, int dest, byte[] params)
Build <Clear Analog Timer> command.

param
src source address of command
param
dest destination address of command
param
params byte array of timing information and analog service information to be cleared
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_CLEAR_ANALOG_TIMER, params);
    
static HdmiCecMessagebuildClearDigitalTimer(int src, int dest, byte[] params)
Build <Clear Digital Timer> command.

param
src source address of command
param
dest destination address of command
param
params byte array of timing information and digital service information to be cleared
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_CLEAR_DIGITAL_TIMER, params);
    
static HdmiCecMessagebuildClearExternalTimer(int src, int dest, byte[] params)
Build <Clear Digital Timer> command.

param
src source address of command
param
dest destination address of command
param
params byte array of timing information and external source information to be cleared
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_CLEAR_EXTERNAL_TIMER, params);
    
private static HdmiCecMessagebuildCommand(int src, int dest, int opcode)
Build a {@link HdmiCecMessage} without extra parameter.

param
src source address of command
param
dest destination address of command
param
opcode opcode for a message
return
newly created {@link HdmiCecMessage}

        return new HdmiCecMessage(src, dest, opcode, HdmiCecMessage.EMPTY_PARAM);
    
private static HdmiCecMessagebuildCommand(int src, int dest, int opcode, byte[] params)
Build a {@link HdmiCecMessage} with given values.

param
src source address of command
param
dest destination address of command
param
opcode opcode for a message
param
params extra parameters for command
return
newly created {@link HdmiCecMessage}

        return new HdmiCecMessage(src, dest, opcode, params);
    
static HdmiCecMessagebuildDeviceVendorIdCommand(int src, int vendorId)
Build <Device Vendor Id> command. It has three bytes vendor id as parameter.

This is a broadcast message sent to all devices on the bus.

param
src source address of command
param
vendorId device's vendor id
return
newly created {@link HdmiCecMessage}

        byte[] params = new byte[] {
                (byte) ((vendorId >> 16) & 0xFF),
                (byte) ((vendorId >> 8) & 0xFF),
                (byte) (vendorId & 0xFF)
        };
        // <Device Vendor Id> is broadcast message.
        return buildCommand(src, Constants.ADDR_BROADCAST,
                Constants.MESSAGE_DEVICE_VENDOR_ID, params);
    
static HdmiCecMessagebuildFeatureAbortCommand(int src, int dest, int originalOpcode, int reason)
Build <Feature Abort> command. <Feature Abort> consists of 1 byte original opcode and 1 byte reason fields with basic fields.

param
src source address of command
param
dest destination address of command
param
originalOpcode original opcode causing feature abort
param
reason reason of feature abort
return
newly created {@link HdmiCecMessage}

        byte[] params = new byte[] {
                (byte) (originalOpcode & 0xFF),
                (byte) (reason & 0xFF),
        };
        return buildCommand(src, dest, Constants.MESSAGE_FEATURE_ABORT, params);
    
static HdmiCecMessagebuildGiveAudioStatus(int src, int dest)
Build <Give Audio Status> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_GIVE_AUDIO_STATUS);
    
static HdmiCecMessagebuildGiveDevicePowerStatus(int src, int dest)
Build <Give Device Power Status> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_GIVE_DEVICE_POWER_STATUS);
    
static HdmiCecMessagebuildGiveDeviceVendorIdCommand(int src, int dest)
Build <Give Vendor Id Command> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_GIVE_DEVICE_VENDOR_ID);
    
static HdmiCecMessagebuildGiveOsdNameCommand(int src, int dest)
Build <Give Osd Name> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_GIVE_OSD_NAME);
    
static HdmiCecMessagebuildGivePhysicalAddress(int src, int dest)
Build <Give Physical Address> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_GIVE_PHYSICAL_ADDRESS);
    
static HdmiCecMessagebuildGiveSystemAudioModeStatus(int src, int dest)
Build <Give System Audio Mode Status> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_GIVE_SYSTEM_AUDIO_MODE_STATUS);
    
static HdmiCecMessagebuildInactiveSource(int src, int physicalAddress)
Build <Inactive Source> command.

param
src source address of command
param
physicalAddress physical address of the device to become inactive
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, Constants.ADDR_TV,
                Constants.MESSAGE_INACTIVE_SOURCE, physicalAddressToParam(physicalAddress));
    
static HdmiCecMessagebuildRecordOff(int src, int dest)
Build <Record Off> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_RECORD_OFF);
    
static HdmiCecMessagebuildRecordOn(int src, int dest, byte[] params)
Build <Record On> command.

param
src source address of command
param
dest destination address of command
param
params parameter of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_RECORD_ON, params);
    
static HdmiCecMessagebuildReportArcInitiated(int src, int dest)
Build <Report Arc Initiated>

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_REPORT_ARC_INITIATED);
    
static HdmiCecMessagebuildReportArcTerminated(int src, int dest)
Build <Report Arc Terminated>

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_REPORT_ARC_TERMINATED);
    
static HdmiCecMessagebuildReportMenuStatus(int src, int dest, int menuStatus)
Build <Report Menu Status> command.

param
src source address of command
param
dest destination address of command
param
menuStatus menu status of the device
return
newly created {@link HdmiCecMessage}

        byte[] param = new byte[] {
                (byte) (menuStatus & 0xFF)
        };
        return buildCommand(src, dest, Constants.MESSAGE_MENU_STATUS, param);
    
static HdmiCecMessagebuildReportPhysicalAddressCommand(int src, int address, int deviceType)
Build <Report Physical Address> command. It has two bytes physical address and one byte device type as parameter.

This is a broadcast message sent to all devices on the bus.

param
src source address of command
param
address physical address of device
param
deviceType type of device
return
newly created {@link HdmiCecMessage}

        byte[] params = new byte[] {
                // Two bytes for physical address
                (byte) ((address >> 8) & 0xFF),
                (byte) (address & 0xFF),
                // One byte device type
                (byte) (deviceType & 0xFF)
        };
        // <Report Physical Address> is broadcast message.
        return buildCommand(src, Constants.ADDR_BROADCAST,
                Constants.MESSAGE_REPORT_PHYSICAL_ADDRESS, params);
    
static HdmiCecMessagebuildReportPowerStatus(int src, int dest, int powerStatus)
Build <Report Power Status> command.

param
src source address of command
param
dest destination address of command
param
powerStatus power status of the device
return
newly created {@link HdmiCecMessage}

        byte[] param = new byte[] {
                (byte) (powerStatus & 0xFF)
        };
        return buildCommand(src, dest, Constants.MESSAGE_REPORT_POWER_STATUS, param);
    
static HdmiCecMessagebuildRequestArcInitiation(int src, int dest)
Build <Request Arc Initiation>

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_REQUEST_ARC_INITIATION);
    
static HdmiCecMessagebuildRequestArcTermination(int src, int dest)
Build <Request Arc Termination>

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_REQUEST_ARC_TERMINATION);
    
static HdmiCecMessagebuildRoutingChange(int src, int oldPath, int newPath)
Build <Routing Change> command.

This is a broadcast message sent to all devices on the bus.

param
src source address of command
param
oldPath physical address of the currently active routing path
param
newPath physical address of the new active routing path
return
newly created {@link HdmiCecMessage}

        byte[] param = new byte[] {
            (byte) ((oldPath >> 8) & 0xFF), (byte) (oldPath & 0xFF),
            (byte) ((newPath >> 8) & 0xFF), (byte) (newPath & 0xFF)
        };
        return buildCommand(src, Constants.ADDR_BROADCAST, Constants.MESSAGE_ROUTING_CHANGE,
                param);
    
static HdmiCecMessagebuildSetAnalogueTimer(int src, int dest, byte[] params)
Build <Set Analogue Timer> command.

param
src source address of command
param
dest destination address of command
param
params byte array of timing information and analog service information to be recorded
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_SET_ANALOG_TIMER, params);
    
static HdmiCecMessagebuildSetDigitalTimer(int src, int dest, byte[] params)
Build <Set Digital Timer> command.

param
src source address of command
param
dest destination address of command
param
params byte array of timing information and digital service information to be recorded
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_SET_DIGITAL_TIMER, params);
    
static HdmiCecMessagebuildSetExternalTimer(int src, int dest, byte[] params)
Build <Set External Timer> command.

param
src source address of command
param
dest destination address of command
param
params byte array of timing information and external source information to be recorded
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_SET_EXTERNAL_TIMER, params);
    
static HdmiCecMessagebuildSetMenuLanguageCommand(int src, java.lang.String language)
Build <Set Menu Language > command.

This is a broadcast message sent to all devices on the bus.

param
src source address of command
param
language 3-letter ISO639-2 based language code
return
newly created {@link HdmiCecMessage} if language is valid. Otherwise, return null

        if (language.length() != 3) {
            return null;
        }
        // Hdmi CEC uses lower-cased ISO 639-2 (3 letters code).
        String normalized = language.toLowerCase();
        byte[] params = new byte[] {
                (byte) (normalized.charAt(0) & 0xFF),
                (byte) (normalized.charAt(1) & 0xFF),
                (byte) (normalized.charAt(2) & 0xFF),
        };
        // <Set Menu Language> is broadcast message.
        return buildCommand(src, Constants.ADDR_BROADCAST,
                Constants.MESSAGE_SET_MENU_LANGUAGE, params);
    
static HdmiCecMessagebuildSetOsdNameCommand(int src, int dest, java.lang.String name)
Build <Set Osd Name > command.

param
src source address of command
param
name display (OSD) name of device
return
newly created {@link HdmiCecMessage} if valid name. Otherwise, return null

        int length = Math.min(name.length(), OSD_NAME_MAX_LENGTH);
        byte[] params;
        try {
            params = name.substring(0, length).getBytes("US-ASCII");
        } catch (UnsupportedEncodingException e) {
            return null;
        }
        return buildCommand(src, dest, Constants.MESSAGE_SET_OSD_NAME, params);
    
static HdmiCecMessagebuildSetStreamPath(int src, int streamPath)
Build <Set Stream Path> command.

This is a broadcast message sent to all devices on the bus.

param
src source address of command
param
streamPath physical address of the device to start streaming
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, Constants.ADDR_BROADCAST,
                Constants.MESSAGE_SET_STREAM_PATH, physicalAddressToParam(streamPath));
    
public static HdmiCecMessagebuildStandby(int src, int dest)
Build <Standby> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_STANDBY);
    
static HdmiCecMessagebuildSystemAudioModeRequest(int src, int avr, int avrPhysicalAddress, boolean enableSystemAudio)
Build <System Audio Mode Request> command.

param
src source address of command
param
avr destination address of command, it should be AVR
param
avrPhysicalAddress physical address of AVR
param
enableSystemAudio whether to enable System Audio Mode or not
return
newly created {@link HdmiCecMessage}

        if (enableSystemAudio) {
            return buildCommand(src, avr, Constants.MESSAGE_SYSTEM_AUDIO_MODE_REQUEST,
                    physicalAddressToParam(avrPhysicalAddress));
        } else {
            return buildCommand(src, avr, Constants.MESSAGE_SYSTEM_AUDIO_MODE_REQUEST);
        }
    
static HdmiCecMessagebuildTextViewOn(int src, int dest)
Build <Text View On> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_TEXT_VIEW_ON);
    
static HdmiCecMessagebuildUserControlPressed(int src, int dest, int uiCommand)
Build <User Control Pressed> command.

param
src source address of command
param
dest destination address of command
param
uiCommand keycode that user pressed
return
newly created {@link HdmiCecMessage}

        return buildUserControlPressed(src, dest, new byte[] { (byte) (uiCommand & 0xFF) });
    
static HdmiCecMessagebuildUserControlPressed(int src, int dest, byte[] commandParam)
Build <User Control Pressed> command.

param
src source address of command
param
dest destination address of command
param
commandParam uiCommand and the additional parameter
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_USER_CONTROL_PRESSED, commandParam);
    
static HdmiCecMessagebuildUserControlReleased(int src, int dest)
Build <User Control Released> command.

param
src source address of command
param
dest destination address of command
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_USER_CONTROL_RELEASED);
    
static HdmiCecMessagebuildVendorCommand(int src, int dest, byte[] params)
Build <Vendor Command> command.

param
src source address of command
param
dest destination address of command
param
params vendor-specific parameters
return
newly created {@link HdmiCecMessage}

        return buildCommand(src, dest, Constants.MESSAGE_VENDOR_COMMAND, params);
    
static HdmiCecMessagebuildVendorCommandWithId(int src, int dest, int vendorId, byte[] operands)
Build <Vendor Command With ID> command.

param
src source address of command
param
dest destination address of command
param
vendorId vendor ID
param
operands vendor-specific parameters
return
newly created {@link HdmiCecMessage}

        byte[] params = new byte[operands.length + 3];  // parameter plus len(vendorId)
        params[0] = (byte) ((vendorId >> 16) & 0xFF);
        params[1] = (byte) ((vendorId >> 8) & 0xFF);
        params[2] = (byte) (vendorId & 0xFF);
        System.arraycopy(operands, 0, params, 3, operands.length);
        return buildCommand(src, dest, Constants.MESSAGE_VENDOR_COMMAND_WITH_ID, params);
    
static HdmiCecMessageof(int src, int dest, byte[] body)
Build {@link HdmiCecMessage} from raw data.

param
src source address of command
param
dest destination address of command
param
body body of message. It includes opcode.
return
newly created {@link HdmiCecMessage}

        byte opcode = body[0];
        byte params[] = Arrays.copyOfRange(body, 1, body.length);
        return new HdmiCecMessage(src, dest, opcode, params);
    
private static byte[]physicalAddressToParam(int physicalAddress)

        return new byte[] {
                (byte) ((physicalAddress >> 8) & 0xFF),
                (byte) (physicalAddress & 0xFF)
        };