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

Commit 504715c5 authored by chaviw's avatar chaviw
Browse files

Wait for input windows to be set before proceeding with inject for tests

Added a new test method to allow the client to wait until input windows
have been propagated to InputFlinger before proceeding to inject input.
This ensures that the inject is called when all windows have been set
up.

Bug: 123041491
Test: ListPopupWindowTest, PopupMenuTest
Change-Id: I42abfa4ea23a14ae1a003c6ee8976cc466f1d5af
parent 263a4d08
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -128,7 +128,13 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
                : InputManager.INJECT_INPUT_EVENT_MODE_ASYNC;
        final long identity = Binder.clearCallingIdentity();
        try {
            return InputManager.getInstance().injectInputEvent(event, mode);
            IWindowManager manager = IWindowManager.Stub.asInterface(
                    ServiceManager.getService(Context.WINDOW_SERVICE));
            try {
                return manager.injectInputAfterTransactionsApplied(event, mode);
            } catch (RemoteException e) {
            }
            return false;
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
+9 −0
Original line number Diff line number Diff line
@@ -582,4 +582,13 @@ interface IWindowManager
     *        display should be re-parented to.
     */
    void reparentDisplayContent(int displayId, in SurfaceControl sc);

    /**
     * Waits for transactions to get applied before injecting input.
     * This includes waiting for the input windows to get sent to InputManager.
     *
     * This is needed for testing since the system add windows and injects input
     * quick enough that the windows don't have time to get sent to InputManager.
     */
     boolean injectInputAfterTransactionsApplied(in InputEvent ev, int mode);
}
+13 −0
Original line number Diff line number Diff line
@@ -209,6 +209,7 @@ import android.view.IWindowSession;
import android.view.IWindowSessionCallback;
import android.view.InputChannel;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputEventReceiver;
import android.view.InsetsState;
import android.view.KeyEvent;
@@ -7403,4 +7404,16 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }
    }

    @Override
    public boolean injectInputAfterTransactionsApplied(InputEvent ev, int mode) {
        synchronized (mGlobalLock) {
            mWindowPlacerLocked.performSurfacePlacementIfScheduled();
            new SurfaceControl.Transaction()
                    .syncInputWindows()
                    .apply(true);
        }

        return mInputManager.injectInputEvent(ev, mode);
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -85,6 +85,12 @@ class WindowSurfacePlacer {
        return mDeferDepth > 0;
    }

    void performSurfacePlacementIfScheduled() {
        if (mTraversalScheduled) {
            performSurfacePlacement();
        }
    }

    final void performSurfacePlacement() {
        performSurfacePlacement(false /* force */);
    }