Fix NPE in PackageManagerInternal.getPackagesForAppId().

The original code would cause NPE for ejected non-shared-user
packages, because List.of() requires the argument to be non-null and
throws an NPE otherwise.

In order to be consistent with the shared user case, we should return
empty list when the APK isn't available.

Bug: 263504888
Test: presubmit
Change-Id: Iefd80188a8dc6be5cd49b3b813aa809fd3489fff
This commit is contained in:
Hai Zhang
2023-05-03 21:43:45 -07:00
parent 02b7943a14
commit c46674d0ca

View File

@@ -5624,7 +5624,12 @@ public class ComputerEngine implements Computer {
return sus.getPackages();
} else if (settingBase instanceof PackageSetting) {
final PackageSetting ps = (PackageSetting) settingBase;
return List.of(ps.getPkg());
final AndroidPackage pkg = ps.getPkg();
if (pkg != null) {
return Collections.singletonList(pkg);
} else {
return Collections.emptyList();
}
} else {
return Collections.emptyList();
}