This commit is contained in:
topjohnwu 2019-07-28 03:47:07 -07:00
parent 9adfb382e8
commit b16f696b0e
6 changed files with 17 additions and 34 deletions

View File

@ -1,15 +0,0 @@
package com.topjohnwu.magisk.data.repository
import com.topjohnwu.magisk.data.database.PolicyDao
import com.topjohnwu.magisk.model.entity.MagiskPolicy
class AppRepository(private val policyDao: PolicyDao) {
fun deleteOutdated() = policyDao.deleteOutdated()
fun delete(packageName: String) = policyDao.delete(packageName)
fun delete(uid: Int) = policyDao.delete(uid)
fun fetch(uid: Int) = policyDao.fetch(uid)
fun fetchAll() = policyDao.fetchAll()
fun update(policy: MagiskPolicy) = policyDao.update(policy)
}

View File

@ -1,6 +1,5 @@
package com.topjohnwu.magisk.di
import com.topjohnwu.magisk.data.repository.AppRepository
import com.topjohnwu.magisk.data.repository.LogRepository
import com.topjohnwu.magisk.data.repository.MagiskRepository
import com.topjohnwu.magisk.data.repository.StringRepository
@ -10,6 +9,5 @@ import org.koin.dsl.module
val repositoryModule = module {
single { MagiskRepository(get(), get()) }
single { LogRepository(get()) }
single { AppRepository(get()) }
single { StringRepository(get()) }
}

View File

@ -7,8 +7,8 @@ import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.Info
import com.topjohnwu.magisk.data.database.PolicyDao
import com.topjohnwu.magisk.data.database.base.su
import com.topjohnwu.magisk.data.repository.AppRepository
import com.topjohnwu.magisk.extensions.inject
import com.topjohnwu.magisk.extensions.reboot
import com.topjohnwu.magisk.ui.surequest.SuRequestActivity
@ -20,7 +20,7 @@ import com.topjohnwu.superuser.Shell
open class GeneralReceiver : BroadcastReceiver() {
private val appRepo: AppRepository by inject()
private val policyDB: PolicyDao by inject()
companion object {
const val REQUEST = "request"
@ -65,10 +65,10 @@ open class GeneralReceiver : BroadcastReceiver() {
Intent.ACTION_PACKAGE_REPLACED ->
// This will only work pre-O
if (Config.suReAuth)
appRepo.delete(getPkg(intent)).blockingGet()
policyDB.delete(getPkg(intent)).blockingGet()
Intent.ACTION_PACKAGE_FULLY_REMOVED -> {
val pkg = getPkg(intent)
appRepo.delete(pkg).blockingGet()
policyDB.delete(pkg).blockingGet()
"magiskhide --rm $pkg".su().blockingGet()
}
Intent.ACTION_LOCALE_CHANGED -> Shortcuts.setup(context)

View File

@ -10,7 +10,7 @@ import com.skoumal.teanity.util.DiffObservableList
import com.skoumal.teanity.viewevents.SnackbarEvent
import com.topjohnwu.magisk.BR
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.data.repository.AppRepository
import com.topjohnwu.magisk.data.database.PolicyDao
import com.topjohnwu.magisk.extensions.toggle
import com.topjohnwu.magisk.model.entity.MagiskPolicy
import com.topjohnwu.magisk.model.entity.Policy
@ -26,7 +26,7 @@ import io.reactivex.disposables.Disposable
import me.tatarka.bindingcollectionadapter2.ItemBinding
class SuperuserViewModel(
private val appRepo: AppRepository,
private val policyDB: PolicyDao,
private val packageManager: PackageManager,
private val resources: Resources,
rxBus: RxBus
@ -54,7 +54,7 @@ class SuperuserViewModel(
fun updatePolicies() {
if (fetchTask?.isDisposed?.not() == true) return
fetchTask = appRepo.fetchAll()
fetchTask = policyDB.fetchAll()
.flattenAsFlowable { it }
.map { PolicyRvItem(it, it.applicationInfo.loadIcon(packageManager)) }
.toList()
@ -140,9 +140,9 @@ class SuperuserViewModel(
}
private fun updatePolicy(policy: MagiskPolicy) =
appRepo.update(policy).andThen(Single.just(policy))
policyDB.update(policy).andThen(Single.just(policy))
private fun deletePolicy(policy: MagiskPolicy) =
appRepo.delete(policy.uid).andThen(Single.just(policy))
policyDB.delete(policy.uid).andThen(Single.just(policy))
}

View File

@ -16,7 +16,7 @@ import com.skoumal.teanity.util.KObservableField
import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.data.repository.AppRepository
import com.topjohnwu.magisk.data.database.PolicyDao
import com.topjohnwu.magisk.extensions.now
import com.topjohnwu.magisk.model.entity.MagiskPolicy
import com.topjohnwu.magisk.model.entity.Policy
@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit.*
class SuRequestViewModel(
private val packageManager: PackageManager,
private val appRepo: AppRepository,
private val policyDB: PolicyDao,
private val timeoutPrefs: SharedPreferences,
private val resources: Resources
) : MagiskViewModel() {
@ -121,8 +121,8 @@ class SuRequestViewModel(
}
val bundle = connector.readSocketInput()
val uid = bundle.getString("uid")?.toIntOrNull() ?: return false
appRepo.deleteOutdated().blockingGet() // wrong!
policy = runCatching { appRepo.fetch(uid).blockingGet() }
policyDB.deleteOutdated().blockingGet() // wrong!
policy = runCatching { policyDB.fetch(uid).blockingGet() }
.getOrDefault(uid.toPolicy(packageManager))
} catch (e: IOException) {
e.printStackTrace()
@ -156,7 +156,7 @@ class SuRequestViewModel(
policy?.until ?: 0
}
policy = policy?.copy(policy = action, until = until)?.apply {
appRepo.update(this).blockingGet()
policyDB.update(this).blockingGet()
}
handleAction()

View File

@ -7,7 +7,7 @@ import android.os.Process
import android.widget.Toast
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.data.repository.AppRepository
import com.topjohnwu.magisk.data.database.PolicyDao
import com.topjohnwu.magisk.data.repository.LogRepository
import com.topjohnwu.magisk.extensions.inject
import com.topjohnwu.magisk.model.entity.MagiskPolicy
@ -38,8 +38,8 @@ object SuLogger {
}.getOrElse { return }
} else {
// Doesn't report whether notify or not, check database ourselves
val appRepo: AppRepository by inject()
val policy = appRepo.fetch(fromUid).blockingGet() ?: return
val policyDB: PolicyDao by inject()
val policy = policyDB.fetch(fromUid).blockingGet() ?: return
notify = policy.notification
policy
}.copy(policy = data.getInt("policy", -1))