Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,20 @@ object ConfigCache {
return isAutoInclude
}

fun getAutoIncludeModules(): List<String> {
val result = mutableListOf<String>()
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<Module> {
ensureCacheReady()
if (processName == "system_server") {
Expand Down
Loading