Commit b16f696b authored by topjohnwu's avatar topjohnwu

Cleanups

parent 9adfb382
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)
}
\ No newline at end of file
package com.topjohnwu.magisk.di 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.LogRepository
import com.topjohnwu.magisk.data.repository.MagiskRepository import com.topjohnwu.magisk.data.repository.MagiskRepository
import com.topjohnwu.magisk.data.repository.StringRepository import com.topjohnwu.magisk.data.repository.StringRepository
...@@ -10,6 +9,5 @@ import org.koin.dsl.module ...@@ -10,6 +9,5 @@ import org.koin.dsl.module
val repositoryModule = module { val repositoryModule = module {
single { MagiskRepository(get(), get()) } single { MagiskRepository(get(), get()) }
single { LogRepository(get()) } single { LogRepository(get()) }
single { AppRepository(get()) }
single { StringRepository(get()) } single { StringRepository(get()) }
} }
...@@ -7,8 +7,8 @@ import com.topjohnwu.magisk.ClassMap ...@@ -7,8 +7,8 @@ import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.Const import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.Info 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.database.base.su
import com.topjohnwu.magisk.data.repository.AppRepository
import com.topjohnwu.magisk.extensions.inject import com.topjohnwu.magisk.extensions.inject
import com.topjohnwu.magisk.extensions.reboot import com.topjohnwu.magisk.extensions.reboot
import com.topjohnwu.magisk.ui.surequest.SuRequestActivity import com.topjohnwu.magisk.ui.surequest.SuRequestActivity
...@@ -20,7 +20,7 @@ import com.topjohnwu.superuser.Shell ...@@ -20,7 +20,7 @@ import com.topjohnwu.superuser.Shell
open class GeneralReceiver : BroadcastReceiver() { open class GeneralReceiver : BroadcastReceiver() {
private val appRepo: AppRepository by inject() private val policyDB: PolicyDao by inject()
companion object { companion object {
const val REQUEST = "request" const val REQUEST = "request"
...@@ -65,10 +65,10 @@ open class GeneralReceiver : BroadcastReceiver() { ...@@ -65,10 +65,10 @@ open class GeneralReceiver : BroadcastReceiver() {
Intent.ACTION_PACKAGE_REPLACED -> Intent.ACTION_PACKAGE_REPLACED ->
// This will only work pre-O // This will only work pre-O
if (Config.suReAuth) if (Config.suReAuth)
appRepo.delete(getPkg(intent)).blockingGet() policyDB.delete(getPkg(intent)).blockingGet()
Intent.ACTION_PACKAGE_FULLY_REMOVED -> { Intent.ACTION_PACKAGE_FULLY_REMOVED -> {
val pkg = getPkg(intent) val pkg = getPkg(intent)
appRepo.delete(pkg).blockingGet() policyDB.delete(pkg).blockingGet()
"magiskhide --rm $pkg".su().blockingGet() "magiskhide --rm $pkg".su().blockingGet()
} }
Intent.ACTION_LOCALE_CHANGED -> Shortcuts.setup(context) Intent.ACTION_LOCALE_CHANGED -> Shortcuts.setup(context)
......
...@@ -10,7 +10,7 @@ import com.skoumal.teanity.util.DiffObservableList ...@@ -10,7 +10,7 @@ import com.skoumal.teanity.util.DiffObservableList
import com.skoumal.teanity.viewevents.SnackbarEvent import com.skoumal.teanity.viewevents.SnackbarEvent
import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.BR
import com.topjohnwu.magisk.R 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.extensions.toggle
import com.topjohnwu.magisk.model.entity.MagiskPolicy import com.topjohnwu.magisk.model.entity.MagiskPolicy
import com.topjohnwu.magisk.model.entity.Policy import com.topjohnwu.magisk.model.entity.Policy
...@@ -26,7 +26,7 @@ import io.reactivex.disposables.Disposable ...@@ -26,7 +26,7 @@ import io.reactivex.disposables.Disposable
import me.tatarka.bindingcollectionadapter2.ItemBinding import me.tatarka.bindingcollectionadapter2.ItemBinding
class SuperuserViewModel( class SuperuserViewModel(
private val appRepo: AppRepository, private val policyDB: PolicyDao,
private val packageManager: PackageManager, private val packageManager: PackageManager,
private val resources: Resources, private val resources: Resources,
rxBus: RxBus rxBus: RxBus
...@@ -54,7 +54,7 @@ class SuperuserViewModel( ...@@ -54,7 +54,7 @@ class SuperuserViewModel(
fun updatePolicies() { fun updatePolicies() {
if (fetchTask?.isDisposed?.not() == true) return if (fetchTask?.isDisposed?.not() == true) return
fetchTask = appRepo.fetchAll() fetchTask = policyDB.fetchAll()
.flattenAsFlowable { it } .flattenAsFlowable { it }
.map { PolicyRvItem(it, it.applicationInfo.loadIcon(packageManager)) } .map { PolicyRvItem(it, it.applicationInfo.loadIcon(packageManager)) }
.toList() .toList()
...@@ -140,9 +140,9 @@ class SuperuserViewModel( ...@@ -140,9 +140,9 @@ class SuperuserViewModel(
} }
private fun updatePolicy(policy: MagiskPolicy) = private fun updatePolicy(policy: MagiskPolicy) =
appRepo.update(policy).andThen(Single.just(policy)) policyDB.update(policy).andThen(Single.just(policy))
private fun deletePolicy(policy: MagiskPolicy) = private fun deletePolicy(policy: MagiskPolicy) =
appRepo.delete(policy.uid).andThen(Single.just(policy)) policyDB.delete(policy.uid).andThen(Single.just(policy))
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ import com.skoumal.teanity.util.KObservableField ...@@ -16,7 +16,7 @@ import com.skoumal.teanity.util.KObservableField
import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.R 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.extensions.now
import com.topjohnwu.magisk.model.entity.MagiskPolicy import com.topjohnwu.magisk.model.entity.MagiskPolicy
import com.topjohnwu.magisk.model.entity.Policy import com.topjohnwu.magisk.model.entity.Policy
...@@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit.* ...@@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit.*
class SuRequestViewModel( class SuRequestViewModel(
private val packageManager: PackageManager, private val packageManager: PackageManager,
private val appRepo: AppRepository, private val policyDB: PolicyDao,
private val timeoutPrefs: SharedPreferences, private val timeoutPrefs: SharedPreferences,
private val resources: Resources private val resources: Resources
) : MagiskViewModel() { ) : MagiskViewModel() {
...@@ -121,8 +121,8 @@ class SuRequestViewModel( ...@@ -121,8 +121,8 @@ class SuRequestViewModel(
} }
val bundle = connector.readSocketInput() val bundle = connector.readSocketInput()
val uid = bundle.getString("uid")?.toIntOrNull() ?: return false val uid = bundle.getString("uid")?.toIntOrNull() ?: return false
appRepo.deleteOutdated().blockingGet() // wrong! policyDB.deleteOutdated().blockingGet() // wrong!
policy = runCatching { appRepo.fetch(uid).blockingGet() } policy = runCatching { policyDB.fetch(uid).blockingGet() }
.getOrDefault(uid.toPolicy(packageManager)) .getOrDefault(uid.toPolicy(packageManager))
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
...@@ -156,7 +156,7 @@ class SuRequestViewModel( ...@@ -156,7 +156,7 @@ class SuRequestViewModel(
policy?.until ?: 0 policy?.until ?: 0
} }
policy = policy?.copy(policy = action, until = until)?.apply { policy = policy?.copy(policy = action, until = until)?.apply {
appRepo.update(this).blockingGet() policyDB.update(this).blockingGet()
} }
handleAction() handleAction()
......
...@@ -7,7 +7,7 @@ import android.os.Process ...@@ -7,7 +7,7 @@ import android.os.Process
import android.widget.Toast import android.widget.Toast
import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.R 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.data.repository.LogRepository
import com.topjohnwu.magisk.extensions.inject import com.topjohnwu.magisk.extensions.inject
import com.topjohnwu.magisk.model.entity.MagiskPolicy import com.topjohnwu.magisk.model.entity.MagiskPolicy
...@@ -38,8 +38,8 @@ object SuLogger { ...@@ -38,8 +38,8 @@ object SuLogger {
}.getOrElse { return } }.getOrElse { return }
} else { } else {
// Doesn't report whether notify or not, check database ourselves // Doesn't report whether notify or not, check database ourselves
val appRepo: AppRepository by inject() val policyDB: PolicyDao by inject()
val policy = appRepo.fetch(fromUid).blockingGet() ?: return val policy = policyDB.fetch(fromUid).blockingGet() ?: return
notify = policy.notification notify = policy.notification
policy policy
}.copy(policy = data.getInt("policy", -1)) }.copy(policy = data.getInt("policy", -1))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment