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

Commit 99b8ad87 authored by Paul Colta's avatar Paul Colta
Browse files

HDMI: Avoid creating multiple DeviceDiscoveryActions for a local device

After an OTT device wakes-up, a hot-plug can be trigerred by the TV.
Both actions (wake-up & hot-plug) will trigger address allocations which
will end-up launching a `DeviceDiscoveryAction`. This has to be avoided
to not send more messages than necessary and to not have any issues with
the known list of connected devices.

Test: atest HdmiCecLocalDevicePlaybackTest
Bug: 314264570
Bug: 264611886
Change-Id: Ib0e7594d0fb21eaba5934edb8a2b1dc0dc24f6f6
parent 6ea41f31
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1117,6 +1117,7 @@ abstract class HdmiCecLocalDevice extends HdmiLocalDevice {
    }

    // Returns all actions matched with given class type.
    @VisibleForTesting
    @ServiceThreadOnly
    <T extends HdmiCecFeatureAction> List<T> getActions(final Class<T> clazz) {
        assertRunOnServiceThread();
+4 −0
Original line number Diff line number Diff line
@@ -126,6 +126,10 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
    private void launchDeviceDiscovery() {
        assertRunOnServiceThread();
        clearDeviceInfoList();
        if (hasAction(DeviceDiscoveryAction.class)) {
            Slog.i(TAG, "Device Discovery Action is in progress. Restarting.");
            removeAction(DeviceDiscoveryAction.class);
        }
        DeviceDiscoveryAction action = new DeviceDiscoveryAction(this,
                new DeviceDiscoveryAction.DeviceDiscoveryCallback() {
                    @Override
+12 −0
Original line number Diff line number Diff line
@@ -1773,6 +1773,18 @@ public class HdmiCecLocalDevicePlaybackTest {
        assertThat(mNativeWrapper.getResultMessages()).contains(givePhysicalAddress);
    }

    @Test
    public void wakeUp_hotPlugIn_invokesDeviceDiscoveryOnce() {
        mNativeWrapper.setPollAddressResponse(Constants.ADDR_PLAYBACK_2, SendMessageResult.SUCCESS);
        mHdmiControlService.onWakeUp(HdmiControlService.WAKE_UP_SCREEN_ON);
        mTestLooper.dispatchAll();

        mNativeWrapper.onHotplugEvent(1, true);
        mTestLooper.dispatchAll();

        assertThat(mHdmiCecLocalDevicePlayback.getActions(DeviceDiscoveryAction.class)).hasSize(1);
    }

    @Test
    public void hotplugDetectionAction_addDevice() {
        int otherPlaybackLogicalAddress = mPlaybackLogicalAddress == Constants.ADDR_PLAYBACK_2