Prevent shell response crashes

This commit is contained in:
topjohnwu
2017-01-26 13:46:54 +08:00
parent c3c155a1ed
commit 46a4070f84
12 changed files with 118 additions and 81 deletions

View File

@@ -3,22 +3,26 @@ package com.topjohnwu.magisk;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ValueSortedMap;
import java.util.List;
public class Global {
public static class Constant {
// No global constants now
}
public static class Info {
public static double magiskVersion;
public static double remoteMagiskVersion = -1;
public static String magiskVersionString = "(none)";
public static double remoteMagiskVersion = -1;
public static String magiskLink;
public static String releaseNoteLink;
public static int SNCheckResult = -1;
@@ -43,11 +47,28 @@ public class Global {
public static boolean shellLogging;
public static boolean devLogging;
public static void init(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
isDarkTheme = prefs.getBoolean("dark_theme", false);
devLogging = prefs.getBoolean("developer_logging", false);
shellLogging = prefs.getBoolean("shell_logging", false);
}
public static void init(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Configs.isDarkTheme = prefs.getBoolean("dark_theme", false);
Configs.devLogging = prefs.getBoolean("developer_logging", false);
Configs.shellLogging = prefs.getBoolean("shell_logging", false);
updateMagiskInfo();
}
static void updateMagiskInfo() {
List<String> ret = Shell.sh("getprop magisk.version");
if (Utils.isValidShellResponse(ret)) {
Info.magiskVersion = -1;
} else {
try {
Info.magiskVersionString = ret.get(0);
Info.magiskVersion = Double.parseDouble(ret.get(0));
} catch (NumberFormatException e) {
// Custom version don't need to receive updates
Info.magiskVersion = Double.POSITIVE_INFINITY;
}
}
}