diff --git a/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java b/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java index 179d9b1ce..909b1ba6c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java @@ -3,16 +3,21 @@ package com.topjohnwu.magisk; import android.app.Fragment; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v7.widget.CardView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.CheckBox; import android.widget.Spinner; import android.widget.TextView; +import com.topjohnwu.magisk.receivers.MagiskDlReceiver; import com.topjohnwu.magisk.utils.CallbackHandler; +import com.topjohnwu.magisk.utils.Utils; +import java.util.ArrayList; import java.util.List; import butterknife.BindView; @@ -28,6 +33,9 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi @BindView(R.id.install_title) TextView installTitle; @BindView(R.id.block_spinner) Spinner spinner; @BindView(R.id.detect_bootimage) Button detectButton; + @BindView(R.id.flash_button) CardView flashButton; + @BindView(R.id.keep_force_enc) CheckBox keepEncChkbox; + @BindView(R.id.keep_verity) CheckBox keepVerityChkbox; @Nullable @Override @@ -36,6 +44,17 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi ButterKnife.bind(this, v); detectButton.setOnClickListener(v1 -> toAutoDetect()); installTitle.setText(getString(R.string.install_magisk_title, StatusFragment.remoteMagiskVersion)); + flashButton.setOnClickListener(v1 -> { + String bootImage = bootBlock; + if (bootImage == null) { + bootImage = blockList.get(spinner.getSelectedItemPosition() - 1); + } + Utils.dlAndReceive( + getActivity(), + new MagiskDlReceiver(bootImage, keepEncChkbox.isChecked(), keepVerityChkbox.isChecked()), + StatusFragment.magiskLink, + "Magisk-v" + String.valueOf(StatusFragment.remoteMagiskVersion) + ".zip"); + }); if (blockDetectionDone.isTriggered) { updateUI(); } @@ -48,9 +67,10 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi } private void updateUI() { - blockList.add(0, getString(R.string.auto_detect, bootBlock)); + List items = new ArrayList<>(blockList); + items.add(0, getString(R.string.auto_detect, bootBlock)); ArrayAdapter adapter = new ArrayAdapter<>(getActivity(), - android.R.layout.simple_spinner_item, blockList); + android.R.layout.simple_spinner_item, items); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); toAutoDetect(); @@ -75,36 +95,3 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi CallbackHandler.unRegister(blockDetectionDone, this); } } - -// private AlertDialog.OnClickListener flashMagisk = (dialogInterface, i) -> Utils.dlAndReceive( -// getActivity(), -// new DownloadReceiver() { -// @Override -// public void task(Uri uri) { -// new Async.FlashZIP(mContext, uri, mFilename) { -// @Override -// protected boolean unzipAndCheck() { -// publishProgress(mContext.getString(R.string.zip_install_unzip_zip_msg)); -// if (Shell.rootAccess()) { -// // We might not have busybox yet, unzip with Java -// // We will have complete busybox after Magisk installation -// ZipUtils.unzip(mCachedFile, new File(mCachedFile.getParent(), "magisk")); -// Shell.su( -// "mkdir -p " + Async.TMP_FOLDER_PATH + "/magisk", -// "cp -af " + mCachedFile.getParent() + "/magisk/. " + Async.TMP_FOLDER_PATH + "/magisk" -// ); -// } -// super.unzipAndCheck(); -// return true; -// } -// -// @Override -// protected void done() { -// Shell.su("setprop magisk.version " + String.valueOf(StatusFragment.remoteMagiskVersion)); -// super.done(); -// } -// }.exec(); -// } -// }, -// StatusFragment.magiskLink, -// "Magisk-v" + String.valueOf(StatusFragment.remoteMagiskVersion) + ".zip"); diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java index 3c2cf976f..c8f06a5ae 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java @@ -32,7 +32,7 @@ public abstract class DownloadReceiver extends BroadcastReceiver { switch (status) { case DownloadManager.STATUS_SUCCESSFUL: Uri uri = Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))); - task(uri); + onDownloadDone(uri); break; default: Toast.makeText(context, R.string.download_file_error, Toast.LENGTH_LONG).show(); @@ -52,5 +52,5 @@ public abstract class DownloadReceiver extends BroadcastReceiver { mFilename = filename; } - public abstract void task(Uri uri); + public abstract void onDownloadDone(Uri uri); } diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/MagiskDlReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/MagiskDlReceiver.java new file mode 100644 index 000000000..41313c7c5 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/MagiskDlReceiver.java @@ -0,0 +1,67 @@ +package com.topjohnwu.magisk.receivers; + +import android.net.Uri; + +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.StatusFragment; +import com.topjohnwu.magisk.utils.Async; +import com.topjohnwu.magisk.utils.Shell; +import com.topjohnwu.magisk.utils.ZipUtils; + +import java.io.File; + +public class MagiskDlReceiver extends DownloadReceiver { + + String mBoot; + boolean mEnc, mVerity; + + public MagiskDlReceiver(String bootImage, boolean keepEnc, boolean keepVerity) { + mBoot = bootImage; + mEnc = keepEnc; + mVerity = keepVerity; + } + + @Override + public void onDownloadDone(Uri uri) { + new Async.FlashZIP(mContext, uri, mFilename) { + + @Override + protected void preProcessing() throws Throwable { + Shell.su( + "echo \"BOOTIMAGE=/dev/block/" + mBoot + "\" > /dev/.magisk", + "echo \"KEEPFORCEENCRYPT=" + String.valueOf(mEnc) + "\" >> /dev/.magisk", + "echo \"KEEPVERITY=" + String.valueOf(mVerity) + "\" >> /dev/.magisk" + ); + } + + @Override + protected boolean unzipAndCheck() { + publishProgress(mContext.getString(R.string.zip_install_unzip_zip_msg)); + if (Shell.rootAccess()) { + // We might not have busybox yet, unzip with Java + // We will have complete busybox after Magisk installation + ZipUtils.unzip(mCachedFile, new File(mCachedFile.getParent(), "magisk")); + Shell.su( + "mkdir -p " + Async.TMP_FOLDER_PATH + "/magisk", + "cp -af " + mCachedFile.getParent() + "/magisk/. " + Async.TMP_FOLDER_PATH + "/magisk", + "mv -f " + mCachedFile.getParent() + "/magisk/META-INF " + mCachedFile.getParent() + "/META-INF" + ); + } + return true; + } + + @Override + protected void onSuccess() { + new Async.RootTask() { + @Override + protected Void doInBackground(Void... params) { + Shell.su("setprop magisk.version " + + String.valueOf(StatusFragment.remoteMagiskVersion)); + return null; + } + }.exec(); + super.onSuccess(); + } + }.exec(); + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/RepoDlReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/RepoDlReceiver.java index 70f132ceb..b52903f07 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/RepoDlReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/RepoDlReceiver.java @@ -11,7 +11,7 @@ import java.io.OutputStream; public class RepoDlReceiver extends DownloadReceiver { @Override - public void task(Uri uri) { + public void onDownloadDone(Uri uri) { // Flash the zip new Async.FlashZIP(mContext, uri, mFilename){ @Override diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index 402409339..7c26fa4c7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -62,7 +62,6 @@ public class Async { StatusFragment.remoteMagiskVersion = magisk.getDouble("versionCode"); StatusFragment.magiskLink = magisk.getString("link"); StatusFragment.magiskChangelog = magisk.getString("changelog"); - } catch (JSONException ignored) {} return null; } @@ -153,7 +152,8 @@ public class Async { protected void preProcessing() throws Throwable {} - private void copyToCache() throws Throwable { + protected void copyToCache() throws Throwable { + publishProgress(mContext.getString(R.string.copying_msg)); try { InputStream in = mContext.getContentResolver().openInputStream(mUri); mCachedFile = new File(mContext.getCacheDir().getAbsolutePath() + "/install.zip"); @@ -229,7 +229,7 @@ public class Async { } return -1; } - if (ret != null && Boolean.parseBoolean(ret.get(ret.size() - 1))) { + if (Boolean.parseBoolean(ret.get(ret.size() - 1))) { return 1; } return -1; @@ -299,9 +299,11 @@ public class Async { public static class GetBootBlocks extends RootTask { @Override protected Void doInBackground(Void... params) { - InstallFragment.blockList = Shell.su("ls /dev/block | grep mmc"); - if (InstallFragment.bootBlock == null) { - InstallFragment.bootBlock = Utils.detectBootImage(); + if (Shell.rootAccess()) { + InstallFragment.blockList = Shell.su("ls /dev/block | grep mmc"); + if (InstallFragment.bootBlock == null) { + InstallFragment.bootBlock = Utils.detectBootImage(); + } } return null; } diff --git a/app/src/main/res/layout/install_fragment.xml b/app/src/main/res/layout/install_fragment.xml index 7e98e10f3..2f3668003 100644 --- a/app/src/main/res/layout/install_fragment.xml +++ b/app/src/main/res/layout/install_fragment.xml @@ -133,7 +133,6 @@ android:layout_marginEnd="25dp" android:layout_marginStart="25dp" /> - @@ -151,7 +150,6 @@ android:foreground="?android:attr/selectableItemBackground" android:clickable="true"> - - SafetyNet Passed Functionality greatly limited - + + "(Auto) %1$s" + Boot Image Location + Detect + Advanced Settings + Keep force encryption + Keep dm-verity + Install Magisk Version: v%1$.1f + Magiskify (No info provided) @@ -86,6 +94,7 @@ Installation succeeded! Do you want to reboot now? Reboot + Copying zip to temp directory Installing Unzipping zip file … Processing zip file … @@ -118,12 +127,4 @@ Reboot to apply settings - "(Auto) %1$s" - Boot Image Location - Detect - Advanced Settings - Keep force encryption - Keep dm-verity - Install Magisk Version: v%1$.1f -