From bef8ee0ed372e2c750c81371f2044dc67348750b Mon Sep 17 00:00:00 2001 From: 1q23lyc45 <174172451+1q23lyc45@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:52:53 +0000 Subject: [PATCH] Action.sh Suppport 9/13 --- .../magisk/core/model/module/LocalModule.kt | 3 ++ .../topjohnwu/magisk/core/tasks/RunAction.kt | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 app/src/main/java/com/topjohnwu/magisk/core/tasks/RunAction.kt 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 3d966d380..928efcb68 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 @@ -37,6 +37,7 @@ data class LocalModule( val isRiru: Boolean get() = (id == "riru-core") || riruFolder.exists() val isZygisk: Boolean get() = zygiskFolder.exists() val zygiskUnloaded: Boolean get() = unloaded.exists() + val hasAction: Boolean; var enable: Boolean get() = !disableFile.exists() @@ -100,6 +101,8 @@ data class LocalModule( if (name.isEmpty()) { name = id } + + hasAction = RootUtils.fs.getFile(path, "action.sh").exists() } suspend fun fetch(): Boolean { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/RunAction.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/RunAction.kt new file mode 100644 index 000000000..145849d5b --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/RunAction.kt @@ -0,0 +1,42 @@ +package com.topjohnwu.magisk.core.tasks + +import android.net.Uri +import androidx.core.net.toFile +import com.topjohnwu.magisk.core.AppContext +import com.topjohnwu.magisk.core.Const +import com.topjohnwu.magisk.core.ktx.writeTo +import com.topjohnwu.magisk.core.utils.MediaStoreUtils.displayName +import com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream +import com.topjohnwu.magisk.core.utils.unzip +import com.topjohnwu.superuser.Shell +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import timber.log.Timber +import java.io.File +import java.io.FileNotFoundException +import java.io.IOException + +open class RunAction( + private val module: String, + private val console: MutableList, + private val logs: MutableList +) { + @Throws(IOException::class) + private suspend fun run(): Boolean { + return Shell.cmd("run_action \'$module\'").to(console, logs).exec().isSuccess + } + + open suspend fun exec() = withContext(Dispatchers.IO) { + try { + if (!run()) { + console.add("! Run action failed") + false + } else { + true + } + } catch (e: IOException) { + Timber.e(e) + false + } + } +}