Ensure visible activities when device is unlocked.

When the device is locked we transition all activities to the stopped
state. However, we were only resuming the activity in the focused stack
when the device is unlocked. We now:
- Ensure all visible acitvities when the device is unlocked regardless
of stack.
- If the activity is marked as visible, but in the STOPPED state, we go
ahead and restart it.
- Correctly set ActivityRecord.stopped to false when we restart an
activity into the PAUSED state.

Fixes: 37119770
Bug: 37244415
Test: Make sure docked activity state isn't STOPPED when device is
unlocked.

Change-Id: I1498eeddaa3c1f5dd5135dca56271ffc22b704f2
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 68e25c3..88de8a5 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -1477,11 +1477,12 @@
             stack.minimalResumeActivityLocked(r);
         } else {
             // This activity is not starting in the resumed state... which should look like we asked
-            // it to pause+stop (but remain visible), and it has done so and reported back the
+            // it to resume+pause (but remain visible), and it has done so and reported back the
             // current icicle and other state.
             if (DEBUG_STATES) Slog.v(TAG_STATES,
                     "Moving to PAUSED: " + r + " (starting in paused state)");
             r.state = PAUSED;
+            r.stopped = false;
         }
 
         // Launch the new version setup screen if needed.  We do this -after-
@@ -3089,6 +3090,7 @@
             }
         }
         mGoingToSleepActivities.clear();
+        ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
     }
 
     void activitySleptLocked(ActivityRecord r) {