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

Commit 930bee1a authored by mattsziklay's avatar mattsziklay
Browse files

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
parent 294922a2
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -544,7 +544,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                    mResult.mRootView,
                    mOnCaptionTouchListener,
                    mOnCaptionButtonClickListener,
                    mWindowManagerWrapper
                    mWindowManagerWrapper,
                    mHandler
            );
        } else if (mRelayoutParams.mLayoutResId
                == R.layout.desktop_mode_app_header) {
+25 −15
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.Point
import android.hardware.input.InputManager
import android.os.Handler
import android.view.MotionEvent.ACTION_DOWN
import android.view.SurfaceControl
import android.view.View
@@ -44,7 +45,8 @@ internal class AppHandleViewHolder(
    rootView: View,
    onCaptionTouchListener: View.OnTouchListener,
    onCaptionButtonClickListener: OnClickListener,
    private val windowManagerWrapper: WindowManagerWrapper
    private val windowManagerWrapper: WindowManagerWrapper,
    private val handler: Handler
) : WindowDecorationViewHolder(rootView) {

    companion object {
@@ -54,6 +56,7 @@ internal class AppHandleViewHolder(
    private val captionView: View = rootView.requireViewById(R.id.desktop_mode_caption)
    private val captionHandle: ImageButton = rootView.requireViewById(R.id.caption_handle)
    private val inputManager = context.getSystemService(InputManager::class.java)
    private var statusBarInputLayerExists = false

    // An invisible View that takes up the same coordinates as captionHandle but is layered
    // above the status bar. The purpose of this View is to receive input intended for
@@ -78,14 +81,18 @@ internal class AppHandleViewHolder(
        // If handle is not in status bar region(i.e., bottom stage in vertical split),
        // do not create an input layer
        if (position.y >= 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,7 +110,8 @@ 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 " +
                "LayoutParams")
@@ -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,9 +150,12 @@ internal class AppHandleViewHolder(
     * is not visible.
     */
    fun disposeStatusBarInputLayer() {
        statusBarInputLayerExists = false
        handler.post {
            statusBarInputLayer?.releaseView()
            statusBarInputLayer = null
        }
    }

    private fun getCaptionHandleBarColor(taskInfo: RunningTaskInfo): Int {
        return if (shouldUseLightCaptionColors(taskInfo)) {
+0 −1
Original line number Diff line number Diff line
@@ -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());