Make commands data class

This commit is contained in:
Mygod
2020-08-07 06:54:19 +08:00
parent 8ecc455f6b
commit 7b94be74a2
3 changed files with 9 additions and 8 deletions

View File

@@ -28,7 +28,7 @@ fun ProcessBuilder.fixPath(redirect: Boolean = false) = apply {
}
@Parcelize
class Dump(val path: String, val cacheDir: File = app.deviceStorage.codeCacheDir) : RootCommandNoResult {
data class Dump(val path: String, val cacheDir: File = app.deviceStorage.codeCacheDir) : RootCommandNoResult {
@Suppress("BlockingMethodInNonBlockingContext")
override suspend fun execute() = withContext(Dispatchers.IO) {
FileOutputStream(path, true).use { out ->
@@ -128,7 +128,8 @@ class ReadArp : RootCommand<ParcelableString> {
@Parcelize
@RequiresApi(30)
class StartTethering(private val type: Int, private val showProvisioningUi: Boolean) : RootCommand<ParcelableInt?> {
data class StartTethering(private val type: Int,
private val showProvisioningUi: Boolean) : RootCommand<ParcelableInt?> {
override suspend fun execute(): ParcelableInt? {
val future = CompletableDeferred<Int?>()
val callback = object : TetheringManager.StartTetheringCallback {
@@ -151,8 +152,8 @@ class StartTethering(private val type: Int, private val showProvisioningUi: Bool
@Parcelize
@RequiresApi(24)
@Suppress("DEPRECATION")
class StartTetheringLegacy(private val cacheDir: File, private val type: Int,
private val showProvisioningUi: Boolean) : RootCommand<ParcelableBoolean> {
data class StartTetheringLegacy(private val cacheDir: File, private val type: Int,
private val showProvisioningUi: Boolean) : RootCommand<ParcelableBoolean> {
override suspend fun execute(): ParcelableBoolean {
val future = CompletableDeferred<Boolean>()
val callback = object : TetheringManager.StartTetheringCallback {
@@ -172,7 +173,7 @@ class StartTetheringLegacy(private val cacheDir: File, private val type: Int,
@Parcelize
@RequiresApi(24)
class StopTethering(private val type: Int) : RootCommandNoResult {
data class StopTethering(private val type: Int) : RootCommandNoResult {
override suspend fun execute(): Parcelable? {
TetheringManager.stopTethering(type)
return null
@@ -180,7 +181,7 @@ class StopTethering(private val type: Int) : RootCommandNoResult {
}
@Parcelize
class SettingsGlobalPut(val name: String, val value: String) : RootCommandNoResult {
data class SettingsGlobalPut(val name: String, val value: String) : RootCommandNoResult {
companion object {
suspend fun int(name: String, value: Int) {
try {

View File

@@ -49,7 +49,7 @@ object RepeaterCommands {
}
@Parcelize
class SetChannel(private val oc: Int) : RootCommand<ParcelableInt?> {
data class SetChannel(private val oc: Int) : RootCommand<ParcelableInt?> {
override suspend fun execute() = Services.p2p!!.run {
setWifiP2pChannels(obtainChannel(), 0, oc)?.let { ParcelableInt(it) }
}

View File

@@ -45,7 +45,7 @@ object RoutingCommands {
}
@Parcelize
class Process(val command: List<String>, private val redirect: Boolean = false) : RootCommand<ProcessResult> {
data class Process(val command: List<String>, private val redirect: Boolean = false) : RootCommand<ProcessResult> {
@Suppress("BlockingMethodInNonBlockingContext")
override suspend fun execute() = withContext(Dispatchers.IO) {
val process = ProcessBuilder(command).fixPath(redirect).start()