Uninstalled app su requests should still show in logs

This commit is contained in:
topjohnwu 2022-01-18 04:44:11 -08:00
parent 0ad0ef485c
commit 6b67902d53
4 changed files with 29 additions and 20 deletions

View File

@ -3,7 +3,6 @@ package com.topjohnwu.magisk.core.magiskdb
import android.content.pm.PackageManager
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.model.su.SuPolicy
import com.topjohnwu.magisk.core.model.su.toMap
import com.topjohnwu.magisk.core.model.su.toPolicy
import com.topjohnwu.magisk.di.AppContext
import com.topjohnwu.magisk.ktx.now

View File

@ -3,8 +3,6 @@ package com.topjohnwu.magisk.core.model.su
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.ALLOW
import com.topjohnwu.magisk.ktx.now
import com.topjohnwu.magisk.ktx.timeFormatTime
import com.topjohnwu.magisk.ktx.toTime
@ -22,9 +20,3 @@ data class SuLog(
@PrimaryKey(autoGenerate = true) var id: Int = 0
@Ignore val timeString = time.toTime(timeFormatTime)
}
fun SuPolicy.toLog(
toUid: Int,
fromPid: Int,
command: String
) = SuLog(uid, toUid, fromPid, packageName, appName, command, policy == ALLOW, now)

View File

@ -25,16 +25,20 @@ data class SuPolicy(
const val ALLOW = 2
}
}
fun toLog(toUid: Int, fromPid: Int, command: String) = SuLog(
uid, toUid, fromPid, packageName, appName,
command, policy == ALLOW, System.currentTimeMillis()
)
fun SuPolicy.toMap() = mapOf(
"uid" to uid,
"package_name" to packageName,
"policy" to policy,
"until" to until,
"logging" to logging,
"notification" to notification
)
fun toMap() = mapOf(
"uid" to uid,
"package_name" to packageName,
"policy" to policy,
"until" to until,
"logging" to logging,
"notification" to notification
)
}
@Throws(PackageManager.NameNotFoundException::class)
fun Map<String, String>.toPolicy(pm: PackageManager): SuPolicy {
@ -70,3 +74,13 @@ fun Int.toPolicy(pm: PackageManager, policy: Int = INTERACTIVE): SuPolicy {
policy = policy
)
}
fun Int.toUidPolicy(pm: PackageManager, policy: Int): SuPolicy {
return SuPolicy(
uid = this,
packageName = "[UID] $this",
appName = "[UID] $this",
icon = pm.defaultActivityIcon,
policy = policy
)
}

View File

@ -8,8 +8,8 @@ import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.model.su.SuPolicy
import com.topjohnwu.magisk.core.model.su.toLog
import com.topjohnwu.magisk.core.model.su.toPolicy
import com.topjohnwu.magisk.core.model.su.toUidPolicy
import com.topjohnwu.magisk.di.ServiceLocator
import com.topjohnwu.magisk.utils.Utils
import kotlinx.coroutines.GlobalScope
@ -58,7 +58,11 @@ object SuCallbackHandler {
val notify = data.getBoolean("notify", true)
val allow = data["policy"].toInt() ?: return
val policy = runCatching { fromUid.toPolicy(pm, allow) }.getOrElse { return }
val policy = runCatching {
fromUid.toPolicy(pm, allow)
}.getOrElse {
fromUid.toUidPolicy(pm, allow)
}
if (notify)
notify(context, policy)