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

Commit 7eab624a authored by Paul Colța's avatar Paul Colța Committed by Android (Google) Code Review
Browse files

Merge "HDMI: Fix DeviceDiscoveryAction continuing when removed" into main

parents f8a572e3 46f845da
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -140,7 +140,13 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
                    wrapUpAndFinish();
                    return;
                }

                // Check if the action was finished before the callback was called.
                // See {@link HdmiCecFeatureAction#finish}.
                if (mState == STATE_NONE) {
                    Slog.v(TAG, "Action was already finished before the callback was called.");
                    wrapUpAndFinish();
                    return;
                }
                Slog.v(TAG, "Device detected: " + ackedAddress);
                allocateDevices(ackedAddress);
                if (mDelayPeriod > 0) {
@@ -453,7 +459,6 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
            wrapUpAndFinish();
            return;
        }

        // If finished current stage, move on to next stage.
        if (mProcessedDeviceCount == mDevices.size()) {
            mProcessedDeviceCount = 0;
+15 −1
Original line number Diff line number Diff line
@@ -160,6 +160,9 @@ final class HdmiCecController {
    // This variable is used for testing, in order to delay the logical address allocation.
    private long mLogicalAddressAllocationDelay = 0;

    // This variable is used for testing, in order to delay polling devices.
    private long mPollDevicesDelay = 0;

    // Private constructor.  Use HdmiCecController.create().
    private HdmiCecController(
            HdmiControlService service, NativeWrapper nativeWrapper, HdmiCecAtomWriter atomWriter) {
@@ -462,6 +465,14 @@ final class HdmiCecController {
        mLogicalAddressAllocationDelay = delay;
    }

    /**
     * This method is used for testing, in order to delay polling devices.
     */
    @VisibleForTesting
    void setPollDevicesDelay(long delay) {
        mPollDevicesDelay = delay;
    }

    /**
     * Returns true if the language code is well-formed.
     */
@@ -523,7 +534,10 @@ final class HdmiCecController {
        // Extract polling candidates. No need to poll against local devices.
        List<Integer> pollingCandidates = pickPollCandidates(pickStrategy);
        ArrayList<Integer> allocated = new ArrayList<>();
        runDevicePolling(sourceAddress, pollingCandidates, retryCount, callback, allocated);
        mControlHandler.postDelayed(
                () -> runDevicePolling(
                        sourceAddress, pollingCandidates, retryCount, callback, allocated),
                mPollDevicesDelay);
    }

    private List<Integer> pickPollCandidates(int pickStrategy) {
+13 −0
Original line number Diff line number Diff line
@@ -1775,6 +1775,11 @@ public class HdmiCecLocalDevicePlaybackTest {

    @Test
    public void wakeUp_hotPlugIn_invokesDeviceDiscoveryOnce() {
        // There might be a leftover HotplugDetectionAction that can interfere with the test.
        mHdmiCecLocalDevicePlayback.removeAction(HotplugDetectionAction.class);

        long pollingDelay = TimeUnit.SECONDS.toMillis(60);
        mHdmiCecController.setPollDevicesDelay(pollingDelay);
        mNativeWrapper.setPollAddressResponse(Constants.ADDR_PLAYBACK_2, SendMessageResult.SUCCESS);
        mHdmiControlService.onWakeUp(HdmiControlService.WAKE_UP_SCREEN_ON);
        mTestLooper.dispatchAll();
@@ -1783,6 +1788,14 @@ public class HdmiCecLocalDevicePlaybackTest {
        mTestLooper.dispatchAll();

        assertThat(mHdmiCecLocalDevicePlayback.getActions(DeviceDiscoveryAction.class)).hasSize(1);
        mTestLooper.moveTimeForward(pollingDelay);
        mTestLooper.dispatchAll();

        HdmiCecMessage givePhysicalAddress = HdmiCecMessageBuilder.buildGivePhysicalAddress(
                Constants.ADDR_PLAYBACK_1,
                Constants.ADDR_PLAYBACK_2);
        assertThat(mNativeWrapper.getResultMessages().stream()
                .filter(message -> message.equals(givePhysicalAddress)).count()).isEqualTo(1);
    }

    @Test