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

Commit ca29d4cb authored by Nathalie Le Clair's avatar Nathalie Le Clair Committed by Android (Google) Code Review
Browse files

Merge changes I8715af82,I547c47a3

* changes:
  Only wake up at the start of OneTouchPlayAction
  Remove ActiveSourceAction immediately on standby
parents 6b8d2655 78b3dd9f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1262,6 +1262,7 @@ abstract class HdmiCecLocalDevice {
            boolean initiatedByCec, final PendingActionClearedCallback originalCallback) {
        removeAction(AbsoluteVolumeAudioStatusAction.class);
        removeAction(SetAudioVolumeLevelDiscoveryAction.class);
        removeAction(ActiveSourceAction.class);

        mPendingActionClearedCallback =
                new PendingActionClearedCallback() {
+16 −4
Original line number Diff line number Diff line
@@ -91,7 +91,8 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction {

        boolean is20TargetOnBefore = mIsCec20 && getTargetDevicePowerStatus(mSource, mTargetAddress,
                HdmiControlManager.POWER_STATUS_UNKNOWN) == HdmiControlManager.POWER_STATUS_ON;
        broadcastActiveSource();
        // Make the device the active source.
        setAndBroadcastActiveSource();
        // If the device is not an audio system itself, request the connected audio system to
        // turn on.
        if (shouldTurnOnConnectedAudioSystem()) {
@@ -108,9 +109,11 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction {
                queryDevicePowerStatus();
            } else if (targetPowerStatus == HdmiControlManager.POWER_STATUS_ON) {
                if (!is20TargetOnBefore) {
                    // If the device is still the active source, send the <Active Source> message
                    // again.
                    // Suppress 2nd <Active Source> message if the target device was already on when
                    // the 1st one was sent.
                    broadcastActiveSource();
                    maySendActiveSource();
                }
                finishWithCallback(HdmiControlManager.RESULT_SUCCESS);
                return true;
@@ -121,7 +124,9 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction {
        return true;
    }

    private void broadcastActiveSource() {
    private void setAndBroadcastActiveSource() {
        // If the device wasn´t the active source yet,
        // this makes it the active source and wakes it up.
        mSource.mService.setAndBroadcastActiveSourceFromOneDeviceType(
                mTargetAddress, getSourcePath(), "OneTouchPlayAction#broadcastActiveSource()");
        // When OneTouchPlay is called, client side should be responsible to send out the intent
@@ -135,6 +140,11 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction {
        mSource.setLocalActivePort(Constants.CEC_SWITCH_HOME);
    }

    private void maySendActiveSource() {
        // Only send <Active Source> if the device is already the active source at this time.
        mSource.maySendActiveSource(mTargetAddress);
    }

    private void queryDevicePowerStatus() {
        sendCommand(HdmiCecMessageBuilder.buildGiveDevicePowerStatus(getSourceAddress(),
                mTargetAddress));
@@ -149,7 +159,9 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction {
        if (cmd.getOpcode() == Constants.MESSAGE_REPORT_POWER_STATUS) {
            int status = cmd.getParams()[0];
            if (status == HdmiControlManager.POWER_STATUS_ON) {
                broadcastActiveSource();
                // If the device is still the active source, send the <Active Source> message
                // again.
                maySendActiveSource();
                finishWithCallback(HdmiControlManager.RESULT_SUCCESS);
            }
            return true;
+40 −0
Original line number Diff line number Diff line
@@ -628,6 +628,46 @@ public class OneTouchPlayActionTest {
        assertThat(mNativeWrapper.getResultMessages()).contains(standbyMessage);
    }

    @Test
    public void noWakeUpOnReportPowerStatus() throws Exception {
        setUp(true);

        HdmiCecLocalDevicePlayback playbackDevice = new HdmiCecLocalDevicePlayback(
                mHdmiControlService);
        playbackDevice.init();
        mLocalDevices.add(playbackDevice);
        mHdmiControlService.allocateLogicalAddress(mLocalDevices, INITIATED_BY_ENABLE_CEC);
        mTestLooper.dispatchAll();

        mNativeWrapper.setPollAddressResponse(ADDR_TV, SendMessageResult.SUCCESS);
        mHdmiControlService.getHdmiCecNetwork().addCecDevice(INFO_TV);
        mTestLooper.dispatchAll();
        mNativeWrapper.clearResultMessages();

        TestActionTimer actionTimer = new TestActionTimer();
        TestCallback callback = new TestCallback();
        OneTouchPlayAction action = createOneTouchPlayAction(playbackDevice, actionTimer, callback,
                false);
        playbackDevice.addAndStartAction(action);
        mTestLooper.dispatchAll();

        assertThat(mPowerManager.isInteractive()).isTrue();
        mPowerManager.setInteractive(false);
        mTestLooper.dispatchAll();

        HdmiCecMessage reportPowerStatusOn =
                HdmiCecMessage.build(
                        ADDR_TV,
                        playbackDevice.getDeviceInfo().getLogicalAddress(),
                        Constants.MESSAGE_REPORT_POWER_STATUS,
                        POWER_ON);
        action.processCommand(reportPowerStatusOn);
        mTestLooper.dispatchAll();

        assertThat(mPowerManager.isInteractive()).isFalse();
        assertThat(callback.getResult()).isEqualTo(HdmiControlManager.RESULT_SUCCESS);
    }

    private static class TestActionTimer implements ActionTimer {
        private int mState;