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

Commit 93529a47 authored by Craig Mautner's avatar Craig Mautner
Browse files

Resume user where they left off.

Remember which stack was in front when the user changes. Restore that
stack when the user changes back. Remove user state when user is
deleted.

Fixes bug 11068986.

Change-Id: I18dfbc35a0c2e21e7a4024227cbfc5ba1208b3a3
parent 3d61bf45
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -15818,9 +15818,11 @@ public final class ActivityManagerService extends ActivityManagerNative
                    }
                }
                boolean haveActivities = mStackSupervisor.switchUserLocked(userId, uss);
                if (!haveActivities) {
                boolean homeInFront = mStackSupervisor.switchUserLocked(userId, uss);
                if (homeInFront) {
                    startHomeActivityLocked(userId);
                } else {
                    mStackSupervisor.resumeTopActivitiesLocked();
                }
                EventLogTags.writeAmSwitchUser(userId);
@@ -16146,6 +16148,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            } catch (RemoteException e) {
            }
        }
        mStackSupervisor.removeUserLocked(userId);
    }
    @Override
+2 −7
Original line number Diff line number Diff line
@@ -549,31 +549,26 @@ final class ActivityStack {

    /*
     * Move the activities around in the stack to bring a user to the foreground.
     * @return whether there are any activities for the specified user.
     */
    final boolean switchUserLocked(int userId) {
    final void switchUserLocked(int userId) {
        if (VALIDATE_TOKENS) {
            validateAppTokensLocked();
        }
        if (mCurrentUser == userId) {
            return true;
            return;
        }
        mCurrentUser = userId;

        // Move userId's tasks to the top.
        boolean haveActivities = false;
        int index = mTaskHistory.size();
        for (int i = 0; i < index; ++i) {
            TaskRecord task = mTaskHistory.get(i);
            if (task.userId == userId) {
                haveActivities = true;
                mTaskHistory.remove(i);
                mTaskHistory.add(task);
                --index;
            }
        }

        return haveActivities;
    }

    void minimalResumeActivityLocked(ActivityRecord r) {
+14 −5
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import android.util.EventLog;
import android.util.Slog;
import android.util.SparseArray;

import android.util.SparseBooleanArray;
import com.android.internal.app.HeavyWeightSwitcherActivity;
import com.android.internal.os.TransferPipe;
import com.android.server.am.ActivityManagerService.PendingActivityLaunch;
@@ -203,6 +204,9 @@ public final class ActivityStackSupervisor {
     */
    final PowerManager.WakeLock mGoingToSleep;

    /** State of the stacks when user switched, indexed by userId. */
    SparseBooleanArray mUserHomeInFront = new SparseBooleanArray(2);

    public ActivityStackSupervisor(ActivityManagerService service, Context context,
            Looper looper) {
        mService = service;
@@ -1960,6 +1964,10 @@ public final class ActivityStackSupervisor {
        }
    }

    void removeUserLocked(int userId) {
        mUserHomeInFront.delete(userId);
    }

    /**
     * @return true if some activity was finished (or would have finished if doit were true).
     */
@@ -2278,17 +2286,17 @@ public final class ActivityStackSupervisor {
    }

    boolean switchUserLocked(int userId, UserStartedState uss) {
        mUserHomeInFront.put(mCurrentUser, isFrontStack(mHomeStack));
        final boolean homeInFront = mUserHomeInFront.get(userId, true);
        mCurrentUser = userId;

        mStartingUsers.add(uss);
        boolean haveActivities = false;
        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
            haveActivities |= mStacks.get(stackNdx).switchUserLocked(userId);
            mStacks.get(stackNdx).switchUserLocked(userId);
        }

        resumeTopActivitiesLocked();

        return haveActivities;
        moveHomeStack(homeInFront);
        return homeInFront;
    }

    final ArrayList<ActivityRecord> processStoppingActivitiesLocked(boolean remove) {
@@ -2381,6 +2389,7 @@ public final class ActivityStackSupervisor {
        pw.print(prefix); pw.print("mStackState="); pw.println(stackStateToString(mStackState));
        pw.print(prefix); pw.println("mSleepTimeout: " + mSleepTimeout);
        pw.print(prefix); pw.println("mCurTaskId: " + mCurTaskId);
        pw.print(prefix); pw.println("mUserHomeInFront: " + mUserHomeInFront);
    }

    ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) {