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

Commit fecb2620 authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Failing setPackagesSuspended if user has a DO / PO" into pi-dev...

Merge "Merge "Failing setPackagesSuspended if user has a DO / PO" into pi-dev am: 694f6000" into pi-dev-plus-aosp
parents 99ebce82 1516fa8a
Loading
Loading
Loading
Loading
+12 −18
Original line number Diff line number Diff line
@@ -13636,24 +13636,14 @@ public class PackageManagerService extends IPackageManager.Stub
            // install reason correctly.
            return installReason;
        }
        final IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface(
            ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
        if (dpm != null) {
            ComponentName owner = null;
            try {
                owner = dpm.getDeviceOwnerComponent(true /* callingUserOnly */);
                if (owner == null) {
                    owner = dpm.getProfileOwner(UserHandle.getUserId(installerUid));
                }
            } catch (RemoteException e) {
            }
            if (owner != null && owner.getPackageName().equals(installerPackageName)) {
        final String ownerPackage = mProtectedPackages.getDeviceOwnerOrProfileOwnerPackage(
                UserHandle.getUserId(installerUid));
        if (ownerPackage != null && ownerPackage.equals(installerPackageName)) {
            // If the install is being performed by a device or profile owner, the install
            // reason should be enterprise policy.
            return PackageManager.INSTALL_REASON_POLICY;
        }
        }
        if (installReason == PackageManager.INSTALL_REASON_POLICY) {
            // If the install is being performed by a regular app (i.e. neither system app nor
@@ -14051,7 +14041,11 @@ public class PackageManagerService extends IPackageManager.Stub
            throw new IllegalArgumentException("CallingPackage " + callingPackage + " does not"
                    + " belong to calling app id " + UserHandle.getAppId(callingUid));
        }
        if (!PLATFORM_PACKAGE_NAME.equals(callingPackage)
                && mProtectedPackages.getDeviceOwnerOrProfileOwnerPackage(userId) != null) {
            throw new UnsupportedOperationException("Cannot suspend/unsuspend packages. User "
                    + userId + " has an active DO or PO");
        }
        if (ArrayUtils.isEmpty(packageNames)) {
            return packageNames;
        }
+7 −0
Original line number Diff line number Diff line
@@ -88,6 +88,13 @@ public class ProtectedPackages {
        return false;
    }

    public synchronized String getDeviceOwnerOrProfileOwnerPackage(int userId) {
        if (mDeviceOwnerUserId == userId) {
            return mDeviceOwnerPackage;
        }
        return mProfileOwnerPackages.get(userId);
    }

    /**
     * Returns {@code true} if a given package is protected. Otherwise, returns {@code false}.
     *
+5 −2
Original line number Diff line number Diff line
@@ -73,6 +73,9 @@ import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker
import static com.android.server.devicepolicy.TransferOwnershipMetadataManager.ADMIN_TYPE_DEVICE_OWNER;
import static com.android.server.devicepolicy.TransferOwnershipMetadataManager.ADMIN_TYPE_PROFILE_OWNER;
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
import static org.xmlpull.v1.XmlPullParser.END_TAG;
import static org.xmlpull.v1.XmlPullParser.TEXT;
@@ -9193,8 +9196,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            long id = mInjector.binderClearCallingIdentity();
            try {
                return mIPackageManager.setPackagesSuspendedAsUser(
                        packageNames, suspended, null, null, null, "android", callingUserId);
                return mIPackageManager.setPackagesSuspendedAsUser(packageNames, suspended,
                        null, null, null, PLATFORM_PACKAGE_NAME, callingUserId);
            } catch (RemoteException re) {
                // Shouldn't happen.
                Slog.e(LOG_TAG, "Failed talking to the package manager", re);