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

Commit e014b9ef authored by Lenka Trochtova's avatar Lenka Trochtova Committed by Android (Google) Code Review
Browse files

Merge "Let the profile owner set lock-to-apps if the user is affiliated." into nyc-dev

parents 0c4ad623 a7c85ade
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -7513,7 +7513,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    /**
     * Sets which packages may enter lock task mode.
     *
     * This function can only be called by the device owner.
     * <p>This function can only be called by the device owner or alternatively by the profile owner
     * in case the user is affiliated.
     *
     * @param packages The list of packages allowed to enter lock task mode.
     */
    @Override
@@ -7521,10 +7523,17 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            throws SecurityException {
        Preconditions.checkNotNull(who, "ComponentName is null");
        synchronized (this) {
            getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);

            int userHandle = mInjector.binderGetCallingUserHandle().getIdentifier();
            ActiveAdmin deviceOwner = getActiveAdminWithPolicyForUidLocked(
                who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER, mInjector.binderGetCallingUid());
            ActiveAdmin profileOwner = getActiveAdminWithPolicyForUidLocked(
                who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER, mInjector.binderGetCallingUid());
            if (deviceOwner != null || (profileOwner != null && isAffiliatedUser())) {
                int userHandle = mInjector.userHandleGetCallingUserId();
                setLockTaskPackagesLocked(userHandle, new ArrayList<>(Arrays.asList(packages)));
            } else {
                throw new SecurityException("Admin " + who +
                    " is neither the device owner or affiliated user's profile owner.");
            }
        }
    }