Flutter Engine
The Flutter Engine
PluginRegistry.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.plugin.common;
6
7import android.app.Activity;
8import android.content.Context;
9import android.content.Intent;
10import androidx.annotation.NonNull;
11import androidx.annotation.Nullable;
12import io.flutter.embedding.engine.plugins.FlutterPlugin;
13import io.flutter.embedding.engine.plugins.activity.ActivityAware;
14import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
15import io.flutter.plugin.platform.PlatformViewRegistry;
16import io.flutter.view.FlutterNativeView;
17import io.flutter.view.FlutterView;
18import io.flutter.view.TextureRegistry;
19
20/**
21 * Container class for Android API listeners used by {@link ActivityPluginBinding}.
22 *
23 * <p>This class also contains deprecated v1 embedding APIs used for plugin registration.
24 *
25 * <p>In v1 Android applications, an auto-generated and auto-updated plugin registrant class
26 * (GeneratedPluginRegistrant) makes use of a {@link PluginRegistry} to register contributions from
27 * each plugin mentioned in the application's pubspec file. The generated registrant class is, again
28 * by default, called from the application's main {@link android.app.Activity}, which defaults to an
29 * instance of {@link io.flutter.app.FlutterActivity}, itself a {@link PluginRegistry}.
30 */
31public interface PluginRegistry {
32 /**
33 * Returns a {@link Registrar} for receiving the registrations pertaining to the specified plugin.
34 *
35 * @param pluginKey a unique String identifying the plugin; typically the fully qualified name of
36 * the plugin's main class.
37 * @return A {@link Registrar} for receiving the registrations pertianing to the specified plugin.
38 * @deprecated See https://flutter.dev/go/android-project-migration for migration details.
39 */
40 @Deprecated
41 @NonNull
42 Registrar registrarFor(@NonNull String pluginKey);
43
44 /**
45 * Returns whether the specified plugin is known to this registry.
46 *
47 * @param pluginKey a unique String identifying the plugin; typically the fully qualified name of
48 * the plugin's main class.
49 * @return true if this registry has handed out a registrar for the specified plugin.
50 * @deprecated See https://flutter.dev/go/android-project-migration for migration details.
51 */
52 @Deprecated
53 boolean hasPlugin(@NonNull String pluginKey);
54
55 /**
56 * Returns the value published by the specified plugin, if any.
57 *
58 * <p>Plugins may publish a single value, such as an instance of the plugin's main class, for
59 * situations where external control or interaction is needed. Clients are expected to know the
60 * value's type.
61 *
62 * @param <T> The type of the value.
63 * @param pluginKey a unique String identifying the plugin; typically the fully qualified name of
64 * the plugin's main class.
65 * @return the published value, possibly null.
66 * @deprecated See https://flutter.dev/go/android-project-migration for migration details.
67 */
68 @Deprecated
69 @Nullable
70 <T> T valuePublishedByPlugin(@NonNull String pluginKey);
71
72 /**
73 * Receiver of registrations from a single plugin.
74 *
75 * @deprecated This registrar is for Flutter's v1 embedding. For instructions on migrating a
76 * plugin from Flutter's v1 Android embedding to v2, visit
77 * http://flutter.dev/go/android-plugin-migration
78 */
79 @Deprecated
80 interface Registrar {
81 /**
82 * Returns the {@link android.app.Activity} that forms the plugin's operating context.
83 *
84 * <p>Plugin authors should not assume the type returned by this method is any specific subclass
85 * of {@code Activity} (such as {@link io.flutter.app.FlutterActivity} or {@link
86 * io.flutter.app.FlutterFragmentActivity}), as applications are free to use any activity
87 * subclass.
88 *
89 * <p>When there is no foreground activity in the application, this will return null. If a
90 * {@link Context} is needed, use context() to get the application's context.
91 *
92 * <p>This registrar is for Flutter's v1 embedding. To access an {@code Activity} from a plugin
93 * using the v2 embedding, see {@link ActivityPluginBinding#getActivity()}. To obtain an
94 * instance of an {@link ActivityPluginBinding} in a Flutter plugin, implement the {@link
95 * ActivityAware} interface. A binding is provided in {@link
96 * ActivityAware#onAttachedToActivity(ActivityPluginBinding)} and {@link
97 * ActivityAware#onReattachedToActivityForConfigChanges(ActivityPluginBinding)}.
98 *
99 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
100 * http://flutter.dev/go/android-plugin-migration
101 */
102 @Nullable
103 Activity activity();
104
105 /**
106 * Returns the {@link android.app.Application}'s {@link Context}.
107 *
108 * <p>This registrar is for Flutter's v1 embedding. To access a {@code Context} from a plugin
109 * using the v2 embedding, see {@link
110 * FlutterPlugin.FlutterPluginBinding#getApplicationContext()}
111 *
112 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
113 * http://flutter.dev/go/android-plugin-migration
114 */
115 @NonNull
116 Context context();
117
118 /**
119 * Returns the active {@link Context}.
120 *
121 * <p>This registrar is for Flutter's v1 embedding. In the v2 embedding, there is no concept of
122 * an "active context". Either use the application {@code Context} or an attached {@code
123 * Activity}. See {@link #context()} and {@link #activity()} for more details.
124 *
125 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
126 * http://flutter.dev/go/android-plugin-migration
127 *
128 * @return the current {@link #activity() Activity}, if not null, otherwise the {@link
129 * #context() Application}.
130 */
131 @NonNull
132 Context activeContext();
133
134 /**
135 * Returns a {@link BinaryMessenger} which the plugin can use for creating channels for
136 * communicating with the Dart side.
137 *
138 * <p>This registrar is for Flutter's v1 embedding. To access a {@code BinaryMessenger} from a
139 * plugin using the v2 embedding, see {@link
140 * FlutterPlugin.FlutterPluginBinding#getBinaryMessenger()}
141 *
142 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
143 * http://flutter.dev/go/android-plugin-migration
144 */
145 @NonNull
147
148 /**
149 * Returns a {@link TextureRegistry} which the plugin can use for managing backend textures.
150 *
151 * <p>This registrar is for Flutter's v1 embedding. To access a {@code TextureRegistry} from a
152 * plugin using the v2 embedding, see {@link
153 * FlutterPlugin.FlutterPluginBinding#getTextureRegistry()}
154 *
155 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
156 * http://flutter.dev/go/android-plugin-migration
157 */
158 @NonNull
160
161 /**
162 * Returns the application's {@link PlatformViewRegistry}.
163 *
164 * <p>Plugins can use the platform registry to register their view factories.
165 *
166 * <p>This registrar is for Flutter's v1 embedding. To access a {@code PlatformViewRegistry}
167 * from a plugin using the v2 embedding, see {@link
168 * FlutterPlugin.FlutterPluginBinding#getPlatformViewRegistry()}
169 *
170 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
171 * http://flutter.dev/go/android-plugin-migration
172 */
173 @NonNull
175
176 /**
177 * Returns the {@link FlutterView} that's instantiated by this plugin's {@link #activity()
178 * activity}.
179 *
180 * <p>This registrar is for Flutter's v1 embedding. The {@link FlutterView} referenced by this
181 * method does not exist in the v2 embedding. Additionally, no {@code View} is exposed to any
182 * plugins in the v2 embedding. Platform views can access their containing {@code View} using
183 * the platform views APIs. If you have a use-case that absolutely requires a plugin to access
184 * an Android {@code View}, please file a ticket on GitHub.
185 *
186 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
187 * http://flutter.dev/go/android-plugin-migration
188 */
189 @NonNull
191
192 /**
193 * Returns the file name for the given asset. The returned file name can be used to access the
194 * asset in the APK through the {@link android.content.res.AssetManager} API.
195 *
196 * <p>TODO(mattcarroll): point this method towards new lookup method.
197 *
198 * @param asset the name of the asset. The name can be hierarchical
199 * @return the filename to be used with {@link android.content.res.AssetManager}
200 */
201 @NonNull
202 String lookupKeyForAsset(@NonNull String asset);
203
204 /**
205 * Returns the file name for the given asset which originates from the specified packageName.
206 * The returned file name can be used to access the asset in the APK through the {@link
207 * android.content.res.AssetManager} API.
208 *
209 * <p>TODO(mattcarroll): point this method towards new lookup method.
210 *
211 * @param asset the name of the asset. The name can be hierarchical
212 * @param packageName the name of the package from which the asset originates
213 * @return the file name to be used with {@link android.content.res.AssetManager}
214 */
215 @NonNull
216 String lookupKeyForAsset(@NonNull String asset, @NonNull String packageName);
217
218 /**
219 * Publishes a value associated with the plugin being registered.
220 *
221 * <p>The published value is available to interested clients via {@link
222 * PluginRegistry#valuePublishedByPlugin(String)}.
223 *
224 * <p>Publication should be done only when client code needs to interact with the plugin in a
225 * way that cannot be accomplished by the plugin registering callbacks with client APIs.
226 *
227 * <p>Overwrites any previously published value.
228 *
229 * <p>This registrar is for Flutter's v1 embedding. The concept of publishing values from
230 * plugins is not supported in the v2 embedding.
231 *
232 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
233 * http://flutter.dev/go/android-plugin-migration
234 *
235 * @param value the value, possibly null.
236 * @return this {@link Registrar}.
237 */
238 @NonNull
239 Registrar publish(@Nullable Object value);
240
241 /**
242 * Adds a callback allowing the plugin to take part in handling incoming calls to {@code
243 * Activity#onRequestPermissionsResult(int, String[], int[])} or {@code
244 * androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int,
245 * String[], int[])}.
246 *
247 * <p>This registrar is for Flutter's v1 embedding. To listen for permission results in the v2
248 * embedding, use {@link
249 * ActivityPluginBinding#addRequestPermissionsResultListener(PluginRegistry.RequestPermissionsResultListener)}.
250 *
251 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
252 * http://flutter.dev/go/android-plugin-migration
253 *
254 * @param listener a {@link RequestPermissionsResultListener} callback.
255 * @return this {@link Registrar}.
256 */
257 @NonNull
259 @NonNull RequestPermissionsResultListener listener);
260
261 /**
262 * Adds a callback allowing the plugin to take part in handling incoming calls to {@link
263 * Activity#onActivityResult(int, int, Intent)}.
264 *
265 * <p>This registrar is for Flutter's v1 embedding. To listen for {@code Activity} results in
266 * the v2 embedding, use {@link
267 * ActivityPluginBinding#addActivityResultListener(PluginRegistry.ActivityResultListener)}.
268 *
269 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
270 * http://flutter.dev/go/android-plugin-migration
271 *
272 * @param listener an {@link ActivityResultListener} callback.
273 * @return this {@link Registrar}.
274 */
275 @NonNull
277
278 /**
279 * Adds a callback allowing the plugin to take part in handling incoming calls to {@link
280 * Activity#onNewIntent(Intent)}.
281 *
282 * <p>This registrar is for Flutter's v1 embedding. To listen for new {@code Intent}s in the v2
283 * embedding, use {@link
284 * ActivityPluginBinding#addOnNewIntentListener(PluginRegistry.NewIntentListener)}.
285 *
286 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
287 * http://flutter.dev/go/android-plugin-migration
288 *
289 * @param listener a {@link NewIntentListener} callback.
290 * @return this {@link Registrar}.
291 */
292 @NonNull
294
295 /**
296 * Adds a callback allowing the plugin to take part in handling incoming calls to {@link
297 * Activity#onUserLeaveHint()}.
298 *
299 * <p>This registrar is for Flutter's v1 embedding. To listen for leave hints in the v2
300 * embedding, use {@link
301 * ActivityPluginBinding#addOnUserLeaveHintListener(PluginRegistry.UserLeaveHintListener)}.
302 *
303 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
304 * http://flutter.dev/go/android-plugin-migration
305 *
306 * @param listener a {@link UserLeaveHintListener} callback.
307 * @return this {@link Registrar}.
308 */
309 @NonNull
311
312 /**
313 * Adds a callback allowing the plugin to take part in handling incoming calls to {@link
314 * Activity#onWindowFocusChanged(boolean)}.
315 *
316 * <p>This registrar is for Flutter's v1 embedding. To listen for leave hints in the v2
317 * embedding, use {@link
318 * ActivityPluginBinding#addOnWindowFocusChangedListener(PluginRegistry.WindowFocusChangedListener)}.
319 *
320 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
321 * http://flutter.dev/go/android-plugin-migration
322 *
323 * @param listener a {@link WindowFocusChangedListener} callback.
324 * @return this {@link Registrar}.
325 */
326 @NonNull
328
329 /**
330 * Adds a callback allowing the plugin to take part in handling incoming calls to {@link
331 * Activity#onDestroy()}.
332 *
333 * <p>This registrar is for Flutter's v1 embedding. The concept of {@code View} destruction does
334 * not exist in the v2 embedding. However, plugins in the v2 embedding can respond to {@link
335 * ActivityAware#onDetachedFromActivityForConfigChanges()} and {@link
336 * ActivityAware#onDetachedFromActivity()}, which indicate the loss of a visual context for the
337 * running Flutter experience. Developers should implement {@link ActivityAware} for their
338 * {@link FlutterPlugin} if such callbacks are needed. Also, plugins can respond to {@link
339 * FlutterPlugin#onDetachedFromEngine(FlutterPlugin.FlutterPluginBinding)}, which indicates that
340 * the given plugin has been completely disconnected from the associated Flutter experience and
341 * should clean up any resources.
342 *
343 * <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
344 * http://flutter.dev/go/android-plugin-migration
345 *
346 * @param listener a {@link ViewDestroyListener} callback.
347 * @return this {@link Registrar}.
348 */
349 // TODO(amirh): Add a line in the javadoc above that points to a Platform Views website guide
350 // when one is available (but not a website API doc)
351 @NonNull
353 }
354
355 /**
356 * Delegate interface for handling result of permissions requests on behalf of the main {@link
357 * Activity}.
358 */
360 /**
361 * @param requestCode The request code passed in {@code
362 * ActivityCompat.requestPermissions(android.app.Activity, String[], int)}.
363 * @param permissions The requested permissions.
364 * @param grantResults The grant results for the corresponding permissions which is either
365 * {@code PackageManager.PERMISSION_GRANTED} or {@code PackageManager.PERMISSION_DENIED}.
366 * @return true if the result has been handled.
367 */
369 int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults);
370 }
371
372 /**
373 * Delegate interface for handling activity results on behalf of the main {@link
374 * android.app.Activity}.
375 */
377 /**
378 * @param requestCode The integer request code originally supplied to {@code
379 * startActivityForResult()}, allowing you to identify who this result came from.
380 * @param resultCode The integer result code returned by the child activity through its {@code
381 * setResult()}.
382 * @param data An Intent, which can return result data to the caller (various data can be
383 * attached to Intent "extras").
384 * @return true if the result has been handled.
385 */
386 boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data);
387 }
388
389 /**
390 * Delegate interface for handling new intents on behalf of the main {@link android.app.Activity}.
391 */
393 /**
394 * @param intent The new intent that was started for the activity.
395 * @return true if the new intent has been handled.
396 */
397 boolean onNewIntent(@NonNull Intent intent);
398 }
399
400 /**
401 * Delegate interface for handling user leave hints on behalf of the main {@link
402 * android.app.Activity}.
403 */
406 }
407
408 /**
409 * Delegate interface for handling window focus changes on behalf of the main {@link
410 * android.app.Activity}.
411 */
413 void onWindowFocusChanged(boolean hasFocus);
414 }
415
416 /**
417 * Delegate interface for handling an {@link android.app.Activity}'s onDestroy method being
418 * called. A plugin that implements this interface can adopt the {@link FlutterNativeView} by
419 * retaining a reference and returning true.
420 *
421 * @deprecated See https://flutter.dev/go/android-project-migration for migration details.
422 */
423 @Deprecated
425 boolean onViewDestroy(@NonNull FlutterNativeView view);
426 }
427
428 /**
429 * Callback interface for registering plugins with a plugin registry.
430 *
431 * <p>For example, an Application may use this callback interface to provide a background service
432 * with a callback for calling its GeneratedPluginRegistrant.registerWith method.
433 *
434 * @deprecated See https://flutter.dev/go/android-project-migration for migration details.
435 */
436 @Deprecated
438 void registerWith(@NonNull PluginRegistry registry);
439 }
440}
uint8_t value
boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
Registrar addActivityResultListener(@NonNull ActivityResultListener listener)
Registrar publish(@Nullable Object value)
Registrar addNewIntentListener(@NonNull NewIntentListener listener)
String lookupKeyForAsset(@NonNull String asset)
String lookupKeyForAsset(@NonNull String asset, @NonNull String packageName)
Registrar addViewDestroyListener(@NonNull ViewDestroyListener listener)
Registrar addRequestPermissionsResultListener( @NonNull RequestPermissionsResultListener listener)
Registrar addUserLeaveHintListener(@NonNull UserLeaveHintListener listener)
Registrar addWindowFocusChangedListener(@NonNull WindowFocusChangedListener listener)
boolean onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
boolean onViewDestroy(@NonNull FlutterNativeView view)
boolean hasPlugin(@NonNull String pluginKey)
< T > T valuePublishedByPlugin(@NonNull String pluginKey)
Registrar registrarFor(@NonNull String pluginKey)
#define T
Definition: precompiler.cc:65
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63