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 style when launch app from Launcher.
Test: atest SplashscreenTests
Bug: 206746601

Change-Id: I105e2fcfc7a6ee8de7f442931cbeb4b6e517850d
This commit is contained in:
wilsonshih
2021-11-25 18:03:31 +08:00
parent 544739c611
commit a19270f278
3 changed files with 19 additions and 6 deletions

View File

@@ -431,7 +431,7 @@ public class ActivityOptions extends ComponentOptions {
private boolean mOverrideTaskTransition; private boolean mOverrideTaskTransition;
private String mSplashScreenThemeResName; private String mSplashScreenThemeResName;
@SplashScreen.SplashScreenStyle @SplashScreen.SplashScreenStyle
private int mSplashScreenStyle; private int mSplashScreenStyle = SplashScreen.SPLASH_SCREEN_STYLE_UNDEFINED;
private boolean mRemoveWithTaskOrganizer; private boolean mRemoveWithTaskOrganizer;
private boolean mLaunchedFromBubble; private boolean mLaunchedFromBubble;
private boolean mTransientLaunch; private boolean mTransientLaunch;

View File

@@ -42,6 +42,11 @@ import java.util.ArrayList;
* <code>Activity.getSplashScreen()</code> to get the SplashScreen.</p> * <code>Activity.getSplashScreen()</code> to get the SplashScreen.</p>
*/ */
public interface SplashScreen { public interface SplashScreen {
/**
* The splash screen style is not defined.
* @hide
*/
int SPLASH_SCREEN_STYLE_UNDEFINED = -1;
/** /**
* Force splash screen to be empty. * Force splash screen to be empty.
* @hide * @hide
@@ -55,6 +60,7 @@ public interface SplashScreen {
/** @hide */ /** @hide */
@IntDef(prefix = { "SPLASH_SCREEN_STYLE_" }, value = { @IntDef(prefix = { "SPLASH_SCREEN_STYLE_" }, value = {
SPLASH_SCREEN_STYLE_UNDEFINED,
SPLASH_SCREEN_STYLE_EMPTY, SPLASH_SCREEN_STYLE_EMPTY,
SPLASH_SCREEN_STYLE_ICON SPLASH_SCREEN_STYLE_ICON
}) })

View File

@@ -6432,6 +6432,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
} else if (optionsStyle == SplashScreen.SPLASH_SCREEN_STYLE_ICON) { } else if (optionsStyle == SplashScreen.SPLASH_SCREEN_STYLE_ICON) {
return false; 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) { if (sourceRecord == null) {
sourceRecord = searchCandidateLaunchingActivity(); sourceRecord = searchCandidateLaunchingActivity();
@@ -6441,11 +6448,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return sourceRecord.mSplashScreenStyleEmpty; return sourceRecord.mSplashScreenStyleEmpty;
} }
// If this activity was launched from a system surface for first start, never use an empty // If this activity was launched from Launcher or System for first start, never use an
// splash screen. Need to check sourceRecord before in case this activity is launched from // empty splash screen.
// service. // Need to check sourceRecord before in case this activity is launched from service.
// Otherwise use empty. return !startActivity || !(mLaunchSourceType == LAUNCH_SOURCE_TYPE_SYSTEM
return !startActivity || !launchedFromSystemSurface(); || mLaunchSourceType == LAUNCH_SOURCE_TYPE_HOME);
} }
private int getSplashscreenTheme() { private int getSplashscreenTheme() {