Skip to content

Commit f51f82b

Browse files
committed
Updates
1 parent db633ba commit f51f82b

File tree

2 files changed

+62
-32
lines changed

2 files changed

+62
-32
lines changed

android/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ dependencies {
9595
implementation("dev.rikka.shizuku:api:13.1.5")
9696
implementation("dev.rikka.shizuku:provider:13.1.5")
9797
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
98-
implementation("org.lsposed.hiddenapibypass:hiddenapibypass:4.3")
98+
implementation("org.lsposed.hiddenapibypass:hiddenapibypass:6.1")
9999
}
100100

101101
val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86_64" to 4)

android/app/src/main/kotlin/me/biplobsd/rsm/ShellService.kt

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,48 +88,78 @@ class ShellService : IShellService.Stub {
8888
return readFd
8989
}
9090

91+
fun getInstalledPackagesMethod(pm: Any): java.lang.reflect.Method {
92+
return try {
93+
pm.javaClass.getMethod(
94+
"getInstalledPackages",
95+
Long::class.javaPrimitiveType,
96+
Int::class.javaPrimitiveType
97+
)
98+
} catch (e: NoSuchMethodException) {
99+
pm.javaClass.getMethod(
100+
"getInstalledPackages",
101+
Int::class.javaPrimitiveType,
102+
Int::class.javaPrimitiveType
103+
)
104+
}
105+
}
106+
107+
fun getPackageInfoMethod(pm: Any): java.lang.reflect.Method {
108+
return try {
109+
pm.javaClass.getMethod(
110+
"getPackageInfo",
111+
String::class.java,
112+
Long::class.javaPrimitiveType,
113+
Int::class.javaPrimitiveType
114+
)
115+
} catch (e: NoSuchMethodException) {
116+
pm.javaClass.getMethod(
117+
"getPackageInfo",
118+
String::class.java,
119+
Int::class.javaPrimitiveType,
120+
Int::class.javaPrimitiveType
121+
)
122+
}
123+
}
124+
91125
override fun getInstalledApps(): List<AppInfoResult> {
92126
ensureInitialized()
93127
val pm = packageManager ?: throw Exception("PackageManager not available")
94-
val getInstalledPackagesMethod =
95-
pm.javaClass.getMethod(
96-
"getInstalledPackages",
97-
Long::class.javaPrimitiveType,
98-
Int::class.javaPrimitiveType
99-
)
100-
101-
val parceledListSlice = getInstalledPackagesMethod.invoke(pm, 0L, 0)
102-
val getListMethod = parceledListSlice!!.javaClass.getMethod("getList")
103-
@Suppress("UNCHECKED_CAST")
104-
val packages = getListMethod.invoke(parceledListSlice) as List<PackageInfo>
105-
106-
return packages.mapNotNull { packageInfo ->
107-
try {
108-
val appInfo = packageInfo.applicationInfo ?: return@mapNotNull null
109-
val isSystemApp = (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
110-
val label = AppUtils.getAppLabel(context, appInfo, packageInfo.packageName)
111-
AppInfoResult(packageInfo.packageName, label, null, isSystemApp)
112-
} catch (e: Exception) {
113-
null
128+
129+
return try {
130+
val method = getInstalledPackagesMethod(pm)
131+
val flags = if (method.parameterTypes[0] == Long::class.javaPrimitiveType) 0L else 0
132+
val parceledListSlice = method.invoke(pm, flags, 0) ?: return emptyList()
133+
134+
val getListMethod = parceledListSlice.javaClass.getMethod("getList")
135+
@Suppress("UNCHECKED_CAST")
136+
val packages = getListMethod.invoke(parceledListSlice) as? List<PackageInfo> ?: return emptyList()
137+
138+
packages.mapNotNull { packageInfo ->
139+
try {
140+
val appInfo = packageInfo.applicationInfo ?: return@mapNotNull null
141+
val isSystemApp = (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
142+
val label = AppUtils.getAppLabel(context, appInfo, packageInfo.packageName)
143+
AppInfoResult(packageInfo.packageName, label, null, isSystemApp)
144+
} catch (e: Exception) {
145+
e.printStackTrace()
146+
null
147+
}
114148
}
149+
} catch (e: Exception) {
150+
e.printStackTrace()
151+
emptyList()
115152
}
116153
}
117154

118155
override fun getAppInfo(packageName: String): AppInfoResult? {
119156
ensureInitialized()
120157
val pm = packageManager ?: return null
158+
121159
return try {
122-
val getPackageInfoMethod =
123-
pm.javaClass.getMethod(
124-
"getPackageInfo",
125-
String::class.java,
126-
Long::class.javaPrimitiveType,
127-
Int::class.javaPrimitiveType
128-
)
129-
130-
val packageInfo =
131-
getPackageInfoMethod.invoke(pm, packageName, 0L, 0) as? PackageInfo
132-
?: return null
160+
val method = getPackageInfoMethod(pm)
161+
val flags = if (method.parameterTypes[1] == Long::class.javaPrimitiveType) 0L else 0
162+
val packageInfo = method.invoke(pm, packageName, flags, 0) as? PackageInfo ?: return null
133163

134164
val appInfo = packageInfo.applicationInfo ?: return null
135165
val isSystemApp = (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0

0 commit comments

Comments
 (0)