From 84f0ff2fad683cd1d2fcaa980a36b0a262cf1afd Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 12 Aug 2019 03:31:59 -0700 Subject: [PATCH] Fix manager package name database management --- .../magisk/data/repository/DBConfig.kt | 31 +++++++++++-------- .../com/topjohnwu/magisk/ui/SplashActivity.kt | 4 +-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/DBConfig.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/DBConfig.kt index 119cf3bf6..1129a18cd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/DBConfig.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/DBConfig.kt @@ -2,7 +2,6 @@ package com.topjohnwu.magisk.data.repository import com.topjohnwu.magisk.data.database.SettingsDao import com.topjohnwu.magisk.data.database.StringDao -import com.topjohnwu.magisk.extensions.trimEmptyToNull import io.reactivex.schedulers.Schedulers import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty @@ -36,12 +35,10 @@ class DBSettingsValue( private var value: Int? = null - private fun getKey(property: KProperty<*>) = name.trimEmptyToNull() ?: property.name - @Synchronized override fun getValue(thisRef: DBConfig, property: KProperty<*>): Int { if (value == null) - value = thisRef.settingsDao.fetch(getKey(property), default).blockingGet() + value = thisRef.settingsDao.fetch(name, default).blockingGet() return value!! } @@ -49,7 +46,7 @@ class DBSettingsValue( synchronized(this) { this.value = value } - thisRef.settingsDao.put(getKey(property), value) + thisRef.settingsDao.put(name, value) .subscribeOn(Schedulers.io()) .subscribe() } @@ -77,12 +74,10 @@ class DBStringsValue( private var value: String? = null - private fun getKey(property: KProperty<*>) = name.trimEmptyToNull() ?: property.name - @Synchronized override fun getValue(thisRef: DBConfig, property: KProperty<*>): String { if (value == null) - value = thisRef.stringDao.fetch(getKey(property), default).blockingGet() + value = thisRef.stringDao.fetch(name, default).blockingGet() return value!! } @@ -90,12 +85,22 @@ class DBStringsValue( synchronized(this) { this.value = value } - if (sync) { - thisRef.stringDao.put(getKey(property), value).blockingAwait() + if (value.isEmpty()) { + if (sync) { + thisRef.stringDao.delete(name).blockingAwait() + } else { + thisRef.stringDao.delete(name) + .subscribeOn(Schedulers.io()) + .subscribe() + } } else { - thisRef.stringDao.put(getKey(property), value) - .subscribeOn(Schedulers.io()) - .subscribe() + if (sync) { + thisRef.stringDao.put(name, value).blockingAwait() + } else { + thisRef.stringDao.put(name, value) + .subscribeOn(Schedulers.io()) + .subscribe() + } } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt index 82ab980fd..7021b62ba 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt @@ -6,12 +6,10 @@ import android.text.TextUtils import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import com.topjohnwu.magisk.* -import com.topjohnwu.magisk.data.database.SettingsDao import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.view.Notifications import com.topjohnwu.magisk.view.Shortcuts import com.topjohnwu.superuser.Shell -import org.koin.android.ext.android.get open class SplashActivity : AppCompatActivity() { @@ -35,7 +33,7 @@ open class SplashActivity : AppCompatActivity() { private fun initAndStart() { val pkg = Config.suManager if (Config.suManager.isNotEmpty() && packageName == BuildConfig.APPLICATION_ID) { - get().delete(Config.Key.SU_MANAGER) + Config.suManager = "" Shell.su("pm uninstall $pkg").submit() } if (TextUtils.equals(pkg, packageName)) {