diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 6196b918d3..55a5f63693 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -516,6 +516,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platfor FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewFactory.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistry.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistryImpl.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/SingleViewPresentation.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java diff --git a/engine/src/flutter/shell/platform/android/BUILD.gn b/engine/src/flutter/shell/platform/android/BUILD.gn index 9ff065b3ab..bb5b74c05e 100644 --- a/engine/src/flutter/shell/platform/android/BUILD.gn +++ b/engine/src/flutter/shell/platform/android/BUILD.gn @@ -158,6 +158,7 @@ java_library("flutter_shell_java") { "io/flutter/plugin/platform/PlatformViewFactory.java", "io/flutter/plugin/platform/PlatformViewRegistry.java", "io/flutter/plugin/platform/PlatformViewRegistryImpl.java", + "io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java", "io/flutter/plugin/platform/PlatformViewsController.java", "io/flutter/plugin/platform/SingleViewPresentation.java", "io/flutter/plugin/platform/VirtualDisplayController.java", diff --git a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java index 7710a60898..13297ae592 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java @@ -94,6 +94,10 @@ public class FlutterPluginRegistry mPlatformViewsController.onPreEngineRestart(); } + public PlatformViewsController getPlatformViewsController() { + return mPlatformViewsController; + } + private class FlutterRegistrar implements Registrar { private final String pluginKey; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/android/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/android/FlutterView.java index e8216f97b3..3c104b32c6 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/android/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/android/FlutterView.java @@ -447,7 +447,10 @@ public class FlutterView extends FrameLayout { this, flutterEngine.getAccessibilityChannel(), (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE), - getContext().getContentResolver() + getContext().getContentResolver(), + // TODO(mattcaroll): plumb the platform views controller to the accessibility bridge. + // https://github.com/flutter/flutter/issues/29618 + null ); accessibilityBridge.setOnAccessibilityChangeListener(onAccessibilityChangeListener); resetWillNotDraw( diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java new file mode 100644 index 0000000000..8f07f6b0c5 --- /dev/null +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java @@ -0,0 +1,13 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugin.platform; + +/** + * Facilitates interaction between the accessibility bridge and embedded platform views. + */ +public interface PlatformViewsAccessibilityDelegate { + // TODO(amirh): add a View getViewById(int id) here. + // not filing a tracking issue as this is going to be done in the next PR. +} diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index e7297567e1..bd2ba001e2 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -14,6 +14,7 @@ import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.StandardMethodCodec; +import io.flutter.view.AccessibilityBridge; import io.flutter.view.TextureRegistry; import java.nio.ByteBuffer; @@ -31,7 +32,7 @@ import static android.view.MotionEvent.PointerProperties; * Each {@link io.flutter.app.FlutterPluginRegistry} has a single platform views controller. * A platform views controller can be attached to at most one Flutter view. */ -public class PlatformViewsController implements MethodChannel.MethodCallHandler { +public class PlatformViewsController implements MethodChannel.MethodCallHandler, PlatformViewsAccessibilityDelegate { private static final String TAG = "PlatformViewsController"; private static final String CHANNEL_NAME = "flutter/platform_views"; @@ -50,6 +51,9 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler // The messenger used to communicate with the framework over the platform views channel. private BinaryMessenger mMessenger; + // The accessibility bridge to which accessibility events form the platform views will be dispatched. + private AccessibilityBridge accessibilityBridge; + private final HashMap vdControllers; public PlatformViewsController() { @@ -94,6 +98,25 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler mTextureRegistry = null; } + /** + * Attaches an accessibility bridge for this platform views controller. + * + * Accessibility events sent by platform views that belonging to this controller will be + * dispatched to this accessibility bridge. + */ + public void attachAccessibilityBridge(AccessibilityBridge accessibilityBridge) { + this.accessibilityBridge = accessibilityBridge; + } + + /** + * Detaches the current accessibility bridge. + * + * Any accessibility events sent by platform views belonging to this controller will be ignored. + */ + public void detachAccessibiltyBridge() { + this.accessibilityBridge = null; + } + public PlatformViewRegistry getRegistry() { return mRegistry; } @@ -106,6 +129,17 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler flushAllViews(); } + /** + * Returns the embedded view with id, or null if no view with this id is registered. + */ + public View getPlatformViewById(Integer id) { + VirtualDisplayController controller = vdControllers.get(id); + if (controller == null) { + return null; + } + return controller.getView(); + } + @Override public void onMethodCall(final MethodCall call, final MethodChannel.Result result) { if (Build.VERSION.SDK_INT < MINIMAL_SDK) { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java index b0f8e92888..f18616b157 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -15,7 +15,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.provider.Settings; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; @@ -27,8 +26,8 @@ import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeProvider; -import io.flutter.embedding.engine.FlutterJNI; import io.flutter.embedding.engine.systemchannels.AccessibilityChannel; +import io.flutter.plugin.platform.PlatformViewsAccessibilityDelegate; import io.flutter.util.Predicate; import java.nio.ByteBuffer; @@ -90,6 +89,11 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { @NonNull private final AccessibilityManager accessibilityManager; + // The delegate for interacting with embedded platform views. Used to embed accessibility data for an embedded + // view in the accessibility tree. + @NonNull + private final PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate; + // Android's {@link ContentResolver}, which is used to observe the global TRANSITION_ANIMATION_SCALE, // which determines whether Flutter's animations should be enabled or disabled for accessibility // purposes. @@ -307,12 +311,14 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { @NonNull View rootAccessibilityView, @NonNull AccessibilityChannel accessibilityChannel, @NonNull AccessibilityManager accessibilityManager, - @NonNull ContentResolver contentResolver + @NonNull ContentResolver contentResolver, + @NonNull PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate ) { this.rootAccessibilityView = rootAccessibilityView; this.accessibilityChannel = accessibilityChannel; this.accessibilityManager = accessibilityManager; this.contentResolver = contentResolver; + this.platformViewsAccessibilityDelegate = platformViewsAccessibilityDelegate; decorView = ((Activity) rootAccessibilityView.getContext()).getWindow().getDecorView(); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index 0ef972ebdc..0935ab6af2 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -43,6 +43,7 @@ import io.flutter.embedding.engine.systemchannels.SystemChannel; import io.flutter.plugin.common.*; import io.flutter.plugin.editing.TextInputPlugin; import io.flutter.plugin.platform.PlatformPlugin; +import io.flutter.plugin.platform.PlatformViewsController; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -660,12 +661,15 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture protected void onAttachedToWindow() { super.onAttachedToWindow(); + PlatformViewsController platformViewsController = getPluginRegistry().getPlatformViewsController(); mAccessibilityNodeProvider = new AccessibilityBridge( this, new AccessibilityChannel(dartExecutor, getFlutterNativeView().getFlutterJNI()), (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE), - getContext().getContentResolver() + getContext().getContentResolver(), + platformViewsController ); + platformViewsController.attachAccessibilityBridge(mAccessibilityNodeProvider); mAccessibilityNodeProvider.setOnAccessibilityChangeListener(onAccessibilityChangeListener); resetWillNotDraw( @@ -678,6 +682,7 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture protected void onDetachedFromWindow() { super.onDetachedFromWindow(); + getPluginRegistry().getPlatformViewsController().detachAccessibiltyBridge(); mAccessibilityNodeProvider.release(); mAccessibilityNodeProvider = null; }