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

Commit f387b283 authored by Filip Gruszczynski's avatar Filip Gruszczynski Committed by Android (Google) Code Review
Browse files

Merge "Preserve windows during stack resize."

parents bb8346e7 bc5a6c5f
Loading
Loading
Loading
Loading
+78 −22
Original line number Diff line number Diff line
@@ -295,6 +295,62 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        return curLayout;
    }

    /** @hide */
    public static String configurationDiffToString(int diff) {
        ArrayList<String> list = new ArrayList<>();
        if ((diff & ActivityInfo.CONFIG_MCC) != 0) {
            list.add("CONFIG_MCC");
        }
        if ((diff & ActivityInfo.CONFIG_MNC) != 0) {
            list.add("CONFIG_MNC");
        }
        if ((diff & ActivityInfo.CONFIG_LOCALE) != 0) {
            list.add("CONFIG_LOCALE");
        }
        if ((diff & ActivityInfo.CONFIG_TOUCHSCREEN) != 0) {
            list.add("CONFIG_TOUCHSCREEN");
        }
        if ((diff & ActivityInfo.CONFIG_KEYBOARD) != 0) {
            list.add("CONFIG_KEYBOARD");
        }
        if ((diff & ActivityInfo.CONFIG_KEYBOARD_HIDDEN) != 0) {
            list.add("CONFIG_KEYBOARD_HIDDEN");
        }
        if ((diff & ActivityInfo.CONFIG_NAVIGATION) != 0) {
            list.add("CONFIG_NAVIGATION");
        }
        if ((diff & ActivityInfo.CONFIG_ORIENTATION) != 0) {
            list.add("CONFIG_ORIENTATION");
        }
        if ((diff & ActivityInfo.CONFIG_SCREEN_LAYOUT) != 0) {
            list.add("CONFIG_SCREEN_LAYOUT");
        }
        if ((diff & ActivityInfo.CONFIG_UI_MODE) != 0) {
            list.add("CONFIG_UI_MODE");
        }
        if ((diff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) {
            list.add("CONFIG_SCREEN_SIZE");
        }
        if ((diff & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
            list.add("CONFIG_SMALLEST_SCREEN_SIZE");
        }
        if ((diff & ActivityInfo.CONFIG_LAYOUT_DIRECTION) != 0) {
            list.add("CONFIG_LAYOUT_DIRECTION");
        }
        if ((diff & ActivityInfo.CONFIG_FONT_SCALE) != 0) {
            list.add("CONFIG_FONT_SCALE");
        }
        StringBuilder builder = new StringBuilder("{");
        for (int i = 0, n = list.size(); i < n; i++) {
            builder.append(list.get(i));
            if (i != n - 1) {
                builder.append(", ");
            }
        }
        builder.append("}");
        return builder.toString();
    }

    /**
     * Check if the Configuration's current {@link #screenLayout} is at
     * least the given size.
+8 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST;
import static com.android.server.am.ActivityManagerDebugConfig.*;
import static com.android.server.am.ActivityStackSupervisor.FORCE_FOCUS;
import static com.android.server.am.ActivityStackSupervisor.ON_TOP;
import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
@@ -4626,7 +4627,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            // is hosted by the process...  then make sure all visible
            // activities are running, taking care of restarting this
            // process.
            mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
            mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
        }
    }
@@ -8664,7 +8665,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            if (task.mResizeable != resizeable) {
                task.mResizeable = resizeable;
                mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
                mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
                mStackSupervisor.resumeTopActivitiesLocked();
            }
        }
@@ -9108,7 +9109,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        long ident = Binder.clearCallingIdentity();
        try {
            synchronized (this) {
                mStackSupervisor.resizeStackLocked(stackId, bounds);
                mStackSupervisor.resizeStackLocked(stackId, bounds, !PRESERVE_WINDOWS);
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
@@ -11188,7 +11189,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                final boolean translucentChanged = r.changeWindowTranslucency(true);
                if (translucentChanged) {
                    r.task.stack.releaseBackgroundResources(r);
                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
                }
                mWindowManager.setAppFullscreen(token, true);
                return translucentChanged;
@@ -11216,7 +11217,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                if (translucentChanged) {
                    r.task.stack.convertActivityToTranslucent(r);
                }
                mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
                mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
                mWindowManager.setAppFullscreen(token, false);
                return translucentChanged;
            }
@@ -17699,7 +17700,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                kept = mainStack.ensureActivityConfigurationLocked(starting, changes, false);
                // And we need to make sure at this point that all other activities
                // are made visible with the correct configuration.
                mStackSupervisor.ensureActivitiesVisibleLocked(starting, changes);
                mStackSupervisor.ensureActivitiesVisibleLocked(starting, changes,
                        !PRESERVE_WINDOWS);
            }
        }
+11 −4
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;

import static com.android.server.am.ActivityStackSupervisor.MOVING;
import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;

import android.graphics.Rect;
import android.util.ArraySet;
@@ -815,7 +816,7 @@ final class ActivityStack {
    }

    void goToSleep() {
        ensureActivitiesVisibleLocked(null, 0);
        ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);

        // Make sure any stopped but visible activities are now sleeping.
        // This ensures that the activity's onStop() is called.
@@ -1379,7 +1380,8 @@ final class ActivityStack {
     * Make sure that all activities that need to be visible (that is, they
     * currently can be seen by the user) actually are.
     */
    final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) {
    final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges,
            boolean preserveWindows) {
        ActivityRecord top = topRunningActivityLocked(null);
        if (top == null) {
            return;
@@ -1428,7 +1430,7 @@ final class ActivityStack {
                    // First: if this is not the current activity being started, make
                    // sure it matches the current configuration.
                    if (r != starting) {
                        ensureActivityConfigurationLocked(r, 0, false);
                        ensureActivityConfigurationLocked(r, 0, preserveWindows);
                    }

                    if (r.app == null || r.app.thread == null) {
@@ -2342,7 +2344,7 @@ final class ActivityStack {
                // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we
                // tell WindowManager that r is visible even though it is at the back of the stack.
                mWindowManager.setAppVisibility(r.appToken, true);
                ensureActivitiesVisibleLocked(null, 0);
                ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
            } else if (SHOW_APP_STARTING_PREVIEW && doShow) {
                // Figure out if we are transitioning from another activity that is
                // "has the same starting icon" as the next one.  This allows the
@@ -4024,6 +4026,11 @@ final class ActivityStack {
            return true;
        }

        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
                "Configuration changes for " + r + " ; taskChanges="
                        + Configuration.configurationDiffToString(taskChanges) + ", allChanges="
                        + Configuration.configurationDiffToString(changes));

        // If the activity isn't currently running, just leave the new
        // configuration and it will pick that up next time it starts.
        if (r.app == null || r.app.thread == null) {
+21 −14
Original line number Diff line number Diff line
@@ -175,6 +175,9 @@ public final class ActivityStackSupervisor implements DisplayListener {
    // should be created if it doesn't exist already.
    private static final boolean CREATE_IF_NEEDED = true;

    // Used to indicate that windows of activities should be preserved during the resize.
    static final boolean PRESERVE_WINDOWS = true;

    // Used to indicate if an object (e.g. task) should be moved/created
    // at the top of its container (e.g. stack).
    static final boolean ON_TOP = true;
@@ -189,6 +192,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
    // Activity actions an app cannot start if it uses a permission which is not granted.
    private static final ArrayMap<String, String> ACTION_TO_RUNTIME_PERMISSION =
            new ArrayMap<>();

    static {
        ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_IMAGE_CAPTURE,
                Manifest.permission.CAMERA);
@@ -660,7 +664,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
            }
        }
        if (!didSomething) {
            ensureActivitiesVisibleLocked(null, 0);
            ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
        }
        return didSomething;
    }
@@ -2629,7 +2633,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
                }
                mLaunchingActivity.release();
            }
            ensureActivitiesVisibleLocked(null, 0);
            ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
        }

        // Atomically retrieve all of the other things to do.
@@ -2963,7 +2967,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
        }
    }

    void resizeStackLocked(int stackId, Rect bounds) {
    void resizeStackLocked(int stackId, Rect bounds, boolean preserveWindows) {
        final ActivityStack stack = getStack(stackId);
        if (stack == null) {
            Slog.w(TAG, "resizeStack: stackId " + stackId + " not found.");
@@ -3002,7 +3006,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
                // docked stack tasks to the fullscreen stack.
                for (int i = FIRST_STATIC_STACK_ID; i <= LAST_STATIC_STACK_ID; i++) {
                    if (i != DOCKED_STACK_ID) {
                        resizeStackLocked(i, null);
                        resizeStackLocked(i, null, preserveWindows);
                    }
                }

@@ -3033,20 +3037,22 @@ public final class ActivityStackSupervisor implements DisplayListener {
                            tempRect.right -= leftChange;
                            tempRect.top -= bottomChange;
                            tempRect.bottom -= topChange;
                            resizeStackLocked(i, tempRect);
                            resizeStackLocked(i, tempRect, PRESERVE_WINDOWS);
                        }
                    }
                }

            }
            // Since we are resizing the stack, all other operations should strive to preserve
            // windows.
            preserveWindows = true;
        }
        stack.setBounds(bounds);

        if (r != null) {
            final boolean updated = stack.ensureActivityConfigurationLocked(r, 0, false);
            final boolean updated = stack.ensureActivityConfigurationLocked(r, 0, preserveWindows);
            // And we need to make sure at this point that all other activities
            // are made visible with the correct configuration.
            ensureActivitiesVisibleLocked(r, 0);
            ensureActivitiesVisibleLocked(r, 0, preserveWindows);
            if (!updated) {
                resumeTopActivitiesLocked(stack, null, null);
            }
@@ -3107,7 +3113,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
                final boolean preserveWindow = resizedByUser && !changedStacks;
                kept = stack.ensureActivityConfigurationLocked(r, 0, preserveWindow);
                // All other activities must be made visible with their correct configuration.
                ensureActivitiesVisibleLocked(r, 0);
                ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
                if (!kept) {
                    resumeTopActivitiesLocked(stack, null, null);
                    if (changedStacks && stackId == FULLSCREEN_WORKSPACE_STACK_ID) {
@@ -3255,7 +3261,7 @@ public final class ActivityStackSupervisor implements DisplayListener {

        // The task might have already been running and its visibility needs to be synchronized with
        // the visibility of the stack / windows.
        ensureActivitiesVisibleLocked(null, 0);
        ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
        resumeTopActivitiesLocked();
    }

@@ -3275,7 +3281,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
        stack.positionTask(task, position, stackChanged);
        // The task might have already been running and its visibility needs to be synchronized with
        // the visibility of the stack / windows.
        stack.ensureActivitiesVisibleLocked(null, 0);
        stack.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
        resumeTopActivitiesLocked();
    }

@@ -3450,7 +3456,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
            mService.updateUsageStats(r, true);
        }
        if (allResumedActivitiesComplete()) {
            ensureActivitiesVisibleLocked(null, 0);
            ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
            mWindowManager.executeAppTransition();
            return true;
        }
@@ -3536,14 +3542,15 @@ public final class ActivityStackSupervisor implements DisplayListener {
        mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget();
    }

    void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) {
    void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges,
            boolean preserveWindows) {
        // First the front stacks. In case any are not fullscreen and are in front of home.
        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
            final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
            final int topStackNdx = stacks.size() - 1;
            for (int stackNdx = topStackNdx; stackNdx >= 0; --stackNdx) {
                final ActivityStack stack = stacks.get(stackNdx);
                stack.ensureActivitiesVisibleLocked(starting, configChanges);
                stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows);
            }
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.am;

import static com.android.server.am.ActivityManagerDebugConfig.*;
import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;

import java.io.File;
import java.io.FileInputStream;
@@ -347,7 +348,7 @@ public final class CompatModePackages {
                stack.ensureActivityConfigurationLocked(starting, 0, false);
                // And we need to make sure at this point that all other activities
                // are made visible with the correct configuration.
                stack.ensureActivitiesVisibleLocked(starting, 0);
                stack.ensureActivitiesVisibleLocked(starting, 0, !PRESERVE_WINDOWS);
            }
        }
    }