Merge "Fix activity manager timeout during shutdown" into oc-mr1-dev

This commit is contained in:
David Stevens
2017-08-23 01:58:36 +00:00
committed by Android (Google) Code Review
3 changed files with 26 additions and 27 deletions

View File

@@ -1184,7 +1184,8 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
* function get called again when those actions complete.
*
* @param shuttingDown true when the called because the device is shutting down.
* @return true if something must be done before going to sleep.
* @return true if the stack finished going to sleep, false if the stack only started the
* process of going to sleep (checkReadyForSleep will be called when that process finishes).
*/
boolean goToSleepIfPossible(boolean shuttingDown) {
boolean shouldSleep = true;
@@ -1235,10 +1236,10 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
goToSleep();
}
return !shouldSleep;
return shouldSleep;
}
private void goToSleep() {
void goToSleep() {
ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
// Make sure any paused or stopped but visible activities are now sleeping.

View File

@@ -3173,15 +3173,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
boolean timedout = false;
final long endTime = System.currentTimeMillis() + timeout;
while (true) {
boolean cantShutdown = false;
for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
cantShutdown |=
stacks.get(stackNdx).goToSleepIfPossible(true /* shuttingDown */);
}
}
if (cantShutdown) {
if (!putStacksToSleepLocked(true /* allowDelay */, true /* shuttingDown */)) {
long timeRemaining = endTime - System.currentTimeMillis();
if (timeRemaining > 0) {
try {
@@ -3268,19 +3260,8 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
return;
}
if (allowDelay) {
boolean dontSleep = false;
for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx);
final ArrayList<ActivityStack> stacks = display.mStacks;
for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
dontSleep |= stacks.get(stackNdx).goToSleepIfPossible(false /* shuttingDown */);
}
}
if (dontSleep) {
return;
}
if (!putStacksToSleepLocked(allowDelay, false /* shuttingDown */)) {
return;
}
// Send launch end powerhint before going sleep
@@ -3296,6 +3277,23 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
}
}
// Tries to put all activity stacks to sleep. Returns true if all stacks were
// successfully put to sleep.
private boolean putStacksToSleepLocked(boolean allowDelay, boolean shuttingDown) {
boolean allSleep = true;
for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
if (allowDelay) {
allSleep &= stacks.get(stackNdx).goToSleepIfPossible(shuttingDown);
} else {
stacks.get(stackNdx).goToSleep();
}
}
}
return allSleep;
}
boolean reportResumedActivityLocked(ActivityRecord r) {
final ActivityStack stack = r.getStack();
if (isFocusedStack(stack)) {

View File

@@ -17,9 +17,9 @@
package com.android.server.am;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import android.app.ActivityManager;
import android.content.ComponentName;
@@ -81,7 +81,7 @@ public class ActivityStackTests extends ActivityTestsBase {
final boolean waiting = testStack.goToSleepIfPossible(false);
// Ensure we report not being ready for sleep.
assertTrue(waiting);
assertFalse(waiting);
// Make sure the resumed activity is untouched.
assertEquals(testStack.mResumedActivity, activityRecord);