5package io.flutter.embedding.engine.plugins.shim;
7import androidx.annotation.NonNull;
9import io.flutter.embedding.engine.FlutterEngine;
10import io.flutter.embedding.engine.plugins.FlutterPlugin;
11import io.flutter.embedding.engine.plugins.activity.ActivityAware;
12import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
13import io.flutter.plugin.common.PluginRegistry;
14import java.util.HashMap;
15import java.util.HashSet;
39 private static final String TAG =
"ShimPluginRegistry";
42 private final Map<String, Object> pluginMap =
new HashMap<>();
43 private final ShimRegistrarAggregate shimRegistrarAggregate;
46 this.flutterEngine = flutterEngine;
47 this.shimRegistrarAggregate =
new ShimRegistrarAggregate();
48 this.flutterEngine.getPlugins().add(shimRegistrarAggregate);
54 Log.
v(
TAG,
"Creating plugin Registrar for '" + pluginKey +
"'");
55 if (pluginMap.containsKey(pluginKey)) {
56 throw new IllegalStateException(
"Plugin key " + pluginKey +
" is already in use");
58 pluginMap.put(pluginKey,
null);
60 shimRegistrarAggregate.addPlugin(registrar);
65 public boolean hasPlugin(@NonNull String pluginKey) {
66 return pluginMap.containsKey(pluginKey);
70 @SuppressWarnings(
"unchecked")
72 return (
T) pluginMap.get(pluginKey);
89 private final Set<ShimRegistrar> shimRegistrars =
new HashSet<>();
94 shimRegistrars.add(shimRegistrar);
96 if (flutterPluginBinding !=
null) {
97 shimRegistrar.onAttachedToEngine(flutterPluginBinding);
99 if (activityPluginBinding !=
null) {
100 shimRegistrar.onAttachedToActivity(activityPluginBinding);
105 public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
106 flutterPluginBinding = binding;
107 for (ShimRegistrar shimRegistrar : shimRegistrars) {
108 shimRegistrar.onAttachedToEngine(binding);
113 public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
114 for (ShimRegistrar shimRegistrar : shimRegistrars) {
115 shimRegistrar.onDetachedFromEngine(binding);
117 flutterPluginBinding =
null;
118 activityPluginBinding =
null;
122 public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
123 activityPluginBinding = binding;
124 for (ShimRegistrar shimRegistrar : shimRegistrars) {
125 shimRegistrar.onAttachedToActivity(binding);
130 public void onDetachedFromActivityForConfigChanges() {
131 for (ShimRegistrar shimRegistrar : shimRegistrars) {
132 shimRegistrar.onDetachedFromActivity();
134 activityPluginBinding =
null;
138 public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
139 activityPluginBinding = binding;
140 for (ShimRegistrar shimRegistrar : shimRegistrars) {
141 shimRegistrar.onReattachedToActivityForConfigChanges(binding);
146 public void onDetachedFromActivity() {
147 for (ShimRegistrar shimRegistrar : shimRegistrars) {
148 shimRegistrar.onDetachedFromActivity();
150 activityPluginBinding =
null;
static void v(@NonNull String tag, @NonNull String message)
public< T > T valuePublishedByPlugin(@NonNull String pluginKey)
boolean hasPlugin(@NonNull String pluginKey)
Registrar registrarFor(@NonNull String pluginKey)
ShimPluginRegistry(@NonNull FlutterEngine flutterEngine)