From 44f5e52d5335b95b87de1d046042e090510d282e Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Thu, 25 Nov 2021 18:03:31 +0800 Subject: [PATCH] Provide default splash screen style for Launcher and SystemUI. Previous the splash screen style can either be EMPTY or ICON, and need to be set by new hidden API #setSplashscreenStyle, so the flag will always be "EMPTY" for those 3rd party Launcher Apps which may have not upgrade to targetSDK 31. To correct the default behaivor for Launcher Apps, create a new UNDEFINED style as default value for splashScreenStyle, and if the value is UNDEFINED, determine the style by checking the launch source. Test: Verify no change when default home is NexusLauncher. Test: Set 3rd-party Launcher as default home, verify the splash screen style should be ICON when launch app from Launcher. Test: atest SplashscreenTests Bug: 206746601 Change-Id: I105e2fcfc7a6ee8de7f442931cbeb4b6e517850d Merged-In: I105e2fcfc7a6ee8de7f442931cbeb4b6e517850d --- core/java/android/app/ActivityOptions.java | 2 +- core/java/android/window/SplashScreen.java | 6 ++++++ .../com/android/server/wm/ActivityRecord.java | 18 +++++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java index edcab29dec94a..0ff9f6655b8a8 100644 --- a/core/java/android/app/ActivityOptions.java +++ b/core/java/android/app/ActivityOptions.java @@ -431,7 +431,7 @@ public class ActivityOptions { private boolean mOverrideTaskTransition; private String mSplashScreenThemeResName; @SplashScreen.SplashScreenStyle - private int mSplashScreenStyle; + private int mSplashScreenStyle = SplashScreen.SPLASH_SCREEN_STYLE_UNDEFINED; private boolean mRemoveWithTaskOrganizer; private boolean mLaunchedFromBubble; private boolean mTransientLaunch; diff --git a/core/java/android/window/SplashScreen.java b/core/java/android/window/SplashScreen.java index b9bf009fb2bb0..090dbff488e92 100644 --- a/core/java/android/window/SplashScreen.java +++ b/core/java/android/window/SplashScreen.java @@ -42,6 +42,11 @@ import java.util.ArrayList; * Activity.getSplashScreen() to get the SplashScreen.

*/ public interface SplashScreen { + /** + * The splash screen style is not defined. + * @hide + */ + int SPLASH_SCREEN_STYLE_UNDEFINED = -1; /** * Force splash screen to be empty. * @hide @@ -55,6 +60,7 @@ public interface SplashScreen { /** @hide */ @IntDef(prefix = { "SPLASH_SCREEN_STYLE_" }, value = { + SPLASH_SCREEN_STYLE_UNDEFINED, SPLASH_SCREEN_STYLE_EMPTY, SPLASH_SCREEN_STYLE_ICON }) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index d97c845ef7c41..dbeb3f5e23590 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -6563,6 +6563,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } else if (optionsStyle == SplashScreen.SPLASH_SCREEN_STYLE_ICON) { return false; } + // Choose the default behavior for Launcher and SystemUI when the SplashScreen style is + // not specified in the ActivityOptions. + if (mLaunchSourceType == LAUNCH_SOURCE_TYPE_HOME) { + return false; + } else if (mLaunchSourceType == LAUNCH_SOURCE_TYPE_SYSTEMUI) { + return true; + } } if (sourceRecord == null) { sourceRecord = searchCandidateLaunchingActivity(); @@ -6572,14 +6579,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 + // If this activity was launched from Launcher or System for first start, never use an + // empty splash screen. // Need to check sourceRecord before in case this activity is launched from service. - if (launchedFromSystemSurface()) { - return false; - } - - // Otherwise use empty. - return true; + return !startActivity || !(mLaunchSourceType == LAUNCH_SOURCE_TYPE_SYSTEM + || mLaunchSourceType == LAUNCH_SOURCE_TYPE_HOME); } private int getSplashscreenTheme() {