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

Commit 22821f90 authored by Yunfan Chen's avatar Yunfan Chen
Browse files

Avoid the caption bar overlaps with status bar

When a window under desktop mode, and get fullscreen when the maximize
button on the caption bar is pressed, the caption bar will layout
starting from (0, 0) point of the display, and it will overlaps with the
status bar, made the buttons on caption bar hard to interact with.

This patch extend the caption bar by the status bar size when it
overlaps and maximized, also added padding to the corresponding view to
make the buttons on the caption moving downward to be accessible by the
users.

The extension only applied to CaptionWindowDecoration.

Test: WindowDecorationTests
Test: Check desktop mode targets
Bug: 351920380
Flag: EXEMPT bugfix
Change-Id: I0065cdc3e51be187d24e617fb97f191a69c86a3c
parent 8350f4b8
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
@@ -37,10 +38,12 @@ import android.graphics.drawable.VectorDrawable;
import android.os.Handler;
import android.util.Size;
import android.view.Choreographer;
import android.view.InsetsState;
import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.window.WindowContainerTransaction;

@@ -194,7 +197,8 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
            RelayoutParams relayoutParams,
            ActivityManager.RunningTaskInfo taskInfo,
            boolean applyStartTransactionOnDraw,
            boolean setTaskCropAndPosition) {
            boolean setTaskCropAndPosition,
            InsetsState displayInsetsState) {
        relayoutParams.reset();
        relayoutParams.mRunningTaskInfo = taskInfo;
        relayoutParams.mLayoutResId = R.layout.caption_window_decor;
@@ -222,6 +226,8 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
        controlsElement.mWidthResId = R.dimen.caption_right_buttons_width;
        controlsElement.mAlignment = RelayoutParams.OccludingCaptionElement.Alignment.END;
        relayoutParams.mOccludingCaptionElements.add(controlsElement);
        relayoutParams.mCaptionTopPadding = getTopPadding(relayoutParams,
                taskInfo.getConfiguration().windowConfiguration.getBounds(), displayInsetsState);
    }

    @SuppressLint("MissingPermission")
@@ -237,7 +243,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
        final WindowContainerTransaction wct = new WindowContainerTransaction();

        updateRelayoutParams(mRelayoutParams, taskInfo, applyStartTransactionOnDraw,
                setTaskCropAndPosition);
                setTaskCropAndPosition, mDisplayController.getInsetsState(taskInfo.displayId));

        relayout(mRelayoutParams, startT, finishT, wct, oldRootView, mResult);
        // After this line, mTaskInfo is up-to-date and should be used instead of taskInfo
@@ -343,6 +349,18 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
        mDragResizeListener = null;
    }

    private static int getTopPadding(RelayoutParams params, Rect taskBounds,
            InsetsState insetsState) {
        if (!params.mRunningTaskInfo.isFreeform()) {
            Insets systemDecor = insetsState.calculateInsets(taskBounds,
                    WindowInsets.Type.systemBars() & ~WindowInsets.Type.captionBar(),
                    false /* ignoreVisibility */);
            return systemDecor.top;
        } else {
            return 0;
        }
    }

    /**
     * Checks whether the touch event falls inside the customizable caption region.
     */
+8 −1
Original line number Diff line number Diff line
@@ -237,7 +237,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        outResult.mHeight = taskBounds.height();
        outResult.mRootView.setTaskFocusState(mTaskInfo.isFocused);
        final Resources resources = mDecorWindowContext.getResources();
        outResult.mCaptionHeight = loadDimensionPixelSize(resources, params.mCaptionHeightId);
        outResult.mCaptionHeight = loadDimensionPixelSize(resources, params.mCaptionHeightId)
                + params.mCaptionTopPadding;
        outResult.mCaptionWidth = params.mCaptionWidthId != Resources.ID_NULL
                ? loadDimensionPixelSize(resources, params.mCaptionWidthId) : taskBounds.width();
        outResult.mCaptionX = (outResult.mWidth - outResult.mCaptionWidth) / 2;
