Fix user switching.

- Save and restore WindowManager stack states.
- Maintain ActivityManager activity states based on the stack
the activity is in.

Fixes bug 8646641.

Change-Id: I16c76c7708ab49121c3884a7e5bf219898b92d3f
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 3557e90..3758bb1 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -234,7 +234,7 @@
     int mThumbnailWidth = -1;
     int mThumbnailHeight = -1;
 
-    private int mCurrentUser;
+    int mCurrentUser;
 
     final int mStackId;
 
@@ -576,7 +576,8 @@
     }
 
     /*
-     * Move the activities around in the stack to bring a user to the foreground.
+     * Move the activities around in the stack to bring a user to the foreground. This only
+     * matters on the home stack. All other stacks are single user.
      * @return whether there are any activities for the specified user.
      */
     final boolean switchUserLocked(int userId, UserStartedState uss) {
@@ -602,9 +603,6 @@
             }
         }
 
-        // task is now the original topmost TaskRecord. Transition from the old top to the new top.
-        ActivityRecord top = task != null ? task.getTopActivity() : null;
-        resumeTopActivityLocked(top);
         return haveActivities;
     }
 
@@ -1718,7 +1716,7 @@
         }
 
         if (doResume) {
-            mStackSupervisor.resumeTopActivityLocked();
+            mStackSupervisor.resumeTopActivitiesLocked();
         }
     }