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

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

Use mDecorWindowContext to verify window resources

Fixes an issue where two different Contexts are used to create an
AdditionalWindow and verify the SurfaceControl.Transactions on its
SurfaceControl.

The window is created using mDecorWindowContext, which may have an
overriden density and may be different that the density of the
display. Meanwhile, the verification phase was using the Context of
ShellTestCase.java, which is a TestableContext whose density will be
true to the display density. This CL changes that the verification
phase to also use mDecorWindowContext. It also changes the Context
object passed into the constructor of TestWindowDecoration from
Instrumentation.getContext() to the TestableContext for consistency.

Bug: 286259007
Test: `atest WindowDecorationTests`, then from settings change the
display size, then running `atest WindowDecorationTests` again.

Change-Id: I8d61f6836c7088efd5d77edf494066b2a2b12f8a
parent 2eb911d3
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import android.window.SurfaceSyncGroup;
import android.window.WindowContainerTransaction;

import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;

import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.ShellTestCase;
@@ -411,15 +410,17 @@ public class WindowDecorationTests extends ShellTestCase {
        verify(additionalWindowSurfaceBuilder).build();
        verify(mMockSurfaceControlAddWindowT).setPosition(additionalWindowSurface, 0, 0);
        final int width = WindowDecoration.loadDimensionPixelSize(
                mContext.getResources(), mCaptionMenuWidthId);
                windowDecor.mDecorWindowContext.getResources(), mCaptionMenuWidthId);
        final int height = WindowDecoration.loadDimensionPixelSize(
                mContext.getResources(), mRelayoutParams.mCaptionHeightId);
                windowDecor.mDecorWindowContext.getResources(), mRelayoutParams.mCaptionHeightId);
        verify(mMockSurfaceControlAddWindowT).setWindowCrop(additionalWindowSurface, width, height);
        final int shadowRadius = WindowDecoration.loadDimensionPixelSize(mContext.getResources(),
        final int shadowRadius = WindowDecoration.loadDimensionPixelSize(
                windowDecor.mDecorWindowContext.getResources(),
                mCaptionMenuShadowRadiusId);
        verify(mMockSurfaceControlAddWindowT)
                .setShadowRadius(additionalWindowSurface, shadowRadius);
        final int cornerRadius = WindowDecoration.loadDimensionPixelSize(mContext.getResources(),
        final int cornerRadius = WindowDecoration.loadDimensionPixelSize(
                windowDecor.mDecorWindowContext.getResources(),
                mCaptionMenuCornerRadiusId);
        verify(mMockSurfaceControlAddWindowT)
                .setCornerRadius(additionalWindowSurface, cornerRadius);
@@ -514,8 +515,7 @@ public class WindowDecorationTests extends ShellTestCase {

    private TestWindowDecoration createWindowDecoration(
            ActivityManager.RunningTaskInfo taskInfo, SurfaceControl testSurface) {
        return new TestWindowDecoration(InstrumentationRegistry.getInstrumentation().getContext(),
                mMockDisplayController, mMockShellTaskOrganizer,
        return new TestWindowDecoration(mContext, mMockDisplayController, mMockShellTaskOrganizer,
                taskInfo, testSurface,
                new MockObjectSupplier<>(mMockSurfaceControlBuilders,
                        () -> createMockSurfaceControlBuilder(mock(SurfaceControl.class))),