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

Commit cd00e1e6 authored by Jorge Gil's avatar Jorge Gil
Browse files

Remove window decor for constructor

The window decor config should be created based on the type of caption
that will be drawn (handle vs header) because the density in the config
can be different for each type. Instead of passing in a config in the
ctor, always calculate it on relayout(), which is when the caption type
is known for the first time. The config isn't needed before relayout().

Bug: 332414819
Test: atest WMShellUnitTests
Change-Id: I9af8a483e648b9b94cddf7037a86bd27f595ed57
parent ef81b387
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -93,8 +93,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
            Choreographer choreographer,
            SyncTransactionQueue syncQueue,
            ResizeHandleSizeRepository resizeHandleSizeRepository) {
        super(context, displayController, taskOrganizer, taskInfo, taskSurface,
                taskInfo.getConfiguration());
        super(context, displayController, taskOrganizer, taskInfo, taskSurface);

        mHandler = handler;
        mChoreographer = choreographer;
+2 −9
Original line number Diff line number Diff line
@@ -140,13 +140,12 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            ShellTaskOrganizer taskOrganizer,
            ActivityManager.RunningTaskInfo taskInfo,
            SurfaceControl taskSurface,
            Configuration windowDecorConfig,
            Handler handler,
            Choreographer choreographer,
            SyncTransactionQueue syncQueue,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer,
            ResizeHandleSizeRepository resizeHandleSizeRepository) {
        this (context, displayController, taskOrganizer, taskInfo, taskSurface, windowDecorConfig,
        this (context, displayController, taskOrganizer, taskInfo, taskSurface,
                handler, choreographer, syncQueue, rootTaskDisplayAreaOrganizer,
                resizeHandleSizeRepository, SurfaceControl.Builder::new,
                SurfaceControl.Transaction::new, WindowContainerTransaction::new,
@@ -159,7 +158,6 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            ShellTaskOrganizer taskOrganizer,
            ActivityManager.RunningTaskInfo taskInfo,
            SurfaceControl taskSurface,
            Configuration windowDecorConfig,
            Handler handler,
            Choreographer choreographer,
            SyncTransactionQueue syncQueue,
@@ -170,7 +168,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            Supplier<WindowContainerTransaction> windowContainerTransactionSupplier,
            Supplier<SurfaceControl> surfaceControlSupplier,
            SurfaceControlViewHostFactory surfaceControlViewHostFactory) {
        super(context, displayController, taskOrganizer, taskInfo, taskSurface, windowDecorConfig,
        super(context, displayController, taskOrganizer, taskInfo, taskSurface,
                surfaceControlBuilderSupplier, surfaceControlTransactionSupplier,
                windowContainerTransactionSupplier, surfaceControlSupplier,
                surfaceControlViewHostFactory);
@@ -964,17 +962,12 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                SyncTransactionQueue syncQueue,
                RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer,
                ResizeHandleSizeRepository resizeHandleSizeRepository) {
            final Configuration windowDecorConfig =
                    DesktopModeStatus.isDesktopDensityOverrideSet()
                    ? context.getResources().getConfiguration() // Use system context
                    : taskInfo.configuration; // Use task configuration
            return new DesktopModeWindowDecoration(
                    context,
                    displayController,
                    taskOrganizer,
                    taskInfo,
                    taskSurface,
                    windowDecorConfig,
                    handler,
                    choreographer,
                    syncQueue,
+10 −9
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.windowdecor;

import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.content.res.Configuration.DENSITY_DPI_UNDEFINED;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsets.Type.mandatorySystemGestures;
import static android.view.WindowInsets.Type.statusBars;
@@ -145,9 +146,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
            DisplayController displayController,
            ShellTaskOrganizer taskOrganizer,
            RunningTaskInfo taskInfo,
            SurfaceControl taskSurface,
            Configuration windowDecorConfig) {
        this(context, displayController, taskOrganizer, taskInfo, taskSurface, windowDecorConfig,
            SurfaceControl taskSurface) {
        this(context, displayController, taskOrganizer, taskInfo, taskSurface,
                SurfaceControl.Builder::new, SurfaceControl.Transaction::new,
                WindowContainerTransaction::new, SurfaceControl::new,
                new SurfaceControlViewHostFactory() {});
@@ -159,7 +159,6 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
            ShellTaskOrganizer taskOrganizer,
            RunningTaskInfo taskInfo,
            @NonNull SurfaceControl taskSurface,
            Configuration windowDecorConfig,
            Supplier<SurfaceControl.Builder> surfaceControlBuilderSupplier,
            Supplier<SurfaceControl.Transaction> surfaceControlTransactionSupplier,
            Supplier<WindowContainerTransaction> windowContainerTransactionSupplier,
@@ -176,8 +175,6 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        mSurfaceControlViewHostFactory = surfaceControlViewHostFactory;

        mDisplay = mDisplayController.getDisplay(mTaskInfo.displayId);
        mWindowDecorConfig = windowDecorConfig;
        mDecorWindowContext = mContext.createConfigurationContext(mWindowDecorConfig);
    }

    /**
@@ -220,8 +217,11 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        outResult.mRootView = rootView;
        rootView = null; // Clear it just in case we use it accidentally

        final int oldDensityDpi = mWindowDecorConfig.densityDpi;
        final int oldNightMode = mWindowDecorConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK;
        final int oldDensityDpi = mWindowDecorConfig != null
                ? mWindowDecorConfig.densityDpi : DENSITY_DPI_UNDEFINED;
        final int oldNightMode =  mWindowDecorConfig != null
                ? (mWindowDecorConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK)
                : Configuration.UI_MODE_NIGHT_UNDEFINED;
        mWindowDecorConfig = params.mWindowDecorConfig != null ? params.mWindowDecorConfig
                : mTaskInfo.getConfiguration();
        final int newDensityDpi = mWindowDecorConfig.densityDpi;
@@ -230,7 +230,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
                || mDisplay == null
                || mDisplay.getDisplayId() != mTaskInfo.displayId
                || oldLayoutResId != mLayoutResId
                || oldNightMode != newNightMode) {
                || oldNightMode != newNightMode
                || mDecorWindowContext == null) {
            releaseViews(wct);

            if (!obtainDisplayOrRegisterListener()) {
+1 −1
Original line number Diff line number Diff line
@@ -346,7 +346,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
    private DesktopModeWindowDecoration createWindowDecoration(
            ActivityManager.RunningTaskInfo taskInfo) {
        return new DesktopModeWindowDecoration(mContext, mMockDisplayController,
                mMockShellTaskOrganizer, taskInfo, mMockSurfaceControl, mConfiguration,
                mMockShellTaskOrganizer, taskInfo, mMockSurfaceControl,
                mMockHandler, mMockChoreographer, mMockSyncQueue, mMockRootTaskDisplayAreaOrganizer,
                mMockResizeHandleSizeRepository, SurfaceControl.Builder::new,
                mMockTransactionSupplier, WindowContainerTransaction::new, SurfaceControl::new,
+10 −12
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import static org.mockito.quality.Strictness.LENIENT;

import android.app.ActivityManager;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Point;
@@ -134,7 +133,6 @@ public class WindowDecorationTests extends ShellTestCase {
    private SurfaceControl.Transaction mMockSurfaceControlFinishT;
    private SurfaceControl.Transaction mMockSurfaceControlAddWindowT;
    private WindowDecoration.RelayoutParams mRelayoutParams = new WindowDecoration.RelayoutParams();
    private Configuration mWindowConfiguration = new Configuration();
    private int mCaptionMenuWidthId;

    @Before
@@ -303,7 +301,6 @@ public class WindowDecorationTests extends ShellTestCase {
        taskInfo.isFocused = true;
        // Density is 2. Shadow radius is 10px. Caption height is 64px.
        taskInfo.configuration.densityDpi = DisplayMetrics.DENSITY_DEFAULT * 2;
        mWindowConfiguration.densityDpi = taskInfo.configuration.densityDpi;

        final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);

@@ -314,14 +311,16 @@ public class WindowDecorationTests extends ShellTestCase {
        verify(mMockWindowContainerTransaction, never())
                .removeInsetsSource(eq(taskInfo.token), any(), anyInt(), anyInt());

        final SurfaceControl.Transaction t2 = mock(SurfaceControl.Transaction.class);
        mMockSurfaceControlTransactions.add(t2);
        taskInfo.isVisible = false;
        windowDecor.relayout(taskInfo);

        final InOrder releaseOrder = inOrder(t, mMockSurfaceControlViewHost);
        final InOrder releaseOrder = inOrder(t2, mMockSurfaceControlViewHost);
        releaseOrder.verify(mMockSurfaceControlViewHost).release();
        releaseOrder.verify(t).remove(captionContainerSurface);
        releaseOrder.verify(t).remove(decorContainerSurface);
        releaseOrder.verify(t).apply();
        releaseOrder.verify(t2).remove(captionContainerSurface);
        releaseOrder.verify(t2).remove(decorContainerSurface);
        releaseOrder.verify(t2).apply();
        // Expect to remove two insets sources, the caption insets and the mandatory gesture insets.
        verify(mMockWindowContainerTransaction, Mockito.times(2))
                .removeInsetsSource(eq(taskInfo.token), any(), anyInt(), anyInt());
@@ -836,7 +835,7 @@ public class WindowDecorationTests extends ShellTestCase {

    private TestWindowDecoration createWindowDecoration(ActivityManager.RunningTaskInfo taskInfo) {
        return new TestWindowDecoration(mContext, mMockDisplayController, mMockShellTaskOrganizer,
                taskInfo, mMockTaskSurface, mWindowConfiguration,
                taskInfo, mMockTaskSurface,
                new MockObjectSupplier<>(mMockSurfaceControlBuilders,
                        () -> createMockSurfaceControlBuilder(mock(SurfaceControl.class))),
                new MockObjectSupplier<>(mMockSurfaceControlTransactions,
@@ -877,16 +876,15 @@ public class WindowDecorationTests extends ShellTestCase {
        TestWindowDecoration(Context context, DisplayController displayController,
                ShellTaskOrganizer taskOrganizer, ActivityManager.RunningTaskInfo taskInfo,
                SurfaceControl taskSurface,
                Configuration windowConfiguration,
                Supplier<SurfaceControl.Builder> surfaceControlBuilderSupplier,
                Supplier<SurfaceControl.Transaction> surfaceControlTransactionSupplier,
                Supplier<WindowContainerTransaction> windowContainerTransactionSupplier,
                Supplier<SurfaceControl> surfaceControlSupplier,
                SurfaceControlViewHostFactory surfaceControlViewHostFactory) {
            super(context, displayController, taskOrganizer, taskInfo, taskSurface,
                    windowConfiguration, surfaceControlBuilderSupplier,
                    surfaceControlTransactionSupplier, windowContainerTransactionSupplier,
                    surfaceControlSupplier, surfaceControlViewHostFactory);
                    surfaceControlBuilderSupplier, surfaceControlTransactionSupplier,
                    windowContainerTransactionSupplier, surfaceControlSupplier,
                    surfaceControlViewHostFactory);
        }

        @Override