Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] Add HC++ platform view controller. #56776

Closed
wants to merge 10 commits into from
Closed
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
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -44357,6 +44357,7 @@ ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/syst
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/NavigationChannel.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel2.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/ProcessTextChannel.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/RestorationChannel.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/ScribeChannel.java + ../../../flutter/LICENSE
Expand Down Expand Up @@ -44400,6 +44401,7 @@ ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platf
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewFakeWindowViewGroup.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewWindowManager.java + ../../../flutter/LICENSE
Expand Down Expand Up @@ -47296,6 +47298,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/system
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/NavigationChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel2.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/ProcessTextChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/RestorationChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/ScribeChannel.java
Expand Down Expand Up @@ -47343,6 +47346,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platfor
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewFakeWindowViewGroup.java
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewWindowManager.java
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ android_java_sources = [
"io/flutter/embedding/engine/systemchannels/NavigationChannel.java",
"io/flutter/embedding/engine/systemchannels/PlatformChannel.java",
"io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java",
"io/flutter/embedding/engine/systemchannels/PlatformViewsChannel2.java",
"io/flutter/embedding/engine/systemchannels/ProcessTextChannel.java",
"io/flutter/embedding/engine/systemchannels/RestorationChannel.java",
"io/flutter/embedding/engine/systemchannels/ScribeChannel.java",
Expand Down Expand Up @@ -330,6 +331,7 @@ android_java_sources = [
"io/flutter/plugin/platform/PlatformViewWrapper.java",
"io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java",
"io/flutter/plugin/platform/PlatformViewsController.java",
"io/flutter/plugin/platform/PlatformViewsController2.java",
"io/flutter/plugin/platform/SingleViewFakeWindowViewGroup.java",
"io/flutter/plugin/platform/SingleViewPresentation.java",
"io/flutter/plugin/platform/SingleViewWindowManager.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,8 @@ public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) {
this,
this.flutterEngine.getTextInputChannel(),
this.flutterEngine.getScribeChannel(),
this.flutterEngine.getPlatformViewsController());
this.flutterEngine.getPlatformViewsController(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to your change- would probably be simpler to just pass flutterEngine into this call?

this.flutterEngine.getPlatformViewsController2());

try {
textServicesManager =
Expand Down Expand Up @@ -1168,6 +1169,10 @@ public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) {
this.flutterEngine
.getPlatformViewsController()
.attachToFlutterRenderer(this.flutterEngine.getRenderer());
this.flutterEngine.getPlatformViewsController2().attachAccessibilityBridge(accessibilityBridge);
this.flutterEngine
.getPlatformViewsController2()
.attachToFlutterRenderer(this.flutterEngine.getRenderer());

// Inform the Android framework that it should retrieve a new InputConnection
// now that an engine is attached.
Expand All @@ -1186,6 +1191,7 @@ public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) {
sendViewportMetricsToFlutter();

flutterEngine.getPlatformViewsController().attachToView(this);
flutterEngine.getPlatformViewsController2().attachToView(this);

// Notify engine attachment listeners of the attachment.
for (FlutterEngineAttachmentListener listener : flutterEngineAttachmentListeners) {
Expand Down Expand Up @@ -1226,9 +1232,11 @@ public void detachFromFlutterEngine() {
getContext().getContentResolver().unregisterContentObserver(systemSettingsObserver);

flutterEngine.getPlatformViewsController().detachFromView();
flutterEngine.getPlatformViewsController2().detachFromView();

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

// Disconnect and clean up the AccessibilityBridge.
accessibilityBridge.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.flutter.embedding.engine.systemchannels.TextInputChannel;
import io.flutter.plugin.localization.LocalizationPlugin;
import io.flutter.plugin.platform.PlatformViewsController;
import io.flutter.plugin.platform.PlatformViewsController2;
import io.flutter.plugin.text.ProcessTextPlugin;
import io.flutter.util.ViewUtils;
import java.util.HashSet;
Expand Down Expand Up @@ -109,6 +110,7 @@ public class FlutterEngine implements ViewUtils.DisplayUpdater {

// Platform Views.
@NonNull private final PlatformViewsController platformViewsController;
@NonNull private final PlatformViewsController2 platformViewsController2;

// Engine Lifecycle.
@NonNull private final Set<EngineLifecycleListener> engineLifecycleListeners = new HashSet<>();
Expand All @@ -124,6 +126,7 @@ public void onPreEngineRestart() {
}

platformViewsController.onPreEngineRestart();
platformViewsController2.onPreEngineRestart();
restorationChannel.clearData();
}

Expand Down Expand Up @@ -359,9 +362,11 @@ public FlutterEngine(
flutterLoader.startInitialization(context.getApplicationContext());
flutterLoader.ensureInitializationComplete(context, dartVmArgs);
}
PlatformViewsController2 platformViewsController2 = new PlatformViewsController2();

flutterJNI.addEngineLifecycleListener(engineLifecycleListener);
flutterJNI.setPlatformViewsController(platformViewsController);
flutterJNI.setPlatformViewsController2(platformViewsController2);
flutterJNI.setLocalizationPlugin(localizationPlugin);
flutterJNI.setDeferredComponentManager(injector.deferredComponentManager());

Expand All @@ -379,6 +384,8 @@ public FlutterEngine(
this.platformViewsController = platformViewsController;
this.platformViewsController.onAttachedToJNI();

this.platformViewsController2 = platformViewsController2;

this.pluginRegistry =
new FlutterEngineConnectionRegistry(
context.getApplicationContext(), this, flutterLoader, group);
Expand Down Expand Up @@ -472,6 +479,7 @@ public void destroy() {
// The order that these things are destroyed is important.
pluginRegistry.destroy();
platformViewsController.onDetachedFromJNI();
platformViewsController2.onDetachedFromJNI();
dartExecutor.onDetachedFromJNI();
flutterJNI.removeEngineLifecycleListener(engineLifecycleListener);
flutterJNI.setDeferredComponentManager(null);
Expand Down Expand Up @@ -648,6 +656,11 @@ public PlatformViewsController getPlatformViewsController() {
return platformViewsController;
}

@NonNull
public PlatformViewsController2 getPlatformViewsController2() {
return platformViewsController2;
}

@NonNull
public ActivityControlSurface getActivityControlSurface() {
return pluginRegistry;
Expand Down
79 changes: 79 additions & 0 deletions shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.util.Size;
import android.util.TypedValue;
import android.view.Surface;
import android.view.SurfaceControl;
import android.view.SurfaceHolder;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
Expand All @@ -36,6 +37,7 @@
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.localization.LocalizationPlugin;
import io.flutter.plugin.platform.PlatformViewsController;
import io.flutter.plugin.platform.PlatformViewsController2;
import io.flutter.util.Preconditions;
import io.flutter.view.AccessibilityBridge;
import io.flutter.view.FlutterCallbackInformation;
Expand Down Expand Up @@ -388,6 +390,7 @@ public boolean isCodePointRegionalIndicator(int codePoint) {
@Nullable private PlatformMessageHandler platformMessageHandler;
@Nullable private LocalizationPlugin localizationPlugin;
@Nullable private PlatformViewsController platformViewsController;
@Nullable private PlatformViewsController2 platformViewsController2;

@Nullable private DeferredComponentManager deferredComponentManager;

Expand Down Expand Up @@ -765,6 +768,13 @@ public void setPlatformViewsController(@NonNull PlatformViewsController platform
this.platformViewsController = platformViewsController;
}

@UiThread
public void setPlatformViewsController2(
@NonNull PlatformViewsController2 platformViewsController2) {
ensureRunningOnMainThread();
this.platformViewsController2 = platformViewsController2;
}

// ------ Start Accessibility Support -----
/**
* Sets the {@link AccessibilityDelegate} for the attached Flutter context.
Expand Down Expand Up @@ -1272,6 +1282,75 @@ public void destroyOverlaySurfaces() {
}
platformViewsController.destroyOverlaySurfaces();
}
// ----- New Platform Views ----------

@SuppressWarnings("unused")
@UiThread
public SurfaceControl.Transaction createTransaction() {
if (platformViewsController2 == null) {
throw new RuntimeException("");
}
return platformViewsController2.createTransaction();
}

@SuppressWarnings("unused")
@UiThread
public void swapTransactions() {
if (platformViewsController2 == null) {
throw new RuntimeException("");
}
platformViewsController2.swapTransactions();
}

@SuppressWarnings("unused")
@UiThread
public void applyTransactions() {
if (platformViewsController2 == null) {
throw new RuntimeException("");
}
platformViewsController2.applyTransactions();
}

@SuppressWarnings("unused")
@UiThread
public FlutterOverlaySurface createOverlaySurface2() {
if (platformViewsController2 == null) {
throw new RuntimeException(
"platformViewsController must be set before attempting to position an overlay surface");
}
return platformViewsController2.createOverlaySurface();
}

@SuppressWarnings("unused")
@UiThread
public void destroyOverlaySurface2() {
ensureRunningOnMainThread();
if (platformViewsController2 == null) {
throw new RuntimeException(
"platformViewsController must be set before attempting to destroy an overlay surface");
}
platformViewsController2.destroyOverlaySurface();
}

@UiThread
public void onDisplayPlatformView2(
int viewId,
int x,
int y,
int width,
int height,
int viewWidth,
int viewHeight,
FlutterMutatorsStack mutatorsStack) {
ensureRunningOnMainThread();
if (platformViewsController2 == null) {
throw new RuntimeException(
"platformViewsController must be set before attempting to position a platform view");
}
platformViewsController2.onDisplayPlatformView(
viewId, x, y, width, height, viewWidth, viewHeight, mutatorsStack);
}

// ----- End Engine Lifecycle Support ----

// ----- Start Localization Support ----
Expand Down
Loading
Loading