11package com .fox2code .mmm .androidacy ;
22
33import android .net .Uri ;
4+ import android .util .Log ;
45import android .webkit .JavascriptInterface ;
56import android .widget .Toast ;
67
78import com .fox2code .mmm .MainApplication ;
89import com .fox2code .mmm .installer .InstallerInitializer ;
10+ import com .fox2code .mmm .manager .LocalModuleInfo ;
11+ import com .fox2code .mmm .manager .ModuleInfo ;
912import com .fox2code .mmm .manager .ModuleManager ;
1013import com .fox2code .mmm .utils .IntentHelper ;
1114
1215public 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}
0 commit comments