You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Update env fix handling logic
This commit is contained in:
@@ -31,7 +31,10 @@ sealed class Configuration : Parcelable {
|
||||
@Parcelize
|
||||
object Uninstall : Configuration()
|
||||
|
||||
@Parcelize
|
||||
object EnvFix : Configuration()
|
||||
|
||||
@Parcelize
|
||||
data class Patch(val fileUri: Uri) : Configuration()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ sealed class DownloadSubject : Parcelable {
|
||||
open val title: String get() = file.name
|
||||
|
||||
@Parcelize
|
||||
data class Module(
|
||||
class Module(
|
||||
val module: Repo,
|
||||
val configuration: Configuration
|
||||
) : DownloadSubject() {
|
||||
@@ -33,7 +33,7 @@ sealed class DownloadSubject : Parcelable {
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class Manager(
|
||||
class Manager(
|
||||
val configuration: Configuration.APK
|
||||
) : DownloadSubject() {
|
||||
|
||||
@@ -53,13 +53,13 @@ sealed class DownloadSubject : Parcelable {
|
||||
|
||||
}
|
||||
|
||||
sealed class Magisk : DownloadSubject() {
|
||||
abstract class Magisk : DownloadSubject() {
|
||||
|
||||
abstract val configuration: Configuration
|
||||
val magisk: MagiskJson = Info.remote.magisk
|
||||
|
||||
@Parcelize
|
||||
data class Flash(
|
||||
private class DownloadInternal(
|
||||
override val configuration: Configuration
|
||||
) : Magisk() {
|
||||
override val url: String get() = magisk.link
|
||||
@@ -72,8 +72,8 @@ sealed class DownloadSubject : Parcelable {
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
class Uninstall : Magisk() {
|
||||
override val configuration: Configuration get() = Configuration.Uninstall
|
||||
private class Uninstall : Magisk() {
|
||||
override val configuration get() = Configuration.Uninstall
|
||||
override val url: String get() = Info.remote.uninstaller.link
|
||||
|
||||
@IgnoredOnParcel
|
||||
@@ -83,8 +83,8 @@ sealed class DownloadSubject : Parcelable {
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
class Download : Magisk() {
|
||||
override val configuration: Configuration get() = Configuration.Download
|
||||
private class Download : Magisk() {
|
||||
override val configuration get() = Configuration.Download
|
||||
override val url: String get() = magisk.link
|
||||
|
||||
@IgnoredOnParcel
|
||||
@@ -97,7 +97,8 @@ sealed class DownloadSubject : Parcelable {
|
||||
operator fun invoke(configuration: Configuration) = when (configuration) {
|
||||
Configuration.Download -> Download()
|
||||
Configuration.Uninstall -> Uninstall()
|
||||
else -> Flash(configuration)
|
||||
Configuration.EnvFix, is Configuration.Flash -> DownloadInternal(configuration)
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.topjohnwu.magisk.model.events.dialog
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.widget.Toast
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.core.tasks.MagiskInstaller
|
||||
import com.topjohnwu.magisk.core.utils.Utils
|
||||
import com.topjohnwu.magisk.extensions.reboot
|
||||
import com.topjohnwu.magisk.core.download.DownloadService
|
||||
import com.topjohnwu.magisk.model.entity.internal.Configuration.EnvFix
|
||||
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Magisk
|
||||
import com.topjohnwu.magisk.view.MagiskDialog
|
||||
import com.topjohnwu.superuser.internal.UiThreadHandler
|
||||
import org.koin.core.KoinComponent
|
||||
|
||||
class EnvFixDialog : DialogEvent() {
|
||||
|
||||
@@ -21,14 +22,16 @@ class EnvFixDialog : DialogEvent() {
|
||||
onClick {
|
||||
dialog.applyTitle(R.string.setup_title)
|
||||
.applyMessage(R.string.setup_msg)
|
||||
.applyButton(MagiskDialog.ButtonType.POSITIVE) {
|
||||
title = ""
|
||||
}
|
||||
.applyButton(MagiskDialog.ButtonType.NEGATIVE) {
|
||||
title = ""
|
||||
}
|
||||
.resetButtons()
|
||||
.cancellable(false)
|
||||
fixEnv(it)
|
||||
val lbm = LocalBroadcastManager.getInstance(dialog.context)
|
||||
lbm.registerReceiver(object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent?) {
|
||||
dialog.dismiss()
|
||||
lbm.unregisterReceiver(this)
|
||||
}
|
||||
}, IntentFilter(DISMISS))
|
||||
DownloadService(dialog.context) { subject = Magisk(EnvFix) }
|
||||
}
|
||||
}
|
||||
.applyButton(MagiskDialog.ButtonType.NEGATIVE) {
|
||||
@@ -36,20 +39,7 @@ class EnvFixDialog : DialogEvent() {
|
||||
}
|
||||
.let { Unit }
|
||||
|
||||
private fun fixEnv(dialog: DialogInterface) {
|
||||
object : MagiskInstaller(), KoinComponent {
|
||||
override fun operations() = fixEnv()
|
||||
|
||||
override fun onResult(success: Boolean) {
|
||||
dialog.dismiss()
|
||||
Utils.toast(
|
||||
if (success) R.string.reboot_delay_toast else R.string.setup_fail,
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
if (success)
|
||||
UiThreadHandler.handler.postDelayed({ reboot() }, 5000)
|
||||
}
|
||||
}.exec()
|
||||
companion object {
|
||||
const val DISMISS = "com.topjohnwu.magisk.ENV_DONE"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.topjohnwu.magisk.model.flash
|
||||
|
||||
interface FlashResultListener {
|
||||
|
||||
fun onResult(isSuccess: Boolean)
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.topjohnwu.magisk.model.flash
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.core.os.postDelayed
|
||||
import com.topjohnwu.magisk.core.tasks.FlashZip
|
||||
import com.topjohnwu.magisk.extensions.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: FlashResultListener
|
||||
) : FlashZip(uri, console, log) {
|
||||
|
||||
override fun onResult(success: Boolean) {
|
||||
if (!success) {
|
||||
console.add("! Installation failed")
|
||||
}
|
||||
|
||||
resultListener.onResult(success)
|
||||
}
|
||||
|
||||
class Install(
|
||||
uri: Uri,
|
||||
console: MutableList<String>,
|
||||
log: MutableList<String>,
|
||||
resultListener: FlashResultListener
|
||||
) : 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: FlashResultListener
|
||||
) : 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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.topjohnwu.magisk.model.flash
|
||||
|
||||
import android.net.Uri
|
||||
import com.topjohnwu.magisk.core.tasks.MagiskInstaller
|
||||
import com.topjohnwu.superuser.Shell
|
||||
|
||||
sealed class Patching(
|
||||
file: Uri,
|
||||
private val console: MutableList<String>,
|
||||
logs: MutableList<String>,
|
||||
private val resultListener: FlashResultListener
|
||||
) : MagiskInstaller(file, 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.onResult(success)
|
||||
}
|
||||
|
||||
class File(
|
||||
file: Uri,
|
||||
private val uri: Uri,
|
||||
console: MutableList<String>,
|
||||
logs: MutableList<String>,
|
||||
resultListener: FlashResultListener
|
||||
) : Patching(file, console, logs, resultListener) {
|
||||
override fun operations() = doPatchFile(uri)
|
||||
}
|
||||
|
||||
class SecondSlot(
|
||||
file: Uri,
|
||||
console: MutableList<String>,
|
||||
logs: MutableList<String>,
|
||||
resultListener: FlashResultListener
|
||||
) : Patching(file, console, logs, resultListener) {
|
||||
override fun operations() = secondSlot()
|
||||
}
|
||||
|
||||
class Direct(
|
||||
file: Uri,
|
||||
console: MutableList<String>,
|
||||
logs: MutableList<String>,
|
||||
resultListener: FlashResultListener
|
||||
) : Patching(file, console, logs, resultListener) {
|
||||
override fun operations() = direct()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user