Rewritten flashing internal modules to model
This is done in an effort to separate flash activity to smaller pieces.
This commit is contained in:
parent
11d716a3c8
commit
aceb3ee863
@ -0,0 +1,62 @@
|
|||||||
|
package com.topjohnwu.magisk.model.flash
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.core.os.postDelayed
|
||||||
|
import com.topjohnwu.magisk.tasks.FlashZip
|
||||||
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
|
import com.topjohnwu.magisk.utils.inject
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import com.topjohnwu.superuser.internal.UiThreadHandler
|
||||||
|
|
||||||
|
sealed class Flashing(
|
||||||
|
uri: Uri,
|
||||||
|
private val console: MutableList<String>,
|
||||||
|
log: MutableList<String>,
|
||||||
|
private val resultListener: (Result<Boolean>) -> Unit
|
||||||
|
) : FlashZip(uri, console, log) {
|
||||||
|
|
||||||
|
override fun onResult(success: Boolean) {
|
||||||
|
if (!success) {
|
||||||
|
console.add("! Installation failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
resultListener(Result.success(success))
|
||||||
|
}
|
||||||
|
|
||||||
|
class Install(
|
||||||
|
uri: Uri,
|
||||||
|
console: MutableList<String>,
|
||||||
|
log: MutableList<String>,
|
||||||
|
resultListener: (Result<Boolean>) -> Unit = {}
|
||||||
|
) : Flashing(uri, console, log, resultListener) {
|
||||||
|
|
||||||
|
override fun onResult(success: Boolean) {
|
||||||
|
if (success) {
|
||||||
|
Utils.loadModules()
|
||||||
|
}
|
||||||
|
super.onResult(success)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Uninstall(
|
||||||
|
uri: Uri,
|
||||||
|
console: MutableList<String>,
|
||||||
|
log: MutableList<String>,
|
||||||
|
resultListener: (Result<Boolean>) -> Unit = {}
|
||||||
|
) : Flashing(uri, console, log, resultListener) {
|
||||||
|
|
||||||
|
private val context: Context by inject()
|
||||||
|
|
||||||
|
override fun onResult(success: Boolean) {
|
||||||
|
if (success) {
|
||||||
|
UiThreadHandler.handler.postDelayed(3000) {
|
||||||
|
Shell.su("pm uninstall " + context.packageName).exec()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onResult(success)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.topjohnwu.magisk.model.flash
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import com.topjohnwu.magisk.tasks.MagiskInstaller
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
|
||||||
|
sealed class Patching(
|
||||||
|
private val console: MutableList<String>,
|
||||||
|
logs: List<String>,
|
||||||
|
private val resultListener: (Result<Boolean>) -> Unit
|
||||||
|
) : MagiskInstaller(console, logs) {
|
||||||
|
|
||||||
|
override fun onResult(success: Boolean) {
|
||||||
|
if (success) {
|
||||||
|
console.add("- All done!")
|
||||||
|
} else {
|
||||||
|
Shell.sh("rm -rf $installDir").submit()
|
||||||
|
console.add("! Installation failed")
|
||||||
|
}
|
||||||
|
resultListener(Result.success(success))
|
||||||
|
}
|
||||||
|
|
||||||
|
class File(
|
||||||
|
private val uri: Uri,
|
||||||
|
console: MutableList<String>,
|
||||||
|
logs: List<String>,
|
||||||
|
resultListener: (Result<Boolean>) -> Unit = {}
|
||||||
|
) : Patching(console, logs, resultListener) {
|
||||||
|
override fun operations() =
|
||||||
|
extractZip() && handleFile(uri) && patchBoot() && storeBoot()
|
||||||
|
}
|
||||||
|
|
||||||
|
class SecondSlot(
|
||||||
|
console: MutableList<String>,
|
||||||
|
logs: List<String>,
|
||||||
|
resultListener: (Result<Boolean>) -> Unit = {}
|
||||||
|
) : Patching(console, logs, resultListener) {
|
||||||
|
override fun operations() =
|
||||||
|
findSecondaryImage() && extractZip() && patchBoot() && flashBoot() && postOTA()
|
||||||
|
}
|
||||||
|
|
||||||
|
class Direct(
|
||||||
|
console: MutableList<String>,
|
||||||
|
logs: List<String>,
|
||||||
|
resultListener: (Result<Boolean>) -> Unit = {}
|
||||||
|
) : Patching(console, logs, resultListener) {
|
||||||
|
override fun operations() =
|
||||||
|
findImage() && extractZip() && patchBoot() && flashBoot()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user