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

Commit a9913ce0 authored by Paul Colta's avatar Paul Colta
Browse files

HDMI: Reset WakeUpMessageReceived flag when source device asserts <AS>

This patch makes sure the device will send `<Standby>` message when
going to sleep after asserting active source.

Bug: 383849602
Test: atest com.android.server.hdmi
Flag: EXEMPT bugfix
Change-Id: I287f5cf39bc2f285795e16b37274b764453e2482
parent 06994af7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -408,6 +408,7 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
        if (!isActiveSource()) {
            return;
        }
        mService.setWakeUpMessageReceived(false);
        addAndStartAction(new ActiveSourceAction(this, dest), true);
    }

+4 −0
Original line number Diff line number Diff line
@@ -3861,6 +3861,10 @@ public class HdmiControlService extends SystemService {
        return mWakeUpMessageReceived;
    }

    void setWakeUpMessageReceived(boolean wakeUpMessageReceived) {
        mWakeUpMessageReceived = wakeUpMessageReceived;
    }

    protected boolean isStandbyMessageReceived() {
        return mStandbyMessageReceived;
    }
+46 −0
Original line number Diff line number Diff line
@@ -2322,6 +2322,52 @@ public class HdmiCecLocalDevicePlaybackTest {
        assertThat(mNativeWrapper.getResultMessages()).doesNotContain(featureAbortReleased);
    }

    @Test
    public void hotplugOut_hotPlugIn_standbyFromPlayback_sendStandbyMessage() {
        mHdmiCecLocalDevicePlayback.mService.getHdmiCecConfig().setStringValue(
                HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE,
                HdmiControlManager.POWER_CONTROL_MODE_TV);
        mTestLooper.dispatchAll();

        mPowerManager.setInteractive(true);
        mNativeWrapper.onHotplugEvent(1, false);
        mTestLooper.dispatchAll();
        // Advance time to trigger the device to go to standby after hotplug out.
        mPowerManagerInternal.setIdleDuration(
                HdmiCecLocalDevicePlayback.STANDBY_AFTER_HOTPLUG_OUT_DELAY_MS);
        mTestLooper.moveTimeForward(HdmiCecLocalDevicePlayback.STANDBY_AFTER_HOTPLUG_OUT_DELAY_MS);
        mTestLooper.dispatchAll();

        assertThat(mPowerManager.isInteractive()).isFalse();
        assertThat(mHdmiCecLocalDevicePlayback.getActiveSource().logicalAddress)
                .isNotEqualTo(mPlaybackLogicalAddress);
        mNativeWrapper.onHotplugEvent(1, true);
        mNativeWrapper.setPhysicalAddress(mPlaybackPhysicalAddress);
        mNativeWrapper.clearResultMessages();
        mTestLooper.dispatchAll();

        HdmiCecMessage setStreamPathToPlayback = HdmiCecMessageBuilder.buildSetStreamPath(ADDR_TV,
                mPlaybackPhysicalAddress);
        assertThat(mHdmiCecLocalDevicePlayback.handleSetStreamPath(setStreamPathToPlayback))
                .isEqualTo(Constants.HANDLED);
        mTestLooper.dispatchAll();

        // Verify that the device broadcasts an <Active Source> message.
        HdmiCecMessage activeSource =
                HdmiCecMessageBuilder.buildActiveSource(mPlaybackLogicalAddress,
                        mPlaybackPhysicalAddress);
        assertThat(mNativeWrapper.getResultMessages()).contains(activeSource);

        // Trigger standby and verify the <Standby> message is sent to the TV.
        mHdmiCecLocalDevicePlayback.onStandby(false, HdmiControlService.STANDBY_SCREEN_OFF);
        mTestLooper.dispatchAll();

        HdmiCecMessage standbyMessageToTv =
                HdmiCecMessageBuilder.buildStandby(
                        mHdmiCecLocalDevicePlayback.getDeviceInfo().getLogicalAddress(), ADDR_TV);
        assertThat(mNativeWrapper.getResultMessages()).contains(standbyMessageToTv);
    }

    @Test
    public void onHotplugInAfterHotplugOut_noStandbyAfterDelay() {
        mPowerManager.setInteractive(true);