Skip to content

Commit 49efde1

Browse files
committed
Load a legacy module into its own process again
A legacy module reports being active by hooking a method in its own app, so it has to be in its own scope before it can say anything at all. The View-era manager added that row on every save -- `if (legacy) list.add(self)` -- and hid it again on read. #796 dropped both halves: ScopeViewModel.apply writes the draft verbatim, and ConfigCache builds its scope map from the stored rows alone. Every legacy module has reported itself inactive since (#816). ConfigCache derives the scope during the rebuild now, so configurations written by those builds need no repair and nothing that replaces the scope table can drop it again. Legacy is the loader's own verdict, the strategy loadModule settled on, so an API 101 module keeps its own process to itself. Insertions go through one helper, because a module can now reach the same process by more than one route.
1 parent 61c89db commit 49efde1

1 file changed

Lines changed: 34 additions & 7 deletions

File tree

daemon/src/main/kotlin/org/matrix/vector/daemon/data/ConfigCache.kt

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,15 @@ object ConfigCache {
270270
}
271271

272272
val newScopes = mutableMapOf<ProcessScope, MutableList<Module>>()
273+
274+
// A module can reach the same process by more than one route: self rows in two users each
275+
// propagate into the other's, and the scope derived below can name a process a row named as
276+
// well. Twice in the list is twice loaded, so every insertion goes through here.
277+
fun addToScope(processName: String, uid: Int, module: Module) {
278+
val modules = newScopes.getOrPut(ProcessScope(processName, uid)) { mutableListOf() }
279+
if (modules.none { it === module }) modules.add(module)
280+
}
281+
273282
ModuleDatabase.enabledScopeRows().forEach { scopeRow ->
274283
val appPkg = scopeRow.appPackage
275284
val modPkg = scopeRow.modulePackage
@@ -278,7 +287,7 @@ object ConfigCache {
278287
val module = newModules[modPkg] ?: return@forEach
279288

280289
if (appPkg == "system") {
281-
newScopes.getOrPut(ProcessScope("system_server", 1000)) { mutableListOf() }.add(module)
290+
addToScope("system_server", 1000, module)
282291
return@forEach
283292
}
284293

@@ -291,22 +300,40 @@ object ConfigCache {
291300
val appUid = pkgInfo.applicationInfo!!.uid
292301

293302
for (processName in processNames) {
294-
val processScope = ProcessScope(processName, appUid)
295-
newScopes.getOrPut(processScope) { mutableListOf() }.add(module)
303+
addToScope(processName, appUid, module)
296304

297305
if (modPkg == appPkg) {
298306
val appId = appUid % PER_USER_RANGE
299307
userManager?.getRealUsers()?.forEach { user ->
300308
val moduleUid = user.id * PER_USER_RANGE + appId
301-
if (moduleUid != appUid) {
302-
val moduleSelf = ProcessScope(processName, moduleUid)
303-
newScopes.getOrPut(moduleSelf) { mutableListOf() }.add(module)
304-
}
309+
if (moduleUid != appUid) addToScope(processName, moduleUid, module)
305310
}
306311
}
307312
}
308313
}
309314

315+
// A legacy module reports being active by hooking a method in its own app, so it has to be
316+
// in its own scope before it can say anything at all. The manager used to add that row on
317+
// every save and hide it again on read; #796 dropped both halves, and every legacy module
318+
// has reported itself inactive since (#816).
319+
//
320+
// Derived here rather than stored, so a configuration written by those builds needs no
321+
// repair and nothing that replaces the scope table can drop it again. Legacy is the
322+
// loader's own verdict, so a module built against API 101 keeps its own process to itself.
323+
newModules.values
324+
.filter { it.file?.legacy == true }
325+
.forEach { module ->
326+
userManager?.getRealUsers()?.forEach { user ->
327+
val pkgInfo =
328+
packageManager?.getPackageInfoWithComponents(
329+
module.packageName, MATCH_ALL_FLAGS, user.id) ?: return@forEach
330+
val moduleUid = pkgInfo.applicationInfo?.uid ?: return@forEach
331+
pkgInfo.fetchProcesses().forEach { processName ->
332+
addToScope(processName, moduleUid, module)
333+
}
334+
}
335+
}
336+
310337
// --- ATOMIC STATE SWAP ---
311338
//
312339
// Against the *current* state, not against the copy taken at the top of this function. A

0 commit comments

Comments
 (0)