mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-05 23:14:03 -05:00
su: add legacy cmd compatibility check
This commit is contained in:
@@ -63,6 +63,7 @@ object SuCallbackHandler {
|
||||
val toUid = data.getIntComp("to.uid", -1)
|
||||
val pid = data.getIntComp("pid", -1)
|
||||
val command = data.getString("command", "")
|
||||
val legacyCmd = data.getBoolean("legacy_cmd", false)
|
||||
val target = data.getIntComp("target", -1)
|
||||
val seContext = data.getString("context", "")
|
||||
val gids = data.getString("gids", "")
|
||||
@@ -76,7 +77,7 @@ object SuCallbackHandler {
|
||||
}.getOrNull() ?: createSuLog(fromUid, toUid, pid, command, policy, target, seContext, gids)
|
||||
|
||||
if (notify)
|
||||
notify(context, log.action >= SuPolicy.ALLOW, log.appName)
|
||||
notify(context, log.action >= SuPolicy.ALLOW, log.appName, legacyCmd)
|
||||
|
||||
runBlocking { ServiceLocator.logRepo.insert(log) }
|
||||
SuEvents.notifyLogUpdated()
|
||||
@@ -93,17 +94,24 @@ object SuCallbackHandler {
|
||||
pm.getPackageInfo(uid, pid)?.applicationInfo?.getLabel(pm)
|
||||
}.getOrNull() ?: "[UID] $uid"
|
||||
|
||||
notify(context, policy >= SuPolicy.ALLOW, appName)
|
||||
notify(context, policy >= SuPolicy.ALLOW, appName, false)
|
||||
}
|
||||
|
||||
private fun notify(context: Context, granted: Boolean, appName: String) {
|
||||
private fun notify(
|
||||
context: Context, granted: Boolean,
|
||||
appName: String, legacyCmd: Boolean
|
||||
) {
|
||||
val resId = if (granted) R.string.su_allow_toast else R.string.su_deny_toast
|
||||
var str = context.getString(resId, appName)
|
||||
if (legacyCmd) {
|
||||
str += "\n${context.getString(R.string.su_legacy_cmd)}"
|
||||
}
|
||||
when (Config.suNotification) {
|
||||
Config.Value.NOTIFICATION_TOAST -> {
|
||||
val resId = if (granted) R.string.su_allow_toast else R.string.su_deny_toast
|
||||
context.toast(context.getString(resId, appName), Toast.LENGTH_SHORT)
|
||||
context.toast(str, Toast.LENGTH_SHORT)
|
||||
}
|
||||
Config.Value.NOTIFICATION_STATUS_BAR -> {
|
||||
Notifications.suNotification(granted, appName)
|
||||
Notifications.suNotification(granted, str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ object Notifications {
|
||||
private const val SU_NOTIFICATION_TIMEOUT_MS = 3_000L
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
fun suNotification(granted: Boolean, appName: String) {
|
||||
fun suNotification(granted: Boolean, text: String) {
|
||||
AppContext.apply {
|
||||
val flag = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||
val pending = PendingIntent.getActivity(this, 0, selfLaunchIntent(), flag)
|
||||
@@ -115,11 +115,6 @@ object Notifications {
|
||||
if (granted) R.string.su_notification_granted_title
|
||||
else R.string.su_notification_denied_title
|
||||
)
|
||||
val text = getString(
|
||||
if (granted) R.string.su_allow_toast
|
||||
else R.string.su_deny_toast,
|
||||
appName
|
||||
)
|
||||
val builder = if (SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Notification.Builder(this, SU_CHANNEL)
|
||||
.setSmallIcon(getBitmap(R.drawable.ic_magisk_outline).toIcon())
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
<string name="thirtymin">30 分钟</string>
|
||||
<string name="sixtymin">60 分钟</string>
|
||||
<string name="su_allow_toast">%1$s 已被授予超级用户权限</string>
|
||||
<string name="su_legacy_cmd">警告:检测到不支持的命令行</string>
|
||||
<string name="su_deny_toast">%1$s 已被拒绝超级用户权限</string>
|
||||
<string name="su_snack_grant">已授予 %1$s 超级用户权限</string>
|
||||
<string name="su_snack_deny">已拒绝 %1$s 超级用户权限</string>
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
<string name="grant">Grant</string>
|
||||
<string name="superuser_grant">Grant Superuser</string>
|
||||
<string name="su_allow_toast">%1$s was granted Superuser rights</string>
|
||||
<string name="su_legacy_cmd">Warning: Unsupported command line detected</string>
|
||||
<string name="su_deny_toast">%1$s was denied Superuser rights</string>
|
||||
<string name="su_snack_grant">Superuser rights of %1$s are granted</string>
|
||||
<string name="su_snack_deny">Superuser rights of %1$s are denied</string>
|
||||
|
||||
Reference in New Issue
Block a user