Potentially fix 'database is locked' crash
# Conflicts: # CHANGELOG.md # app/src/main/java/eu/kanade/tachiyomi/di/AppModule.kt
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user