Inject back key event if focused window didn't be drawn

If an user applied a back gesture and core found the focused window
without any surface drawn, the input window could still be invisible
and the focus request would be pending. In such situation, we should
directly inject the back key so it could dispatch to the right focused
window after the focus request is applied.

Test: atest BackNavigationControllerTests
Bug: 260265858
Change-Id: I77b1cad23d458927715333bdcef701f5cf409347
This commit is contained in:
Arthur Hung
2022-12-01 08:46:46 +00:00
parent 7957cfbbc4
commit a13a07e395
3 changed files with 30 additions and 0 deletions

View File

@@ -4171,6 +4171,12 @@
"group": "WM_DEBUG_REMOTE_ANIMATIONS",
"at": "com\/android\/server\/wm\/RemoteAnimationController.java"
},
"1945495497": {
"message": "Focused window didn't have a valid surface drawn.",
"level": "DEBUG",
"group": "WM_DEBUG_BACK_PREVIEW",
"at": "com\/android\/server\/wm\/BackNavigationController.java"
},
"1947239194": {
"message": "Deferring rotation, still finishing previous rotation",
"level": "VERBOSE",

View File

@@ -168,6 +168,12 @@ class BackNavigationController {
+ "recents. Overriding back callback to recents controller callback.");
return null;
}
if (!window.isDrawn()) {
ProtoLog.d(WM_DEBUG_BACK_PREVIEW,
"Focused window didn't have a valid surface drawn.");
return null;
}
}
if (window == null) {

View File

@@ -150,6 +150,7 @@ public class BackNavigationControllerTests extends WindowTestsBase {
WindowState window = createWindow(null, WindowManager.LayoutParams.TYPE_WALLPAPER,
"Wallpaper");
addToWindowMap(window, true);
makeWindowVisibleAndDrawn(window);
IOnBackInvokedCallback callback = createOnBackInvokedCallback();
window.setOnBackInvokedCallbackInfo(
@@ -236,6 +237,20 @@ public class BackNavigationControllerTests extends WindowTestsBase {
1, appLatch.getCount());
}
@Test
public void backInfoWindowWithoutDrawn() {
WindowState window = createWindow(null, WindowManager.LayoutParams.TYPE_APPLICATION,
"TestWindow");
addToWindowMap(window, true);
IOnBackInvokedCallback callback = createOnBackInvokedCallback();
window.setOnBackInvokedCallbackInfo(
new OnBackInvokedCallbackInfo(callback, OnBackInvokedDispatcher.PRIORITY_DEFAULT));
BackNavigationInfo backNavigationInfo = startBackNavigation();
assertThat(backNavigationInfo).isNull();
}
private IOnBackInvokedCallback withSystemCallback(Task task) {
IOnBackInvokedCallback callback = createOnBackInvokedCallback();
task.getTopMostActivity().getTopChild().setOnBackInvokedCallbackInfo(
@@ -309,6 +324,7 @@ public class BackNavigationControllerTests extends WindowTestsBase {
Mockito.doNothing().when(task).reparentSurfaceControl(any(), any());
mAtm.setFocusedTask(task.mTaskId, record);
addToWindowMap(window, true);
makeWindowVisibleAndDrawn(window);
return task;
}
@@ -333,6 +349,8 @@ public class BackNavigationControllerTests extends WindowTestsBase {
addToWindowMap(window1, true);
addToWindowMap(window2, true);
makeWindowVisibleAndDrawn(window2);
CrossActivityTestCase testCase = new CrossActivityTestCase();
testCase.task = task;
testCase.recordBack = record1;