Add Install UI

This commit is contained in:
topjohnwu 2016-12-25 17:17:20 +08:00
parent a5a2df4956
commit 8fe4cfecb6
3 changed files with 231 additions and 35 deletions

View File

@ -8,6 +8,10 @@ import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import com.topjohnwu.magisk.receivers.DownloadReceiver;
import com.topjohnwu.magisk.utils.Async;
@ -16,56 +20,104 @@ import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils;
import java.io.File;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
// Currently empty, placing some code that we be used in the future
public class InstallFragment extends Fragment {
private List<String> blockList;
@BindView(R.id.block_spinner) Spinner spinner;
@BindView(R.id.detect_bootimage) Button detectButton;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.install_fragment, container, false);
ButterKnife.bind(this, v);
detectButton.setOnClickListener(v1 -> detectBootImage());
getBlockList();
return v;
}
private void getBlockList() {
new Async.RootTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
blockList = Utils.getBlockList();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, blockList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
detectBootImage();
}
}.exec();
}
private void detectBootImage() {
new Async.RootTask<Void, Void, Void>() {
String boot;
@Override
protected Void doInBackground(Void... params) {
boot = Utils.detectBootImage();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (boot != null) {
int idx = blockList.indexOf(boot);
if (idx != -1) {
spinner.setSelection(idx);
}
}
}
}.exec();
}
@Override
public void onResume() {
super.onResume();
getActivity().setTitle(R.string.install);
}
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");
}
// 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

@ -67,7 +67,7 @@ public class Utils {
return Shell.rootAccess() && Boolean.parseBoolean(Shell.su(command).get(0));
}
static List<String> getModList(String path) {
public static List<String> getModList(String path) {
List<String> ret;
String command = "find " + path + " -type d -maxdepth 1 ! -name \"*.core\" ! -name \"*lost+found\" ! -name \"*magisk\"";
if (Shell.rootAccess()) {
@ -138,6 +138,25 @@ public class Utils {
.replace("#", "").replace("@", "").replace("*", "");
}
public static List<String> getBlockList() {
return Shell.su("ls /dev/block | grep mmc");
}
public static String detectBootImage() {
String[] commands = {
"for PARTITION in kern-a KERN-A android_boot ANDROID_BOOT kernel KERNEL boot BOOT lnx LNX; do",
"BOOTIMAGE=`readlink /dev/block/by-name/$PARTITION || readlink /dev/block/platform/*/by-name/$PARTITION || readlink /dev/block/platform/*/*/by-name/$PARTITION`",
"if [ ! -z \"$BOOTIMAGE\" ]; then break; fi",
"done",
"echo \"${BOOTIMAGE##*/}\""
};
List<String> ret = Shell.su(commands);
if (!ret.isEmpty()) {
return ret.get(0);
}
return null;
}
public static class ByteArrayInOutStream extends ByteArrayOutputStream {
public ByteArrayInputStream getInputStream() {
ByteArrayInputStream in = new ByteArrayInputStream(buf, 0, count);

View File

@ -1,6 +1,131 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/install_info_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
style="?attr/cardStyle"
app:cardUseCompatPadding="true">
<TextView
android:id="@+id/install_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="15dp"
android:textStyle="bold"
android:text="Install Magisk Version: v10" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/bootimage_card"
android:layout_gravity="center"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
style="?attr/cardStyle"
app:cardUseCompatPadding="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="10dp"
android:text="Boot Image Location"
android:textStyle="bold" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/block_spinner"
android:layout_weight="1" />
<Button
android:text="Detect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detect_bootimage"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/install_option_card"
android:layout_gravity="center"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
style="?attr/cardStyle"
app:cardUseCompatPadding="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="10dp"
android:text="Advanced Settings"
android:textStyle="bold" />
<CheckBox
android:text="Keep force encryption"
android:id="@+id/keep_force_enc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginStart="25dp" />
<CheckBox
android:text="Keep dm-verity"
android:id="@+id/keep_verity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginStart="25dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>