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

Commit ae644bed authored by Will Osborn's avatar Will Osborn
Browse files

Get Context for corner radius from correct display

Test: local + presubmit
Flag: EXEMPT bugfix
Bug: 416287239

Change-Id: If788e737f93e22e37bbc1a1aed1120119678aa97
parent a73c04e8
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -700,13 +700,15 @@ public abstract class WMShellModule {
            ShellTaskOrganizer shellTaskOrganizer,
            Transitions transitions,
            Optional<RecentTasksController> recentTasksController,
            HomeTransitionObserver homeTransitionObserver) {
            HomeTransitionObserver homeTransitionObserver,
            DisplayController displayController) {
        return new RecentsTransitionHandler(
                shellInit,
                shellTaskOrganizer,
                transitions,
                recentTasksController.orElse(null),
                homeTransitionObserver);
                homeTransitionObserver,
                displayController);
    }

    //
+13 −5
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ import com.android.internal.os.IResultReceiver;
import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.Flags;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.R;
@@ -121,18 +122,21 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,

    private final HomeTransitionObserver mHomeTransitionObserver;
    private @Nullable Color mBackgroundColor;
    private final DisplayController mDisplayController;

    public RecentsTransitionHandler(
            @NonNull ShellInit shellInit,
            @NonNull ShellTaskOrganizer shellTaskOrganizer,
            @NonNull Transitions transitions,
            @Nullable RecentTasksController recentTasksController,
            @NonNull HomeTransitionObserver homeTransitionObserver) {
            @NonNull HomeTransitionObserver homeTransitionObserver,
            @NonNull DisplayController displayController) {
        mShellTaskOrganizer = shellTaskOrganizer;
        mTransitions = transitions;
        mExecutor = transitions.getMainExecutor();
        mRecentTasksController = recentTasksController;
        mHomeTransitionObserver = homeTransitionObserver;
        mDisplayController = displayController;
        if (recentTasksController == null) return;
        shellInit.addInitCallback(this::onInit, this);
    }
