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

Commit 29219d96 authored by Craig Mautner's avatar Craig Mautner
Browse files

Steady improvement to multi stack.

- Fix back button behavior with two stacks. Stopping activities were
held in that state indefinitely. This change causes IDLE_NOW_MSG to
be sent immediately for the last activity in a stack.

- Touch in non-focused stack was being ignored because of focus tests
in AbsListView.

- Change the focused stack when the activity focus changes. Renamed
mMainStack to mFocusedStack to reflect this.

- Resume all top stack activities when resuming.

- Assign intent task to ActivityRecord if it doesn't have a task.
Fixes bug 8433463.

Change-Id: I8d3c806234511697bc209ab99890730ffa514d20
parent bbcc289d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2398,7 +2398,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     * @return True if the selector should be shown
     */
    boolean shouldShowSelector() {
        return (hasFocus() && !isInTouchMode()) || touchModeDrawsInPressedState();
        return (!isInTouchMode()) || touchModeDrawsInPressedState();
    }

    private void drawSelector(Canvas canvas) {
@@ -2736,7 +2736,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }

        public boolean sameWindow() {
            return hasWindowFocus() && getWindowAttachCount() == mOriginalAttachCount;
            return getWindowAttachCount() == mOriginalAttachCount;
        }
    }

+14 −8
Original line number Diff line number Diff line
@@ -1925,6 +1925,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    final void setFocusedActivityLocked(ActivityRecord r) {
        if (mFocusedActivity != r) {
            mFocusedActivity = r;
            mStackSupervisor.setFocusedStack(r);
            if (r != null) {
                mWindowManager.setFocusedApp(r.appToken, true);
            }
@@ -4815,6 +4816,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        return rec;
    }
    @Override
    public void cancelIntentSender(IIntentSender sender) {
        if (!(sender instanceof PendingIntentRecord)) {
            return;
@@ -4848,6 +4850,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }
    @Override
    public String getPackageForIntentSender(IIntentSender pendingResult) {
        if (!(pendingResult instanceof PendingIntentRecord)) {
            return null;
@@ -4860,6 +4863,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        return null;
    }
    @Override
    public int getUidForIntentSender(IIntentSender sender) {
        if (sender instanceof PendingIntentRecord) {
            try {
@@ -4871,6 +4875,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        return -1;
    }
    @Override
    public boolean isIntentSenderTargetedToPackage(IIntentSender pendingResult) {
        if (!(pendingResult instanceof PendingIntentRecord)) {
            return false;
@@ -4892,6 +4897,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        return false;
    }
    @Override
    public boolean isIntentSenderAnActivity(IIntentSender pendingResult) {
        if (!(pendingResult instanceof PendingIntentRecord)) {
            return false;
+17 −9
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ final class ActivityStack {
    static final boolean localLOGV = ActivityManagerService.localLOGV;
    static final boolean DEBUG_SWITCH = ActivityManagerService.DEBUG_SWITCH;
    static final boolean DEBUG_PAUSE = ActivityManagerService.DEBUG_PAUSE;
    static final boolean DEBUG_VISBILITY = ActivityManagerService.DEBUG_VISBILITY || true;
    static final boolean DEBUG_VISBILITY = ActivityManagerService.DEBUG_VISBILITY;
    static final boolean DEBUG_USER_LEAVING = ActivityManagerService.DEBUG_USER_LEAVING;
    static final boolean DEBUG_TRANSITION = ActivityManagerService.DEBUG_TRANSITION;
    static final boolean DEBUG_RESULTS = ActivityManagerService.DEBUG_RESULTS;
@@ -984,10 +984,12 @@ final class ActivityStack {
                    destroyActivityLocked(prev, true, false, "pause-config");
                } else {
                    mStackSupervisor.mStoppingActivities.add(prev);
                    if (mStackSupervisor.mStoppingActivities.size() > 3) {
                    if (mStackSupervisor.mStoppingActivities.size() > 3 ||
                            prev.frontOfTask && mTaskHistory.size() <= 1) {
                        // If we already have a few activities waiting to stop,
                        // then give up on things going idle and start clearing
                        // them out.
                        // them out. Or if r is the last of activity of the last task the stack
                        // will be empty and must be cleared immediately.
                        if (DEBUG_PAUSE) Slog.v(TAG, "To many pending stops, forcing idle");
                        scheduleIdleLocked();
                    } else {
@@ -1750,9 +1752,13 @@ final class ActivityStack {
                if (prev != null) {
                    // We don't want to reuse the previous starting preview if:
                    // (1) The current activity is in a different task.
                    if (prev.task != r.task) prev = null;
                    if (prev.task != r.task) {
                        prev = null;
                    }
                    // (2) The current activity is already displayed.
                    else if (prev.nowVisible) prev = null;
                    else if (prev.nowVisible) {
                        prev = null;
                    }
                }
                mService.mWindowManager.setAppStartingWindow(
                        r.appToken, r.packageName, r.theme,
@@ -1774,7 +1780,7 @@ final class ActivityStack {
        }

        if (doResume) {
            mStackSupervisor.getTopStack().resumeTopActivityLocked(null);
            mStackSupervisor.resumeTopActivitiesLocked();
        }
    }

@@ -2569,7 +2575,7 @@ final class ActivityStack {
        r.pauseKeyDispatchingLocked();
        if (mStackSupervisor.isFrontStack(this)) {
            if (mService.mFocusedActivity == r) {
                mService.setFocusedActivityLocked(topRunningActivityLocked(null));
                mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked());
            }
        }

@@ -2623,10 +2629,12 @@ final class ActivityStack {
        if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) {
            if (!mStackSupervisor.mStoppingActivities.contains(r)) {
                mStackSupervisor.mStoppingActivities.add(r);
                if (mStackSupervisor.mStoppingActivities.size() > 3) {
                if (mStackSupervisor.mStoppingActivities.size() > 3
                        || r.frontOfTask && mTaskHistory.size() <= 1) {
                    // If we already have a few activities waiting to stop,
                    // then give up on things going idle and start clearing
                    // them out.
                    // them out. Or if r is the last of activity of the last task the stack
                    // will be empty and must be cleared immediately.
                    scheduleIdleLocked();
                } else {
                    checkReadyForSleepLocked();
+84 −14
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.server.am;

import static android.Manifest.permission.START_ANY_ACTIVITY;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static com.android.server.am.ActivityManagerService.localLOGV;
import static com.android.server.am.ActivityManagerService.DEBUG_CONFIGURATION;
@@ -99,8 +101,8 @@ public class ActivityStackSupervisor {
    private ActivityStack mHomeStack;

    /** The non-home stack currently receiving input or launching the next activity. If home is
     * in front then mHomeStack overrides mMainStack. */
    private ActivityStack mMainStack;
     * in front then mHomeStack overrides mFocusedStack. */
    private ActivityStack mFocusedStack;

    /** All the non-launcher stacks */
    private ArrayList<ActivityStack> mStacks = new ArrayList<ActivityStack>();
@@ -150,7 +152,7 @@ public class ActivityStackSupervisor {
            case STACK_STATE_HOME_IN_BACK:
            case STACK_STATE_HOME_TO_BACK:
            default:
                return mMainStack;
                return mFocusedStack;
        }
    }

@@ -162,7 +164,7 @@ public class ActivityStackSupervisor {
            case STACK_STATE_HOME_TO_FRONT:
            case STACK_STATE_HOME_IN_BACK:
            default:
                return mMainStack;
                return mFocusedStack;
        }
    }

@@ -238,8 +240,8 @@ public class ActivityStackSupervisor {
            mStacks.remove(stack);
            final int stackId = stack.mStackId;
            final int nextStackId = mService.mWindowManager.removeStack(stackId);
            if (mMainStack.mStackId == stackId) {
                mMainStack = nextStackId == HOME_STACK_ID ? null : getStack(nextStackId);
            if (mFocusedStack.mStackId == stackId) {
                mFocusedStack = nextStackId == HOME_STACK_ID ? null : getStack(nextStackId);
            }
        }
    }
@@ -329,10 +331,9 @@ public class ActivityStackSupervisor {
    }

    boolean allPausedActivitiesComplete() {
        final boolean homeInBack = !homeIsInFront();
        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
            final ActivityStack stack = mStacks.get(stackNdx);
            if (stack.isHomeStack() ^ homeInBack) {
            if (isFrontStack(stack)) {
                final ActivityRecord r = stack.mLastPausedActivity;
                if (r != null && r.state != ActivityState.PAUSED
                        && r.state != ActivityState.STOPPED
@@ -353,6 +354,35 @@ public class ActivityStackSupervisor {
        return true;
    }

    ActivityRecord topRunningActivityLocked() {
        ActivityRecord r = null;
        if (mFocusedStack != null) {
            r = mFocusedStack.topRunningActivityLocked(null);
            if (r != null) {
                return r;
            }
        }
        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
            final ActivityStack stack = mStacks.get(stackNdx);
            if (stack != mFocusedStack && isFrontStack(stack)) {
                r = stack.topRunningActivityLocked(null);
                if (r != null) {
                    return r;
                }
            }
        }
        return null;
    }

    void resumeTopActivitiesLocked() {
        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
            final ActivityStack stack = mStacks.get(stackNdx);
            if (isFrontStack(stack)) {
                stack.resumeTopActivityLocked(null);
            }
        }
    }

    ActivityRecord getTasksLocked(int maxNum, IThumbnailReceiver receiver,
            PendingThumbnailsRecord pending, List<RunningTaskInfo> list) {
        ActivityRecord r = null;
@@ -1043,13 +1073,29 @@ public class ActivityStackSupervisor {
                // Time to create the first app stack.
                int stackId = mService.createStack(-1, HOME_STACK_ID,
                        StackBox.TASK_STACK_GOES_OVER, 1.0f);
                mMainStack = getStack(stackId);
                mFocusedStack = getStack(stackId);
            }
            return mMainStack;
            return mFocusedStack;
        }
        return mHomeStack;
    }

    void setFocusedStack(ActivityRecord r) {
        if (r == null) {
            return;
        }
        if (r.isHomeActivity) {
            if (mStackState != STACK_STATE_HOME_IN_FRONT) {
                mStackState = STACK_STATE_HOME_TO_FRONT;
            }
        } else {
            mFocusedStack = r.task.stack;
            if (mStackState != STACK_STATE_HOME_IN_BACK) {
                mStackState = STACK_STATE_HOME_TO_BACK;
            }
        }
    }

    final int startActivityUncheckedLocked(ActivityRecord r,
            ActivityRecord sourceRecord, int startFlags, boolean doResume,
            Bundle options) {
@@ -1091,8 +1137,8 @@ public class ActivityStackSupervisor {
            // This activity is not being started from another...  in this
            // case we -always- start a new task.
            if ((launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
                Slog.w(TAG, "startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: "
                      + intent);
                Slog.w(TAG, "startActivity called from non-Activity context; forcing " +
                        "Intent.FLAG_ACTIVITY_NEW_TASK for: " + intent);
                launchFlags |= Intent.FLAG_ACTIVITY_NEW_TASK;
            }
        } else if (sourceRecord.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
@@ -1150,6 +1196,9 @@ public class ActivityStackSupervisor {
                        ? findTaskLocked(intent, r.info)
                        : findActivityLocked(intent, r.info);
                if (intentActivity != null) {
                    if (r.task == null) {
                        r.task = intentActivity.task;
                    }
                    targetStack = intentActivity.task.stack;
                    moveHomeStack(targetStack.isHomeStack());
                    if (intentActivity.task.intent == null) {
@@ -1174,8 +1223,8 @@ public class ActivityStackSupervisor {
                            // user's face, right now.
                            movedHome = true;
                            if ((launchFlags &
                                    (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_TASK_ON_HOME))
                                    == (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_TASK_ON_HOME)) {
                                    (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
                                    == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
                                // Caller wants to appear on home activity, so before starting
                                // their own activity we will bring home to the front.
                                r.mLaunchHomeTaskNext = true;
@@ -1200,6 +1249,9 @@ public class ActivityStackSupervisor {
                        } else {
                            ActivityOptions.abort(options);
                        }
                        if (r.task == null)  Slog.v(TAG,
                                "startActivityUncheckedLocked: task left null",
                                new RuntimeException("here").fillInStackTrace());
                        return ActivityManager.START_RETURN_INTENT_TO_CALLER;
                    }
                    if ((launchFlags &
@@ -1293,6 +1345,9 @@ public class ActivityStackSupervisor {
                        } else {
                            ActivityOptions.abort(options);
                        }
                        if (r.task == null)  Slog.v(TAG,
                            "startActivityUncheckedLocked: task left null",
                            new RuntimeException("here").fillInStackTrace());
                        return ActivityManager.START_TASK_TO_FRONT;
                    }
                }
@@ -1330,9 +1385,15 @@ public class ActivityStackSupervisor {
                                // We don't need to start a new activity, and
                                // the client said not to do anything if that
                                // is the case, so this is it!
                                if (r.task == null)  Slog.v(TAG,
                                    "startActivityUncheckedLocked: task left null",
                                    new RuntimeException("here").fillInStackTrace());
                                return ActivityManager.START_RETURN_INTENT_TO_CALLER;
                            }
                            top.deliverNewIntentLocked(callingUid, r.intent);
                            if (r.task == null)  Slog.v(TAG,
                                "startActivityUncheckedLocked: task left null",
                                new RuntimeException("here").fillInStackTrace());
                            return ActivityManager.START_DELIVERED_TO_TOP;
                        }
                    }
@@ -1345,6 +1406,9 @@ public class ActivityStackSupervisor {
                        r.requestCode, Activity.RESULT_CANCELED, null);
            }
            ActivityOptions.abort(options);
            if (r.task == null)  Slog.v(TAG,
                "startActivityUncheckedLocked: task left null",
                new RuntimeException("here").fillInStackTrace());
            return ActivityManager.START_CLASS_NOT_FOUND;
        }

@@ -1394,6 +1458,9 @@ public class ActivityStackSupervisor {
                        targetStack.resumeTopActivityLocked(null);
                    }
                    ActivityOptions.abort(options);
                    if (r.task == null)  Slog.v(TAG,
                        "startActivityUncheckedLocked: task left null",
                        new RuntimeException("here").fillInStackTrace());
                    return ActivityManager.START_DELIVERED_TO_TOP;
                }
            } else if (!addingToTask &&
@@ -1413,6 +1480,9 @@ public class ActivityStackSupervisor {
                        setLaunchHomeTaskNextFlag(sourceRecord, null, targetStack);
                        targetStack.resumeTopActivityLocked(null);
                    }
                    if (r.task == null)  Slog.v(TAG,
                        "startActivityUncheckedLocked: task left null",
                        new RuntimeException("here").fillInStackTrace());
                    return ActivityManager.START_DELIVERED_TO_TOP;
                }
            }
+2 −6
Original line number Diff line number Diff line
@@ -305,7 +305,8 @@ public class WindowAnimator {
                                    wallpaperInUnForceHiding = true;
                                }
                            }
                            if (mCurrentFocus == null || mCurrentFocus.mLayer < win.mLayer) {
                            final WindowState currentFocus = mService.mCurrentFocus;
                            if (currentFocus == null || currentFocus.mLayer < win.mLayer) {
                                // We are showing on to of the current
                                // focus, so re-evaluate focus to make
                                // sure it is correct.
@@ -670,11 +671,6 @@ public class WindowAnimator {
        }
    }

    WindowState mCurrentFocus;
    void setCurrentFocus(final WindowState currentFocus) {
        mCurrentFocus = currentFocus;
    }

    boolean isDimmingLocked(int displayId) {
        return getDisplayContentsAnimatorLocked(displayId).mDimAnimator.isDimming();
    }
Loading