From 7004a8801d0a60013681a86043bab74b4d42d680 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Mon, 10 Apr 2017 09:50:21 -0700 Subject: [PATCH] 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 --- .../java/com/android/server/am/ActivityStack.java | 12 ++++++++++++ .../android/server/am/ActivityStackSupervisor.java | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 78887c6d82096..f551a445e773e 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -65,6 +65,7 @@ import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NA import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; import static com.android.server.am.ActivityRecord.ASSISTANT_ACTIVITY_TYPE; import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; +import static com.android.server.am.ActivityStack.ActivityState.STOPPED; import static com.android.server.am.ActivityStackSupervisor.FindTaskResult; import static com.android.server.am.ActivityStackSupervisor.ON_TOP; import static com.android.server.am.ActivityStackSupervisor.PAUSE_IMMEDIATELY; @@ -1166,6 +1167,8 @@ class ActivityStack extends ConfigurationContai final ArrayList activities = mTaskHistory.get(taskNdx).mActivities; for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { final ActivityRecord r = activities.get(activityNdx); + // TODO(b/37244415): This just wrong. We should also be moving PAUSED activities to + // the stopped state when we are sleeping. if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED || r.state == ActivityState.PAUSED || r.state == ActivityState.PAUSING) { r.setSleeping(true); @@ -1800,6 +1803,15 @@ class ActivityStack extends ConfigurationContai if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Skipping: already visible at " + r); + if (r.state == STOPPED) { + // In this case the activity is visible, but in the stopped state. + // This sometimes happens if the activity is behind the lockscreen. + // Restart the activity to the paused or resumed state since we want + // it to be in the visible state now. + makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, + resumeNextActivity, r); + } + if (r.handleAlreadyVisible()) { resumeNextActivity = false; } diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 68e25c37dca84..88de8a5fcbed3 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 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D 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 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } } mGoingToSleepActivities.clear(); + ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); } void activitySleptLocked(ActivityRecord r) {