Make sure 'FlutterSplashView.onRestoreInstanceState' doesn't crash (flutter/engine#31045)
* Make sure 'FlutterSplashView.onRestoreInstanceState' doesn't crash * Add the unit test
This commit is contained in:
@@ -14,6 +14,7 @@ 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;
|
||||
@@ -28,7 +29,7 @@ import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
|
||||
@Nullable private SplashScreen splashScreen;
|
||||
@Nullable private FlutterView flutterView;
|
||||
@Nullable private View splashScreenView;
|
||||
@Nullable private Bundle splashScreenState;
|
||||
@VisibleForTesting @Nullable /* package */ Bundle splashScreenState;
|
||||
@Nullable private String transitioningIsolateId;
|
||||
@Nullable private String previousCompletedSplashIsolate;
|
||||
|
||||
@@ -99,6 +100,10 @@ import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
|
||||
|
||||
@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;
|
||||
|
||||
@@ -955,6 +955,14 @@ public class FlutterViewTest {
|
||||
assertEquals(null, flutterView.findViewByAccessibilityIdTraversal(accessibilityViewId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flutterSplashView_itDoesNotCrashOnRestoreInstanceState() {
|
||||
final FlutterSplashView splashView = new FlutterSplashView(RuntimeEnvironment.application);
|
||||
splashView.onRestoreInstanceState(View.BaseSavedState.EMPTY_STATE);
|
||||
// It should not crash and "splashScreenState" should be null.
|
||||
assertEquals(null, splashView.splashScreenState);
|
||||
}
|
||||
|
||||
public void ViewportMetrics_initializedPhysicalTouchSlop() {
|
||||
FlutterView flutterView = new FlutterView(RuntimeEnvironment.application);
|
||||
FlutterEngine flutterEngine =
|
||||
|
||||
Reference in New Issue
Block a user