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

SystemAudioAutoInitiationAction

public final class SystemAudioAutoInitiationAction extends HdmiCecFeatureAction
Action to initiate system audio once AVR is detected on Device discovery action.

Fields Summary
private final int
mAvrAddress
private static final int
STATE_WAITING_FOR_SYSTEM_AUDIO_MODE_STATUS
Constructors Summary
SystemAudioAutoInitiationAction(HdmiCecLocalDevice source, int avrAddress)


        
        super(source);
        mAvrAddress = avrAddress;
    
Methods Summary
private booleancanChangeSystemAudio()

        return !(tv().hasAction(SystemAudioActionFromTv.class)
               || tv().hasAction(SystemAudioActionFromAvr.class));
    
private voidhandleSystemAudioModeStatusMessage()

        if (!canChangeSystemAudio()) {
            HdmiLogger.debug("Cannot change system audio mode in auto initiation action.");
            finish();
            return;
        }

        boolean systemAudioModeSetting = tv().getSystemAudioModeSetting();
        // Update AVR's system audio mode regardless of AVR's status.
        addAndStartAction(new SystemAudioActionFromTv(tv(), mAvrAddress, systemAudioModeSetting,
                null));
        finish();
    
private voidhandleSystemAudioModeStatusTimeout()

        if (tv().getSystemAudioModeSetting()) {
            if (canChangeSystemAudio()) {
                addAndStartAction(new SystemAudioActionFromTv(tv(), mAvrAddress, true, null));
            }
        } else {
            tv().setSystemAudioMode(false, true);
        }
        finish();
    
voidhandleTimerEvent(int state)

        if (mState != state) {
            return;
        }

        switch (mState) {
            case STATE_WAITING_FOR_SYSTEM_AUDIO_MODE_STATUS:
                handleSystemAudioModeStatusTimeout();
                break;
        }
    
booleanprocessCommand(HdmiCecMessage cmd)

        if (mState != STATE_WAITING_FOR_SYSTEM_AUDIO_MODE_STATUS
                || mAvrAddress != cmd.getSource()) {
            return false;
        }

        if (cmd.getOpcode() == Constants.MESSAGE_SYSTEM_AUDIO_MODE_STATUS) {
            handleSystemAudioModeStatusMessage();
            return true;
        }
        return false;
    
private voidsendGiveSystemAudioModeStatus()

        sendCommand(HdmiCecMessageBuilder.buildGiveSystemAudioModeStatus(getSourceAddress(),
                mAvrAddress), new SendMessageCallback() {
            @Override
            public void onSendCompleted(int error) {
                if (error != Constants.SEND_RESULT_SUCCESS) {
                    tv().setSystemAudioMode(false, true);
                    finish();
                }
            }
        });
    
booleanstart()

        mState = STATE_WAITING_FOR_SYSTEM_AUDIO_MODE_STATUS;

        addTimer(mState, HdmiConfig.TIMEOUT_MS);
        sendGiveSystemAudioModeStatus();
        return true;