[core] Fix NPE when getting package components (#228)

This commit is contained in:
LoveSy 2021-02-28 14:22:39 +08:00 committed by GitHub
parent 3537701778
commit 1182c9187d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -117,6 +117,7 @@ public class PackageService {
private static Set<String> fetchProcesses(PackageInfo pkgInfo) {
HashSet<String> processNames = new HashSet<>();
if (pkgInfo == null) return processNames;
for (ComponentInfo[] componentInfos : new ComponentInfo[][]{pkgInfo.activities, pkgInfo.receivers, pkgInfo.providers}) {
if (componentInfos == null) continue;
for (ComponentInfo componentInfo : componentInfos) {
@ -148,6 +149,7 @@ public class PackageService {
pkgInfo = pm.getPackageInfo(packageName, flags | PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS, userId);
} catch (Exception e) {
pkgInfo = pm.getPackageInfo(packageName, flags, userId);
if (pkgInfo == null) return null;
try {
pkgInfo.activities = pm.getPackageInfo(packageName, flags | PackageManager.GET_ACTIVITIES, userId).activities;
} catch (Exception ignored) {