Update libsu

This commit is contained in:
topjohnwu 2024-06-28 15:44:42 -07:00
parent 2112c916f5
commit 45fa1fce70
5 changed files with 56 additions and 27 deletions

View File

@ -80,7 +80,7 @@ dependencies {
implementation("dev.rikka.rikkax.recyclerview:recyclerview-ktx:1.3.2") implementation("dev.rikka.rikkax.recyclerview:recyclerview-ktx:1.3.2")
implementation("io.noties.markwon:core:4.6.2") implementation("io.noties.markwon:core:4.6.2")
val vLibsu = "5.3.0" val vLibsu = "6.0.0"
implementation("com.github.topjohnwu.libsu:core:${vLibsu}") implementation("com.github.topjohnwu.libsu:core:${vLibsu}")
implementation("com.github.topjohnwu.libsu:service:${vLibsu}") implementation("com.github.topjohnwu.libsu:service:${vLibsu}")
implementation("com.github.topjohnwu.libsu:nio:${vLibsu}") implementation("com.github.topjohnwu.libsu:nio:${vLibsu}")

View File

@ -68,11 +68,12 @@ open class App() : Application() {
ServiceLocator.context = base ServiceLocator.context = base
app.registerActivityLifecycleCallbacks(ActivityTracker) app.registerActivityLifecycleCallbacks(ActivityTracker)
Shell.setDefaultBuilder(Shell.Builder.create() val shellBuilder = Shell.Builder.create()
.setFlags(Shell.FLAG_MOUNT_MASTER) .setFlags(Shell.FLAG_MOUNT_MASTER)
.setInitializers(ShellInit::class.java) .setInitializers(ShellInit::class.java)
.setContext(base) .setContext(base)
.setTimeout(2)) .setTimeout(2)
Shell.setDefaultBuilder(shellBuilder)
Shell.EXECUTOR = Dispatchers.IO.asExecutor() Shell.EXECUTOR = Dispatchers.IO.asExecutor()
RootUtils.bindTask = RootService.bindOrTask( RootUtils.bindTask = RootService.bindOrTask(
intent<RootUtils>(), intent<RootUtils>(),

View File

@ -6,39 +6,49 @@ import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.di.ServiceLocator
import com.topjohnwu.magisk.core.tasks.MagiskInstaller import com.topjohnwu.magisk.core.tasks.MagiskInstaller
import com.topjohnwu.magisk.core.utils.RootUtils import com.topjohnwu.magisk.core.utils.RootUtils
import com.topjohnwu.superuser.CallbackList
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.internal.NOPList import kotlinx.coroutines.Runnable
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import timber.log.Timber
object TestHandler { object TestHandler {
object LogList : CallbackList<String>(Runnable::run) {
override fun onAddElement(e: String) {
Timber.i(e)
}
}
fun run(method: String): Bundle { fun run(method: String): Bundle {
val r = Bundle() var reason: String? = null
fun prerequisite(): Boolean {
// Make sure the Magisk app can get root
val shell = Shell.getShell()
if (!shell.isRoot) {
reason = "shell not root"
return false
}
// Make sure the root service is running
RootUtils.Connection.await()
return true
}
fun setup(): Boolean { fun setup(): Boolean {
val nop = NOPList.getInstance()
return runBlocking { return runBlocking {
MagiskInstaller.Emulator(nop, nop).exec() MagiskInstaller.Emulator(LogList, LogList).exec()
} }
} }
fun test(): Boolean { fun test(): Boolean {
// Make sure Zygisk works correctly // Make sure Zygisk works correctly
if (!Info.isZygiskEnabled) { if (!Info.isZygiskEnabled) {
r.putString("reason", "zygisk not enabled") reason = "zygisk not enabled"
return false return false
} }
// Make sure the Magisk app can get root
val shell = Shell.getShell()
if (!shell.isRoot) {
r.putString("reason", "shell not root")
return false
}
// Make sure the root service is running
RootUtils.Connection.await()
// Clear existing grant for ADB shell // Clear existing grant for ADB shell
runBlocking { runBlocking {
ServiceLocator.policyDB.delete(2000) ServiceLocator.policyDB.delete(2000)
@ -48,21 +58,23 @@ object TestHandler {
return true return true
} }
val b = runCatching { val result = prerequisite() && runCatching {
when (method) { when (method) {
"setup" -> setup() "setup" -> setup()
"test" -> test() "test" -> test()
else -> { else -> {
r.putString("reason", "unknown method") reason = "unknown method"
false false
} }
} }
}.getOrElse { }.getOrElse {
r.putString("reason", it.stackTraceToString()) reason = it.stackTraceToString()
false false
} }
r.putBoolean("result", b) return Bundle().apply {
return r putBoolean("result", result)
if (reason != null) putString("reason", reason)
}
} }
} }

View File

@ -23,13 +23,13 @@ import com.topjohnwu.magisk.core.ktx.copyAndClose
import com.topjohnwu.magisk.core.ktx.reboot import com.topjohnwu.magisk.core.ktx.reboot
import com.topjohnwu.magisk.core.ktx.toast import com.topjohnwu.magisk.core.ktx.toast
import com.topjohnwu.magisk.core.ktx.writeTo import com.topjohnwu.magisk.core.ktx.writeTo
import com.topjohnwu.magisk.core.utils.DummyList
import com.topjohnwu.magisk.core.utils.MediaStoreUtils import com.topjohnwu.magisk.core.utils.MediaStoreUtils
import com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream import com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream
import com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream import com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
import com.topjohnwu.magisk.core.utils.RootUtils import com.topjohnwu.magisk.core.utils.RootUtils
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ShellUtils import com.topjohnwu.superuser.ShellUtils
import com.topjohnwu.superuser.internal.NOPList
import com.topjohnwu.superuser.internal.UiThreadHandler import com.topjohnwu.superuser.internal.UiThreadHandler
import com.topjohnwu.superuser.nio.ExtendedFile import com.topjohnwu.superuser.nio.ExtendedFile
import com.topjohnwu.superuser.nio.FileSystemManager import com.topjohnwu.superuser.nio.FileSystemManager
@ -51,8 +51,8 @@ import java.util.zip.ZipFile
import java.util.zip.ZipInputStream import java.util.zip.ZipInputStream
abstract class MagiskInstallImpl protected constructor( abstract class MagiskInstallImpl protected constructor(
protected val console: MutableList<String> = NOPList.getInstance(), protected val console: MutableList<String>,
private val logs: MutableList<String> = NOPList.getInstance() private val logs: MutableList<String>
) { ) {
protected lateinit var installDir: ExtendedFile protected lateinit var installDir: ExtendedFile
@ -625,7 +625,7 @@ abstract class MagiskInstaller(
} }
} }
class FixEnv(private val callback: () -> Unit) : MagiskInstallImpl() { class FixEnv(private val callback: () -> Unit) : MagiskInstallImpl(DummyList, DummyList) {
override suspend fun operations() = fixEnv() override suspend fun operations() = fixEnv()
override suspend fun exec(): Boolean { override suspend fun exec(): Boolean {

View File

@ -0,0 +1,16 @@
package com.topjohnwu.magisk.core.utils
object DummyList : java.util.AbstractList<String>() {
override val size: Int get() = 0
override fun get(index: Int): String {
throw IndexOutOfBoundsException()
}
override fun add(element: String): Boolean = false
override fun add(index: Int, element: String) {}
override fun clear() {}
}