Catch NameNotFoundException during onPackageModified

Fix: 249249607

Test: build & CTS
Change-Id: Ic5e241513ce0a45fa204c9bea3c1f79f3e3e93f7
This commit is contained in:
Guojing Yuan
2022-09-30 18:20:16 +00:00
parent 7333207b1b
commit 6061bdb2ea
2 changed files with 13 additions and 3 deletions

View File

@@ -1152,6 +1152,9 @@ public class CompanionDeviceManagerService extends SystemService {
}
private void updateSpecialAccessPermissionAsSystem(PackageInfo packageInfo) {
if (packageInfo == null) {
return;
}
if (containsEither(packageInfo.requestedPermissions,
android.Manifest.permission.RUN_IN_BACKGROUND,
android.Manifest.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND)) {

View File

@@ -54,12 +54,19 @@ final class PackageUtils {
private static final String PROPERTY_PRIMARY_TAG =
"android.companion.PROPERTY_PRIMARY_COMPANION_DEVICE_SERVICE";
static @Nullable PackageInfo getPackageInfo(@NonNull Context context,
@Nullable
static PackageInfo getPackageInfo(@NonNull Context context,
@UserIdInt int userId, @NonNull String packageName) {
final PackageManager pm = context.getPackageManager();
final PackageInfoFlags flags = PackageInfoFlags.of(GET_PERMISSIONS | GET_CONFIGURATIONS);
return Binder.withCleanCallingIdentity(() ->
pm.getPackageInfoAsUser(packageName, flags , userId));
return Binder.withCleanCallingIdentity(() -> {
try {
return pm.getPackageInfoAsUser(packageName, flags, userId);
} catch (PackageManager.NameNotFoundException e) {
Slog.e(TAG, "Package [" + packageName + "] is not found.");
return null;
}
});
}
static void enforceUsesCompanionDeviceFeature(@NonNull Context context,