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

Commit 330757df authored by Matthew Ng's avatar Matthew Ng
Browse files

Corrects the recents and home stacks position around docked state (1/2)

Since splitting home stack into home and recents, some problems where
the home stack would appear above when home stack is not visible. This
would cause home stack to be below docked stack and think home is
visible when it is not. Then docking an app would minimize the docked
stack and go into a wierd state when recents is resumed/launched.

When docked stack is used, it will verify that recents is created and
avoids seeing home stack as visible when below docked stack with at
least 1 stack in between. Whenever an app is docked, this will make sure
home stack is below recents.

This will fix some parts of the cts tests that use
"adb shell am stack move-task <taskId> 3 true" and avoid glitches with
the docked stack.

The following scenarios were tested:
- Boot and dock and app without starting recents
- Dock after launching an app (when recents already created)
- Toggle dock with "adb shell am stack move-task <taskId> 3 true" and
undocking multiple times
- Dock with long press recents

Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test
CtsServicesHostTestCases
android.server.cts.ActivityManagerDockedStackTests
Bug: 35351074, 35145587
Change-Id: I6ac25c64f7d1050ea2260631ff4c052fcca3f185
parent 902adc6c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -475,7 +475,7 @@ interface IActivityManager {
    void reportSizeConfigurations(in IBinder token, in int[] horizontalSizeConfiguration,
            in int[] verticalSizeConfigurations, in int[] smallestWidthConfigurations);
    boolean moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate,
            in Rect initialBounds, boolean moveHomeStackFront);
            in Rect initialBounds);
    void suppressResizeConfigChanges(boolean suppress);
    void moveTasksToFullscreenStack(int fromStackId, boolean onTop);
    boolean moveTopActivityToPinnedStack(int stackId, in Rect bounds);
+1 −1
Original line number Diff line number Diff line
@@ -519,7 +519,7 @@ public class SystemServicesProxy {

        try {
            return mIam.moveTaskToDockedStack(taskId, createMode, true /* onTop */,
                    false /* animate */, initialBounds, true /* moveHomeStackFront */ );
                    false /* animate */, initialBounds);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
+3 −11
Original line number Diff line number Diff line
@@ -10241,13 +10241,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                    mWindowManager.setDockedStackCreateState(DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT,
                            null /* initialBounds */);
                }
                final boolean successful = task.reparent(stackId, toTop,
                task.reparent(stackId, toTop,
                        REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, "moveTaskToStack");
                if (successful && stackId == DOCKED_STACK_ID) {
                    // If task moved to docked stack - show recents if needed.
                    mWindowManager.showRecentApps(false /* fromHome */);
                }
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
@@ -10320,7 +10315,7 @@ public class ActivityManagerService extends IActivityManager.Stub
     */
    @Override
    public boolean moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate,
            Rect initialBounds, boolean moveHomeStackFront) {
            Rect initialBounds) {
        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToDockedStack()");
        synchronized (this) {
            long ident = Binder.clearCallingIdentity();
@@ -10337,12 +10332,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                // Defer resuming until we move the home stack to the front below
                final boolean moved = task.reparent(DOCKED_STACK_ID, toTop,
                        REPARENT_KEEP_STACK_AT_FRONT, animate, DEFER_RESUME,
                        REPARENT_KEEP_STACK_AT_FRONT, animate, !DEFER_RESUME,
                        "moveTaskToDockedStack");
                if (moved) {
                    if (moveHomeStackFront) {
                        mStackSupervisor.moveHomeStackToFront("moveTaskToDockedStack");
                    }
                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
                }
                return moved;
+10 −0
Original line number Diff line number Diff line
@@ -1582,6 +1582,16 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                    : STACK_INVISIBLE;
        }

        // Set home stack to invisible when it is below but not immediately below the docked stack
        // A case would be if recents stack exists but has no tasks and is below the docked stack
        // and home stack is below recents
        if (mStackId == HOME_STACK_ID) {
            int dockedStackIndex = mStacks.indexOf(mStackSupervisor.getStack(DOCKED_STACK_ID));
            if (dockedStackIndex > stackIndex && stackIndex != dockedStackIndex - 1) {
                return STACK_INVISIBLE;
            }
        }

        // Find the first stack behind front stack that actually got something visible.
        int stackBehindTopIndex = mStacks.indexOf(topStack) - 1;
        while (stackBehindTopIndex >= 0 &&
+13 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static android.app.ActivityManager.StackId.HOME_STACK_ID;
import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
import static android.app.ActivityManager.StackId.LAST_STATIC_STACK_ID;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.app.ActivityManager.StackId.RECENTS_STACK_ID;
import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
@@ -670,6 +671,13 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
        mHomeStack.moveToFront(reason);
    }

    void moveRecentsStackToFront(String reason) {
        final ActivityStack recentsStack = getStack(RECENTS_STACK_ID);
        if (recentsStack != null) {
            recentsStack.moveToFront(reason);
        }
    }

    /** Returns true if the focus activity was adjusted to the home stack top activity. */
    boolean moveHomeStackTaskToTop(String reason) {
        mHomeStack.moveHomeStackTaskToTop();
@@ -2048,6 +2056,11 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
        if (!createStaticStackIfNeeded || !StackId.isStaticStack(stackId)) {
            return null;
        }
        if (stackId == DOCKED_STACK_ID) {
            // Make sure recents stack exist when creating a dock stack as it normally need to be on
            // the other side of the docked stack and we make visibility decisions based on that.
            getStack(RECENTS_STACK_ID, CREATE_IF_NEEDED, createOnTop);
        }
        return (T) createStackOnDisplay(stackId, DEFAULT_DISPLAY, createOnTop);
    }

Loading