From ed9c44a27331ff535611d715ccea5b3edcfffc6c Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Wed, 16 Jun 2021 12:11:43 +0800 Subject: [PATCH] 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 --- .../java/com/android/server/wm/ActivityRecord.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 8514f3599832c..3fb4c8822c642 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -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; }