From e437ffdbae065b5a08456412a8e036c191a3903e Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 24 Aug 2020 04:04:52 -0700 Subject: [PATCH] Improvements to the installation UI - No longer show irrelevant options to the user - No longer require an additional button press to start installation --- .../java/com/topjohnwu/magisk/core/Config.kt | 4 +++ .../java/com/topjohnwu/magisk/core/Info.kt | 8 ++--- .../magisk/core/tasks/MagiskInstaller.kt | 12 +++---- .../topjohnwu/magisk/core/utils/RootInit.kt | 15 +++++++-- .../main/java/com/topjohnwu/magisk/ktx/XSU.kt | 4 +-- .../magisk/ui/install/InstallFragment.kt | 3 +- .../magisk/ui/install/InstallViewModel.kt | 6 ++-- .../main/res/layout/fragment_install_md2.xml | 32 ++++++++----------- 8 files changed, 44 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt index 8d0e0be61..934868309 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt @@ -106,6 +106,10 @@ object Config : PreferenceModel, DBConfig { else Value.DEFAULT_CHANNEL + @JvmStatic var keepVerity = false + @JvmStatic var keepEnc = false + @JvmStatic var recovery = false + var bootId by preference(Key.BOOT_ID, "") var askedHome by preference(Key.ASKED_HOME, false) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt index 59956d935..af51ff5e9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt @@ -26,14 +26,10 @@ object Info { var remote = UpdateInfo() - // Toggle-able options - @JvmStatic var keepVerity = false - @JvmStatic var keepEnc = false - @JvmStatic var recovery = false - - // Immutable device state + // Device state @JvmStatic var isSAR = false @JvmStatic var isAB = false + @JvmStatic var isFBE = false @JvmStatic var ramdisk = false @JvmStatic var hasGMS = true diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index b4da7ef23..d9c7483fb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -9,15 +9,15 @@ import androidx.annotation.WorkerThread import androidx.core.os.postDelayed import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.core.Info +import com.topjohnwu.magisk.core.Config +import com.topjohnwu.magisk.core.utils.MediaStoreUtils +import com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream +import com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream import com.topjohnwu.magisk.data.network.GithubRawServices import com.topjohnwu.magisk.di.Protected import com.topjohnwu.magisk.events.dialog.EnvFixDialog import com.topjohnwu.magisk.ktx.reboot import com.topjohnwu.magisk.ktx.withStreams -import com.topjohnwu.magisk.core.utils.MediaStoreUtils -import com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream -import com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.signing.SignBoot import com.topjohnwu.superuser.Shell @@ -272,8 +272,8 @@ abstract class MagiskInstallImpl : KoinComponent { return false } - if (!("KEEPFORCEENCRYPT=${Info.keepEnc} KEEPVERITY=${Info.keepVerity} " + - "RECOVERYMODE=${Info.recovery} sh update-binary " + + if (!("KEEPFORCEENCRYPT=${Config.keepEnc} KEEPVERITY=${Config.keepVerity} " + + "RECOVERYMODE=${Config.recovery} sh update-binary " + "sh boot_patch.sh $srcBoot").sh().isSuccess) { return false } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt index 6d38d656a..2a44738a0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt @@ -1,13 +1,16 @@ package com.topjohnwu.magisk.core.utils import android.content.Context +import android.os.Build import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.wrap import com.topjohnwu.magisk.ktx.rawResource import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.ShellUtils +import com.topjohnwu.superuser.io.SuFile class RootInit : Shell.Initializer() { @@ -39,13 +42,19 @@ class RootInit : Shell.Initializer() { fun getBool(name: String) = getvar(name).toBoolean() Const.MAGISKTMP = getvar("MAGISKTMP") - Info.keepVerity = getBool("KEEPVERITY") - Info.keepEnc = getBool("KEEPFORCEENCRYPT") Info.isSAR = getBool("SYSTEM_ROOT") Info.ramdisk = getBool("RAMDISKEXIST") - Info.recovery = getBool("RECOVERYMODE") Info.isAB = getBool("ISAB") + // FBE does not exist pre 7.0 + if (Build.VERSION.SDK_INT >= 24) + Info.isFBE = SuFile("/data/unencrypted").exists() + + // Default presets + Config.recovery = getBool("RECOVERYMODE") + Config.keepVerity = getBool("KEEPVERITY") + Config.keepEnc = getBool("KEEPFORCEENCRYPT") + return true } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt b/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt index a500d7cb7..7127e5e5a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt @@ -1,13 +1,13 @@ package com.topjohnwu.magisk.ktx import android.content.Context +import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const -import com.topjohnwu.magisk.core.Info import com.topjohnwu.superuser.Shell import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -fun reboot(reason: String = if (Info.recovery) "recovery" else "") { +fun reboot(reason: String = if (Config.recovery) "recovery" else "") { Shell.su("/system/bin/svc power reboot $reason || /system/bin/reboot $reason").submit() } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt index 2182416f6..993d6efb7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt @@ -7,6 +7,7 @@ import com.topjohnwu.magisk.arch.BaseUIFragment import com.topjohnwu.magisk.core.download.BaseDownloadService import com.topjohnwu.magisk.databinding.FragmentInstallMd2Binding import com.topjohnwu.magisk.events.RequestFileEvent +import com.topjohnwu.magisk.ktx.coroutineScope import org.koin.androidx.viewmodel.ext.android.viewModel class InstallFragment : BaseUIFragment() { @@ -24,7 +25,7 @@ class InstallFragment : BaseUIFragment + @@ -168,8 +173,10 @@ isEnabled="@{viewModel.method == @id/method_patch ? viewModel.data != null : viewModel.method != -1}" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:onClick="@{() -> viewModel.step(2)}" - android:text="@string/install_next" /> + android:onClick="@{() -> viewModel.install()}" + android:text="@string/install_start" + app:icon="@drawable/ic_forth_md2" + app:iconGravity="textEnd"/> @@ -211,7 +218,7 @@ @@ -224,7 +231,6 @@ -