mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 04:25:27 +00:00
Say goodbye to old modules
This commit is contained in:
parent
60ae685d1e
commit
817f050bcd
@ -57,12 +57,10 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
|
||||
String etag = prefs.getString(ETAG_KEY, "");
|
||||
header.put("If-None-Match", etag);
|
||||
|
||||
magiskManager.repoMap = new ValueSortedMap<>();
|
||||
|
||||
// Make a request to main URL for repo info
|
||||
String jsonString = WebService.request(REPO_URL, WebService.GET, null, header, false);
|
||||
|
||||
ValueSortedMap<String, Repo> cached = dbHelper.getRepoMap();
|
||||
ValueSortedMap<String, Repo> cached = dbHelper.getRepoMap(false), fetched = new ValueSortedMap<>();
|
||||
|
||||
if (!TextUtils.isEmpty(jsonString)) {
|
||||
try {
|
||||
@ -97,27 +95,24 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
|
||||
repo.update(updatedDate);
|
||||
}
|
||||
if (repo.getId() != null) {
|
||||
magiskManager.repoMap.put(id, repo);
|
||||
fetched.put(id, repo);
|
||||
}
|
||||
} catch (BaseModule.CacheModException ignored) {}
|
||||
|
||||
// Update the database
|
||||
dbHelper.addRepoMap(fetched);
|
||||
// The leftover cached are those removed remote, cleanup db
|
||||
dbHelper.removeRepo(cached);
|
||||
// Update ETag
|
||||
prefs.edit().putString(ETAG_KEY, etag).apply();
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
// Use cached if no internet or no updates
|
||||
Logger.dev("LoadRepos: No updates, use cached");
|
||||
magiskManager.repoMap.putAll(cached);
|
||||
cached.clear();
|
||||
}
|
||||
|
||||
// Update the database
|
||||
dbHelper.addRepoMap(magiskManager.repoMap);
|
||||
// The leftover cached are those removed remote, cleanup db
|
||||
dbHelper.removeRepo(cached);
|
||||
// Update ETag
|
||||
prefs.edit().putString(ETAG_KEY, etag).apply();
|
||||
magiskManager.repoMap = dbHelper.getRepoMap();
|
||||
|
||||
Logger.dev("LoadRepos: Repo load done");
|
||||
return null;
|
||||
|
@ -13,7 +13,7 @@ import java.util.Collection;
|
||||
|
||||
public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
private static final int DATABASE_VER = 1;
|
||||
private static final int DATABASE_VER = 2;
|
||||
private static final String TABLE_NAME = "repos";
|
||||
|
||||
public RepoDatabaseHelper(Context context) {
|
||||
@ -33,8 +33,12 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
||||
"(id TEXT, name TEXT, version TEXT, versionCode INT, " +
|
||||
"author TEXT, description TEXT, repo_name TEXT, last_update INT, " +
|
||||
"PRIMARY KEY(id))");
|
||||
oldVersion++;
|
||||
}
|
||||
if (oldVersion == 1) {
|
||||
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD template INT");
|
||||
oldVersion++;
|
||||
}
|
||||
// No upgrades yet
|
||||
}
|
||||
|
||||
public void addRepoMap(ValueSortedMap<String, Repo> map) {
|
||||
@ -62,6 +66,10 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
||||
}
|
||||
|
||||
public ValueSortedMap<String, Repo> getRepoMap() {
|
||||
return getRepoMap(true);
|
||||
}
|
||||
|
||||
public ValueSortedMap<String, Repo> getRepoMap(boolean filtered) {
|
||||
ValueSortedMap<String, Repo> ret = new ValueSortedMap<>();
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
Repo repo;
|
||||
@ -69,6 +77,10 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
||||
while (c.moveToNext()) {
|
||||
repo = new Repo(c);
|
||||
Logger.dev("Load from cache: " + repo.getId());
|
||||
if (repo.getTemplateVersion() < 3 && filtered) {
|
||||
Logger.dev("Outdated repo: " + repo.getId());
|
||||
continue;
|
||||
}
|
||||
ret.put(repo.getId(), repo);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
public abstract class BaseModule implements Comparable<BaseModule> {
|
||||
|
||||
private String mId, mName, mVersion, mAuthor, mDescription;
|
||||
private int mVersionCode = 0;
|
||||
private int mVersionCode = 0, templateVersion = 0;
|
||||
|
||||
protected BaseModule() {}
|
||||
|
||||
@ -22,6 +22,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
||||
mVersionCode = c.getInt(c.getColumnIndex("versionCode"));
|
||||
mAuthor = c.getString(c.getColumnIndex("author"));
|
||||
mDescription = c.getString(c.getColumnIndex("description"));
|
||||
templateVersion = c.getInt(c.getColumnIndex("template"));
|
||||
}
|
||||
|
||||
protected void parseProps(List<String> props) throws CacheModException { parseProps(props.toArray(new String[props.size()])); }
|
||||
@ -57,6 +58,10 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
||||
case "description":
|
||||
mDescription = prop[1];
|
||||
break;
|
||||
case "template":
|
||||
try {
|
||||
templateVersion = Integer.parseInt(prop[1]);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
case "cacheModule":
|
||||
if (Boolean.parseBoolean(prop[1]))
|
||||
throw new CacheModException(mId);
|
||||
@ -99,6 +104,10 @@ public abstract class BaseModule implements Comparable<BaseModule> {
|
||||
return mVersionCode;
|
||||
}
|
||||
|
||||
public int getTemplateVersion() {
|
||||
return templateVersion;
|
||||
}
|
||||
|
||||
public static class CacheModException extends Exception {
|
||||
public CacheModException(String id) {
|
||||
Logger.error("Cache mods are no longer supported! id: " + id);
|
||||
|
@ -53,6 +53,7 @@ public class Repo extends BaseModule {
|
||||
values.put("description", getDescription());
|
||||
values.put("repo_name", repoName);
|
||||
values.put("last_update", mLastUpdate.getTime());
|
||||
values.put("template", getTemplateVersion());
|
||||
return values;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user