Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 6414bd8

Browse files
committed
Fix-up AndroidacyWebAPI
1 parent a37c047 commit 6414bd8

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package com.fox2code.mmm.androidacy;
22

33
import android.net.Uri;
4+
import android.util.Log;
45
import android.webkit.JavascriptInterface;
56
import android.widget.Toast;
67

78
import com.fox2code.mmm.MainApplication;
89
import com.fox2code.mmm.installer.InstallerInitializer;
10+
import com.fox2code.mmm.manager.LocalModuleInfo;
11+
import com.fox2code.mmm.manager.ModuleInfo;
912
import com.fox2code.mmm.manager.ModuleManager;
1013
import com.fox2code.mmm.utils.IntentHelper;
1114

1215
public class AndroidacyWebAPI {
16+
private static final String TAG = "AndroidacyWebAPI";
1317
private final AndroidacyActivity activity;
1418

1519
public AndroidacyWebAPI(AndroidacyActivity activity) {
@@ -27,8 +31,12 @@ public void cancel() {
2731
this.activity.forceBackPressed();
2832
}
2933

34+
/**
35+
* Open an url always in an external page or browser.
36+
*/
3037
@JavascriptInterface
3138
public void openUrl(String url) {
39+
Log.d(TAG, "Received openUrl request: " + url);
3240
if (Uri.parse(url).getScheme().equals("https")) {
3341
IntentHelper.openUrl(this.activity, url);
3442
}
@@ -39,24 +47,36 @@ public boolean isLightTheme() {
3947
return MainApplication.getINSTANCE().isLightTheme();
4048
}
4149

50+
/**
51+
* Check if the manager has received root access
52+
* (Note: hasRoot only return true on Magisk rooted phones)
53+
*/
4254
@JavascriptInterface
4355
public boolean hasRoot() {
4456
return InstallerInitializer.peekMagiskPath() != null;
4557
}
4658

59+
/**
60+
* Check if the install API can be used
61+
*/
4762
@JavascriptInterface
4863
public boolean canInstall() {
4964
return InstallerInitializer.peekMagiskPath() != null &&
5065
!MainApplication.isShowcaseMode();
5166
}
5267

68+
/**
69+
* install a module via url, with the file checked with the md5 checksum value.
70+
*/
5371
@JavascriptInterface
54-
public void install(String moduleUrl, String installTitle) {
72+
public void install(String moduleUrl, String installTitle,String checksum) {
5573
if (MainApplication.isShowcaseMode() ||
56-
InstallerInitializer.peekMagiskPath() != null) {
74+
InstallerInitializer.peekMagiskPath() == null) {
5775
// With lockdown mode enabled or lack of root, install should not have any effect
5876
return;
5977
}
78+
Log.d(TAG, "Received install request: " +
79+
moduleUrl + " " + installTitle + " " + checksum);
6080
Uri uri = Uri.parse(moduleUrl);
6181
if (uri.getScheme().equals("https") && uri.getHost().endsWith(".androidacy.com")) {
6282
IntentHelper.openInstaller(this.activity, moduleUrl, installTitle, null);
@@ -65,8 +85,38 @@ public void install(String moduleUrl, String installTitle) {
6585
}
6686
}
6787

88+
/**
89+
* Tell if the moduleId is installed on the device
90+
*/
6891
@JavascriptInterface
6992
public boolean isModuleInstalled(String moduleId) {
7093
return ModuleManager.getINSTANCE().getModules().get(moduleId) != null;
7194
}
95+
96+
/**
97+
* Tell if the moduleId is updating and waiting a reboot to update
98+
*/
99+
@JavascriptInterface
100+
public boolean isModuleUpdating(String moduleId) {
101+
LocalModuleInfo localModuleInfo = ModuleManager.getINSTANCE().getModules().get(moduleId);
102+
return localModuleInfo != null && localModuleInfo.hasFlag(ModuleInfo.FLAG_MODULE_UPDATING);
103+
}
104+
105+
/**
106+
* Return the module version name or null if not installed.
107+
*/
108+
@JavascriptInterface
109+
public String getModuleVersion(String moduleId) {
110+
LocalModuleInfo localModuleInfo = ModuleManager.getINSTANCE().getModules().get(moduleId);
111+
return localModuleInfo != null ? localModuleInfo.version : null;
112+
}
113+
114+
/**
115+
* Return the module version code or -1 if not installed.
116+
*/
117+
@JavascriptInterface
118+
public long getModuleVersionCode(String moduleId) {
119+
LocalModuleInfo localModuleInfo = ModuleManager.getINSTANCE().getModules().get(moduleId);
120+
return localModuleInfo != null ? localModuleInfo.updateVersionCode : -1L;
121+
}
72122
}

app/src/main/java/com/fox2code/mmm/utils/PropUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,14 @@ public static void readProperties(ModuleInfo moduleInfo, InputStream inputStream
181181
break;
182182
case "minMagisk":
183183
try {
184-
moduleInfo.minMagisk = Integer.parseInt(value);
184+
int i = value.indexOf('.');
185+
if (i == -1) {
186+
moduleInfo.minMagisk = Integer.parseInt(value);
187+
} else {
188+
moduleInfo.minMagisk = // Allow 24.1 to mean 24100
189+
(Integer.parseInt(value.substring(0, i)) * 1000) +
190+
(Integer.parseInt(value.substring(i + 1)) * 100);
191+
}
185192
} catch (Exception e) {
186193
moduleInfo.minMagisk = 0;
187194
}

0 commit comments

Comments
 (0)