Skip to content

Commit a099efe

Browse files
committed
Force using readonly database for getModulePrefs
1 parent ec23fd8 commit a099efe

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,30 @@ object PreferenceStore {
88

99
fun getModulePrefs(packageName: String, userId: Int, group: String): Map<String, Any> {
1010
val result = mutableMapOf<String, Any>()
11-
ConfigCache.dbHelper.readableDatabase
12-
.query(
13-
"configs",
14-
arrayOf("`key`", "data"),
15-
"module_pkg_name = ? AND user_id = ? AND `group` = ?",
16-
arrayOf(packageName, userId.toString(), group),
17-
null,
18-
null,
19-
null)
20-
.use { cursor ->
21-
while (cursor.moveToNext()) {
22-
val key = cursor.getString(0)
23-
val blob = cursor.getBlob(1)
24-
val obj = SerializationUtilsX.deserialize<Any>(blob)
25-
if (obj != null) result[key] = obj
11+
val db =
12+
runCatching {
13+
SQLiteDatabase.openDatabase(
14+
FileSystem.dbPath.absolutePath, null, SQLiteDatabase.OPEN_READONLY)
15+
}
16+
.getOrNull() ?: return result
17+
db.use {
18+
it.query(
19+
"configs",
20+
arrayOf("`key`", "data"),
21+
"module_pkg_name = ? AND user_id = ? AND `group` = ?",
22+
arrayOf(packageName, userId.toString(), group),
23+
null,
24+
null,
25+
null)
26+
.use { cursor ->
27+
while (cursor.moveToNext()) {
28+
val key = cursor.getString(0)
29+
val blob = cursor.getBlob(1)
30+
val obj = SerializationUtilsX.deserialize<Any>(blob)
31+
if (obj != null) result[key] = obj
32+
}
2633
}
27-
}
34+
}
2835
return result
2936
}
3037

0 commit comments

Comments
 (0)