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

HdmiCecFeatureAction

public abstract class HdmiCecFeatureAction extends Object
Encapsulates a sequence of CEC command exchange for a certain feature.

Many CEC features are accomplished by CEC devices on the bus exchanging more than one command. {@link HdmiCecFeatureAction} represents the life cycle of the communication, manages the state as the process progresses, and if necessary, returns the result to the caller which initiates the action, through the callback given at the creation of the object. All the actual action classes inherit FeatureAction.

More than one FeatureAction objects can be up and running simultaneously, maintained by {@link HdmiCecLocalDevice}. Each action is passed a new command arriving from the bus, and either consumes it if the command is what the action expects, or yields it to other action. Declared as package private, accessed by {@link HdmiControlService} only.

Fields Summary
private static final String
TAG
protected static final int
MSG_TIMEOUT
protected static final int
STATE_NONE
protected int
mState
private final HdmiControlService
mService
private final HdmiCecLocalDevice
mSource
protected ActionTimer
mActionTimer
private ArrayList
mOnFinishedCallbacks
Constructors Summary
HdmiCecFeatureAction(HdmiCecLocalDevice source)


      
        mSource = source;
        mService = mSource.getService();
        mActionTimer = createActionTimer(mService.getServiceLooper());
    
Methods Summary
protected final voidaddAndStartAction(com.android.server.hdmi.HdmiCecFeatureAction action)

        mSource.addAndStartAction(action);
    
protected final voidaddOnFinishedCallback(com.android.server.hdmi.HdmiCecFeatureAction action, java.lang.Runnable runnable)

        if (mOnFinishedCallbacks == null) {
            mOnFinishedCallbacks = new ArrayList<>();
        }
        mOnFinishedCallbacks.add(Pair.create(action, runnable));
    
protected voidaddTimer(int state, int delayMillis)

        mActionTimer.sendTimerMessage(state, delayMillis);
    
voidclear()
Clean up action's state.

Declared as package-private. Only {@link HdmiControlService} can access it.

        mState = STATE_NONE;
        // Clear all timers.
        mActionTimer.clearTimerMessage();
    
private com.android.server.hdmi.HdmiCecFeatureAction$ActionTimercreateActionTimer(android.os.Looper looper)

        return new ActionTimerHandler(looper);
    
protected voidfinish()
Finish up the action. Reset the state, and remove itself from the action queue.

        finish(true);
    
voidfinish(boolean removeSelf)

        clear();
        if (removeSelf) {
            removeAction(this);
        }
        if (mOnFinishedCallbacks != null) {
            for (Pair<HdmiCecFeatureAction, Runnable> actionCallbackPair: mOnFinishedCallbacks) {
                if (actionCallbackPair.first.mState != STATE_NONE) {
                    actionCallbackPair.second.run();
                }
            }
            mOnFinishedCallbacks = null;
        }
    
protected final java.util.ListgetActions(java.lang.Class clazz)

        return mSource.getActions(clazz);
    
protected final HdmiCecMessageCachegetCecMessageCache()

        return mSource.getCecMessageCache();
    
protected final intgetSourceAddress()

        return mSource.getDeviceInfo().getLogicalAddress();
    
protected final intgetSourcePath()

        return mSource.getDeviceInfo().getPhysicalAddress();
    
abstract voidhandleTimerEvent(int state)
Called when the action should handle the timer event it created before.

CEC standard mandates each command transmission should be responded within certain period of time. The method is called when the timer it created as it transmitted a command gets expired. Inner logic should take an appropriate action.

param
state the state associated with the time when the timer was created

protected final HdmiCecLocalDevicelocalDevice()

        return mSource;
    
protected final HdmiCecLocalDevicePlaybackplayback()

        return (HdmiCecLocalDevicePlayback) mSource;
    
protected final voidpollDevices(com.android.server.hdmi.HdmiControlService.DevicePollingCallback callback, int pickStrategy, int retryCount)

        mService.pollDevices(callback, getSourceAddress(), pickStrategy, retryCount);
    
abstract booleanprocessCommand(HdmiCecMessage cmd)
Process the command. Called whenever a new command arrives.

param
cmd command to process
return
true if the command was consumed in the process; Otherwise false.

protected final voidremoveAction(com.android.server.hdmi.HdmiCecFeatureAction action)
Remove the action from the action queue. This is called after the action finishes its role.

param
action

        mSource.removeAction(action);
    
protected final voidremoveAction(java.lang.Class clazz)

        mSource.removeActionExcept(clazz, null);
    
protected final voidremoveActionExcept(java.lang.Class clazz, com.android.server.hdmi.HdmiCecFeatureAction exception)

        mSource.removeActionExcept(clazz, exception);
    
protected final voidsendCommand(HdmiCecMessage cmd, HdmiControlService.SendMessageCallback callback)

        mService.sendCecCommand(cmd, callback);
    
protected final voidsendCommand(HdmiCecMessage cmd)

        mService.sendCecCommand(cmd);
    
protected final voidsendUserControlPressedAndReleased(int targetAddress, int uiCommand)

        mSource.sendUserControlPressedAndReleased(targetAddress, uiCommand);
    
voidsetActionTimer(com.android.server.hdmi.HdmiCecFeatureAction$ActionTimer actionTimer)

        mActionTimer = actionTimer;
    
abstract booleanstart()
Called after the action is created. Initialization or first step to take for the action can be done in this method. Shall update {@code mState} to indicate that the action has started.

return
true if the operation is successful; otherwise false.

booleanstarted()

        return mState != STATE_NONE;
    
protected final HdmiCecLocalDeviceTvtv()

        return (HdmiCecLocalDeviceTv) mSource;