Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
io.flutter.embedding.engine.systemchannels.SettingsChannel.ConfigurationQueue Class Reference

Classes

class  SentConfiguration
 

Public Member Functions

SentConfiguration getConfiguration (int configGeneration)
 
BasicMessageChannel.Reply enqueueConfiguration (SentConfiguration config)
 

Detailed Description

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.

Definition at line 175 of file SettingsChannel.java.

Member Function Documentation

◆ enqueueConfiguration()

BasicMessageChannel.Reply io.flutter.embedding.engine.systemchannels.SettingsChannel.ConfigurationQueue.enqueueConfiguration ( SentConfiguration  config)
inline

Adds the most recently sent SentConfiguration to the queue.

Returns
a BasicMessageChannel.Reply whose reply method must be called when the embedder receives the reply for the sent configuration, to properly clean up older configurations in the queue.

Definition at line 233 of file SettingsChannel.java.

233 {
234 sentQueue.add(config);
235 final SentConfiguration configurationToRemove = previousEnqueuedConfiguration;
236 previousEnqueuedConfiguration = config;
237 return configurationToRemove == null
238 ? null
239 : new BasicMessageChannel.Reply() {
240 @UiThread
241 @Override
242 public void reply(Object reply) {
243 // Removes the SentConfiguration sent right before `config`. Since
244 // platform messages are also FIFO older messages will be removed
245 // before newer ones.
246 sentQueue.remove(configurationToRemove);
247 if (!sentQueue.isEmpty()) {
248 Log.e(
249 TAG,
250 "The queue becomes empty after removing config generation "
251 + String.valueOf(configurationToRemove.generationNumber));
252 }
253 }
254 };
255 }
void Log(const char *format,...) SK_PRINTF_LIKE(1

◆ getConfiguration()

SentConfiguration io.flutter.embedding.engine.systemchannels.SettingsChannel.ConfigurationQueue.getConfiguration ( int  configGeneration)
inline

Returns the SentConfiguration associated with the given configGeneration, and removes configurations older than the returned configurations from the queue as they are no longer needed.

Definition at line 191 of file SettingsChannel.java.

191 {
192 if (currentConfiguration == null) {
193 currentConfiguration = sentQueue.poll();
194 }
195
196 // Remove the older entries, up to the entry associated with
197 // configGeneration. Here we assume the generationNumber never overflows.
198 while (currentConfiguration != null
199 && currentConfiguration.generationNumber < configGeneration) {
200 currentConfiguration = sentQueue.poll();
201 }
202
203 if (currentConfiguration == null) {
204 Log.e(
205 TAG,
206 "Cannot find config with generation: "
207 + String.valueOf(configGeneration)
208 + ", after exhausting the queue.");
209 return null;
210 } else if (currentConfiguration.generationNumber != configGeneration) {
211 Log.e(
212 TAG,
213 "Cannot find config with generation: "
214 + String.valueOf(configGeneration)
215 + ", the oldest config is now: "
216 + String.valueOf(currentConfiguration.generationNumber));
217 return null;
218 }
219 return currentConfiguration;
220 }

The documentation for this class was generated from the following file: