mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fizzle onConfigurationChanged if no FlutterView (flutter/engine#13445)
This commit is contained in:
parent
1bb68ff308
commit
019c555be8
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user