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

Commit 78b3dd9f authored by Nathalie Le Clair's avatar Nathalie Le Clair
Browse files

Only wake up at the start of OneTouchPlayAction

Before this CL, the device was waking up unexpectedly in following
situation:
1. a OneTouchPlayAction is started
2. the device starts going to standby, which takes some time
3. before the standby is completed, the connected TV reports its power
   status and the device is woken up again.

This is solved by no longer waking the device when the connected TV
reports its power status. It is enough to send an <Active Source>
message.

Test: atest, new test passes with the CL and fails without
Bug: 230189461
Change-Id: I8715af82d863e935012506ae32c722d80b40e5da
parent a8299cd5
Loading
Loading
Loading
Loading
+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;