Loading core/java/com/android/internal/policy/DesktopModeCompatUtils.java +12 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,13 @@ package com.android.internal.policy; import static android.content.pm.ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED; import static android.content.pm.ActivityInfo.OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import android.annotation.NonNull; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.graphics.Rect; import android.window.DesktopModeFlags; /** Loading Loading @@ -48,6 +52,14 @@ public final class DesktopModeCompatUtils { || info.isChangeEnabled(OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS)); } /** * Returns the orientation of the given {@code rect}. */ public static @Configuration.Orientation int computeConfigOrientation(@NonNull Rect rect) { return rect.height() >= rect.width() ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; } private static boolean isConfigurationDecoupled(@NonNull ActivityInfo info, boolean optOutEdgeToEdge) { return info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED) && !optOutEdgeToEdge; Loading libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt +3 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.graphics.Rect import android.os.SystemProperties import android.util.Size import android.window.DesktopModeFlags import com.android.internal.policy.DesktopModeCompatUtils import com.android.wm.shell.ShellTaskOrganizer import com.android.wm.shell.common.DisplayController import com.android.wm.shell.common.DisplayLayout Loading Loading @@ -86,9 +87,10 @@ fun calculateInitialBounds( val topActivityInfo = taskInfo.topActivityInfo ?: return positionInScreen(idealSize, stableBounds) val screenOrientation = requestedScreenOrientation ?: topActivityInfo.screenOrientation val stableBoundsOrientation = DesktopModeCompatUtils.computeConfigOrientation(stableBounds) val initialSize: Size = when (taskInfo.configuration.orientation) { when (stableBoundsOrientation) { ORIENTATION_LANDSCAPE -> { if (taskInfo.canChangeAspectRatio) { if (isFixedOrientationPortrait(screenOrientation)) { Loading services/core/java/com/android/server/wm/AppCompatUtils.java +0 −10 Original line number Diff line number Diff line Loading @@ -18,8 +18,6 @@ package com.android.server.wm; import static android.app.WindowConfiguration.ROTATION_UNDEFINED; import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.content.res.Configuration.UI_MODE_TYPE_MASK; import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET; Loading Loading @@ -85,14 +83,6 @@ final class AppCompatUtils { return Math.max(width, height) / (float) Math.min(width, height); } /** * Returns the orientation of the given {@code rect}. */ static @Configuration.Orientation int computeConfigOrientation(@NonNull Rect rect) { return rect.height() >= rect.width() ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; } /** * @param config The current {@link Configuration} * @return {@code true} if using a VR headset. Loading services/core/java/com/android/server/wm/DesktopModeBoundsCalculator.java +5 −2 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ import android.view.Gravity; import android.window.DesktopExperienceFlags; import android.window.DesktopModeFlags; import com.android.internal.policy.DesktopModeCompatUtils; import java.util.function.Consumer; /** Loading Loading @@ -158,7 +160,8 @@ public final class DesktopModeBoundsCalculator { } final DesktopAppCompatAspectRatioPolicy desktopAppCompatAspectRatioPolicy = activity.mAppCompatController.getDesktopAspectRatioPolicy(); final int stableBoundsOrientation = AppCompatUtils.computeConfigOrientation(stableBounds); final int stableBoundsOrientation = DesktopModeCompatUtils.computeConfigOrientation(stableBounds); int activityOrientation = getActivityConfigurationOrientation( activity, task, stableBoundsOrientation); // Use orientation mismatch to resolve aspect ratio to match fixed orientation letterboxing Loading Loading @@ -251,7 +254,7 @@ public final class DesktopModeBoundsCalculator { task.topRunningActivity().getWindowConfiguration(); final Rect existingBounds = windowConfiguration.getAppBounds() != null ? windowConfiguration.getAppBounds() : windowConfiguration.getBounds(); return AppCompatUtils.computeConfigOrientation(existingBounds); return DesktopModeCompatUtils.computeConfigOrientation(existingBounds); } final int activityOrientation = activity.getOverrideOrientation(); final DesktopAppCompatAspectRatioPolicy desktopAppCompatAspectRatioPolicy = Loading services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java +2 −1 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ import android.view.Gravity; import androidx.test.filters.SmallTest; import com.android.internal.policy.DesktopModeCompatUtils; import com.android.window.flags.Flags; import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; Loading Loading @@ -325,7 +326,7 @@ public class DesktopModeLaunchParamsModifierTests extends .setActivity(activity).setOptions(options).calculate()); // Original orientation and aspect ratio of activity is maintained. assertEquals(ORIENTATION_PORTRAIT, AppCompatUtils.computeConfigOrientation(mResult.mBounds)); DesktopModeCompatUtils.computeConfigOrientation(mResult.mBounds)); assertEquals(expectedAspectRatio, AppCompatUtils.computeAspectRatio(mResult.mAppBounds), /* delta */ 0.05); } Loading Loading
core/java/com/android/internal/policy/DesktopModeCompatUtils.java +12 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,13 @@ package com.android.internal.policy; import static android.content.pm.ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED; import static android.content.pm.ActivityInfo.OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import android.annotation.NonNull; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.graphics.Rect; import android.window.DesktopModeFlags; /** Loading Loading @@ -48,6 +52,14 @@ public final class DesktopModeCompatUtils { || info.isChangeEnabled(OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS)); } /** * Returns the orientation of the given {@code rect}. */ public static @Configuration.Orientation int computeConfigOrientation(@NonNull Rect rect) { return rect.height() >= rect.width() ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; } private static boolean isConfigurationDecoupled(@NonNull ActivityInfo info, boolean optOutEdgeToEdge) { return info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED) && !optOutEdgeToEdge; Loading
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt +3 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.graphics.Rect import android.os.SystemProperties import android.util.Size import android.window.DesktopModeFlags import com.android.internal.policy.DesktopModeCompatUtils import com.android.wm.shell.ShellTaskOrganizer import com.android.wm.shell.common.DisplayController import com.android.wm.shell.common.DisplayLayout Loading Loading @@ -86,9 +87,10 @@ fun calculateInitialBounds( val topActivityInfo = taskInfo.topActivityInfo ?: return positionInScreen(idealSize, stableBounds) val screenOrientation = requestedScreenOrientation ?: topActivityInfo.screenOrientation val stableBoundsOrientation = DesktopModeCompatUtils.computeConfigOrientation(stableBounds) val initialSize: Size = when (taskInfo.configuration.orientation) { when (stableBoundsOrientation) { ORIENTATION_LANDSCAPE -> { if (taskInfo.canChangeAspectRatio) { if (isFixedOrientationPortrait(screenOrientation)) { Loading
services/core/java/com/android/server/wm/AppCompatUtils.java +0 −10 Original line number Diff line number Diff line Loading @@ -18,8 +18,6 @@ package com.android.server.wm; import static android.app.WindowConfiguration.ROTATION_UNDEFINED; import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.content.res.Configuration.UI_MODE_TYPE_MASK; import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET; Loading Loading @@ -85,14 +83,6 @@ final class AppCompatUtils { return Math.max(width, height) / (float) Math.min(width, height); } /** * Returns the orientation of the given {@code rect}. */ static @Configuration.Orientation int computeConfigOrientation(@NonNull Rect rect) { return rect.height() >= rect.width() ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; } /** * @param config The current {@link Configuration} * @return {@code true} if using a VR headset. Loading
services/core/java/com/android/server/wm/DesktopModeBoundsCalculator.java +5 −2 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ import android.view.Gravity; import android.window.DesktopExperienceFlags; import android.window.DesktopModeFlags; import com.android.internal.policy.DesktopModeCompatUtils; import java.util.function.Consumer; /** Loading Loading @@ -158,7 +160,8 @@ public final class DesktopModeBoundsCalculator { } final DesktopAppCompatAspectRatioPolicy desktopAppCompatAspectRatioPolicy = activity.mAppCompatController.getDesktopAspectRatioPolicy(); final int stableBoundsOrientation = AppCompatUtils.computeConfigOrientation(stableBounds); final int stableBoundsOrientation = DesktopModeCompatUtils.computeConfigOrientation(stableBounds); int activityOrientation = getActivityConfigurationOrientation( activity, task, stableBoundsOrientation); // Use orientation mismatch to resolve aspect ratio to match fixed orientation letterboxing Loading Loading @@ -251,7 +254,7 @@ public final class DesktopModeBoundsCalculator { task.topRunningActivity().getWindowConfiguration(); final Rect existingBounds = windowConfiguration.getAppBounds() != null ? windowConfiguration.getAppBounds() : windowConfiguration.getBounds(); return AppCompatUtils.computeConfigOrientation(existingBounds); return DesktopModeCompatUtils.computeConfigOrientation(existingBounds); } final int activityOrientation = activity.getOverrideOrientation(); final DesktopAppCompatAspectRatioPolicy desktopAppCompatAspectRatioPolicy = Loading
services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java +2 −1 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ import android.view.Gravity; import androidx.test.filters.SmallTest; import com.android.internal.policy.DesktopModeCompatUtils; import com.android.window.flags.Flags; import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; Loading Loading @@ -325,7 +326,7 @@ public class DesktopModeLaunchParamsModifierTests extends .setActivity(activity).setOptions(options).calculate()); // Original orientation and aspect ratio of activity is maintained. assertEquals(ORIENTATION_PORTRAIT, AppCompatUtils.computeConfigOrientation(mResult.mBounds)); DesktopModeCompatUtils.computeConfigOrientation(mResult.mBounds)); assertEquals(expectedAspectRatio, AppCompatUtils.computeAspectRatio(mResult.mAppBounds), /* delta */ 0.05); } Loading