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

Commit ce3c2103 authored by Bryce Lee's avatar Bryce Lee
Browse files

Only pilfer once in InputSession.

This change modifies the behavior of InputSession to only pilfer
motion events once.

Fixes: 333596426
Test: atest InputSessionTest#testPilferOnce
Flag: ACONFIG com.android.systemui.dream_input_session_pilfer_once DISABLED
Change-Id: Ied60cbabcb4bed53f9ec77e580d722338f4de448
parent 2ec65e25
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -761,3 +761,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
    name: "dream_input_session_pilfer_once"
    namespace: "systemui"
    description: "Pilfer at most once per input session"
    bug: "324600132"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.view.Choreographer;
import android.view.GestureDetector;
import android.view.MotionEvent;

import com.android.systemui.Flags;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.shared.system.InputChannelCompat;
import com.android.systemui.shared.system.InputMonitorCompat;
@@ -41,6 +42,12 @@ public class InputSession {
    private final InputChannelCompat.InputEventReceiver mInputEventReceiver;
    private final GestureDetector mGestureDetector;

    // Pilfering is a destructive operation. Once pilfering starts, the all events will be captured
    // by the associated monitor. We track whether we're pilfering since initiating pilfering
    // requires reaching out to the InputManagerService, which can be a heavy operation. This is
    // especially costly if this is happening on a continuous stream of motion events.
    private boolean mPilfering;

    /**
     * Default session constructor.
     * @param inputMonitor Input monitor to track input events.
@@ -70,7 +77,9 @@ public class InputSession {

                    if (ev instanceof MotionEvent
                            && mGestureDetector.onTouchEvent((MotionEvent) ev)
                            && pilferOnGestureConsume) {
                            && pilferOnGestureConsume
                            && !(mPilfering && Flags.dreamInputSessionPilferOnce())) {
                        mPilfering = true;
                        mInputMonitor.pilferPointers();
                    }
                });
+15 −0
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@ package com.android.systemui.dreams.touch;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.platform.test.annotations.EnableFlags;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.Choreographer;
@@ -31,6 +33,7 @@ import android.view.MotionEvent;

import androidx.test.filters.SmallTest;

import com.android.systemui.Flags;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.shared.system.InputChannelCompat;
import com.android.systemui.shared.system.InputMonitorCompat;
@@ -127,6 +130,18 @@ public class InputSessionTest extends SysuiTestCase {
        verify(mInputMonitor, never()).pilferPointers();
    }

    @Test
    @EnableFlags(Flags.FLAG_DREAM_INPUT_SESSION_PILFER_ONCE)
    public void testPilferOnce() {
        createSession(true);
        final MotionEvent event = Mockito.mock(MotionEvent.class);
        when(mGestureDetector.onTouchEvent(event)).thenReturn(true);
        mEventListener.onInputEvent(event);
        mEventListener.onInputEvent(event);
        verify(mInputEventListener, times(2)).onInputEvent(eq(event));
        verify(mInputMonitor, times(1)).pilferPointers();
    }

    /**
     * Ensures components are properly disposed.
     */