From 0bf2a8c4606cee86c732b36c71972e315b0fbfe6 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Tue, 13 Jul 2021 20:35:14 -0700 Subject: [PATCH] Revert "Make FlutterFragment usable without requiring it to be attached to an Android Activity. (#27332)" (flutter/engine#27382) This reverts commit ba49de983781dd2267d50780b696e981f74fd84d. --- .../FlutterActivityAndFragmentDelegate.java | 8 ++++---- ...FlutterActivityAndFragmentDelegateTest.java | 18 ++++-------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java index 0f398ef0fe..18dd0cddb2 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java @@ -276,15 +276,15 @@ import java.util.Arrays; if (host.getRenderMode() == RenderMode.surface) { FlutterSurfaceView flutterSurfaceView = new FlutterSurfaceView( - host.getContext(), host.getTransparencyMode() == TransparencyMode.transparent); + host.getActivity(), host.getTransparencyMode() == TransparencyMode.transparent); // Allow our host to customize FlutterSurfaceView, if desired. host.onFlutterSurfaceViewCreated(flutterSurfaceView); // Create the FlutterView that owns the FlutterSurfaceView. - flutterView = new FlutterView(host.getContext(), flutterSurfaceView); + flutterView = new FlutterView(host.getActivity(), flutterSurfaceView); } else { - FlutterTextureView flutterTextureView = new FlutterTextureView(host.getContext()); + FlutterTextureView flutterTextureView = new FlutterTextureView(host.getActivity()); flutterTextureView.setOpaque(host.getTransparencyMode() == TransparencyMode.opaque); @@ -292,7 +292,7 @@ import java.util.Arrays; host.onFlutterTextureViewCreated(flutterTextureView); // Create the FlutterView that owns the FlutterTextureView. - flutterView = new FlutterView(host.getContext(), flutterTextureView); + flutterView = new FlutterView(host.getActivity(), flutterTextureView); } // Add listener to be notified when Flutter renders its first frame. diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index 9b6f7877af..ddad953b64 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -378,9 +378,6 @@ public class FlutterActivityAndFragmentDelegateTest { // Declare that the host does NOT want Flutter to attach to the surrounding Activity. when(mockHost.shouldAttachEngineToActivity()).thenReturn(false); - // getActivity() returns null if the activity is not attached - when(mockHost.getActivity()).thenReturn(null); - // Create the real object that we're testing. FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost); @@ -388,21 +385,14 @@ public class FlutterActivityAndFragmentDelegateTest { // Flutter is attached to the surrounding Activity in onAttach. delegate.onAttach(RuntimeEnvironment.application); - // Make sure all of the other lifecycle methods can run safely as well - // without a valid Activity - delegate.onCreateView(null, null, null); - delegate.onStart(); - delegate.onResume(); - delegate.onPause(); - delegate.onStop(); - delegate.onDestroyView(); + // Verify that the ActivityControlSurface was NOT told to attach to an Activity. + verify(mockFlutterEngine.getActivityControlSurface(), never()) + .attachToActivity(any(Activity.class), any(Lifecycle.class)); // Flutter is detached from the surrounding Activity in onDetach. delegate.onDetach(); - // Verify that the ActivityControlSurface was NOT told to attach or detach to an Activity. - verify(mockFlutterEngine.getActivityControlSurface(), never()) - .attachToActivity(any(Activity.class), any(Lifecycle.class)); + // Verify that the ActivityControlSurface was NOT told to detach from the Activity. verify(mockFlutterEngine.getActivityControlSurface(), never()).detachFromActivity(); }