Class SettingsChannel.ConfigurationQueue

java.lang.Object
io.flutter.embedding.engine.systemchannels.SettingsChannel.ConfigurationQueue
Enclosing class:
SettingsChannel

@VisibleForTesting public static class SettingsChannel.ConfigurationQueue extends Object
A FIFO queue that maintains generations of configurations that are potentially used by the Flutter application.

Platform configurations needed by the Flutter app (for example, text scale factor) are retrived on the platform thread, serialized and sent to the Flutter application running on the Flutter UI thread. However, configurations exposed as functions that take parameters are typically not serializable. To allow the Flutter app to access these configurations, one possible solution is to create dart bindings that allow the Flutter framework to invoke these functions via JNI synchronously. To ensure the serialized configuration and these functions represent the same set of configurations at any given time, a "generation" id is used in these synchronous calls, to keep them consistent with the serialized configuration that the Flutter app most recently received and is currently using.

A unique generation identifier is generated by the SettingsChannel and associated with a configuration when it sends a serialized configuration to the Flutter framework. This queue keeps different generations of configurations that could be used by the Flutter framework, and cleans up old configurations that the Flutter framework no longer uses. When the Flutter framework invokes a function to access the configuration with a generation identifier, this queue finds the configuration with that identifier and also cleans up configurations that are no longer needed.

This mechanism is only needed because TypedValue#applyDimension does not take the current text scale factor as an input. Once the AndroidX API that allows us to query the scaled font size with a pure function is available, we can scrap this class and make the implementation much simpler.