Skip to content

Commit 6990e7e

Browse files
authored
Implement missing auto_include feature in daemon (#681)
During the previous refactor #597, we forget to implement the `auto_include` feature.
1 parent 846527e commit 6990e7e

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import android.util.Log
1616
import hidden.HiddenApiBridge
1717
import io.github.libxposed.service.IXposedScopeCallback
1818
import kotlinx.coroutines.launch
19+
import org.lsposed.lspd.models.Application
1920
import org.lsposed.lspd.service.IDaemonService
2021
import org.lsposed.lspd.service.ILSPApplicationService
2122
import org.matrix.vector.daemon.data.ConfigCache
@@ -275,10 +276,32 @@ object VectorService : IDaemonService.Stub() {
275276
isXposedModule =
276277
ModuleDatabase.updateModuleApkPath(
277278
moduleName, ConfigCache.getModuleApkPath(appInfo), false)
278-
} else if (ConfigCache.state.scopes.keys.any { it.uid == uid }) {
279-
// If not a module, but it's an app that was previously a "scope" (target)
280-
// for a module, we need to refresh the cache.
281-
ConfigCache.requestCacheUpdate()
279+
} else {
280+
if (ConfigCache.state.scopes.keys.any { it.uid == uid }) {
281+
// If not a module, but it's an app that was previously a "scope" (target)
282+
// for a module, we need to refresh the cache.
283+
ConfigCache.requestCacheUpdate()
284+
}
285+
286+
if (action == Intent.ACTION_PACKAGE_ADDED &&
287+
!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false) &&
288+
moduleName != null) {
289+
290+
ConfigCache.getAutoIncludeModules().forEach { xposedModule ->
291+
val scopeList = ConfigCache.getModuleScope(xposedModule) ?: mutableListOf()
292+
293+
val newScope =
294+
Application().apply {
295+
this.packageName = moduleName
296+
this.userId = userId
297+
}
298+
299+
scopeList.add(newScope)
300+
if (!ModuleDatabase.setModuleScope(xposedModule, scopeList)) {
301+
Log.e(TAG, "Failed to auto-include $moduleName for $xposedModule")
302+
}
303+
}
304+
}
282305
}
283306
}
284307
Intent.ACTION_UID_REMOVED -> {
@@ -353,7 +376,7 @@ object VectorService : IDaemonService.Stub() {
353376
val scopes = ConfigCache.getModuleScope(packageName) ?: mutableListOf()
354377
if (scopes.none { it.packageName == scopePackageName && it.userId == userId }) {
355378
scopes.add(
356-
org.lsposed.lspd.models.Application().apply {
379+
Application().apply {
357380
this.packageName = scopePackageName
358381
this.userId = userId
359382
})

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,20 @@ object ConfigCache {
314314
return isAutoInclude
315315
}
316316

317+
fun getAutoIncludeModules(): List<String> {
318+
val result = mutableListOf<String>()
319+
ConfigCache.dbHelper.readableDatabase
320+
.query("modules", arrayOf("module_pkg_name"), "auto_include = 1", null, null, null, null)
321+
.use { cursor ->
322+
val idx = cursor.getColumnIndexOrThrow("module_pkg_name")
323+
while (cursor.moveToNext()) {
324+
val pkgName = cursor.getString(idx)
325+
if (pkgName != "lspd") result.add(pkgName)
326+
}
327+
}
328+
return result
329+
}
330+
317331
fun getModulesForProcess(processName: String, uid: Int): List<Module> {
318332
ensureCacheReady()
319333
if (processName == "system_server") {

0 commit comments

Comments
 (0)