From 9b1907adfcf139a6339e81c507227a08fc7f74cb Mon Sep 17 00:00:00 2001 From: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Fri, 24 Feb 2023 11:31:27 +0800 Subject: [PATCH] Annotation Nullable (#2394) --- .../lsposed/lspd/service/PackageService.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 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 e04601e2..a0a35670 100644 --- a/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java +++ b/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java @@ -47,6 +47,7 @@ import android.util.Log; import android.util.Pair; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.lsposed.lspd.models.Application; @@ -105,6 +106,7 @@ public class PackageService { return pm; } + @Nullable public static PackageInfo getPackageInfo(String packageName, int flags, int userId) throws RemoteException { IPackageManager pm = getPackageManager(); if (pm == null) return null; @@ -126,6 +128,7 @@ public class PackageService { return res; } + @Nullable public static ApplicationInfo getApplicationInfo(String packageName, int flags, int userId) throws RemoteException { IPackageManager pm = getPackageManager(); if (pm == null) return null; @@ -206,6 +209,7 @@ public class PackageService { } @SuppressWarnings({"ConstantConditions", "SameParameterValue"}) + @Nullable private static PackageInfo getPackageInfoWithComponents(String packageName, int flags, int userId) throws RemoteException { IPackageManager pm = getPackageManager(); if (pm == null) return null; @@ -291,18 +295,25 @@ public class PackageService { } } - public static ParcelableListSlice queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) throws RemoteException { - IPackageManager pm = getPackageManager(); - if (pm == null) return null; - ParceledListSlice infos; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - infos = pm.queryIntentActivities(intent, resolvedType, (long) flags, userId); - } else { - infos = pm.queryIntentActivities(intent, resolvedType, flags, userId); + @Nullable + public static ParcelableListSlice queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) { + try { + IPackageManager pm = getPackageManager(); + if (pm == null) return null; + ParceledListSlice infos; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + infos = pm.queryIntentActivities(intent, resolvedType, (long) flags, userId); + } else { + infos = pm.queryIntentActivities(intent, resolvedType, flags, userId); + } + return new ParcelableListSlice<>(infos.getList()); + } catch (Exception e) { + Log.e(TAG, "queryIntentActivities", e); + return new ParcelableListSlice<>(new ArrayList<>()); } - return new ParcelableListSlice<>(infos.getList()); } + @Nullable public static Intent getLaunchIntentForPackage(String packageName) throws RemoteException { Intent intentToResolve = new Intent(Intent.ACTION_MAIN); intentToResolve.addCategory(Intent.CATEGORY_INFO);