From 930bee1aecfa66e362089a839151ebebcdbeefee Mon Sep 17 00:00:00 2001 From: mattsziklay Date: Tue, 10 Sep 2024 15:12:20 -0700 Subject: Let handler perform input layer creation. The creation of a view for statusBarInputLayer added significant latency to bindData calls in AppHandleViewHolder. This CL has the handler post those interactions with the view instead. Bug: 360393260 Test: Manual, check perfetto trace for DesktopModeWindowDecoration#relayout-binding. Flag: EXEMPT, bugfix Change-Id: Iae9b38f6695675ca8c9b34de4f6f86736fa91682 --- .../windowdecor/DesktopModeWindowDecoration.java | 3 +- .../windowdecor/viewholder/AppHandleViewHolder.kt | 40 ++++++++++++++-------- .../DesktopModeWindowDecorationTests.java | 1 - 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java index 5d16d972a0f2..cb55009061d3 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java @@ -544,7 +544,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration= SystemBarUtils.getStatusBarHeight(context)) return - if (!isCaptionVisible && hasStatusBarInputLayer() ) { + if (!isCaptionVisible && statusBarInputLayerExists) { disposeStatusBarInputLayer() return } - if (hasStatusBarInputLayer()) { - updateStatusBarInputLayer(position) + // Input layer view creation / modification takes a significant amount of time; + // post them so we don't hold up DesktopModeWindowDecoration#relayout. + if (statusBarInputLayerExists) { + handler.post { updateStatusBarInputLayer(position) } } else { - createStatusBarInputLayer(position, width, height) + // Input layer is created on a delay; prevent multiple from being created. + statusBarInputLayerExists = true + handler.post { createStatusBarInputLayer(position, width, height) } } } @@ -103,9 +110,10 @@ internal class AppHandleViewHolder( if (!Flags.enableAdditionalWindowsAboveStatusBar()) return statusBarInputLayer = AdditionalSystemViewContainer(context, windowManagerWrapper, taskInfo.taskId, handlePosition.x, handlePosition.y, handleWidth, handleHeight, - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + ) val view = statusBarInputLayer?.view ?: error("Unable to find statusBarInputLayer View") - val lp = statusBarInputLayer?.lp ?: error("Unable to find statusBarInputLayer" + + val lp = statusBarInputLayer?.lp ?: error("Unable to find statusBarInputLayer " + "LayoutParams") lp.title = "Handle Input Layer of task " + taskInfo.taskId lp.setTrustedOverlay() @@ -130,12 +138,11 @@ internal class AppHandleViewHolder( } private fun updateStatusBarInputLayer(globalPosition: Point) { - statusBarInputLayer?.setPosition(SurfaceControl.Transaction(), globalPosition.x.toFloat(), - globalPosition.y.toFloat()) ?: return - } - - private fun hasStatusBarInputLayer(): Boolean { - return statusBarInputLayer != null + statusBarInputLayer?.setPosition( + SurfaceControl.Transaction(), + globalPosition.x.toFloat(), + globalPosition.y.toFloat() + ) ?: return } /** @@ -143,8 +150,11 @@ internal class AppHandleViewHolder( * is not visible. */ fun disposeStatusBarInputLayer() { - statusBarInputLayer?.releaseView() - statusBarInputLayer = null + statusBarInputLayerExists = false + handler.post { + statusBarInputLayer?.releaseView() + statusBarInputLayer = null + } } private fun getCaptionHandleBarColor(taskInfo: RunningTaskInfo): Int { diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java index 1741fe447fad..96e0ede1b0b8 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java @@ -837,7 +837,6 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase { } private void verifyHandleMenuCreated(@Nullable Uri uri) { - verify(mMockHandleMenuFactory).create(any(), any(), anyInt(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean(), eq(uri), anyInt(), anyInt(), anyInt()); -- cgit v1.2.3-59-g8ed1b