diff options
| author | wilsonshih <wilsonshih@google.com> | 2021-12-21 13:45:31 +0800 |
|---|---|---|
| committer | wilsonshih <wilsonshih@google.com> | 2022-01-25 20:40:23 +0800 |
| commit | 946a4063f73eef2a89e6e171c3eaad6c1a919c13 (patch) | |
| tree | b5197707e69e69c51c35d38fa79133fa9a322ba8 /core/java/android/window/SplashScreenView.java | |
| parent | 85b897d6f3f7eeec60073f15bca05056ef38657d (diff) | |
Allow app to receive onSplashscreenExit even for empty splash screen.
Allow developers to customize the exit animation for empty style splash
screen, there is a target sdk version check to prevents apps from
crash if the app didn't do null pointer check for #getIconView.
Bug: 205907456
Test: atest SplashscreenTests
Change-Id: I235f25fdf42b7177a6e195d3ffc07b92690e6f79
Diffstat (limited to 'core/java/android/window/SplashScreenView.java')
| -rw-r--r-- | core/java/android/window/SplashScreenView.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/core/java/android/window/SplashScreenView.java b/core/java/android/window/SplashScreenView.java index f04155d112d4..b90e628da714 100644 --- a/core/java/android/window/SplashScreenView.java +++ b/core/java/android/window/SplashScreenView.java @@ -151,6 +151,7 @@ public final class SplashScreenView extends FrameLayout { private Instant mIconAnimationStart; private Duration mIconAnimationDuration; private Consumer<Runnable> mUiThreadInitTask; + private boolean mAllowHandleEmpty = true; public Builder(@NonNull Context context) { mContext = context; @@ -258,6 +259,15 @@ public final class SplashScreenView extends FrameLayout { } /** + * Sets whether this view can be copied and transferred to the client if the view is + * empty style splash screen. + */ + public Builder setAllowHandleEmpty(boolean allowHandleEmpty) { + mAllowHandleEmpty = allowHandleEmpty; + return this; + } + + /** * Create SplashScreenWindowView object from materials. */ public SplashScreenView build() { @@ -303,7 +313,7 @@ public final class SplashScreenView extends FrameLayout { } view.mIconView = imageView; } - if (mOverlayDrawable != null || mIconDrawable == null) { + if (mOverlayDrawable != null || (view.mIconView == null && !mAllowHandleEmpty)) { view.setNotCopyable(); } @@ -720,13 +730,15 @@ public final class SplashScreenView extends FrameLayout { private RemoteCallback mClientCallback; public SplashScreenViewParcelable(SplashScreenView view) { - mIconSize = view.mIconView.getWidth(); + final View iconView = view.getIconView(); + mIconSize = iconView != null ? iconView.getWidth() : 0; mBackgroundColor = view.getInitBackgroundColor(); - mIconBackground = copyDrawable(view.getIconView().getBackground()); + mIconBackground = iconView != null ? copyDrawable(iconView.getBackground()) : null; mSurfacePackage = view.mSurfacePackageCopy; if (mSurfacePackage == null) { // We only need to copy the drawable if we are not using a SurfaceView - mIconBitmap = copyDrawable(((ImageView) view.getIconView()).getDrawable()); + mIconBitmap = iconView != null + ? copyDrawable(((ImageView) view.getIconView()).getDrawable()) : null; } mBrandingBitmap = copyDrawable(view.getBrandingView().getBackground()); |
