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

Commit 9a08f827 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Apply minimal task dimension to all task bounds change.

We only used to apply the minimal dimension on resizeTask in
ActivityStackSuperior which is mostly used for freeform and
missed resizes that went through other channels like resizeStack
which is used for split-screen.
We now apply it on TaskRecord.updateOverrideConfiguration which
all task bounds changes go through.

Bug: 27220870
Change-Id: I856948c371f5f5f144e61029ced4a467f7ebe33a
parent 9cea80cd
Loading
Loading
Loading
Loading
+3 −37
Original line number Diff line number Diff line
@@ -400,7 +400,7 @@ public final class ActivityStackSupervisor implements DisplayListener {

    // The default minimal size that will be used if the activity doesn't specify its minimal size.
    // It will be calculated when the default display gets added.
    private int mDefaultMinimalSizeOfResizeableTask = -1;
    int mDefaultMinimalSizeOfResizeableTask = -1;

    // Whether tasks have moved and we need to rank the tasks before next OOM scoring
    private boolean mTaskLayersChanged = true;
@@ -2039,8 +2039,6 @@ public final class ActivityStackSupervisor implements DisplayListener {
            return true;
        }

        adjustForMinimalTaskDimensions(task, bounds);

        // If this is a forced resize, let it go through even if the bounds is not changing,
        // as we might need a relayout due to surface size change (to/from fullscreen).
        final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
@@ -2074,7 +2072,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
        // to be relaunched due to configuration change.
        boolean kept = true;
        if (overrideConfig != null) {
            ActivityRecord r = task.topRunningActivityLocked();
            final ActivityRecord r = task.topRunningActivityLocked();
            if (r != null) {
                final ActivityStack stack = task.stack;
                kept = stack.ensureActivityConfigurationLocked(r, 0, preserveWindow);
@@ -2085,44 +2083,12 @@ public final class ActivityStackSupervisor implements DisplayListener {
                }
            }
        }
        mWindowManager.resizeTask(task.taskId, bounds, task.mOverrideConfig, kept, forced);
        mWindowManager.resizeTask(task.taskId, task.mBounds, task.mOverrideConfig, kept, forced);

        Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
        return kept;
    }

    private void adjustForMinimalTaskDimensions(TaskRecord task, Rect bounds) {
        if (bounds == null) {
            return;
        }
        int minimalSize = task.mMinimalSize == -1 ? mDefaultMinimalSizeOfResizeableTask
                : task.mMinimalSize;
        final boolean adjustWidth = minimalSize > bounds.width();
        final boolean adjustHeight = minimalSize > bounds.height();
        if (!(adjustWidth || adjustHeight)) {
            return;
        }
        Rect taskBounds = task.mBounds;
        if (adjustWidth) {
            if (taskBounds != null && bounds.right == taskBounds.right) {
                bounds.left = bounds.right - minimalSize;
            } else {
                // Either left bounds match, or neither match, or the previous bounds were
                // fullscreen and we default to keeping left.
                bounds.right = bounds.left + minimalSize;
            }
        }
        if (adjustHeight) {
            if (taskBounds != null && bounds.bottom == taskBounds.bottom) {
                bounds.top = bounds.bottom - minimalSize;
            } else {
                // Either top bounds match, or neither match, or the previous bounds were
                // fullscreen and we default to keeping top.
                bounds.bottom = bounds.top + minimalSize;
            }
        }
    }

    ActivityStack createStackOnDisplay(int stackId, int displayId, boolean onTop) {
        ActivityDisplay activityDisplay = mActivityDisplays.get(displayId);
        if (activityDisplay == null) {
+38 −3
Original line number Diff line number Diff line
@@ -245,6 +245,7 @@ final class TaskRecord {
    Rect mBounds = null;
    private final Rect mTmpStableBounds = new Rect();
    private final Rect mTmpNonDecorBounds = new Rect();
    private final Rect mTmpRect = new Rect();
    private final Rect mTmpRect2 = new Rect();

    // Last non-fullscreen bounds the task was launched in or resized to.
@@ -1314,6 +1315,38 @@ final class TaskRecord {
        return task;
    }

    private void adjustForMinimalTaskDimensions(Rect bounds) {
        if (bounds == null) {
            return;
        }
        final int minimalSize = mMinimalSize == -1
                ? mService.mStackSupervisor.mDefaultMinimalSizeOfResizeableTask : mMinimalSize;
        final boolean adjustWidth = minimalSize > bounds.width();
        final boolean adjustHeight = minimalSize > bounds.height();
        if (!(adjustWidth || adjustHeight)) {
            return;
        }

        if (adjustWidth) {
            if (mBounds != null && bounds.right == mBounds.right) {
                bounds.left = bounds.right - minimalSize;
            } else {
                // Either left bounds match, or neither match, or the previous bounds were
                // fullscreen and we default to keeping left.
                bounds.right = bounds.left + minimalSize;
            }
        }
        if (adjustHeight) {
            if (mBounds != null && bounds.bottom == mBounds.bottom) {
                bounds.top = bounds.bottom - minimalSize;
            } else {
                // Either top bounds match, or neither match, or the previous bounds were
                // fullscreen and we default to keeping top.
                bounds.bottom = bounds.top + minimalSize;
            }
        }
    }

    /**
     * Update task's override configuration based on the bounds.
     * @param bounds The bounds of the task.
@@ -1346,15 +1379,17 @@ final class TaskRecord {
            mBounds = null;
            mOverrideConfig = Configuration.EMPTY;
        } else {
            mTmpRect.set(bounds);
            adjustForMinimalTaskDimensions(mTmpRect);
            if (mBounds == null) {
                mBounds = new Rect(bounds);
                mBounds = new Rect(mTmpRect);
            } else {
                mBounds.set(bounds);
                mBounds.set(mTmpRect);
            }
            if (stack == null || StackId.persistTaskBounds(stack.mStackId)) {
                mLastNonFullscreenBounds = mBounds;
            }
            mOverrideConfig = calculateOverrideConfig(bounds, insetBounds);
            mOverrideConfig = calculateOverrideConfig(mTmpRect, insetBounds);
        }

        if (mFullscreen != oldFullscreen) {