From 27c97fa86596c50f851df45018e2eed0e9bb8857 Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Wed, 15 Dec 2021 22:28:27 +0100 Subject: [PATCH] Add low quality module filter, and filter out invalid repo modules. --- app/build.gradle | 4 ++-- .../java/com/fox2code/mmm/MainApplication.java | 5 +++++ .../main/java/com/fox2code/mmm/ModuleHolder.java | 5 ++++- .../java/com/fox2code/mmm/manager/ModuleInfo.java | 2 +- .../main/java/com/fox2code/mmm/repo/RepoData.java | 11 +++++++++-- .../java/com/fox2code/mmm/repo/RepoManager.java | 7 +++++-- .../fox2code/mmm/settings/SettingsActivity.java | 3 +++ .../java/com/fox2code/mmm/utils/PropUtils.java | 14 +++++++++++++- .../main/res/drawable/ic_baseline_warning_24.xml | 10 ++++++++++ app/src/main/res/values/strings.xml | 5 +++++ app/src/main/res/xml/root_preferences.xml | 7 +++++++ 11 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_warning_24.xml diff --git a/app/build.gradle b/app/build.gradle index 950f990..3a6135b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.fox2code.mmm" minSdk 21 targetSdk 31 - versionCode 11 - versionName "0.2.2" + versionCode 12 + versionName "0.2.3-rc1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index d531a0a..bbf516c 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -101,6 +101,11 @@ public class MainApplication extends Application implements CompatActivity.Appli getSharedPreferences().getBoolean("developer", false); } + public static boolean isDisableLowQualityModuleFilter() { + return getSharedPreferences().getBoolean("pref_disable_low_quality_module_filter", + false) && isDeveloper(); + } + public static boolean isUsingMagiskCommand() { return InstallerInitializer.peekMagiskVersion() >= Constants.MAGISK_VER_CODE_INSTALL_COMMAND && getSharedPreferences().getBoolean("pref_use_magisk_install_command", false) diff --git a/app/src/main/java/com/fox2code/mmm/ModuleHolder.java b/app/src/main/java/com/fox2code/mmm/ModuleHolder.java index 74aee8d..49c553f 100644 --- a/app/src/main/java/com/fox2code/mmm/ModuleHolder.java +++ b/app/src/main/java/com/fox2code/mmm/ModuleHolder.java @@ -11,6 +11,7 @@ import com.fox2code.mmm.installer.InstallerInitializer; import com.fox2code.mmm.manager.ModuleInfo; import com.fox2code.mmm.repo.RepoModule; import com.fox2code.mmm.utils.IntentHelper; +import com.fox2code.mmm.utils.PropUtils; import java.util.Comparator; import java.util.List; @@ -125,7 +126,9 @@ public final class ModuleHolder implements Comparable { public boolean shouldRemove() { return this.notificationType != null ? this.notificationType.shouldRemove() : - this.footerPx == 0 && this.moduleInfo == null && this.repoModule == null; + this.footerPx == 0 && this.moduleInfo == null && (this.repoModule == null || + (PropUtils.isLowQualityModule(this.repoModule.moduleInfo) && + !MainApplication.isDisableLowQualityModuleFilter())); } public void getButtons(Context context, List buttonTypeList, boolean showcaseMode) { diff --git a/app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java b/app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java index c3a1225..79adde6 100644 --- a/app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java +++ b/app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java @@ -18,7 +18,7 @@ public class ModuleInfo { public final String id; public String name; public String version; - public int versionCode; + public long versionCode; public String author; public String description; // Community meta diff --git a/app/src/main/java/com/fox2code/mmm/repo/RepoData.java b/app/src/main/java/com/fox2code/mmm/repo/RepoData.java index 1b290f2..02a6573 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoData.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoData.java @@ -1,6 +1,7 @@ package com.fox2code.mmm.repo; import android.content.SharedPreferences; +import android.text.TextUtils; import com.fox2code.mmm.manager.ModuleInfo; import com.fox2code.mmm.utils.Files; @@ -66,6 +67,8 @@ public class RepoData { for (int i = 0; i < len; i++) { JSONObject module = array.getJSONObject(i); String moduleId = module.getString("id"); + // Deny remote modules ids shorter than 3 chars long or that start with a digit + if (moduleId.length() < 3 || Character.isDigit(moduleId.charAt(0))) continue; long moduleLastUpdate = module.getLong("last_update"); String moduleNotesUrl = module.getString("notes_url"); String modulePropsUrl = module.getString("prop_url"); @@ -108,8 +111,12 @@ public class RepoData { File file = new File(this.cacheRoot, repoModule.id + ".prop"); if (file.exists()) { try { - PropUtils.readProperties(repoModule.moduleInfo, file.getAbsolutePath()); - repoModule.moduleInfo.flags &= ~ModuleInfo.FLAG_METADATA_INVALID; + ModuleInfo moduleInfo = repoModule.moduleInfo; + PropUtils.readProperties(moduleInfo, file.getAbsolutePath()); + moduleInfo.flags &= ~ModuleInfo.FLAG_METADATA_INVALID; + if (moduleInfo.version == null) { + moduleInfo.version = "v" + moduleInfo.versionCode; + } return true; } catch (Exception ignored) { file.delete(); diff --git a/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java b/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java index 3575199..1683c45 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java @@ -9,6 +9,7 @@ import com.fox2code.mmm.manager.ModuleInfo; import com.fox2code.mmm.utils.Files; import com.fox2code.mmm.utils.Hashes; import com.fox2code.mmm.utils.Http; +import com.fox2code.mmm.utils.PropUtils; import java.io.File; import java.util.HashMap; @@ -147,6 +148,7 @@ public final class RepoManager { updateListener.update(STEP1 / repoDatas.length * (i + 1)); } int updatedModules = 0; + boolean allowLowQualityModules = MainApplication.isDisableLowQualityModuleFilter(); for (int i = 0; i < repoUpdaters.length; i++) { List repoModules = repoUpdaters[i].toUpdate(); RepoData repoData = repoDatas[i]; @@ -154,8 +156,9 @@ public final class RepoManager { try { Files.write(new File(repoData.cacheRoot, repoModule.id + ".prop"), Http.doHttpGet(repoModule.propUrl, false)); - if (repoDatas[i].tryLoadMetadata(repoModule)) { - // Note: registeredRepoModule may not null if registered by multiple repos + if (repoDatas[i].tryLoadMetadata(repoModule) && (allowLowQualityModules || + !PropUtils.isLowQualityModule(repoModule.moduleInfo))) { + // Note: registeredRepoModule may not be null if registered by multiple repos RepoModule registeredRepoModule = this.modules.get(repoModule.id); if (registeredRepoModule == null) { this.modules.put(repoModule.id, repoModule); 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 27e0779..1c93a74 100644 --- a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java +++ b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java @@ -89,6 +89,9 @@ public class SettingsActivity extends CompatActivity { if ("dark".equals(themePreference.getValue())) { findPreference("pref_force_dark_terminal").setEnabled(false); } + if (!MainApplication.isDeveloper()) { + findPreference("pref_disable_low_quality_module_filter").setVisible(false); + } if (InstallerInitializer.peekMagiskVersion() < Constants.MAGISK_VER_CODE_INSTALL_COMMAND || !MainApplication.isDeveloper()) { findPreference("pref_use_magisk_install_command").setVisible(false); diff --git a/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java b/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java index 1a4bb08..a6cfcdf 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java +++ b/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java @@ -1,6 +1,7 @@ package com.fox2code.mmm.utils; import android.os.Build; +import android.text.TextUtils; import com.fox2code.mmm.manager.ModuleInfo; import com.topjohnwu.superuser.io.SuFileInputStream; @@ -81,7 +82,7 @@ public class PropUtils { break; case "versionCode": readVersionCode = true; - moduleInfo.versionCode = Integer.parseInt(value); + moduleInfo.versionCode = Long.parseLong(value); break; case "author": moduleInfo.author = value; @@ -167,4 +168,15 @@ public class PropUtils { moduleInfo.config = moduleConfigsFallbacks.get(moduleInfo.id); } } + + // Some module are really so low quality that it has become very annoying. + public static boolean isLowQualityModule(ModuleInfo moduleInfo) { + final String description; + return moduleInfo == null || moduleInfo.hasFlag(ModuleInfo.FLAG_METADATA_INVALID) + || moduleInfo.name.length() < 3 || moduleInfo.versionCode < 0 + || moduleInfo.author == null || !TextUtils.isGraphic(moduleInfo.author) + || (description = moduleInfo.description) == null || !TextUtils.isGraphic(description) + || description.toLowerCase(Locale.ROOT).equals(moduleInfo.name.toLowerCase(Locale.ROOT)) + || description.length() < Math.min(Math.max(moduleInfo.name.length() + 4, 16), 24); + } } diff --git a/app/src/main/res/drawable/ic_baseline_warning_24.xml b/app/src/main/res/drawable/ic_baseline_warning_24.xml new file mode 100644 index 0000000..a02bc13 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_warning_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 800da52..60aa0b0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -56,4 +56,9 @@ Developer mode enabled Force English language + Disable low quality module filter + + Some modules do not declare their metadata properly,causing visual glitches, + and/or indicating poor module quality, disable at your own risk! + \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index ea71ebf..03dcb82 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -37,6 +37,13 @@ app:title="@string/show_incompatible_pref" app:summary="@string/show_incompatible_desc"/> + +