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

View File

@ -44,7 +44,7 @@ public class AboutActivity extends AppCompatActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
Logger.dh("AboutActivity: Theme is " + theme);
Logger.dev("AboutActivity: Theme is " + theme);
if (theme.equals("Dark")) {
setTheme(R.style.AppTheme_dh);
}

View File

@ -76,7 +76,7 @@ public class AutoRootFragment extends ListFragment {
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Logger.dh("Click");
Logger.dev("Click");
super.onListItemClick(l, v, position, id);
ApplicationInfo app = applist.get(position);
ToggleApp(app.packageName, position, v);
@ -84,7 +84,7 @@ public class AutoRootFragment extends ListFragment {
}
private void ToggleApp(String appToCheck, int position, View v) {
Logger.dh("Magisk","AutoRootFragment: ToggleApp called for " + appToCheck);
Logger.dev("Magisk","AutoRootFragment: ToggleApp called for " + appToCheck);
Set<String> blackListSet = prefs.getStringSet("auto_blacklist", null);
assert blackListSet != null;
arrayBlackList = new ArrayList<>(blackListSet);
@ -100,7 +100,7 @@ public class AutoRootFragment extends ListFragment {
}
}
Logger.dh("Committing set, value is: " + arrayBlackList.toString());
Logger.dev("Committing set, value is: " + arrayBlackList.toString());
SharedPreferences.Editor editor = prefs.edit();
editor.putStringSet("auto_blacklist", new HashSet<>(arrayBlackList));
editor.apply();

View File

@ -40,7 +40,7 @@ import butterknife.ButterKnife;
public class LogFragment extends Fragment {
private static final String MAGISK_LOG = "/cache/magisk.log";
private static final String MAGISK_LOG = "/cache/magisk.dev";
@BindView(R.id.txtLog) TextView txtLog;
@BindView(R.id.svLog) ScrollView svLog;
@ -154,7 +154,7 @@ public class LogFragment extends Fragment {
Calendar now = Calendar.getInstance();
String filename = String.format(
"magisk_%s_%04d%02d%02d_%02d%02d%02d.log", "error",
"magisk_%s_%04d%02d%02d_%02d%02d%02d.dev", "error",
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));

View File

@ -49,7 +49,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
protected void onCreate(final Bundle savedInstanceState) {
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
Logger.dh("MainActivity: Theme is " + theme);
Logger.dev("MainActivity: Theme is " + theme);
if (theme.equals("Dark")) {
setTheme(R.style.AppTheme_dh);
}
@ -98,7 +98,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
navigationView.setCheckedItem(R.id.downloads);
}
}
hm = getFragmentManager().findFragmentByTag("log");
hm = getFragmentManager().findFragmentByTag("dev");
if (hm != null) {
if (hm.isVisible()) {
navigationView.setCheckedItem(R.id.log);
@ -143,7 +143,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
String toLaunch = "";
toLaunch = getIntent().getExtras().getString("Relaunch");
if (toLaunch.equals("Settings")) {
Logger.dh("MainActivity: Intent has extras " + getIntent().getExtras().getString("Relaunch"));
Logger.dev("MainActivity: Intent has extras " + getIntent().getExtras().getString("Relaunch"));
mSelectedId = R.id.settings;
}
@ -170,7 +170,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
drawer.closeDrawer(GravityCompat.START);
} else {
int backStackEntryCount = getFragmentManager().getBackStackEntryCount();
Logger.dh("Welcomeactivity: Entrycount is " + backStackEntryCount);
Logger.dev("Welcomeactivity: Entrycount is " + backStackEntryCount);
if (backStackEntryCount >= 2) {
super.onBackPressed();
} else {
@ -227,7 +227,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
break;
case R.id.log:
setTitle(R.string.log);
tag = "log";
tag = "dev";
navFragment = new LogFragment();
break;
case R.id.settings:

View File

@ -9,20 +9,17 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import com.ipaulpro.afilechooser.utils.FileUtils;
import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Utils;
import java.util.ArrayList;
import java.util.List;
@ -73,7 +70,7 @@ public class ModulesFragment extends Fragment {
listener = (pref, s) -> {
if (s.equals("module_done")) {
if (pref.getBoolean(s, false)) {
Logger.dh("ModulesFragment: UI refresh triggered");
Logger.dev("ModulesFragment: UI refresh triggered");
updateUI();
}
}

View File

@ -9,7 +9,6 @@ import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -66,7 +65,7 @@ public class ReposFragment extends Fragment {
listener = (pref, s) -> {
if (s.equals("repo_done")) {
if (pref.getBoolean(s, false)) {
Logger.dh("ReposFragment: UI refresh triggered");
Logger.dev("ReposFragment: UI refresh triggered");
updateUI();
}
}
@ -146,7 +145,7 @@ public class ReposFragment extends Fragment {
// };
//
// String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("theme", "");
// Logger.dh("ReposFragment: Theme is " + theme);
// Logger.dev("ReposFragment: Theme is " + theme);
// if (theme.equals("Dark")) {
// builder = new AlertDialog.Builder(getActivity(),R.style.AlertDialog_dh);
// } else {

View File

@ -174,7 +174,7 @@ public class RootFragment extends Fragment {
listener = (prefs1, key) -> {
if ((key.contains("autoRootEnable")) | (key.equals("root"))) {
Logger.dh("RootFragmnet, keychange detected for " + key);
Logger.dev("RootFragmnet, keychange detected for " + key);
new updateUI().execute();
}

View File

@ -100,7 +100,7 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Logger.dh("Settings: NewValue is " + key);
Logger.dev("Settings: NewValue is " + key);
if (key.equals("theme")) {
String pref = sharedPreferences.getString(key, "");
@ -117,7 +117,7 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
intent.putExtra("Relaunch", "Settings");
startActivity(intent);
Logger.dh("SettingsFragment: theme is " + pref);
Logger.dev("SettingsFragment: theme is " + pref);
}

View File

@ -10,10 +10,8 @@ import android.support.v7.app.AppCompatActivity;
import com.topjohnwu.magisk.services.MonitorService;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
@ -34,7 +32,7 @@ public class SplashActivity extends AppCompatActivity {
if (!defaultPrefs.contains("auto_blacklist")) {
Logger.dh("SplashActivity: Setting default preferences for application");
Logger.dev("SplashActivity: Setting default preferences for application");
SharedPreferences.Editor editor = defaultPrefs.edit();
Set<String> set = new HashSet<>();
set.add("com.google.android.apps.walletnfcrel");

View File

@ -25,7 +25,7 @@ public class Module extends BaseModule {
if (mName == null)
mName = mId;
Logger.dh("Creating Module, id: " + mId);
Logger.dev("Creating Module, id: " + mId);
mEnable = !Utils.itemExist(mDisableFile);
mRemove = Utils.itemExist(mRemoveFile);

View File

@ -65,7 +65,7 @@ public class MonitorService extends AccessibilityService {
ActivityInfo activityInfo = tryGetActivity(componentName);
boolean isActivity = activityInfo != null;
if (isActivity) {
Logger.dh("MonitorService: CurrentActivity: " + event.getPackageName());
Logger.dev("MonitorService: CurrentActivity: " + event.getPackageName());
String mPackage = componentName.getPackageName();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
@ -108,11 +108,11 @@ public class MonitorService extends AccessibilityService {
String rootString = rootToggle ? "on" : "off";
if (Utils.rootEnabled() != rootToggle) {
Logger.dh("MonitorService: toggling root " + rootString);
Logger.dev("MonitorService: toggling root " + rootString);
Utils.toggleRoot(rootToggle, getApplicationContext());
if (Utils.rootEnabled() != rootToggle) {
Utils.toggleRoot(rootToggle, getApplicationContext());
Logger.dh("MonitorService: FORCING to " + rootString);
Logger.dev("MonitorService: FORCING to " + rootString);
}
}

View File

@ -19,7 +19,7 @@ public class TileServiceNewApi extends android.service.quicksettings.TileService
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Logger.dh("QST (New): Service start");
Logger.dev("QST (New): Service start");
return super.onStartCommand(intent, flags, startId);
}
@ -27,7 +27,7 @@ public class TileServiceNewApi extends android.service.quicksettings.TileService
@Override
public void onTileAdded() {
super.onTileAdded();
Logger.dh("QST (New): Tile added");
Logger.dev("QST (New): Tile added");
setupState();
this.getQsTile().updateTile();
}
@ -36,7 +36,7 @@ public class TileServiceNewApi extends android.service.quicksettings.TileService
public void onClick() {
mRootsState = Utils.CheckRootsState(getApplicationContext());
switchState(mRootsState);
Logger.dh("QST (New): Tile clicked");
Logger.dev("QST (New): Tile clicked");
}
@ -44,13 +44,13 @@ public class TileServiceNewApi extends android.service.quicksettings.TileService
public void onStartListening() {
super.onStartListening();
setupState();
Logger.dh("QST (New): Tile is listening");
Logger.dev("QST (New): Tile is listening");
}
@Override
public void onStopListening() {
super.onStopListening();
Logger.dh("QST (New): Tile stopped listening");
Logger.dev("QST (New): Tile stopped listening");
}
private void setupState() {
@ -58,11 +58,11 @@ public class TileServiceNewApi extends android.service.quicksettings.TileService
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("autoRootEnable",false).apply();
}
mRootsState = Utils.CheckRootsState(getApplicationContext());
Logger.dh("QST (New): SetupState");
Logger.dev("QST (New): SetupState");
Icon iconRoot = Icon.createWithResource(getApplicationContext(), R.drawable.root);
Icon iconAuto = Icon.createWithResource(getApplicationContext(), R.drawable.ic_autoroot);
Tile tile = getQsTile();
Logger.dh("QST: State is " + mRootsState);
Logger.dev("QST: State is " + mRootsState);
switch (mRootsState) {
case 2:

View File

@ -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() {

View File

@ -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);

View File

@ -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) {

View File

@ -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 {