fix cache issues + increase performance

cache is feature complete now, custom repos adding is still having leaks

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/285/head
androidacy-user 1 year ago
parent 1f38a197de
commit 6d0dec6ead

@ -352,6 +352,9 @@ public final class AndroidacyRepoData extends RepoData {
repoModule.notesUrl = this.injectToken(repoModule.notesUrl);
repoModule.qualityText = R.string.module_downloads;
repoModule.qualityValue = jsonObject.optInt("downloads", 0);
if (repoModule.qualityValue == 0) {
repoModule.qualityValue = jsonObject.optInt("stats", 0);
}
String checksum = jsonObject.optString("checksum", "");
repoModule.checksum = checksum.isEmpty() ? null : checksum;
ModuleInfo moduleInfo = repoModule.moduleInfo;

@ -165,12 +165,6 @@ public class InstallerActivity extends FoxActivity {
throw new SecurityException("Module cache is not in cache dir!");
File moduleCache = this.toDelete = urlMode ?
new File(this.moduleCache, "module.zip") : new File(finalTarget);
try {
if (!moduleCache.getCanonicalPath().startsWith(MainApplication.getINSTANCE().getCacheDir().getAbsolutePath()))
throw new SecurityException("Module cache is not in cache dir!");
} catch (
IOException ignored) {
}
if (urlMode && moduleCache.exists() && !moduleCache.delete() &&
!new SuFile(moduleCache.getAbsolutePath()).delete())
Timber.e("Failed to delete module cache");

@ -40,13 +40,12 @@ public class RepoData extends XRepo {
public final String id;
public final File cacheRoot;
public final SharedPreferences cachedPreferences;
public JSONObject metaDataCache;
public final HashMap<String, RepoModule> moduleHashMap;
public final JSONObject supportedProperties = new JSONObject();
private final Object populateLock = new Object();
public JSONObject metaDataCache;
public long lastUpdate;
public String name, website, support, donate, submitModule;
public final JSONObject supportedProperties = new JSONObject();
protected String defaultName, defaultWebsite, defaultSupport, defaultDonate, defaultSubmitModule;
// array with module info default values
@ -189,6 +188,10 @@ public class RepoData extends XRepo {
String moduleChecksum = module.optString("checksum");
String moduleStars = module.optString("stars");
String moduleDownloads = module.optString("downloads");
// if downloads is mull or empty, try to get it from the stats field
if (moduleDownloads.isEmpty() && module.has("stats")) {
moduleDownloads = module.optString("stats");
}
RepoModule repoModule = this.moduleHashMap.get(moduleId);
if (repoModule == null) {
repoModule = new RepoModule(this, moduleId);
@ -212,15 +215,13 @@ public class RepoData extends XRepo {
try {
repoModule.qualityValue = Integer.parseInt(moduleStars);
repoModule.qualityText = R.string.module_stars;
} catch (
NumberFormatException ignored) {
} catch (NumberFormatException ignored) {
}
} else if (!moduleDownloads.isEmpty()) {
try {
repoModule.qualityValue = Integer.parseInt(moduleDownloads);
repoModule.qualityText = R.string.module_downloads;
} catch (
NumberFormatException ignored) {
} catch (NumberFormatException ignored) {
}
}
}
@ -269,8 +270,7 @@ public class RepoData extends XRepo {
moduleInfo.version = "v" + moduleInfo.versionCode;
}
return true;
} catch (
Exception ignored) {
} catch (Exception ignored) {
boolean delete = file.delete();
if (!delete) {
throw new RuntimeException("Failed to delete invalid metadata file");
@ -312,7 +312,15 @@ public class RepoData extends XRepo {
// reposlist realm
RealmConfiguration realmConfiguration2 = new RealmConfiguration.Builder().name("ReposList.realm").allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build();
Realm realm2 = Realm.getInstance(realmConfiguration2);
this.enabled = (!this.forceHide) && Objects.requireNonNull(realm2.where(ReposList.class).equalTo("id", this.id).findFirst()).isEnabled();
boolean dbEnabled;
try {
dbEnabled = Objects.requireNonNull(realm2.where(ReposList.class).equalTo("id", this.id).findFirst()).isEnabled();
} catch (NullPointerException e) {
Timber.e(e, "Error while updating enabled state");
// for now, throw an exception
throw e;
}
this.enabled = (!this.forceHide) && dbEnabled;
}
public String getUrl() throws NoSuchAlgorithmException {
@ -327,37 +335,30 @@ public class RepoData extends XRepo {
@NonNull
@Override
public String getName() {
if (isNonNull(this.name))
return this.name;
if (this.defaultName != null)
return this.defaultName;
if (isNonNull(this.name)) return this.name;
if (this.defaultName != null) return this.defaultName;
return this.url;
}
@NonNull
public String getWebsite() {
if (isNonNull(this.website))
return this.website;
if (this.defaultWebsite != null)
return this.defaultWebsite;
if (isNonNull(this.website)) return this.website;
if (this.defaultWebsite != null) return this.defaultWebsite;
return this.url;
}
public String getSupport() {
if (isNonNull(this.support))
return this.support;
if (isNonNull(this.support)) return this.support;
return this.defaultSupport;
}
public String getDonate() {
if (isNonNull(this.donate))
return this.donate;
if (isNonNull(this.donate)) return this.donate;
return this.defaultDonate;
}
public String getSubmitModule() {
if (isNonNull(this.submitModule))
return this.submitModule;
if (isNonNull(this.submitModule)) return this.submitModule;
return this.defaultSubmitModule;
}

@ -128,27 +128,20 @@ public final class RepoManager extends SyncManager {
}
public static String internalIdOfUrl(String url) {
switch (url) {
case MAGISK_ALT_REPO:
case MAGISK_ALT_REPO_JSDELIVR:
return "magisk_alt_repo";
case ANDROIDACY_MAGISK_REPO_ENDPOINT:
case ANDROIDACY_TEST_MAGISK_REPO_ENDPOINT:
return "androidacy_repo";
default:
return "repo_" + Hashes.hashSha256(url.getBytes(StandardCharsets.UTF_8));
}
return switch (url) {
case MAGISK_ALT_REPO, MAGISK_ALT_REPO_JSDELIVR -> "magisk_alt_repo";
case ANDROIDACY_MAGISK_REPO_ENDPOINT, ANDROIDACY_TEST_MAGISK_REPO_ENDPOINT ->
"androidacy_repo";
default -> "repo_" + Hashes.hashSha256(url.getBytes(StandardCharsets.UTF_8));
};
}
static boolean isBuiltInRepo(String repo) {
switch (repo) {
case RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT:
case RepoManager.ANDROIDACY_TEST_MAGISK_REPO_ENDPOINT:
case RepoManager.MAGISK_ALT_REPO:
case RepoManager.MAGISK_ALT_REPO_JSDELIVR:
return true;
}
return false;
return switch (repo) {
case RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT, RepoManager.ANDROIDACY_TEST_MAGISK_REPO_ENDPOINT, RepoManager.MAGISK_ALT_REPO, RepoManager.MAGISK_ALT_REPO_JSDELIVR ->
true;
default -> false;
};
}
/**
@ -408,10 +401,7 @@ public final class RepoManager extends SyncManager {
}
}
switch (url) {
case MAGISK_REPO:
case MAGISK_REPO_MANAGER: {
repoData.defaultWebsite = MAGISK_REPO_HOMEPAGE;
}
case MAGISK_REPO, MAGISK_REPO_MANAGER -> repoData.defaultWebsite = MAGISK_REPO_HOMEPAGE;
}
this.repoData.put(url, repoData);
if (this.initialized) {

@ -262,6 +262,15 @@ public class RepoUpdater {
} else {
lastUpdate = 0;
}
// now downloads or stars
int downloads;
if (module.has("downloads")) {
downloads = module.getInt("downloads");
} else if (module.has("stars")) {
downloads = module.getInt("stars");
} else {
downloads = 0;
}
// get module repo id
String repoId = this.repoData.id;
// get module installed
@ -308,6 +317,7 @@ public class RepoUpdater {
moduleListCache.setInstalledVersionCode(installedVersionCode);
moduleListCache.setSafe(safe);
moduleListCache.setLastUpdate(lastUpdate);
moduleListCache.setStats(downloads);
realm.copyToRealmOrUpdate(moduleListCache);
realm.commitTransaction();
} catch (

@ -37,8 +37,9 @@ public class ModuleListCache extends RealmObject {
private int lastUpdate;
// androidacy specific, may be added by other repos
private boolean safe;
private int stats;
public ModuleListCache(String codename, String name, String version, int versionCode, String author, String description, int minApi, int maxApi, int minMagisk, boolean needRamdisk, String support, String donate, String config, boolean changeBoot, boolean mmtReborn, String repoId, boolean installed, int installedVersionCode, int lastUpdate) {
public ModuleListCache(String codename, String name, String version, int versionCode, String author, String description, int minApi, int maxApi, int minMagisk, boolean needRamdisk, String support, String donate, String config, boolean changeBoot, boolean mmtReborn, String repoId, boolean installed, int installedVersionCode, int lastUpdate, int stats) {
this.codename = codename;
this.name = name;
this.version = version;
@ -59,6 +60,7 @@ public class ModuleListCache extends RealmObject {
this.installedVersionCode = installedVersionCode;
this.lastUpdate = lastUpdate;
this.safe = false;
this.stats = stats;
}
public ModuleListCache() {
@ -241,6 +243,14 @@ public class ModuleListCache extends RealmObject {
this.safe = safe;
}
public int getStats() {
return stats;
}
public void setStats(int stats) {
this.stats = stats;
}
private JSONObject toJson() {
JSONObject jsonObject = new JSONObject();
try {
@ -261,6 +271,9 @@ public class ModuleListCache extends RealmObject {
jsonObject.put("repoId", repoId);
jsonObject.put("installed", installed);
jsonObject.put("installedVersionCode", installedVersionCode);
jsonObject.put("lastUpdate", lastUpdate);
jsonObject.put("safe", safe);
jsonObject.put("stats", stats);
} catch (JSONException e) {
e.printStackTrace();
}

Loading…
Cancel
Save