use of com.topjohnwu.magisk.receivers.DownloadReceiver in project MagiskManager by topjohnwu.
the class ShowUI method magiskInstallDialog.
public static void magiskInstallDialog(Activity activity) {
MagiskManager mm = Utils.getMagiskManager(activity);
String filename = Utils.fmt("Magisk-v%s(%d).zip", mm.remoteMagiskVersionString, mm.remoteMagiskVersionCode);
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).setPositiveButton(R.string.install, (d, i) -> {
List<String> options = new ArrayList<>();
options.add(mm.getString(R.string.download_zip_only));
options.add(mm.getString(R.string.patch_boot_file));
if (Shell.rootAccess()) {
options.add(mm.getString(R.string.direct_install));
}
String s = Utils.cmd("echo $SLOT");
if (s != null) {
options.add(mm.getString(R.string.install_second_slot));
}
char[] slot = s == null ? null : s.toCharArray();
new AlertDialog.Builder(activity).setTitle(R.string.select_method).setItems(options.toArray(new String[0]), (dialog, idx) -> {
String boot;
DownloadReceiver receiver = null;
switch(idx) {
case 1:
if (mm.remoteMagiskVersionCode < 1400) {
MagiskManager.toast(R.string.no_boot_file_patch_support, Toast.LENGTH_LONG);
return;
}
MagiskManager.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
((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(activity, new DownloadReceiver() {
@Override
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, data.getData()).putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_BOOT);
mm.startActivity(intent);
}
}, mm.magiskLink, filename);
}
});
return;
case 0:
receiver = new DownloadReceiver() {
@Override
public void onDownloadDone(Uri uri) {
Utils.showUriSnack(activity, uri);
}
};
break;
case 2:
boot = mm.bootBlock;
if (boot == null)
return;
receiver = new DownloadReceiver() {
@Override
public void onDownloadDone(Uri uri) {
Intent intent = new Intent(mm, FlashActivity.class);
intent.setData(uri).putExtra(Const.Key.FLASH_SET_BOOT, boot).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
activity.startActivity(intent);
}
};
break;
case 3:
assert (slot != null);
// Choose the other slot
if (slot[1] == 'a')
slot[1] = 'b';
else
slot[1] = 'a';
// Then find the boot image again
boot = Utils.cmd("SLOT=" + String.valueOf(slot) + "; find_boot_image;" + "echo \"$BOOTIMAGE\"");
Shell.Async.su("mount_partitions");
if (boot == null)
return;
receiver = new DownloadReceiver() {
@Override
public void onDownloadDone(Uri uri) {
Intent intent = new Intent(mm, FlashActivity.class);
intent.setData(uri).putExtra(Const.Key.FLASH_SET_BOOT, boot).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
activity.startActivity(intent);
}
};
default:
}
Utils.dlAndReceive(activity, receiver, mm.magiskLink, filename);
}).show();
}).setNeutralButton(R.string.release_notes, (d, i) -> {
if (mm.releaseNoteLink != null) {
Intent openLink = new Intent(Intent.ACTION_VIEW, Uri.parse(mm.releaseNoteLink));
openLink.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mm.startActivity(openLink);
}
}).setNegativeButton(R.string.no_thanks, null).show();
}
Aggregations