Officially drop Cache Modules

This commit is contained in:
topjohnwu 2016-11-09 00:46:26 +08:00
parent 436b0624e7
commit aababe1a87
6 changed files with 53 additions and 56 deletions

View File

@ -15,6 +15,7 @@ import android.widget.TextView;
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.utils.Async;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import java.util.List; import java.util.List;
@ -43,11 +44,7 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
@Override @Override
public void onBindViewHolder(final ViewHolder holder, int position) { public void onBindViewHolder(final ViewHolder holder, int position) {
final Module module = mList.get(position); final Module module = mList.get(position);
if (module.isCache()) { holder.title.setText(module.getName());
holder.title.setText("[Cache] " + module.getName());
} else {
holder.title.setText(module.getName());
}
String author = module.getAuthor(); String author = module.getAuthor();
String versionName = module.getVersion(); String versionName = module.getVersion();
String description = module.getDescription(); String description = module.getDescription();
@ -62,9 +59,10 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
} }
holder.checkBox.setChecked(module.isEnabled()); holder.checkBox.setChecked(module.isEnabled());
holder.checkBox.setOnCheckedChangeListener((compoundButton, isChecked) -> { holder.checkBox.setOnClickListener((v) -> {
if (isChecked) { CheckBox checkBox = (CheckBox) v;
new AsyncTask<Void, Void, Void>() { if (checkBox.isChecked()) {
new Async.RootTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
module.removeDisableFile(); module.removeDisableFile();
@ -75,9 +73,9 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
Snackbar.make(mView, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show(); Snackbar.make(mView, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
} }
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }.exec();
} else { } else {
new AsyncTask<Void, Void, Void>() { new Async.RootTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
module.createDisableFile(); module.createDisableFile();
@ -88,13 +86,13 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
Snackbar.make(mView, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show(); Snackbar.make(mView, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show();
} }
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }.exec();
} }
}); });
holder.delete.setOnClickListener(v -> { holder.delete.setOnClickListener(v -> {
if (module.willBeRemoved()) { if (module.willBeRemoved()) {
new AsyncTask<Void, Void, Void>() { new Async.RootTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
module.deleteRemoveFile(); module.deleteRemoveFile();
@ -106,9 +104,9 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
Snackbar.make(mView, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show(); Snackbar.make(mView, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
updateDeleteButton(holder, module); updateDeleteButton(holder, module);
} }
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }.exec();
} else { } else {
new AsyncTask<Void, Void, Void>() { new Async.RootTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
module.createRemoveFile(); module.createRemoveFile();
@ -120,7 +118,7 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
Snackbar.make(mView, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show(); Snackbar.make(mView, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show();
updateDeleteButton(holder, module); updateDeleteButton(holder, module);
} }
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }.exec();
} }
}); });

View File

@ -76,11 +76,7 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
} else { } else {
repo = mUpdateRepos.get(position); repo = mUpdateRepos.get(position);
} }
if (repo.isCache()) { holder.title.setText(repo.getName());
holder.title.setText("[Cache] " + repo.getName());
} else {
holder.title.setText(repo.getName());
}
String author = repo.getAuthor(); String author = repo.getAuthor();
String versionName = repo.getVersion(); String versionName = repo.getVersion();
String description = repo.getDescription(); String description = repo.getDescription();

View File

