Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 27c97fa

Browse files
committed
Add low quality module filter, and filter out invalid repo modules.
1 parent 874d5c7 commit 27c97fa

File tree

11 files changed

+64
-9
lines changed

11 files changed

+64
-9
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.fox2code.mmm"
1111
minSdk 21
1212
targetSdk 31
13-
versionCode 11
14-
versionName "0.2.2"
13+
versionCode 12
14+
versionName "0.2.3-rc1"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

app/src/main/java/com/fox2code/mmm/MainApplication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public static boolean isDeveloper() {
101101
getSharedPreferences().getBoolean("developer", false);
102102
}
103103

104+
public static boolean isDisableLowQualityModuleFilter() {
105+
return getSharedPreferences().getBoolean("pref_disable_low_quality_module_filter",
106+
false) && isDeveloper();
107+
}
108+
104109
public static boolean isUsingMagiskCommand() {
105110
return InstallerInitializer.peekMagiskVersion() >= Constants.MAGISK_VER_CODE_INSTALL_COMMAND
106111
&& getSharedPreferences().getBoolean("pref_use_magisk_install_command", false)

app/src/main/java/com/fox2code/mmm/ModuleHolder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.fox2code.mmm.manager.ModuleInfo;
1212
import com.fox2code.mmm.repo.RepoModule;
1313
import com.fox2code.mmm.utils.IntentHelper;
14+
import com.fox2code.mmm.utils.PropUtils;
1415

1516
import java.util.Comparator;
1617
import java.util.List;
@@ -125,7 +126,9 @@ public Type getCompareType(Type type) {
125126

126127
public boolean shouldRemove() {
127128
return this.notificationType != null ? this.notificationType.shouldRemove() :
128-
this.footerPx == 0 && this.moduleInfo == null && this.repoModule == null;
129+
this.footerPx == 0 && this.moduleInfo == null && (this.repoModule == null ||
130+
(PropUtils.isLowQualityModule(this.repoModule.moduleInfo) &&
131+
!MainApplication.isDisableLowQualityModuleFilter()));
129132
}
130133

131134
public void getButtons(Context context, List<ActionButtonType> buttonTypeList, boolean showcaseMode) {

app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ModuleInfo {
1818
public final String id;
1919
public String name;
2020
public String version;
21-
public int versionCode;
21+
public long versionCode;
2222
public String author;
2323
public String description;
2424
// Community meta

app/src/main/java/com/fox2code/mmm/repo/RepoData.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.fox2code.mmm.repo;
22

33
import android.content.SharedPreferences;
4+
import android.text.TextUtils;
45

56
import com.fox2code.mmm.manager.ModuleInfo;
67
import com.fox2code.mmm.utils.Files;
@@ -66,6 +67,8 @@ List<RepoModule> populate(JSONObject jsonObject) throws JSONException {
6667
for (int i = 0; i < len; i++) {
6768
JSONObject module = array.getJSONObject(i);
6869
String moduleId = module.getString("id");
70+
// Deny remote modules ids shorter than 3 chars long or that start with a digit
71+
if (moduleId.length() < 3 || Character.isDigit(moduleId.charAt(0))) continue;
6972
long moduleLastUpdate = module.getLong("last_update");
7073
String moduleNotesUrl = module.getString("notes_url");
7174
String modulePropsUrl = module.getString("prop_url");
@@ -108,8 +111,12 @@ public boolean tryLoadMetadata(RepoModule repoModule) {
108111
File file = new File(this.cacheRoot, repoModule.id + ".prop");
109112
if (file.exists()) {
110113
try {
111-
PropUtils.readProperties(repoModule.moduleInfo, file.getAbsolutePath());
112-
repoModule.moduleInfo.flags &= ~ModuleInfo.FLAG_METADATA_INVALID;
114+
ModuleInfo moduleInfo = repoModule.moduleInfo;
115+
PropUtils.readProperties(moduleInfo, file.getAbsolutePath());
116+
moduleInfo.flags &= ~ModuleInfo.FLAG_METADATA_INVALID;
117+
if (moduleInfo.version == null) {
118+
moduleInfo.version = "v" + moduleInfo.versionCode;
119+
}
113120
return true;
114121
} catch (Exception ignored) {
115122
file.delete();

app/src/main/java/com/fox2code/mmm/repo/RepoManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fox2code.mmm.utils.Files;
1010
import com.fox2code.mmm.utils.Hashes;
1111
import com.fox2code.mmm.utils.Http;
12+
import com.fox2code.mmm.utils.PropUtils;
1213

1314
import java.io.File;
1415
import java.util.HashMap;
@@ -147,15 +148,17 @@ private boolean scanInternal(UpdateListener updateListener) {
147148
updateListener.update(STEP1 / repoDatas.length * (i + 1));
148149
}
149150
int updatedModules = 0;
151+
boolean allowLowQualityModules = MainApplication.isDisableLowQualityModuleFilter();
150152
for (int i = 0; i < repoUpdaters.length; i++) {
151153
List<RepoModule> repoModules = repoUpdaters[i].toUpdate();
152154
RepoData repoData = repoDatas[i];
153155
for (RepoModule repoModule:repoModules) {
154156
try {
155157
Files.write(new File(repoData.cacheRoot, repoModule.id + ".prop"),
156158
Http.doHttpGet(repoModule.propUrl, false));
157-
if (repoDatas[i].tryLoadMetadata(repoModule)) {
158-
// Note: registeredRepoModule may not null if registered by multiple repos
159+
if (repoDatas[i].tryLoadMetadata(repoModule) && (allowLowQualityModules ||
160+
!PropUtils.isLowQualityModule(repoModule.moduleInfo))) {
161+
// Note: registeredRepoModule may not be null if registered by multiple repos
159162
RepoModule registeredRepoModule = this.modules.get(repoModule.id);
160163
if (registeredRepoModule == null) {
161164
this.modules.put(repoModule.id, repoModule);

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
8989
if ("dark".equals(themePreference.getValue())) {
9090
findPreference("pref_force_dark_terminal").setEnabled(false);
9191
}
92+
if (!MainApplication.isDeveloper()) {
93+
findPreference("pref_disable_low_quality_module_filter").setVisible(false);
94+
}
9295
if (InstallerInitializer.peekMagiskVersion() < Constants.MAGISK_VER_CODE_INSTALL_COMMAND
9396
|| !MainApplication.isDeveloper()) {
9497
findPreference("pref_use_magisk_install_command").setVisible(false);

app/src/main/java/com/fox2code/mmm/utils/PropUtils.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.fox2code.mmm.utils;
22

33
import android.os.Build;
4+
import android.text.TextUtils;
45

56
import com.fox2code.mmm.manager.ModuleInfo;
67
import com.topjohnwu.superuser.io.SuFileInputStream;
@@ -81,7 +82,7 @@ public static void readProperties(ModuleInfo moduleInfo, String file) throws IOE
8182
break;
8283
case "versionCode":
8384
readVersionCode = true;
84-
moduleInfo.versionCode = Integer.parseInt(value);
85+
moduleInfo.versionCode = Long.parseLong(value);
8586
break;
8687
case "author":
8788
moduleInfo.author = value;
@@ -167,4 +168,15 @@ else if (moduleInfo.id.startsWith("riru_")
167168
moduleInfo.config = moduleConfigsFallbacks.get(moduleInfo.id);
168169
}
169170
}
171+
172+
// Some module are really so low quality that it has become very annoying.
173+
public static boolean isLowQualityModule(ModuleInfo moduleInfo) {
174+
final String description;
175+
return moduleInfo == null || moduleInfo.hasFlag(ModuleInfo.FLAG_METADATA_INVALID)
176+
|| moduleInfo.name.length() < 3 || moduleInfo.versionCode < 0
177+
|| moduleInfo.author == null || !TextUtils.isGraphic(moduleInfo.author)
178+
|| (description = moduleInfo.description) == null || !TextUtils.isGraphic(description)
179+
|| description.toLowerCase(Locale.ROOT).equals(moduleInfo.name.toLowerCase(Locale.ROOT))
180+
|| description.length() < Math.min(Math.max(moduleInfo.name.length() + 4, 16), 24);
181+
}
170182
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z"/>
10+
</vector>

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@
5656
</string>
5757
<string name="dev_mode_enabled">Developer mode enabled</string>
5858
<string name="force_english_pref">Force English language</string>
59+
<string name="disable_low_quality_module_filter_pref">Disable low quality module filter</string>
60+
<string name="disable_low_quality_module_filter_desc">
61+
Some modules do not declare their metadata properly,causing visual glitches,
62+
and/or indicating poor module quality, disable at your own risk!
63+
</string>
5964
</resources>

0 commit comments

Comments
 (0)