Potentially fix 'database is locked' crash

# Conflicts:
#	CHANGELOG.md
#	app/src/main/java/eu/kanade/tachiyomi/di/AppModule.kt
This commit is contained in:
AntsyLich
2026-03-23 20:13:39 +06:00
committed by Jobobby04
parent 4552221020
commit 925fb118af
2 changed files with 32 additions and 24 deletions
-1
View File
@@ -204,7 +204,6 @@ dependencies {
implementation(sylibs.sqlcipher)
// SY <--
implementation(libs.kotlin.reflect)
implementation(libs.kotlinx.collections.immutable)
@@ -53,21 +53,29 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.InjektRegistrar
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.lang.ref.WeakReference
private val lock = Any()
class AppModule(val app: Application) : InjektModule {
// SY -->
private val securityPreferences: SecurityPreferences by injectLazy()
// SY <--
private var sqlDriverRef: WeakReference<SqlDriver>? = null
override fun InjektRegistrar.registerInjectables() {
addSingleton(app)
addSingletonFactory<SqlDriver> {
synchronized(lock) {
sqlDriverRef?.get()?.let { return@synchronized it }
// SY -->
if (securityPreferences.encryptDatabase.get()) {
System.loadLibrary("sqlcipher")
return@addSingletonFactory AndroidSqliteDriver(
return@synchronized AndroidSqliteDriver(
schema = Database.Schema,
context = app,
name = CbzCrypto.DATABASE_NAME,
@@ -86,7 +94,8 @@ class AppModule(val app: Application) : InjektModule {
cursor.close()
}
},
)
).also { sqlDriverRef = WeakReference(it) }
}
}
// SY <--
@@ -97,7 +106,7 @@ class AppModule(val app: Application) : InjektModule {
configuration = AndroidxSqliteConfiguration(
isForeignKeyConstraintsEnabled = true,
),
)
).also { sqlDriverRef = WeakReference(it) }
}
addSingletonFactory {
Database(