From 897c99b34552a0ac2250b88adfad9701a8005175 Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Tue, 10 May 2022 18:55:26 +0200 Subject: [PATCH] Add `needRamdisk` and `changeBoot` module flags. --- DEVELOPERS.md | 4 ++++ .../com/fox2code/mmm/manager/ModuleInfo.aidl | 3 --- .../mmm/androidacy/AndroidacyRepoData.java | 1 + .../mmm/installer/InstallerInitializer.java | 19 ++++++++++++++++--- .../com/fox2code/mmm/manager/ModuleInfo.java | 4 ++++ .../mmm/module/ModuleViewListBuilder.java | 5 ++++- .../com/fox2code/mmm/utils/PropUtils.java | 6 ++++++ 7 files changed, 35 insertions(+), 7 deletions(-) delete mode 100644 app/src/main/aidl/com/fox2code/mmm/manager/ModuleInfo.aidl diff --git a/DEVELOPERS.md b/DEVELOPERS.md index e29a7f8..cdce7e9 100644 --- a/DEVELOPERS.md +++ b/DEVELOPERS.md @@ -46,9 +46,11 @@ This the manager support these new optional properties minApi= maxApi= minMagisk= +needRamdisk= support= donate= config= +changeBoot= ``` Note: All urls must start with `https://`, or else will be ignored NoteĀ²: For `minMagisk`, `XX.Y` is parsed as `XXY00`, so you can just put the Magisk version name. @@ -57,10 +59,12 @@ NoteĀ²: For `minMagisk`, `XX.Y` is parsed as `XXY00`, so you can just put the Ma (See: [Codenames, Tags, and Build Numbers](https://source.android.com/setup/start/build-numbers)) - `minMagisk` tell the manager which is the minimum Magisk version required for the module (Often for magisk `xx.y` the version code is `xxyzz`, `zz` being non `00` on canary builds) +- `needRamdisk` tell the manager the module need boot ramdisk to be installed - `support` support link to direct users when they need support for you modules - `donate` donate link to direct users to where they can financially support your project - `config` package name of the application that configure your module (Note: The icon won't appear in the module list if the module or target app is not installed) +- `changeBoot` tell the manager the module may change the boot image Note: Fox's Mmm use fallback [here](app/src/main/java/com/fox2code/mmm/utils/PropUtils.java#L36) diff --git a/app/src/main/aidl/com/fox2code/mmm/manager/ModuleInfo.aidl b/app/src/main/aidl/com/fox2code/mmm/manager/ModuleInfo.aidl deleted file mode 100644 index 488fde5..0000000 --- a/app/src/main/aidl/com/fox2code/mmm/manager/ModuleInfo.aidl +++ /dev/null @@ -1,3 +0,0 @@ -package com.fox2code.mmm.manager; - -parcelable ModuleInfo; diff --git a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java index e722f02..54d6204 100644 --- a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java +++ b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java @@ -206,6 +206,7 @@ public class AndroidacyRepoData extends RepoData { } catch (Exception e) { moduleInfo.minMagisk = 0; } + moduleInfo.needRamdisk = jsonObject.optBoolean("needRamdisk", false); moduleInfo.support = filterURL(jsonObject.optString("support")); moduleInfo.donate = filterURL(jsonObject.optString("donate")); String config = jsonObject.optString("config", ""); diff --git a/app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java b/app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java index 475d47f..4fc7e76 100644 --- a/app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java +++ b/app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java @@ -20,6 +20,7 @@ public class InstallerInitializer extends Shell.Initializer { new File("/system/bin/magisk"); private static String MAGISK_PATH; private static int MAGISK_VERSION_CODE; + private static boolean HAS_RAMDISK; public static final int ERROR_OK = 0; public static final int ERROR_NO_PATH = 1; @@ -44,6 +45,10 @@ public class InstallerInitializer extends Shell.Initializer { return InstallerInitializer.MAGISK_VERSION_CODE; } + public static boolean peekHasRamdisk() { + return InstallerInitializer.HAS_RAMDISK; + } + public static void tryGetMagiskPathAsync(Callback callback) { tryGetMagiskPathAsync(callback, false); } @@ -90,14 +95,22 @@ public class InstallerInitializer extends Shell.Initializer { private static String tryGetMagiskPath(boolean forceCheck) { String MAGISK_PATH = InstallerInitializer.MAGISK_PATH; int MAGISK_VERSION_CODE; + boolean HAS_RAMDISK = InstallerInitializer.HAS_RAMDISK; if (MAGISK_PATH != null && !forceCheck) return MAGISK_PATH; ArrayList output = new ArrayList<>(); - if(!Shell.cmd("magisk -V", "magisk --path").to(output).exec().isSuccess()) { + if(!Shell.cmd("if grep ' / ' /proc/mounts | grep -q '/dev/root' &> /dev/null; " + + "then echo true; else echo false; fi", "magisk -V", "magisk --path") + .to(output).exec().isSuccess()) { + if (output.size() != 0) { + HAS_RAMDISK = "false".equals(output.get(0)) || + "true".equalsIgnoreCase(System.getProperty("ro.build.ab_update")); + } + InstallerInitializer.HAS_RAMDISK = HAS_RAMDISK; return null; } - MAGISK_PATH = output.size() < 2 ? "" : output.get(1); + MAGISK_PATH = output.size() < 3 ? "" : output.get(2); Log.d(TAG, "Magisk runtime path: " + MAGISK_PATH); - MAGISK_VERSION_CODE = Integer.parseInt(output.get(0)); + MAGISK_VERSION_CODE = Integer.parseInt(output.get(1)); Log.d(TAG, "Magisk version code: " + MAGISK_VERSION_CODE); if (MAGISK_VERSION_CODE >= Constants.MAGISK_VER_CODE_FLAT_MODULES && MAGISK_VERSION_CODE < Constants.MAGISK_VER_CODE_PATH_SUPPORT && 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 3c0036b..3973209 100644 --- a/app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java +++ b/app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java @@ -27,10 +27,12 @@ public class ModuleInfo { public String description; public String updateJson; // Community meta + public boolean changeBoot; public String support; public String donate; public String config; // Community restrictions + public boolean needRamdisk; public int minMagisk; public int minApi; public int maxApi; @@ -50,9 +52,11 @@ public class ModuleInfo { this.author = moduleInfo.author; this.description = moduleInfo.description; this.updateJson = moduleInfo.updateJson; + this.changeBoot = moduleInfo.changeBoot; this.support = moduleInfo.support; this.donate = moduleInfo.donate; this.config = moduleInfo.config; + this.needRamdisk = moduleInfo.needRamdisk; this.minMagisk = moduleInfo.minMagisk; this.minApi = moduleInfo.minApi; this.maxApi = moduleInfo.maxApi; diff --git a/app/src/main/java/com/fox2code/mmm/module/ModuleViewListBuilder.java b/app/src/main/java/com/fox2code/mmm/module/ModuleViewListBuilder.java index ba7c85c..44948f3 100644 --- a/app/src/main/java/com/fox2code/mmm/module/ModuleViewListBuilder.java +++ b/app/src/main/java/com/fox2code/mmm/module/ModuleViewListBuilder.java @@ -94,7 +94,10 @@ public class ModuleViewListBuilder { InstallerInitializer.peekMagiskVersion())) || // If 64bit only system, skip 32bit only modules (no32bitSupport && (AppUpdateManager.getFlagsForModule(repoModule.id) - & AppUpdateManager.FLAG_COMPAT_NEED_32BIT) != 0) + & AppUpdateManager.FLAG_COMPAT_NEED_32BIT) != 0) || + // If module need ramdisk but boot doesn't have one + (repoModule.moduleInfo.needRamdisk && + !InstallerInitializer.peekHasRamdisk()) ) continue; // Skip adding incompatible modules ModuleHolder moduleHolder = this.mappedModuleHolders.get(repoModule.id); if (moduleHolder == null) { 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 63639c2..fbf0989 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java +++ b/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java @@ -192,6 +192,9 @@ public class PropUtils { moduleInfo.updateJson = value; readUpdateJson = true; break; + case "changeBoot": + moduleInfo.changeBoot = Boolean.parseBoolean(value); + break; case "support": // Do not accept invalid or too broad support links if (isInvalidURL(value) || @@ -207,6 +210,9 @@ public class PropUtils { case "config": moduleInfo.config = value; break; + case "needRamdisk": + moduleInfo.needRamdisk = Boolean.parseBoolean(value); + break; case "minMagisk": try { int i = value.indexOf('.');