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

Commit cf4c4f45 authored by Sherry Huang's avatar Sherry Huang Committed by Android (Google) Code Review
Browse files

Merge "HDMI: Add a timeout between polls for HotplugDetectionAction" into main

parents e5d335a0 8dc227bb
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -528,15 +528,17 @@ final class HdmiCecController {
     */
    @ServiceThreadOnly
    void pollDevices(DevicePollingCallback callback, int sourceAddress, int pickStrategy,
            int retryCount) {
            int retryCount, long pollingMessageInterval) {
        assertRunOnServiceThread();

        // Extract polling candidates. No need to poll against local devices.
        List<Integer> pollingCandidates = pickPollCandidates(pickStrategy);
        ArrayList<Integer> allocated = new ArrayList<>();
        // pollStarted indication to avoid polling delay for the first message
        mControlHandler.postDelayed(
                () -> runDevicePolling(
                        sourceAddress, pollingCandidates, retryCount, callback, allocated),
                ()
                        -> runDevicePolling(sourceAddress, pollingCandidates, retryCount, callback,
                                allocated, pollingMessageInterval, /**pollStarted**/ false),
                mPollDevicesDelay);
    }

@@ -576,9 +578,10 @@ final class HdmiCecController {
    }

    @ServiceThreadOnly
    private void runDevicePolling(final int sourceAddress,
            final List<Integer> candidates, final int retryCount,
            final DevicePollingCallback callback, final List<Integer> allocated) {
    private void runDevicePolling(final int sourceAddress, final List<Integer> candidates,
            final int retryCount, final DevicePollingCallback callback,
            final List<Integer> allocated, final long pollingMessageInterval,
            final boolean pollStarted) {
        assertRunOnServiceThread();
        if (candidates.isEmpty()) {
            if (callback != null) {
@@ -587,11 +590,10 @@ final class HdmiCecController {
            }
            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() {
        mIoHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (sendPollMessage(sourceAddress, candidate, retryCount)) {
@@ -600,12 +602,12 @@ final class HdmiCecController {
                runOnServiceThread(new Runnable() {
                    @Override
                    public void run() {
                        runDevicePolling(sourceAddress, candidates, retryCount, callback,
                                allocated);
                        runDevicePolling(sourceAddress, candidates, retryCount, callback, allocated,
                                pollingMessageInterval, /**pollStarted**/ true);
                    }
                });
            }
        });
        }, pollStarted ? pollingMessageInterval : 0);
    }

    @IoThreadOnly
+7 −1
Original line number Diff line number Diff line
@@ -229,7 +229,13 @@ abstract class HdmiCecFeatureAction {

    protected final void pollDevices(DevicePollingCallback callback, int pickStrategy,
            int retryCount) {
        mService.pollDevices(callback, getSourceAddress(), pickStrategy, retryCount);
        pollDevices(callback, pickStrategy, retryCount, 0);
    }

    protected final void pollDevices(DevicePollingCallback callback, int pickStrategy,
            int retryCount, long pollingMessageInterval) {
        mService.pollDevices(
                callback, getSourceAddress(), pickStrategy, retryCount, pollingMessageInterval);
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -1823,10 +1823,10 @@ public class HdmiControlService extends SystemService {
     */
    @ServiceThreadOnly
    void pollDevices(DevicePollingCallback callback, int sourceAddress, int pickStrategy,
            int retryCount) {
            int retryCount, long pollingMessageInterval) {
        assertRunOnServiceThread();
        mCecController.pollDevices(callback, sourceAddress, checkPollStrategy(pickStrategy),
                retryCount);
                retryCount, pollingMessageInterval);
    }

    private int checkPollStrategy(int pickStrategy) {
+23 −15
Original line number Diff line number Diff line
@@ -38,8 +38,10 @@ import java.util.List;
final class HotplugDetectionAction extends HdmiCecFeatureAction {
    private static final String TAG = "HotPlugDetectionAction";

    public static final int POLLING_INTERVAL_MS_FOR_TV = 5000;
    public static final int POLLING_INTERVAL_MS_FOR_PLAYBACK = 60000;
    public static final long POLLING_MESSAGE_INTERVAL_MS_FOR_TV = 0;
    public static final long POLLING_MESSAGE_INTERVAL_MS_FOR_PLAYBACK = 500;
    public static final int POLLING_BATCH_INTERVAL_MS_FOR_TV = 5000;
    public static final int POLLING_BATCH_INTERVAL_MS_FOR_PLAYBACK = 60000;
    public static final int TIMEOUT_COUNT = 3;
    private static final int AVR_COUNT_MAX = 3;

@@ -69,8 +71,9 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
        super(source);
    }

    private int getPollingInterval() {
        return mIsTvDevice ? POLLING_INTERVAL_MS_FOR_TV : POLLING_INTERVAL_MS_FOR_PLAYBACK;
    private int getPollingBatchInterval() {
        return mIsTvDevice ? POLLING_BATCH_INTERVAL_MS_FOR_TV
                           : POLLING_BATCH_INTERVAL_MS_FOR_PLAYBACK;
    }

    @Override
@@ -83,7 +86,7 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
        // Start timer without polling.
        // The first check for all devices will be initiated 15 seconds later for TV panels and 60
        // seconds later for playback devices.
        addTimer(mState, getPollingInterval());
        addTimer(mState, getPollingBatchInterval());
        return true;
    }

@@ -107,11 +110,11 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
                } else if (tv().isSystemAudioActivated()) {
                    pollAudioSystem();
                }
                addTimer(mState, POLLING_INTERVAL_MS_FOR_TV);
                addTimer(mState, POLLING_BATCH_INTERVAL_MS_FOR_TV);
                return;
            }
            pollAllDevices();
            addTimer(mState, POLLING_INTERVAL_MS_FOR_PLAYBACK);
            addTimer(mState, POLLING_BATCH_INTERVAL_MS_FOR_PLAYBACK);
        }
    }

@@ -127,19 +130,24 @@ final class HotplugDetectionAction extends HdmiCecFeatureAction {
        mState = STATE_WAIT_FOR_NEXT_POLLING;
        pollAllDevices();

        addTimer(mState, getPollingInterval());
        addTimer(mState, getPollingBatchInterval());
    }

    private void pollAllDevices() {
        Slog.v(TAG, "Poll all devices.");

        pollDevices(new DevicePollingCallback() {
        pollDevices(
                new DevicePollingCallback() {
                    @Override
                    public void onPollingFinished(List<Integer> ackedAddress) {
                        checkHotplug(ackedAddress, false);
                        Slog.v(TAG, "Finish poll all devices.");
                    }
        }, Constants.POLL_ITERATION_IN_ORDER
                | Constants.POLL_STRATEGY_REMOTES_DEVICES, HdmiConfig.HOTPLUG_DETECTION_RETRY);
                },
                Constants.POLL_ITERATION_IN_ORDER | Constants.POLL_STRATEGY_REMOTES_DEVICES,
                HdmiConfig.HOTPLUG_DETECTION_RETRY,
                mIsTvDevice ? POLLING_MESSAGE_INTERVAL_MS_FOR_TV
                            : POLLING_MESSAGE_INTERVAL_MS_FOR_PLAYBACK);
    }

    private void pollAudioSystem() {
+9 −2
Original line number Diff line number Diff line
@@ -58,7 +58,9 @@ import java.util.concurrent.TimeUnit;
public class HdmiCecLocalDevicePlaybackTest {
    private static final int TIMEOUT_MS = HdmiConfig.TIMEOUT_MS + 1;
    private static final int HOTPLUG_INTERVAL =
            HotplugDetectionAction.POLLING_INTERVAL_MS_FOR_PLAYBACK;
            HotplugDetectionAction.POLLING_BATCH_INTERVAL_MS_FOR_PLAYBACK;
    private static final long POLLING_DELAY =
            HotplugDetectionAction.POLLING_MESSAGE_INTERVAL_MS_FOR_PLAYBACK;

    private static final int PORT_1 = 1;
    private static final HdmiDeviceInfo INFO_TV = HdmiDeviceInfo.cecDeviceBuilder()
@@ -1867,9 +1869,14 @@ public class HdmiCecLocalDevicePlaybackTest {

        mNativeWrapper.setPollAddressResponse(otherPlaybackLogicalAddress,
                SendMessageResult.SUCCESS);
        // Moving forward to skip hotplug interval for polling to start
        mTestLooper.moveTimeForward(HOTPLUG_INTERVAL);
        mTestLooper.dispatchAll();

        // Skipping each polling delay and dispatch each polling message
        for (int i = 0; i < 14; i++) {
            mTestLooper.moveTimeForward(POLLING_DELAY);
            mTestLooper.dispatchAll();
        }
        // Check for <Give Physical Address> being sent to the newly discovered device.
        // This message is sent as part of the HotplugDetectionAction to available devices.
        HdmiCecMessage givePhysicalAddress = HdmiCecMessageBuilder.buildGivePhysicalAddress(
Loading