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

Commit 0c94d28f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix LetterboxScrollProcessor correctly recycle event" into main

parents d8b56ee8 a355f47b
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -159,7 +159,11 @@ public class LetterboxScrollProcessor {
     */
    @Nullable
    public InputEvent processInputEventBeforeFinish(@NonNull InputEvent inputEvent) {
        return mGeneratedEventIds.remove(inputEvent.getId()) ? null : inputEvent;
        if (mGeneratedEventIds.remove(inputEvent.getId())) {
            inputEvent.recycleIfNeededAfterDispatch();
            return null;
        }
        return inputEvent;
    }

    @NonNull
+13 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import static android.view.MotionEvent.ACTION_UP;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.graphics.Rect;
@@ -40,6 +42,7 @@ import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.ArrayList;
import java.util.List;
@@ -193,6 +196,16 @@ public class LetterboxScrollProcessorTest {

        // Ensure all processed events (that are not ignored) are offset over the app.
        assertXCoordinatesAdjustedToZero(scrollGestureEvents, processedEvents);

        // The first event is synthesized event. Ensure it is recycled in the processor.
        // Mockito cannot mock final class, the event is faked by returning the same ID.
        final InputEvent mockEvent = Mockito.mock(InputEvent.class);
        when(mockEvent.getId()).thenReturn(processedEvents.getFirst().getId());
        final InputEvent firstEventToBeFinished =
                mLetterboxScrollProcessor.processInputEventBeforeFinish(mockEvent);
        verify(mockEvent).recycleIfNeededAfterDispatch();
        assertNull(firstEventToBeFinished);

        // Except the first generated ACTION_DOWN event, ensure the following events should be
        // finished (these events should not be generated).
        assertMotionEventsShouldBeFinished(processedEvents.subList(1, processedEvents.size()));