Replaced log calls from magiskdb to repo

This commit is contained in:
Viktor De Pasquale
2019-05-09 17:01:34 +02:00
parent 90d85eaf7d
commit 7abdac72a4
7 changed files with 55 additions and 50 deletions

View File

@@ -18,11 +18,8 @@ object DatabaseDefinition {
@AnyThread
fun MagiskQuery.query() = query.su()
fun String.suRaw() = Single.just(Shell.su(this))
.map { it.exec().out }
fun String.su() = suRaw()
.map { it.toMap() }
fun String.suRaw() = Single.fromCallable { Shell.su(this).exec().out }
fun String.su() = suRaw().map { it.toMap() }
fun List<String>.toMap() = map { it.split(Regex("\\|")) }
.map { it.toMapInternal() }

View File

@@ -1,10 +1,13 @@
package com.topjohnwu.magisk.data.repository
import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.Constants
import com.topjohnwu.magisk.data.database.LogDao
import com.topjohnwu.magisk.data.database.base.suRaw
import com.topjohnwu.magisk.model.entity.MagiskLog
import com.topjohnwu.magisk.model.entity.WrappedMagiskLog
import com.topjohnwu.magisk.utils.toSingle
import com.topjohnwu.superuser.Shell
import timber.log.Timber
import java.util.concurrent.TimeUnit
@@ -21,6 +24,13 @@ class LogRepository(
.filter { it.isNotEmpty() }
.map { Timber.i(it.toString()); it }
fun clearLogs() = logDao.deleteAll()
fun clearOutdated() = logDao.deleteOutdated()
fun clearMagiskLogs() = Shell.su("echo -n > " + Const.MAGISK_LOG)
.toSingle()
.map { it.exec() }
private fun List<MagiskLog>.wrap(): List<WrappedMagiskLog> {
val day = TimeUnit.DAYS.toMillis(1)
var currentDay = firstOrNull()?.date?.time ?: return listOf()