From 86481c74ffc804d6e3fc01ce89102af3ca4dbab5 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 8 Sep 2019 00:44:26 -0400 Subject: [PATCH] Allow user to select recovery mode Close #1674 --- .../com/topjohnwu/magisk/ui/home/HomeViewModel.kt | 4 ++++ app/src/main/res/layout/fragment_magisk.xml | 12 ++++++++++++ app/src/main/res/values/strings.xml | 1 + scripts/boot_patch.sh | 8 +++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index d14dc9d8e..2c98a4190 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -41,6 +41,7 @@ class HomeViewModel( val isForceEncryption = KObservableField(Info.keepEnc) val isKeepVerity = KObservableField(Info.keepVerity) + val isRecovery = KObservableField(Info.recovery) private val _magiskState = KObservableField(MagiskState.LOADING) val magiskState = Observer(_magiskState, isConnected) { @@ -112,6 +113,9 @@ class HomeViewModel( isKeepVerity.addOnPropertyChangedCallback { Info.keepVerity = it ?: return@addOnPropertyChangedCallback } + isRecovery.addOnPropertyChangedCallback { + Info.recovery = it ?: return@addOnPropertyChangedCallback + } isConnected.addOnPropertyChangedCallback { if (it == true) refresh() } diff --git a/app/src/main/res/layout/fragment_magisk.xml b/app/src/main/res/layout/fragment_magisk.xml index 763f2aaea..e72cecda2 100644 --- a/app/src/main/res/layout/fragment_magisk.xml +++ b/app/src/main/res/layout/fragment_magisk.xml @@ -185,6 +185,18 @@ app:layout_constraintWidth_default="wrap" app:layout_constraintWidth_min="300dp" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 08e22d74d..87ba28157 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -24,6 +24,7 @@ Advanced Settings Preserve force encryption Preserve AVB 2.0/dm-verity + Recovery Mode Installed: %1$s Latest: %1$s Uninstall diff --git a/scripts/boot_patch.sh b/scripts/boot_patch.sh index 2129f852e..4f4510771 100644 --- a/scripts/boot_patch.sh +++ b/scripts/boot_patch.sh @@ -7,7 +7,7 @@ # Usage: boot_patch.sh # # The following flags can be set in environment variables: -# KEEPVERITY, KEEPFORCEENCRYPT +# KEEPVERITY, KEEPFORCEENCRYPT, RECOVERYMODE # # This script should be placed in a directory with the following files: # @@ -84,6 +84,8 @@ case $? in ;; esac +[ -f recovery_dtbo ] && RECOVERYMODE=true + ########################################################################################## # Ramdisk restores ########################################################################################## @@ -101,7 +103,7 @@ case $((STATUS & 3)) in 0 ) # Stock boot ui_print "- Stock boot image detected" ui_print "- Backing up stock boot image" - SHA1=`./magiskboot --sha1 "$BOOTIMAGE" 2>/dev/null` + SHA1=`./magiskboot sha1 "$BOOTIMAGE" 2>/dev/null` STOCKDUMP=stock_boot_${SHA1}.img.gz ./magiskboot compress "$BOOTIMAGE" $STOCKDUMP cp -af ramdisk.cpio ramdisk.cpio.orig 2>/dev/null @@ -133,8 +135,8 @@ ui_print "- Patching ramdisk" echo "KEEPVERITY=$KEEPVERITY" > config echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config +echo "RECOVERYMODE=$RECOVERYMODE" >> config [ ! -z $SHA1 ] && echo "SHA1=$SHA1" >> config -[ -f recovery_dtbo ] && echo "RECOVERYMODE=true" >> config ./magiskboot cpio ramdisk.cpio \ "add 750 init magiskinit" \