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

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

Merge "HDMI: Ignore <Routing Information> with PA equal to sender's PA" into main

parents 1152b38d 00b42270
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -514,6 +514,18 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
    protected int handleRoutingInformation(HdmiCecMessage message) {
    protected int handleRoutingInformation(HdmiCecMessage message) {
        assertRunOnServiceThread();
        assertRunOnServiceThread();
        int physicalAddress = HdmiUtils.twoBytesToInt(message.getParams());
        int physicalAddress = HdmiUtils.twoBytesToInt(message.getParams());
        HdmiDeviceInfo sourceDevice = mService.getHdmiCecNetwork()
                .getCecDeviceInfo(message.getSource());
        // Ignore <Routing Information> messages pointing to the same physical address as the
        // message sender. In this case, we shouldn't consider the sender to be the active source.
        // See more b/321771821#comment7.
        if (sourceDevice != null
                && sourceDevice.getLogicalAddress() != Constants.ADDR_TV
                && sourceDevice.getPhysicalAddress() == physicalAddress) {
            Slog.d(TAG, "<Routing Information> is ignored, it is pointing to the same physical"
                    + " address as the message sender");
            return Constants.HANDLED;
        }
        handleRoutingChangeAndInformation(physicalAddress, message);
        handleRoutingChangeAndInformation(physicalAddress, message);
        return Constants.HANDLED;
        return Constants.HANDLED;
    }
    }
+58 −0
Original line number Original line Diff line number Diff line
@@ -659,6 +659,64 @@ public class HdmiCecLocalDevicePlaybackTest {
        mTestLooper.dispatchAll();
        mTestLooper.dispatchAll();
        assertThat(mActiveMediaSessionsPaused).isFalse();
        assertThat(mActiveMediaSessionsPaused).isFalse();
    }
    }
    @Test
    public void handleRoutingInformation_physicalAddressOfSender_Tv_activeSourceChange() {
        mHdmiCecLocalDevicePlayback.mService.getHdmiCecConfig().setStringValue(
                HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
                HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW);
        mHdmiCecLocalDevicePlayback.setActiveSource(mPlaybackLogicalAddress,
                mPlaybackPhysicalAddress, "HdmiCecLocalDevicePlaybackTest");
        mPowerManager.setInteractive(true);
        // Physical address reported in this message is the same as message sender's (TV) physical
        // address.
        HdmiCecMessage message =
                HdmiCecMessageBuilder.buildRoutingInformation(Constants.ADDR_TV, 0x0000);

        assertThat(mHdmiCecLocalDevicePlayback.handleRoutingInformation(message))
                .isEqualTo(Constants.HANDLED);
        assertThat(mHdmiCecLocalDevicePlayback.isActiveSource()).isFalse();
        assertThat(mHdmiCecLocalDevicePlayback.getActiveSource().physicalAddress).isEqualTo(
                0x0000);
        // Active source's logical address is invalidated.
        // See {@link HdmiCecLocalDevicePlayback#handleRoutingChangeAndInformation}.
        assertThat(mHdmiCecLocalDevicePlayback.getActiveSource().logicalAddress).isEqualTo(
                ADDR_INVALID);
        assertThat(mPowerManager.isInteractive()).isFalse();
    }

    @Test
    public void handleRoutingInformation_physicalAddressOfSender_notTv_noActiveSourceChange() {
        mHdmiCecLocalDevicePlayback.mService.getHdmiCecConfig().setStringValue(
                HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
                HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW);
        mHdmiCecLocalDevicePlayback.setActiveSource(mPlaybackLogicalAddress,
                mPlaybackPhysicalAddress, "HdmiCecLocalDevicePlaybackTest");
        // Add a device to the network and assert that this device is included in the list of
        // devices.
        HdmiDeviceInfo infoPlayback = HdmiDeviceInfo.cecDeviceBuilder()
                .setLogicalAddress(Constants.ADDR_PLAYBACK_3)
                .setPhysicalAddress(0x1000)
                .setPortId(PORT_1)
                .setDeviceType(HdmiDeviceInfo.DEVICE_PLAYBACK)
                .setVendorId(0x1000)
                .setDisplayName("Playback 3")
                .build();
        mHdmiControlService.getHdmiCecNetwork().addCecDevice(infoPlayback);
        mPowerManager.setInteractive(true);
        // Physical address reported in this message is the same as message sender's (Playback_3)
        // physical address.
        HdmiCecMessage message =
                HdmiCecMessageBuilder.buildRoutingInformation(Constants.ADDR_PLAYBACK_3, 0x1000);

        assertThat(mHdmiCecLocalDevicePlayback.handleRoutingInformation(message))
                .isEqualTo(Constants.HANDLED);
        assertThat(mHdmiCecLocalDevicePlayback.isActiveSource()).isTrue();
        assertThat(mHdmiCecLocalDevicePlayback.getActiveSource().physicalAddress).isEqualTo(
                mPlaybackPhysicalAddress);
        assertThat(mHdmiCecLocalDevicePlayback.getActiveSource().logicalAddress).isEqualTo(
                mPlaybackLogicalAddress);
        assertThat(mPowerManager.isInteractive()).isTrue();
    }


    @Test
    @Test
    public void handleSetStreamPath() {
    public void handleSetStreamPath() {