Repository navigation
ADFA-7142: Keep plugin resource loaders off the activity's Resources - #2250
davidschachterADFA wants to merge 2 commits into
Conversation
Plugins built with their own resource package id resolved resources through the host activity's own Resources, and their first use added the plugin's ResourcesLoader to them. On Android 11+ addLoaders makes ResourcesManager build a new ResourcesImpl for the activity and rebase its themes, in the middle of the tab's first LayoutInflater.inflate; the views built then drew sp text at about half size (Note 20 Ultra, display size overridden to 720x1544). That the swap carries the wrong scale is inferred, not confirmed. PluginResourceContext now adds the loader to a copy made with createConfigurationContext from the activity's current configuration, and builds the plugin theme and PluginTheme lookup on that copy. The copy is cached against the activity (held weakly) and its full configuration, so a fontScale, uiMode or density change the activity handles in place rebuilds the copy and the theme. Before Android 11 there is no ResourcesLoader, and the in-place addAssetPath path stays as it was; the legacy (0x7f) path is untouched. A debug log prints the copy's fontScale, density and scaledDensity when it is built. PluginResourceContextActivityResourcesTest pins that a first inflation through the plugin inflater leaves the activity's Resources with no loaders and the same AssetManager, puts the loader on the copy, and that 15sp text through the plugin context matches the activity's, before and after a font-scale change applied to the activity in place. Robolectric does not reproduce the half-size text. Before the fix the loader assertion fails, and the two size tests crash in Robolectric's applyStyle CHECK because it has no shadow for the native theme rebase the swap triggers. Dropping the configuration from the cache key fails the font-scale test (81px vs 45px). Two existing tests that pinned resources === activity.resources now compare configurations. Needs a device check: plugin tab text (Shell-Hooks "Hooks", AI Core "Agent") at font scale 0.8, 1.0 and 2.0 on the Note 20 Ultra at 720x1544, with the logged values compared against the activity's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZWMkFWJh7CY7P4kCH
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
|
Device check on the Note 20 Ultra (build C-d-1113-1127, this PR at d815369): this fix breaks AI Core. The PR is converted to draft until a revised fix is checked.
Next: a revised fix that keeps the copy for plugin inflation and also adds the loader to the activity's |
…use it d815369 stopped adding a plugin's ResourcesLoader to the activity's own Resources. On the Note 20 Ultra that crashed AI Core's Agent tab ("No package ID 42 found for ID 0x420a0007"): AI Core resolves its own ids through the activity as well as through the plugin context. ChatFragment calls Fragment.getString and resources.getInteger, which go through requireContext(), and builds its dialogs on ContextThemeWrapper(requireContext(), R.style.PluginTheme), as FilePickerDialogFragment does. Those lookups only ever worked because every such plugin's loader sat on the activity's Resources. The activity's Resources get the loader again, as on stage, and before the copy is built, so that rebuild is done before any plugin view exists. getResources() and getTheme() still hand out the per-activity, per-configuration copy, so plugin views are never built on Resources that addLoaders has just rebuilt. ensurePluginResourcesAdded's patchedResources slot now tracks only the activity's Resources; each copy gets the loader once, through addPluginResources, when it is built. createConfigurationContext passes the base context's loaders on, so the copy usually starts with the loader already. The pre-R and legacy paths are unchanged, and getAssets()'s comment is back to stage's. PluginResourceContextActivityResourcesTest now pins: once the plugin context is used, its loader is on the activity's Resources and on a ContextThemeWrapper over the activity (AI Core's pattern); the plugin context's Resources are a different object that also carries it; inflated plugin views and the plugin theme are built on that copy; and 15sp resolves to the same pixels through both, also after a font-scale change applied to the activity in place. On d815369's code the activity-loader test fails and the rest pass. Robolectric cannot load an APK into a ResourcesLoader, so no plugin id is resolved, and it has no shadow for the native theme rebase that adding a loader to the activity triggers. A theme made on the activity's Resources before the patch then trips a CHECK when copied or used, so sp is compared through DisplayMetrics, and the inflation test snapshots a host theme made after the patch. Needs a device check: the Agent and Hooks tabs open without the package-id errors, plugin dialogs and strings resolve, plugin text is the right size at font scale 0.8, 1.0 and 2.0 at 720x1544, and the plugin theme still looks right now that it is copied from the activity's theme across AssetManagers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZWMkFWJh7CY7P4kCH
|
Device check on C-d-1113-1314 (Note 20 Ultra): fails. Keep this a draft; this PR's cause is wrong.
The resource changes here don't address it. The direction is an open question on ADFA-7142. |
|
Superseded by #2255. The device check showed the cause was ADFA-4212's text scaling, not plugin Resources (see the comment above), so these Resources changes aren't needed. |
ADFA-7142
In plugin tabs in the editor's bottom panel (Shell-Hooks' "Hooks", AI Core's "Agent"), text in the views a tab builds on first inflation was drawn at about half its sp size. dp sizes were right, and views added later were normal. Found in ADFA-3570's device QA on a Note 20 Ultra.
Cause
PluginResourceContext.getResources()/getTheme()returned the host activity's ownResources. The first time a tab inflated,ensurePluginResourcesAddedcalledactivity.resources.addLoaders(...)in the middle of that inflation. On Android 11+,addLoadersmakes the framework build a newResourcesImplfor the activity and rebase its themes (checked in the SDK sources).EditorActivityKthandlesfontScalechanges itself, which may matter.Change
getResources()andgetTheme()use a copy of the activity's resources:createConfigurationContext(Configuration(activity config)). The plugin'sResourcesLoadergoes on the copy. The activity's ownResourcesare never changed.fontScale,densityandscaledDensitywhen it is built, so a device run can confirm them.addAssetPath; minSdk is 28), legacy plugins, and per-plugingetAssets()(ADFA-6794).Sibling sweep
PluginFragmentHelper.getPluginInflater,PluginManager's registration and itsgetAssetsuse for languages.EditorBottomSheetTabAdapterandPluginFragmentFactory: class loaders only.PluginScreenActivity,PluginEditorTabManager, andPluginTabDockableContent's overlay context.PluginDrawableResolverandgetIdentifier, which now resolve through the copy. It still holds the host APK.addAssetPathsites.PluginLoaderandPluginDocumentationManageruse fresh, plugin-only AssetManagers, and quickbuild and the profiler run in other processes.Testing
PluginResourceContextActivityResourcesTest(Robolectric, sdk 34) asserts three things: the activity'sresourceshave no loaders after resolving through the plugin context; 15sp gives the same pixels through the plugin and through the activity; and they still agree after a font-scale change.addLoaderstriggers. That's a side effect of the same mutation, not the size bug.ResourcesProvider, so the test injects an empty loader by reflection.resources === app.resourcesnow compare configurations.spotlessCheckis clean, and:app:compileV8DebugKotlinbuilds.Theme.setTonow copies across AssetManagers.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAZWMkFWJh7CY7P4kCH