Functionality done

This commit is contained in:
topjohnwu 2016-12-27 04:38:16 +08:00
parent 13ec1aafa0
commit 5e7c3ed46a
7 changed files with 111 additions and 58 deletions

View File

@ -3,16 +3,21 @@ package com.topjohnwu.magisk;
import android.app.Fragment; import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import com.topjohnwu.magisk.receivers.MagiskDlReceiver;
import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.Utils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import butterknife.BindView; 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.install_title) TextView installTitle;
@BindView(R.id.block_spinner) Spinner spinner; @BindView(R.id.block_spinner) Spinner spinner;
@BindView(R.id.detect_bootimage) Button detectButton; @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 @Nullable
@Override @Override
@ -36,6 +44,17 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi
ButterKnife.bind(this, v); ButterKnife.bind(this, v);
detectButton.setOnClickListener(v1 -> toAutoDetect()); detectButton.setOnClickListener(v1 -> toAutoDetect());
installTitle.setText(getString(R.string.install_magisk_title, StatusFragment.remoteMagiskVersion)); 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) { if (blockDetectionDone.isTriggered) {
updateUI(); updateUI();
} }
@ -48,9 +67,10 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi
} }
private void updateUI() { private void updateUI() {
blockList.add(0, getString(R.string.auto_detect, bootBlock)); List<String> items = new ArrayList<>(blockList);
items.add(0, getString(R.string.auto_detect, bootBlock));
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), ArrayAdapter<String> 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); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter); spinner.setAdapter(adapter);
toAutoDetect(); toAutoDetect();
@ -75,36 +95,3 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi
CallbackHandler.unRegister(blockDetectionDone, this); 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");

View File

@ -32,7 +32,7 @@ public abstract class DownloadReceiver extends BroadcastReceiver {
switch (status) { switch (status) {
case DownloadManager.STATUS_SUCCESSFUL: case DownloadManager.STATUS_SUCCESSFUL:
Uri uri = Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))); Uri uri = Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)));
task(uri); onDownloadDone(uri);
break; break;
default: default:
Toast.makeText(context, R.string.download_file_error, Toast.LENGTH_LONG).show(); Toast.makeText(context, R.string.download_file_error, Toast.LENGTH_LONG).show();
@ -52,5 +52,5 @@ public abstract class DownloadReceiver extends BroadcastReceiver {
mFilename = filename; mFilename = filename;
} }
public abstract void task(Uri uri); public abstract void onDownloadDone(Uri uri);
} }

View File

@ -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<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Shell.su("setprop magisk.version "
+ String.valueOf(StatusFragment.remoteMagiskVersion));
return null;
}
}.exec();
super.onSuccess();
}
}.exec();
}
}

View File

