diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/AppRepository.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/AppRepository.kt deleted file mode 100644 index 9f5e6c587..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/AppRepository.kt +++ /dev/null @@ -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) - -} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt index e1cad742f..6f2de1747 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt @@ -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()) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt index 1d37448ca..a631694a5 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt @@ -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) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt index 2bbc313d6..48073d942 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -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)) } \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt index bf5a62d1d..b160954cb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt @@ -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() diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.kt b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.kt index 2e1c7b441..54e705eb5 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.kt @@ -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))