Update libsu

This commit is contained in:
topjohnwu 2022-02-28 20:14:58 -08:00
parent e7c82f20e3
commit 71e37345b4
23 changed files with 39 additions and 40 deletions

View File

@ -86,7 +86,7 @@ dependencies {
implementation("${bindingAdapter}:${vBAdapt}")
implementation("${bindingAdapter}-recyclerview:${vBAdapt}")
val vLibsu = "3.2.1"
val vLibsu = "4.0.0"
implementation("com.github.topjohnwu.libsu:core:${vLibsu}")
implementation("com.github.topjohnwu.libsu:io:${vLibsu}")
implementation("com.github.topjohnwu.libsu:service:${vLibsu}")

View File

@ -111,13 +111,13 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
runCatching {
// Hidden, remove com.topjohnwu.magisk if exist as it could be malware
packageManager.getApplicationInfo(APPLICATION_ID, 0)
Shell.su("(pm uninstall $APPLICATION_ID)& >/dev/null 2>&1").exec()
Shell.cmd("(pm uninstall $APPLICATION_ID)& >/dev/null 2>&1").exec()
}
} else {
if (Config.suManager.isNotEmpty())
Config.suManager = ""
pkg ?: return
if (!Shell.su("(pm uninstall $pkg)& >/dev/null 2>&1").exec().isSuccess) {
if (!Shell.cmd("(pm uninstall $pkg)& >/dev/null 2>&1").exec().isSuccess) {
// Uninstall through Android API
uninstallAndWait(pkg)
}

View File

@ -70,7 +70,7 @@ open class App() : Application() {
override fun onCreate() {
super.onCreate()
RootRegistry.bindTask = RootService.createBindTask(
RootRegistry.bindTask = RootService.bindOrTask(
intent<RootRegistry>(),
UiThreadHandler.executor,
RootRegistry.Connection
@ -92,8 +92,6 @@ object ActivityTracker : Application.ActivityLifecycleCallbacks {
@Volatile
var foreground: Activity? = null
val hasForeground get() = foreground != null
override fun onActivityResumed(activity: Activity) {
if (activity is SuRequestActivity) return
foreground = activity

View File

@ -43,7 +43,7 @@ open class Receiver : BaseReceiver() {
getUid(intent)?.let { rmPolicy(it) }
}
Intent.ACTION_PACKAGE_FULLY_REMOVED -> {
getPkg(intent)?.let { Shell.su("magisk --denylist rm $it").submit() }
getPkg(intent)?.let { Shell.cmd("magisk --denylist rm $it").submit() }
}
Intent.ACTION_LOCALE_CHANGED -> Shortcuts.setupDynamic(context)
Intent.ACTION_MY_PACKAGE_REPLACED -> {

View File

@ -18,7 +18,7 @@ class Query(private val _query: String) {
suspend inline fun <R : Any> query(crossinline mapper: (Map<String, String>) -> R?): List<R> =
withContext(Dispatchers.Default) {
Shell.su(query).await().out.map { line ->
Shell.cmd(query).await().out.map { line ->
async {
line.split("\\|".toRegex())
.map { it.split("=", limit = 2) }
@ -32,7 +32,7 @@ class Query(private val _query: String) {
suspend inline fun query() = query { it }
suspend inline fun commit() = Shell.su(query).to(null).await()
suspend inline fun commit() = Shell.cmd(query).to(null).await()
}
class Delete : Query.Builder {

View File

@ -46,15 +46,15 @@ data class LocalModule(
if (enable) {
disableFile.delete()
if (Const.Version.atLeast_21_2())
Shell.su("copy_sepolicy_rules").submit()
Shell.cmd("copy_sepolicy_rules").submit()
else
Shell.su("mkdir -p $dir", "cp -af $ruleFile $dir").submit()
Shell.cmd("mkdir -p $dir", "cp -af $ruleFile $dir").submit()
} else {
!disableFile.createNewFile()
if (Const.Version.atLeast_21_2())
Shell.su("copy_sepolicy_rules").submit()
Shell.cmd("copy_sepolicy_rules").submit()
else
Shell.su("rm -rf $dir").submit()
Shell.cmd("rm -rf $dir").submit()
}
}
@ -65,15 +65,15 @@ data class LocalModule(
if (updateFile.exists()) return
removeFile.createNewFile()
if (Const.Version.atLeast_21_2())
Shell.su("copy_sepolicy_rules").submit()
Shell.cmd("copy_sepolicy_rules").submit()
else
Shell.su("rm -rf $PERSIST/$id").submit()
Shell.cmd("rm -rf $PERSIST/$id").submit()
} else {
removeFile.delete()
if (Const.Version.atLeast_21_2())
Shell.su("copy_sepolicy_rules").submit()
Shell.cmd("copy_sepolicy_rules").submit()
else
Shell.su("cp -af $ruleFile $PERSIST/$id").submit()
Shell.cmd("cp -af $ruleFile $PERSIST/$id").submit()
}
}
@ -103,7 +103,7 @@ data class LocalModule(
init {
runCatching {
parseProps(Shell.su("dos2unix < $path/module.prop").exec().out)
parseProps(Shell.cmd("dos2unix < $path/module.prop").exec().out)
}
if (id.isEmpty()) {

View File

@ -36,7 +36,7 @@ class SuRequestHandler(
// Never allow com.topjohnwu.magisk (could be malware)
if (policy.packageName == BuildConfig.APPLICATION_ID) {
Shell.su("(pm uninstall ${BuildConfig.APPLICATION_ID})& >/dev/null 2>&1").exec()
Shell.cmd("(pm uninstall ${BuildConfig.APPLICATION_ID})& >/dev/null 2>&1").exec()
return false
}

View File

@ -63,7 +63,7 @@ open class FlashZip(
console.add("- Installing ${mUri.displayName}")
return Shell.su("sh $installDir/update-binary dummy 1 \'$zipFile\'")
return Shell.cmd("sh $installDir/update-binary dummy 1 \'$zipFile\'")
.to(console, logs).exec().isSuccess
}
@ -79,7 +79,7 @@ open class FlashZip(
Timber.e(e)
false
} finally {
Shell.su("cd /", "rm -rf $installDir ${Const.TMPDIR}").submit()
Shell.cmd("cd /", "rm -rf $installDir ${Const.TMPDIR}").submit()
}
}
}

View File

@ -110,7 +110,7 @@ object HideAPK {
Timber.e(e)
stub.createNewFile()
val cmd = "\$MAGISKBIN/magiskinit -x manager ${stub.path}"
if (!Shell.su(cmd).exec().isSuccess)
if (!Shell.cmd(cmd).exec().isSuccess)
return false
}

View File

@ -452,7 +452,7 @@ abstract class MagiskInstaller(
if (success) {
console.add("- All done!")
} else {
Shell.sh("rm -rf $installDir").submit()
Shell.cmd("rm -rf $installDir").submit()
console.add("! Installation failed")
}
return success
@ -497,7 +497,7 @@ abstract class MagiskInstaller(
val success = super.exec()
if (success) {
UiThreadHandler.handler.postDelayed(3000) {
Shell.su("pm uninstall ${context.packageName}").exec()
Shell.cmd("pm uninstall ${context.packageName}").exec()
}
}
return success

View File

@ -5,6 +5,7 @@ import android.content.Intent
import android.content.ServiceConnection
import android.os.Binder
import android.os.IBinder
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ipc.RootService
import timber.log.Timber
import java.util.concurrent.CountDownLatch
@ -48,6 +49,6 @@ class RootRegistry(stub: Any?) : RootService() {
}
companion object {
var bindTask: Runnable? = null
var bindTask: Shell.Task? = null
}
}

View File

@ -19,7 +19,7 @@ import java.util.jar.JarFile
class ShellInit : Shell.Initializer() {
override fun onInit(context: Context, shell: Shell): Boolean {
if (shell.isRoot) {
RootRegistry.bindTask?.run()
RootRegistry.bindTask?.let { shell.execTask(it) }
RootRegistry.bindTask = null
}
shell.newJob().apply {

View File

@ -29,9 +29,9 @@ class LogRepository(
}
}
if (Info.env.isActive) {
Shell.su("cat ${Const.MAGISK_LOG} || logcat -d -s Magisk").to(list).await()
Shell.cmd("cat ${Const.MAGISK_LOG} || logcat -d -s Magisk").to(list).await()
} else {
Shell.sh("logcat -d").to(list).await()
Shell.cmd("logcat -d").to(list).await()
}
return list.buf.toString()
}
@ -39,7 +39,7 @@ class LogRepository(
suspend fun clearLogs() = logDao.deleteAll()
fun clearMagiskLogs(cb: (Shell.Result) -> Unit) =
Shell.su("echo -n > ${Const.MAGISK_LOG}").submit(cb)
Shell.cmd("echo -n > ${Const.MAGISK_LOG}").submit(cb)
suspend fun insert(log: SuLog) = logDao.insert(log)

View File

@ -20,7 +20,7 @@ object RebootEvent {
R.id.action_reboot_bootloader -> systemReboot("bootloader")
R.id.action_reboot_download -> systemReboot("download")
R.id.action_reboot_edl -> systemReboot("edl")
R.id.action_reboot_recovery -> Shell.su("/system/bin/reboot recovery").submit()
R.id.action_reboot_recovery -> Shell.cmd("/system/bin/reboot recovery").submit()
else -> Unit
}
return true

View File

@ -34,7 +34,7 @@ class UninstallDialog : DialogEvent() {
show()
}
Shell.su("restore_imgs").submit { result ->
Shell.cmd("restore_imgs").submit { result ->
dialog.dismiss()
if (result.isSuccess) {
Utils.toast(R.string.restore_done, Toast.LENGTH_SHORT)

View File

@ -84,7 +84,7 @@ fun Intent.startActivity(context: Context) = context.startActivity(this)
fun Intent.startActivityWithRoot() {
val args = mutableListOf("am", "start", "--user", Const.USER_ID.toString())
val cmd = toCommand(args).joinToString(" ")
Shell.su(cmd).submit()
Shell.cmd(cmd).submit()
}
fun Intent.toCommand(args: MutableList<String> = mutableListOf()): MutableList<String> {

View File

@ -8,14 +8,14 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
fun reboot(reason: String = if (Config.recovery) "recovery" else "") {
Shell.su("/system/bin/svc power reboot $reason || /system/bin/reboot $reason").submit()
Shell.cmd("/system/bin/svc power reboot $reason || /system/bin/reboot $reason").submit()
}
fun relaunchApp(context: Context) {
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName) ?: return
val args = mutableListOf("am", "start", "--user", Const.USER_ID.toString())
val cmd = intent.toCommand(args).joinToString(separator = " ")
Shell.su("run_delay 1 \"$cmd\"").exec()
Shell.cmd("run_delay 1 \"$cmd\"").exec()
Runtime.getRuntime().exit(0)
}

View File

@ -103,7 +103,7 @@ class ProcessRvItem(
set(value) = set(value, process.isEnabled, { process.isEnabled = it }, BR.enabled) {
val arg = if (it) "add" else "rm"
val (name, pkg) = process
Shell.su("magisk --denylist $arg $pkg \'$name\'").submit()
Shell.cmd("magisk --denylist $arg $pkg \'$name\'").submit()
}
fun toggle() {

View File

@ -52,7 +52,7 @@ class DenyListViewModel : BaseViewModel() {
state = State.LOADING
val (apps, diff) = withContext(Dispatchers.Default) {
val pm = AppContext.packageManager
val denyList = Shell.su("magisk --denylist ls").exec().out
val denyList = Shell.cmd("magisk --denylist ls").exec().out
.map { CmdlineListItem(it) }
val apps = pm.getInstalledApplications(MATCH_UNINSTALLED_PACKAGES).run {
asFlow()

View File

@ -144,7 +144,7 @@ class HomeViewModel(
private suspend fun ensureEnv() {
if (MagiskState.NOT_INSTALLED == stateMagisk || checkedEnv) return
val cmd = "env_check ${Info.env.versionString} ${Info.env.versionCode}"
if (!Shell.su(cmd).await().isSuccess) {
if (!Shell.cmd(cmd).await().isSuccess) {
EnvFixDialog(this).publish()
}
checkedEnv = true

View File

@ -257,7 +257,7 @@ object DenyList : BaseSettingsItem.Toggle() {
set(value) {
field = value
val cmd = if (value) "enable" else "disable"
Shell.su("magisk --denylist $cmd").submit { result ->
Shell.cmd("magisk --denylist $cmd").submit { result ->
if (result.isSuccess) {
Config.denyList = value
} else {

View File

@ -134,7 +134,7 @@ class SettingsViewModel : BaseViewModel(), BaseSettingsItem.Handler {
}
private fun createHosts() {
Shell.su("add_hosts_module").submit {
Shell.cmd("add_hosts_module").submit {
Utils.toast(R.string.settings_hosts_toast, Toast.LENGTH_SHORT)
}
}

View File

@ -25,7 +25,7 @@ tasks.withType<KotlinCompile> {
dependencies {
implementation(kotlin("gradle-plugin", "1.6.10"))
implementation("com.android.tools.build:gradle:7.1.1")
implementation("com.android.tools.build:gradle:7.1.2")
implementation("androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0-alpha01")
implementation("io.michaelrocks:paranoid-gradle-plugin:0.3.7")
implementation("org.eclipse.jgit:org.eclipse.jgit:5.12.0.202106070339-r")