From 6b67902d535a1e28d204523dbd1a6d803c4aecb4 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 18 Jan 2022 04:44:11 -0800 Subject: [PATCH] Uninstalled app su requests should still show in logs --- .../magisk/core/magiskdb/PolicyDao.kt | 1 - .../topjohnwu/magisk/core/model/su/SuLog.kt | 8 ----- .../magisk/core/model/su/SuPolicy.kt | 32 +++++++++++++------ .../magisk/core/su/SuCallbackHandler.kt | 8 +++-- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/PolicyDao.kt b/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/PolicyDao.kt index 7cafbe1e6..26da6e725 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/PolicyDao.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/PolicyDao.kt @@ -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 diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuLog.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuLog.kt index 63792fe14..eb126344d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuLog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuLog.kt @@ -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) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuPolicy.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuPolicy.kt index cbe406850..0010712c4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuPolicy.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuPolicy.kt @@ -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.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 + ) +} diff --git a/app/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt b/app/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt index 9fc6b1977..a3f3a70c0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt @@ -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)