[android] workaround for HC bug. (flutter/engine#54408)

Testing

FYI @jason-simmons 

"Fixes" https://github.com/flutter/flutter/issues/152691
This commit is contained in:
Jonah Williams 2024-08-07 17:06:58 -07:00 committed by GitHub
parent f0f2dd5a14
commit 95edf0d8db
2 changed files with 14 additions and 20 deletions

View File

@ -1115,14 +1115,13 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
* testing.
*/
@VisibleForTesting
void initializePlatformViewIfNeeded(int viewId) {
boolean initializePlatformViewIfNeeded(int viewId) {
final PlatformView platformView = platformViews.get(viewId);
if (platformView == null) {
throw new IllegalStateException(
"Platform view hasn't been initialized from the platform view channel.");
return false;
}
if (platformViewParent.get(viewId) != null) {
return;
return true;
}
final View embeddedView = platformView.getView();
if (embeddedView == null) {
@ -1160,6 +1159,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
parentView.addView(embeddedView);
flutterView.addView(parentView);
return true;
}
public void attachToFlutterRenderer(@NonNull FlutterRenderer flutterRenderer) {
@ -1189,7 +1189,9 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
int viewHeight,
@NonNull FlutterMutatorsStack mutatorsStack) {
initializeRootImageViewIfNeeded();
initializePlatformViewIfNeeded(viewId);
if (!initializePlatformViewIfNeeded(viewId)) {
return;
}
final FlutterMutatorView parentView = platformViewParent.get(viewId);
parentView.readyToDisplay(mutatorsStack, x, y, width, height);

View File

@ -461,7 +461,7 @@ public class PlatformViewsControllerTest {
// Simulate create call from the framework.
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
assertTrue(platformViewsController.initializePlatformViewIfNeeded(platformViewId));
View resultAndroidView = platformViewsController.getPlatformViewById(platformViewId);
assertNotNull(resultAndroidView);
@ -647,11 +647,7 @@ public class PlatformViewsControllerTest {
jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
assertThrows(
IllegalStateException.class,
() -> {
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
});
assertFalse(platformViewsController.initializePlatformViewIfNeeded(platformViewId));
}
@Test
@ -675,11 +671,7 @@ public class PlatformViewsControllerTest {
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
assertThrows(
IllegalStateException.class,
() -> {
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
});
assertFalse(platformViewsController.initializePlatformViewIfNeeded(platformViewId));
}
@Test
@ -901,7 +893,7 @@ public class PlatformViewsControllerTest {
// Simulate create call from the framework.
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
assertTrue(platformViewsController.initializePlatformViewIfNeeded(platformViewId));
assertNotNull(androidView.getParent());
assertTrue(androidView.getParent() instanceof FlutterMutatorView);
@ -912,7 +904,7 @@ public class PlatformViewsControllerTest {
// Simulate create call from the framework.
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
assertTrue(platformViewsController.initializePlatformViewIfNeeded(platformViewId));
assertNotNull(androidView.getParent());
assertTrue(androidView.getParent() instanceof FlutterMutatorView);
@ -941,7 +933,7 @@ public class PlatformViewsControllerTest {
// Simulate create call from the framework.
createPlatformView(
jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
assertTrue(platformViewsController.initializePlatformViewIfNeeded(platformViewId));
when(platformView.getView()).thenReturn(null);
@ -1080,7 +1072,7 @@ public class PlatformViewsControllerTest {
// Simulate create call from the framework.
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
assertTrue(platformViewsController.initializePlatformViewIfNeeded(platformViewId));
assertEquals(flutterView.getChildCount(), 2);
// Simulate first frame from the framework.