diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java b/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java index 70db85832..fb3006839 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java @@ -15,6 +15,7 @@ import android.widget.TextView; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.module.Module; +import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Shell; import java.util.List; @@ -43,11 +44,7 @@ public class ModulesAdapter extends RecyclerView.Adapter { - if (isChecked) { - new AsyncTask() { + holder.checkBox.setOnClickListener((v) -> { + CheckBox checkBox = (CheckBox) v; + if (checkBox.isChecked()) { + new Async.RootTask() { @Override protected Void doInBackground(Void... voids) { module.removeDisableFile(); @@ -75,9 +73,9 @@ public class ModulesAdapter extends RecyclerView.Adapter() { + new Async.RootTask() { @Override protected Void doInBackground(Void... voids) { module.createDisableFile(); @@ -88,13 +86,13 @@ public class ModulesAdapter extends RecyclerView.Adapter { if (module.willBeRemoved()) { - new AsyncTask() { + new Async.RootTask() { @Override protected Void doInBackground(Void... voids) { module.deleteRemoveFile(); @@ -106,9 +104,9 @@ public class ModulesAdapter extends RecyclerView.Adapter() { + new Async.RootTask() { @Override protected Void doInBackground(Void... voids) { module.createRemoveFile(); @@ -120,7 +118,7 @@ public class ModulesAdapter extends RecyclerView.Adapter } else { repo = mUpdateRepos.get(position); } - if (repo.isCache()) { - holder.title.setText("[Cache] " + repo.getName()); - } else { - holder.title.setText(repo.getName()); - } + holder.title.setText(repo.getName()); String author = repo.getAuthor(); String versionName = repo.getVersion(); String description = repo.getDescription(); diff --git a/app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java b/app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java index 491f672a6..b18de2d73 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java @@ -1,6 +1,8 @@ package com.topjohnwu.magisk.module; +import com.topjohnwu.magisk.utils.Logger; + import java.util.List; public abstract class BaseModule { @@ -9,9 +11,9 @@ public abstract class BaseModule { protected boolean mIsCacheModule = false; protected int mVersionCode = 0; - protected void parseProps(List props) { parseProps(props.toArray(new String[props.size()])); } + protected void parseProps(List props) throws CacheModException { parseProps(props.toArray(new String[props.size()])); } - protected void parseProps(String[] props) { + protected void parseProps(String[] props) throws CacheModException { for (String line : props) { String[] prop = line.split("=", 2); if (prop.length != 2) { @@ -34,7 +36,9 @@ public abstract class BaseModule { this.mVersion = prop[1]; break; case "versionCode": - this.mVersionCode = Integer.parseInt(prop[1]); + try { + this.mVersionCode = Integer.parseInt(prop[1]); + } catch (NumberFormatException ignored) {} break; case "author": this.mAuthor = prop[1]; @@ -55,6 +59,8 @@ public abstract class BaseModule { break; } } + if (mIsCacheModule) + throw new CacheModException(mId); } public String getName() { @@ -75,14 +81,6 @@ public abstract class BaseModule { return mDescription; } - public boolean isCache() { - return mIsCacheModule; - } - - public void setCache() { - mIsCacheModule = true; - } - public int getVersionCode() { return mVersionCode; } @@ -94,4 +92,10 @@ public abstract class BaseModule { public String getSupportUrl() { return mSupportUrl; } + + public static class CacheModException extends Exception { + public CacheModException(String id) { + Logger.dev("Cache mods are no longer supported! id: " + id); + } + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/module/Module.java b/app/src/main/java/com/topjohnwu/magisk/module/Module.java index 16de64c5f..faf2438a4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/Module.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Module.java @@ -8,7 +8,7 @@ public class Module extends BaseModule { private String mRemoveFile, mDisableFile, mUpdateFile; private boolean mEnable, mRemove, mUpdated; - public Module(String path) { + public Module(String path) throws CacheModException { parseProps(Utils.readFile(path + "/module.prop")); diff --git a/app/src/main/java/com/topjohnwu/magisk/module/Repo.java b/app/src/main/java/com/topjohnwu/magisk/module/Repo.java index 7f7482e71..c76ae905e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/Repo.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Repo.java @@ -12,7 +12,7 @@ public class Repo extends BaseModule { protected String repoName, mLogUrl, mManifestUrl, mZipUrl; protected Date mLastUpdate; - public Repo(Context context, String name, Date lastUpdate) { + public Repo(Context context, String name, Date lastUpdate) throws CacheModException { repoName = name; mLastUpdate = lastUpdate; mLogUrl = context.getString(R.string.file_url, repoName, "changelog.txt"); @@ -21,16 +21,18 @@ public class Repo extends BaseModule { update(); } - public void update() { + public void update() throws CacheModException { Logger.dev("Repo: Re-fetch prop " + mId); String props = WebRequest.makeWebServiceCall(mManifestUrl, WebRequest.GET, true); String lines[] = props.split("\\n"); parseProps(lines); } - public void update(Date lastUpdate) { + public void update(Date lastUpdate) throws CacheModException { Logger.dev("Repo: Old: " + mLastUpdate); Logger.dev("Repo: New: " + lastUpdate); + if (mIsCacheModule) + throw new CacheModException(mId); if (lastUpdate.after(mLastUpdate)) { mLastUpdate = lastUpdate; update(); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java b/app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java index eb468e222..bdad0dfc4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java @@ -6,6 +6,7 @@ import android.content.SharedPreferences; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.module.BaseModule; import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Repo; @@ -23,7 +24,6 @@ import java.util.TreeMap; public class ModuleHelper { public static final String MAGISK_PATH = "/magisk"; - public static final String MAGISK_CACHE_PATH = "/cache/magisk"; private static final String file_key = "RepoMap"; private static final String key = "repomap"; @@ -38,16 +38,11 @@ public class ModuleHelper { for (String path : Utils.getModList(MAGISK_PATH)) { Logger.dev("ModuleHelper: Adding modules from " + path); - Module module = new Module(path); - moduleMap.put(module.getId(), module); - } - - for (String path : Utils.getModList(MAGISK_CACHE_PATH)) { - Logger.dev("ModuleHelper: Adding cache modules from " + path); - Module cacheMod = new Module(path); - // Force set to cache - cacheMod.setCache(); - moduleMap.put(cacheMod.getId(), cacheMod); + Module module; + try { + module = new Module(path); + moduleMap.put(module.getId(), module); + } catch (BaseModule.CacheModException ignored) {} } Logger.dev("ModuleHelper: Module load done"); @@ -90,16 +85,18 @@ public class ModuleHelper { continue; } Repo repo = cached.get(id); - if (repo == null) { - Logger.dev("ModuleHelper: Create new repo " + id); - repo = new Repo(context, name, updatedDate); - } else { - Logger.dev("ModuleHelper: Cached repo " + id); - repo.update(updatedDate); - } - if (repo.getId() != null) { - repoMap.put(id, repo); - } + try { + if (repo == null) { + Logger.dev("ModuleHelper: Create new repo " + id); + repo = new Repo(context, name, updatedDate); + } else { + Logger.dev("ModuleHelper: Cached repo " + id); + repo.update(updatedDate); + } + if (repo.getId() != null) { + repoMap.put(id, repo); + } + } catch (BaseModule.CacheModException ignored) {} } } catch (JSONException e) { e.printStackTrace();