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
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ public void detachFromFlutterEngine() {
flutterEngine.getPlatformViewsController().detachFromView();

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

Choose a reason for hiding this comment

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

wow. Really good catch!


// Disconnect and clean up the AccessibilityBridge.
accessibilityBridge.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ default void onFlutterViewDetached() {}
*/
// Default interface methods are supported on all min SDK versions of Android.
@SuppressLint("NewApi")
default void onInputConnectionLocked() {};
default void onInputConnectionLocked() {}

/**
* Callback fired when the platform input connection has been unlocked. See also {@link
Expand All @@ -79,5 +79,5 @@ default void onFlutterViewDetached() {}
*/
// Default interface methods are supported on all min SDK versions of Android.
@SuppressLint("NewApi")
default void onInputConnectionUnlocked() {};
default void onInputConnectionUnlocked() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public interface PlatformViewsAccessibilityDelegate {
* <p>Any accessibility events sent by platform views belonging to this delegate will be ignored
* until a new accessibility bridge is attached.
*/
void detachAccessibiltyBridge();
void detachAccessibilityBridge();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
/**
* Manages platform views.
*
* <p>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.
* <p>Each {@link io.flutter.embedding.engine.FlutterEngine} or {@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 PlatformViewsAccessibilityDelegate {
private static final String TAG = "PlatformViewsController";
Expand All @@ -55,8 +56,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
private Context context;

// The View currently rendering the Flutter UI associated with these platform views.
// TODO(egarciad): Investigate if this can be downcasted to `FlutterView`.
private View flutterView;
private FlutterView flutterView;

// The texture registry maintaining the textures into which the embedded views will be rendered.
@Nullable private TextureRegistry textureRegistry;
Expand Down Expand Up @@ -111,10 +111,10 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
private boolean synchronizeToNativeViewHierarchy = true;

// Overlay layer IDs that were displayed since the start of the current frame.
private HashSet<Integer> currentFrameUsedOverlayLayerIds;
private final HashSet<Integer> currentFrameUsedOverlayLayerIds;

// Platform view IDs that were displayed since the start of the current frame.
private HashSet<Integer> currentFrameUsedPlatformViewIds;
private final HashSet<Integer> currentFrameUsedPlatformViewIds;

// Used to acquire the original motion events using the motionEventIds.
private final MotionEventTracker motionEventTracker;
Expand Down Expand Up @@ -290,12 +290,9 @@ public void resizePlatformView(
vdController.resize(
physicalWidth,
physicalHeight,
new Runnable() {
@Override
public void run() {
unlockInputConnection(vdController);
onComplete.run();
}
() -> {
unlockInputConnection(vdController);
onComplete.run();
});
}

Expand Down Expand Up @@ -483,7 +480,7 @@ public void detach() {
* This {@code PlatformViewsController} and its {@code FlutterEngine} is now attached to an
* Android {@code View} that renders a Flutter UI.
*/
public void attachToView(@NonNull View flutterView) {
public void attachToView(@NonNull FlutterView flutterView) {
this.flutterView = flutterView;

// Inform all existing platform views that they are now associated with
Expand Down Expand Up @@ -518,7 +515,7 @@ public void attachAccessibilityBridge(AccessibilityBridge accessibilityBridge) {
}

@Override
public void detachAccessibiltyBridge() {
public void detachAccessibilityBridge() {
accessibilityEventsDelegate.setAccessibilityBridge(null);
}

Expand Down Expand Up @@ -720,7 +717,7 @@ private void flushAllViews() {

private void initializeRootImageViewIfNeeded() {
if (synchronizeToNativeViewHierarchy && !flutterViewConvertedToImageView) {
((FlutterView) flutterView).convertToImageView();
flutterView.convertToImageView();
flutterViewConvertedToImageView = true;
}
}
Expand Down Expand Up @@ -764,7 +761,7 @@ void initializePlatformViewIfNeeded(int viewId) {

platformViewParent.put(viewId, parentView);
parentView.addView(platformView.getView());
((FlutterView) flutterView).addView(parentView);
flutterView.addView(parentView);
}

public void attachToFlutterRenderer(FlutterRenderer flutterRenderer) {
Expand Down Expand Up @@ -829,7 +826,7 @@ public void onDisplayOverlaySurface(int id, int x, int y, int width, int height)

final FlutterImageView overlayView = overlayLayerViews.get(id);
if (overlayView.getParent() == null) {
((FlutterView) flutterView).addView(overlayView);
flutterView.addView(overlayView);
}

FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams((int) width, (int) height);
Expand All @@ -852,14 +849,13 @@ public void onBeginFrame() {
* <p>This member is not intended for public use, and is only visible for testing.
*/
public void onEndFrame() {
final FlutterView view = (FlutterView) flutterView;
// If there are no platform views in the current frame,
// then revert the image view surface and use the previous surface.
//
// Otherwise, acquire the latest image.
if (flutterViewConvertedToImageView && currentFrameUsedPlatformViewIds.isEmpty()) {
flutterViewConvertedToImageView = false;
view.revertImageView(
flutterView.revertImageView(
() -> {
// Destroy overlay surfaces once the surface reversion is completed.
finishFrame(false);
Expand All @@ -876,7 +872,7 @@ public void onEndFrame() {
// dropped.
// For example, a toolbar widget painted by Flutter may not be rendered.
final boolean isFrameRenderedUsingImageReaders =
flutterViewConvertedToImageView && view.acquireLatestImageViewFrame();
flutterViewConvertedToImageView && flutterView.acquireLatestImageViewFrame();
finishFrame(isFrameRenderedUsingImageReaders);
}

Expand All @@ -886,7 +882,7 @@ private void finishFrame(boolean isFrameRenderedUsingImageReaders) {
final FlutterImageView overlayView = overlayLayerViews.valueAt(i);

if (currentFrameUsedOverlayLayerIds.contains(overlayId)) {
((FlutterView) flutterView).attachOverlaySurfaceToRender(overlayView);
flutterView.attachOverlaySurfaceToRender(overlayView);
final boolean didAcquireOverlaySurfaceImage = overlayView.acquireLatestImage();
isFrameRenderedUsingImageReaders &= didAcquireOverlaySurfaceImage;
} else {
Expand Down Expand Up @@ -970,12 +966,11 @@ public FlutterOverlaySurface createOverlaySurface() {
*/
public void destroyOverlaySurfaces() {
for (int i = 0; i < overlayLayerViews.size(); i++) {
int overlayId = overlayLayerViews.keyAt(i);
FlutterImageView overlayView = overlayLayerViews.valueAt(i);
overlayView.detachFromRenderer();
overlayView.closeImageReader();
if (flutterView != null) {
((FlutterView) flutterView).removeView(overlayView);
flutterView.removeView(overlayView);
}
}
overlayLayerViews.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package io.flutter.plugin.platform;

import static android.content.Context.INPUT_METHOD_SERVICE;
import static android.content.Context.WINDOW_SERVICE;
import static android.view.View.OnFocusChangeListener;

Expand Down Expand Up @@ -99,7 +98,7 @@ static class PresentationState {
// presentation.
private FrameLayout container;

private PresentationState state;
private final PresentationState state;

private boolean startFocused = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static VirtualDisplayController create(
private final OnFocusChangeListener focusChangeListener;
private VirtualDisplay virtualDisplay;
@VisibleForTesting SingleViewPresentation presentation;
private Surface surface;
private final Surface surface;

private VirtualDisplayController(
Context context,
Expand Down
31 changes: 5 additions & 26 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
@NonNull private final AccessibilityViewEmbedder accessibilityViewEmbedder;

// The delegate for interacting with embedded platform views. Used to embed accessibility data for
// an embedded
// view in the accessibility tree.
// an embedded view in the accessibility tree.
@NonNull private final PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate;

// Android's {@link ContentResolver}, which is used to observe the global
Expand Down Expand Up @@ -386,11 +385,7 @@ public AccessibilityBridge(
@NonNull AccessibilityChannel accessibilityChannel,
@NonNull AccessibilityManager accessibilityManager,
@NonNull ContentResolver contentResolver,
// This should be @NonNull once the plumbing for
// io.flutter.embedding.engine.android.FlutterView is done.
// TODO(mattcarrol): Add the annotation once the plumbing is done.
// https://github.com/flutter/flutter/issues/29618
PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
@NonNull PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
this(
rootAccessibilityView,
accessibilityChannel,
Expand All @@ -407,11 +402,7 @@ public AccessibilityBridge(
@NonNull AccessibilityManager accessibilityManager,
@NonNull ContentResolver contentResolver,
@NonNull AccessibilityViewEmbedder accessibilityViewEmbedder,
// This should be @NonNull once the plumbing for
// io.flutter.embedding.engine.android.FlutterView is done.
// TODO(mattcarrol): Add the annotation once the plumbing is done.
// https://github.com/flutter/flutter/issues/29618
PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
@NonNull PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
this.rootAccessibilityView = rootAccessibilityView;
this.accessibilityChannel = accessibilityChannel;
this.accessibilityManager = accessibilityManager;
Expand Down Expand Up @@ -464,13 +455,7 @@ public void onTouchExplorationStateChanged(boolean isTouchExplorationEnabled) {
this.contentResolver.registerContentObserver(transitionUri, false, animationScaleObserver);
}

// platformViewsAccessibilityDelegate should be @NonNull once the plumbing
// for io.flutter.embedding.engine.android.FlutterView is done.
// TODO(mattcarrol): Remove the null check once the plumbing is done.
// https://github.com/flutter/flutter/issues/29618
if (platformViewsAccessibilityDelegate != null) {
platformViewsAccessibilityDelegate.attachAccessibilityBridge(this);
}
platformViewsAccessibilityDelegate.attachAccessibilityBridge(this);
}

/**
Expand All @@ -482,13 +467,7 @@ public void onTouchExplorationStateChanged(boolean isTouchExplorationEnabled) {
*/
public void release() {
isReleased = true;
// platformViewsAccessibilityDelegate should be @NonNull once the plumbing
// for io.flutter.embedding.engine.android.FlutterView is done.
// TODO(mattcarrol): Remove the null check once the plumbing is done.
// https://github.com/flutter/flutter/issues/29618
if (platformViewsAccessibilityDelegate != null) {
platformViewsAccessibilityDelegate.detachAccessibiltyBridge();
}
platformViewsAccessibilityDelegate.detachAccessibilityBridge();
setOnAccessibilityChangeListener(null);
accessibilityManager.removeAccessibilityStateChangeListener(accessibilityStateChangeListener);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class PlatformViewsControllerTest {
public void itNotifiesVirtualDisplayControllersOfViewAttachmentAndDetachment() {
// Setup test structure.
// Create a fake View that represents the View that renders a Flutter UI.
View fakeFlutterView = new View(RuntimeEnvironment.systemContext);
FlutterView fakeFlutterView = new FlutterView(RuntimeEnvironment.systemContext);

// Create fake VirtualDisplayControllers. This requires internal knowledge of
// PlatformViewsController. We know that all PlatformViewsController does is
Expand Down