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

SystemAudioStatusAction

public final class SystemAudioStatusAction extends HdmiCecFeatureAction
Action to update audio status (volume or mute) of audio amplifier

Fields Summary
private static final String
TAG
private static final int
STATE_WAIT_FOR_REPORT_AUDIO_STATUS
private final int
mAvrAddress
private final android.hardware.hdmi.IHdmiControlCallback
mCallback
Constructors Summary
SystemAudioStatusAction(HdmiCecLocalDevice source, int avrAddress, android.hardware.hdmi.IHdmiControlCallback callback)


       
              
        super(source);
        mAvrAddress = avrAddress;
        mCallback = callback;
    
Methods Summary
private voidfinishWithCallback(int returnCode)

        if (mCallback != null) {
            try {
                mCallback.onComplete(returnCode);
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to invoke callback.", e);
            }
        }
        finish();
    
private voidhandleReportAudioStatus(HdmiCecMessage cmd)

        byte[] params = cmd.getParams();
        boolean mute = (params[0] & 0x80) == 0x80;
        int volume = params[0] & 0x7F;
        tv().setAudioStatus(mute, volume);

        if (!(tv().isSystemAudioActivated() ^ mute)) {
            // Toggle AVR's mute status to match with the system audio status.
            sendUserControlPressedAndReleased(mAvrAddress, HdmiCecKeycode.CEC_KEYCODE_MUTE);
        }
        finishWithCallback(HdmiControlManager.RESULT_SUCCESS);
    
private voidhandleSendGiveAudioStatusFailure()

        // Inform to all application that the audio status (volumn, mute) of
        // the audio amplifier is unknown.
        tv().setAudioStatus(false, Constants.UNKNOWN_VOLUME);

        int uiCommand = tv().isSystemAudioActivated()
                ? HdmiCecKeycode.CEC_KEYCODE_RESTORE_VOLUME_FUNCTION  // SystemAudioMode: ON
                : HdmiCecKeycode.CEC_KEYCODE_MUTE_FUNCTION;           // SystemAudioMode: OFF
        sendUserControlPressedAndReleased(mAvrAddress, uiCommand);

        // Still return SUCCESS to callback.
        finishWithCallback(HdmiControlManager.RESULT_SUCCESS);
    
voidhandleTimerEvent(int state)

        if (mState != state) {
            return;
        }

        handleSendGiveAudioStatusFailure();
    
booleanprocessCommand(HdmiCecMessage cmd)

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

        switch (cmd.getOpcode()) {
            case Constants.MESSAGE_REPORT_AUDIO_STATUS:
                handleReportAudioStatus(cmd);
                return true;
        }

        return false;
    
private voidsendGiveAudioStatus()

        sendCommand(HdmiCecMessageBuilder.buildGiveAudioStatus(getSourceAddress(), mAvrAddress),
                new SendMessageCallback() {
            @Override
            public void onSendCompleted(int error) {
                if (error != Constants.SEND_RESULT_SUCCESS) {
                    handleSendGiveAudioStatusFailure();
                }
            }
        });
    
booleanstart()

        mState = STATE_WAIT_FOR_REPORT_AUDIO_STATUS;
        addTimer(mState, HdmiConfig.TIMEOUT_MS);
        sendGiveAudioStatus();
        return true;