@@ -1636,24 +1640,28 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
            }
        }

        private static void setCornerRadiusForFreeformTasks(
        private void setCornerRadiusForFreeformTasks(
                Context context,
                SurfaceControl.Transaction t,
                ArrayList<TaskState> tasks) {
            if (!ENABLE_DESKTOP_RECENTS_TRANSITIONS_CORNERS_BUGFIX.isTrue()) {
                return;
            }
            int cornerRadius = getCornerRadius(context);
            for (int i = 0; i < tasks.size(); ++i) {
                TaskState task = tasks.get(i);
                if (task.mTaskInfo != null && task.mTaskInfo.isFreeform()) {
                    int cornerRadius = getCornerRadius(context, task.mTaskInfo.displayId);
                    t.setCornerRadius(task.mTaskSurface, cornerRadius);
                }
            }
        }

        private static int getCornerRadius(Context context) {
            return context.getResources().getDimensionPixelSize(
        private int getCornerRadius(Context context, int displayId) {
            Context displayContext = mDisplayController.getDisplayContext(displayId);
            if (displayContext == null) {
                displayContext = context;
            }
            return displayContext.getResources().getDimensionPixelSize(
                    R.dimen.desktop_windowing_freeform_rounded_corner_radius);
        }

+40 −1
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.TestRunningTaskInfoBuilder;
import com.android.wm.shell.TestShellExecutor;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.DisplayInsetsController;
import com.android.wm.shell.common.TaskStackListenerImpl;
import com.android.wm.shell.desktopmode.DesktopRepository;
@@ -102,6 +103,8 @@ import java.util.Optional;
public class RecentsTransitionHandlerTest extends ShellTestCase {

    private static final int FREEFORM_TASK_CORNER_RADIUS = 32;
    private static final int FREEFORM_TASK_CORNER_RADIUS_ON_CD = 24;
    private static final int CONNECTED_DISPLAY_ID = 1;

    @Mock
    private Context mContext;
@@ -125,6 +128,9 @@ public class RecentsTransitionHandlerTest extends ShellTestCase {
    private UserManager mUserManager;

    @Mock private DesktopRepository mDesktopRepository;
    @Mock private DisplayController mDisplayController;
    @Mock private Context mConnectedDisplayContext;
    @Mock private Resources mConnectedDisplayResources;

    private ShellTaskOrganizer mShellTaskOrganizer;
    private RecentTasksController mRecentTasksController;
@@ -151,6 +157,12 @@ public class RecentsTransitionHandlerTest extends ShellTestCase {
        when(mResources.getDimensionPixelSize(
                R.dimen.desktop_windowing_freeform_rounded_corner_radius)
        ).thenReturn(FREEFORM_TASK_CORNER_RADIUS);
        when(mDisplayController.getDisplayContext(CONNECTED_DISPLAY_ID)).thenReturn(
                mConnectedDisplayContext);
        when(mConnectedDisplayContext.getResources()).thenReturn(mConnectedDisplayResources);
        when(mConnectedDisplayResources.getDimensionPixelSize(
                R.dimen.desktop_windowing_freeform_rounded_corner_radius)
        ).thenReturn(FREEFORM_TASK_CORNER_RADIUS_ON_CD);
        mShellInit = spy(new ShellInit(mMainExecutor));
        mShellController = spy(new ShellController(mContext, mShellInit, mShellCommandHandler,
                mDisplayInsetsController, mUserManager, mMainExecutor));
@@ -165,7 +177,8 @@ public class RecentsTransitionHandlerTest extends ShellTestCase {

        doReturn(mMainExecutor).when(mTransitions).getMainExecutor();
        mRecentsTransitionHandler = new RecentsTransitionHandler(mShellInit, mShellTaskOrganizer,
                mTransitions, mRecentTasksController, mock(HomeTransitionObserver.class));
                mTransitions, mRecentTasksController, mock(HomeTransitionObserver.class),
                mDisplayController);
        // By default use a mock finish transaction since we are sending transitions that don't have
        // real surface controls
        mRecentsTransitionHandler.setFinishTransactionSupplier(
@@ -440,6 +453,32 @@ public class RecentsTransitionHandlerTest extends ShellTestCase {
        verify(finishT).setCornerRadius(leash, FREEFORM_TASK_CORNER_RADIUS);
    }

    @Test
    @EnableFlags(FLAG_ENABLE_DESKTOP_RECENTS_TRANSITIONS_CORNERS_BUGFIX)
    public void testFinish_returningToFreeformTasks_setsCornerRadiusOnConnectedDisplay() {
        ActivityManager.RunningTaskInfo freeformTask =
                new TestRunningTaskInfoBuilder().setWindowingMode(
                        WINDOWING_MODE_FREEFORM).setDisplayId(CONNECTED_DISPLAY_ID).build();
        TransitionInfo transitionInfo = new TransitionInfoBuilder(TRANSIT_CLOSE)
                .addChange(TRANSIT_CLOSE, freeformTask)
                .build();
        SurfaceControl leash = transitionInfo.getChanges().get(0).getLeash();
        final IBinder transition = startRecentsTransition(/* synthetic= */ false);
        SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
        mRecentsTransitionHandler.setFinishTransactionSupplier(() -> finishT);
        mRecentsTransitionHandler.startAnimation(
                transition, transitionInfo, new StubTransaction(),
                new StubTransaction(),
                mock(Transitions.TransitionFinishCallback.class));

        mRecentsTransitionHandler.findController(transition).finish(/* toHome= */ false,
                false /* sendUserLeaveHint */, mock(IResultReceiver.class));
        mMainExecutor.flushAll();


        verify(finishT).setCornerRadius(leash, FREEFORM_TASK_CORNER_RADIUS_ON_CD);
    }

    private IBinder startRecentsTransition(boolean synthetic) {
        return startRecentsTransition(synthetic, mock(IRecentsAnimationRunner.class));
    }
+2 −1
Original line number Diff line number Diff line
@@ -1325,7 +1325,8 @@ public class ShellTransitionTests extends ShellTestCase {
        doReturn(mContext).when(mockRecentsTaskController).getContext();
        final RecentsTransitionHandler recentsHandler =
                new RecentsTransitionHandler(shellInit, mock(ShellTaskOrganizer.class), transitions,
                        mockRecentsTaskController, mock(HomeTransitionObserver.class));
                        mockRecentsTaskController, mock(HomeTransitionObserver.class),
                        mock(DisplayController.class));
        recentsHandler.setFinishTransactionSupplier(
                () -> mock(SurfaceControl.Transaction.class));
        transitions.replaceDefaultHandlerForTest(mDefaultHandler);