Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cef1aed9 authored by Songchun Fan's avatar Songchun Fan
Browse files

[pm] fix a deadlock

Avoid calling into AppOpsService under PMS's lock.

FIXES: 332032058
Test: atest android.appenumeration.cts.CrossUserPackageVisibilityTests#testSetApplicationCategoryHint_cannotDetectStubPkg
Test: atest android.content.pm.cts.ApplicationInfoTest#setOwnAppCategory
Test: atest android.packageinstaller.install.cts.SessionTest#setAppCategory

Change-Id: I64b5ab2bb1f171f6fd61e2af4e16436ad8b88a91
parent 37ee1886
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -5753,17 +5753,22 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        @Override
        public void setApplicationCategoryHint(String packageName, int categoryHint,
                String callerPackageName) {
            final int callingUid = Binder.getCallingUid();
            final int userId = UserHandle.getCallingUserId();
            final FunctionalUtils.ThrowingBiFunction<PackageStateMutator.InitialState, Computer,
                    PackageStateMutator.Result> implementation = (initialState, computer) -> {
                if (computer.getInstantAppPackageName(Binder.getCallingUid()) != null) {
                if (computer.getInstantAppPackageName(callingUid) != null) {
                    throw new SecurityException(
                            "Instant applications don't have access to this method");
                }
                mInjector.getSystemService(AppOpsManager.class)
                        .checkPackage(Binder.getCallingUid(), callerPackageName);
                final int callerPackageUid = computer.getPackageUid(callerPackageName, 0, userId);
                if (callerPackageUid != callingUid) {
                    throw new SecurityException(
                            "Package " + callerPackageName + " does not belong to " + callingUid);
                }

                PackageStateInternal packageState = computer.getPackageStateForInstalledAndFiltered(
                        packageName, Binder.getCallingUid(), UserHandle.getCallingUserId());
                        packageName, callingUid, userId);
                if (packageState == null) {
                    throw new IllegalArgumentException("Unknown target package " + packageName);
                }