Magisk Update checker use prefs listener

This commit is contained in:
topjohnwu
2016-09-28 18:05:55 +08:00
parent cb5187fd8d
commit 0acc5e33b3
11 changed files with 411 additions and 276 deletions
@@ -58,7 +58,7 @@ public class Async {
"for tool in $(" + toolPath + "/busybox --list); do",
"ln -s " + busybox + " " + toolPath + "/$tool",
"done",
!Utils.commandExists("zip") ? "ln -s " + zip + " " + toolPath + "/zip" : ""
"ln -s " + zip + " " + toolPath + "/zip"
);
}
}
@@ -101,24 +101,8 @@ public class Async {
@Override
protected void onPostExecute(Void v) {
if (Shell.rootAccess() && Utils.magiskVersion == -1) {
new AlertDialog.Builder(mContext)
.setTitle(R.string.no_magisk_title)
.setMessage(R.string.no_magisk_msg)
.setCancelable(true)
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(
mContext,
new DownloadReceiver() {
@Override
public void task(Uri uri) {
new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
},
Utils.magiskLink,
"Magisk-v" + String.valueOf(Utils.remoteMagiskVersion) + ".zip"))
.setNegativeButton(R.string.no_thanks, null)
.show();
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
prefs.edit().putBoolean("update_check_done", true).apply();
}
}
@@ -9,8 +9,6 @@ import com.topjohnwu.magisk.ModulesFragment;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebRequest;
import org.json.JSONArray;
import org.json.JSONException;
@@ -46,9 +44,7 @@ public class RepoHelper {
}
// Making a request to url and getting response
String token = context.getString(R.string.some_string);
String url1 = context.getString(R.string.url_main);
String jsonStr = WebRequest.makeWebServiceCall(url1 + Utils.procFile(token, context), WebRequest.GET);
String jsonStr = WebRequest.makeWebServiceCall(context.getString(R.string.url_main) + Utils.getToken(), WebRequest.GET);
if (jsonStr != null && !jsonStr.isEmpty()) {
try {
JSONArray jsonArray = new JSONArray(jsonStr);
@@ -164,9 +164,9 @@ public class Shell {
STDOUT.join();
process.destroy();
} else {
STDIN.write(("echo \' \'\n").getBytes("UTF-8"));
STDIN.write(("echo\n").getBytes("UTF-8"));
STDIN.flush();
STDIN.write(("echo \'-done-\'\n").getBytes("UTF-8"));
STDIN.write(("echo \'-root-done-\'\n").getBytes("UTF-8"));
STDIN.flush();
while (true) {
try {
@@ -177,9 +177,11 @@ public class Shell {
// Process still running, gobble output until done
int end = res.size() - 1;
if (end > 0) {
if (res.get(end).equals("-done-")) {
if (res.get(end).equals("-root-done-")) {
res.remove(end);
res.remove(end - 1);
if (res.get(end -1).isEmpty()) {
res.remove(end -1);
}
break;
}
}
@@ -57,9 +57,12 @@ public class Utils {
public static final String MAGISK_CACHE_PATH = "/cache/magisk";
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
private static final String cryptoPass = "MagiskRox666";
private static final String secret = "GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus";
public static void init(Context context) {
List<String> ret = Shell.sh("getprop magisk.version");
if (ret.get(0).replaceAll("\\s", "").isEmpty()) {
if (ret.get(0).isEmpty()) {
magiskVersion = -1;
} else {
magiskVersion = Integer.parseInt(ret.get(0));
@@ -187,15 +190,14 @@ public class Utils {
context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
public static String procFile(String value, Context context) {
public static String getToken() {
String cryptoPass = context.getResources().getString(R.string.pass);
try {
DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(keySpec);
byte[] encrypedPwdBytes = Base64.decode(value, Base64.DEFAULT);
byte[] encrypedPwdBytes = Base64.decode(secret, Base64.DEFAULT);
// cipher is not thread safe
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
@@ -208,7 +210,7 @@ public class Utils {
| InvalidKeySpecException e) {
e.printStackTrace();
}
return value;
return secret;
}
public static void SetupQuickSettingsTile(Context mContext) {