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 io.flutter.Log; import io.flutter.embedding.android.FlutterView; import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener; /* loaded from: classes5.dex */ final class FlutterSplashView extends FrameLayout { private static String TAG = "FlutterSplashView"; private final FlutterView.FlutterEngineAttachmentListener flutterEngineAttachmentListener; private final FlutterUiDisplayListener flutterUiDisplayListener; private FlutterView flutterView; private final Runnable onTransitionComplete; private String previousCompletedSplashIsolate; private SplashScreen splashScreen; Bundle splashScreenState; private View splashScreenView; private String transitioningIsolateId; public FlutterSplashView(Context context) { this(context, null, 0); } public FlutterSplashView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0); } public FlutterSplashView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); this.flutterEngineAttachmentListener = new FlutterView.FlutterEngineAttachmentListener(this) { // from class: io.flutter.embedding.android.FlutterSplashView.1 final FlutterSplashView this$0; @Override // io.flutter.embedding.android.FlutterView.FlutterEngineAttachmentListener public void onFlutterEngineDetachedFromFlutterView() { } { this.this$0 = this; } @Override // io.flutter.embedding.android.FlutterView.FlutterEngineAttachmentListener public void onFlutterEngineAttachedToFlutterView(FlutterEngine flutterEngine) { this.this$0.flutterView.removeFlutterEngineAttachmentListener(this); FlutterSplashView flutterSplashView = this.this$0; flutterSplashView.displayFlutterViewWithSplash(flutterSplashView.flutterView, this.this$0.splashScreen); } }; this.flutterUiDisplayListener = new FlutterUiDisplayListener(this) { // from class: io.flutter.embedding.android.FlutterSplashView.2 final FlutterSplashView this$0; @Override // io.flutter.embedding.engine.renderer.FlutterUiDisplayListener public void onFlutterUiNoLongerDisplayed() { } { this.this$0 = this; } @Override // io.flutter.embedding.engine.renderer.FlutterUiDisplayListener public void onFlutterUiDisplayed() { if (this.this$0.splashScreen != null) { this.this$0.transitionToFlutter(); } } }; this.onTransitionComplete = new Runnable(this) { // from class: io.flutter.embedding.android.FlutterSplashView.3 final FlutterSplashView this$0; { this.this$0 = this; } @Override // java.lang.Runnable public void run() { FlutterSplashView flutterSplashView = this.this$0; flutterSplashView.removeView(flutterSplashView.splashScreenView); FlutterSplashView flutterSplashView2 = this.this$0; flutterSplashView2.previousCompletedSplashIsolate = flutterSplashView2.transitioningIsolateId; } }; setSaveEnabled(true); } @Override // android.view.View protected final Parcelable onSaveInstanceState() { SavedState savedState = new SavedState(super.onSaveInstanceState()); savedState.previousCompletedSplashIsolate = this.previousCompletedSplashIsolate; SplashScreen splashScreen = this.splashScreen; savedState.splashScreenState = splashScreen != null ? splashScreen.saveSplashScreenState() : null; return savedState; } @Override // android.view.View protected final void onRestoreInstanceState(Parcelable parcelable) { if (!(parcelable instanceof SavedState)) { super.onRestoreInstanceState(parcelable); return; } SavedState savedState = (SavedState) parcelable; super.onRestoreInstanceState(savedState.getSuperState()); this.previousCompletedSplashIsolate = savedState.previousCompletedSplashIsolate; this.splashScreenState = savedState.splashScreenState; } public final void displayFlutterViewWithSplash(FlutterView flutterView, SplashScreen splashScreen) { FlutterView flutterView2 = this.flutterView; if (flutterView2 != null) { flutterView2.removeOnFirstFrameRenderedListener(this.flutterUiDisplayListener); removeView(this.flutterView); } View view = this.splashScreenView; if (view != null) { removeView(view); } this.flutterView = flutterView; addView(flutterView); this.splashScreen = splashScreen; if (splashScreen != null) { if (isSplashScreenNeededNow()) { Log.v(TAG, "Showing splash screen UI."); View createSplashView = splashScreen.createSplashView(getContext(), this.splashScreenState); this.splashScreenView = createSplashView; addView(createSplashView); flutterView.addOnFirstFrameRenderedListener(this.flutterUiDisplayListener); return; } if (isSplashScreenTransitionNeededNow()) { Log.v(TAG, "Showing an immediate splash transition to Flutter due to previously interrupted transition."); View createSplashView2 = splashScreen.createSplashView(getContext(), this.splashScreenState); this.splashScreenView = createSplashView2; addView(createSplashView2); transitionToFlutter(); return; } if (flutterView.isAttachedToFlutterEngine()) { return; } Log.v(TAG, "FlutterView is not yet attached to a FlutterEngine. Showing nothing until a FlutterEngine is attached."); flutterView.addFlutterEngineAttachmentListener(this.flutterEngineAttachmentListener); } } private boolean isSplashScreenNeededNow() { FlutterView flutterView = this.flutterView; return (flutterView == null || !flutterView.isAttachedToFlutterEngine() || this.flutterView.hasRenderedFirstFrame() || hasSplashCompleted()) ? false : true; } private boolean isSplashScreenTransitionNeededNow() { SplashScreen splashScreen; FlutterView flutterView = this.flutterView; return flutterView != null && flutterView.isAttachedToFlutterEngine() && (splashScreen = this.splashScreen) != null && splashScreen.doesSplashViewRememberItsTransition() && wasPreviousSplashTransitionInterrupted(); } private boolean wasPreviousSplashTransitionInterrupted() { FlutterView flutterView = this.flutterView; if (flutterView == null) { throw new IllegalStateException("Cannot determine if previous splash transition was interrupted when no FlutterView is set."); } if (flutterView.isAttachedToFlutterEngine()) { return this.flutterView.hasRenderedFirstFrame() && !hasSplashCompleted(); } 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."); } private boolean hasSplashCompleted() { FlutterView flutterView = this.flutterView; if (flutterView == null) { throw new IllegalStateException("Cannot determine if splash has completed when no FlutterView is set."); } if (flutterView.isAttachedToFlutterEngine()) { return this.flutterView.getAttachedFlutterEngine().getDartExecutor().getIsolateServiceId() != null && this.flutterView.getAttachedFlutterEngine().getDartExecutor().getIsolateServiceId().equals(this.previousCompletedSplashIsolate); } 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."); } /* JADX INFO: Access modifiers changed from: private */ public void transitionToFlutter() { this.transitioningIsolateId = this.flutterView.getAttachedFlutterEngine().getDartExecutor().getIsolateServiceId(); Log.v(TAG, "Transitioning splash screen to a Flutter UI. Isolate: " + this.transitioningIsolateId); this.splashScreen.transitionToFlutter(this.onTransitionComplete); } /* loaded from: classes5.dex */ public static class SavedState extends View.BaseSavedState { public static Parcelable.Creator CREATOR = new Parcelable.Creator() { // from class: io.flutter.embedding.android.FlutterSplashView.SavedState.1 /* JADX WARN: Can't rename method to resolve collision */ @Override // android.os.Parcelable.Creator public SavedState createFromParcel(Parcel parcel) { return new SavedState(parcel); } /* JADX WARN: Can't rename method to resolve collision */ @Override // android.os.Parcelable.Creator public SavedState[] newArray(int i) { return new SavedState[i]; } }; private String previousCompletedSplashIsolate; private Bundle splashScreenState; SavedState(Parcelable parcelable) { super(parcelable); } SavedState(Parcel parcel) { super(parcel); this.previousCompletedSplashIsolate = parcel.readString(); this.splashScreenState = parcel.readBundle(getClass().getClassLoader()); } @Override // android.view.View.BaseSavedState, android.view.AbsSavedState, android.os.Parcelable public void writeToParcel(Parcel parcel, int i) { super.writeToParcel(parcel, i); parcel.writeString(this.previousCompletedSplashIsolate); parcel.writeBundle(this.splashScreenState); } } }