From 70aa4d18be4865ef28795aa9e78f6b36ac437d8a Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Mon, 15 May 2017 00:05:54 +0200 Subject: [PATCH] Also add starting window when activity is not alive The fact whether the process is running or not is not necessarily a reason to not show a starting window. Sometimes the process with an activity gets killed, but later gets restarted because of some broadcast or service without recreating the activity. In this case, we still need a splash screen to hide the recreation delay, which is usually as expensive as if the process is not running. Test: Open Calendar, kill `pid calendar`, reopen it, make sure starting window is shown. Test: As above but with a couple of other apps - with and widhout trampoline activities. Test: Boot freshly and open a couple of apps from recents Change-Id: I8c4f928fca77b5446cab55c89bc69adbaaaa8da3 Fixes: 37951698 --- .../java/com/android/server/am/ActivityRecord.java | 3 ++- .../server/wm/AppWindowContainerController.java | 9 +++++---- .../wm/AppWindowContainerControllerTests.java | 13 ++++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index 4e00f2dc40237..81cd38254bd7f 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -2165,7 +2165,8 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme, compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(), - allowTaskSnapshot()); + allowTaskSnapshot(), + state.ordinal() >= RESUMED.ordinal() && state.ordinal() <= STOPPED.ordinal()); if (shown) { mStartingWindowState = STARTING_WINDOW_SHOWN; } diff --git a/services/core/java/com/android/server/wm/AppWindowContainerController.java b/services/core/java/com/android/server/wm/AppWindowContainerController.java index b5e194b4b93b6..5545e2b770ee0 100644 --- a/services/core/java/com/android/server/wm/AppWindowContainerController.java +++ b/services/core/java/com/android/server/wm/AppWindowContainerController.java @@ -447,7 +447,7 @@ public class AppWindowContainerController public boolean addStartingWindow(String pkg, int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags, IBinder transferFrom, boolean newTask, boolean taskSwitch, boolean processRunning, - boolean allowTaskSnapshot) { + boolean allowTaskSnapshot, boolean activityCreated) { synchronized(mWindowMap) { if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "setAppStartingWindow: token=" + mToken + " pkg=" + pkg + " transferFrom=" + transferFrom); @@ -475,7 +475,7 @@ public class AppWindowContainerController } final int type = getStartingWindowType(newTask, taskSwitch, processRunning, - allowTaskSnapshot); + allowTaskSnapshot, activityCreated); if (type == STARTING_WINDOW_TYPE_SNAPSHOT) { return createSnapshot(); @@ -546,8 +546,9 @@ public class AppWindowContainerController } private int getStartingWindowType(boolean newTask, boolean taskSwitch, boolean processRunning, - boolean allowTaskSnapshot) { - if (newTask || !processRunning) { + boolean allowTaskSnapshot, boolean activityCreated) { + if (newTask || !processRunning + || (taskSwitch && !activityCreated)) { return STARTING_WINDOW_TYPE_SPLASH_SCREEN; } else if (taskSwitch && allowTaskSnapshot) { return STARTING_WINDOW_TYPE_SNAPSHOT; diff --git a/services/tests/servicestests/src/com/android/server/wm/AppWindowContainerControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/AppWindowContainerControllerTests.java index dcbedb6f71b82..da3b9c9e92981 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AppWindowContainerControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/AppWindowContainerControllerTests.java @@ -97,7 +97,8 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { final WindowTestUtils.TestAppWindowContainerController controller = createAppWindowController(); controller.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), - android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true); + android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, + false); waitUntilHandlersIdle(); final AppWindowToken atoken = controller.getAppWindowToken(mDisplayContent); assertHasStartingWindow(atoken); @@ -113,11 +114,12 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { final WindowTestUtils.TestAppWindowContainerController controller2 = createAppWindowController(); controller1.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), - android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true); + android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, + false); waitUntilHandlersIdle(); controller2.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), android.R.style.Theme, null, "Test", 0, 0, 0, 0, controller1.mToken.asBinder(), - true, true, false, true); + true, true, false, true, false); waitUntilHandlersIdle(); assertNoStartingWindow(controller1.getAppWindowToken(mDisplayContent)); assertHasStartingWindow(controller2.getAppWindowToken(mDisplayContent)); @@ -134,10 +136,11 @@ public class AppWindowContainerControllerTests extends WindowTestsBase { // Surprise, ...! Transfer window in the middle of the creation flow. controller2.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), android.R.style.Theme, null, "Test", 0, 0, 0, 0, controller1.mToken.asBinder(), - true, true, false, true); + true, true, false, true, false); }); controller1.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(), - android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true); + android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, + false); waitUntilHandlersIdle(); assertNoStartingWindow(controller1.getAppWindowToken(mDisplayContent)); assertHasStartingWindow(controller2.getAppWindowToken(mDisplayContent));