Annotation Nullable (#2394)

This commit is contained in:
Howard Wu 2023-02-24 11:31:27 +08:00 committed by GitHub
parent 3d11c2f0f7
commit 9b1907adfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 9 deletions

View File

@ -47,6 +47,7 @@ import android.util.Log;
import android.util.Pair; import android.util.Pair;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.lsposed.lspd.models.Application; import org.lsposed.lspd.models.Application;
@ -105,6 +106,7 @@ public class PackageService {
return pm; return pm;
} }
@Nullable
public static PackageInfo getPackageInfo(String packageName, int flags, int userId) throws RemoteException { public static PackageInfo getPackageInfo(String packageName, int flags, int userId) throws RemoteException {
IPackageManager pm = getPackageManager(); IPackageManager pm = getPackageManager();
if (pm == null) return null; if (pm == null) return null;
@ -126,6 +128,7 @@ public class PackageService {
return res; return res;
} }
@Nullable
public static ApplicationInfo getApplicationInfo(String packageName, int flags, int userId) throws RemoteException { public static ApplicationInfo getApplicationInfo(String packageName, int flags, int userId) throws RemoteException {
IPackageManager pm = getPackageManager(); IPackageManager pm = getPackageManager();
if (pm == null) return null; if (pm == null) return null;
@ -206,6 +209,7 @@ public class PackageService {
} }
@SuppressWarnings({"ConstantConditions", "SameParameterValue"}) @SuppressWarnings({"ConstantConditions", "SameParameterValue"})
@Nullable
private static PackageInfo getPackageInfoWithComponents(String packageName, int flags, int userId) throws RemoteException { private static PackageInfo getPackageInfoWithComponents(String packageName, int flags, int userId) throws RemoteException {
IPackageManager pm = getPackageManager(); IPackageManager pm = getPackageManager();
if (pm == null) return null; if (pm == null) return null;
@ -291,18 +295,25 @@ public class PackageService {
} }
} }
public static ParcelableListSlice<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) throws RemoteException { @Nullable
IPackageManager pm = getPackageManager(); public static ParcelableListSlice<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) {
if (pm == null) return null; try {
ParceledListSlice<ResolveInfo> infos; IPackageManager pm = getPackageManager();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (pm == null) return null;
infos = pm.queryIntentActivities(intent, resolvedType, (long) flags, userId); ParceledListSlice<ResolveInfo> infos;
} else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
infos = pm.queryIntentActivities(intent, resolvedType, flags, userId); 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 { public static Intent getLaunchIntentForPackage(String packageName) throws RemoteException {
Intent intentToResolve = new Intent(Intent.ACTION_MAIN); Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_INFO); intentToResolve.addCategory(Intent.CATEGORY_INFO);