diff --git a/app/src/main/java/com/topjohnwu/magisk/Config.kt b/app/src/main/java/com/topjohnwu/magisk/Config.kt index 8502a5f99..f39c49827 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Config.kt +++ b/app/src/main/java/com/topjohnwu/magisk/Config.kt @@ -3,9 +3,9 @@ package com.topjohnwu.magisk import android.content.Context import android.util.Xml import androidx.core.content.edit -import com.topjohnwu.magisk.data.repository.DBConfig import com.topjohnwu.magisk.data.database.SettingsDao import com.topjohnwu.magisk.data.database.StringDao +import com.topjohnwu.magisk.data.repository.DBConfig import com.topjohnwu.magisk.di.Protected import com.topjohnwu.magisk.model.preference.PreferenceModel import com.topjohnwu.magisk.utils.* diff --git a/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt index 55de36521..d1103a7cd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt @@ -1,6 +1,8 @@ package com.topjohnwu.magisk.di -import com.topjohnwu.magisk.data.repository.* +import com.topjohnwu.magisk.data.repository.AppRepository +import com.topjohnwu.magisk.data.repository.LogRepository +import com.topjohnwu.magisk.data.repository.MagiskRepository import org.koin.dsl.module diff --git a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt index 4807fdb62..636858e6a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt @@ -11,9 +11,9 @@ import com.topjohnwu.magisk.data.database.base.su import com.topjohnwu.magisk.data.repository.AppRepository import com.topjohnwu.magisk.ui.surequest.SuRequestActivity import com.topjohnwu.magisk.utils.DownloadApp -import com.topjohnwu.magisk.utils.RootUtils import com.topjohnwu.magisk.utils.SuLogger import com.topjohnwu.magisk.utils.inject +import com.topjohnwu.magisk.utils.reboot import com.topjohnwu.magisk.view.Notifications import com.topjohnwu.magisk.view.Shortcuts import com.topjohnwu.superuser.Shell @@ -76,7 +76,7 @@ open class GeneralReceiver : BroadcastReceiver() { Info.managerLink = intent.getStringExtra(Const.Key.INTENT_SET_LINK) DownloadApp.upgrade(intent.getStringExtra(Const.Key.INTENT_SET_NAME)) } - Const.Key.BROADCAST_REBOOT -> RootUtils.reboot() + Const.Key.BROADCAST_REBOOT -> reboot() } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt index 99d72aa13..8fa107221 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt @@ -103,7 +103,7 @@ class FlashViewModel( .subscribeK { SnackbarEvent(it).publish() } .add() - fun restartPressed() = RootUtils.reboot() + fun restartPressed() = reboot() fun backPressed() = back() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt index 08a14441f..146e5fcd8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt @@ -16,7 +16,7 @@ import com.topjohnwu.magisk.databinding.FragmentModulesBinding import com.topjohnwu.magisk.model.events.OpenFilePickerEvent import com.topjohnwu.magisk.ui.base.MagiskFragment import com.topjohnwu.magisk.ui.flash.FlashActivity -import com.topjohnwu.magisk.utils.RootUtils +import com.topjohnwu.magisk.utils.reboot import com.topjohnwu.superuser.Shell import org.koin.androidx.viewmodel.ext.android.sharedViewModel @@ -64,19 +64,20 @@ class ModulesFragment : MagiskFragment( override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.reboot -> { - RootUtils.reboot() + reboot() return true } R.id.reboot_recovery -> { - Shell.su("/system/bin/reboot recovery").submit() + reboot("recovery") return true } R.id.reboot_bootloader -> { + reboot("booloader") Shell.su("/system/bin/reboot bootloader").submit() return true } R.id.reboot_download -> { - Shell.su("/system/bin/reboot download").submit() + reboot("download") return true } else -> return false @@ -90,26 +91,4 @@ class ModulesFragment : MagiskFragment( startActivityForResult(intent, Const.ID.FETCH_ZIP) } } - - /*override fun getListeningEvents(): IntArray { - return intArrayOf(Event.MODULE_LOAD_DONE) - } - - override fun onEvent(event: Int) { - updateUI(Event.getResult(event)) - }*/ - - /*private fun updateUI(moduleMap: Map) { - listModules.clear() - listModules.addAll(moduleMap.values) - if (listModules.size == 0) { - emptyRv!!.visibility = View.VISIBLE - recyclerView!!.visibility = View.GONE - } else { - emptyRv!!.visibility = View.GONE - recyclerView!!.visibility = View.VISIBLE - recyclerView!!.adapter = ModulesAdapter(listModules) - } - mSwipeRefreshLayout!!.isRefreshing = false - }*/ } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/RootUtils.kt b/app/src/main/java/com/topjohnwu/magisk/utils/RootUtils.kt index fe8d0c9e8..edae6e30d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/RootUtils.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/RootUtils.kt @@ -155,10 +155,5 @@ class RootUtils : Shell.Initializer() { fun rmAndLaunch(rm: String, component: ComponentName) { Shell.su("(rm_launch $rm ${component.flattenToString()})").exec() } - - @JvmStatic - fun reboot() { - Shell.su("/system/bin/reboot ${if (Info.recovery) "recovery" else ""}").submit() - } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/XSU.kt b/app/src/main/java/com/topjohnwu/magisk/utils/XSU.kt index 5dcd620a6..2d0f2fbd4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/XSU.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/XSU.kt @@ -1,18 +1,13 @@ package com.topjohnwu.magisk.utils +import com.topjohnwu.magisk.Info import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.io.SuFileInputStream import com.topjohnwu.superuser.io.SuFileOutputStream import java.io.File -fun reboot(recovery: Boolean = false): Shell.Result { - val command = StringBuilder("/system/bin/reboot") - .appendIf(recovery) { - append(" recovery") - } - .toString() - - return Shell.su(command).exec() +fun reboot(reason: String = if (Info.recovery) "recovery" else "") { + Shell.su("/system/bin/svc power reboot $reason || /system/bin/reboot $reason").submit() } fun File.suOutputStream() = SuFileOutputStream(this) diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.java deleted file mode 100644 index de4931acf..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.topjohnwu.magisk.view.dialogs; - -import android.app.Activity; -import android.app.ProgressDialog; -import android.widget.Toast; - -import androidx.annotation.NonNull; - -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.tasks.MagiskInstaller; -import com.topjohnwu.magisk.utils.RootUtils; -import com.topjohnwu.magisk.utils.Utils; -import com.topjohnwu.superuser.Shell; -import com.topjohnwu.superuser.internal.UiThreadHandler; -import com.topjohnwu.superuser.io.SuFile; - -public class EnvFixDialog extends CustomAlertDialog { - - public EnvFixDialog(@NonNull Activity activity) { - super(activity); - setTitle(R.string.env_fix_title); - setMessage(R.string.env_fix_msg); - setCancelable(true); - setPositiveButton(R.string.yes, (d, i) -> { - ProgressDialog pd = ProgressDialog.show(activity, - activity.getString(R.string.setup_title), - activity.getString(R.string.setup_msg)); - new MagiskInstaller() { - @Override - protected boolean operations() { - installDir = new SuFile("/data/adb/magisk"); - Shell.su("rm -rf /data/adb/magisk/*").exec(); - return extractZip() && Shell.su("fix_env").exec().isSuccess(); - } - - @Override - protected void onResult(boolean success) { - pd.dismiss(); - Utils.INSTANCE.toast(success ? R.string.reboot_delay_toast : R.string.setup_fail, Toast.LENGTH_LONG); - if (success) - UiThreadHandler.handler.postDelayed(RootUtils::reboot, 5000); - } - }.exec(); - }); - setNegativeButton(R.string.no_thanks, null); - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.kt b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.kt new file mode 100644 index 000000000..521d61b27 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.kt @@ -0,0 +1,41 @@ +package com.topjohnwu.magisk.view.dialogs + +import android.app.Activity +import android.app.ProgressDialog +import android.widget.Toast +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.tasks.MagiskInstaller +import com.topjohnwu.magisk.utils.Utils +import com.topjohnwu.magisk.utils.reboot +import com.topjohnwu.superuser.Shell +import com.topjohnwu.superuser.internal.UiThreadHandler +import com.topjohnwu.superuser.io.SuFile + +class EnvFixDialog(activity: Activity) : CustomAlertDialog(activity) { + + init { + setTitle(R.string.env_fix_title) + setMessage(R.string.env_fix_msg) + setCancelable(true) + setPositiveButton(R.string.yes) { _, _ -> + val pd = ProgressDialog.show(activity, + activity.getString(R.string.setup_title), + activity.getString(R.string.setup_msg)) + object : MagiskInstaller() { + override fun operations(): Boolean { + installDir = SuFile("/data/adb/magisk") + Shell.su("rm -rf /data/adb/magisk/*").exec() + return extractZip() && Shell.su("fix_env").exec().isSuccess + } + + override fun onResult(success: Boolean) { + pd.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() + } + setNegativeButton(R.string.no_thanks, null) + } +}