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

OneTouchPlayAction

public final class OneTouchPlayAction extends HdmiCecFeatureAction
Feature action that performs one touch play against TV/Display device. This action is initiated via {@link android.hardware.hdmi.HdmiPlaybackClient#oneTouchPlay(OneTouchPlayCallback)} from the Android system working as playback device to turn on the TV, and switch the input.

Package-private, accessed by {@link HdmiControlService} only.

Fields Summary
private static final String
TAG
private static final int
STATE_WAITING_FOR_REPORT_POWER_STATUS
private static final int
LOOP_COUNTER_MAX
private final int
mTargetAddress
private final android.hardware.hdmi.IHdmiControlCallback
mCallback
private int
mPowerStatusCounter
Constructors Summary
private OneTouchPlayAction(HdmiCecLocalDevice localDevice, int targetAddress, android.hardware.hdmi.IHdmiControlCallback callback)

        super(localDevice);
        mTargetAddress = targetAddress;
        mCallback = callback;
    
Methods Summary
private voidbroadcastActiveSource()

        sendCommand(HdmiCecMessageBuilder.buildActiveSource(getSourceAddress(), getSourcePath()));
        // Because only playback device can create this action, it's safe to cast.
        playback().setActiveSource(true);
    
static com.android.server.hdmi.OneTouchPlayActioncreate(HdmiCecLocalDevicePlayback source, int targetAddress, android.hardware.hdmi.IHdmiControlCallback callback)


    // Factory method. Ensures arguments are valid.
       
                
        if (source == null || callback == null) {
            Slog.e(TAG, "Wrong arguments");
            return null;
        }
        return new OneTouchPlayAction(source, targetAddress,
                callback);
    
voidhandleTimerEvent(int state)

        if (mState != state) {
            return;
        }
        if (state == STATE_WAITING_FOR_REPORT_POWER_STATUS) {
            if (mPowerStatusCounter++ < LOOP_COUNTER_MAX) {
                queryDevicePowerStatus();
                addTimer(mState, HdmiConfig.TIMEOUT_MS);
            } else {
                // Couldn't wake up the TV for whatever reason. Report failure.
                invokeCallback(HdmiControlManager.RESULT_TIMEOUT);
                finish();
            }
        }
    
private voidinvokeCallback(int result)

        try {
            mCallback.onComplete(result);
        } catch (RemoteException e) {
            Slog.e(TAG, "Callback failed:" + e);
        }
    
booleanprocessCommand(HdmiCecMessage cmd)

        if (mState != STATE_WAITING_FOR_REPORT_POWER_STATUS
                || mTargetAddress != cmd.getSource()) {
            return false;
        }
        if (cmd.getOpcode() == Constants.MESSAGE_REPORT_POWER_STATUS) {
            int status = cmd.getParams()[0];
            if (status == HdmiControlManager.POWER_STATUS_ON) {
                broadcastActiveSource();
                invokeCallback(HdmiControlManager.RESULT_SUCCESS);
                finish();
            }
            return true;
        }
        return false;
    
private voidqueryDevicePowerStatus()

        sendCommand(HdmiCecMessageBuilder.buildGiveDevicePowerStatus(getSourceAddress(),
                mTargetAddress));
    
booleanstart()

        sendCommand(HdmiCecMessageBuilder.buildTextViewOn(getSourceAddress(), mTargetAddress));
        broadcastActiveSource();
        queryDevicePowerStatus();
        mState = STATE_WAITING_FOR_REPORT_POWER_STATUS;
        addTimer(mState, HdmiConfig.TIMEOUT_MS);
        return true;