From 85755e30227e3eabc01011533309d742baf40087 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 5 May 2020 01:22:40 -0700 Subject: [PATCH] Tone down our DTB patching - Do not attempt to patch DTB anywhere outside of boot images as they are no longer essential. This makes Magisk installation to only modify strictly boot/recovery partitions again. - The only required patch for DTB is to strip verity out of partitions --- .../topjohnwu/magisk/core/SplashActivity.kt | 4 -- .../topjohnwu/magisk/core/tasks/DTBPatch.kt | 37 ------------------- .../magisk/core/tasks/MagiskInstallImpl.kt | 5 +-- .../magisk/core/view/Notifications.kt | 26 ------------- app/src/main/res/raw/manager.sh | 23 ------------ scripts/boot_patch.sh | 5 --- scripts/util_functions.sh | 22 ----------- 7 files changed, 1 insertion(+), 121 deletions(-) delete mode 100644 app/src/main/java/com/topjohnwu/magisk/core/tasks/DTBPatch.kt diff --git a/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt b/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt index e75376d08..41d68b2d2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt @@ -5,7 +5,6 @@ import android.content.Context import android.os.Bundle import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.core.tasks.patchDTB import com.topjohnwu.magisk.core.utils.Utils import com.topjohnwu.magisk.core.view.Notifications import com.topjohnwu.magisk.core.view.Shortcuts @@ -48,9 +47,6 @@ open class SplashActivity : Activity() { Utils.scheduleUpdateCheck(this) Shortcuts.setup(this) - // Patch DTB partitions if needed - patchDTB(this) - // Pre-fetch network stuffs get() diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/DTBPatch.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/DTBPatch.kt deleted file mode 100644 index b4d026e4f..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/DTBPatch.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.topjohnwu.magisk.core.tasks - -import android.content.Context -import android.content.ContextWrapper -import android.content.Intent -import android.content.IntentFilter -import com.topjohnwu.magisk.core.Const -import com.topjohnwu.magisk.core.Info -import com.topjohnwu.magisk.core.base.BaseReceiver -import com.topjohnwu.magisk.core.view.Notifications -import com.topjohnwu.superuser.Shell -import timber.log.Timber - -private const val DTB_PATCH_RESULT = "dtb_result" -private const val DTB_PATCH_ACTION = "com.topjohnwu.magisk.DTBO_PATCH" - -private class DTBPatchReceiver : BaseReceiver() { - override fun onReceive(context: ContextWrapper, intent: Intent?) { - intent?.also { - val result = it.getIntExtra(DTB_PATCH_RESULT, 1) - Timber.d("result=[$result]") - if (result == 0) - Notifications.dtboPatched(context) - } - context.unregisterReceiver(this) - } -} - -fun patchDTB(context: Context) { - if (Info.isNewReboot) { - val c = context.applicationContext - c.registerReceiver(DTBPatchReceiver(), IntentFilter(DTB_PATCH_ACTION)) - val broadcastCmd = "am broadcast --user ${Const.USER_ID} -p ${c.packageName} " + - "-a $DTB_PATCH_ACTION --ei $DTB_PATCH_RESULT \$result" - Shell.su("mm_patch_dtb '$broadcastCmd'").submit() - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstallImpl.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstallImpl.kt index 956c9ff0c..fca87e49e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstallImpl.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstallImpl.kt @@ -287,10 +287,7 @@ abstract class MagiskInstallImpl : FlashResultListener { private fun flashBoot(): Boolean { if (!"direct_install $installDir $srcBoot".sh().isSuccess) return false - arrayOf( - "(KEEPVERITY=${Info.keepVerity} patch_dtb_partitions)", - "run_migrations" - ).sh() + arrayOf("run_migrations").sh() return true } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/view/Notifications.kt b/app/src/main/java/com/topjohnwu/magisk/core/view/Notifications.kt index ddcc7765e..a0fe52183 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/view/Notifications.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/view/Notifications.kt @@ -85,32 +85,6 @@ object Notifications { mgr.notify(Const.ID.APK_UPDATE_NOTIFICATION_ID, builder.build()) } - fun dtboPatched(context: Context) { - val intent = context.intent() - .setAction(Const.Key.BROADCAST_REBOOT) - val pendingIntent = PendingIntent.getBroadcast(context, - Const.ID.DTBO_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT) - - val builder = updateBuilder( - context - ) - .setContentTitle(context.getString(R.string.dtbo_patched_title)) - .setContentText(context.getString(R.string.dtbo_patched_reboot)) - - if (SDK_INT >= 23) { - val action = Notification.Action.Builder( - context.getBitmap(R.drawable.ic_refresh).toIcon(), - context.getString(R.string.reboot), pendingIntent).build() - builder.addAction(action) - } else { - builder.addAction( - R.drawable.ic_refresh, - context.getString(R.string.reboot), pendingIntent) - } - - mgr.notify(Const.ID.DTBO_NOTIFICATION_ID, builder.build()) - } - fun progress(context: Context, title: CharSequence): Notification.Builder { val builder = if (SDK_INT >= 26) { Notification.Builder(context, PROGRESS_NOTIFICATION_CHANNEL) diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index dbf63d73e..34f2b19d9 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -34,29 +34,6 @@ direct_install() { return 0 } -mm_patch_dtb() { - (local result=1 - local PATCHED=$TMPDIR/dt.patched - for name in dtb dtbo; do - local IMAGE=`find_block $name$SLOT` - if [ ! -z $IMAGE ]; then - if $MAGISKBIN/magiskboot dtb $IMAGE patch $PATCHED; then - result=0 - if [ ! -z $SHA1 ]; then - # Backup stuffs - mkdir /data/magisk_backup_${SHA1} 2>/dev/null - cat $IMAGE | gzip -9 > /data/magisk_backup_${SHA1}/${name}.img.gz - fi - cat $PATCHED /dev/zero > $IMAGE - rm -f $PATCHED - fi - fi - done - # Run broadcast command passed from app - eval $1 - )& >/dev/null 2>&1 -} - restore_imgs() { [ -z $SHA1 ] && return 1 local BACKUPDIR=/data/magisk_backup_$SHA1 diff --git a/scripts/boot_patch.sh b/scripts/boot_patch.sh index 6a5b01851..f0189691d 100644 --- a/scripts/boot_patch.sh +++ b/scripts/boot_patch.sh @@ -117,11 +117,6 @@ case $((STATUS & 3)) in ;; esac -if [ $((STATUS & 8)) -ne 0 ]; then - # Possibly using 2SI, export env var - export TWOSTAGEINIT=true -fi - ################## # Ramdisk Patches ################## diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index d05f4b96c..7ceb8add0 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -420,27 +420,6 @@ flash_image() { return 0 } -patch_dtb_partitions() { - local result=1 - cd $MAGISKBIN - for name in dtb dtbo dtbs; do - local IMAGE=`find_block $name$SLOT` - if [ ! -z $IMAGE ]; then - ui_print "- $name image: $IMAGE" - if ./magiskboot dtb $IMAGE patch dt.patched; then - result=0 - ui_print "- Backing up stock $name image" - cat $IMAGE > stock_${name}.img - ui_print "- Flashing patched $name" - cat dt.patched /dev/zero > $IMAGE - rm -f dt.patched - fi - fi - done - cd / - return $result -} - # Common installation script for flash_script.sh and addon.d.sh install_magisk() { cd $MAGISKBIN @@ -478,7 +457,6 @@ install_magisk() { ./magiskboot cleanup rm -f new-boot.img - patch_dtb_partitions run_migrations }