@ -11,7 +11,7 @@ import java.io.OutputStream;
public class RepoDlReceiver extends DownloadReceiver { public class RepoDlReceiver extends DownloadReceiver {
@Override @Override
public void task(Uri uri) { public void onDownloadDone(Uri uri) {
// Flash the zip // Flash the zip
new Async.FlashZIP(mContext, uri, mFilename){ new Async.FlashZIP(mContext, uri, mFilename){
@Override @Override

View File

@ -62,7 +62,6 @@ public class Async {
StatusFragment.remoteMagiskVersion = magisk.getDouble("versionCode"); StatusFragment.remoteMagiskVersion = magisk.getDouble("versionCode");
StatusFragment.magiskLink = magisk.getString("link"); StatusFragment.magiskLink = magisk.getString("link");
StatusFragment.magiskChangelog = magisk.getString("changelog"); StatusFragment.magiskChangelog = magisk.getString("changelog");
} catch (JSONException ignored) {} } catch (JSONException ignored) {}
return null; return null;
} }
@ -153,7 +152,8 @@ public class Async {
protected void preProcessing() throws Throwable {} protected void preProcessing() throws Throwable {}
private void copyToCache() throws Throwable { protected void copyToCache() throws Throwable {
publishProgress(mContext.getString(R.string.copying_msg));
try { try {
InputStream in = mContext.getContentResolver().openInputStream(mUri); InputStream in = mContext.getContentResolver().openInputStream(mUri);
mCachedFile = new File(mContext.getCacheDir().getAbsolutePath() + "/install.zip"); mCachedFile = new File(mContext.getCacheDir().getAbsolutePath() + "/install.zip");
@ -229,7 +229,7 @@ public class Async {
} }
return -1; return -1;
} }
if (ret != null && Boolean.parseBoolean(ret.get(ret.size() - 1))) { if (Boolean.parseBoolean(ret.get(ret.size() - 1))) {
return 1; return 1;
} }
return -1; return -1;
@ -299,10 +299,12 @@ public class Async {
public static class GetBootBlocks extends RootTask<Void, Void, Void> { public static class GetBootBlocks extends RootTask<Void, Void, Void> {
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
if (Shell.rootAccess()) {
InstallFragment.blockList = Shell.su("ls /dev/block | grep mmc"); InstallFragment.blockList = Shell.su("ls /dev/block | grep mmc");
if (InstallFragment.bootBlock == null) { if (InstallFragment.bootBlock == null) {
InstallFragment.bootBlock = Utils.detectBootImage(); InstallFragment.bootBlock = Utils.detectBootImage();
} }
}
return null; return null;
} }

View File

@ -133,7 +133,6 @@
android:layout_marginEnd="25dp" android:layout_marginEnd="25dp"
android:layout_marginStart="25dp" /> android:layout_marginStart="25dp" />
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
@ -151,7 +150,6 @@
android:foreground="?android:attr/selectableItemBackground" android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"> android:clickable="true">
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -161,7 +159,6 @@
android:layout_marginEnd="25dp" android:layout_marginEnd="25dp"
android:layout_marginStart="25dp"> android:layout_marginStart="25dp">
<ImageView <ImageView
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -173,10 +170,9 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="Magiskify" android:text="@string/magiskify"
android:ems="10" android:ems="10"
android:gravity="center" android:gravity="center"
android:id="@+id/editText"
android:layout_weight="1" android:layout_weight="1"
android:textStyle="bold" android:textStyle="bold"
android:textColor="@android:color/black" android:textColor="@android:color/black"

View File

@ -31,7 +31,15 @@
<string name="safetyNet_pass">SafetyNet Passed</string> <string name="safetyNet_pass">SafetyNet Passed</string>
<string name="root_info_warning">Functionality greatly limited</string> <string name="root_info_warning">Functionality greatly limited</string>
<!--Root Fragment--> <!--Install Fragment-->
<string name="auto_detect">"(Auto) %1$s"</string>
<string name="boot_image_title">Boot Image Location</string>
<string name="detect_button">Detect</string>
<string name="advanced_settings_title">Advanced Settings</string>
<string name="keep_force_encryption">Keep force encryption</string>
<string name="keep_dm_verity">Keep dm-verity</string>
<string name="install_magisk_title">Install Magisk Version: v%1$.1f</string>
<string name="magiskify">Magiskify</string>
<!--Module Fragment--> <!--Module Fragment-->
<string name="no_info_provided">(No info provided)</string> <string name="no_info_provided">(No info provided)</string>
@ -86,6 +94,7 @@
<string name="reboot_title">Installation succeeded!</string> <string name="reboot_title">Installation succeeded!</string>
<string name="reboot_msg">Do you want to reboot now?</string> <string name="reboot_msg">Do you want to reboot now?</string>
<string name="reboot">Reboot</string> <string name="reboot">Reboot</string>
<string name="copying_msg">Copying zip to temp directory</string>
<string name="zip_install_progress_title">Installing</string> <string name="zip_install_progress_title">Installing</string>
<string name="zip_install_unzip_zip_msg">Unzipping zip file …</string> <string name="zip_install_unzip_zip_msg">Unzipping zip file …</string>
<string name="zip_install_process_zip_msg">Processing zip file …</string> <string name="zip_install_process_zip_msg">Processing zip file …</string>
@ -118,12 +127,4 @@
<string name="settings_reboot_toast">Reboot to apply settings</string> <string name="settings_reboot_toast">Reboot to apply settings</string>
<string name="auto_detect">"(Auto) %1$s"</string>
<string name="boot_image_title">Boot Image Location</string>
<string name="detect_button">Detect</string>
<string name="advanced_settings_title">Advanced Settings</string>
<string name="keep_force_encryption">Keep force encryption</string>
<string name="keep_dm_verity">Keep dm-verity</string>
<string name="install_magisk_title">Install Magisk Version: v%1$.1f</string>
</resources> </resources>