Fix manager package name database management

This commit is contained in:
topjohnwu 2019-08-12 03:31:59 -07:00
parent e6561e5f84
commit 84f0ff2fad
2 changed files with 19 additions and 16 deletions

View File

@ -2,7 +2,6 @@ package com.topjohnwu.magisk.data.repository
import com.topjohnwu.magisk.data.database.SettingsDao import com.topjohnwu.magisk.data.database.SettingsDao
import com.topjohnwu.magisk.data.database.StringDao import com.topjohnwu.magisk.data.database.StringDao
import com.topjohnwu.magisk.extensions.trimEmptyToNull
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import kotlin.properties.ReadWriteProperty import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
@ -36,12 +35,10 @@ class DBSettingsValue(
private var value: Int? = null private var value: Int? = null
private fun getKey(property: KProperty<*>) = name.trimEmptyToNull() ?: property.name
@Synchronized @Synchronized
override fun getValue(thisRef: DBConfig, property: KProperty<*>): Int { override fun getValue(thisRef: DBConfig, property: KProperty<*>): Int {
if (value == null) if (value == null)
value = thisRef.settingsDao.fetch(getKey(property), default).blockingGet() value = thisRef.settingsDao.fetch(name, default).blockingGet()
return value!! return value!!
} }
@ -49,7 +46,7 @@ class DBSettingsValue(
synchronized(this) { synchronized(this) {
this.value = value this.value = value
} }
thisRef.settingsDao.put(getKey(property), value) thisRef.settingsDao.put(name, value)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.subscribe() .subscribe()
} }
@ -77,12 +74,10 @@ class DBStringsValue(
private var value: String? = null private var value: String? = null
private fun getKey(property: KProperty<*>) = name.trimEmptyToNull() ?: property.name
@Synchronized @Synchronized
override fun getValue(thisRef: DBConfig, property: KProperty<*>): String { override fun getValue(thisRef: DBConfig, property: KProperty<*>): String {
if (value == null) if (value == null)
value = thisRef.stringDao.fetch(getKey(property), default).blockingGet() value = thisRef.stringDao.fetch(name, default).blockingGet()
return value!! return value!!
} }
@ -90,12 +85,22 @@ class DBStringsValue(
synchronized(this) { synchronized(this) {
this.value = value this.value = value
} }
if (sync) { if (value.isEmpty()) {
thisRef.stringDao.put(getKey(property), value).blockingAwait() if (sync) {
thisRef.stringDao.delete(name).blockingAwait()
} else {
thisRef.stringDao.delete(name)
.subscribeOn(Schedulers.io())
.subscribe()
}
} else { } else {
thisRef.stringDao.put(getKey(property), value) if (sync) {
.subscribeOn(Schedulers.io()) thisRef.stringDao.put(name, value).blockingAwait()
.subscribe() } else {
thisRef.stringDao.put(name, value)
.subscribeOn(Schedulers.io())
.subscribe()
}
} }
} }
} }

View File

@ -6,12 +6,10 @@ import android.text.TextUtils
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.topjohnwu.magisk.* import com.topjohnwu.magisk.*
import com.topjohnwu.magisk.data.database.SettingsDao
import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.view.Notifications import com.topjohnwu.magisk.view.Notifications
import com.topjohnwu.magisk.view.Shortcuts import com.topjohnwu.magisk.view.Shortcuts
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import org.koin.android.ext.android.get
open class SplashActivity : AppCompatActivity() { open class SplashActivity : AppCompatActivity() {
@ -35,7 +33,7 @@ open class SplashActivity : AppCompatActivity() {
private fun initAndStart() { private fun initAndStart() {
val pkg = Config.suManager val pkg = Config.suManager
if (Config.suManager.isNotEmpty() && packageName == BuildConfig.APPLICATION_ID) { if (Config.suManager.isNotEmpty() && packageName == BuildConfig.APPLICATION_ID) {
get<SettingsDao>().delete(Config.Key.SU_MANAGER) Config.suManager = ""
Shell.su("pm uninstall $pkg").submit() Shell.su("pm uninstall $pkg").submit()
} }
if (TextUtils.equals(pkg, packageName)) { if (TextUtils.equals(pkg, packageName)) {