You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
manager: introduce app package info API for webui-next
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".KernelSUApplication"
|
android:name=".KernelSUApplication"
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ class WebUIActivity : ComponentActivity() {
|
|||||||
val name = intent.getStringExtra("name")!!
|
val name = intent.getStringExtra("name")!!
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
setTaskDescription(ActivityManager.TaskDescription("KSUNEXT - $name"))
|
setTaskDescription(ActivityManager.TaskDescription("WebUI-Next | $name"))
|
||||||
} else {
|
} else {
|
||||||
val taskDescription = ActivityManager.TaskDescription.Builder().setLabel("KSUNEXT - $name").build()
|
val taskDescription = ActivityManager.TaskDescription.Builder().setLabel("WebUI-Next | $name").build()
|
||||||
setTaskDescription(taskDescription)
|
setTaskDescription(taskDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.rifsxd.ksunext.ui.webui
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.pm.ApplicationInfo
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
@@ -197,6 +198,73 @@ class WebViewInterface(
|
|||||||
}
|
}
|
||||||
return currentModuleInfo.toString()
|
return currentModuleInfo.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun listSystemPackages(): String {
|
||||||
|
val pm = context.packageManager
|
||||||
|
val packages = pm.getInstalledPackages(0)
|
||||||
|
val jsonArray = JSONArray()
|
||||||
|
for (pkg in packages) {
|
||||||
|
val appInfo = pkg.applicationInfo
|
||||||
|
if (appInfo != null && (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||||
|
jsonArray.put(pkg.packageName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return jsonArray.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun listUserPackages(): String {
|
||||||
|
val pm = context.packageManager
|
||||||
|
val packages = pm.getInstalledPackages(0)
|
||||||
|
val jsonArray = JSONArray()
|
||||||
|
for (pkg in packages) {
|
||||||
|
val appInfo = pkg.applicationInfo
|
||||||
|
if (appInfo != null && (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0) {
|
||||||
|
jsonArray.put(pkg.packageName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return jsonArray.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun listAllPackages(): String {
|
||||||
|
val pm = context.packageManager
|
||||||
|
val packages = pm.getInstalledPackages(0)
|
||||||
|
val jsonArray = JSONArray()
|
||||||
|
for (pkg in packages) {
|
||||||
|
jsonArray.put(pkg.packageName)
|
||||||
|
}
|
||||||
|
return jsonArray.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun getPackagesInfo(packageNamesJson: String): String {
|
||||||
|
val pm = context.packageManager
|
||||||
|
val packageNames = JSONArray(packageNamesJson)
|
||||||
|
val jsonArray = JSONArray()
|
||||||
|
for (i in 0 until packageNames.length()) {
|
||||||
|
val pkgName = packageNames.getString(i)
|
||||||
|
try {
|
||||||
|
val pkg = pm.getPackageInfo(pkgName, 0)
|
||||||
|
val appInfo = pkg.applicationInfo
|
||||||
|
val obj = JSONObject()
|
||||||
|
obj.put("packageName", pkg.packageName)
|
||||||
|
obj.put("versionName", pkg.versionName ?: "")
|
||||||
|
obj.put("versionCode", pkg.longVersionCode)
|
||||||
|
obj.put("appLabel", if (appInfo != null) pm.getApplicationLabel(appInfo).toString() else "")
|
||||||
|
obj.put("isSystem", appInfo != null && (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0)
|
||||||
|
obj.put("uid", appInfo?.uid ?: JSONObject.NULL)
|
||||||
|
jsonArray.put(obj)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
val obj = JSONObject()
|
||||||
|
obj.put("packageName", pkgName)
|
||||||
|
obj.put("error", "Package not found or inaccessible")
|
||||||
|
jsonArray.put(obj)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return jsonArray.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hideSystemUI(window: Window) =
|
fun hideSystemUI(window: Window) =
|
||||||
|
|||||||
Reference in New Issue
Block a user