Merge "Calculate freeform bounds for fullscreen task" into tm-qpr-dev am: a3256d337d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19415029

Change-Id: Ifa482f36fb6f9d2417ce504ab2a4199fa79b9e97
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Kazuki Takise
2022-11-18 11:37:45 +00:00
committed by Automerger Merge Worker
2 changed files with 62 additions and 26 deletions

View File

@@ -182,26 +182,34 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
// is set with the suggestedDisplayArea. If it is set, but the eventual TaskDisplayArea is // is set with the suggestedDisplayArea. If it is set, but the eventual TaskDisplayArea is
// different, we should recalculating the bounds. // different, we should recalculating the bounds.
boolean hasInitialBoundsForSuggestedDisplayAreaInFreeformWindow = false; boolean hasInitialBoundsForSuggestedDisplayAreaInFreeformWindow = false;
final boolean canApplyFreeformPolicy = // Note that initial bounds needs to be set to fullscreen tasks too as it's used as restore
// bounds.
final boolean canCalculateBoundsForFullscreenTask =
canCalculateBoundsForFullscreenTask(suggestedDisplayArea, launchMode);
final boolean canApplyFreeformWindowPolicy =
canApplyFreeformWindowPolicy(suggestedDisplayArea, launchMode); canApplyFreeformWindowPolicy(suggestedDisplayArea, launchMode);
if (mSupervisor.canUseActivityOptionsLaunchBounds(options) final boolean canApplyWindowLayout = layout != null
&& (canApplyFreeformPolicy || canApplyPipWindowPolicy(launchMode))) { && (canApplyFreeformWindowPolicy || canCalculateBoundsForFullscreenTask);
final boolean canApplyBoundsFromActivityOptions =
mSupervisor.canUseActivityOptionsLaunchBounds(options)
&& (canApplyFreeformWindowPolicy
|| canApplyPipWindowPolicy(launchMode)
|| canCalculateBoundsForFullscreenTask);
if (canApplyBoundsFromActivityOptions) {
hasInitialBounds = true; hasInitialBounds = true;
launchMode = launchMode == WINDOWING_MODE_UNDEFINED // |launchMode| at this point can be fullscreen, PIP, MultiWindow, etc. Only set
// freeform windowing mode if appropriate by checking |canApplyFreeformWindowPolicy|.
launchMode = launchMode == WINDOWING_MODE_UNDEFINED && canApplyFreeformWindowPolicy
? WINDOWING_MODE_FREEFORM ? WINDOWING_MODE_FREEFORM
: launchMode; : launchMode;
outParams.mBounds.set(options.getLaunchBounds()); outParams.mBounds.set(options.getLaunchBounds());
if (DEBUG) appendLog("activity-options-bounds=" + outParams.mBounds); if (DEBUG) appendLog("activity-options-bounds=" + outParams.mBounds);
} else if (launchMode == WINDOWING_MODE_PINNED) { } else if (canApplyWindowLayout) {
// System controls PIP window's bounds, so don't apply launch bounds.
if (DEBUG) appendLog("empty-window-layout-for-pip");
} else if (launchMode == WINDOWING_MODE_FULLSCREEN) {
if (DEBUG) appendLog("activity-options-fullscreen=" + outParams.mBounds);
} else if (layout != null && canApplyFreeformPolicy) {
mTmpBounds.set(currentParams.mBounds); mTmpBounds.set(currentParams.mBounds);
getLayoutBounds(suggestedDisplayArea, root, layout, mTmpBounds); getLayoutBounds(suggestedDisplayArea, root, layout, mTmpBounds);
if (!mTmpBounds.isEmpty()) { if (!mTmpBounds.isEmpty()) {
launchMode = WINDOWING_MODE_FREEFORM; launchMode = canApplyFreeformWindowPolicy ? WINDOWING_MODE_FREEFORM : launchMode;
outParams.mBounds.set(mTmpBounds); outParams.mBounds.set(mTmpBounds);
hasInitialBounds = true; hasInitialBounds = true;
hasInitialBoundsForSuggestedDisplayAreaInFreeformWindow = true; hasInitialBoundsForSuggestedDisplayAreaInFreeformWindow = true;
@@ -211,6 +219,8 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
} }
} else if (launchMode == WINDOWING_MODE_MULTI_WINDOW } else if (launchMode == WINDOWING_MODE_MULTI_WINDOW
&& options != null && options.getLaunchBounds() != null) { && options != null && options.getLaunchBounds() != null) {
// TODO: Investigate whether we can migrate this clause to the
// |canApplyBoundsFromActivityOptions| case above.
outParams.mBounds.set(options.getLaunchBounds()); outParams.mBounds.set(options.getLaunchBounds());
hasInitialBounds = true; hasInitialBounds = true;
if (DEBUG) appendLog("multiwindow-activity-options-bounds=" + outParams.mBounds); if (DEBUG) appendLog("multiwindow-activity-options-bounds=" + outParams.mBounds);
@@ -250,11 +260,9 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
if (!currentParams.mBounds.isEmpty()) { if (!currentParams.mBounds.isEmpty()) {
// Carry over bounds from callers regardless of launch mode because bounds is still // Carry over bounds from callers regardless of launch mode because bounds is still
// used to restore last non-fullscreen bounds when launch mode is not freeform. // used to restore last non-fullscreen bounds when launch mode is not freeform.
// Therefore it's not a resolution step for non-freeform launch mode and only
// consider it fully resolved only when launch mode is freeform.
outParams.mBounds.set(currentParams.mBounds); outParams.mBounds.set(currentParams.mBounds);
fullyResolvedCurrentParam = true;
if (launchMode == WINDOWING_MODE_FREEFORM) { if (launchMode == WINDOWING_MODE_FREEFORM) {
fullyResolvedCurrentParam = true;
if (DEBUG) appendLog("inherit-bounds=" + outParams.mBounds); if (DEBUG) appendLog("inherit-bounds=" + outParams.mBounds);
} }
} }
@@ -370,7 +378,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
// an existing task. // an existing task.
adjustBoundsToAvoidConflictInDisplayArea(taskDisplayArea, outParams.mBounds); adjustBoundsToAvoidConflictInDisplayArea(taskDisplayArea, outParams.mBounds);
} }
} else if (taskDisplayArea.inFreeformWindowingMode()) { } else {
if (source != null && source.inFreeformWindowingMode() if (source != null && source.inFreeformWindowingMode()
&& resolvedMode == WINDOWING_MODE_FREEFORM && resolvedMode == WINDOWING_MODE_FREEFORM
&& outParams.mBounds.isEmpty() && outParams.mBounds.isEmpty()
@@ -562,10 +570,19 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
return display.getDisplayId() == source.getDisplayId(); return display.getDisplayId() == source.getDisplayId();
} }
private boolean canCalculateBoundsForFullscreenTask(@NonNull TaskDisplayArea displayArea,
int launchMode) {
return mSupervisor.mService.mSupportsFreeformWindowManagement
&& ((displayArea.getWindowingMode() == WINDOWING_MODE_FULLSCREEN
&& launchMode == WINDOWING_MODE_UNDEFINED)
|| launchMode == WINDOWING_MODE_FULLSCREEN);
}
private boolean canApplyFreeformWindowPolicy(@NonNull TaskDisplayArea suggestedDisplayArea, private boolean canApplyFreeformWindowPolicy(@NonNull TaskDisplayArea suggestedDisplayArea,
int launchMode) { int launchMode) {
return mSupervisor.mService.mSupportsFreeformWindowManagement return mSupervisor.mService.mSupportsFreeformWindowManagement
&& (suggestedDisplayArea.inFreeformWindowingMode() && ((suggestedDisplayArea.inFreeformWindowingMode()
&& launchMode == WINDOWING_MODE_UNDEFINED)
|| launchMode == WINDOWING_MODE_FREEFORM); || launchMode == WINDOWING_MODE_FREEFORM);
} }
@@ -727,16 +744,10 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
private void getTaskBounds(@NonNull ActivityRecord root, @NonNull TaskDisplayArea displayArea, private void getTaskBounds(@NonNull ActivityRecord root, @NonNull TaskDisplayArea displayArea,
@NonNull ActivityInfo.WindowLayout layout, int resolvedMode, boolean hasInitialBounds, @NonNull ActivityInfo.WindowLayout layout, int resolvedMode, boolean hasInitialBounds,
@NonNull Rect inOutBounds) { @NonNull Rect inOutBounds) {
if (resolvedMode == WINDOWING_MODE_FULLSCREEN) { if (resolvedMode != WINDOWING_MODE_FREEFORM
// We don't handle letterboxing here. Letterboxing will be handled by valid checks && resolvedMode != WINDOWING_MODE_FULLSCREEN) {
// later. // This function should be used only for freeform bounds adjustment. Freeform bounds
inOutBounds.setEmpty(); // needs to be set to fullscreen tasks too as restore bounds.
if (DEBUG) appendLog("maximized-bounds");
return;
}
if (resolvedMode != WINDOWING_MODE_FREEFORM) {
// We don't apply freeform bounds adjustment to other windowing modes.
if (DEBUG) { if (DEBUG) {
appendLog("skip-bounds-" + WindowConfiguration.windowingModeToString(resolvedMode)); appendLog("skip-bounds-" + WindowConfiguration.windowingModeToString(resolvedMode));
} }

View File

@@ -638,6 +638,29 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
WINDOWING_MODE_FULLSCREEN); WINDOWING_MODE_FULLSCREEN);
} }
@Test
public void testBoundsInOptionsInfersFullscreenWithBoundsOnFreeformSupportFullscreenDisplay() {
final TestDisplayContent fullscreenDisplay = createNewDisplayContent(
WINDOWING_MODE_FULLSCREEN);
mAtm.mTaskSupervisor.mService.mSupportsFreeformWindowManagement = true;
final ActivityOptions options = ActivityOptions.makeBasic();
final Rect expectedBounds = new Rect(0, 0, 100, 100);
options.setLaunchBounds(expectedBounds);
mCurrent.mPreferredTaskDisplayArea = fullscreenDisplay.getDefaultTaskDisplayArea();
assertEquals(RESULT_CONTINUE,
new CalculateRequestBuilder().setOptions(options).calculate());
// Setting bounds shouldn't lead to freeform windowing mode on fullscreen display by
// default (even with freeform support), but we need to check here if the bounds is set even
// with fullscreen windowing mode in case it's restored later.
assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
WINDOWING_MODE_FULLSCREEN);
assertEquals(expectedBounds, mResult.mBounds);
}
@Test @Test
public void testInheritsFreeformModeFromSourceOnFullscreenDisplay() { public void testInheritsFreeformModeFromSourceOnFullscreenDisplay() {
final TestDisplayContent fullscreenDisplay = createNewDisplayContent( final TestDisplayContent fullscreenDisplay = createNewDisplayContent(
@@ -1020,6 +1043,8 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
WINDOWING_MODE_FULLSCREEN); WINDOWING_MODE_FULLSCREEN);
final ActivityRecord source = createSourceActivity(fullscreenDisplay); final ActivityRecord source = createSourceActivity(fullscreenDisplay);
source.getTask().setWindowingMode(WINDOWING_MODE_FREEFORM); source.getTask().setWindowingMode(WINDOWING_MODE_FREEFORM);
// Set some bounds to avoid conflict with the other activity.
source.setBounds(100, 100, 200, 200);
final ActivityOptions options = ActivityOptions.makeBasic(); final ActivityOptions options = ActivityOptions.makeBasic();
final Rect expected = new Rect(0, 0, 150, 150); final Rect expected = new Rect(0, 0, 150, 150);