Fix-up AndroidacyWebAPI

This commit is contained in:
Fox2Code 2022-01-29 01:38:40 +01:00
parent a37c047edb
commit 6414bd8c9a
2 changed files with 60 additions and 3 deletions

View File

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

View File

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