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

Commit b3ecb72a authored by Jungshik Jang's avatar Jungshik Jang
Browse files

Use async polling for HPD action

Since Device polling holds whole IO thread while it's running,
other sending requests would be blocked until it's finished.
Usually polling takes more than 1 seconds and some action might
be timeouted.
This change sends polling message asynchrousely for
each device address.

Bug: 17381548

Change-Id: I2f47931c5882649d6ac56092986d34d1da48f710
parent 5c0ed94d
Loading
Loading
Loading
Loading
+25 −17
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.server.hdmi.HdmiControlService.DevicePollingCallback;
import libcore.util.EmptyArray;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
@@ -367,7 +368,8 @@ final class HdmiCecController {

        // Extract polling candidates. No need to poll against local devices.
        List<Integer> pollingCandidates = pickPollCandidates(pickStrategy);
        runDevicePolling(sourceAddress, pollingCandidates, retryCount, callback);
        ArrayList<Integer> allocated = new ArrayList<>();
        runDevicePolling(sourceAddress, pollingCandidates, retryCount, callback, allocated);
    }

    /**
@@ -395,7 +397,7 @@ final class HdmiCecController {
        }

        int iterationStrategy = pickStrategy & Constants.POLL_ITERATION_STRATEGY_MASK;
        ArrayList<Integer> pollingCandidates = new ArrayList<>();
        LinkedList<Integer> pollingCandidates = new LinkedList<>();
        switch (iterationStrategy) {
            case Constants.POLL_ITERATION_IN_ORDER:
                for (int i = Constants.ADDR_TV; i <= Constants.ADDR_SPECIFIC_USE; ++i) {
@@ -430,27 +432,33 @@ final class HdmiCecController {
    @ServiceThreadOnly
    private void runDevicePolling(final int sourceAddress,
            final List<Integer> candidates, final int retryCount,
            final DevicePollingCallback callback) {
            final DevicePollingCallback callback, final List<Integer> allocated) {
        assertRunOnServiceThread();
        if (candidates.isEmpty()) {
            if (callback != null) {
                HdmiLogger.debug("[P]:AllocatedAddress=%s", allocated.toString());
                callback.onPollingFinished(allocated);
            }
            return;
        }

        final Integer candidate = candidates.remove(0);
        // Proceed polling action for the next address once polling action for the
        // previous address is done.
        runOnIoThread(new Runnable() {
            @Override
            public void run() {
                final ArrayList<Integer> allocated = new ArrayList<>();
                for (Integer address : candidates) {
                    if (sendPollMessage(sourceAddress, address, retryCount)) {
                        allocated.add(address);
                    }
                if (sendPollMessage(sourceAddress, candidate, retryCount)) {
                    allocated.add(candidate);
                }
                HdmiLogger.debug("[P]:Allocated Address=" + allocated);
                if (callback != null) {
                runOnServiceThread(new Runnable() {
                    @Override
                    public void run() {
                            callback.onPollingFinished(allocated);
                        runDevicePolling(sourceAddress, candidates, retryCount, callback,
                                allocated);
                    }
                });
            }
            }
        });
    }