summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Eghosa Ewansiha-Vlachavas <eevlachavas@google.com> 2024-02-26 14:43:45 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-02-26 14:43:45 +0000
commitee3c8fc2d5c19e059c0fdc635c589abdeca1e141 (patch)
treedaaca56f20265e917894303603e05b05f93677cf
parent973636110c22dad9a3ab355f528478dfce52c11c (diff)
parentb8cc5006305ba05ed5153a00d7c5d1c2f7a2f58e (diff)
Merge "Modify desktop windowing initial bounds" into main
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeVisualIndicator.java5
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt39
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/EnterDesktopTaskTransitionHandler.java2
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java8
-rw-r--r--services/core/java/com/android/server/wm/DesktopModeLaunchParamsModifier.java40
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java17
6 files changed, 50 insertions, 61 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeVisualIndicator.java b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeVisualIndicator.java
index 405341803a46..7091c4b7210a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeVisualIndicator.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeVisualIndicator.java
@@ -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_MULTI_WINDOW;
-import static com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler.FINAL_FREEFORM_SCALE;
-
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.RectEvaluator;
@@ -389,7 +387,8 @@ public class DesktopModeVisualIndicator {
layout.width() - padding,
layout.height() - padding);
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),
(int) (adjustmentPercentage * layout.height() / 2),
(int) (layout.width() - (adjustmentPercentage * layout.width() / 2)),
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
index 98f9988eaabb..dcffb2d3e8fa 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
@@ -16,7 +16,6 @@
package com.android.wm.shell.desktopmode
-import android.app.ActivityManager
import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityOptions
import android.app.PendingIntent
@@ -35,7 +34,6 @@ import android.graphics.Rect
import android.graphics.Region
import android.os.IBinder
import android.os.SystemProperties
-import android.util.DisplayMetrics.DENSITY_DEFAULT
import android.view.Display.DEFAULT_DISPLAY
import android.view.SurfaceControl
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.ShellTaskOrganizer
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.ExternalInterfaceBinder
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.draganddrop.DragAndDropController
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.RecentsTransitionStateListener
import com.android.wm.shell.splitscreen.SplitScreenController
@@ -85,7 +83,6 @@ import com.android.wm.shell.windowdecor.OnTaskResizeAnimationListener
import java.io.PrintWriter
import java.util.concurrent.Executor
import java.util.function.Consumer
-import java.util.function.Function
/** Handles moving tasks in and out of desktop */
class DesktopTasksController(
@@ -551,11 +548,7 @@ class DesktopTasksController(
if (taskInfo.configuration.windowConfiguration.bounds == stableBounds) {
// The desktop task is currently occupying the whole stable bounds, toggle to the
// default bounds.
- getDefaultDesktopTaskBounds(
- density = taskInfo.configuration.densityDpi.toFloat() / DENSITY_DEFAULT,
- stableBounds = stableBounds,
- outBounds = destinationBounds
- )
+ getDefaultDesktopTaskBounds(displayLayout, destinationBounds)
} else {
// Toggle to the stable bounds.
destinationBounds.set(stableBounds)
@@ -610,15 +603,17 @@ class DesktopTasksController(
}
}
- private fun getDefaultDesktopTaskBounds(density: Float, stableBounds: Rect, outBounds: Rect) {
- val width = (DESKTOP_MODE_DEFAULT_WIDTH_DP * density + 0.5f).toInt()
- val height = (DESKTOP_MODE_DEFAULT_HEIGHT_DP * density + 0.5f).toInt()
- outBounds.set(0, 0, width, height)
- // Center the task in stable bounds
+ private fun getDefaultDesktopTaskBounds(displayLayout: DisplayLayout, outBounds: Rect) {
+ // TODO(b/319819547): Account for app constraints so apps do not become letterboxed
+ val screenBounds = Rect(0, 0, displayLayout.width(), displayLayout.height())
+ // Update width and height with default desktop mode values
+ 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(
- stableBounds.centerX() - outBounds.centerX(),
- stableBounds.centerY() - outBounds.centerY()
- )
+ screenBounds.centerX() - outBounds.centerX(),
+ screenBounds.centerY() - outBounds.centerY())
}
/**
@@ -1233,13 +1228,9 @@ class DesktopTasksController(
SystemProperties.getInt("persist.wm.debug.desktop_mode_density", 284)
private val DESKTOP_DENSITY_ALLOWED_RANGE = (100..1000)
- // Override default freeform task width when desktop mode is enabled. In dips.
- private val DESKTOP_MODE_DEFAULT_WIDTH_DP =
- SystemProperties.getInt("persist.wm.debug.desktop_mode.default_width", 840)
-
- // 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)
+ @JvmField
+ val DESKTOP_MODE_INITIAL_BOUNDS_SCALE = SystemProperties
+ .getInt("persist.wm.debug.freeform_initial_bounds_scale", 75) / 100f
/**
* Check if desktop density override is enabled
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/EnterDesktopTaskTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/EnterDesktopTaskTransitionHandler.java
index 07cf202ddfac..79bb5408df82 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/EnterDesktopTaskTransitionHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/EnterDesktopTaskTransitionHandler.java
@@ -54,8 +54,6 @@ public class EnterDesktopTaskTransitionHandler implements Transitions.Transition
private final Transitions mTransitions;
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;
private final List<IBinder> mPendingTransitionTokens = new ArrayList<>();
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
index 5b8ffb30dc4a..c1406d052195 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
@@ -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_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.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
*/
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 int screenWidth = displayLayout.width();
final int screenHeight = displayLayout.height();
final float adjustmentPercentage = (1f - scale) / 2;
- final Rect endBounds = new Rect((int) (screenWidth * adjustmentPercentage),
+ return new Rect((int) (screenWidth * adjustmentPercentage),
(int) (screenHeight * adjustmentPercentage),
(int) (screenWidth * (adjustmentPercentage + scale)),
(int) (screenHeight * (adjustmentPercentage + scale)));
- return endBounds;
}
/**
@@ -875,7 +874,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
c -> {
c.onDragPositioningEndThroughStatusBar(relevantDecor.mTaskInfo,
calculateFreeformBounds(ev.getDisplayId(),
- FINAL_FREEFORM_SCALE));
+ DesktopTasksController
+ .DESKTOP_MODE_INITIAL_BOUNDS_SCALE));
});
}
});
diff --git a/services/core/java/com/android/server/wm/DesktopModeLaunchParamsModifier.java b/services/core/java/com/android/server/wm/DesktopModeLaunchParamsModifier.java
index 1dc9493eddc6..f11d6ec0828c 100644
--- a/services/core/java/com/android/server/wm/DesktopModeLaunchParamsModifier.java
+++ b/services/core/java/com/android/server/wm/DesktopModeLaunchParamsModifier.java
@@ -16,8 +16,6 @@
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_WITH_CLASS_NAME;
@@ -30,7 +28,6 @@ import android.util.Slog;
import com.android.server.wm.LaunchParamsController.LaunchParamsModifier;
import com.android.wm.shell.Flags;
-
/**
* 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 DESKTOP_MODE_PROTO2_SUPPORTED =
SystemProperties.getBoolean("persist.wm.debug.desktop_mode_2", false);
- // Override default freeform task width when desktop mode is enabled. In dips.
- private static final int DESKTOP_MODE_DEFAULT_WIDTH_DP = SystemProperties.getInt(
- "persist.wm.debug.desktop_mode.default_width", 840);
- // 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);
+ public static final float DESKTOP_MODE_INITIAL_BOUNDS_SCALE =
+ SystemProperties
+ .getInt("persist.wm.debug.desktop_mode_initial_bounds_scale", 75) / 100f;
private StringBuilder mLogBuilder;
@@ -108,23 +102,29 @@ public class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
return RESULT_SKIP;
}
- // Update width and height with default desktop mode values
- 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());
+ calculateAndCentreInitialBounds(task, outParams);
appendLog("setting desktop mode task bounds to %s", outParams.mBounds);
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) {
if (DEBUG) {
mLogBuilder = new StringBuilder(
diff --git a/services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java b/services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java
index dc4e47dfea30..ef36bff91a67 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java
@@ -20,8 +20,8 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
-import static android.util.DisplayMetrics.DENSITY_DEFAULT;
+import static com.android.server.wm.DesktopModeLaunchParamsModifier.DESKTOP_MODE_INITIAL_BOUNDS_SCALE;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_BOUNDS;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_DISPLAY;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.RESULT_DONE;
@@ -30,6 +30,7 @@ import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
+import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
@@ -113,9 +114,14 @@ public class DesktopModeLaunchParamsModifierTests extends WindowTestsBase {
public void testUsesDefaultBounds() {
final Task task = new TaskBuilder(mSupervisor).setActivityType(
ACTIVITY_TYPE_STANDARD).build();
+ final int displayHeight = 1600;
+ final int displayWidth = 2560;
+ task.getDisplayArea().setBounds(new Rect(0, 0, displayWidth, displayHeight));
+ final int desiredWidth = (int) (displayWidth * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
+ final int desiredHeight = (int) (displayHeight * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
assertEquals(RESULT_DONE, new CalculateRequestBuilder().setTask(task).calculate());
- assertEquals(dpiToPx(task, 840), mResult.mBounds.width());
- assertEquals(dpiToPx(task, 630), mResult.mBounds.height());
+ assertEquals(desiredWidth, mResult.mBounds.width());
+ assertEquals(desiredHeight, mResult.mBounds.height());
}
@Test
@@ -131,11 +137,6 @@ public class DesktopModeLaunchParamsModifierTests extends WindowTestsBase {
assertEquals(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode);
}
- private int dpiToPx(Task task, int dpi) {
- float density = (float) task.getConfiguration().densityDpi / DENSITY_DEFAULT;
- return (int) (dpi * density + 0.5f);
- }
-
private class CalculateRequestBuilder {
private Task mTask;
private int mPhase = PHASE_BOUNDS;