From eb838c4147fd599655ed6df520c5b3dc3e7c7d78 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Thu, 9 Feb 2023 11:48:53 -0500 Subject: [PATCH] add status notice for safe modules other tweaks known issues still: local module list doesnt show actions for updates etc, module cache isn't consistently used Signed-off-by: androidacy-user --- .../java/com/fox2code/mmm/manager/ModuleInfo.java | 2 ++ .../com/fox2code/mmm/module/ActionButtonType.java | 13 +++++++++++++ .../java/com/fox2code/mmm/module/ModuleHolder.java | 3 +++ .../main/java/com/fox2code/mmm/repo/RepoData.java | 4 ++++ .../java/com/fox2code/mmm/repo/RepoUpdater.java | 10 ++++++++++ .../fox2code/mmm/utils/realm/ModuleListCache.java | 11 +++++++++++ .../main/res/drawable/baseline_verified_user_24.xml | 5 +++++ app/src/main/res/values/strings.xml | 2 +- 8 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/baseline_verified_user_24.xml 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 91f8e03..2aec369 100644 --- a/app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java +++ b/app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java @@ -45,6 +45,7 @@ public class ModuleInfo { public int maxApi; // Module status (0 if not from Module Manager) public int flags; + public boolean safe; public ModuleInfo(String id) { this.id = id; @@ -69,6 +70,7 @@ public class ModuleInfo { this.minApi = moduleInfo.minApi; this.maxApi = moduleInfo.maxApi; this.flags = moduleInfo.flags; + this.safe = moduleInfo.safe; } public boolean hasFlag(int flag) { diff --git a/app/src/main/java/com/fox2code/mmm/module/ActionButtonType.java b/app/src/main/java/com/fox2code/mmm/module/ActionButtonType.java index f90bb08..3dd77d0 100644 --- a/app/src/main/java/com/fox2code/mmm/module/ActionButtonType.java +++ b/app/src/main/java/com/fox2code/mmm/module/ActionButtonType.java @@ -216,6 +216,19 @@ public enum ActionButtonType { new MaterialAlertDialogBuilder(button.getContext()).setTitle(R.string.warning).setMessage(R.string.warning_message).setPositiveButton(R.string.understand, (v, i) -> { }).create().show(); } + }, SAFE() { + // SAFE is for modules that the api says are clean. only supported by androidacy currently + @Override + public void update(Chip button, ModuleHolder moduleHolder) { + button.setChipIcon(button.getContext().getDrawable(R.drawable.baseline_verified_user_24)); + button.setText(R.string.safe); + } + + @Override + public void doAction(Chip button, ModuleHolder moduleHolder) { + new MaterialAlertDialogBuilder(button.getContext()).setTitle(R.string.safe_module).setMessage(R.string.safe_message).setPositiveButton(R.string.understand, (v, i) -> { + }).create().show(); + } }; @DrawableRes diff --git a/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java b/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java index b54e3cd..caffd9b 100644 --- a/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java +++ b/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java @@ -212,6 +212,9 @@ public final class ModuleHolder implements Comparable { if (moduleInfo.donate != null) { buttonTypeList.add(ActionButtonType.DONATE); } + if (moduleInfo.safe) { + buttonTypeList.add(ActionButtonType.SAFE); + } } public boolean hasUpdate() { 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 3255578..9b517c9 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoData.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoData.java @@ -92,6 +92,7 @@ public class RepoData extends XRepo { supportedProperties.put("repoId", ""); supportedProperties.put("installed", ""); supportedProperties.put("installedVersionCode", ""); + supportedProperties.put("safe", ""); } catch (JSONException e) { Timber.e(e, "Error while setting up supportedProperties"); } @@ -354,6 +355,7 @@ public class RepoData extends XRepo { // should update (lastUpdate > 15 minutes) public boolean shouldUpdate() { + Timber.d("Repo " + this.id + " should update check called"); 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); ReposList repo = realm2.where(ReposList.class).equalTo("id", this.id).findFirst(); @@ -367,8 +369,10 @@ public class RepoData extends XRepo { long currentTime = System.currentTimeMillis(); long diff = currentTime - lastUpdate; long diffMinutes = diff / (60 * 1000) % 60; + Timber.d("Repo " + this.id + " updated: " + diffMinutes + " minutes ago"); return diffMinutes > 15; } else { + Timber.d("Repo " + this.id + " should update could not find repo in database"); return true; } } 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 99052b6..a2fc494 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java @@ -250,6 +250,15 @@ public class RepoUpdater { boolean installed = false; // get module installed version code int installedVersionCode = 0; + // get safe property. for now, only supported by androidacy repo and they use "vt_status" key + boolean safe = false; + if (this.repoData.getName().equals("Androidacy Modules Repo")) { + if (module.has("vt_status")) { + if (module.getString("vt_status").equals("safe")) { + safe = true; + } + } + } // insert module to realm // first create a collection of all the properties // then insert to realm @@ -279,6 +288,7 @@ public class RepoUpdater { moduleListCache.setRepoId(repoId); moduleListCache.setInstalled(installed); moduleListCache.setInstalledVersionCode(installedVersionCode); + moduleListCache.setSafe(safe); realm.copyToRealmOrUpdate(moduleListCache); realm.commitTransaction(); } catch ( diff --git a/app/src/main/java/com/fox2code/mmm/utils/realm/ModuleListCache.java b/app/src/main/java/com/fox2code/mmm/utils/realm/ModuleListCache.java index 714f163..4d4075f 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/realm/ModuleListCache.java +++ b/app/src/main/java/com/fox2code/mmm/utils/realm/ModuleListCache.java @@ -34,6 +34,8 @@ public class ModuleListCache extends RealmObject { private boolean installed; private int installedVersionCode; private int lastUpdate; + // androidacy specific, may be added by other repos + private boolean safe; public ModuleListCache(String id, 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) { this.id = id; @@ -55,6 +57,7 @@ public class ModuleListCache extends RealmObject { this.installed = installed; this.installedVersionCode = installedVersionCode; this.lastUpdate = lastUpdate; + this.safe = false; } public ModuleListCache() { @@ -229,6 +232,14 @@ public class ModuleListCache extends RealmObject { this.lastUpdate = lastUpdate; } + public boolean isSafe() { + return safe; + } + + public void setSafe(boolean safe) { + this.safe = safe; + } + private JSONObject toJson() { JSONObject jsonObject = new JSONObject(); try { diff --git a/app/src/main/res/drawable/baseline_verified_user_24.xml b/app/src/main/res/drawable/baseline_verified_user_24.xml new file mode 100644 index 0000000..7412473 --- /dev/null +++ b/app/src/main/res/drawable/baseline_verified_user_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3295e0f..36da048 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -359,5 +359,5 @@ No modules installed on device Notifies when module updates are found Updates - This module has metadata that is either invalid or considered a marker for a low-quality module. Uninstallation is recommended.Online + This module has metadata that is either invalid or considered a marker for a low-quality module. Uninstallation is recommended.OnlineSafeVerified safe moduleThis module has been verified by the repository as safe, meaning it passes certain quality and safety thresholds, and is checked for malware.