@@ -456,6 +457,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
                }
                mViewHost.getRootSurfaceControl().applyTransactionOnDraw(onDrawTransaction);
            }
            outResult.mRootView.setPadding(0, params.mCaptionTopPadding, 0, 0);
            mViewHost.setView(outResult.mRootView, lp);
            Trace.endSection();
        } else {
@@ -466,6 +468,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
                }
                mViewHost.getRootSurfaceControl().applyTransactionOnDraw(onDrawTransaction);
            }
            outResult.mRootView.setPadding(0, params.mCaptionTopPadding, 0, 0);
            mViewHost.relayout(lp);
            Trace.endSection();
        }
@@ -678,6 +681,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        int mShadowRadiusId;
        int mCornerRadius;

        int mCaptionTopPadding;

        Configuration mWindowDecorConfig;

        boolean mApplyStartTransactionOnDraw;
@@ -693,6 +698,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
            mShadowRadiusId = Resources.ID_NULL;
            mCornerRadius = 0;

            mCaptionTopPadding = 0;

            mApplyStartTransactionOnDraw = false;
            mSetTaskPositionAndCrop = false;
            mWindowDecorConfig = null;
+7 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.WindowConfiguration
import android.content.ComponentName
import android.testing.AndroidTestingRunner
import android.view.Display
import android.view.InsetsState
import android.view.WindowInsetsController
import androidx.test.filters.SmallTest
import com.android.wm.shell.ShellTestCase
@@ -45,7 +46,8 @@ class CaptionWindowDecorationTests : ShellTestCase() {
            relayoutParams,
            taskInfo,
            true,
            false
            false,
            InsetsState()
        )

        Truth.assertThat(relayoutParams.hasInputFeatureSpy()).isTrue()
@@ -63,7 +65,8 @@ class CaptionWindowDecorationTests : ShellTestCase() {
            relayoutParams,
            taskInfo,
            true,
            false
            false,
            InsetsState()
        )

        Truth.assertThat(relayoutParams.hasInputFeatureSpy()).isFalse()
@@ -77,7 +80,8 @@ class CaptionWindowDecorationTests : ShellTestCase() {
            relayoutParams,
            taskInfo,
            true,
            false
            false,
            InsetsState()
        )
        Truth.assertThat(relayoutParams.mOccludingCaptionElements.size).isEqualTo(2)
        Truth.assertThat(relayoutParams.mOccludingCaptionElements[0].mAlignment).isEqualTo(
+3 −0
Original line number Diff line number Diff line
@@ -865,6 +865,7 @@ public class WindowDecorationTests extends ShellTestCase {
        final TestWindowDecoration windowDecor = createWindowDecoration(
                new TestRunningTaskInfoBuilder().build());
        mRelayoutParams.mApplyStartTransactionOnDraw = true;
        mRelayoutResult.mRootView = mMockView;

        windowDecor.updateViewHost(mRelayoutParams, mMockSurfaceControlStartT, mRelayoutResult);

@@ -876,6 +877,7 @@ public class WindowDecorationTests extends ShellTestCase {
        final TestWindowDecoration windowDecor = createWindowDecoration(
                new TestRunningTaskInfoBuilder().build());
        mRelayoutParams.mApplyStartTransactionOnDraw = true;
        mRelayoutResult.mRootView = mMockView;

        assertThrows(IllegalArgumentException.class,
                () -> windowDecor.updateViewHost(
@@ -887,6 +889,7 @@ public class WindowDecorationTests extends ShellTestCase {
        final TestWindowDecoration windowDecor = createWindowDecoration(
                new TestRunningTaskInfoBuilder().build());
        mRelayoutParams.mApplyStartTransactionOnDraw = false;
        mRelayoutResult.mRootView = mMockView;

        windowDecor.updateViewHost(mRelayoutParams, null /* onDrawTransaction */, mRelayoutResult);
    }