Repository navigation
Conversation
Reinstalling a module and starting one of its targets right away handed the target the module as it was before the install. The package manager deletes the old /data/app directory as soon as the install returns, but the cache only moves to the new APK once ACTION_PACKAGE_ADDED reaches the daemon and performCacheUpdate has read the module again. Until that state is swapped in, getModulesForProcess serves the old LoadedModule: an apkPath that no longer exists, and the code that was read from it. The window is the delivery of the broadcast plus the rebuild, and the rebuild is the long part on release builds, where every dex of the module is obfuscated as it is read. With a module of about 100 MB it stayed open for roughly 2.5 seconds after `pm install` returned; on a debug build, which does not obfuscate, it is under a second and hard to hit. A target started inside it logs "VectorModuleClassLoader: Cannot open" for the deleted path, and whatever the module reads from its own APK fails: resources injected from it failed about 80 times per start. getModulesForProcess now checks that the APK of every module it is about to hand out still exists. When one is gone it takes the rebuild lock, which waits out a rebuild already running, and runs one itself if the state is still stale after that. performCacheUpdate already falls back to the package manager's path when the stored one is missing, so this holds even before the broadcast has arrived. A normal start only pays for a stat per module. Measured on Android 13 with a release build. Starting the target 0.5 to 1.8 seconds after `pm install`, 8 starts out of 8 got the deleted path before this change. With it, 6 starts out of 6 at 0.5 to 0.9 seconds got the new APK, the process waiting 0.36 to 1.95 seconds for the rebuild instead of the usual 0.05.
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.
Reinstalling a module and starting one of its targets right away handed the target the module as it was before the install. The package manager deletes the old
/data/appdirectory as soon as the install returns, but the cache only moves to the new APK onceACTION_PACKAGE_ADDEDreaches the daemon andperformCacheUpdatehas read the module again. Until that state is swapped in,getModulesForProcessserves the oldLoadedModule: anapkPaththat no longer exists, and the code that was read from it.The window is the delivery of the broadcast plus the rebuild, and the rebuild is the long part on release builds, where every dex of the module is obfuscated as it is read. With a module of about 100 MB it stayed open for roughly 2.5 seconds after
pm installreturned; on a debug build, which does not obfuscate, it is under a second and hard to hit. A target started inside it logsVectorModuleClassLoader: Cannot openfor the deleted path, and whatever the module reads from its own APK fails: resources injected from it failed about 80 times per start.getModulesForProcessnow checks that the APK of every module it is about to hand out still exists. When one is gone it takes the rebuild lock, which waits out a rebuild already running, and runs one itself if the state is still stale after that.performCacheUpdatealready falls back to the package manager's path when the stored one is missing, so this holds even before the broadcast has arrived. A normal start only pays for a stat per module.Measured on Android 13 with a release build. Starting the target 0.5 to 1.8 seconds after
pm install, 8 starts out of 8 got the deleted path before this change. With it, 6 starts out of 6 at 0.5 to 0.9 seconds got the new APK, the process waiting 0.36 to 1.95 seconds for the rebuild instead of the usual 0.05.