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.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<ModulesAdapter.ViewHold
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final Module module = mList.get(position);
if (module.isCache()) {
holder.title.setText("[Cache] " + module.getName());
} else {
holder.title.setText(module.getName());
}
holder.title.setText(module.getName());
String author = module.getAuthor();
String versionName = module.getVersion();
String description = module.getDescription();
@ -62,9 +59,10 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
}
holder.checkBox.setChecked(module.isEnabled());
holder.checkBox.setOnCheckedChangeListener((compoundButton, isChecked) -> {
if (isChecked) {
new AsyncTask<Void, Void, Void>() {
holder.checkBox.setOnClickListener((v) -> {
CheckBox checkBox = (CheckBox) v;
if (checkBox.isChecked()) {
new Async.RootTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
module.removeDisableFile();
@ -75,9 +73,9 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
protected void onPostExecute(Void v) {
Snackbar.make(mView, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}.exec();
} else {
new AsyncTask<Void, Void, Void>() {
new Async.RootTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
module.createDisableFile();
@ -88,13 +86,13 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
protected void onPostExecute(Void v) {
Snackbar.make(mView, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show();
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}.exec();
}
});
holder.delete.setOnClickListener(v -> {
if (module.willBeRemoved()) {
new AsyncTask<Void, Void, Void>() {
new Async.RootTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
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();
updateDeleteButton(holder, module);
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}.exec();
} else {
new AsyncTask<Void, Void, Void>() {
new Async.RootTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
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();
updateDeleteButton(holder, module);
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}.exec();
}
});

View File

@ -76,11 +76,7 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
} 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();

View File

@ -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<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) {
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);
}
}
}

View File

@ -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"));

View File

@ -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();

View File

@ -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();