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

Commit ee3c8fc2 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge "Modify desktop windowing initial bounds" into main

parents 97363611 b8cc5006
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -22,8 +22,6 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;


import static com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler.FINAL_FREEFORM_SCALE;

import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.RectEvaluator;
import android.animation.RectEvaluator;
@@ -389,7 +387,8 @@ public class DesktopModeVisualIndicator {
                            layout.width() - padding,
                            layout.width() - padding,
                            layout.height() - padding);
                            layout.height() - padding);
                case TO_DESKTOP_INDICATOR:
                case TO_DESKTOP_INDICATOR:
                    final float adjustmentPercentage = 1f - FINAL_FREEFORM_SCALE;
                    final float adjustmentPercentage = 1f
                            - DesktopTasksController.DESKTOP_MODE_INITIAL_BOUNDS_SCALE;
                    return new Rect((int) (adjustmentPercentage * layout.width() / 2),
                    return new Rect((int) (adjustmentPercentage * layout.width() / 2),
                            (int) (adjustmentPercentage * layout.height() / 2),
                            (int) (adjustmentPercentage * layout.height() / 2),
                            (int) (layout.width() - (adjustmentPercentage * layout.width() / 2)),
                            (int) (layout.width() - (adjustmentPercentage * layout.width() / 2)),
+15 −24
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


package com.android.wm.shell.desktopmode
package com.android.wm.shell.desktopmode


import android.app.ActivityManager
import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityOptions
import android.app.ActivityOptions
import android.app.PendingIntent
import android.app.PendingIntent
@@ -35,7 +34,6 @@ import android.graphics.Rect
import android.graphics.Region
import android.graphics.Region
import android.os.IBinder
import android.os.IBinder
import android.os.SystemProperties
import android.os.SystemProperties
import android.util.DisplayMetrics.DENSITY_DEFAULT
import android.view.Display.DEFAULT_DISPLAY
import android.view.Display.DEFAULT_DISPLAY
import android.view.SurfaceControl
import android.view.SurfaceControl
import android.view.WindowManager.TRANSIT_CHANGE
import android.view.WindowManager.TRANSIT_CHANGE
@@ -51,6 +49,7 @@ import com.android.internal.policy.ScreenDecorationsUtils
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayLayout
import com.android.wm.shell.common.ExecutorUtils
import com.android.wm.shell.common.ExecutorUtils
import com.android.wm.shell.common.ExternalInterfaceBinder
import com.android.wm.shell.common.ExternalInterfaceBinder
import com.android.wm.shell.common.LaunchAdjacentController
import com.android.wm.shell.common.LaunchAdjacentController
@@ -68,7 +67,6 @@ import com.android.wm.shell.desktopmode.DesktopModeTaskRepository.VisibleTasksLi
import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler.DragToDesktopStateListener
import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler.DragToDesktopStateListener
import com.android.wm.shell.draganddrop.DragAndDropController
import com.android.wm.shell.draganddrop.DragAndDropController
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.recents.RecentTasksController
import com.android.wm.shell.recents.RecentsTransitionHandler
import com.android.wm.shell.recents.RecentsTransitionHandler
import com.android.wm.shell.recents.RecentsTransitionStateListener
import com.android.wm.shell.recents.RecentsTransitionStateListener
import com.android.wm.shell.splitscreen.SplitScreenController
import com.android.wm.shell.splitscreen.SplitScreenController
@@ -85,7 +83,6 @@ import com.android.wm.shell.windowdecor.OnTaskResizeAnimationListener
import java.io.PrintWriter
import java.io.PrintWriter
import java.util.concurrent.Executor
import java.util.concurrent.Executor
import java.util.function.Consumer
import java.util.function.Consumer
import java.util.function.Function


/** Handles moving tasks in and out of desktop */
/** Handles moving tasks in and out of desktop */
class DesktopTasksController(
class DesktopTasksController(
@@ -551,11 +548,7 @@ class DesktopTasksController(
        if (taskInfo.configuration.windowConfiguration.bounds == stableBounds) {
        if (taskInfo.configuration.windowConfiguration.bounds == stableBounds) {
            // The desktop task is currently occupying the whole stable bounds, toggle to the
            // The desktop task is currently occupying the whole stable bounds, toggle to the
            // default bounds.
            // default bounds.
            getDefaultDesktopTaskBounds(
            getDefaultDesktopTaskBounds(displayLayout, destinationBounds)
                density = taskInfo.configuration.densityDpi.toFloat() / DENSITY_DEFAULT,
                stableBounds = stableBounds,
                outBounds = destinationBounds
            )
        } else {
        } else {
            // Toggle to the stable bounds.
            // Toggle to the stable bounds.
            destinationBounds.set(stableBounds)
            destinationBounds.set(stableBounds)
@@ -610,15 +603,17 @@ class DesktopTasksController(
        }
        }
    }
    }


    private fun getDefaultDesktopTaskBounds(density: Float, stableBounds: Rect, outBounds: Rect) {
    private fun getDefaultDesktopTaskBounds(displayLayout: DisplayLayout, outBounds: Rect) {
        val width = (DESKTOP_MODE_DEFAULT_WIDTH_DP * density + 0.5f).toInt()
        // TODO(b/319819547): Account for app constraints so apps do not become letterboxed
        val height = (DESKTOP_MODE_DEFAULT_HEIGHT_DP * density + 0.5f).toInt()
        val screenBounds = Rect(0, 0, displayLayout.width(), displayLayout.height())
        outBounds.set(0, 0, width, height)
        // Update width and height with default desktop mode values
        // Center the task in stable bounds
        val desiredWidth = screenBounds.width().times(DESKTOP_MODE_INITIAL_BOUNDS_SCALE).toInt()
        val desiredHeight = screenBounds.height().times(DESKTOP_MODE_INITIAL_BOUNDS_SCALE).toInt()
        outBounds.set(0, 0, desiredWidth, desiredHeight)
        // Center the task in screen bounds
        outBounds.offset(
        outBounds.offset(
            stableBounds.centerX() - outBounds.centerX(),
                screenBounds.centerX() - outBounds.centerX(),
            stableBounds.centerY() - outBounds.centerY()
                screenBounds.centerY() - outBounds.centerY())
        )
    }
    }


    /**
    /**
@@ -1233,13 +1228,9 @@ class DesktopTasksController(
            SystemProperties.getInt("persist.wm.debug.desktop_mode_density", 284)
            SystemProperties.getInt("persist.wm.debug.desktop_mode_density", 284)
        private val DESKTOP_DENSITY_ALLOWED_RANGE = (100..1000)
        private val DESKTOP_DENSITY_ALLOWED_RANGE = (100..1000)


        // Override default freeform task width when desktop mode is enabled. In dips.
        @JvmField
        private val DESKTOP_MODE_DEFAULT_WIDTH_DP =
        val DESKTOP_MODE_INITIAL_BOUNDS_SCALE = SystemProperties
            SystemProperties.getInt("persist.wm.debug.desktop_mode.default_width", 840)
                .getInt("persist.wm.debug.freeform_initial_bounds_scale", 75) / 100f

        // Override default freeform task height when desktop mode is enabled. In dips.
        private val DESKTOP_MODE_DEFAULT_HEIGHT_DP =
            SystemProperties.getInt("persist.wm.debug.desktop_mode.default_height", 630)


        /**
        /**
         * Check if desktop density override is enabled
         * Check if desktop density override is enabled
+0 −2
Original line number Original line Diff line number Diff line
@@ -54,8 +54,6 @@ public class EnterDesktopTaskTransitionHandler implements Transitions.Transition
    private final Transitions mTransitions;
    private final Transitions mTransitions;
    private final Supplier<SurfaceControl.Transaction> mTransactionSupplier;
    private final Supplier<SurfaceControl.Transaction> mTransactionSupplier;


    // The size of the screen after drag relative to the fullscreen size
    public static final float FINAL_FREEFORM_SCALE = 0.6f;
    public static final int FREEFORM_ANIMATION_DURATION = 336;
    public static final int FREEFORM_ANIMATION_DURATION = 336;


    private final List<IBinder> mPendingTransitionTokens = new ArrayList<>();
    private final List<IBinder> mPendingTransitionTokens = new ArrayList<>();
+4 −4
Original line number Original line Diff line number Diff line
@@ -28,7 +28,6 @@ import static android.view.WindowInsets.Type.statusBars;


import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
import static com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler.FINAL_FREEFORM_SCALE;
import static com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler.FREEFORM_ANIMATION_DURATION;
import static com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler.FREEFORM_ANIMATION_DURATION;
import static com.android.wm.shell.windowdecor.MoveToDesktopAnimator.DRAG_FREEFORM_SCALE;
import static com.android.wm.shell.windowdecor.MoveToDesktopAnimator.DRAG_FREEFORM_SCALE;


@@ -824,16 +823,16 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
     * @param scale the amount to scale to relative to the Screen Bounds
     * @param scale the amount to scale to relative to the Screen Bounds
     */
     */
    private Rect calculateFreeformBounds(int displayId, float scale) {
    private Rect calculateFreeformBounds(int displayId, float scale) {
        // TODO(b/319819547): Account for app constraints so apps do not become letterboxed
        final DisplayLayout displayLayout = mDisplayController.getDisplayLayout(displayId);
        final DisplayLayout displayLayout = mDisplayController.getDisplayLayout(displayId);
        final int screenWidth = displayLayout.width();
        final int screenWidth = displayLayout.width();
        final int screenHeight = displayLayout.height();
        final int screenHeight = displayLayout.height();


        final float adjustmentPercentage = (1f - scale) / 2;
        final float adjustmentPercentage = (1f - scale) / 2;
        final Rect endBounds = new Rect((int) (screenWidth * adjustmentPercentage),
        return new Rect((int) (screenWidth * adjustmentPercentage),
                (int) (screenHeight * adjustmentPercentage),
                (int) (screenHeight * adjustmentPercentage),
                (int) (screenWidth * (adjustmentPercentage + scale)),
                (int) (screenWidth * (adjustmentPercentage + scale)),
                (int) (screenHeight * (adjustmentPercentage + scale)));
                (int) (screenHeight * (adjustmentPercentage + scale)));
        return endBounds;
    }
    }


    /**
    /**
@@ -875,7 +874,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                        c -> {
                        c -> {
                            c.onDragPositioningEndThroughStatusBar(relevantDecor.mTaskInfo,
                            c.onDragPositioningEndThroughStatusBar(relevantDecor.mTaskInfo,
                                    calculateFreeformBounds(ev.getDisplayId(),
                                    calculateFreeformBounds(ev.getDisplayId(),
                                            FINAL_FREEFORM_SCALE));
                                            DesktopTasksController
                                                    .DESKTOP_MODE_INITIAL_BOUNDS_SCALE));
                        });
                        });
            }
            }
        });
        });
+20 −20
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


package com.android.server.wm;
package com.android.server.wm;


import static android.util.DisplayMetrics.DENSITY_DEFAULT;

import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;


@@ -30,7 +28,6 @@ import android.util.Slog;


import com.android.server.wm.LaunchParamsController.LaunchParamsModifier;
import com.android.server.wm.LaunchParamsController.LaunchParamsModifier;
import com.android.wm.shell.Flags;
import com.android.wm.shell.Flags;

/**
/**
 * The class that defines default launch params for tasks in desktop mode
 * The class that defines default launch params for tasks in desktop mode
 */
 */
@@ -44,12 +41,9 @@ public class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
    private static final boolean ENABLE_DESKTOP_WINDOWING = Flags.enableDesktopWindowing();
    private static final boolean ENABLE_DESKTOP_WINDOWING = Flags.enableDesktopWindowing();
    private static final boolean DESKTOP_MODE_PROTO2_SUPPORTED =
    private static final boolean DESKTOP_MODE_PROTO2_SUPPORTED =
            SystemProperties.getBoolean("persist.wm.debug.desktop_mode_2", false);
            SystemProperties.getBoolean("persist.wm.debug.desktop_mode_2", false);
    // Override default freeform task width when desktop mode is enabled. In dips.
    public static final float DESKTOP_MODE_INITIAL_BOUNDS_SCALE =
    private static final int DESKTOP_MODE_DEFAULT_WIDTH_DP = SystemProperties.getInt(
            SystemProperties
            "persist.wm.debug.desktop_mode.default_width", 840);
                    .getInt("persist.wm.debug.desktop_mode_initial_bounds_scale", 75) / 100f;
    // Override default freeform task height when desktop mode is enabled. In dips.
    private static final int DESKTOP_MODE_DEFAULT_HEIGHT_DP = SystemProperties.getInt(
            "persist.wm.debug.desktop_mode.default_height", 630);


    private StringBuilder mLogBuilder;
    private StringBuilder mLogBuilder;


@@ -108,23 +102,29 @@ public class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            return RESULT_SKIP;
            return RESULT_SKIP;
        }
        }


        // Update width and height with default desktop mode values
        calculateAndCentreInitialBounds(task, outParams);
        float density = (float) task.getConfiguration().densityDpi / DENSITY_DEFAULT;
        final int width = (int) (DESKTOP_MODE_DEFAULT_WIDTH_DP * density + 0.5f);
        final int height = (int) (DESKTOP_MODE_DEFAULT_HEIGHT_DP * density + 0.5f);
        outParams.mBounds.right = width;
        outParams.mBounds.bottom = height;

        // Center the task in window bounds
        Rect windowBounds = task.getWindowConfiguration().getBounds();
        outParams.mBounds.offset(windowBounds.centerX() - outParams.mBounds.centerX(),
                windowBounds.centerY() - outParams.mBounds.centerY());


        appendLog("setting desktop mode task bounds to %s", outParams.mBounds);
        appendLog("setting desktop mode task bounds to %s", outParams.mBounds);


        return RESULT_DONE;
        return RESULT_DONE;
    }
    }


    /**
     * Calculates the initial height and width of a task in desktop mode and centers it within the
     * window bounds.
     */
    private void calculateAndCentreInitialBounds(Task task,
            LaunchParamsController.LaunchParams outParams) {
        // TODO(b/319819547): Account for app constraints so apps do not become letterboxed
        final Rect windowBounds = task.getDisplayArea().getBounds();
        final int width = (int) (windowBounds.width() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
        final int height = (int) (windowBounds.height() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
        outParams.mBounds.right = width;
        outParams.mBounds.bottom = height;
        outParams.mBounds.offset(windowBounds.centerX() - outParams.mBounds.centerX(),
                windowBounds.centerY() - outParams.mBounds.centerY());
    }

    private void initLogBuilder(Task task, ActivityRecord activity) {
    private void initLogBuilder(Task task, ActivityRecord activity) {
        if (DEBUG) {
        if (DEBUG) {
            mLogBuilder = new StringBuilder(
            mLogBuilder = new StringBuilder(
Loading