Skip to content

Commit

Permalink
Fix manager package name database management
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Aug 12, 2019
1 parent e6561e5 commit 84f0ff2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
31 changes: 18 additions & 13 deletions app/src/main/java/com/topjohnwu/magisk/data/repository/DBConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,20 +35,18 @@ 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!!
}

override fun setValue(thisRef: DBConfig, property: KProperty<*>, value: Int) {
synchronized(this) {
this.value = value
}
thisRef.settingsDao.put(getKey(property), value)
thisRef.settingsDao.put(name, value)
.subscribeOn(Schedulers.io())
.subscribe()
}
Expand Down Expand Up @@ -77,25 +74,33 @@ 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!!
}

override fun setValue(thisRef: DBConfig, property: KProperty<*>, value: String) {
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()
}
}
}
}
4 changes: 1 addition & 3 deletions app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -35,7 +33,7 @@ open class SplashActivity : AppCompatActivity() {
private fun initAndStart() {
val pkg = Config.suManager
if (Config.suManager.isNotEmpty() && packageName == BuildConfig.APPLICATION_ID) {
get<SettingsDao>().delete(Config.Key.SU_MANAGER)
Config.suManager = ""
Shell.su("pm uninstall $pkg").submit()
}
if (TextUtils.equals(pkg, packageName)) {
Expand Down

0 comments on commit 84f0ff2

Please sign in to comment.