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

Commit d2819821 authored by Paul's avatar Paul Committed by Paul Colța
Browse files

HDMICEC: Implement active tracking of CEC Network for Playback devices

Poll all the non-local logical addresses when the device is either turned on or when the CEC setting is enabled. After that the addresses are polled once every 1 minute.
Implement method inside HdmiCecLocalDevicePlayback that launches a DeviceDiscoveryAction with a HotplugDetectionAction inside its callback.
Add unit tests for DeviceDiscoveryAction and HotplugDetectionAction for HdmiCecLocalDevicePlayback.

Bug: 199057329
Test: make && atest CtsHdmiCecHostTestCases
Change-Id: I1133cdbced4a1e40e299a95bb9ced565c8059774
parent c0c38ddd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ final class DeviceSelectActionFromPlayback extends HdmiCecFeatureAction {
        mIsCec20 = isCec20;
    }

    private int getTargetAddress() {
    int getTargetAddress() {
        return mTarget.getLogicalAddress();
    }

+2 −1
Original line number Diff line number Diff line
@@ -324,7 +324,8 @@ final class HdmiCecController {
    /**
     * Return the physical address of the device.
     *
     * <p>Declared as package-private. accessed by {@link HdmiControlService} only.
     * <p>Declared as package-private. accessed by {@link HdmiControlService} and
     * {@link HdmiCecNetwork} only.
     *
     * @return CEC physical address of the device. The range of success address
     *         is between 0x0000 and 0xFFFF. If failed it returns -1
+18 −11
Original line number Diff line number Diff line
@@ -274,6 +274,13 @@ abstract class HdmiCecLocalDevice {
        return false;
    }

    // Clear all device info.
    @ServiceThreadOnly
    void clearDeviceInfoList() {
        assertRunOnServiceThread();
        mService.getHdmiCecNetwork().clearDeviceList();
    }

    @ServiceThreadOnly
    @Constants.HandleMessageResult
    protected final int onMessage(HdmiCecMessage message) {
+38 −2
Original line number Diff line number Diff line
@@ -105,9 +105,42 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
                        }
                    });
        }
        launchDeviceDiscovery();
        startQueuedActions();
    }

    @ServiceThreadOnly
    private void launchDeviceDiscovery() {
        assertRunOnServiceThread();
        clearDeviceInfoList();
        DeviceDiscoveryAction action = new DeviceDiscoveryAction(this,
                new DeviceDiscoveryAction.DeviceDiscoveryCallback() {
                    @Override
                    public void onDeviceDiscoveryDone(List<HdmiDeviceInfo> deviceInfos) {
                        for (HdmiDeviceInfo info : deviceInfos) {
                            mService.getHdmiCecNetwork().addCecDevice(info);
                        }

                        // Since we removed all devices when it starts and device discovery action
                        // does not poll local devices, we should put device info of local device
                        // manually here.
                        for (HdmiCecLocalDevice device : mService.getAllLocalDevices()) {
                            synchronized (device.mLock) {
                                mService.getHdmiCecNetwork().addCecDevice(device.getDeviceInfo());
                            }
                        }

                        List<HotplugDetectionAction> hotplugActions =
                                getActions(HotplugDetectionAction.class);
                        if (hotplugActions.isEmpty()) {
                            addAndStartAction(
                                    new HotplugDetectionAction(HdmiCecLocalDevicePlayback.this));
                        }
                    }
                });
        addAndStartAction(action);
    }

    @Override
    @ServiceThreadOnly
    protected int getPreferredAddress() {
@@ -450,9 +483,12 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
    @Override
    @ServiceThreadOnly
    protected void disableDevice(boolean initiatedByCec, PendingActionClearedCallback callback) {
        super.disableDevice(initiatedByCec, callback);

        assertRunOnServiceThread();
        removeAction(DeviceDiscoveryAction.class);
        removeAction(HotplugDetectionAction.class);
        removeAction(NewDeviceAction.class);
        super.disableDevice(initiatedByCec, callback);
        clearDeviceInfoList();
        checkIfPendingActionsCleared();
    }

+1 −8
Original line number Diff line number Diff line
@@ -685,7 +685,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
                            mService.getHdmiCecNetwork().addCecDevice(info);
                        }

                        // Since we removed all devices when it's start and
                        // Since we removed all devices when it starts and
                        // device discovery action does not poll local devices,
                        // we should put device info of local device manually here
                        for (HdmiCecLocalDevice device : mService.getAllLocalDevices()) {
@@ -734,13 +734,6 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        }
    }

    // Clear all device info.
    @ServiceThreadOnly
    private void clearDeviceInfoList() {
        assertRunOnServiceThread();
        mService.getHdmiCecNetwork().clearDeviceList();
    }

    @ServiceThreadOnly
    // Seq #32
    void changeSystemAudioMode(boolean enabled, IHdmiControlCallback callback) {
Loading