Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b38cd68b authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

Update HdmiControlService.deviceSelect()

The device selection action should have stopped if
TV's own power goes to standby in the middle. This CL
implements the right behavior.

Some TODO's about OSD banner were removed as they
can be handled in caller (TV app) when invoking the API
or upon receiving the callback based on the result. One
more callback result constant was added accordingly.

Bug: 15843137
Bug: 15844312
Bug: 15845651

Change-Id: Ib118fd6e80e9abdfb531e3f321d8db1c9cec45bd
parent 4ab7606f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ public final class HdmiControlManager {
    public static final int RESULT_ALREADY_IN_PROGRESS = 4;
    public static final int RESULT_EXCEPTION = 5;
    public static final int RESULT_INCORRECT_MODE = 6;
    public static final int RESULT_COMMUNICATION_FAILED = 7;

    // True if we have a logical device of type playback hosted in the system.
    private final boolean mHasPlaybackDevice;
+26 −13
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.hardware.hdmi.IHdmiControlCallback;
import android.os.RemoteException;
import android.util.Slog;

import com.android.server.hdmi.HdmiControlService.SendMessageCallback;

/**
 * Handles an action that selects a logical device as a new active source.
 *
@@ -66,6 +68,7 @@ final class DeviceSelectAction extends FeatureAction {

    private final HdmiCecDeviceInfo mTarget;
    private final IHdmiControlCallback mCallback;
    private final HdmiCecMessage mGivePowerStatus;

    private int mPowerStatusCounter = 0;

@@ -81,25 +84,39 @@ final class DeviceSelectAction extends FeatureAction {
        super(source);
        mCallback = callback;
        mTarget = target;
        mGivePowerStatus = HdmiCecMessageBuilder.buildGiveDevicePowerStatus(
                getSourceAddress(), getTargetAddress());
    }

    int getTargetAddress() {
        return mTarget.getLogicalAddress();
    }

    @Override
    public boolean start() {
        // TODO: Call the logic that display a banner saying the select action got started.
        // Seq #9
        queryDevicePowerStatus();
        return true;
    }

    private void queryDevicePowerStatus() {
        sendCommand(HdmiCecMessageBuilder.buildGiveDevicePowerStatus(
                getSourceAddress(), mTarget.getLogicalAddress()));
        sendCommand(mGivePowerStatus, new SendMessageCallback() {
            @Override
            public void onSendCompleted(int error) {
                if (error == Constants.SEND_RESULT_NAK) {
                    invokeCallback(HdmiControlManager.RESULT_COMMUNICATION_FAILED);
                    finish();
                    return;
                }
            }
        });
        mState = STATE_WAIT_FOR_REPORT_POWER_STATUS;
        addTimer(mState, TIMEOUT_MS);
    }

    @Override
    public boolean processCommand(HdmiCecMessage cmd) {
        if (cmd.getSource() != mTarget.getLogicalAddress()) {
        if (cmd.getSource() != getTargetAddress()) {
            return false;
        }
        int opcode = cmd.getOpcode();
@@ -128,9 +145,6 @@ final class DeviceSelectAction extends FeatureAction {
    }

    private boolean handleReportPowerStatus(int powerStatus) {
        // TODO: Check TV's own status which might have been updated during the action.
        //       If in 'Standby' or 'Transit to standby', remove the banner
        //       and stop this action. Otherwise, send <Set Stream Path>
        switch (powerStatus) {
            case HdmiControlManager.POWER_STATUS_ON:
                sendSetStreamPath();
@@ -186,6 +200,11 @@ final class DeviceSelectAction extends FeatureAction {
        }
        switch (mState) {
            case STATE_WAIT_FOR_REPORT_POWER_STATUS:
                if (tv().isPowerStandbyOrTransient()) {
                    invokeCallback(HdmiControlManager.RESULT_INCORRECT_MODE);
                    finish();
                    return;
                }
                sendSetStreamPath();
                break;
            case STATE_WAIT_FOR_DEVICE_TO_TRANSIT_TO_STANDBY:
@@ -194,8 +213,6 @@ final class DeviceSelectAction extends FeatureAction {
                queryDevicePowerStatus();
                break;
            case STATE_WAIT_FOR_ACTIVE_SOURCE:
                // TODO: Remove the banner
                //       Display banner "Communication failed. Please check your cable or connection"
                invokeCallback(HdmiControlManager.RESULT_TIMEOUT);
                finish();
                break;
@@ -212,8 +229,4 @@ final class DeviceSelectAction extends FeatureAction {
            Slog.e(TAG, "Callback failed:" + e);
        }
    }

    int getTargetAddress() {
        return mTarget.getLogicalAddress();
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -1076,4 +1076,8 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    boolean isProhibitMode() {
        return mService.isProhibitMode();
    }

    boolean isPowerStandbyOrTransient() {
        return mService.isPowerStandbyOrTransient();
    }
}