From 565cc1660fb5d797714ccc4d239ceb27825e1415 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Wed, 8 Feb 2023 11:48:25 -0500 Subject: [PATCH] fix update checks Signed-off-by: androidacy-user --- .../com/fox2code/mmm/AppUpdateManager.java | 54 ++++++------------- .../com/fox2code/mmm/repo/RepoUpdater.java | 4 ++ .../mmm/settings/SettingsActivity.java | 1 - 3 files changed, 20 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/fox2code/mmm/AppUpdateManager.java b/app/src/main/java/com/fox2code/mmm/AppUpdateManager.java index 981f299..99546bd 100644 --- a/app/src/main/java/com/fox2code/mmm/AppUpdateManager.java +++ b/app/src/main/java/com/fox2code/mmm/AppUpdateManager.java @@ -28,8 +28,8 @@ public class AppUpdateManager { public static final int FLAG_COMPAT_FORCE_HIDE = 0x0080; public static final int FLAG_COMPAT_MMT_REBORN = 0x0100; public static final int FLAG_COMPAT_ZIP_WRAPPER = 0x0200; - private static final AppUpdateManager INSTANCE = new AppUpdateManager(); public static final String RELEASES_API_URL = "https://api.github.com/repos/Fox2Code/FoxMagiskModuleManager/releases/latest"; + private static final AppUpdateManager INSTANCE = new AppUpdateManager(); private final HashMap compatDataId = new HashMap<>(); private final Object updateLock = new Object(); private final File compatFile; @@ -77,45 +77,23 @@ public class AppUpdateManager { synchronized (this.updateLock) { if (lastChecked != this.lastChecked) return this.peekShouldUpdate(); - boolean preReleaseNewer = true; try { - JSONObject releases = new JSONObject(new String(Http.doHttpGet(RELEASES_API_URL, false), StandardCharsets.UTF_8)); - String latestRelease = null, latestPreRelease = null; - for (int i = 0; i < releases.length(); i++) { - JSONObject release; - try { - release = releases.getJSONObject(String.valueOf(i)); - } catch ( - Exception e) { - continue; - } - // Skip invalid entries - if (release.getBoolean("draft")) - continue; - boolean preRelease = release.getBoolean("prerelease"); - String version = release.getString("tag_name"); - if (version.startsWith("v")) - version = version.substring(1); - if (preRelease) { - if (latestPreRelease == null) - latestPreRelease = version; - } else if (latestRelease == null) { - latestRelease = version; - if (latestPreRelease == null) - preReleaseNewer = false; - } - if (latestRelease != null && latestPreRelease != null) { - break; // We read everything we needed to read. - } + JSONObject release = new JSONObject(new String(Http.doHttpGet(RELEASES_API_URL, false), StandardCharsets.UTF_8)); + String latestRelease = null; + boolean preRelease = false; + // get latest_release from tag_name translated to int + if (release.has("tag_name")) { + latestRelease = release.getString("tag_name"); + preRelease = release.getBoolean("prerelease"); + } + Timber.d("Latest release: %s, isPreRelease: %s", latestRelease, preRelease); + if (latestRelease == null) + return false; + if (preRelease) { + this.latestRelease = "99999999"; // prevent updating to pre-release + return false; } - if (latestRelease != null) - this.latestRelease = latestRelease; - if (BuildConfig.DEBUG) - Timber.d("Latest release: %s", latestRelease); - if (BuildConfig.DEBUG) - Timber.d("Latest pre-release: %s", latestPreRelease); - if (BuildConfig.DEBUG) - Timber.d("Latest pre-release newer: %s", preReleaseNewer); + this.latestRelease = latestRelease; this.lastChecked = System.currentTimeMillis(); } catch ( Exception ioe) { diff --git a/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java b/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java index 26da2e0..99052b6 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java @@ -46,6 +46,7 @@ public class RepoUpdater { } // if we shouldn't update, get the values from the ModuleListCache realm if (!this.repoData.shouldUpdate()) { + Timber.d("Fetching index from cache for %s", this.repoData.id); RealmConfiguration realmConfiguration = new RealmConfiguration.Builder() .name("ModuleListCache.realm") .schemaVersion(1) @@ -64,6 +65,7 @@ public class RepoUpdater { this.toApply.add(new RepoModule(repoData, moduleListCache.getId())); } this.toApply = new HashSet<>(this.toUpdate); + Timber.d("Fetched %d modules from cache for %s", this.toApply.size(), this.repoData.id); return this.toUpdate.size(); } try { @@ -299,6 +301,8 @@ public class RepoUpdater { ReposList repoListCache = r.where(ReposList.class).equalTo("id", this.repoData.id).findFirst(); if (repoListCache != null) { repoListCache.setLastUpdate((int) System.currentTimeMillis()); + } else { + Timber.w("Failed to update lastUpdate for repo %s", this.repoData.id); } }); } diff --git a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java index a5ea27b..14ea73a 100644 --- a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java +++ b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java @@ -202,7 +202,6 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity { public static class SettingsFragment extends PreferenceFragmentCompat implements FoxActivity.OnBackPressedCallback { - @SuppressLint("UnspecifiedImmutableFlag") @Override @SuppressWarnings("ConstantConditions")