@ -1,6 +1,8 @@
package com.topjohnwu.magisk.module; package com.topjohnwu.magisk.module;
import com.topjohnwu.magisk.utils.Logger;
import java.util.List; import java.util.List;
public abstract class BaseModule { public abstract class BaseModule {
@ -9,9 +11,9 @@ public abstract class BaseModule {
protected boolean mIsCacheModule = false; protected boolean mIsCacheModule = 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) 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) { for (String line : props) {
String[] prop = line.split("=", 2); String[] prop = line.split("=", 2);
if (prop.length != 2) { if (prop.length != 2) {
@ -34,7 +36,9 @@ public abstract class BaseModule {
this.mVersion = prop[1]; this.mVersion = prop[1];
break; break;
case "versionCode": case "versionCode":
this.mVersionCode = Integer.parseInt(prop[1]); try {
this.mVersionCode = Integer.parseInt(prop[1]);
} catch (NumberFormatException ignored) {}
break; break;
case "author": case "author":
this.mAuthor = prop[1]; this.mAuthor = prop[1];
@ -55,6 +59,8 @@ public abstract class BaseModule {
break; break;
} }
} }
if (mIsCacheModule)
throw new CacheModException(mId);
} }
public String getName() { public String getName() {
@ -75,14 +81,6 @@ public abstract class BaseModule {
return mDescription; return mDescription;
} }
public boolean isCache() {
return mIsCacheModule;
}
public void setCache() {
mIsCacheModule = true;
}
public int getVersionCode() { public int getVersionCode() {
return mVersionCode; return mVersionCode;
} }
@ -94,4 +92,10 @@ public abstract class BaseModule {
public String getSupportUrl() { public String getSupportUrl() {
return mSupportUrl; return mSupportUrl;
} }
public static class CacheModException extends Exception {
public CacheModException(String id) {
Logger.dev("Cache mods are no longer supported! id: " + id);
}
}
} }

View File

@ -8,7 +8,7 @@ public class Module extends BaseModule {
private String mRemoveFile, mDisableFile, mUpdateFile; private String mRemoveFile, mDisableFile, mUpdateFile;
private boolean mEnable, mRemove, mUpdated; private boolean mEnable, mRemove, mUpdated;
public Module(String path) { public Module(String path) throws CacheModException {
parseProps(Utils.readFile(path + "/module.prop")); parseProps(Utils.readFile(path + "/module.prop"));

View File

@ -12,7 +12,7 @@ public class Repo extends BaseModule {
protected String repoName, mLogUrl, mManifestUrl, mZipUrl; protected String repoName, mLogUrl, mManifestUrl, mZipUrl;
protected Date mLastUpdate; protected Date mLastUpdate;
public Repo(Context context, String name, Date lastUpdate) { public Repo(Context context, String name, Date lastUpdate) throws CacheModException {
repoName = name; repoName = name;
mLastUpdate = lastUpdate; mLastUpdate = lastUpdate;
mLogUrl = context.getString(R.string.file_url, repoName, "changelog.txt"); mLogUrl = context.getString(R.string.file_url, repoName, "changelog.txt");
@ -21,16 +21,18 @@ public class Repo extends BaseModule {
update(); update();
} }
public void update() { public void update() throws CacheModException {
Logger.dev("Repo: Re-fetch prop " + mId); Logger.dev("Repo: Re-fetch prop " + mId);
String props = WebRequest.makeWebServiceCall(mManifestUrl, WebRequest.GET, true); String props = WebRequest.makeWebServiceCall(mManifestUrl, WebRequest.GET, true);
String lines[] = props.split("\\n"); String lines[] = props.split("\\n");
parseProps(lines); parseProps(lines);
} }
public void update(Date lastUpdate) { public void update(Date lastUpdate) throws CacheModException {
Logger.dev("Repo: Old: " + mLastUpdate); Logger.dev("Repo: Old: " + mLastUpdate);
Logger.dev("Repo: New: " + lastUpdate); Logger.dev("Repo: New: " + lastUpdate);
if (mIsCacheModule)
throw new CacheModException(mId);
if (lastUpdate.after(mLastUpdate)) { if (lastUpdate.after(mLastUpdate)) {
mLastUpdate = lastUpdate; mLastUpdate = lastUpdate;
update(); update();

View File

@ -6,6 +6,7 @@ import android.content.SharedPreferences;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.module.BaseModule;
import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.module.Repo;
@ -23,7 +24,6 @@ import java.util.TreeMap;
public class ModuleHelper { public class ModuleHelper {
public static final String MAGISK_PATH = "/magisk"; 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 file_key = "RepoMap";
private static final String key = "repomap"; private static final String key = "repomap";
@ -38,16 +38,11 @@ public class ModuleHelper {
for (String path : Utils.getModList(MAGISK_PATH)) { for (String path : Utils.getModList(MAGISK_PATH)) {
Logger.dev("ModuleHelper: Adding modules from " + path); Logger.dev("ModuleHelper: Adding modules from " + path);
Module module = new Module(path); Module module;
moduleMap.put(module.getId(), module); try {
} module = new Module(path);
moduleMap.put(module.getId(), module);
for (String path : Utils.getModList(MAGISK_CACHE_PATH)) { } catch (BaseModule.CacheModException ignored) {}
Logger.dev("ModuleHelper: Adding cache modules from " + path);
Module cacheMod = new Module(path);
// Force set to cache
cacheMod.setCache();
moduleMap.put(cacheMod.getId(), cacheMod);
} }
Logger.dev("ModuleHelper: Module load done"); Logger.dev("ModuleHelper: Module load done");
@ -90,16 +85,18 @@ public class ModuleHelper {
continue; continue;
} }
Repo repo = cached.get(id); Repo repo = cached.get(id);
if (repo == null) { try {
Logger.dev("ModuleHelper: Create new repo " + id); if (repo == null) {
repo = new Repo(context, name, updatedDate); Logger.dev("ModuleHelper: Create new repo " + id);
} else { repo = new Repo(context, name, updatedDate);
Logger.dev("ModuleHelper: Cached repo " + id); } else {
repo.update(updatedDate); Logger.dev("ModuleHelper: Cached repo " + id);
} repo.update(updatedDate);
if (repo.getId() != null) { }
repoMap.put(id, repo); if (repo.getId() != null) {
} repoMap.put(id, repo);
}
} catch (BaseModule.CacheModException ignored) {}
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();