diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 32d9847fa..1c1ccfcf7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -73,6 +73,7 @@ + BuildConfig.VERSION_CODE) { - ShowUI.showManagerInstallDialog(getActivity()); + ShowUI.managerInstallDialog(getActivity()); return; } ((NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll(); - ShowUI.showMagiskInstallDialog(this, + ShowUI.magiskInstallDialog(getActivity(), keepEncChkbox.isChecked(), keepVerityChkbox.isChecked()); } @OnClick(R.id.uninstall_button) void uninstall() { - ShowUI.showUninstallDialog(this); + ShowUI.uninstallDialog(getActivity()); } @Nullable @@ -207,25 +196,6 @@ public class MagiskFragment extends Fragment return expandableContainer; } - public String getSelectedBootImage() { - if (Shell.rootAccess()) { - if (mm.bootBlock != null) { - return mm.bootBlock; - } else { - int idx = spinner.getSelectedItemPosition(); - if (idx > 0) { - return mm.blockList.get(idx - 1); - } else { - SnackbarMaker.make(getActivity(), - R.string.manual_boot_image, Snackbar.LENGTH_LONG).show(); - return null; - } - } - } else { - return null; - } - } - private void updateUI() { ((MainActivity) getActivity()).checkHideSection(); @@ -235,7 +205,6 @@ public class MagiskFragment extends Fragment magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); safetyNetCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); - bootImageCard.setVisibility(hasNetwork && hasRoot ? View.VISIBLE : View.GONE); installOptionCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); uninstallButton.setVisibility(isUpToDate && hasRoot ? View.VISIBLE : View.GONE); @@ -253,20 +222,6 @@ public class MagiskFragment extends Fragment magiskStatusIcon.setImageResource(image); magiskStatusIcon.setColorFilter(color); - - List items = new ArrayList<>(); - if (mm.bootBlock != null) { - items.add(getString(R.string.auto_detect, mm.bootBlock)); - spinner.setEnabled(false); - } else { - items.add(getString(R.string.cannot_auto_detect)); - if (mm.blockList != null) - items.addAll(mm.blockList); - } - ArrayAdapter adapter = new ArrayAdapter<>(getActivity(), - android.R.layout.simple_spinner_item, items); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spinner.setAdapter(adapter); } private void updateCheckUI() { diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java index 0b5ffa7fc..588875e84 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java @@ -55,7 +55,6 @@ public class MagiskManager extends Application { // Data public Map moduleMap; - public List blockList; public List locales; // Configurations diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index 6ffdacbd8..9c4a3c7bc 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -21,8 +21,6 @@ import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; -import java.io.IOException; -import java.io.InputStream; import java.util.List; public class SplashActivity extends Activity { @@ -57,27 +55,10 @@ public class SplashActivity extends Activity { // Magisk working as expected if (Shell.rootAccess() && mm.magiskVersionCode > 0) { - // Load utility shell scripts - try (InputStream in = getAssets().open(Const.UTIL_FUNCTIONS)) { - Shell.getShell().loadInputStream(in); - } catch (IOException e) { - e.printStackTrace(); - } - - // Root shell initialization - Shell.su_raw( - "export PATH=" + Const.BUSYBOXPATH + ":$PATH", - "mount_partitions", - "BOOTIMAGE=", - "find_boot_image", - "migrate_boot_backup" - ); List ret = Shell.su("echo \"$BOOTIMAGE\""); if (Utils.isValidShellResponse(ret)) { mm.bootBlock = ret.get(0); - } else { - mm.blockList = Shell.su("find /dev/block -type b | grep -vE 'dm|ram|loop'"); } // Setup suDB @@ -105,6 +86,9 @@ public class SplashActivity extends Activity { // Fire asynctasks loadModuleTask.exec(); + + // Check dtbo status + Utils.patchDTBO(); } // Write back default values diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java index 4a233e4eb..1cf6ded2b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java @@ -55,9 +55,9 @@ public class CheckUpdates extends ParallelTask { MagiskManager mm = MagiskManager.get(); if (showNotification && mm.updateNotification) { if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) { - ShowUI.showManagerUpdateNotification(); + ShowUI.managerUpdateNotification(); } else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) { - ShowUI.showMagiskUpdateNotification(); + ShowUI.magiskUpdateNotification(); } } mm.updateCheckDone.publish(); diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java index 4dbea4151..8f0871b4f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java @@ -226,13 +226,15 @@ public class InstallMagisk extends ParallelTask { mList.add("*********************************"); break; case DIRECT_MODE: - // Direct flash boot image + // Direct flash boot image and patch dtbo if possible Shell.su(mList, "rm -rf /data/magisk/*", + "mkdir -p /data/magisk 2>/dev/null", "mv -f " + install + "/* /data/magisk", "rm -rf " + install, "flash_boot_image " + patched_boot + " " + mBootLocation, - "rm -rf " + patched_boot); + "rm -rf " + patched_boot, + "patch_dtbo_image"); break; default: return false; diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/RestoreStockBoot.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/RestoreStockBoot.java index 6854e28c4..1d19f73c3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/RestoreStockBoot.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/RestoreStockBoot.java @@ -11,30 +11,22 @@ import java.util.List; public class RestoreStockBoot extends ParallelTask { - private String mBoot; - - public RestoreStockBoot(String boot) { - mBoot = boot; - } - @Override protected Boolean doInBackground(Void... voids) { String sha1; List ret = Utils.readFile("/.backup/.sha1"); - if (!Utils.isValidShellResponse(ret)) { + if (Utils.isValidShellResponse(ret)) { + sha1 = ret.get(0); + } else { ret = Shell.su("cat /init.magisk.rc | grep STOCKSHA1"); if (!Utils.isValidShellResponse(ret)) return false; sha1 = ret.get(0).substring(ret.get(0).indexOf('=') + 1); - } else { - sha1 = ret.get(0); } - String stock_boot = "/data/stock_boot_" + sha1 + ".img.gz"; - if (!Utils.itemExist(stock_boot)) - return false; - Shell.su_raw("flash_boot_image " + stock_boot + " " + mBoot); - return true; + ret = Shell.su("restore_imgs " + sha1 + " && echo true || echo false"); + + return Utils.isValidShellResponse(ret) && Boolean.parseBoolean(ret.get(ret.size() - 1)); } @Override diff --git a/app/src/main/java/com/topjohnwu/magisk/components/Activity.java b/app/src/main/java/com/topjohnwu/magisk/components/Activity.java index 1e7d52b00..ad9cbbba6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/Activity.java +++ b/app/src/main/java/com/topjohnwu/magisk/components/Activity.java @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.components; +import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.content.res.Configuration; @@ -20,6 +21,7 @@ public class Activity extends AppCompatActivity { private AssetManager mAssetManager = null; private Resources mResources = null; + private ActivityResultListener activityResultListener; public Activity() { super(); @@ -83,6 +85,18 @@ public class Activity extends AppCompatActivity { } } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (activityResultListener != null) + activityResultListener.onActivityResult(requestCode, resultCode, data); + activityResultListener = null; + } + + public void startActivityForResult(Intent intent, int requestCode, ActivityResultListener listener) { + activityResultListener = listener; + super.startActivityForResult(intent, requestCode); + } + @Keep public void swapResources(String dexPath) { mAssetManager = Utils.getAssets(dexPath); @@ -99,4 +113,8 @@ public class Activity extends AppCompatActivity { mResources = null; } + public interface ActivityResultListener { + void onActivityResult(int requestCode, int resultCode, Intent data); + } + } diff --git a/app/src/main/java/com/topjohnwu/magisk/components/Fragment.java b/app/src/main/java/com/topjohnwu/magisk/components/Fragment.java index 5fc9d3861..74df99c32 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/Fragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/components/Fragment.java @@ -1,15 +1,11 @@ package com.topjohnwu.magisk.components; -import android.content.Intent; - import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Utils; public class Fragment extends android.support.v4.app.Fragment { - private ActivityResultListener activityResultListener; - public MagiskManager getApplication() { return Utils.getMagiskManager(getActivity()); } @@ -29,20 +25,4 @@ public class Fragment extends android.support.v4.app.Fragment { } super.onPause(); } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (activityResultListener != null) - activityResultListener.onActivityResult(requestCode, resultCode, data); - activityResultListener = null; - } - - public void startActivityForResult(Intent intent, int requestCode, ActivityResultListener listener) { - activityResultListener = listener; - super.startActivityForResult(intent, requestCode); - } - - public interface ActivityResultListener { - void onActivityResult(int requestCode, int resultCode, Intent data); - } } diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/BootReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/BootReceiver.java index 183f2f34c..189ed45e1 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/BootReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/BootReceiver.java @@ -19,10 +19,7 @@ public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { - // There is currently no need to start an IntentService onBoot - // startIntentService(context); - } + startIntentService(context); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/RebootReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/RebootReceiver.java new file mode 100644 index 000000000..41ce61ec0 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/RebootReceiver.java @@ -0,0 +1,14 @@ +package com.topjohnwu.magisk.receivers; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import com.topjohnwu.magisk.utils.Shell; + +public class RebootReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + Shell.su_raw("reboot"); + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/services/OnBootIntentService.java b/app/src/main/java/com/topjohnwu/magisk/services/OnBootIntentService.java index c82e465c0..5a3eca9c1 100644 --- a/app/src/main/java/com/topjohnwu/magisk/services/OnBootIntentService.java +++ b/app/src/main/java/com/topjohnwu/magisk/services/OnBootIntentService.java @@ -5,8 +5,11 @@ import android.content.Intent; import android.os.Build; import android.support.v4.app.NotificationCompat; +import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Const; +import com.topjohnwu.magisk.utils.Shell; +import com.topjohnwu.magisk.utils.Utils; public class OnBootIntentService extends IntentService { @@ -29,6 +32,17 @@ public class OnBootIntentService extends IntentService { @Override protected void onHandleIntent(Intent intent) { - // Currently nothing to do + /* Pixel 2 (XL) devices will need to patch dtbo.img. + * However, that is not possible if Magisk is installed by + * patching boot image with Magisk Manager and fastboot flash + * the boot image, since at that time we do not have root. + * Check for dtbo status every boot time, and prompt user + * to reboot if dtbo wasn't patched and patched by Magisk Manager. + * */ + MagiskManager mm = Utils.getMagiskManager(this); + mm.loadMagiskInfo(); + if (Shell.rootAccess()) { + Utils.patchDTBO(); + } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Const.java b/app/src/main/java/com/topjohnwu/magisk/utils/Const.java index df4c11481..1e4c8ea49 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Const.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Const.java @@ -59,13 +59,14 @@ public class Const { public static final int MAGISK_UPDATE_NOTIFICATION_ID = 4; public static final int APK_UPDATE_NOTIFICATION_ID = 5; public static final int ONBOOT_NOTIFICATION_ID = 6; - public static final String NOTIFICATION_CHANNEL = "magisk_update_notice"; + public static final int DTBO_NOTIFICATION_ID = 7; + public static final String NOTIFICATION_CHANNEL = "magisk_notification"; } public static class Url { public static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json"; - public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json"; - public static final String SNET_URL = "https://www.dropbox.com/s/jg2yhcrn3l9fckc/snet.apk?dl=1"; + public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json"; + public static final String SNET_URL = "https://www.dropbox.com/s/vbq6y8pzfn4rq60/snet.apk?dl=1"; public static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&page=%d"; public static final String FILE_URL = "https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s"; public static final String ZIP_URL = "https://github.com/Magisk-Modules-Repo/%s/archive/master.zip"; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java index d51a546bb..0462b679d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java @@ -78,6 +78,22 @@ public class Shell { } } } + if (rootAccess()) { + // Load utility shell scripts + try (InputStream in = mm.getAssets().open(Const.UTIL_FUNCTIONS)) { + mm.shell.loadInputStream(in); + } catch (IOException e) { + e.printStackTrace(); + } + + // Root shell initialization + mm.shell.run_raw(false, + "export PATH=" + Const.BUSYBOXPATH + ":$PATH", + "mount_partitions", + "find_boot_image", + "migrate_boot_backup" + ); + } } return mm.shell; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java b/app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java index ae1bb152e..d58ff5824 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java @@ -13,7 +13,6 @@ import android.support.v7.app.AlertDialog; import android.widget.Toast; import com.topjohnwu.magisk.FlashActivity; -import com.topjohnwu.magisk.MagiskFragment; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.SplashActivity; @@ -21,6 +20,7 @@ import com.topjohnwu.magisk.asyncs.RestoreStockBoot; import com.topjohnwu.magisk.components.AlertDialogBuilder; import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.receivers.ManagerUpdate; +import com.topjohnwu.magisk.receivers.RebootReceiver; import java.io.File; import java.io.FileOutputStream; @@ -31,14 +31,9 @@ import java.util.List; public class ShowUI { - public static void showMagiskUpdateNotification() { + public static void magiskUpdateNotification() { MagiskManager mm = MagiskManager.get(); - NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL); - builder.setSmallIcon(R.drawable.ic_magisk) - .setContentTitle(mm.getString(R.string.magisk_update_title)) - .setContentText(mm.getString(R.string.magisk_update_available, mm.remoteMagiskVersionString)) - .setVibrate(new long[]{0, 100, 100, 100}) - .setAutoCancel(true); + Intent intent = new Intent(mm, SplashActivity.class); intent.putExtra(Const.Key.OPEN_SECTION, "magisk"); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mm); @@ -46,35 +41,65 @@ public class ShowUI { stackBuilder.addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(Const.ID.MAGISK_UPDATE_NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); - builder.setContentIntent(pendingIntent); + + NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL); + builder.setSmallIcon(R.drawable.ic_magisk) + .setContentTitle(mm.getString(R.string.magisk_update_title)) + .setContentText(mm.getString(R.string.magisk_update_available, mm.remoteMagiskVersionString)) + .setVibrate(new long[]{0, 100, 100, 100}) + .setAutoCancel(true) + .setContentIntent(pendingIntent); + NotificationManager notificationManager = (NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Const.ID.MAGISK_UPDATE_NOTIFICATION_ID, builder.build()); } - public static void showManagerUpdateNotification() { + public static void managerUpdateNotification() { MagiskManager mm = MagiskManager.get(); - NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL); - builder.setSmallIcon(R.drawable.ic_magisk) - .setContentTitle(mm.getString(R.string.manager_update_title)) - .setContentText(mm.getString(R.string.manager_download_install)) - .setVibrate(new long[]{0, 100, 100, 100}) - .setAutoCancel(true); + Intent intent = new Intent(mm, ManagerUpdate.class); intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink); intent.putExtra(Const.Key.INTENT_SET_VERSION, mm.remoteManagerVersionString); PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, Const.ID.APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); - builder.setContentIntent(pendingIntent); + + NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL); + builder.setSmallIcon(R.drawable.ic_magisk) + .setContentTitle(mm.getString(R.string.manager_update_title)) + .setContentText(mm.getString(R.string.manager_download_install)) + .setVibrate(new long[]{0, 100, 100, 100}) + .setAutoCancel(true) + .setContentIntent(pendingIntent); + NotificationManager notificationManager = (NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Const.ID.APK_UPDATE_NOTIFICATION_ID, builder.build()); } - public static void showMagiskInstallDialog(MagiskFragment fragment, boolean enc, boolean verity) { - MagiskManager mm = Utils.getMagiskManager(fragment.getContext()); + public static void dtboPatchedNotification() { + MagiskManager mm = MagiskManager.get(); + + Intent intent = new Intent(mm, RebootReceiver.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, + Const.ID.DTBO_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); + + NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL); + builder.setSmallIcon(R.drawable.ic_magisk) + .setContentTitle(mm.getString(R.string.dtbo_patched_title)) + .setContentText(mm.getString(R.string.dtbo_patched_reboot)) + .setVibrate(new long[]{0, 100, 100, 100}) + .addAction(R.drawable.ic_refresh, mm.getString(R.string.reboot), pendingIntent); + + NotificationManager notificationManager = + (NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.notify(Const.ID.DTBO_NOTIFICATION_ID, builder.build()); + } + + public static void magiskInstallDialog(Activity activity, boolean enc, boolean verity) { + MagiskManager mm = Utils.getMagiskManager(activity); String filename = Utils.getLegalFilename("Magisk-v" + mm.remoteMagiskVersionString + ".zip"); - new AlertDialogBuilder(fragment.getActivity()) + new AlertDialogBuilder(activity) .setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.magisk))) .setMessage(mm.getString(R.string.repo_install_msg, filename)) .setCancelable(true) @@ -90,7 +115,7 @@ public class ShowUI { options.add(mm.getString(R.string.install_second_slot)); } char[] slot = Utils.isValidShellResponse(res) ? res.get(0).toCharArray() : null; - new AlertDialog.Builder(fragment.getActivity()) + new AlertDialog.Builder(activity) .setTitle(R.string.select_method) .setItems( options.toArray(new String [0]), @@ -106,12 +131,13 @@ public class ShowUI { MagiskManager.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG); Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); - fragment.startActivityForResult(intent, Const.ID.SELECT_BOOT, + ((com.topjohnwu.magisk.components.Activity) activity) + .startActivityForResult(intent, Const.ID.SELECT_BOOT, (requestCode, resultCode, data) -> { if (requestCode == Const.ID.SELECT_BOOT && resultCode == Activity.RESULT_OK && data != null) { Utils.dlAndReceive( - fragment.getActivity(), + activity, new DownloadReceiver() { @Override public void onDownloadDone(Uri uri) { @@ -135,12 +161,12 @@ public class ShowUI { receiver = new DownloadReceiver() { @Override public void onDownloadDone(Uri uri) { - Utils.showUriSnack(fragment.getActivity(), uri); + Utils.showUriSnack(activity, uri); } }; break; case 2: - boot = fragment.getSelectedBootImage(); + boot = mm.bootBlock; if (boot == null) return; receiver = new DownloadReceiver() { @@ -148,12 +174,11 @@ public class ShowUI { public void onDownloadDone(Uri uri) { Intent intent = new Intent(mm, FlashActivity.class); intent.setData(uri) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra(Const.Key.FLASH_SET_BOOT, boot) .putExtra(Const.Key.FLASH_SET_ENC, enc) .putExtra(Const.Key.FLASH_SET_VERITY, verity) .putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK); - mm.startActivity(intent); + activity.startActivity(intent); } }; break; @@ -164,7 +189,6 @@ public class ShowUI { else slot[1] = 'a'; // Then find the boot image again List ret = Shell.su( - "BOOTIMAGE=", "SLOT=" + String.valueOf(slot), "find_boot_image", "echo \"$BOOTIMAGE\"" @@ -178,18 +202,17 @@ public class ShowUI { public void onDownloadDone(Uri uri) { Intent intent = new Intent(mm, FlashActivity.class); intent.setData(uri) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra(Const.Key.FLASH_SET_BOOT, boot) .putExtra(Const.Key.FLASH_SET_ENC, enc) .putExtra(Const.Key.FLASH_SET_VERITY, verity) .putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK); - mm.startActivity(intent); + activity.startActivity(intent); } }; default: } Utils.dlAndReceive( - fragment.getActivity(), + activity, receiver, mm.magiskLink, filename @@ -208,7 +231,7 @@ public class ShowUI { .show(); } - public static void showManagerInstallDialog(Activity activity) { + public static void managerInstallDialog(Activity activity) { MagiskManager mm = Utils.getMagiskManager(activity); new AlertDialogBuilder(activity) .setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.app_name))) @@ -228,9 +251,9 @@ public class ShowUI { .show(); } - public static void showUninstallDialog(MagiskFragment fragment) { - MagiskManager mm = Utils.getMagiskManager(fragment.getActivity()); - new AlertDialogBuilder(fragment.getActivity()) + public static void uninstallDialog(Activity activity) { + MagiskManager mm = Utils.getMagiskManager(activity); + new AlertDialogBuilder(activity) .setTitle(R.string.uninstall_magisk_title) .setMessage(R.string.uninstall_magisk_msg) .setPositiveButton(R.string.complete_uninstall, (d, i) -> { @@ -267,9 +290,7 @@ public class ShowUI { } }) .setNeutralButton(R.string.restore_stock_boot, (d, i) -> { - String boot = fragment.getSelectedBootImage(); - if (boot == null) return; - new RestoreStockBoot(boot).exec(); + new RestoreStockBoot().exec(); }) .setNegativeButton(R.string.no_thanks, null) .show(); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index ad2cb4012..7ec13f4a0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -234,4 +234,13 @@ public class Utils { } out.flush(); } + + public static void patchDTBO() { + if (MagiskManager.get().magiskVersionCode >= 1446) { + List ret = Shell.su("patch_dtbo_image && echo true || echo false"); + if (Utils.isValidShellResponse(ret) && Boolean.parseBoolean(ret.get(ret.size() - 1))) { + ShowUI.dtboPatchedNotification(); + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_magisk.xml b/app/src/main/res/layout/fragment_magisk.xml index 0f54cff8f..aaab88fe7 100644 --- a/app/src/main/res/layout/fragment_magisk.xml +++ b/app/src/main/res/layout/fragment_magisk.xml @@ -224,61 +224,6 @@ - - - - - - - - - - -