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

Commit 1152b38d authored by Paul Colța's avatar Paul Colța Committed by Android (Google) Code Review
Browse files

Merge "HDMI: TV should ignore <Standby> from non-AS devices" into main

parents eabff365 57e26739
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -479,6 +479,22 @@ public final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        return Constants.HANDLED;
    }

    @Override
    @ServiceThreadOnly
    @Constants.HandleMessageResult
    protected int handleStandby(HdmiCecMessage message) {
        assertRunOnServiceThread();

        // Ignore <Standby> from non-active source device.
        if (getActiveSource().logicalAddress != message.getSource()) {
            Slog.d(TAG, "<Standby> was not sent by the current active source, ignoring."
                    + " Current active source has logical address "
                    + getActiveSource().logicalAddress);
            return Constants.HANDLED;
        }
        return super.handleStandby(message);
    }

    @Override
    @ServiceThreadOnly
    @Constants.HandleMessageResult
+39 −0
Original line number Diff line number Diff line
@@ -169,6 +169,11 @@ public class HdmiCecLocalDeviceTvTest {
                        return false;
                    }

                    @Override
                    boolean isPowerOnOrTransient() {
                        return true;
                    }

                    @Override
                    void invokeDeviceEventListeners(HdmiDeviceInfo device, int status) {
                        mDeviceEventListeners.add(new DeviceEventListener(device, status));
@@ -1839,4 +1844,38 @@ public class HdmiCecLocalDeviceTvTest {

        assertThat(mNativeWrapper.getResultMessages()).doesNotContain(activeSourceFromTv);
    }

    @Test
    public void handleStandby_fromActiveSource_standby() {
        mPowerManager.setInteractive(true);
        mHdmiControlService.allocateLogicalAddress(mLocalDevices, INITIATED_BY_ENABLE_CEC);
        mHdmiControlService.setActiveSource(ADDR_PLAYBACK_1, 0x1000,
                "HdmiCecLocalDeviceTvTest");
        mTestLooper.dispatchAll();

        HdmiCecMessage standbyMessage = HdmiCecMessageBuilder.buildStandby(ADDR_PLAYBACK_1,
                ADDR_TV);
        assertThat(mHdmiCecLocalDeviceTv.dispatchMessage(standbyMessage))
                .isEqualTo(Constants.HANDLED);
        mTestLooper.dispatchAll();

        assertThat(mPowerManager.isInteractive()).isFalse();
    }

    @Test
    public void handleStandby_fromNonActiveSource_noStandby() {
        mPowerManager.setInteractive(true);
        mHdmiControlService.allocateLogicalAddress(mLocalDevices, INITIATED_BY_ENABLE_CEC);
        mHdmiControlService.setActiveSource(ADDR_PLAYBACK_2, 0x2000,
                "HdmiCecLocalDeviceTvTest");
        mTestLooper.dispatchAll();

        HdmiCecMessage standbyMessage = HdmiCecMessageBuilder.buildStandby(ADDR_PLAYBACK_1,
                ADDR_TV);
        assertThat(mHdmiCecLocalDeviceTv.dispatchMessage(standbyMessage))
                .isEqualTo(Constants.HANDLED);
        mTestLooper.dispatchAll();

        assertThat(mPowerManager.isInteractive()).isTrue();
    }
}