Skip to content

Commit 8821cd4

Browse files
committed
Restore moduleInfo and add package info methods
Re-implemented the moduleInfo() method in KernelSUInterface to return actual module information. Added listPackages() and getPackagesInfo() methods to expose installed package details via JavaScript interface. Updated mmrl version in libs.versions.toml.
1 parent 8c07b54 commit 8821cd4

File tree

2 files changed

+86
-9
lines changed

2 files changed

+86
-9
lines changed

app/src/main/java/com/dergoogler/mmrl/wx/ui/activity/webui/interfaces/KernelSUInterface.kt

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package com.dergoogler.mmrl.wx.ui.activity.webui.interfaces
22

3+
import android.content.pm.ApplicationInfo
4+
import android.content.pm.PackageInfo
35
import android.text.TextUtils
46
import android.view.Window
57
import android.webkit.JavascriptInterface
68
import android.widget.Toast
79
import androidx.compose.runtime.getValue
810
import androidx.compose.runtime.mutableStateOf
911
import androidx.compose.runtime.setValue
12+
import androidx.core.content.pm.PackageInfoCompat
1013
import androidx.core.view.WindowInsetsCompat
1114
import androidx.core.view.WindowInsetsControllerCompat
15+
import com.dergoogler.mmrl.platform.PlatformManager
16+
import com.dergoogler.mmrl.platform.model.ModId.Companion.moduleDir
1217
import com.dergoogler.mmrl.webui.interfaces.WXInterface
1318
import com.dergoogler.mmrl.webui.interfaces.WXOptions
1419
import com.topjohnwu.superuser.CallbackList
@@ -78,17 +83,13 @@ class KernelSUInterface(
7883
}
7984

8085
@JavascriptInterface
81-
fun moduleInfo(): String {
82-
console.warn("$name.moduleInfo() have been removed due to security reasons.")
83-
val currentModuleInfo = JSONObject()
84-
currentModuleInfo.put("moduleDir", null)
85-
currentModuleInfo.put("id", null)
86-
return currentModuleInfo.toString()
86+
fun exec(cmd: String): String {
87+
return withNewRootShell { ShellUtils.fastCmd(this, cmd) }
8788
}
8889

8990
@JavascriptInterface
90-
fun exec(cmd: String): String {
91-
return withNewRootShell { ShellUtils.fastCmd(this, cmd) }
91+
fun execBool(cmd: String): Boolean {
92+
return withNewRootShell { ShellUtils.fastCmdResult(this, cmd) }
9293
}
9394

9495
@JavascriptInterface
@@ -229,6 +230,82 @@ class KernelSUInterface(
229230
}
230231
}
231232

233+
private val um = PlatformManager.userManager
234+
private val pm = PlatformManager.packageManager
235+
private val packages get(): List<PackageInfo> = pm.getInstalledPackagesAll(um, 0)
236+
237+
@JavascriptInterface
238+
fun moduleInfo(): String {
239+
val moduleInfos = JSONArray(PlatformManager.moduleManager.modules)
240+
val currentModuleInfo = JSONObject()
241+
currentModuleInfo.put("moduleDir", modId.moduleDir)
242+
for (i in 0 until moduleInfos.length()) {
243+
val currentInfo = moduleInfos.getJSONObject(i)
244+
245+
if (currentInfo.getString("id") != modId.toString()) {
246+
continue
247+
}
248+
249+
val keys = currentInfo.keys()
250+
for (key in keys) {
251+
currentModuleInfo.put(key, currentInfo[key])
252+
}
253+
break
254+
}
255+
return currentModuleInfo.toString()
256+
}
257+
258+
@JavascriptInterface
259+
fun listPackages(type: String): String {
260+
val packageNames = packages.filter { appInfo ->
261+
val flags = appInfo.applicationInfo?.flags ?: 0
262+
when (type.lowercase()) {
263+
"system" -> (flags and ApplicationInfo.FLAG_SYSTEM) != 0
264+
"user" -> (flags and ApplicationInfo.FLAG_SYSTEM) == 0
265+
else -> true
266+
}
267+
}
268+
.map { it.packageName }
269+
.sorted()
270+
271+
val jsonArray = JSONArray()
272+
for (pkgName in packageNames) {
273+
jsonArray.put(pkgName)
274+
}
275+
return jsonArray.toString()
276+
}
277+
278+
@JavascriptInterface
279+
fun getPackagesInfo(packageNamesJson: String): String {
280+
val packageNames = JSONArray(packageNamesJson)
281+
val jsonArray = JSONArray()
282+
val appMap = packages.associateBy { it.packageName }
283+
for (i in 0 until packageNames.length()) {
284+
val pkgName = packageNames.getString(i)
285+
val appInfo = appMap[pkgName]
286+
if (appInfo != null) {
287+
val app = appInfo.applicationInfo
288+
val obj = JSONObject()
289+
obj.put("packageName", appInfo.packageName)
290+
obj.put("versionName", appInfo.versionName ?: "")
291+
obj.put("versionCode", PackageInfoCompat.getLongVersionCode(appInfo))
292+
obj.put("appLabel", app?.loadLabel(context.packageManager))
293+
obj.put(
294+
"isSystem",
295+
if (app != null) ((app.flags and ApplicationInfo.FLAG_SYSTEM) != 0) else JSONObject.NULL
296+
)
297+
obj.put("uid", app?.uid ?: JSONObject.NULL)
298+
jsonArray.put(obj)
299+
} else {
300+
val obj = JSONObject()
301+
obj.put("packageName", pkgName)
302+
obj.put("error", "Package not found or inaccessible")
303+
jsonArray.put(obj)
304+
}
305+
}
306+
return jsonArray.toString()
307+
}
308+
232309
override fun onActivityStop() {
233310
super.onActivityStop()
234311

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
dexlib2 = "2.5.2"
3-
mmrl = "f45678111a"
3+
mmrl = "v34242"
44
adaptiveAndroid = "1.1.0-rc01"
55
androidGradlePlugin = "8.9.1"
66
androidxActivity = "1.9.3"

0 commit comments

Comments
 (0)