pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/flutter/flutter/pull/182963/files

mous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/code-bedb41adf21fe337.css" /> [Android] Avoid plugin auto-registration during FlutterFragmentActivity recreate timing window by littleGnAl · Pull Request #182963 · flutter/flutter · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,17 @@ public FlutterEngine provideFlutterEngine(@NonNull Context context) {
*/
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
if (flutterFragment != null && flutterFragment.isFlutterEngineInjected()) {
FlutterFragment attachedFlutterFragment = flutterFragment;
if (attachedFlutterFragment == null) {
// During activity recreation, `FragmentManager` may restore and attach an existing
// `FlutterFragment` before `ensureFlutterFragmentCreated()` refreshes the
// `flutterFragment` field.
// Query by tag here so plugin auto-registration can still honor the injected-engine guard.
// Keep `flutterFragment` field ownership in `ensureFlutterFragmentCreated()`; this lookup
// only informs the guard.
attachedFlutterFragment = retrieveExistingFlutterFragmentIfPossible();
}
if (attachedFlutterFragment != null && attachedFlutterFragment.isFlutterEngineInjected()) {
// If the FlutterEngine was explicitly built and injected into this FlutterActivity, the
// builder should explicitly decide whether to automatically register plugins via the
// FlutterEngine's construction parameter or via the AndroidManifest metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,48 @@ public void itHandlesNewFragmentRecreationDuringRestoreWhenActivityIsRecreated()
assertEquals(0, activity.numberOfEnginesCreated);
}

@Test
public void configureFlutterEngine_doesNotRegisterPluginsWhenRecoveredInjectedFragmentIsFound() {
FlutterFragmentActivityWithProvidedEngine activity =
spy(Robolectric.buildActivity(FlutterFragmentActivityWithProvidedEngine.class).get());

FlutterFragment fragment = mock(FlutterFragment.class);
when(fragment.isFlutterEngineInjected()).thenReturn(true);
when(activity.retrieveExistingFlutterFragmentIfPossible()).thenReturn(fragment);

FlutterEngine engine = mock(FlutterEngine.class);
activity.configureFlutterEngine(engine);

assertTrue(GeneratedPluginRegistrant.getRegisteredEngines().isEmpty());
}

@Test
public void recreate_withCachedEngine_doesNotRegisterPlugins() {
FlutterLoader mockFlutterLoader = mock(FlutterLoader.class);
FlutterJNI mockFlutterJni = mock(FlutterJNI.class);
when(mockFlutterJni.isAttached()).thenReturn(true);
when(mockFlutterLoader.automaticallyRegisterPlugins()).thenReturn(false);

FlutterEngine cachedEngine =
new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni, new String[] {}, false);
final String cachedEngineId = "recreate_cached_engine";
FlutterEngineCache.getInstance().put(cachedEngineId, cachedEngine);
Intent intent = FlutterFragmentActivity.withCachedEngine(cachedEngineId).build(ctx);

try (ActivityScenario<FlutterFragmentActivity> scenario = ActivityScenario.launch(intent)) {
scenario.onActivity(
activity -> assertTrue(GeneratedPluginRegistrant.getRegisteredEngines().isEmpty()));

scenario.recreate();

scenario.onActivity(
activity -> assertTrue(GeneratedPluginRegistrant.getRegisteredEngines().isEmpty()));
} finally {
FlutterEngineCache.getInstance().remove(cachedEngineId);
cachedEngine.destroy();
}
}

@Test
@Config(minSdk = Build.API_LEVELS.API_34)
@TargetApi(Build.API_LEVELS.API_34)
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy