From 7d870f9ec27cd7f2f6acf2350774af6c08484229 Mon Sep 17 00:00:00 2001 From: Arthur Hung Date: Thu, 28 Apr 2022 04:52:44 +0000 Subject: [PATCH] Fix back gesture send to wrong focus window Ensure we could get the proper focused window token what it's during updating the focus if user touched down on another non-focused window. It also called `startBackNavigation` when received first move that next to down event to ensure the `WMS.onPointerDownOutsideFocus` could be processed first. Test: atest BackAnimationControllerTest BackNavigationControllerTests Test: enabled split-screen, trigger back gesture on non-focused window Bug: 230442550 Bug: 227724016 Change-Id: I81c4f02d43299c03f94dc295bb23ba80d46bded8 Merged-In: I81c4f02d43299c03f94dc295bb23ba80d46bded8 --- .../android/wm/shell/back/BackAnimationController.java | 10 +++++++--- .../wm/shell/back/BackAnimationControllerTest.java | 5 ++--- .../android/server/wm/BackNavigationController.java | 9 +-------- .../server/wm/BackNavigationControllerTests.java | 1 + 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java index c3fbe55436300..8fa9f564fb222 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java @@ -246,9 +246,13 @@ public class BackAnimationController implements RemoteCallable backEventCaptor = ArgumentCaptor.forClass(BackEvent.class); verify(mIOnBackInvokedCallback).onBackProgressed(backEventCaptor.capture()); assertEquals(animationTarget, backEventCaptor.getValue().getDepartingAnimationTarget()); diff --git a/services/core/java/com/android/server/wm/BackNavigationController.java b/services/core/java/com/android/server/wm/BackNavigationController.java index b37f980ce9a01..aaae82d07976e 100644 --- a/services/core/java/com/android/server/wm/BackNavigationController.java +++ b/services/core/java/com/android/server/wm/BackNavigationController.java @@ -124,8 +124,7 @@ class BackNavigationController { LocalServices.getService(WindowManagerInternal.class); IBinder focusedWindowToken = windowManagerInternal.getFocusedWindowToken(); - window = wmService.windowForClientLocked(null, focusedWindowToken, - false /* throwOnError */); + window = wmService.getFocusedWindowLocked(); if (window == null) { EmbeddedWindowController.EmbeddedWindow embeddedWindow = @@ -146,12 +145,6 @@ class BackNavigationController { "Focused window found using getFocusedWindowToken"); } - if (window == null) { - window = wmService.getFocusedWindowLocked(); - ProtoLog.d(WM_DEBUG_BACK_PREVIEW, - "Focused window found using wmService.getFocusedWindowLocked()"); - } - if (window == null) { // We don't have any focused window, fallback ont the top currentTask of the focused // display. diff --git a/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java index 49cd343ef4af8..873d9f3fc023e 100644 --- a/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java @@ -306,6 +306,7 @@ public class BackNavigationControllerTests extends WindowTestsBase { if (focus) { doReturn(window.getWindowInfo().token) .when(mWindowManagerInternal).getFocusedWindowToken(); + doReturn(window).when(mWm).getFocusedWindowLocked(); } } }