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

Commit f48a5e3d authored by Bernardo Rufino's avatar Bernardo Rufino Committed by Android (Google) Code Review
Browse files

Merge "Optionally wait animations on syncInputTransactions/injectInputEvent"

parents 2bd0d626 ab008846
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -302,8 +302,10 @@ package android.app {
    method public void destroy();
    method @NonNull public android.os.ParcelFileDescriptor[] executeShellCommandRwe(@NonNull String);
    method @Deprecated public boolean grantRuntimePermission(String, String, android.os.UserHandle);
    method public boolean injectInputEvent(@NonNull android.view.InputEvent, boolean, boolean);
    method @Deprecated public boolean revokeRuntimePermission(String, String, android.os.UserHandle);
    method public void syncInputTransactions();
    method public void syncInputTransactions(boolean);
  }

  public class UiModeManager {
+2 −2
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ import android.os.ParcelFileDescriptor;
interface IUiAutomationConnection {
    void connect(IAccessibilityServiceClient client, int flags);
    void disconnect();
    boolean injectInputEvent(in InputEvent event, boolean sync);
    void syncInputTransactions();
    boolean injectInputEvent(in InputEvent event, boolean sync, boolean waitForAnimations);
    void syncInputTransactions(boolean waitForAnimations);
    boolean setRotation(int rotation);
    Bitmap takeScreenshot(in Rect crop);
    boolean clearWindowContentFrameStats(int windowId);
+2 −1
Original line number Diff line number Diff line
@@ -1119,7 +1119,8 @@ public class Instrumentation {
        }
        try {
            WindowManagerGlobal.getWindowManagerService().injectInputAfterTransactionsApplied(event,
                    InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
                    InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH,
                    true /* waitForAnimations */);
        } catch (RemoteException e) {
        }
    }
+47 −3
Original line number Diff line number Diff line
@@ -695,6 +695,9 @@ public final class UiAutomation {

    /**
     * A method for injecting an arbitrary input event.
     *
     * This method waits for all window container animations and surface operations to complete.
     *
     * <p>
     * <strong>Note:</strong> It is caller's responsibility to recycle the event.
     * </p>
@@ -704,12 +707,34 @@ public final class UiAutomation {
     * @return Whether event injection succeeded.
     */
    public boolean injectInputEvent(InputEvent event, boolean sync) {
        return injectInputEvent(event, sync, true /* waitForAnimations */);
    }

    /**
     * A method for injecting an arbitrary input event, optionally waiting for window animations to
     * complete.
     * <p>
     * <strong>Note:</strong> It is caller's responsibility to recycle the event.
     * </p>
     *
     * @param event The event to inject.
     * @param sync  Whether to inject the event synchronously.
     * @param waitForAnimations Whether to wait for all window container animations and surface
     *   operations to complete.
     * @return Whether event injection succeeded.
     *
     * @hide
     */
    @TestApi
    public boolean injectInputEvent(@NonNull InputEvent event, boolean sync,
            boolean waitForAnimations) {
        try {
            if (DEBUG) {
                Log.i(LOG_TAG, "Injecting: " + event + " sync: " + sync);
                Log.i(LOG_TAG, "Injecting: " + event + " sync: " + sync + " waitForAnimations: "
                        + waitForAnimations);
            }
            // Calling out without a lock held.
            return mUiAutomationConnection.injectInputEvent(event, sync);
            return mUiAutomationConnection.injectInputEvent(event, sync, waitForAnimations);
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error while injecting input event!", re);
        }
@@ -726,7 +751,26 @@ public final class UiAutomation {
    public void syncInputTransactions() {
        try {
            // Calling out without a lock held.
            mUiAutomationConnection.syncInputTransactions();
            mUiAutomationConnection.syncInputTransactions(true /* waitForAnimations */);
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error while syncing input transactions!", re);
        }
    }

    /**
     * A request for WindowManagerService to wait until all input information has been sent from
     * WindowManager to native InputManager and optionally wait for animations to complete.
     *
     * @param waitForAnimations Whether to wait for all window container animations and surface
     *   operations to complete.
     *
     * @hide
     */
    @TestApi
    public void syncInputTransactions(boolean waitForAnimations) {
        try {
            // Calling out without a lock held.
            mUiAutomationConnection.syncInputTransactions(waitForAnimations);
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error while syncing input transactions!", re);
        }
+5 −5
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
    }

    @Override
    public boolean injectInputEvent(InputEvent event, boolean sync) {
    public boolean injectInputEvent(InputEvent event, boolean sync, boolean waitForAnimations) {
        synchronized (mLock) {
            throwIfCalledByNotTrustedUidLocked();
            throwIfShutdownLocked();
@@ -134,7 +134,8 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
                : InputManager.INJECT_INPUT_EVENT_MODE_ASYNC;
        final long identity = Binder.clearCallingIdentity();
        try {
            return mWindowManager.injectInputAfterTransactionsApplied(event, mode);
            return mWindowManager.injectInputAfterTransactionsApplied(event, mode,
                    waitForAnimations);
        } catch (RemoteException e) {
        } finally {
            Binder.restoreCallingIdentity(identity);
@@ -143,7 +144,7 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
    }

    @Override
    public void syncInputTransactions() {
    public void syncInputTransactions(boolean waitForAnimations) {
        synchronized (mLock) {
            throwIfCalledByNotTrustedUidLocked();
            throwIfShutdownLocked();
@@ -151,12 +152,11 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
        }

        try {
            mWindowManager.syncInputTransactions();
            mWindowManager.syncInputTransactions(waitForAnimations);
        } catch (RemoteException e) {
        }
    }


    @Override
    public boolean setRotation(int rotation) {
        synchronized (mLock) {
Loading