Skip to content

Commit fca40ed

Browse files
committed
Let a hand-built LoadedApk opt into the API 101 lifecycle
The API 101 onPackageLoaded/onPackageReady callbacks dispatch from the LoadedApk.createAppFactory and createOrUpdateClassLoaderLocked hooks, gated on LoadedApkTracker. A host that builds a LoadedApk by hand, before those hooks exist, never registers with the tracker, so expose VectorStartup.trackLoadedApk (with a Startup facade) to enrol its instance and widen LoadedApkTracker to internal. Once tracked, onPackageLoaded dispatches before the app's AppComponentFactory initializer, as the API requires.
1 parent 8a15649 commit fca40ed

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

legacy/src/main/java/org/matrix/vector/Startup.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ public static void bootstrapXposed(boolean systemServerStarted) {
2020
}
2121
}
2222

23+
/**
24+
* Registers a pre-built {@code LoadedApk} (the LSPatch rootless target) with the modern hooks so
25+
* its package lifecycle is dispatched when its class loader is realized. See
26+
* {@link VectorStartup#trackLoadedApk(Object)}.
27+
*/
28+
public static void trackLoadedApk(Object loadedApk) {
29+
VectorStartup.trackLoadedApk(loadedApk);
30+
}
31+
2332
public static void initXposed(boolean isSystem, String processName, String appDir, IFrameworkService service) {
2433
// Establish the Dependency Injection contract
2534
VectorBootstrap.INSTANCE.init(new LegacyDelegateImpl());

xposed/src/main/kotlin/org/matrix/vector/impl/core/VectorStartup.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ object VectorStartup {
2727
VectorDeopter.deoptBootMethods()
2828
}
2929

30+
/**
31+
* Registers a pre-built [LoadedApk] whose constructor ran before the hooks were installed -- the
32+
* LSPatch rootless target being the one case. Once tracked, [LoadedApkCreateAppFactoryHooker] and
33+
* [LoadedApkCreateCLHooker] dispatch its `onPackageLoaded`/`onPackageReady` (and legacy
34+
* `handleLoadPackage`) exactly once when its class loader is realized, with `onPackageLoaded`
35+
* running *before* the app's `AppComponentFactory` static initializer.
36+
*/
37+
@JvmStatic
38+
fun trackLoadedApk(loadedApk: Any) {
39+
LoadedApkTracker.activeApks.add(loadedApk)
40+
}
41+
3042
@JvmStatic
3143
fun bootstrap(isSystem: Boolean, systemServerStarted: Boolean) {
3244
// Crash Dump Interceptor

xposed/src/main/kotlin/org/matrix/vector/impl/hookers/LoadedApkHookers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private object PackageContextHelper {
8080
}
8181

8282
/** Identity-based tracking for LoadedApk instances. */
83-
private object LoadedApkTracker {
83+
internal object LoadedApkTracker {
8484
// Tracks LoadedApk instances that are currently in their initial bootstrap phase
8585
val activeApks: MutableSet<Any> =
8686
Collections.synchronizedSet(Collections.newSetFromMap(WeakHashMap()))

0 commit comments

Comments
 (0)