Fix Magisk Version; remove unnecessary root calls

This commit is contained in:
topjohnwu 2016-10-01 16:59:01 +08:00
parent f2611f64ac
commit 55410f026b
4 changed files with 44 additions and 44 deletions

View File

@ -3,7 +3,6 @@ package com.topjohnwu.magisk;
import android.app.Fragment;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@ -12,7 +11,6 @@ import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -78,19 +76,7 @@ public class MagiskFragment extends Fragment {
View v = inflater.inflate(R.layout.magisk_fragment, container, false);
ButterKnife.bind(this, v);
if (magiskVersion == -1) {
magiskStatusContainer.setBackgroundColor(colorNeutral);
magiskStatusIcon.setImageResource(statusUnknown);
magiskVersionText.setTextColor(colorNeutral);
magiskVersionText.setText(R.string.magisk_version_error);
} else {
magiskStatusContainer.setBackgroundColor(colorOK);
magiskStatusIcon.setImageResource(statusOK);
magiskVersionText.setText(getString(R.string.magisk_version, String.valueOf(magiskVersion)));
magiskVersionText.setTextColor(colorOK);
}
updateMagiskVersion();
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
@ -120,6 +106,7 @@ public class MagiskFragment extends Fragment {
if (s.equals("update_check_done")) {
if (pref.getBoolean(s, false)) {
Logger.dev("MagiskFragment: UI refresh triggered");
updateMagiskVersion();
updateUI();
}
}
@ -140,15 +127,7 @@ public class MagiskFragment extends Fragment {
prefs.unregisterOnSharedPreferenceChangeListener(listener);
}
private void updateUI() {
String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("theme", "");
if (theme.equals("Dark")) {
builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(getActivity());
}
private void updateMagiskVersion() {
List<String> ret = Shell.sh("getprop magisk.version");
if (ret.get(0).isEmpty()) {
magiskVersion = -1;
@ -156,6 +135,30 @@ public class MagiskFragment extends Fragment {
magiskVersion = Integer.parseInt(ret.get(0));
}
if (magiskVersion == -1) {
magiskStatusContainer.setBackgroundColor(colorNeutral);
magiskStatusIcon.setImageResource(statusUnknown);
magiskVersionText.setTextColor(colorNeutral);
magiskVersionText.setText(R.string.magisk_version_error);
} else {
magiskStatusContainer.setBackgroundColor(colorOK);
magiskStatusIcon.setImageResource(statusOK);
magiskVersionText.setText(getString(R.string.magisk_version, String.valueOf(magiskVersion)));
magiskVersionText.setTextColor(colorOK);
}
}
private void updateUI() {
String theme = prefs.getString("theme", "");
if (theme.equals("Dark")) {
builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(getActivity());
}
if (remoteMagiskVersion == -1) {
appCheckUpdatesContainer.setBackgroundColor(colorWarn);
magiskCheckUpdatesContainer.setBackgroundColor(colorWarn);

View File

@ -98,7 +98,8 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
protected void preProcessing() throws Throwable {
super.preProcessing();
new File(mUri.getPath()).delete();
Shell.su(
Shell.sh(
"PATH=" + context.getApplicationInfo().dataDir + "/tools:$PATH",
"cd " + mFile.getParent(),
"mkdir git",
"unzip -o install.zip -d git",

View File

@ -1,6 +1,5 @@
package com.topjohnwu.magisk;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;

View File

@ -46,24 +46,20 @@ public class Async {
String toolPath = mInfo.dataDir + "/tools";
String busybox = mInfo.dataDir + "/lib/libbusybox.so";
String zip = mInfo.dataDir + "/lib/libzip.so";
if (Shell.rootAccess()) {
if (!Utils.itemExist(false, toolPath)) {
Shell.su(
"rm -rf " + toolPath,
"mkdir " + toolPath,
"chmod 755 " + toolPath,
"cd " + toolPath,
"ln -s " + busybox + " busybox",
"for tool in $(./busybox --list); do",
"ln -s " + busybox + " $tool",
"done",
"rm -f su sh",
"ln -s " + zip + " zip"
);
}
Shell.su("PATH=" + toolPath + ":$PATH");
if (!Utils.itemExist(false, toolPath)) {
Shell.sh(
"mkdir " + toolPath,
"chmod 755 " + toolPath,
"cd " + toolPath,
"ln -s " + busybox + " busybox",
"for tool in $(./busybox --list); do",
"ln -s " + busybox + " $tool",
"done",
"rm -f su sh",
"ln -s " + zip + " zip"
);
}
Shell.su("PATH=" + toolPath + ":$PATH");
return null;
}
}
@ -254,7 +250,7 @@ public class Async {
if (copyToSD && mFile != null) {
String filename = (mName.contains(".zip") ? mName : mName + ".zip");
filename = filename.replace(" ", "_").replace("'", "").replace("\"", "")
.replace("$", "").replace("`", "").replace("(", "_").replace(")", "_")
.replace("$", "").replace("`", "").replace("(", "").replace(")", "")
.replace("#", "").replace("@", "").replace("*", "");
sdFile = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename);
Logger.dev("FlashZip: Copy zip back to " + sdFile.getPath());
@ -268,6 +264,7 @@ public class Async {
mFile.delete();
} catch (IOException e) {
// Use the badass way :)
e.printStackTrace();
Shell.su("cp -af " + mFile.getPath() + " " + sdFile.getPath());
if (!sdFile.exists()) {
sdFile = null;