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

Commit 9ec5dee9 authored by Amy's avatar Amy Committed by shubang
Browse files

Add a delay state into DeviceDiscoveryAction.

ag/5288959

Delay the action for 1000 ms when the current device is not a TV.
Give devices just connected to the currect device enough time to prepare
to handle incoming cec commands during DeviceDiscoveryAction.

Note that this also means TIF will be updated with delay.

Test: local tested.
Change-Id: I7df21165dc98e1388f47a1bdfe2df6efb433d94c
parent 726a71c0
Loading
Loading
Loading
Loading
+39 −2
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
    private static final int STATE_WAITING_FOR_OSD_NAME = 3;
    // State in which the action is waiting for gathering vendor id of non-local devices.
    private static final int STATE_WAITING_FOR_VENDOR_ID = 4;
    // State in which the action is waiting for devices to be ready
    private static final int STATE_WAITING_FOR_DEVICES = 5;

    /**
     * Interface used to report result of device discovery.
@@ -90,15 +92,27 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
    private int mProcessedDeviceCount = 0;
    private int mTimeoutRetry = 0;
    private boolean mIsTvDevice = source().mService.isTvDevice();
    private final int mDelayPeriod;

    /**
     * Constructor.
     *
     * @param source an instance of {@link HdmiCecLocalDevice}.
     * @param delay delay action for this period between query Physical Address and polling
     */
    DeviceDiscoveryAction(HdmiCecLocalDevice source, DeviceDiscoveryCallback callback) {
    DeviceDiscoveryAction(HdmiCecLocalDevice source, DeviceDiscoveryCallback callback, int delay) {
        super(source);
        mCallback = Preconditions.checkNotNull(callback);
        mDelayPeriod = delay;
    }

    /**
     * Constructor.
     *
     * @param source an instance of {@link HdmiCecLocalDevice}.
     */
    DeviceDiscoveryAction(HdmiCecLocalDevice source, DeviceDiscoveryCallback callback) {
        this(source, callback, 0);
    }

    @Override
@@ -117,8 +131,12 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {

                Slog.v(TAG, "Device detected: " + ackedAddress);
                allocateDevices(ackedAddress);
                if (mDelayPeriod > 0) {
                    startToDelayAction();
                } else {
                    startPhysicalAddressStage();
                }
            }
        }, Constants.POLL_ITERATION_REVERSE_ORDER
            | Constants.POLL_STRATEGY_REMOTES_DEVICES, HdmiConfig.DEVICE_POLLING_RETRY);
        return true;
@@ -131,6 +149,13 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
        }
    }

    private void startToDelayAction() {
        Slog.v(TAG, "Waiting for connected devices to be ready");
        mState = STATE_WAITING_FOR_DEVICES;

        checkAndProceedStage();
    }

    private void startPhysicalAddressStage() {
        Slog.v(TAG, "Start [Physical Address Stage]:" + mDevices.size());
        mProcessedDeviceCount = 0;
@@ -159,6 +184,11 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
        addTimer(mState, HdmiConfig.TIMEOUT_MS);
    }

    private void delayActionWithTimePeriod(int timeDelay) {
        mActionTimer.clearTimerMessage();
        addTimer(mState, timeDelay);
    }

    private void startOsdNameStage() {
        Slog.v(TAG, "Start [Osd Name Stage]:" + mDevices.size());
        mProcessedDeviceCount = 0;
@@ -385,6 +415,9 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
    private void sendQueryCommand() {
        int address = mDevices.get(mProcessedDeviceCount).mLogicalAddress;
        switch (mState) {
            case STATE_WAITING_FOR_DEVICES:
                delayActionWithTimePeriod(mDelayPeriod);
                return;
            case STATE_WAITING_FOR_PHYSICAL_ADDRESS:
                queryPhysicalAddress(address);
                return;
@@ -405,6 +438,10 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
            return;
        }

        if (mState == STATE_WAITING_FOR_DEVICES) {
            startPhysicalAddressStage();
            return;
        }
        if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) {
            sendQueryCommand();
            return;