Commit 0acc5e33 authored by topjohnwu's avatar topjohnwu

Magisk Update checker use prefs listener

parent cb5187fd
...@@ -68,12 +68,15 @@ public class SplashActivity extends AppCompatActivity { ...@@ -68,12 +68,15 @@ public class SplashActivity extends AppCompatActivity {
defaultPrefs.edit() defaultPrefs.edit()
.putBoolean("module_done", false) .putBoolean("module_done", false)
.putBoolean("repo_done", false) .putBoolean("repo_done", false)
.putBoolean("update_check_done", false)
.apply(); .apply();
new Async.CheckUpdates(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.LoadModules(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new Async.CheckUpdates(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new Async.LoadRepos(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.constructEnv(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new Async.constructEnv(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new Async.LoadModules(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.LoadRepos(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
// Start main activity // Start main activity
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
startActivity(intent); startActivity(intent);
......
...@@ -8,7 +8,7 @@ import java.util.List; ...@@ -8,7 +8,7 @@ import java.util.List;
public abstract class BaseModule { public abstract class BaseModule {
protected String mId, mName, mVersion, mAuthor, mDescription, mSupportUrl, mDonateUrl; protected String mId, mName, mVersion, mAuthor, mDescription, mSupportUrl, mDonateUrl;
protected boolean mIsCacheModule = false; protected boolean mIsCacheModule = false, mCanUpdate = false;
protected int mVersionCode = 0; protected int mVersionCode = 0;
protected void parseProps(List<String> props) { parseProps(props.toArray(new String[props.size()])); } protected void parseProps(List<String> props) { parseProps(props.toArray(new String[props.size()])); }
...@@ -97,4 +97,12 @@ public abstract class BaseModule { ...@@ -97,4 +97,12 @@ public abstract class BaseModule {
public String getSupportUrl() { public String getSupportUrl() {
return mSupportUrl; return mSupportUrl;
} }
public void setUpdate() {
mCanUpdate = true;
}
public boolean canUpdate() {
return mCanUpdate;
}
} }
...@@ -8,7 +8,7 @@ public class Module extends BaseModule { ...@@ -8,7 +8,7 @@ public class Module extends BaseModule {
private String mRemoveFile; private String mRemoveFile;
private String mDisableFile; private String mDisableFile;
private boolean mEnable, mRemove, mUpdateAvailable = false; private boolean mEnable, mRemove;
public Module(String path) { public Module(String path) {
...@@ -38,7 +38,7 @@ public class Module extends BaseModule { ...@@ -38,7 +38,7 @@ public class Module extends BaseModule {
repo.setInstalled(); repo.setInstalled();
if (repo.getVersionCode() > mVersionCode) { if (repo.getVersionCode() > mVersionCode) {
repo.setUpdate(); repo.setUpdate();
mUpdateAvailable = true; mCanUpdate = true;
} }
} }
} }
...@@ -67,6 +67,4 @@ public class Module extends BaseModule { ...@@ -67,6 +67,4 @@ public class Module extends BaseModule {
return mRemove; return mRemove;
} }
public boolean isUpdateAvailable() { return mUpdateAvailable; }
} }
\ No newline at end of file
...@@ -18,7 +18,7 @@ import java.util.Date; ...@@ -18,7 +18,7 @@ import java.util.Date;
public class Repo extends BaseModule { public class Repo extends BaseModule {
protected String repoName, mLogUrl, mManifestUrl, mZipUrl; protected String repoName, mLogUrl, mManifestUrl, mZipUrl;
protected Date mLastUpdate; protected Date mLastUpdate;
protected boolean mIsInstalled = false, mCanUpdate = false; protected boolean mIsInstalled = false;
public Repo(Context context, String name, Date lastUpdate) { public Repo(Context context, String name, Date lastUpdate) {
repoName = name; repoName = name;
...@@ -42,10 +42,6 @@ public class Repo extends BaseModule { ...@@ -42,10 +42,6 @@ public class Repo extends BaseModule {
} }
} }
public void setUpdate() {
mCanUpdate = true;
}
public void setInstalled() { public void setInstalled() {
mIsInstalled = true; mIsInstalled = true;
} }
...@@ -67,6 +63,4 @@ public class Repo extends BaseModule { ...@@ -67,6 +63,4 @@ public class Repo extends BaseModule {
} }
public boolean isInstalled() { return mIsInstalled; } public boolean isInstalled() { return mIsInstalled; }
public boolean canUpdate() { return mCanUpdate; }
public boolean isCacheModule() { return mIsCacheModule; }
} }
...@@ -58,7 +58,7 @@ public class Async { ...@@ -58,7 +58,7 @@ public class Async {
"for tool in $(" + toolPath + "/busybox --list); do", "for tool in $(" + toolPath + "/busybox --list); do",
"ln -s " + busybox + " " + toolPath + "/$tool", "ln -s " + busybox + " " + toolPath + "/$tool",
"done", "done",
!Utils.commandExists("zip") ? "ln -s " + zip + " " + toolPath + "/zip" : "" "ln -s " + zip + " " + toolPath + "/zip"
); );
} }
} }
...@@ -101,24 +101,8 @@ public class Async { ...@@ -101,24 +101,8 @@ public class Async {
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
if (Shell.rootAccess() && Utils.magiskVersion == -1) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
new AlertDialog.Builder(mContext) prefs.edit().putBoolean("update_check_done", true).apply();
.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();
}
} }
} }
......
...@@ -9,8 +9,6 @@ import com.topjohnwu.magisk.ModulesFragment; ...@@ -9,8 +9,6 @@ import com.topjohnwu.magisk.ModulesFragment;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.module.Repo; 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.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -46,9 +44,7 @@ public class RepoHelper { ...@@ -46,9 +44,7 @@ public class RepoHelper {
} }
// Making a request to url and getting response // Making a request to url and getting response
String token = context.getString(R.string.some_string); String jsonStr = WebRequest.makeWebServiceCall(context.getString(R.string.url_main) + Utils.getToken(), WebRequest.GET);
String url1 = context.getString(R.string.url_main);
String jsonStr = WebRequest.makeWebServiceCall(url1 + Utils.procFile(token, context), WebRequest.GET);
if (jsonStr != null && !jsonStr.isEmpty()) { if (jsonStr != null && !jsonStr.isEmpty()) {
try { try {
JSONArray jsonArray = new JSONArray(jsonStr); JSONArray jsonArray = new JSONArray(jsonStr);
......
...@@ -164,9 +164,9 @@ public class Shell { ...@@ -164,9 +164,9 @@ public class Shell {
STDOUT.join(); STDOUT.join();
process.destroy(); process.destroy();
} else { } else {
STDIN.write(("echo \' \'\n").getBytes("UTF-8")); STDIN.write(("echo\n").getBytes("UTF-8"));
STDIN.flush(); STDIN.flush();
STDIN.write(("echo \'-done-\'\n").getBytes("UTF-8")); STDIN.write(("echo \'-root-done-\'\n").getBytes("UTF-8"));
STDIN.flush(); STDIN.flush();
while (true) { while (true) {
try { try {
...@@ -177,9 +177,11 @@ public class Shell { ...@@ -177,9 +177,11 @@ public class Shell {
// Process still running, gobble output until done // Process still running, gobble output until done
int end = res.size() - 1; int end = res.size() - 1;
if (end > 0) { if (end > 0) {
if (res.get(end).equals("-done-")) { if (res.get(end).equals("-root-done-")) {
res.remove(end); res.remove(end);
res.remove(end - 1); if (res.get(end -1).isEmpty()) {
res.remove(end -1);
}
break; break;
} }
} }
......
...@@ -57,9 +57,12 @@ public class Utils { ...@@ -57,9 +57,12 @@ public class Utils {
public static final String MAGISK_CACHE_PATH = "/cache/magisk"; 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"; 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) { public static void init(Context context) {
List<String> ret = Shell.sh("getprop magisk.version"); List<String> ret = Shell.sh("getprop magisk.version");
if (ret.get(0).replaceAll("\\s", "").isEmpty()) { if (ret.get(0).isEmpty()) {
magiskVersion = -1; magiskVersion = -1;
} else { } else {
magiskVersion = Integer.parseInt(ret.get(0)); magiskVersion = Integer.parseInt(ret.get(0));
...@@ -187,15 +190,14 @@ public class Utils { ...@@ -187,15 +190,14 @@ public class Utils {
context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); 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 { try {
DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8")); DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(keySpec); 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 is not thread safe
Cipher cipher = Cipher.getInstance("DES"); Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key); cipher.init(Cipher.DECRYPT_MODE, key);
...@@ -208,7 +210,7 @@ public class Utils { ...@@ -208,7 +210,7 @@ public class Utils {
| InvalidKeySpecException e) { | InvalidKeySpecException e) {
e.printStackTrace(); e.printStackTrace();
} }
return value; return secret;
} }
public static void SetupQuickSettingsTile(Context mContext) { public static void SetupQuickSettingsTile(Context mContext) {
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
...@@ -163,4 +172,6 @@ ...@@ -163,4 +172,6 @@
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
\ No newline at end of file
</android.support.v4.widget.SwipeRefreshLayout>
\ No newline at end of file
...@@ -105,8 +105,6 @@ ...@@ -105,8 +105,6 @@
<string name="root_system_msg">It seems that you have incompatible root installed\nDo you want to install Magisk compatible root now?</string> <string name="root_system_msg">It seems that you have incompatible root installed\nDo you want to install Magisk compatible root now?</string>
<!--Web Related--> <!--Web Related-->
<string name="pass">MagiskRox666</string>
<string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string>
<string name="url_main">https://api.github.com/orgs/Magisk-Modules-Repo/repos?access_token=</string> <string name="url_main">https://api.github.com/orgs/Magisk-Modules-Repo/repos?access_token=</string>
<string name="file_url">https://raw.githubusercontent.com/Magisk-Modules-Repo/%1$s/master/%2$s</string> <string name="file_url">https://raw.githubusercontent.com/Magisk-Modules-Repo/%1$s/master/%2$s</string>
<string name="zip_url">https://github.com/Magisk-Modules-Repo/%1$s/archive/master.zip</string> <string name="zip_url">https://github.com/Magisk-Modules-Repo/%1$s/archive/master.zip</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment