From 72a03ff774f2469239f7a79a29ef72a6153d3f49 Mon Sep 17 00:00:00 2001
From: wilsonshih
Date: Tue, 18 May 2021 19:35:12 +0800
Subject: [PATCH] Introduce setSplashscreenStyle to specify splash screen
style.
Provide a method ActivityOptions#setSplashscreenStyle to specify
splash screen style if needed.
If not set, the default option will be empty-style splash screen, so
without any other change, the activity launched from systemui with
ActivityOptions will become empty style splash screen.
Bug: 188023621
Bug: 189293785
Test: manual test start application from Launcher and Notification.
Change-Id: I299320db8f32fbd835c7ec0acaad3df3486a13f5
---
core/java/android/app/ActivityOptions.java | 28 +++++++++++++++++++
core/java/android/window/SplashScreen.java | 19 +++++++++++++
.../com/android/server/wm/ActivityRecord.java | 9 ++++++
3 files changed, 56 insertions(+)
diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java
index 306b54d140196..1ce598b5fa183 100644
--- a/core/java/android/app/ActivityOptions.java
+++ b/core/java/android/app/ActivityOptions.java
@@ -56,6 +56,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.window.IRemoteTransition;
+import android.window.SplashScreen;
import android.window.WindowContainerToken;
import java.lang.annotation.Retention;
@@ -327,6 +328,10 @@ public class ActivityOptions {
private static final String KEY_LAUNCHED_FROM_BUBBLE =
"android.activity.launchTypeBubble";
+ /** See {@link #setSplashscreenStyle(int)}. */
+ private static final String KEY_SPLASH_SCREEN_STYLE =
+ "android.activity.splashScreenStyle";
+
/** See {@link #setTransientLaunch()}. */
private static final String KEY_TRANSIENT_LAUNCH = "android.activity.transientLaunch";
@@ -415,6 +420,8 @@ public class ActivityOptions {
private IRemoteTransition mRemoteTransition;
private boolean mOverrideTaskTransition;
private int mSplashScreenThemeResId;
+ @SplashScreen.SplashScreenStyle
+ private int mSplashScreenStyle;
private boolean mRemoveWithTaskOrganizer;
private boolean mLaunchedFromBubble;
private boolean mTransientLaunch;
@@ -1171,6 +1178,7 @@ public class ActivityOptions {
mRemoveWithTaskOrganizer = opts.getBoolean(KEY_REMOVE_WITH_TASK_ORGANIZER);
mLaunchedFromBubble = opts.getBoolean(KEY_LAUNCHED_FROM_BUBBLE);
mTransientLaunch = opts.getBoolean(KEY_TRANSIENT_LAUNCH);
+ mSplashScreenStyle = opts.getInt(KEY_SPLASH_SCREEN_STYLE);
}
/**
@@ -1364,6 +1372,23 @@ public class ActivityOptions {
return mSplashScreenThemeResId;
}
+ /**
+ * Sets the preferred splash screen style.
+ * @hide
+ */
+ public void setSplashscreenStyle(@SplashScreen.SplashScreenStyle int style) {
+ mSplashScreenStyle = style;
+ }
+
+ /**
+ * Gets the preferred splash screen style from caller
+ * @hide
+ */
+ @SplashScreen.SplashScreenStyle
+ public int getSplashScreenStyle() {
+ return mSplashScreenStyle;
+ }
+
/**
* Sets whether the activity is to be launched into LockTask mode.
*
@@ -1932,6 +1957,9 @@ public class ActivityOptions {
if (mTransientLaunch) {
b.putBoolean(KEY_TRANSIENT_LAUNCH, mTransientLaunch);
}
+ if (mSplashScreenStyle != 0) {
+ b.putInt(KEY_SPLASH_SCREEN_STYLE, mSplashScreenStyle);
+ }
return b;
}
diff --git a/core/java/android/window/SplashScreen.java b/core/java/android/window/SplashScreen.java
index 42a58fb65e391..3e0075857402d 100644
--- a/core/java/android/window/SplashScreen.java
+++ b/core/java/android/window/SplashScreen.java
@@ -16,6 +16,7 @@
package android.window;
+import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.StyleRes;
import android.annotation.SuppressLint;
@@ -41,6 +42,24 @@ import java.util.ArrayList;
* Activity.getSplashScreen() to get the SplashScreen.
*/
public interface SplashScreen {
+ /**
+ * Force splash screen to be empty.
+ * @hide
+ */
+ int SPLASH_SCREEN_STYLE_EMPTY = 0;
+ /**
+ * Force splash screen to show icon.
+ * @hide
+ */
+ int SPLASH_SCREEN_STYLE_ICON = 1;
+
+ /** @hide */
+ @IntDef(prefix = { "SPLASH_SCREEN_STYLE_" }, value = {
+ SPLASH_SCREEN_STYLE_EMPTY,
+ SPLASH_SCREEN_STYLE_ICON
+ })
+ @interface SplashScreenStyle {}
+
/**
* Specifies whether an {@link Activity} wants to handle the splash screen animation on its
* own. Normally the splash screen will show on screen before the content of the activity has
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 9c43dd3941240..660cd37b123cb 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -308,6 +308,7 @@ import android.view.WindowManager.TransitionOldType;
import android.view.animation.Animation;
import android.window.IRemoteTransition;
import android.window.SizeConfigurationBuckets;
+import android.window.SplashScreen;
import android.window.SplashScreenView.SplashScreenViewParcelable;
import android.window.TaskSnapshot;
import android.window.WindowContainerToken;
@@ -6182,6 +6183,14 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
}
private boolean shouldUseEmptySplashScreen(ActivityRecord sourceRecord) {
+ if (mPendingOptions != null) {
+ final int optionsStyle = mPendingOptions.getSplashScreenStyle();
+ if (optionsStyle == SplashScreen.SPLASH_SCREEN_STYLE_EMPTY) {
+ return true;
+ } else if (optionsStyle == SplashScreen.SPLASH_SCREEN_STYLE_ICON) {
+ return false;
+ }
+ }
if (sourceRecord == null) {
sourceRecord = searchCandidateLaunchingActivity();
}