feat(native): database lock

- refactor native
This commit is contained in:
rhunk
2024-01-25 23:26:54 +01:00
parent 5563418d79
commit 4fd268c4dc
11 changed files with 275 additions and 159 deletions

View File

@ -183,7 +183,7 @@ class SnapEnhance {
val libName = param.arg<String>(2)
if (libName != "client") return@hook
unhook()
appContext.native.initOnce(appContext.androidContext.classLoader)
appContext.native.initOnce()
appContext.native.nativeUnaryCallCallback = { request ->
appContext.event.post(NativeUnaryCallEvent(request.uri, request.buffer)) {
request.buffer = buffer

View File

@ -17,6 +17,7 @@ import me.rhunk.snapenhance.common.util.ktx.getStringOrNull
import me.rhunk.snapenhance.common.util.protobuf.ProtoReader
import me.rhunk.snapenhance.core.ModContext
import me.rhunk.snapenhance.core.manager.Manager
import me.rhunk.snapenhance.nativelib.NativeLib
enum class DatabaseType(
@ -59,9 +60,15 @@ class DatabaseAccess(
}
private inline fun <T> SQLiteDatabase.performOperation(crossinline query: SQLiteDatabase.() -> T?): T? {
private fun <T> SQLiteDatabase.performOperation(query: SQLiteDatabase.() -> T?): T? {
return runCatching {
synchronized(this) {
if (NativeLib.initialized && openedDatabases[DatabaseType.ARROYO] == this) {
var result: T? = null
context.native.lockNativeDatabase(DatabaseType.ARROYO.fileName) {
result = query()
}
result
} else synchronized(this) {
query()
}
}.onFailure {