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

PowerStatusMonitorAction

public class PowerStatusMonitorAction extends HdmiCecFeatureAction
Action that check each device's power status.

Fields Summary
private static final String
TAG
private static final int
STATE_WAIT_FOR_REPORT_POWER_STATUS
private static final int
STATE_WAIT_FOR_NEXT_MONITORING
private static final int
INVALID_POWER_STATUS
private static final int
MONITIROING_INTERNAL_MS
private static final int
REPORT_POWER_STATUS_TIMEOUT_MS
private final android.util.SparseIntArray
mPowerStatus
Constructors Summary
PowerStatusMonitorAction(HdmiCecLocalDevice source)


      
        super(source);
    
Methods Summary
private booleanhandleReportPowerStatus(HdmiCecMessage cmd)

        int sourceAddress = cmd.getSource();
        int oldStatus = mPowerStatus.get(sourceAddress, INVALID_POWER_STATUS);
        if (oldStatus == INVALID_POWER_STATUS) {
            // if no device exists for incoming message, hands it over to other actions.
            return false;
        }
        int newStatus = cmd.getParams()[0] & 0xFF;
        updatePowerStatus(sourceAddress, newStatus, true);
        return true;
    
private voidhandleTimeout()

        for (int i = 0; i < mPowerStatus.size(); ++i) {
            int logicalAddress = mPowerStatus.keyAt(i);
            updatePowerStatus(logicalAddress, POWER_STATUS_UNKNOWN, false);
        }
        mPowerStatus.clear();
        mState = STATE_WAIT_FOR_NEXT_MONITORING;
    
voidhandleTimerEvent(int state)

        switch (mState) {
            case STATE_WAIT_FOR_NEXT_MONITORING:
                queryPowerStatus();
                break;
            case STATE_WAIT_FOR_REPORT_POWER_STATUS:
                handleTimeout();
                break;
        }
    
booleanprocessCommand(HdmiCecMessage cmd)

        if (mState == STATE_WAIT_FOR_REPORT_POWER_STATUS
                && cmd.getOpcode() == Constants.MESSAGE_REPORT_POWER_STATUS) {
            return handleReportPowerStatus(cmd);
        }
        return false;
    
private voidqueryPowerStatus()

        List<HdmiDeviceInfo> deviceInfos = tv().getDeviceInfoList(false);
        resetPowerStatus(deviceInfos);
        for (HdmiDeviceInfo info : deviceInfos) {
            final int logicalAddress = info.getLogicalAddress();
            sendCommand(HdmiCecMessageBuilder.buildGiveDevicePowerStatus(getSourceAddress(),
                    logicalAddress),
                    new SendMessageCallback() {
                        @Override
                        public void onSendCompleted(int error) {
                            // If fails to send <Give Device Power Status>,
                            // update power status into UNKNOWN.
                            if (error != Constants.SEND_RESULT_SUCCESS) {
                               updatePowerStatus(logicalAddress, POWER_STATUS_UNKNOWN, true);
                            }
                        }
                    });
        }

        mState = STATE_WAIT_FOR_REPORT_POWER_STATUS;

        // Add both timers, monitoring and timeout.
        addTimer(STATE_WAIT_FOR_NEXT_MONITORING, MONITIROING_INTERNAL_MS);
        addTimer(STATE_WAIT_FOR_REPORT_POWER_STATUS, REPORT_POWER_STATUS_TIMEOUT_MS);
    
private voidresetPowerStatus(java.util.List deviceInfos)

        mPowerStatus.clear();
        for (HdmiDeviceInfo info : deviceInfos) {
            mPowerStatus.append(info.getLogicalAddress(), info.getDevicePowerStatus());
        }
    
booleanstart()

        queryPowerStatus();
        return true;
    
private voidupdatePowerStatus(int logicalAddress, int newStatus, boolean remove)

        tv().updateDevicePowerStatus(logicalAddress, newStatus);

        if (remove) {
            mPowerStatus.delete(logicalAddress);
        }