From 8b20dee8c79bca4da7b09403d26b60505d235f7e Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Tue, 11 Jun 2019 18:16:04 -0700 Subject: [PATCH] Sync input transactions after ACTION_UP Changes to windows can happen before or after a touch gesture. For example, a window can be dismissed after ACTION_UP occurs. For those scenarios, sync input transactions after the ACTION_UP event has been injected. Bug: 134414988 Test: atest MultiDisplayPolicyTests Test: atest android.app.cts.DialogTest Test: TaplTestsQuickstep Test: atest ActivityLifecycleTopResumedStateTests Merged-In: I810fad449ea405d104009075d2698109a620a91e Change-Id: I810fad449ea405d104009075d2698109a620a91e --- .../server/wm/WindowManagerService.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index ce8720a2883c5..57fa2ed63121f 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -7626,22 +7626,30 @@ public class WindowManagerService extends IWindowManager.Stub @Override public boolean injectInputAfterTransactionsApplied(InputEvent ev, int mode) { - boolean shouldWaitForAnimToComplete = false; + boolean isDown; + boolean isUp; + if (ev instanceof KeyEvent) { KeyEvent keyEvent = (KeyEvent) ev; - shouldWaitForAnimToComplete = keyEvent.getSource() == InputDevice.SOURCE_MOUSE - || keyEvent.getAction() == KeyEvent.ACTION_DOWN; - } else if (ev instanceof MotionEvent) { + isDown = keyEvent.getAction() == KeyEvent.ACTION_DOWN; + isUp = keyEvent.getAction() == KeyEvent.ACTION_UP; + } else { MotionEvent motionEvent = (MotionEvent) ev; - shouldWaitForAnimToComplete = motionEvent.getSource() == InputDevice.SOURCE_MOUSE - || motionEvent.getAction() == MotionEvent.ACTION_DOWN; + isDown = motionEvent.getAction() == MotionEvent.ACTION_DOWN; + isUp = motionEvent.getAction() == MotionEvent.ACTION_UP; } - if (shouldWaitForAnimToComplete) { + // For ACTION_DOWN, syncInputTransactions before injecting input. + // For ACTION_UP, sync after injecting. + if (isDown) { syncInputTransactions(); } - - return LocalServices.getService(InputManagerInternal.class).injectInputEvent(ev, mode); + final boolean result = + LocalServices.getService(InputManagerInternal.class).injectInputEvent(ev, mode); + if (isUp) { + syncInputTransactions(); + } + return result; } @Override