Fizzle onConfigurationChanged if no FlutterView (flutter/engine#13445)

This commit is contained in:
Dan Field 2019-10-30 15:49:02 -07:00 committed by GitHub
parent 1bb68ff308
commit 019c555be8
2 changed files with 31 additions and 3 deletions

View File

@ -269,9 +269,18 @@ public class FlutterView extends FrameLayout {
@Override
protected void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.v(TAG, "Configuration changed. Sending locales and user settings to Flutter.");
sendLocalesToFlutter(newConfig);
sendUserSettingsToFlutter();
// We've observed on Android Q that going to the background, changing
// orientation, and bringing the app back to foreground results in a sequence
// of detatch from flutterEngine, onConfigurationChanged, followed by attach
// to flutterEngine.
// No-op here so that we avoid NPE; these channels will get notified once
// the activity or fragment tell the view to attach to the Flutter engine
// again (e.g. in onStart).
if (flutterEngine != null) {
Log.v(TAG, "Configuration changed. Sending locales and user settings to Flutter.");
sendLocalesToFlutter(newConfig);
sendUserSettingsToFlutter();
}
}
/**

View File

@ -78,6 +78,25 @@ public class FlutterViewTest {
verify(platformViewsController, times(1)).detachFromView();
}
@Test
public void onConfigurationChanged_fizzlesWhenNullEngine() {
FlutterView flutterView = new FlutterView(RuntimeEnvironment.application);
FlutterEngine flutterEngine = spy(new FlutterEngine(RuntimeEnvironment.application, mockFlutterLoader, mockFlutterJni));
Configuration configuration = RuntimeEnvironment.application.getResources().getConfiguration();
// 1 invocation of channels.
flutterView.attachToFlutterEngine(flutterEngine);
// 2 invocations of channels.
flutterView.onConfigurationChanged(configuration);
flutterView.detachFromFlutterEngine();
// Should fizzle.
flutterView.onConfigurationChanged(configuration);
verify(flutterEngine, times(2)).getLocalizationChannel();
verify(flutterEngine, times(2)).getSettingsChannel();
}
// TODO(mattcarroll): turn this into an e2e test. GitHub #42990
@Test
public void itSendsLightPlatformBrightnessToFlutter() {