mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-22 21:55:05 +00:00
Reduce number of loop
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.ComponentName
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.system.Os
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
@@ -13,7 +14,6 @@ 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() {
|
||||||
@@ -48,6 +48,7 @@ class RootUtils(stub: Any?) : RootService() {
|
|||||||
return try {
|
return try {
|
||||||
block()
|
block()
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
// The process died unexpectedly
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
default
|
default
|
||||||
}
|
}
|
||||||
@@ -60,16 +61,17 @@ class RootUtils(stub: Any?) : RootService() {
|
|||||||
val proc = procList.find { it.pid == pid }
|
val proc = procList.find { it.pid == pid }
|
||||||
if (proc != null)
|
if (proc != null)
|
||||||
return proc
|
return proc
|
||||||
// Find PPID
|
|
||||||
try {
|
// Stop find when root process
|
||||||
File("/proc/$pid/status").useLines {
|
if (Os.stat("/proc/$pid").st_uid == 0) {
|
||||||
val line = it.find { l -> l.startsWith("PPid:") } ?: return null
|
|
||||||
pid = line.substring(5).trim().toInt()
|
|
||||||
}
|
|
||||||
} catch (e: IOException) {
|
|
||||||
// The process died unexpectedly
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find PPID
|
||||||
|
File("/proc/$pid/status").useLines {
|
||||||
|
val line = it.find { l -> l.startsWith("PPid:") } ?: return null
|
||||||
|
pid = line.substring(5).trim().toInt()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user