Add low quality module filter, and filter out invalid repo modules.

pull/12/head 0.2.3-rc1
Fox2Code 3 years ago
parent 874d5c7854
commit 27c97fa865

@ -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"
}

@ -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)

@ -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<ModuleHolder> {
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<ActionButtonType> buttonTypeList, boolean showcaseMode) {

@ -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

@ -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();

@ -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<RepoModule> 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);

@ -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);

@ -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);
}
}

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z"/>
</vector>

@ -56,4 +56,9 @@
</string>
<string name="dev_mode_enabled">Developer mode enabled</string>
<string name="force_english_pref">Force English language</string>
<string name="disable_low_quality_module_filter_pref">Disable low quality module filter</string>
<string name="disable_low_quality_module_filter_desc">
Some modules do not declare their metadata properly,causing visual glitches,
and/or indicating poor module quality, disable at your own risk!
</string>
</resources>

@ -37,6 +37,13 @@
app:title="@string/show_incompatible_pref"
app:summary="@string/show_incompatible_desc"/>
<SwitchPreferenceCompat
app:defaultValue="false"
app:key="pref_disable_low_quality_module_filter"
app:icon="@drawable/ic_baseline_warning_24"
app:title="@string/disable_low_quality_module_filter_pref"
app:summary="@string/disable_low_quality_module_filter_desc"/>
<SwitchPreferenceCompat
app:defaultValue="false"
app:key="pref_use_magisk_install_command"

Loading…
Cancel
Save