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

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

HDMI: Check if sink has CEC enabled after hotplug

Bug: 323557013
Test: atest HdmiControlServiceTest
Change-Id: I4bd2b117e8a15f70086a7171ac05cfa397a7bee7
parent 61b0f8fa
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1366,6 +1366,12 @@ public class HdmiControlService extends SystemService {
                                    // we don't call onInitializeCecComplete()
                                    // since we reallocate the logical address only.
                                    onInitializeCecComplete(initiatedBy);
                                } else if (initiatedBy == INITIATED_BY_HOTPLUG
                                        && mDisplayStatusCallback == null) {
                                    // Force to update display status for hotplug event.
                                    synchronized (mLock) {
                                        announceHdmiControlStatusChange(mHdmiControlEnabled);
                                    }
                                }
                                // We remove local devices here, instead of before the start of
                                // address allocation, to prevent multiple local devices of the
+61 −2
Original line number Diff line number Diff line
@@ -169,14 +169,14 @@ public class HdmiControlServiceTest {
                        .setEarcSupported(true)
                        .build();
        mHdmiPortInfo[3] =
                new HdmiPortInfo.Builder(4, HdmiPortInfo.PORT_INPUT, 0x3000)
                new HdmiPortInfo.Builder(4, HdmiPortInfo.PORT_OUTPUT, 0x3000)
                        .setCecSupported(true)
                        .setMhlSupported(false)
                        .setArcSupported(false)
                        .setEarcSupported(false)
                        .build();
        mHdmiPortInfo[4] =
                new HdmiPortInfo.Builder(4, HdmiPortInfo.PORT_OUTPUT, 0x3000)
                new HdmiPortInfo.Builder(5, HdmiPortInfo.PORT_OUTPUT, 0x3000)
                        .setCecSupported(true)
                        .setMhlSupported(false)
                        .setArcSupported(false)
@@ -840,6 +840,65 @@ public class HdmiControlServiceTest {
        assertThat(hdmiControlStatusCallback.mCecAvailable).isTrue();
    }

    @Test
    public void onHotPlugIn_CecDisabledOnTv_CecNotAvailable() {
        HdmiControlStatusCallback hdmiControlStatusCallback = new HdmiControlStatusCallback();
        mHdmiControlServiceSpy.addHdmiControlStatusChangeListener(hdmiControlStatusCallback);
        mTestLooper.dispatchAll();

        mHdmiControlServiceSpy.setPowerStatus(HdmiControlManager.POWER_STATUS_ON);
        mHdmiControlServiceSpy.playback().removeAction(DevicePowerStatusAction.class);
        mNativeWrapper.clearResultMessages();
        mTestLooper.dispatchAll();

        mHdmiControlServiceSpy.onHotplug(4, true);
        mTestLooper.dispatchAll();

        HdmiCecMessage giveDevicePowerStatus =
                HdmiCecMessageBuilder.buildGiveDevicePowerStatus(
                        mHdmiControlServiceSpy.playback().getDeviceInfo().getLogicalAddress(),
                        Constants.ADDR_TV);
        assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus);
        // Wait for DevicePowerStatusAction to finish.
        mTestLooper.moveTimeForward(HdmiConfig.TIMEOUT_MS);
        mTestLooper.dispatchAll();
        mTestLooper.moveTimeForward(HdmiConfig.TIMEOUT_MS);
        mTestLooper.dispatchAll();

        assertThat(hdmiControlStatusCallback.mCecEnabled).isTrue();
        assertThat(hdmiControlStatusCallback.mCecAvailable).isFalse();
    }

    @Test
    public void onHotPlugIn_CecEnabledOnTv_CecAvailable() {
        HdmiControlStatusCallback hdmiControlStatusCallback = new HdmiControlStatusCallback();
        mHdmiControlServiceSpy.addHdmiControlStatusChangeListener(hdmiControlStatusCallback);
        mTestLooper.dispatchAll();

        mHdmiControlServiceSpy.setPowerStatus(HdmiControlManager.POWER_STATUS_ON);
        mHdmiControlServiceSpy.playback().removeAction(DevicePowerStatusAction.class);
        mNativeWrapper.clearResultMessages();
        mTestLooper.dispatchAll();

        mHdmiControlServiceSpy.onHotplug(4, true);
        mTestLooper.dispatchAll();

        HdmiCecMessage giveDevicePowerStatus =
                HdmiCecMessageBuilder.buildGiveDevicePowerStatus(
                        mHdmiControlServiceSpy.playback().getDeviceInfo().getLogicalAddress(),
                        Constants.ADDR_TV);
        HdmiCecMessage reportPowerStatus =
                HdmiCecMessageBuilder.buildReportPowerStatus(
                        Constants.ADDR_TV,
                        mHdmiControlServiceSpy.playback().getDeviceInfo().getLogicalAddress(),
                        HdmiControlManager.POWER_STATUS_ON);
        assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus);
        mNativeWrapper.onCecMessage(reportPowerStatus);
        mTestLooper.dispatchAll();

        assertThat(hdmiControlStatusCallback.mCecEnabled).isTrue();
        assertThat(hdmiControlStatusCallback.mCecAvailable).isTrue();
    }
    @Test
    public void handleCecCommand_errorParameter_returnsAbortInvalidOperand() {
        // Validity ERROR_PARAMETER. Taken from HdmiCecMessageValidatorTest#isValid_menuStatus