From 6414bd8c9aa6329bb92e7a2a321ee4b1b9c961f2 Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Sat, 29 Jan 2022 01:38:40 +0100 Subject: [PATCH] Fix-up AndroidacyWebAPI --- .../mmm/androidacy/AndroidacyWebAPI.java | 54 ++++++++++++++++++- .../com/fox2code/mmm/utils/PropUtils.java | 9 +++- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java index e4bbb21..11d35f0 100644 --- a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java +++ b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java @@ -1,15 +1,19 @@ package com.fox2code.mmm.androidacy; import android.net.Uri; +import android.util.Log; import android.webkit.JavascriptInterface; import android.widget.Toast; import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.installer.InstallerInitializer; +import com.fox2code.mmm.manager.LocalModuleInfo; +import com.fox2code.mmm.manager.ModuleInfo; import com.fox2code.mmm.manager.ModuleManager; import com.fox2code.mmm.utils.IntentHelper; public class AndroidacyWebAPI { + private static final String TAG = "AndroidacyWebAPI"; private final AndroidacyActivity activity; public AndroidacyWebAPI(AndroidacyActivity activity) { @@ -27,8 +31,12 @@ public class AndroidacyWebAPI { this.activity.forceBackPressed(); } + /** + * Open an url always in an external page or browser. + */ @JavascriptInterface public void openUrl(String url) { + Log.d(TAG, "Received openUrl request: " + url); if (Uri.parse(url).getScheme().equals("https")) { IntentHelper.openUrl(this.activity, url); } @@ -39,24 +47,36 @@ public class AndroidacyWebAPI { return MainApplication.getINSTANCE().isLightTheme(); } + /** + * Check if the manager has received root access + * (Note: hasRoot only return true on Magisk rooted phones) + */ @JavascriptInterface public boolean hasRoot() { return InstallerInitializer.peekMagiskPath() != null; } + /** + * Check if the install API can be used + */ @JavascriptInterface public boolean canInstall() { return InstallerInitializer.peekMagiskPath() != null && !MainApplication.isShowcaseMode(); } + /** + * install a module via url, with the file checked with the md5 checksum value. + */ @JavascriptInterface - public void install(String moduleUrl, String installTitle) { + public void install(String moduleUrl, String installTitle,String checksum) { if (MainApplication.isShowcaseMode() || - InstallerInitializer.peekMagiskPath() != null) { + InstallerInitializer.peekMagiskPath() == null) { // With lockdown mode enabled or lack of root, install should not have any effect return; } + Log.d(TAG, "Received install request: " + + moduleUrl + " " + installTitle + " " + checksum); Uri uri = Uri.parse(moduleUrl); if (uri.getScheme().equals("https") && uri.getHost().endsWith(".androidacy.com")) { IntentHelper.openInstaller(this.activity, moduleUrl, installTitle, null); @@ -65,8 +85,38 @@ public class AndroidacyWebAPI { } } + /** + * Tell if the moduleId is installed on the device + */ @JavascriptInterface public boolean isModuleInstalled(String moduleId) { return ModuleManager.getINSTANCE().getModules().get(moduleId) != null; } + + /** + * Tell if the moduleId is updating and waiting a reboot to update + */ + @JavascriptInterface + public boolean isModuleUpdating(String moduleId) { + LocalModuleInfo localModuleInfo = ModuleManager.getINSTANCE().getModules().get(moduleId); + return localModuleInfo != null && localModuleInfo.hasFlag(ModuleInfo.FLAG_MODULE_UPDATING); + } + + /** + * Return the module version name or null if not installed. + */ + @JavascriptInterface + public String getModuleVersion(String moduleId) { + LocalModuleInfo localModuleInfo = ModuleManager.getINSTANCE().getModules().get(moduleId); + return localModuleInfo != null ? localModuleInfo.version : null; + } + + /** + * Return the module version code or -1 if not installed. + */ + @JavascriptInterface + public long getModuleVersionCode(String moduleId) { + LocalModuleInfo localModuleInfo = ModuleManager.getINSTANCE().getModules().get(moduleId); + return localModuleInfo != null ? localModuleInfo.updateVersionCode : -1L; + } } 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 39e0c6f..fc5fc63 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java +++ b/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java @@ -181,7 +181,14 @@ public class PropUtils { break; case "minMagisk": try { - moduleInfo.minMagisk = Integer.parseInt(value); + int i = value.indexOf('.'); + if (i == -1) { + moduleInfo.minMagisk = Integer.parseInt(value); + } else { + moduleInfo.minMagisk = // Allow 24.1 to mean 24100 + (Integer.parseInt(value.substring(0, i)) * 1000) + + (Integer.parseInt(value.substring(i + 1)) * 100); + } } catch (Exception e) { moduleInfo.minMagisk = 0; }