Final fix for flash zip

This commit is contained in:
topjohnwu
2016-09-28 00:33:01 +08:00
parent e73497e4b7
commit a173179b03
16 changed files with 75 additions and 60 deletions
@@ -3,10 +3,12 @@ package com.topjohnwu.magisk.utils;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.provider.OpenableColumns;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.Toast;
@@ -124,17 +126,17 @@ public class Async {
@Override
protected Void doInBackground(Void... voids) {
ModulesFragment.listModules.clear();
Logger.dh("Loading modules");
Logger.dev("Loading modules");
List<String> magisk = Utils.getModList(Utils.MAGISK_PATH);
List<String> magiskCache = Utils.getModList(Utils.MAGISK_CACHE_PATH);
for (String mod : magisk) {
Logger.dh("Adding modules from " + mod);
Logger.dev("Adding modules from " + mod);
ModulesFragment.listModules.add(new Module(mod));
}
for (String mod : magiskCache) {
Logger.dh("Adding cache modules from " + mod);
Logger.dev("Adding cache modules from " + mod);
Module cacheMod = new Module(mod);
// Prevent people forgot to change module.prop
cacheMod.setCache();
@@ -143,7 +145,7 @@ public class Async {
Collections.sort(ModulesFragment.listModules, new Utils.ModuleComparator());
Logger.dh("Module load done");
Logger.dev("Module load done");
return null;
}
@@ -199,7 +201,11 @@ public class Async {
public FlashZIP(Context context, Uri uri) {
mContext = context;
mUri = uri;
mName = uri.getLastPathSegment();
Cursor c = mContext.getContentResolver().query(uri, null, null, null, null);
int nameIndex = c.getColumnIndex(OpenableColumns.DISPLAY_NAME);
c.moveToFirst();
mName = c.getString(nameIndex);
c.close();
copyToSD = false;
}
@@ -217,7 +223,7 @@ public class Async {
}
outputStream.close();
Logger.dh("FlashZip: File created successfully - " + f.getPath());
Logger.dev("FlashZip: File created successfully - " + f.getPath());
}
@Override
@@ -228,7 +234,7 @@ public class Async {
@Override
protected Boolean doInBackground(Void... voids) {
Logger.dh("FlashZip Running... " + mName);
Logger.dev("FlashZip Running... " + mName);
InputStream in;
try {
try {
@@ -248,13 +254,18 @@ public class Async {
e.printStackTrace();
return false;
}
Logger.dev(mName + "; " + mFile.getPath());
// return false;
if (Shell.rootAccess()) {
ret = Shell.su(
"unzip -o " + mFile.getPath() + " META-INF/com/google/android/* -d " + mFile.getParent(),
"BOOTMODE=true sh " + mFile.getParent() + "/META-INF/com/google/android/update-binary dummy 1 "+ mFile.getPath(),
"if [ $? -eq 0 ]; then echo true; else echo false; fi"
);
Logger.dh("FlashZip: Console log:\n" + ret);
Logger.dev("FlashZip: Console log:");
for (String line : ret) {
Logger.dev(line);
}
}
// Copy the file to sdcard
if (copyToSD) {
@@ -272,7 +283,7 @@ public class Async {
}
}
mFile.delete();
return ret == null || !Boolean.parseBoolean(ret.get(ret.size() - 1));
return ret != null && Boolean.parseBoolean(ret.get(ret.size() - 1));
}
@Override
@@ -285,9 +296,9 @@ public class Async {
} else {
Toast.makeText(mContext, mContext.getString(R.string.manual_install, mFile.getAbsolutePath()), Toast.LENGTH_LONG).show();
}
return;
} else {
done();
}
done();
}
protected void done() {
@@ -7,9 +7,9 @@ import android.util.Log;
public class Logger {
private static final String LOG_TAG = "Magisk: DH";
private static final String LOG_TAG = "Magisk: DEV";
public static void dh(String msg, Object... args) {
public static void dev(String msg, Object... args) {
Context context = null;
try {
context = getApplicationUsingReflection();
@@ -25,6 +25,18 @@ public class Logger {
}
}
public static void dev(String msg) {
Context context = null;
try {
context = getApplicationUsingReflection();
} catch (Exception e) {
e.printStackTrace();
}
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("developer_logging", false)) {
Log.d(LOG_TAG, msg);
}
}
private static Application getApplicationUsingReflection() throws Exception {
return (Application) Class.forName("android.app.AppGlobals")
.getMethod("getInitialApplication").invoke(null, (Object[]) null);
@@ -92,7 +92,7 @@ public class Utils {
public static boolean autoToggleEnabled(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
Logger.dh("Utils: AutoRootEnableCheck is " + preferences.getBoolean("autoRootEnable", false));
Logger.dev("Utils: AutoRootEnableCheck is " + preferences.getBoolean("autoRootEnable", false));
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("autoRootEnable", false);
}
@@ -137,7 +137,7 @@ public class Utils {
}
public static void toggleAutoRoot(Boolean b, Context context) {
Logger.dh("Utils: toggleAutocalled for " + b );
Logger.dev("Utils: toggleAutocalled for " + b );
if (Utils.magiskVersion != -1) {
if (!Utils.hasServicePermission(context)) {
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
@@ -145,7 +145,7 @@ public class Utils {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else {
Logger.dh("Utils: toggleAuto checks passed, setting" + b );
Logger.dev("Utils: toggleAuto checks passed, setting" + b );
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("autoRootEnable", b).apply();
Intent myServiceIntent = new Intent(context, MonitorService.class);
myServiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -236,21 +236,21 @@ public class Utils {
}
public static void SetupQuickSettingsTile(Context mContext) {
Logger.dh("Utils: SetupQuickSettings called");
Logger.dev("Utils: SetupQuickSettings called");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Logger.dh("Utils: Starting N quick settings service");
Logger.dev("Utils: Starting N quick settings service");
Intent serviceIntent = new Intent(mContext, TileServiceNewApi.class);
mContext.startService(serviceIntent);
}
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
Logger.dh("Utils: Marshmallow build detected");
Logger.dev("Utils: Marshmallow build detected");
String mLabelString;
int mRootIcon = R.drawable.root_white;
int mAutoRootIcon = R.drawable.ic_autoroot_white;
int mRootDisabled = R.drawable.root_grey;
int mRootsState = CheckRootsState(mContext);
Logger.dh("Utils: Root State returned as " + mRootsState);
Logger.dev("Utils: Root State returned as " + mRootsState);
final Intent enableBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_ENABLEROOT);
final Intent disableBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_DISABLEROOT);
final Intent autoBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_AUTOROOT);
@@ -304,7 +304,7 @@ public class Utils {
List<String> lines = Shell.su("settings get secure sysui_qs_tiles");
if (lines != null && lines.size() == 1) {
List<String> tiles = new LinkedList<>(Arrays.asList(lines.get(0).split(",")));
Logger.dh("Utils: Current Tile String is " + tiles);
Logger.dev("Utils: Current Tile String is " + tiles);
if (tiles.size() > 1) {
for (String tile : tiles) {
if (tile.equals(qsTileId)) {
@@ -315,7 +315,7 @@ public class Utils {
tiles.add(Math.round(tiles.size() / 2), qsTileId);
String newTiles = TextUtils.join(",", tiles);
Logger.dh("Utils: NewtilesString is " + newTiles);
Logger.dev("Utils: NewtilesString is " + newTiles);
Shell.su("settings put secure sysui_qs_tiles \"" + newTiles + "\"");
Toast.makeText(context, "Tile installed", Toast.LENGTH_SHORT).show();
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
@@ -1,7 +1,5 @@
package com.topjohnwu.magisk.utils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
@@ -52,7 +50,7 @@ public class WebRequest {
*/
public static String makeWebServiceCall(String urladdress, int requestmethod,
HashMap<String, String> params, boolean addNewLines) {
Logger.dh("WebRequest: Service call " + urladdress);
Logger.dev("WebRequest: Service call " + urladdress);
URL url;
String response = "";
try {