Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1d12d82

Browse files
Patrick Sosinskijason-simmons
andauthored
[flutter_releases] Flutter 1.23.0-18.1.pre Engine Cherrypicks (#21838)
* Update 1.23 engine to use Dart 2.11.0-213.1.beta * Call PlatformView.dispose when removing hybrid composition platform views (#21790) Also force disposal of all hybrid platform views when shutting down the engine. Fixes flutter/flutter#66764 Co-authored-by: Jason Simmons <jason-simmons@users.noreply.github.com>
1 parent 6634406 commit 1d12d82

File tree

3 files changed

+45
-57
lines changed

3 files changed

+45
-57
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ vars = {
3434
# Dart is: https://github.com/dart-lang/sdk/blob/master/DEPS.
3535
# You can use //tools/dart/create_updated_flutter_deps.py to produce
3636
# updated revision list of existing dependencies.
37-
'dart_revision': 'e256855d07ba9cad5048f012f38a05446ca2fe09',
37+
'dart_revision': '7cdfa7be71c9530e2ce12a095df1775aa0b9ab63',
3838

3939
# WARNING: DO NOT EDIT MANUALLY
4040
# The lines between blank lines above and below are generated by a script. See create_updated_flutter_deps.py

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.util.SparseArray;
1515
import android.view.MotionEvent;
1616
import android.view.View;
17+
import android.view.ViewGroup;
1718
import android.widget.FrameLayout;
1819
import androidx.annotation.NonNull;
1920
import androidx.annotation.Nullable;
@@ -83,7 +84,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
8384
// The views returned by `PlatformView#getView()`.
8485
//
8586
// This only applies to hybrid composition.
86-
private final SparseArray<View> platformViews;
87+
private final SparseArray<PlatformView> platformViews;
8788

8889
// The platform view parents that are appended to `FlutterView`.
8990
// If an entry in `platformViews` doesn't have an entry in this array, the platform view isn't
@@ -143,32 +144,24 @@ public void createAndroidViewForPlatformView(
143144
}
144145

145146
final PlatformView platformView = factory.create(context, request.viewId, createParams);
146-
final View view = platformView.getView();
147-
if (view == null) {
148-
throw new IllegalStateException(
149-
"PlatformView#getView() returned null, but an Android view reference was expected.");
150-
}
151-
if (view.getParent() != null) {
152-
throw new IllegalStateException(
153-
"The Android view returned from PlatformView#getView() was already added to a parent view.");
154-
}
155-
platformViews.put(request.viewId, view);
147+
platformViews.put(request.viewId, platformView);
156148
}
157149

158150
@Override
159151
public void disposeAndroidViewForPlatformView(int viewId) {
160152
// Hybrid view.
161-
final View platformView = platformViews.get(viewId);
153+
final PlatformView platformView = platformViews.get(viewId);
162154
final FlutterMutatorView parentView = platformViewParent.get(viewId);
163155
if (platformView != null) {
164156
if (parentView != null) {
165-
parentView.removeView(platformView);
157+
parentView.removeView(platformView.getView());
166158
}
167159
platformViews.remove(viewId);
160+
platformView.dispose();
168161
}
169162

170163
if (parentView != null) {
171-
((FlutterView) flutterView).removeView(parentView);
164+
((ViewGroup) parentView.getParent()).removeView(parentView);
172165
platformViewParent.remove(viewId);
173166
}
174167
}
@@ -311,8 +304,10 @@ public void onTouch(@NonNull PlatformViewsChannel.PlatformViewTouch touch) {
311304
vdControllers.get(touch.viewId).dispatchTouchEvent(event);
312305
} else if (platformViews.get(viewId) != null) {
313306
final MotionEvent event = toMotionEvent(density, touch, /*usingVirtualDiplays=*/ false);
314-
View view = platformViews.get(touch.viewId);
315-
view.dispatchTouchEvent(event);
307+
View view = platformViews.get(touch.viewId).getView();
308+
if (view != null) {
309+
view.dispatchTouchEvent(event);
310+
}
316311
} else {
317312
throw new IllegalStateException("Sending touch to an unknown view with id: " + viewId);
318313
}
@@ -580,7 +575,7 @@ public void onPreEngineRestart() {
580575
public View getPlatformViewById(Integer id) {
581576
// Hybrid composition.
582577
if (platformViews.get(id) != null) {
583-
return platformViews.get(id);
578+
return platformViews.get(id).getView();
584579
}
585580
VirtualDisplayController controller = vdControllers.get(id);
586581
if (controller == null) {
@@ -690,6 +685,10 @@ private void flushAllViews() {
690685
controller.dispose();
691686
}
692687
vdControllers.clear();
688+
689+
while (platformViews.size() > 0) {
690+
channelHandler.disposeAndroidViewForPlatformView(platformViews.keyAt(0));
691+
}
693692
}
694693

695694
private void initializeRootImageViewIfNeeded() {
@@ -701,19 +700,27 @@ private void initializeRootImageViewIfNeeded() {
701700

702701
@VisibleForTesting
703702
void initializePlatformViewIfNeeded(int viewId) {
704-
final View view = platformViews.get(viewId);
705-
if (view == null) {
703+
final PlatformView platformView = platformViews.get(viewId);
704+
if (platformView == null) {
706705
throw new IllegalStateException(
707706
"Platform view hasn't been initialized from the platform view channel.");
708707
}
709708
if (platformViewParent.get(viewId) != null) {
710709
return;
711710
}
711+
if (platformView.getView() == null) {
712+
throw new IllegalStateException(
713+
"PlatformView#getView() returned null, but an Android view reference was expected.");
714+
}
715+
if (platformView.getView().getParent() != null) {
716+
throw new IllegalStateException(
717+
"The Android view returned from PlatformView#getView() was already added to a parent view.");
718+
}
712719
final FlutterMutatorView parentView =
713720
new FlutterMutatorView(
714721
context, context.getResources().getDisplayMetrics().density, androidTouchProcessor);
715722
platformViewParent.put(viewId, parentView);
716-
parentView.addView(view);
723+
parentView.addView(platformView.getView());
717724
((FlutterView) flutterView).addView(parentView);
718725
}
719726

@@ -740,9 +747,11 @@ public void onDisplayPlatformView(
740747

741748
final FrameLayout.LayoutParams layoutParams =
742749
new FrameLayout.LayoutParams(viewWidth, viewHeight);
743-
final View platformView = platformViews.get(viewId);
744-
platformView.setLayoutParams(layoutParams);
745-
platformView.bringToFront();
750+
final View view = platformViews.get(viewId).getView();
751+
if (view != null) {
752+
view.setLayoutParams(layoutParams);
753+
view.bringToFront();
754+
}
746755
currentFrameUsedPlatformViewIds.add(viewId);
747756
}
748757

shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
import io.flutter.embedding.engine.systemchannels.MouseCursorChannel;
3030
import io.flutter.embedding.engine.systemchannels.SettingsChannel;
3131
import io.flutter.embedding.engine.systemchannels.TextInputChannel;
32-
import io.flutter.plugin.common.FlutterException;
3332
import io.flutter.plugin.common.MethodCall;
34-
import io.flutter.plugin.common.StandardMessageCodec;
3533
import io.flutter.plugin.common.StandardMethodCodec;
3634
import io.flutter.plugin.localization.LocalizationPlugin;
3735
import java.nio.ByteBuffer;
@@ -262,7 +260,7 @@ public void createPlatformViewMessage__initializesAndroidView() {
262260

263261
// Simulate create call from the framework.
264262
createPlatformView(jni, platformViewsController, platformViewId, "testType");
265-
verify(platformView, times(1)).getView();
263+
verify(viewFactory, times(1)).create(any(), eq(platformViewId), any());
266264
}
267265

268266
@Test
@@ -286,21 +284,11 @@ public void createPlatformViewMessage__throwsIfViewIsNull() {
286284
createPlatformView(jni, platformViewsController, platformViewId, "testType");
287285
assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
288286

289-
final ByteBuffer responseBuffer = ShadowFlutterJNI.getResponses().get(0);
290-
responseBuffer.rewind();
291-
292-
StandardMethodCodec methodCodec = new StandardMethodCodec(new StandardMessageCodec());
293-
try {
294-
methodCodec.decodeEnvelope(responseBuffer);
295-
} catch (FlutterException exception) {
296-
assertTrue(
297-
exception
298-
.getMessage()
299-
.contains(
300-
"PlatformView#getView() returned null, but an Android view reference was expected."));
301-
return;
302-
}
303-
assertFalse(true);
287+
assertThrows(
288+
IllegalStateException.class,
289+
() -> {
290+
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
291+
});
304292
}
305293

306294
@Test
@@ -326,21 +314,11 @@ public void createPlatformViewMessage__throwsIfViewHasParent() {
326314
createPlatformView(jni, platformViewsController, platformViewId, "testType");
327315
assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
328316

329-
final ByteBuffer responseBuffer = ShadowFlutterJNI.getResponses().get(0);
330-
responseBuffer.rewind();
331-
332-
StandardMethodCodec methodCodec = new StandardMethodCodec(new StandardMessageCodec());
333-
try {
334-
methodCodec.decodeEnvelope(responseBuffer);
335-
} catch (FlutterException exception) {
336-
assertTrue(
337-
exception
338-
.getMessage()
339-
.contains(
340-
"The Android view returned from PlatformView#getView() was already added to a parent view."));
341-
return;
342-
}
343-
assertFalse(true);
317+
assertThrows(
318+
IllegalStateException.class,
319+
() -> {
320+
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
321+
});
344322
}
345323

346324
@Test
@@ -381,6 +359,7 @@ public void disposeAndroidView__hybridComposition() {
381359

382360
assertNotNull(androidView.getParent());
383361
assertTrue(androidView.getParent() instanceof FlutterMutatorView);
362+
verify(platformView, times(1)).dispose();
384363
}
385364

386365
@Test

0 commit comments

Comments
 (0)