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

Commit 077e8b2f authored by Massimo Carli's avatar Massimo Carli
Browse files

[1/n] Fix Restart and Resize hints flickering

The flicker was due to a change in the size of the layout when the
hint was displayed. This was triggering a relayout which appeared as
a flicker.

Using a different overload for the SurfaceViewHost#relayout() it's
possible to execute the change in position and resize in the same
transition which happens after the View for the layout has been measured.
This removes the flicker when a long click event happens on a button
to display the tooltip.

Flag: com.android.window.flags.app_compat_async_relayout
Fix: 322463856
Test: atest WMShellUnitTests:CompatUIWindowManagerTest
Test: atest WMShellUnitTests:UserAspectRatioSettingsLayoutTest

Change-Id: I7225f85357b52e3df557ebaceac683e2c4bce2c9
parent 7879f67a
Loading
Loading
Loading
Loading
+35 −10
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.Context;
import android.graphics.Rect;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.SurfaceControl;
import android.view.View;
import android.window.DesktopModeFlags;

@@ -70,6 +71,9 @@ class CompatUIWindowManager extends CompatUIWindowManagerAbstract {

    private final float mHideScmTolerance;

    @NonNull
    private final Rect mLayoutBounds = new Rect();

    CompatUIWindowManager(@NonNull Context context, @NonNull TaskInfo taskInfo,
                          @NonNull SyncTransactionQueue syncQueue,
                          @NonNull Consumer<CompatUIEvent> callback,
@@ -105,6 +109,7 @@ class CompatUIWindowManager extends CompatUIWindowManagerAbstract {

    @Override
    protected void removeLayout() {
        mLayoutBounds.setEmpty();
        mLayout = null;
    }

@@ -171,18 +176,21 @@ class CompatUIWindowManager extends CompatUIWindowManagerAbstract {
    @Override
    @VisibleForTesting
    public void updateSurfacePosition() {
        if (mLayout == null) {
        updateLayoutBounds();
        if (mLayoutBounds.isEmpty()) {
            return;
        }
        // Position of the button in the container coordinate.
        final Rect taskBounds = getTaskBounds();
        final Rect taskStableBounds = getTaskStableBounds();
        final int positionX = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL
                ? taskStableBounds.left - taskBounds.left
                : taskStableBounds.right - taskBounds.left - mLayout.getMeasuredWidth();
        final int positionY = taskStableBounds.bottom - taskBounds.top
                - mLayout.getMeasuredHeight();
        updateSurfacePosition(positionX, positionY);
        updateSurfacePosition(mLayoutBounds.left, mLayoutBounds.top);
    }

    @Override
    @VisibleForTesting
    public void updateSurfacePosition(@NonNull SurfaceControl.Transaction tx) {
        updateLayoutBounds();
        if (mLayoutBounds.isEmpty()) {
            return;
        }
        updateSurfaceBounds(tx, mLayoutBounds);
    }

    @VisibleForTesting
@@ -219,6 +227,23 @@ class CompatUIWindowManager extends CompatUIWindowManagerAbstract {
        return percentageAreaOfLetterboxInTask < mHideScmTolerance;
    }

    private void updateLayoutBounds() {
        if (mLayout == null) {
            mLayoutBounds.setEmpty();
            return;
        }
        // Position of the button in the container coordinate.
        final Rect taskBounds = getTaskBounds();
        final Rect taskStableBounds = getTaskStableBounds();
        final int layoutWidth = mLayout.getMeasuredWidth();
        final int layoutHeight = mLayout.getMeasuredHeight();
        final int positionX = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL
                ? taskStableBounds.left - taskBounds.left
                : taskStableBounds.right - taskBounds.left - layoutWidth;
        final int positionY = taskStableBounds.bottom - taskBounds.top - layoutHeight;
        mLayoutBounds.set(positionX, positionY, positionX + layoutWidth, positionY + layoutHeight);
    }

    private void updateVisibilityOfViews() {
        if (mLayout == null) {
            return;
+23 −2
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.view.WindowManager;
import android.view.WindowlessWindowManager;

import com.android.internal.annotations.VisibleForTesting;
import com.android.window.flags.Flags;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.SyncTransactionQueue;
@@ -327,9 +328,16 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
        if (mViewHost == null) {
            return;
        }
        if (Flags.appCompatAsyncRelayout()) {
            mViewHost.relayout(windowLayoutParams, tx -> {
                updateSurfacePosition(tx);
                tx.apply();
            });
        } else {
            mViewHost.relayout(windowLayoutParams);
            updateSurfacePosition();
        }
    }

    @NonNull
    protected TaskInfo getLastTaskInfo() {
@@ -349,6 +357,10 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
     */
    protected abstract void updateSurfacePosition();

    protected void updateSurfacePosition(@NonNull SurfaceControl.Transaction tx) {

    }

    /**
     * Updates the position of the surface with respect to the given {@code positionX} and {@code
     * positionY}.
@@ -366,6 +378,15 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
        });
    }

    protected void updateSurfaceBounds(@NonNull SurfaceControl.Transaction tx,
            @NonNull Rect bounds) {
        if (mLeash == null) {
            return;
        }
        tx.setPosition(mLeash, bounds.left, bounds.top)
                .setWindowCrop(mLeash, bounds.width(), bounds.height());
    }

    protected int getLayoutDirection() {
        return mContext.getResources().getConfiguration().getLayoutDirection();
    }
+35 −10
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Intent;
import android.graphics.Rect;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.SurfaceControl;
import android.view.View;
import android.view.accessibility.AccessibilityManager;

@@ -69,6 +70,9 @@ class UserAspectRatioSettingsWindowManager extends CompatUIWindowManagerAbstract
    @NonNull
    final CompatUIHintsState mCompatUIHintsState;

    @NonNull
    private final Rect mLayoutBounds = new Rect();

    @Nullable
    private UserAspectRatioSettingsLayout mLayout;

@@ -108,6 +112,7 @@ class UserAspectRatioSettingsWindowManager extends CompatUIWindowManagerAbstract

    @Override
    protected void removeLayout() {
        mLayoutBounds.setEmpty();
        mLayout = null;
    }

@@ -168,18 +173,21 @@ class UserAspectRatioSettingsWindowManager extends CompatUIWindowManagerAbstract
    @Override
    @VisibleForTesting
    public void updateSurfacePosition() {
        if (mLayout == null) {
        updateLayoutBounds();
        if (mLayoutBounds.isEmpty()) {
            return;
        }
        // Position of the button in the container coordinate.
        final Rect taskBounds = getTaskBounds();
        final Rect taskStableBounds = getTaskStableBounds();
        final int positionX = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL
                ? taskStableBounds.left - taskBounds.left
                : taskStableBounds.right - taskBounds.left - mLayout.getMeasuredWidth();
        final int positionY = taskStableBounds.bottom - taskBounds.top
                - mLayout.getMeasuredHeight();
        updateSurfacePosition(positionX, positionY);
        updateSurfacePosition(mLayoutBounds.left, mLayoutBounds.top);
    }

    @Override
    @VisibleForTesting
    public void updateSurfacePosition(@NonNull SurfaceControl.Transaction tx) {
        updateLayoutBounds();
        if (mLayoutBounds.isEmpty()) {
            return;
        }
        updateSurfaceBounds(tx, mLayoutBounds);
    }

    @VisibleForTesting
@@ -202,6 +210,23 @@ class UserAspectRatioSettingsWindowManager extends CompatUIWindowManagerAbstract
                && !isHideDelayReached(mNextButtonHideTimeMs));
    }

    private void updateLayoutBounds() {
        if (mLayout == null) {
            mLayoutBounds.setEmpty();
            return;
        }
        // Position of the button in the container coordinate.
        final Rect taskBounds = getTaskBounds();
        final Rect taskStableBounds = getTaskStableBounds();
        final int layoutWidth = mLayout.getMeasuredWidth();
        final int layoutHeight = mLayout.getMeasuredHeight();
        final int positionX = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL
                ? taskStableBounds.left - taskBounds.left
                : taskStableBounds.right - taskBounds.left - layoutWidth;
        final int positionY = taskStableBounds.bottom - taskBounds.top - layoutHeight;
        mLayoutBounds.set(positionX, positionY, positionX + layoutWidth, positionY + layoutHeight);
    }

    private void showUserAspectRatioButton() {
        if (mLayout == null) {
            return;