fix AI code

This commit is contained in:
vvb2060
2026-07-28 20:10:20 -07:00
committed by John Wu
parent 5c82406ee6
commit 7082518c53
2 changed files with 4 additions and 45 deletions
@@ -3,7 +3,6 @@ package com.topjohnwu.magisk.core.su
import android.content.Context
import android.os.Bundle
import android.widget.Toast
import com.topjohnwu.magisk.core.AppContext
import com.topjohnwu.magisk.core.BuildConfig
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.R
@@ -71,12 +70,11 @@ object SuCallbackHandler {
}
}.getOrNull() ?: createSuLog(fromUid, toUid, pid, command, policy, target, seContext, gids)
runBlocking { ServiceLocator.logRepo.insert(log) }
if (notify || Config.suNotification == Config.Value.NOTIFICATION_STATUS_BAR)
if (notify)
notify(context, log.action >= SuPolicy.ALLOW, log.appName)
runBlocking { ServiceLocator.logRepo.insert(log) }
SuEvents.notifyLogUpdated()
SuEvents.notifyPolicyChanged()
}
private fun handleNotify(context: Context, data: Bundle) {
@@ -91,19 +89,6 @@ object SuCallbackHandler {
}.getOrNull() ?: "[UID] $uid"
notify(context, policy >= SuPolicy.ALLOW, appName)
SuEvents.notifyPolicyChanged()
}
fun notify(granted: Boolean, appName: String) {
when (Config.suNotification) {
Config.Value.NOTIFICATION_TOAST -> {
val resId = if (granted) R.string.su_allow_toast else R.string.su_deny_toast
AppContext.toast(AppContext.getString(resId, appName), Toast.LENGTH_SHORT)
}
Config.Value.NOTIFICATION_STATUS_BAR -> {
Notifications.suNotification(granted, appName)
}
}
}
private fun notify(context: Context, granted: Boolean, appName: String) {
@@ -29,7 +29,6 @@ class SuRequestHandler(
private lateinit var output: File
private lateinit var policy: SuPolicy
private var pid: Int = -1
lateinit var pkgInfo: PackageInfo
private set
@@ -60,7 +59,7 @@ class SuRequestHandler(
private suspend fun init(intent: Intent): Boolean {
val uid = intent.getIntExtra("uid", -1)
pid = intent.getIntExtra("pid", -1)
val pid = intent.getIntExtra("pid", -1)
val fifo = intent.getStringExtra("fifo")
if (uid <= 0 || pid <= 0 || fifo == null) {
Timber.e("Unexpected extras: uid=[${uid}], pid=[${pid}], fifo=[${fifo}]")
@@ -109,32 +108,7 @@ class SuRequestHandler(
}
if (time >= 0) {
policyDB.update(policy)
val appInfo = pkgInfo.applicationInfo
val appName = appInfo?.getLabel(pm)
?: pkgInfo.sharedUserId ?: "[UID] ${policy.uid}"
val packageName = appInfo?.let { pm.getNameForUid(it.uid) }
?: pkgInfo.sharedUserId ?: "[UID] ${policy.uid}"
val log = SuLog(
fromUid = policy.uid,
toUid = 0,
fromPid = pid,
packageName = packageName,
appName = appName,
command = "",
action = policy.policy,
target = -1,
context = "",
gids = "",
)
ServiceLocator.logRepo.insert(log)
val granted = policy.policy >= SuPolicy.ALLOW
SuCallbackHandler.notify(granted, appName)
SuEvents.notifyPolicyChanged()
SuEvents.notifyLogUpdated()
}
}
}