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

Commit af612563 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Ensure input transactions are applied before injecting input"

parents c9147c4c 86dc82eb
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ final class InputMonitor {
    // When true, need to call updateInputWindowsLw().
    private boolean mUpdateInputWindowsNeeded = true;
    private boolean mUpdateInputWindowsPending;
    private boolean mApplyImmediately;

    // Currently focused input window handle.
    private InputWindowHandle mFocusedInputWindowHandle;
@@ -152,7 +153,7 @@ final class InputMonitor {
        mService = service;
        mDisplayContent = mService.mRoot.getDisplayContent(displayId);
        mDisplayId = displayId;
        mInputTransaction = mDisplayContent.getPendingTransaction();
        mInputTransaction = mService.mTransactionFactory.make();
        mHandler = AnimationThread.getHandler();
        mUpdateInputForAllWindowsConsumer = new UpdateInputForAllWindowsConsumer();
    }
@@ -319,6 +320,14 @@ final class InputMonitor {
        }
    }

    void updateInputWindowsImmediately() {
        if (mUpdateInputWindowsPending) {
            mApplyImmediately = true;
            mUpdateInputWindows.run();
            mApplyImmediately = false;
        }
    }

    /* Called when the current input focus changes.
     * Layer assignment is assumed to be complete by the time this is called.
     */
@@ -433,7 +442,12 @@ final class InputMonitor {
                wallpaperInputConsumer.show(mInputTransaction, 0);
            }

            if (mApplyImmediately) {
                mInputTransaction.apply();
            } else {
                mDisplayContent.getPendingTransaction().merge(mInputTransaction);
                mDisplayContent.scheduleAnimation();
            }

            Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
        }
+6 −4
Original line number Diff line number Diff line
@@ -7531,22 +7531,24 @@ public class WindowManagerService extends IWindowManager.Stub

    @Override
    public boolean injectInputAfterTransactionsApplied(InputEvent ev, int mode) {
        boolean shouldWaitForAnimComplete = false;
        boolean shouldWaitForAnimToComplete = false;
        if (ev instanceof KeyEvent) {
            KeyEvent keyEvent = (KeyEvent) ev;
            shouldWaitForAnimComplete = keyEvent.getSource() == InputDevice.SOURCE_MOUSE
            shouldWaitForAnimToComplete = keyEvent.getSource() == InputDevice.SOURCE_MOUSE
                    || keyEvent.getAction() == KeyEvent.ACTION_DOWN;
        } else if (ev instanceof MotionEvent) {
            MotionEvent motionEvent = (MotionEvent) ev;
            shouldWaitForAnimComplete = motionEvent.getSource() == InputDevice.SOURCE_MOUSE
            shouldWaitForAnimToComplete = motionEvent.getSource() == InputDevice.SOURCE_MOUSE
                    || motionEvent.getAction() == MotionEvent.ACTION_DOWN;
        }

        if (shouldWaitForAnimComplete) {
        if (shouldWaitForAnimToComplete) {
            waitForAnimationsToComplete();

            synchronized (mGlobalLock) {
                mWindowPlacerLocked.performSurfacePlacementIfScheduled();
                mRoot.forAllDisplays(displayContent ->
                        displayContent.getInputMonitor().updateInputWindowsImmediately());
            }

            new SurfaceControl.Transaction().syncInputWindows().apply(true);