Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ action("robolectric_tests") {
"test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java",
"test/io/flutter/embedding/android/FlutterActivityTest.java",
"test/io/flutter/embedding/android/FlutterFragmentTest.java",
"test/io/flutter/embedding/android/FlutterViewTest.java",
"test/io/flutter/embedding/engine/FlutterEngineCacheTest.java",
"test/io/flutter/embedding/engine/FlutterJNITest.java",
"test/io/flutter/embedding/engine/RenderingComponentTest.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ public void attachToFlutterEngine(
sendLocalesToFlutter(getResources().getConfiguration());
sendViewportMetricsToFlutter();

flutterEngine.getPlatformViewsController().attachToView(this);

// Notify engine attachment listeners of the attachment.
for (FlutterEngineAttachmentListener listener : flutterEngineAttachmentListeners) {
listener.onFlutterEngineAttachedToFlutterView(flutterEngine);
Expand Down Expand Up @@ -668,6 +670,8 @@ public void detachFromFlutterEngine() {
listener.onFlutterEngineDetachedFromFlutterView();
}

flutterEngine.getPlatformViewsController().detachFromView();

// Disconnect the FlutterEngine's PlatformViewsController from the AccessibilityBridge.
flutterEngine.getPlatformViewsController().detachAccessibiltyBridge();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,19 @@ public void onPreEngineRestart() {
* and {@link FlutterLoader#ensureInitializationComplete(Context, String[])}.
*/
public FlutterEngine(@NonNull Context context) {
this(context, FlutterLoader.getInstance());
this(context, FlutterLoader.getInstance(), new FlutterJNI());
}

/* package */ FlutterEngine(@NonNull Context context, @NonNull FlutterLoader flutterLoader) {
/**
* Constructs a new {@code FlutterEngine}. See {@link #FlutterEngine(Context)}.
*
* {@code flutterJNI} should be a new instance that has never been attached to an engine before.
*/
public FlutterEngine(@NonNull Context context, @NonNull FlutterLoader flutterLoader, @NonNull FlutterJNI flutterJNI) {
this.flutterJNI = flutterJNI;
flutterLoader.startInitialization(context);
flutterLoader.ensureInitializationComplete(context, null);

this.flutterJNI = new FlutterJNI();
flutterJNI.addEngineLifecycleListener(engineLifecycleListener);
attachToJni();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static native void nativeInit(

// TODO(mattcarroll): add javadocs
@UiThread
public static native boolean nativeGetIsSoftwareRenderingEnabled();
public native boolean nativeGetIsSoftwareRenderingEnabled();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this meant to be part of this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now.

This seems to indicate that most of these methods shouldn't be static then, right?


@Nullable
// TODO(mattcarroll): add javadocs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private void unregisterTexture(long textureId) {

// TODO(mattcarroll): describe the native behavior that this invokes
public boolean isSoftwareRenderingEnabled() {
return FlutterJNI.nativeGetIsSoftwareRenderingEnabled();
return flutterJNI.nativeGetIsSoftwareRenderingEnabled();
}

// TODO(mattcarroll): describe the native behavior that this invokes
Expand Down
3 changes: 1 addition & 2 deletions shell/platform/android/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import android.view.inputmethod.InputMethodManager;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -162,7 +161,7 @@ public FlutterView(Context context, AttributeSet attrs, FlutterNativeView native

dartExecutor = mNativeView.getDartExecutor();
flutterRenderer = new FlutterRenderer(mNativeView.getFlutterJNI());
mIsSoftwareRenderingEnabled = FlutterJNI.nativeGetIsSoftwareRenderingEnabled();
mIsSoftwareRenderingEnabled = mNativeView.getFlutterJNI().nativeGetIsSoftwareRenderingEnabled();
mMetrics = new ViewportMetrics();
mMetrics.devicePixelRatio = context.getResources().getDisplayMetrics().density;
setFocusable(true);
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/android/test/io/flutter/FlutterTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import io.flutter.embedding.android.FlutterActivityTest;
import io.flutter.embedding.android.FlutterFragmentTest;
import io.flutter.embedding.android.FlutterViewTest;
import io.flutter.embedding.engine.FlutterEngineCacheTest;
import io.flutter.embedding.engine.FlutterJNITest;
import io.flutter.embedding.engine.RenderingComponentTest;
Expand All @@ -28,6 +29,7 @@
FlutterFragmentTest.class,
FlutterJNITest.class,
FlutterRendererTest.class,
FlutterViewTest.class,
PlatformChannelTest.class,
PreconditionsTest.class,
RenderingComponentTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.flutter.embedding.android;

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 io.flutter.embedding.engine.FlutterJNI;
import io.flutter.embedding.engine.loader.FlutterLoader;
import io.flutter.plugin.platform.PlatformViewsController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import io.flutter.embedding.engine.FlutterEngine;

@Config(manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class FlutterViewTest {
@Mock FlutterJNI mockFlutterJni;
@Mock FlutterLoader mockFlutterLoader;
@Spy PlatformViewsController platformViewsController;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mockFlutterJni.isAttached()).thenReturn(true);
}

@Test
public void attachToFlutterEngine_alertsPlatformViews() {
FlutterView flutterView = new FlutterView(RuntimeEnvironment.application);
FlutterEngine flutterEngine = spy(new FlutterEngine(RuntimeEnvironment.application, mockFlutterLoader, mockFlutterJni));
when(flutterEngine.getPlatformViewsController()).thenReturn(platformViewsController);

flutterView.attachToFlutterEngine(flutterEngine);

verify(platformViewsController, times(1)).attachToView(flutterView);
}

@Test
public void detachFromFlutterEngine_alertsPlatformViews() {
FlutterView flutterView = new FlutterView(RuntimeEnvironment.application);
FlutterEngine flutterEngine = spy(new FlutterEngine(RuntimeEnvironment.application, mockFlutterLoader, mockFlutterJni));
when(flutterEngine.getPlatformViewsController()).thenReturn(platformViewsController);

flutterView.attachToFlutterEngine(flutterEngine);
flutterView.detachFromFlutterEngine();

verify(platformViewsController, times(1)).detachFromView();
}
}