From a1e0df6494c1cd28ae449d1cce856121263460cf Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Fri, 17 Apr 2026 15:59:28 +0200 Subject: [PATCH] Implement missing `auto_include` feature in daemon During the previous refactor #597, we forget to implement the `auto_include` feature. --- .../org/matrix/vector/daemon/VectorService.kt | 33 ++++++++++++++++--- .../matrix/vector/daemon/data/ConfigCache.kt | 14 ++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt index 9ac0cf3a7..1306ff550 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt @@ -16,6 +16,7 @@ import android.util.Log import hidden.HiddenApiBridge import io.github.libxposed.service.IXposedScopeCallback import kotlinx.coroutines.launch +import org.lsposed.lspd.models.Application import org.lsposed.lspd.service.IDaemonService import org.lsposed.lspd.service.ILSPApplicationService import org.matrix.vector.daemon.data.ConfigCache @@ -275,10 +276,32 @@ object VectorService : IDaemonService.Stub() { isXposedModule = ModuleDatabase.updateModuleApkPath( moduleName, ConfigCache.getModuleApkPath(appInfo), false) - } else if (ConfigCache.state.scopes.keys.any { it.uid == uid }) { - // If not a module, but it's an app that was previously a "scope" (target) - // for a module, we need to refresh the cache. - ConfigCache.requestCacheUpdate() + } else { + if (ConfigCache.state.scopes.keys.any { it.uid == uid }) { + // If not a module, but it's an app that was previously a "scope" (target) + // for a module, we need to refresh the cache. + ConfigCache.requestCacheUpdate() + } + + if (action == Intent.ACTION_PACKAGE_ADDED && + !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false) && + moduleName != null) { + + ConfigCache.getAutoIncludeModules().forEach { xposedModule -> + val scopeList = ConfigCache.getModuleScope(xposedModule) ?: mutableListOf() + + val newScope = + Application().apply { + this.packageName = moduleName + this.userId = userId + } + + scopeList.add(newScope) + if (!ModuleDatabase.setModuleScope(xposedModule, scopeList)) { + Log.e(TAG, "Failed to auto-include $moduleName for $xposedModule") + } + } + } } } Intent.ACTION_UID_REMOVED -> { @@ -353,7 +376,7 @@ object VectorService : IDaemonService.Stub() { val scopes = ConfigCache.getModuleScope(packageName) ?: mutableListOf() if (scopes.none { it.packageName == scopePackageName && it.userId == userId }) { scopes.add( - org.lsposed.lspd.models.Application().apply { + Application().apply { this.packageName = scopePackageName this.userId = userId }) diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/data/ConfigCache.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/data/ConfigCache.kt index a4d8963c7..cfeb9d107 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/data/ConfigCache.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/data/ConfigCache.kt @@ -314,6 +314,20 @@ object ConfigCache { return isAutoInclude } + fun getAutoIncludeModules(): List { + val result = mutableListOf() + ConfigCache.dbHelper.readableDatabase + .query("modules", arrayOf("module_pkg_name"), "auto_include = 1", null, null, null, null) + .use { cursor -> + val idx = cursor.getColumnIndexOrThrow("module_pkg_name") + while (cursor.moveToNext()) { + val pkgName = cursor.getString(idx) + if (pkgName != "lspd") result.add(pkgName) + } + } + return result + } + fun getModulesForProcess(processName: String, uid: Int): List { ensureCacheReady() if (processName == "system_server") {