diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c4259fc6b..05d3efbf3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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}") diff --git a/app/src/main/java/com/topjohnwu/magisk/arch/BaseMainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/arch/BaseMainActivity.kt index f38f615c9..ba74f1e3f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/arch/BaseMainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/arch/BaseMainActivity.kt @@ -111,13 +111,13 @@ abstract class BaseMainActivity : 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) } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/App.kt b/app/src/main/java/com/topjohnwu/magisk/core/App.kt index afd9c1430..31d7cde65 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/App.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/App.kt @@ -70,7 +70,7 @@ open class App() : Application() { override fun onCreate() { super.onCreate() - RootRegistry.bindTask = RootService.createBindTask( + RootRegistry.bindTask = RootService.bindOrTask( intent(), 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 diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt b/app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt index 7d639ee1f..f1bcf12dd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt @@ -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 -> { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/Query.kt b/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/Query.kt index 61c04f1e3..6967a6e15 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/Query.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/Query.kt @@ -18,7 +18,7 @@ class Query(private val _query: String) { suspend inline fun query(crossinline mapper: (Map) -> R?): List = 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 { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt index 44593c779..fbc799fc1 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt @@ -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()) { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt b/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt index f05af77be..4238f5323 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt @@ -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 } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/FlashZip.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/FlashZip.kt index 493cb125d..480f86c96 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/FlashZip.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/FlashZip.kt @@ -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() } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt index 213209ab8..f86e40fd4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt @@ -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 } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index 995be3f05..08287289a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -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 diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootRegistry.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootRegistry.kt index a5587960e..4fae2cb3a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootRegistry.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootRegistry.kt @@ -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 } } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt index cfde6eb0c..7f5a9d284 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt @@ -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 { diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/LogRepository.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/LogRepository.kt index 7973fe4a7..b825a7b7e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/LogRepository.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/LogRepository.kt @@ -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) diff --git a/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt b/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt index 6ef20270a..6843e3039 100644 --- a/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt @@ -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 diff --git a/app/src/main/java/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt index 7a07bffbd..bf2ab8f80 100644 --- a/app/src/main/java/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt @@ -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) diff --git a/app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt b/app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt index 711082f75..e4c692287 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt @@ -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 = mutableListOf()): MutableList { diff --git a/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt b/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt index 7127e5e5a..c1496167f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt @@ -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) } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListRvItem.kt index fb36ea95e..678734cea 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListRvItem.kt @@ -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() { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt index 3df51fb7b..288cbf097 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt @@ -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() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index 54772bdc3..6828dc215 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -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 diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt index e12da0c5b..c6e676302 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt @@ -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 { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt index ca9f78875..e6c18a86e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt @@ -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) } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index d661f2717..1c0a1318a 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -25,7 +25,7 @@ tasks.withType { 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")