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.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -12,7 +11,6 @@ import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -78,19 +76,7 @@ public class MagiskFragment extends Fragment {
View v = inflater.inflate(R.layout.magisk_fragment, container, false); View v = inflater.inflate(R.layout.magisk_fragment, container, false);
ButterKnife.bind(this, v); ButterKnife.bind(this, v);
if (magiskVersion == -1) { updateMagiskVersion();
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);
}
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
@ -120,6 +106,7 @@ public class MagiskFragment extends Fragment {
if (s.equals("update_check_done")) { if (s.equals("update_check_done")) {
if (pref.getBoolean(s, false)) { if (pref.getBoolean(s, false)) {
Logger.dev("MagiskFragment: UI refresh triggered"); Logger.dev("MagiskFragment: UI refresh triggered");
updateMagiskVersion();
updateUI(); updateUI();
} }
} }
@ -140,15 +127,7 @@ public class MagiskFragment extends Fragment {
prefs.unregisterOnSharedPreferenceChangeListener(listener); prefs.unregisterOnSharedPreferenceChangeListener(listener);
} }
private void updateMagiskVersion() {
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());
}
List<String> ret = Shell.sh("getprop magisk.version"); List<String> ret = Shell.sh("getprop magisk.version");
if (ret.get(0).isEmpty()) { if (ret.get(0).isEmpty()) {
magiskVersion = -1; magiskVersion = -1;
@ -156,6 +135,30 @@ public class MagiskFragment extends Fragment {
magiskVersion = Integer.parseInt(ret.get(0)); 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) { if (remoteMagiskVersion == -1) {
appCheckUpdatesContainer.setBackgroundColor(colorWarn); appCheckUpdatesContainer.setBackgroundColor(colorWarn);
magiskCheckUpdatesContainer.setBackgroundColor(colorWarn); magiskCheckUpdatesContainer.setBackgroundColor(colorWarn);

View File

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

View File

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

View File

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