Create splash screen if activity launched with FLAG_ACTIVITY_CLEAR_TASK

When an activity launched with NEW_TASK and CLEAR_TASK, there will
finish the original activities and reuse the same task to create a new
activity, so there will need to wait for the new window drawn to
trigger wm transition, which slow down the launch response. And because
this condition should be a kind of warm launch, there should create a
splash screen for it.

Bug: 187808226
Test: atest ActivityRecordTests SplashscreenTests
Test: manual verify by winscope
Change-Id: I263edcd75fcd21999b9ceb9fac8bfcf8419539a3
This commit is contained in:
wilsonshih
2021-06-16 12:11:43 +08:00
parent 5c86c0c10e
commit ed9c44a273

View File

@@ -6254,12 +6254,18 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
final int resolvedTheme = evaluateStartingWindowTheme(packageName, theme,
splashScreenTheme);
final boolean activityCreated =
mState.ordinal() >= STARTED.ordinal() && mState.ordinal() <= STOPPED.ordinal();
// If this activity is just created and all activities below are finish, treat this
// scenario as warm launch.
final boolean newSingleActivity = !newTask && !activityCreated
&& task.getActivity((r) -> !r.finishing && r != this) == null;
final boolean shown = addStartingWindow(packageName, resolvedTheme,
compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(),
allowTaskSnapshot(),
mState.ordinal() >= STARTED.ordinal() && mState.ordinal() <= STOPPED.ordinal(),
mSplashScreenStyleEmpty);
prev != null ? prev.appToken : null,
newTask || newSingleActivity, taskSwitch, isProcessRunning(),
allowTaskSnapshot(), activityCreated, mSplashScreenStyleEmpty);
if (shown) {
mStartingWindowState = STARTING_WINDOW_SHOWN;
}