From 779cf4a3b66e9a5ce613148a16cf6f477387dbfa Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Mon, 30 Mar 2026 13:47:03 +0200 Subject: [PATCH] Fix flag wrapping for getInstalledPackagesReflect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to the Java Language Specification (JLS ยง15.25.2)[https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.25.2]: > If one of the second and third operands is of primitive type $T$, and the type of the other is the result of applying binary numeric promotion to $T$, then the type of the conditional expression is that promoted type. This fixes the bug introduced in #603. --- .../org/lsposed/lspd/service/PackageService.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java b/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java index 8c7a07a1d..eceaa0746 100644 --- a/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java +++ b/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java @@ -103,11 +103,17 @@ public class PackageService { getInstalledPackagesMethod = method; } - private static List getInstalledPackagesReflect(IPackageManager pm, Object flags, int userId) { + private static List getInstalledPackagesReflect(IPackageManager pm, int flags, int userId) { if (getInstalledPackagesMethod == null || pm == null) return Collections.emptyList(); try { - Object result = getInstalledPackagesMethod.invoke(pm, flags, userId); + Object flagsObj; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + flagsObj = (long) flags; + } else { + flagsObj = (int) flags; + } + Object result = getInstalledPackagesMethod.invoke(pm, flagsObj, userId); if (result instanceof ParceledListSlice) { // noinspection unchecked return ((ParceledListSlice) result).getList(); @@ -184,13 +190,11 @@ public static ParcelableListSlice getInstalledPackagesFromAllUsers( throws RemoteException { List res = new ArrayList<>(); IPackageManager pm = getPackageManager(); - if (pm == null) - return ParcelableListSlice.emptyList(); + if (pm == null) return ParcelableListSlice.emptyList(); // Prepare flags once outside the loop - Object flagsObj = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) ? (long) flags : flags; for (var user : UserService.getUsers()) { // Use the reflective helper instead of direct AIDL calls - List infos = getInstalledPackagesReflect(pm, flagsObj, user.id); + List infos = getInstalledPackagesReflect(pm, flags, user.id); res.addAll(infos.parallelStream() .filter(info -> info.applicationInfo != null && info.applicationInfo.uid / PER_USER_RANGE == user.id)