Skip to content

Commit 4b8f069

Browse files
authored
Fix flag wrapping for getInstalledPackagesReflect (#613)
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): > Otherwise, binary numeric promotion (§5.6.2) is applied to the operand types, and the type of the conditional expression is the promoted type of the second and third operands. This commit fixes a bug introduced in #603.
1 parent 4cfca56 commit 4b8f069

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

daemon/src/main/java/org/lsposed/lspd/service/PackageService.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,17 @@ public class PackageService {
103103
getInstalledPackagesMethod = method;
104104
}
105105

106-
private static List<PackageInfo> getInstalledPackagesReflect(IPackageManager pm, Object flags, int userId) {
106+
private static List<PackageInfo> getInstalledPackagesReflect(IPackageManager pm, int flags, int userId) {
107107
if (getInstalledPackagesMethod == null || pm == null)
108108
return Collections.emptyList();
109109
try {
110-
Object result = getInstalledPackagesMethod.invoke(pm, flags, userId);
110+
Object flagsObj;
111+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
112+
flagsObj = (long) flags;
113+
} else {
114+
flagsObj = (int) flags;
115+
}
116+
Object result = getInstalledPackagesMethod.invoke(pm, flagsObj, userId);
111117
if (result instanceof ParceledListSlice) {
112118
// noinspection unchecked
113119
return ((ParceledListSlice<PackageInfo>) result).getList();
@@ -184,13 +190,11 @@ public static ParcelableListSlice<PackageInfo> getInstalledPackagesFromAllUsers(
184190
throws RemoteException {
185191
List<PackageInfo> res = new ArrayList<>();
186192
IPackageManager pm = getPackageManager();
187-
if (pm == null)
188-
return ParcelableListSlice.emptyList();
193+
if (pm == null) return ParcelableListSlice.emptyList();
189194
// Prepare flags once outside the loop
190-
Object flagsObj = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) ? (long) flags : flags;
191195
for (var user : UserService.getUsers()) {
192196
// Use the reflective helper instead of direct AIDL calls
193-
List<PackageInfo> infos = getInstalledPackagesReflect(pm, flagsObj, user.id);
197+
List<PackageInfo> infos = getInstalledPackagesReflect(pm, flags, user.id);
194198
res.addAll(infos.parallelStream()
195199
.filter(info -> info.applicationInfo != null
196200
&& info.applicationInfo.uid / PER_USER_RANGE == user.id)

0 commit comments

Comments
 (0)