[Android] Removes handling of Flutter splash screen (flutter/engine#44047)

Fixes https://github.com/flutter/flutter/issues/105173.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
Camille Simon
2023-07-28 11:08:35 -07:00
committed by GitHub
parent 8e096b49b2
commit 39cbbd22a3
17 changed files with 4 additions and 2008 deletions

View File

@@ -2326,7 +2326,6 @@ ORIGIN: ../../../flutter/shell/platform/android/io/flutter/app/FlutterApplicatio
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/app/FlutterFragmentActivity.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/app/FlutterPlayStoreSplitApplication.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/DrawableSplashScreen.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/ExclusiveAppComponent.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java + ../../../flutter/LICENSE
@@ -2337,7 +2336,6 @@ ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/Flu
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragmentActivity.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterPlayStoreSplitApplication.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterSplashView.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterSurfaceView.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterTextureView.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java + ../../../flutter/LICENSE
@@ -2347,8 +2345,6 @@ ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/Key
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/KeyboardManager.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/KeyboardMap.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/RenderMode.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/SplashScreen.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/SplashScreenProvider.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/TransparencyMode.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/android/WindowInfoRepositoryCallbackAdapterWrapper.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java + ../../../flutter/LICENSE
@@ -5024,7 +5020,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterFragmentActi
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterPlayStoreSplitApplication.java
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/DrawableSplashScreen.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/ExclusiveAppComponent.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java
@@ -5035,7 +5030,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/Flutt
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragmentActivity.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterPlayStoreSplitApplication.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterSplashView.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterSurfaceView.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterTextureView.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java
@@ -5046,8 +5040,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/Keybo
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/KeyboardMap.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/MotionEventTracker.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/RenderMode.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/SplashScreen.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/SplashScreenProvider.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/TransparencyMode.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/WindowInfoRepositoryCallbackAdapterWrapper.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java

View File

@@ -180,7 +180,6 @@ android_java_sources = [
"io/flutter/app/FlutterPlayStoreSplitApplication.java",
"io/flutter/app/FlutterPluginRegistry.java",
"io/flutter/embedding/android/AndroidTouchProcessor.java",
"io/flutter/embedding/android/DrawableSplashScreen.java",
"io/flutter/embedding/android/ExclusiveAppComponent.java",
"io/flutter/embedding/android/FlutterActivity.java",
"io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java",
@@ -191,7 +190,6 @@ android_java_sources = [
"io/flutter/embedding/android/FlutterFragmentActivity.java",
"io/flutter/embedding/android/FlutterImageView.java",
"io/flutter/embedding/android/FlutterPlayStoreSplitApplication.java",
"io/flutter/embedding/android/FlutterSplashView.java",
"io/flutter/embedding/android/FlutterSurfaceView.java",
"io/flutter/embedding/android/FlutterTextureView.java",
"io/flutter/embedding/android/FlutterView.java",
@@ -202,8 +200,6 @@ android_java_sources = [
"io/flutter/embedding/android/KeyboardMap.java",
"io/flutter/embedding/android/MotionEventTracker.java",
"io/flutter/embedding/android/RenderMode.java",
"io/flutter/embedding/android/SplashScreen.java",
"io/flutter/embedding/android/SplashScreenProvider.java",
"io/flutter/embedding/android/TransparencyMode.java",
"io/flutter/embedding/android/WindowInfoRepositoryCallbackAdapterWrapper.java",
"io/flutter/embedding/engine/FlutterEngine.java",

View File

@@ -1,125 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.embedding.android;
import android.animation.Animator;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* {@link SplashScreen} that displays a given {@link Drawable}, which then fades its alpha to zero
* when instructed to {@link #transitionToFlutter(Runnable)}.
*
* <p>Please use the new Splash screen API available on Android S. On lower versions of Android,
* it's no longer necessary to display a splash screen to wait for the Flutter first frame.
*
* @deprecated
*/
@Deprecated
public final class DrawableSplashScreen implements SplashScreen {
private final Drawable drawable;
private final ImageView.ScaleType scaleType;
private final long crossfadeDurationInMillis;
private DrawableSplashScreenView splashView;
/**
* Constructs a {@code DrawableSplashScreen} that displays the given {@code drawable} and
* crossfades to Flutter content in 500 milliseconds.
*
* @param drawable A drawable to display on the Splash screen view.
*/
public DrawableSplashScreen(@NonNull Drawable drawable) {
this(drawable, ImageView.ScaleType.FIT_XY, 500);
}
/**
* Constructs a {@code DrawableSplashScreen} that displays the given {@code drawable} and
* crossfades to Flutter content in the given {@code crossfadeDurationInMillis}.
*
* @param drawable The {@code Drawable} to be displayed as a splash screen.
* @param scaleType The {@link android.widget.ImageView.ScaleType} to be applied to the {@code
* Drawable} when the {@code Drawable} is displayed full-screen.
* @param crossfadeDurationInMillis Duration of the crossfade in milliseconds.
*/
public DrawableSplashScreen(
@NonNull Drawable drawable,
@NonNull ImageView.ScaleType scaleType,
long crossfadeDurationInMillis) {
this.drawable = drawable;
this.scaleType = scaleType;
this.crossfadeDurationInMillis = crossfadeDurationInMillis;
}
@Nullable
@Override
public View createSplashView(@NonNull Context context, @Nullable Bundle savedInstanceState) {
splashView = new DrawableSplashScreenView(context);
splashView.setSplashDrawable(drawable, scaleType);
return splashView;
}
@Override
public void transitionToFlutter(@NonNull Runnable onTransitionComplete) {
if (splashView == null) {
onTransitionComplete.run();
return;
}
splashView
.animate()
.alpha(0.0f)
.setDuration(crossfadeDurationInMillis)
.setListener(
new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {}
@Override
public void onAnimationEnd(Animator animation) {
onTransitionComplete.run();
}
@Override
public void onAnimationCancel(Animator animation) {
onTransitionComplete.run();
}
@Override
public void onAnimationRepeat(Animator animation) {}
});
}
// Public for Android OS requirements. This View should not be used by external developers.
public static class DrawableSplashScreenView extends ImageView {
public DrawableSplashScreenView(@NonNull Context context) {
this(context, null, 0);
}
public DrawableSplashScreenView(@NonNull Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public DrawableSplashScreenView(
@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void setSplashDrawable(@Nullable Drawable drawable) {
setSplashDrawable(drawable, ImageView.ScaleType.FIT_XY);
}
public void setSplashDrawable(
@Nullable Drawable drawable, @NonNull ImageView.ScaleType scaleType) {
setScaleType(scaleType);
setImageDrawable(drawable);
}
}
}

View File

@@ -20,7 +20,6 @@ import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_IN
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.HANDLE_DEEPLINKING_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.INITIAL_ROUTE_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.NORMAL_THEME_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.SPLASH_SCREEN_META_DATA_KEY;
import android.app.Activity;
import android.content.Context;
@@ -28,10 +27,8 @@ import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
@@ -42,7 +39,6 @@ import android.window.OnBackInvokedDispatcher;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.res.ResourcesCompat;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
@@ -69,7 +65,6 @@ import java.util.List;
*
* <ul>
* <li>Displays an Android launch screen.
* <li>Displays a Flutter splash screen.
* <li>Configures the status bar appearance.
* <li>Chooses the Dart execution app bundle path, entrypoint and entrypoint arguments.
* <li>Chooses Flutter's initial route.
@@ -167,7 +162,7 @@ import java.util.List;
* FlutterView}. Using a {@link FlutterView} requires forwarding some calls from an {@code
* Activity}, as well as forwarding lifecycle calls from an {@code Activity} or a {@code Fragment}.
*
* <p><strong>Launch Screen and Splash Screen</strong>
* <p><strong>Launch Screen</strong>
*
* <p>{@code FlutterActivity} supports the display of an Android "launch screen", which is displayed
* while the Android application loads. It is only applicable if {@code FlutterActivity} is the
@@ -201,10 +196,6 @@ import java.util.List;
* <p>With themes defined, and AndroidManifest.xml updated, Flutter displays the specified launch
* screen until the Android application is initialized.
*
* <p>Flutter also requires initialization time. To specify a splash screen for Flutter
* initialization, subclass {@code FlutterActivity} and override {@link #provideSplashScreen()}. See
* {@link SplashScreen} for details on implementing a splash screen.
*
* <p><strong>Alternative Activity</strong> {@link FlutterFragmentActivity} is also available, which
* is similar to {@code FlutterActivity} but it extends {@code FragmentActivity}. You should use
* {@code FlutterActivity}, if possible, but if you need a {@code FragmentActivity} then you should
@@ -756,41 +747,6 @@ public class FlutterActivity extends Activity
}
}
@Nullable
@Override
public SplashScreen provideSplashScreen() {
Drawable manifestSplashDrawable = getSplashScreenFromManifest();
if (manifestSplashDrawable != null) {
return new DrawableSplashScreen(manifestSplashDrawable);
} else {
return null;
}
}
/**
* Returns a {@link Drawable} to be used as a splash screen as requested by meta-data in the
* {@code AndroidManifest.xml} file, or null if no such splash screen is requested.
*
* <p>See {@link FlutterActivityLaunchConfigs#SPLASH_SCREEN_META_DATA_KEY} for the meta-data key
* to be used in a manifest file.
*/
@Nullable
private Drawable getSplashScreenFromManifest() {
try {
Bundle metaData = getMetaData();
int splashScreenId = metaData != null ? metaData.getInt(SPLASH_SCREEN_META_DATA_KEY) : 0;
return splashScreenId != 0
? ResourcesCompat.getDrawable(getResources(), splashScreenId, getTheme())
: null;
} catch (Resources.NotFoundException e) {
Log.e(TAG, "Splash screen not found. Ensure the drawable exists and that it's valid.");
throw e;
} catch (PackageManager.NameNotFoundException e) {
// This is never expected to happen.
return null;
}
}
/**
* Sets this {@code Activity}'s {@code Window} background to be transparent, and hides the status
* bar, if this {@code Activity}'s desired {@link BackgroundMode} is {@link

View File

@@ -30,7 +30,6 @@ import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.util.ViewUtils;
import java.util.Arrays;
import java.util.List;
@@ -344,9 +343,7 @@ import java.util.List;
* with Android tools, such as "Displayed" timing printed with `am start`.
*
* <p>Note that it should only be set to true when {@code Host#getRenderMode()} is {@code
* RenderMode.surface}. This parameter is also ignored, disabling the delay should the legacy
* {@code Host#provideSplashScreen()} be non-null. See <a
* href="https://flutter.dev/go/android-splash-migration">Android Splash Migration</a>.
* RenderMode.surface}.
*
* <p>This method:
*
@@ -397,20 +394,6 @@ import java.util.List;
flutterView.attachToFlutterEngine(flutterEngine);
flutterView.setId(flutterViewId);
SplashScreen splashScreen = host.provideSplashScreen();
if (splashScreen != null) {
Log.w(
TAG,
"A splash screen was provided to Flutter, but this is deprecated. See"
+ " flutter.dev/go/android-splash-migration for migration steps.");
FlutterSplashView flutterSplashView = new FlutterSplashView(host.getContext());
flutterSplashView.setId(ViewUtils.generateViewId(FLUTTER_SPLASH_VIEW_FALLBACK_ID));
flutterSplashView.displayFlutterViewWithSplash(flutterView, splashScreen);
return flutterSplashView;
}
if (shouldDelayFirstAndroidViewDraw) {
delayFirstAndroidViewDraw(flutterView);
}
@@ -952,8 +935,7 @@ import java.util.List;
* FlutterActivityAndFragmentDelegate}.
*/
/* package */ interface Host
extends SplashScreenProvider,
FlutterEngineProvider,
extends FlutterEngineProvider,
FlutterEngineConfigurator,
PlatformPlugin.PlatformPluginDelegate {
/**
@@ -1070,9 +1052,6 @@ import java.util.List;
*/
ExclusiveAppComponent<Activity> getExclusiveAppComponent();
@Nullable
SplashScreen provideSplashScreen();
/**
* Returns the {@link io.flutter.embedding.engine.FlutterEngine} that should be rendered to a
* {@link FlutterView}.

View File

@@ -13,8 +13,6 @@ public class FlutterActivityLaunchConfigs {
/* package */ static final String DART_ENTRYPOINT_META_DATA_KEY = "io.flutter.Entrypoint";
/* package */ static final String DART_ENTRYPOINT_URI_META_DATA_KEY = "io.flutter.EntrypointUri";
/* package */ static final String INITIAL_ROUTE_META_DATA_KEY = "io.flutter.InitialRoute";
/* package */ static final String SPLASH_SCREEN_META_DATA_KEY =
"io.flutter.embedding.android.SplashScreenDrawable";
/* package */ static final String NORMAL_THEME_META_DATA_KEY =
"io.flutter.embedding.android.NormalTheme";
/* package */ static final String HANDLE_DEEPLINKING_META_DATA_KEY =

View File

@@ -1447,18 +1447,6 @@ public class FlutterFragment extends Fragment
return TransparencyMode.valueOf(transparencyModeName);
}
@Override
@Nullable
public SplashScreen provideSplashScreen() {
FragmentActivity parentActivity = getActivity();
if (parentActivity instanceof SplashScreenProvider) {
SplashScreenProvider splashScreenProvider = (SplashScreenProvider) parentActivity;
return splashScreenProvider.provideSplashScreen();
}
return null;
}
/**
* Hook for subclasses to return a {@link io.flutter.embedding.engine.FlutterEngine} with whatever
* configuration is desired.

View File

@@ -19,17 +19,14 @@ import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_IN
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.HANDLE_DEEPLINKING_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.INITIAL_ROUTE_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.NORMAL_THEME_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.SPLASH_SCREEN_META_DATA_KEY;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
@@ -40,7 +37,6 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import io.flutter.Log;
@@ -65,7 +61,7 @@ import java.util.List;
// are duplicated for readability purposes. Be sure to replicate any change in this class in
// FlutterActivity, too.
public class FlutterFragmentActivity extends FragmentActivity
implements SplashScreenProvider, FlutterEngineProvider, FlutterEngineConfigurator {
implements FlutterEngineProvider, FlutterEngineConfigurator {
private static final String TAG = "FlutterFragmentActivity";
// FlutterFragment management.
@@ -439,41 +435,6 @@ public class FlutterFragmentActivity extends FragmentActivity
}
}
@Nullable
@Override
public SplashScreen provideSplashScreen() {
Drawable manifestSplashDrawable = getSplashScreenFromManifest();
if (manifestSplashDrawable != null) {
return new DrawableSplashScreen(manifestSplashDrawable);
} else {
return null;
}
}
/**
* Returns a {@link Drawable} to be used as a splash screen as requested by meta-data in the
* {@code AndroidManifest.xml} file, or null if no such splash screen is requested.
*
* <p>See {@link FlutterActivityLaunchConfigs#SPLASH_SCREEN_META_DATA_KEY} for the meta-data key
* to be used in a manifest file.
*/
@Nullable
private Drawable getSplashScreenFromManifest() {
try {
Bundle metaData = getMetaData();
int splashScreenId = metaData != null ? metaData.getInt(SPLASH_SCREEN_META_DATA_KEY) : 0;
return splashScreenId != 0
? ResourcesCompat.getDrawable(getResources(), splashScreenId, getTheme())
: null;
} catch (Resources.NotFoundException e) {
Log.e(TAG, "Splash screen not found. Ensure the drawable exists and that it's valid.");
throw e;
} catch (PackageManager.NameNotFoundException e) {
// This is never expected to happen.
return null;
}
}
/**
* Sets this {@code Activity}'s {@code Window} background to be transparent, and hides the status
* bar, if this {@code Activity}'s desired {@link BackgroundMode} is {@link

View File

@@ -1,295 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.embedding.android;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import io.flutter.Log;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
/**
* {@code View} that displays a {@link SplashScreen} until a given {@link FlutterView} renders its
* first frame.
*/
/* package */ final class FlutterSplashView extends FrameLayout {
private static String TAG = "FlutterSplashView";
@Nullable private SplashScreen splashScreen;
@Nullable private FlutterView flutterView;
@Nullable private View splashScreenView;
@VisibleForTesting @Nullable /* package */ Bundle splashScreenState;
@Nullable private String transitioningIsolateId;
@Nullable private String previousCompletedSplashIsolate;
@NonNull
private final FlutterView.FlutterEngineAttachmentListener flutterEngineAttachmentListener =
new FlutterView.FlutterEngineAttachmentListener() {
@Override
public void onFlutterEngineAttachedToFlutterView(@NonNull FlutterEngine engine) {
flutterView.removeFlutterEngineAttachmentListener(this);
displayFlutterViewWithSplash(flutterView, splashScreen);
}
@Override
public void onFlutterEngineDetachedFromFlutterView() {}
};
@NonNull
private final FlutterUiDisplayListener flutterUiDisplayListener =
new FlutterUiDisplayListener() {
@Override
public void onFlutterUiDisplayed() {
if (splashScreen != null) {
transitionToFlutter();
}
}
@Override
public void onFlutterUiNoLongerDisplayed() {
// no-op
}
};
@NonNull
private final Runnable onTransitionComplete =
new Runnable() {
@Override
public void run() {
removeView(splashScreenView);
previousCompletedSplashIsolate = transitioningIsolateId;
}
};
public FlutterSplashView(@NonNull Context context) {
this(context, null, 0);
}
public FlutterSplashView(@NonNull Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public FlutterSplashView(
@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setSaveEnabled(true);
}
@Nullable
@Override
protected Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
SavedState savedState = new SavedState(superState);
savedState.previousCompletedSplashIsolate = previousCompletedSplashIsolate;
savedState.splashScreenState =
splashScreen != null ? splashScreen.saveSplashScreenState() : null;
return savedState;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
if (!(state instanceof SavedState)) {
super.onRestoreInstanceState(state);
return;
}
SavedState savedState = (SavedState) state;
super.onRestoreInstanceState(savedState.getSuperState());
previousCompletedSplashIsolate = savedState.previousCompletedSplashIsolate;
splashScreenState = savedState.splashScreenState;
}
/**
* Displays the given {@code splashScreen} on top of the given {@code flutterView} until Flutter
* has rendered its first frame, then the {@code splashScreen} is transitioned away.
*
* <p>If no {@code splashScreen} is provided, this {@code FlutterSplashView} displays the given
* {@code flutterView} on its own.
*/
public void displayFlutterViewWithSplash(
@NonNull FlutterView flutterView, @Nullable SplashScreen splashScreen) {
// If we were displaying a previous FlutterView, remove it.
if (this.flutterView != null) {
this.flutterView.removeOnFirstFrameRenderedListener(flutterUiDisplayListener);
removeView(this.flutterView);
}
// If we were displaying a previous splash screen View, remove it.
if (splashScreenView != null) {
removeView(splashScreenView);
}
// Display the new FlutterView.
this.flutterView = flutterView;
addView(flutterView);
this.splashScreen = splashScreen;
// Display the new splash screen, if needed.
if (splashScreen != null) {
if (isSplashScreenNeededNow()) {
Log.v(TAG, "Showing splash screen UI.");
// This is the typical case. A FlutterEngine is attached to the FlutterView and we're
// waiting for the first frame to render. Show a splash UI until that happens.
splashScreenView = splashScreen.createSplashView(getContext(), splashScreenState);
addView(this.splashScreenView);
flutterView.addOnFirstFrameRenderedListener(flutterUiDisplayListener);
} else if (isSplashScreenTransitionNeededNow()) {
Log.v(
TAG,
"Showing an immediate splash transition to Flutter due to previously interrupted transition.");
splashScreenView = splashScreen.createSplashView(getContext(), splashScreenState);
addView(splashScreenView);
transitionToFlutter();
} else if (!flutterView.isAttachedToFlutterEngine()) {
Log.v(
TAG,
"FlutterView is not yet attached to a FlutterEngine. Showing nothing until a FlutterEngine is attached.");
flutterView.addFlutterEngineAttachmentListener(flutterEngineAttachmentListener);
}
}
}
/**
* Returns true if current conditions require a splash UI to be displayed.
*
* <p>This method does not evaluate whether a previously interrupted splash transition needs to
* resume. See {@link #isSplashScreenTransitionNeededNow()} to answer that question.
*/
private boolean isSplashScreenNeededNow() {
return flutterView != null
&& flutterView.isAttachedToFlutterEngine()
&& !flutterView.hasRenderedFirstFrame()
&& !hasSplashCompleted();
}
/**
* Returns true if a previous splash transition was interrupted by recreation, e.g., an
* orientation change, and that previous transition should be resumed.
*
* <p>Not all splash screens are capable of remembering their transition progress. In those cases,
* this method will return false even if a previous visual transition was interrupted.
*/
private boolean isSplashScreenTransitionNeededNow() {
return flutterView != null
&& flutterView.isAttachedToFlutterEngine()
&& splashScreen != null
&& splashScreen.doesSplashViewRememberItsTransition()
&& wasPreviousSplashTransitionInterrupted();
}
/**
* Returns true if a splash screen was transitioning to a Flutter experience and was then
* interrupted, e.g., by an Android configuration change. Returns false otherwise.
*
* <p>Invoking this method expects that a {@code flutterView} exists and it is attached to a
* {@code FlutterEngine}.
*/
private boolean wasPreviousSplashTransitionInterrupted() {
if (flutterView == null) {
throw new IllegalStateException(
"Cannot determine if previous splash transition was "
+ "interrupted when no FlutterView is set.");
}
if (!flutterView.isAttachedToFlutterEngine()) {
throw new IllegalStateException(
"Cannot determine if previous splash transition was "
+ "interrupted when no FlutterEngine is attached to our FlutterView. This question "
+ "depends on an isolate ID to differentiate Flutter experiences.");
}
return flutterView.hasRenderedFirstFrame() && !hasSplashCompleted();
}
/**
* Returns true if a splash UI for a specific Flutter experience has already completed.
*
* <p>A "specific Flutter experience" is defined as any experience with the same Dart isolate ID.
* The purpose of this distinction is to prevent a situation where a user gets past a splash UI,
* rotates the device (or otherwise triggers a recreation) and the splash screen reappears.
*
* <p>An isolate ID is deemed reasonable as a key for a completion event because a Dart isolate
* cannot be entered twice. Therefore, a single Dart isolate cannot return to an "un-rendered"
* state after having previously rendered content.
*/
private boolean hasSplashCompleted() {
if (flutterView == null) {
throw new IllegalStateException(
"Cannot determine if splash has completed when no FlutterView " + "is set.");
}
if (!flutterView.isAttachedToFlutterEngine()) {
throw new IllegalStateException(
"Cannot determine if splash has completed when no "
+ "FlutterEngine is attached to our FlutterView. This question depends on an isolate ID "
+ "to differentiate Flutter experiences.");
}
// A null isolate ID on a non-null FlutterEngine indicates that the Dart isolate has not
// been initialized. Therefore, no frame has been rendered for this engine, which means
// no splash screen could have completed yet.
return flutterView.getAttachedFlutterEngine().getDartExecutor().getIsolateServiceId() != null
&& flutterView
.getAttachedFlutterEngine()
.getDartExecutor()
.getIsolateServiceId()
.equals(previousCompletedSplashIsolate);
}
/**
* Transitions a splash screen to the Flutter UI.
*
* <p>This method requires that our FlutterView be attached to an engine, and that engine have a
* Dart isolate ID. It also requires that a {@code splashScreen} exist.
*/
private void transitionToFlutter() {
transitioningIsolateId =
flutterView.getAttachedFlutterEngine().getDartExecutor().getIsolateServiceId();
Log.v(TAG, "Transitioning splash screen to a Flutter UI. Isolate: " + transitioningIsolateId);
splashScreen.transitionToFlutter(onTransitionComplete);
}
@Keep
public static class SavedState extends BaseSavedState {
public static Creator<SavedState> CREATOR =
new Creator<SavedState>() {
@Override
public SavedState createFromParcel(Parcel source) {
return new SavedState(source);
}
@Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
private String previousCompletedSplashIsolate;
private Bundle splashScreenState;
SavedState(Parcelable superState) {
super(superState);
}
SavedState(Parcel source) {
super(source);
previousCompletedSplashIsolate = source.readString();
splashScreenState = source.readBundle(getClass().getClassLoader());
}
@Override
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeString(previousCompletedSplashIsolate);
out.writeBundle(splashScreenState);
}
}
}

View File

@@ -1,108 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.embedding.android;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* Splash screen configuration for a given Flutter experience.
*
* <p>Implementations provide a visual representation of a splash screen in {@link
* #createSplashView(Context, Bundle)}, and implement a transition from the splash UI to Flutter's
* UI in {@link #transitionToFlutter(Runnable)}.
*
* <p>Please use the new Splash screen API available on Android S. On lower versions of Android,
* it's no longer necessary to display a splash screen to wait for the Flutter first frame.
*
* @deprecated
*/
@Deprecated
public interface SplashScreen {
/**
* Creates a {@code View} to be displayed as a splash screen before Flutter renders its first
* frame.
*
* <p>This method can be called at any time, and may be called multiple times depending on Android
* configuration changes that require recreation of a view hierarchy. Implementers that provide a
* stateful splash view, such as one with animations, should take care to migrate that animation
* state from the previously returned splash view to the newly created splash view.
*
* @param context The current context. e.g. The activity.
* @param savedInstanceState If the activity is being re-initialized after previously being shut
* down then this Bundle contains the data it most recently supplied in {@code
* onSaveInstanceState(Bundle)}.
* @return The splash screen view.
*/
@Nullable
View createSplashView(@NonNull Context context, @Nullable Bundle savedInstanceState);
/**
* Invoked by Flutter when Flutter has rendered its first frame, and would like the {@code
* splashView} to disappear.
*
* <p>The provided {@code onTransitionComplete} callback must be invoked when the splash {@code
* View} has finished transitioning itself away. The splash {@code View} will be removed and
* destroyed when the callback is invoked.
*
* @param onTransitionComplete The callback after the transition has completed.
*/
void transitionToFlutter(@NonNull Runnable onTransitionComplete);
/**
* Returns {@code true} if the splash {@code View} built by this {@code SplashScreen} remembers
* its transition progress across configuration changes by saving that progress to {@code View}
* state. Returns {@code false} otherwise.
*
* <p>The typical return value for this method is {@code false}. When the return value is {@code
* false}, the following can happen:
*
* <ol>
* <li>Splash {@code View} begins transitioning to the Flutter UI.
* <li>A configuration change occurs, like an orientation change, and the {@code Activity} is
* re-created, along with the {@code View} hierarchy.
* <li>The remainder of the splash transition is skipped and the Flutter UI is displayed.
* </ol>
*
* In the vast majority of cases, skipping a little bit of the splash transition should be
* acceptable. Most users will never experience such a situation, and those that do are unlikely
* to notice the visual artifact. However, a workaround is available for those developers who need
* it.
*
* <p>Returning {@code true} from this method will cause the given splash {@code View} to be
* displayed in the {@code View} hierarchy, even if Flutter has already rendered its first frame.
* It is then the responsibility of the splash {@code View} to remember its previous transition
* progress, restart any animations, and then trigger its completion callback when appropriate. It
* is also the responsibility of the splash {@code View} to immediately invoke the completion
* callback if it has already completed its transition. By meeting these requirements, and
* returning {@code true} from this method, the splash screen experience will be completely
* seamless, including configuration changes.
*
* @return True if the given splash {@code View} should be displayed in the {@code View}
* hierarchy.
*/
// We suppress NewApi because the CI linter thinks that "default" methods are unsupported.
@SuppressLint("NewApi")
default boolean doesSplashViewRememberItsTransition() {
return false;
}
/**
* Returns whatever state is necessary to restore a splash {@code View} after destruction and
* recreation, e.g., orientation change.
*
* @return Bundle used to restore a splash screen state.
*/
// We suppress NewApi because the CI linter thinks that "default" methods are unsupported.
@SuppressLint("NewApi")
@Nullable
default Bundle saveSplashScreenState() {
return null;
}
}

View File

@@ -1,28 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.embedding.android;
import androidx.annotation.Nullable;
/**
* Provides a {@link SplashScreen} to display while Flutter initializes and renders its first frame.
*
* <p>Flutter now automatically keeps the Android launch screen displayed until Flutter has drawn
* the first frame, and thus, there is no longer a need to provide an implementation of this
* interface.
*
* @deprecated
*/
@Deprecated
public interface SplashScreenProvider {
/**
* Provides a {@link SplashScreen} to display while Flutter initializes and renders its first
* frame.
*
* @return The splash screen.
*/
@Nullable
SplashScreen provideSplashScreen();
}

View File

@@ -18,8 +18,6 @@ import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.view.View;
import androidx.annotation.NonNull;
@@ -1227,26 +1225,6 @@ public class FlutterActivityAndFragmentDelegateTest {
assertEquals(View.INVISIBLE, surfaceView.getVisibility());
}
@Test
public void itDoesNotDelayTheFirstDrawWhenRequestedAndWithAProvidedSplashScreen() {
when(mockHost.provideSplashScreen())
.thenReturn(new DrawableSplashScreen(new ColorDrawable(Color.GRAY)));
// ---- Test setup ----
// Create the real object that we're testing.
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
// We're testing lifecycle behaviors, which require/expect that certain methods have already
// been executed by the time they run. Therefore, we run those expected methods first.
delegate.onAttach(ctx);
// --- Execute the behavior under test ---
boolean shouldDelayFirstAndroidViewDraw = true;
delegate.onCreateView(null, null, null, 0, shouldDelayFirstAndroidViewDraw);
assertNull(delegate.activePreDrawListener);
}
@Test
public void usesFlutterEngineGroup() {
FlutterEngineGroup mockEngineGroup = mock(FlutterEngineGroup.class);

View File

@@ -14,13 +14,11 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
@@ -432,19 +430,6 @@ public class FlutterActivityTest {
assertEquals(1, registeredEngines.size());
}
@Test
public void itDoesNotCrashWhenSplashScreenMetadataIsNotDefined() {
Intent intent = FlutterActivity.createDefaultIntent(ctx);
ActivityController<FlutterActivity> activityController =
Robolectric.buildActivity(FlutterActivity.class, intent);
FlutterActivity flutterActivity = activityController.get();
// We never supplied the metadata to the robolectric activity info so it doesn't exist.
SplashScreen splashScreen = flutterActivity.provideSplashScreen();
// It should quietly return a null and not crash.
assertNull(splashScreen);
}
@Test
public void itDoesNotReleaseEnginewhenDetachFromFlutterEngine() {
FlutterActivityAndFragmentDelegate mockDelegate =
@@ -499,80 +484,6 @@ public class FlutterActivityTest {
assertFalse(mockDelegate.isAttached());
}
@Test
@Config(
sdk = Build.VERSION_CODES.KITKAT,
shadows = {SplashShadowResources.class})
public void itLoadsSplashScreenDrawable() throws PackageManager.NameNotFoundException {
Intent intent = FlutterActivity.createDefaultIntent(ctx);
ActivityController<FlutterActivity> activityController =
Robolectric.buildActivity(FlutterActivity.class, intent);
FlutterActivity flutterActivity = activityController.get();
// Inject splash screen drawable resource id in the metadata.
PackageManager pm = ctx.getPackageManager();
ActivityInfo activityInfo =
pm.getActivityInfo(flutterActivity.getComponentName(), PackageManager.GET_META_DATA);
activityInfo.metaData = new Bundle();
activityInfo.metaData.putInt(
FlutterActivityLaunchConfigs.SPLASH_SCREEN_META_DATA_KEY,
SplashShadowResources.SPLASH_DRAWABLE_ID);
shadowOf(ctx.getPackageManager()).addOrUpdateActivity(activityInfo);
// It should load the drawable.
SplashScreen splashScreen = flutterActivity.provideSplashScreen();
assertNotNull(splashScreen);
}
@Test
@Config(
sdk = Build.VERSION_CODES.LOLLIPOP,
shadows = {SplashShadowResources.class})
@TargetApi(21) // Theme references in drawables requires API 21+
public void itLoadsThemedSplashScreenDrawable() throws PackageManager.NameNotFoundException {
// A drawable with theme references can be parsed only if the app theme is supplied
// in getDrawable methods. This test verifies it by fetching a (fake) themed drawable.
// On failure, a Resource.NotFoundException will ocurr.
Intent intent = FlutterActivity.createDefaultIntent(ctx);
ActivityController<FlutterActivity> activityController =
Robolectric.buildActivity(FlutterActivity.class, intent);
FlutterActivity flutterActivity = activityController.get();
// Inject themed splash screen drawable resource id in the metadata.
PackageManager pm = ctx.getPackageManager();
ActivityInfo activityInfo =
pm.getActivityInfo(flutterActivity.getComponentName(), PackageManager.GET_META_DATA);
activityInfo.metaData = new Bundle();
activityInfo.metaData.putInt(
FlutterActivityLaunchConfigs.SPLASH_SCREEN_META_DATA_KEY,
SplashShadowResources.THEMED_SPLASH_DRAWABLE_ID);
shadowOf(ctx.getPackageManager()).addOrUpdateActivity(activityInfo);
// It should load the drawable.
SplashScreen splashScreen = flutterActivity.provideSplashScreen();
assertNotNull(splashScreen);
}
@Test
public void itWithMetadataWithoutSplashScreenResourceKeyDoesNotProvideSplashScreen()
throws PackageManager.NameNotFoundException {
Intent intent = FlutterActivity.createDefaultIntent(ctx);
ActivityController<FlutterActivity> activityController =
Robolectric.buildActivity(FlutterActivity.class, intent);
FlutterActivity flutterActivity = activityController.get();
// Setup an empty metadata file.
PackageManager pm = ctx.getPackageManager();
ActivityInfo activityInfo =
pm.getActivityInfo(flutterActivity.getComponentName(), PackageManager.GET_META_DATA);
activityInfo.metaData = new Bundle();
shadowOf(ctx.getPackageManager()).addOrUpdateActivity(activityInfo);
// It should not load the drawable.
SplashScreen splashScreen = flutterActivity.provideSplashScreen();
assertNull(splashScreen);
}
@Test
@Config(minSdk = Build.VERSION_CODES.JELLY_BEAN, maxSdk = Build.VERSION_CODES.P)
public void fullyDrawn_beforeAndroidQ() {

View File

@@ -350,12 +350,6 @@ public class FlutterAndroidComponentTest {
return null;
}
@Nullable
@Override
public SplashScreen provideSplashScreen() {
return null;
}
@Nullable
@Override
public FlutterEngine provideFlutterEngine(@NonNull Context context) {

View File

@@ -4,19 +4,14 @@ import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.HANDLE_D
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
@@ -38,7 +33,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
@Config(manifest = Config.NONE)
@@ -256,93 +250,6 @@ public class FlutterFragmentActivityTest {
assertEquals(0, activity.numberOfEnginesCreated);
}
@Test
public void itDoesNotCrashWhenSplashScreenMetadataIsNotDefined() {
Intent intent = FlutterFragmentActivity.createDefaultIntent(ctx);
ActivityController<FlutterFragmentActivity> activityController =
Robolectric.buildActivity(FlutterFragmentActivity.class, intent);
FlutterFragmentActivity fragmentActivity = activityController.get();
// We never supplied the resource key to robolectric so it doesn't exist.
SplashScreen splashScreen = fragmentActivity.provideSplashScreen();
// It should quietly return a null and not crash.
assertNull(splashScreen);
}
@Test
@Config(
sdk = Build.VERSION_CODES.KITKAT,
shadows = {SplashShadowResources.class})
public void itLoadsSplashScreenDrawable() throws PackageManager.NameNotFoundException {
Intent intent = FlutterFragmentActivity.createDefaultIntent(ctx);
ActivityController<FlutterFragmentActivity> activityController =
Robolectric.buildActivity(FlutterFragmentActivity.class, intent);
FlutterFragmentActivity activity = activityController.get();
// Inject splash screen drawable resource id in the metadata
PackageManager pm = ctx.getPackageManager();
ActivityInfo activityInfo =
pm.getActivityInfo(activity.getComponentName(), PackageManager.GET_META_DATA);
activityInfo.metaData = new Bundle();
activityInfo.metaData.putInt(
FlutterActivityLaunchConfigs.SPLASH_SCREEN_META_DATA_KEY,
SplashShadowResources.SPLASH_DRAWABLE_ID);
shadowOf(ctx.getPackageManager()).addOrUpdateActivity(activityInfo);
// It should load the drawable.
SplashScreen splashScreen = activity.provideSplashScreen();
assertNotNull(splashScreen);
}
@Test
@Config(
sdk = Build.VERSION_CODES.LOLLIPOP,
shadows = {SplashShadowResources.class})
@TargetApi(21) // Theme references in drawables requires API 21+
public void itLoadsThemedSplashScreenDrawable() throws PackageManager.NameNotFoundException {
// A drawable with theme references can be parsed only if the app theme is supplied
// in getDrawable methods. This test verifies it by fetching a (fake) themed drawable.
// On failure, a Resource.NotFoundException will ocurr.
Intent intent = FlutterFragmentActivity.createDefaultIntent(ctx);
ActivityController<FlutterFragmentActivity> activityController =
Robolectric.buildActivity(FlutterFragmentActivity.class, intent);
FlutterFragmentActivity activity = activityController.get();
// Inject themed splash screen drawable resource id in the metadata.
PackageManager pm = ctx.getPackageManager();
ActivityInfo activityInfo =
pm.getActivityInfo(activity.getComponentName(), PackageManager.GET_META_DATA);
activityInfo.metaData = new Bundle();
activityInfo.metaData.putInt(
FlutterActivityLaunchConfigs.SPLASH_SCREEN_META_DATA_KEY,
SplashShadowResources.THEMED_SPLASH_DRAWABLE_ID);
shadowOf(ctx.getPackageManager()).addOrUpdateActivity(activityInfo);
// It should load the drawable.
SplashScreen splashScreen = activity.provideSplashScreen();
assertNotNull(splashScreen);
}
@Test
public void itWithMetadataWithoutSplashScreenResourceKeyDoesNotProvideSplashScreen()
throws PackageManager.NameNotFoundException {
Intent intent = FlutterFragmentActivity.createDefaultIntent(ctx);
ActivityController<FlutterFragmentActivity> activityController =
Robolectric.buildActivity(FlutterFragmentActivity.class, intent);
FlutterFragmentActivity activity = activityController.get();
// Setup an empty metadata file.
PackageManager pm = ctx.getPackageManager();
ActivityInfo activityInfo =
pm.getActivityInfo(activity.getComponentName(), PackageManager.GET_META_DATA);
activityInfo.metaData = new Bundle();
shadowOf(ctx.getPackageManager()).addOrUpdateActivity(activityInfo);
// It should not load the drawable.
SplashScreen splashScreen = activity.provideSplashScreen();
assertNull(splashScreen);
}
static class FlutterFragmentActivityWithProvidedEngine extends FlutterFragmentActivity {
int numberOfEnginesCreated = 0;

View File

@@ -31,15 +31,12 @@
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/RenderMode.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragmentActivity.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/DrawableSplashScreen.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/KeyChannelResponder.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterSplashView.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/KeyEmbedderResponder.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterTextureView.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/MotionEventTracker.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/SplashScreenProvider.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/WindowInfoRepositoryCallbackAdapterWrapper.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/TransparencyMode.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterEngineProvider.java" />
@@ -50,7 +47,6 @@
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/KeyData.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityLaunchConfigs.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/SplashScreen.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterUiDisplayListener.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/engine/renderer/RenderSurface.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java" />