From 7d970c6f3b4d9be2b7c5da2a0f882901037ae939 Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Wed, 10 Nov 2021 18:08:42 +0800 Subject: [PATCH] Re-order preferred starting window type. Prioritize the snapshot starting window than allDrawn condition, so there should show snapshot on phone when unlock keyguard or do quick switch. There should not affect low-ram device such as wear since there may not capture snapshot, so there should still show splash screen starting window for haven't drawn condition. Also correct one of the shouldUseEmptySplashScreen condition that launchedFromSystemSurface should only allowed when starting activity. Test: Start app, go to lockscreen and unlock, verify there should choose snapshot starting window. Test: atest ActivityRecordTests SplashscreenTests Bug: 176837715 Change-Id: I9112f93da35526f578df805dd5f126236c520d6a --- .../PhoneStartingWindowTypeAlgorithm.java | 33 +++++++++++------- .../com/android/server/wm/ActivityRecord.java | 34 ++++++++++--------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java index 05ba74a917acb..cbf8e7950e3dd 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java @@ -75,27 +75,34 @@ public class PhoneStartingWindowTypeAlgorithm implements StartingWindowTypeAlgor } if (!topIsHome) { - if (!processRunning - || newTask - || (taskSwitch && (!activityCreated || !activityDrawn))) { - return useEmptySplashScreen - ? STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN - : legacySplashScreen - ? STARTING_WINDOW_TYPE_LEGACY_SPLASH_SCREEN - : STARTING_WINDOW_TYPE_SPLASH_SCREEN; + if (!processRunning || newTask || (taskSwitch && !activityCreated)) { + return getSplashscreenType(useEmptySplashScreen, legacySplashScreen); } } - if (taskSwitch && allowTaskSnapshot) { - if (isSnapshotCompatible(windowInfo)) { - return STARTING_WINDOW_TYPE_SNAPSHOT; + + if (taskSwitch) { + if (allowTaskSnapshot) { + if (isSnapshotCompatible(windowInfo)) { + return STARTING_WINDOW_TYPE_SNAPSHOT; + } + if (!topIsHome) { + return STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN; + } } - if (!topIsHome) { - return STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN; + if (!activityDrawn && !topIsHome) { + return getSplashscreenType(useEmptySplashScreen, legacySplashScreen); } } return STARTING_WINDOW_TYPE_NONE; } + private static int getSplashscreenType(boolean emptySplashScreen, boolean legacySplashScreen) { + return emptySplashScreen + ? STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN + : legacySplashScreen + ? STARTING_WINDOW_TYPE_LEGACY_SPLASH_SCREEN + : STARTING_WINDOW_TYPE_SPLASH_SCREEN; + } /** * Returns {@code true} if the task snapshot is compatible with this activity (at least the diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index b6e5876b22192..8644d1ea474be 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -2131,20 +2131,25 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A private int getStartingWindowType(boolean newTask, boolean taskSwitch, boolean processRunning, boolean allowTaskSnapshot, boolean activityCreated, boolean activityAllDrawn, TaskSnapshot snapshot) { - if ((newTask || !processRunning || (taskSwitch && !activityCreated) - || (taskSwitch && !activityAllDrawn)) && !isActivityTypeHome()) { + final boolean isActivityHome = isActivityTypeHome(); + if ((newTask || !processRunning || (taskSwitch && !activityCreated)) + && !isActivityHome) { return STARTING_WINDOW_TYPE_SPLASH_SCREEN; - } else if (taskSwitch && allowTaskSnapshot) { - if (isSnapshotCompatible(snapshot)) { - return STARTING_WINDOW_TYPE_SNAPSHOT; + } + if (taskSwitch) { + if (allowTaskSnapshot) { + if (isSnapshotCompatible(snapshot)) { + return STARTING_WINDOW_TYPE_SNAPSHOT; + } + if (!isActivityHome) { + return STARTING_WINDOW_TYPE_SPLASH_SCREEN; + } } - if (!isActivityTypeHome()) { + if (!activityAllDrawn && !isActivityHome) { return STARTING_WINDOW_TYPE_SPLASH_SCREEN; } - return STARTING_WINDOW_TYPE_NONE; - } else { - return STARTING_WINDOW_TYPE_NONE; } + return STARTING_WINDOW_TYPE_NONE; } /** @@ -6433,14 +6438,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return sourceRecord.mSplashScreenStyleEmpty; } - // If this activity was launched from a system surface, never use an empty splash screen - // Need to check sourceRecord before in case this activity is launched from service. - if (launchedFromSystemSurface()) { - return false; - } - + // If this activity was launched from a system surface for first start, never use an empty + // splash screen. Need to check sourceRecord before in case this activity is launched from + // service. // Otherwise use empty. - return true; + return !startActivity || !launchedFromSystemSurface(); } private int getSplashscreenTheme() {