Repository navigation
Give the daemon's drawable cache a context on MediaTek ROMs - #1115
Open
ShakaRover wants to merge 1 commit into
Open
ShakaRover wants to merge 1 commit into
ShakaRover wants to merge 1 commit into
Conversation
MediaTek's "res opt" patch, which ships on MTK devices running MIUI and HyperOS, parks the process's app context in a static ResourcesImpl.mAppContext that only ContextImpl.createAppContext writes, then dereferences it from AsyncDrawableCache.putCacheList with no null guard on several builds (JingMatrix/Vector JingMatrix#271, JingMatrix#996). The daemon never calls createAppContext, so loading ic_statue_monochrome through the bare FileSystem.resources hands that cache a null context — the fatal coroutine exception in JingMatrix#996's report is exactly this path. Wherever the ROM exposes ResourcesImpl.setAppContext, hand the cache a FakeContext whose ApplicationInfo carries a process name, which keeps putCacheList on its early-return path; everywhere else the reflection misses and nothing changes. Complete FakeContext's fallback ApplicationInfo along the way: the archive parser fills in no process name at all, so a blank info would walk the same guard straight into the null-base ContextWrapper. Verified against the ROM of a Redmi 23046PNC9C (MIUI 14 V816, Android 13, MTK): the smali shows putCacheList evaluating isEnableFeature, skipPreload, processName.equals("system") and isSystemApp in that order, with that static mAppContext as the only context the cache ever sees.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On MTK devices running MIUI/HyperOS, the daemon dies with
Known reports in this family: #271 (
ic_notification), #996 (fatal coroutine exception in the daemon), LSPosed/LSPosed#1339 (same chain in the old daemon). All were closed as ROM-specific without a code fix.Root cause (verified against a real ROM, not guessed)
I pulled
/system_ext/framework/mediatek-framework.jarand/system/framework/framework.jaroff a Redmi 23046PNC9C (MIUI 14 V816, Android 13, Dimensity) and read the smali:ResOptExtImpl.putCacheList(key, dr, origResId, mAppContext)fromResourcesImpl.cacheDrawablefor every cached non-color drawable.mAppContextis a static field onResourcesImplwhose only writer isContextImpl.createAppContext— so it always holds "the last app context created in this process".AsyncDrawableCache.putCacheList(line 189 on this build) evaluates, in order:isEnableFeature()→skipPreload(context)(the only null guard) →context.getApplicationInfo().processName.equals("system")→isSystemApp().createAppContext(it builds its context-lessFileSystem.resourcesas a bareResources(am, null, null)), somAppContextis null there and every ROM variant of that guard chain has some way to NPE: older builds dereference the nullcontextdirectly (#1339 line 164, Parasitic manager failed due to icon resource not found #271 line 165), newer builds null-deref a field of the application info ([Bug] Temporary-root (locked BL, KernelSU LKM late-load) on Android 17 / HyperOS 4: VectorDaemon dies with StackOverflowError (kk.onTransact recursion 32×) → framework never activates #996 line 189).LSPosed/LSPosed#1954 worked around the same family by
resetprop ro.vendor.pref_scale_enable_cfg 0(the feature gate) — this PR fixes it in our code instead.Fix
Wherever the ROM exposes
ResourcesImpl.setAppContext, the daemon'sFileSystem.resourcesnow hands the cache aFakeContextwhoseApplicationInfocarries a process name, which keepsputCacheListon its early-return path (isSystemApp()is true for the framework info; the fallback claims the system process). Everywhere else the reflection misses and the change is a no-op.FakeContext.getApplicationInfo's blank fallback also gets a process name now — the archive parser fills in nothing, so a blank info would walk the same guard straight into the null-baseContextWrapper(getSharedPreferences,getSystemService).ParasiticManagerHookerneeded no change: it already transplants the host's process name into its fabricatedApplicationInfo.Verification
./gradlew :daemon:compileReleaseKotlingreen on this branch.mAppContextmechanism, triggered through a module context we fabricate in our downstream fork); the daemon-side fix targets the identical ROM mechanism that killed the daemon in [Bug] Temporary-root (locked BL, KernelSU LKM late-load) on Android 17 / HyperOS 4: VectorDaemon dies with StackOverflowError (kk.onTransact recursion 32×) → framework never activates #996.runCatching, no behavior change elsewhere).Fixes #271, fixes #996 (the drawable half; the
kk.onTransactrecursion in #996 is a separate daemon binder issue).