mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 20:15:29 +00:00
Allow requesting root from non app process
This commit is contained in:
parent
71e9c044e6
commit
2793d209a4
@ -66,7 +66,11 @@ class SuRequestHandler(
|
|||||||
val fifo = intent.getStringExtra("fifo") ?: throw SuRequestError()
|
val fifo = intent.getStringExtra("fifo") ?: throw SuRequestError()
|
||||||
val uid = intent.getIntExtra("uid", -1).also { if (it < 0) throw SuRequestError() }
|
val uid = intent.getIntExtra("uid", -1).also { if (it < 0) throw SuRequestError() }
|
||||||
val pid = intent.getIntExtra("pid", -1)
|
val pid = intent.getIntExtra("pid", -1)
|
||||||
pkgInfo = pm.getPackageInfo(uid, pid) ?: throw SuRequestError()
|
pkgInfo = pm.getPackageInfo(uid, pid) ?: PackageInfo().apply {
|
||||||
|
val name = pm.getNameForUid(uid) ?: throw SuRequestError()
|
||||||
|
// We only fill in sharedUserId and leave other fields uninitialized
|
||||||
|
sharedUserId = name.split(":")[0]
|
||||||
|
}
|
||||||
output = DataOutputStream(FileOutputStream(fifo).buffered())
|
output = DataOutputStream(FileOutputStream(fifo).buffered())
|
||||||
policy = SuPolicy(uid)
|
policy = SuPolicy(uid)
|
||||||
true
|
true
|
||||||
|
@ -12,6 +12,7 @@ import com.topjohnwu.superuser.ipc.RootService
|
|||||||
import com.topjohnwu.superuser.nio.FileSystemManager
|
import com.topjohnwu.superuser.nio.FileSystemManager
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
import java.util.concurrent.locks.AbstractQueuedSynchronizer
|
import java.util.concurrent.locks.AbstractQueuedSynchronizer
|
||||||
|
|
||||||
class RootUtils(stub: Any?) : RootService() {
|
class RootUtils(stub: Any?) : RootService() {
|
||||||
@ -55,9 +56,14 @@ class RootUtils(stub: Any?) : RootService() {
|
|||||||
if (proc != null)
|
if (proc != null)
|
||||||
return proc
|
return proc
|
||||||
// Find PPID
|
// Find PPID
|
||||||
|
try {
|
||||||
File("/proc/$pid/status").useLines {
|
File("/proc/$pid/status").useLines {
|
||||||
val s = it.find { line -> line.startsWith("PPid:") }
|
val line = it.find { l -> l.startsWith("PPid:") } ?: return null
|
||||||
pid = s?.substring(5)?.trim()?.toInt() ?: -1
|
pid = line.substring(5).trim().toInt()
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
// The process died unexpectedly
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
@ -110,11 +110,21 @@ class SuRequestViewModel(
|
|||||||
private fun showDialog() {
|
private fun showDialog() {
|
||||||
val pm = handler.pm
|
val pm = handler.pm
|
||||||
val info = handler.pkgInfo
|
val info = handler.pkgInfo
|
||||||
val prefix = if (info.sharedUserId == null) "" else "[SharedUID] "
|
val app = info.applicationInfo
|
||||||
|
|
||||||
icon = info.applicationInfo.loadIcon(pm)
|
if (app == null) {
|
||||||
title = "$prefix${info.applicationInfo.getLabel(pm)}"
|
// The request is not coming from an app process, and the UID is a
|
||||||
|
// shared UID. We have no way to know where this request comes from.
|
||||||
|
icon = pm.defaultActivityIcon
|
||||||
|
title = "[SharedUID] ${info.sharedUserId}"
|
||||||
|
packageName = info.sharedUserId
|
||||||
|
} else {
|
||||||
|
val prefix = if (info.sharedUserId == null) "" else "[SharedUID] "
|
||||||
|
icon = app.loadIcon(pm)
|
||||||
|
title = "$prefix${app.getLabel(pm)}"
|
||||||
packageName = info.packageName
|
packageName = info.packageName
|
||||||
|
}
|
||||||
|
|
||||||
selectedItemPosition = timeoutPrefs.getInt(packageName, 0)
|
selectedItemPosition = timeoutPrefs.getInt(packageName, 0)
|
||||||
|
|
||||||
// Set timer
|
// Set timer
|
||||||
@ -135,7 +145,7 @@ class SuRequestViewModel(
|
|||||||
timer.cancel()
|
timer.cancel()
|
||||||
|
|
||||||
val pos = selectedItemPosition
|
val pos = selectedItemPosition
|
||||||
timeoutPrefs.edit().putInt(handler.pkgInfo.packageName, pos).apply()
|
timeoutPrefs.edit().putInt(packageName, pos).apply()
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
handler.respond(action, Config.Value.TIMEOUT_LIST[pos])
|
handler.respond(action, Config.Value.TIMEOUT_LIST[pos])
|
||||||
|
Loading…
Reference in New Issue
Block a user