Null check for the activity intent in FlutterEngineConnectionRegistry.attachToActivityInternal (flutter/engine#35419)

This commit is contained in:
Jason Simmons
2022-08-16 07:58:05 -07:00
committed by GitHub
parent 5c169325bc
commit 9e3d202f48
2 changed files with 12 additions and 7 deletions

View File

@@ -331,9 +331,11 @@ import java.util.Set;
this.activityPluginBinding = new FlutterEngineActivityPluginBinding(activity, lifecycle);
final boolean useSoftwareRendering =
activity
.getIntent()
.getBooleanExtra(FlutterShellArgs.ARG_KEY_ENABLE_SOFTWARE_RENDERING, false);
activity.getIntent() != null
? activity
.getIntent()
.getBooleanExtra(FlutterShellArgs.ARG_KEY_ENABLE_SOFTWARE_RENDERING, false)
: false;
flutterEngine.getPlatformViewsController().setSoftwareRendering(useSoftwareRendering);
// Activate the PlatformViewsController. This must happen before any plugins attempt

View File

@@ -127,15 +127,18 @@ public class FlutterEngineConnectionRegistryTest {
Activity activity = mock(Activity.class);
when(appComponent.getAppComponent()).thenReturn(activity);
// Test attachToActivity with an Activity that has no Intent.
FlutterEngineConnectionRegistry registry =
new FlutterEngineConnectionRegistry(context, flutterEngine, flutterLoader);
registry.attachToActivity(appComponent, mock(Lifecycle.class));
verify(platformViewsController).setSoftwareRendering(false);
Intent intent = mock(Intent.class);
when(intent.getBooleanExtra("enable-software-rendering", false)).thenReturn(false);
when(activity.getIntent()).thenReturn(intent);
FlutterEngineConnectionRegistry registry =
new FlutterEngineConnectionRegistry(context, flutterEngine, flutterLoader);
registry.attachToActivity(appComponent, mock(Lifecycle.class));
verify(platformViewsController).setSoftwareRendering(false);
verify(platformViewsController, times(2)).setSoftwareRendering(false);
when(intent.getBooleanExtra("enable-software-rendering", false)).thenReturn(true);