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

Commit 69bb632c authored by arangelov's avatar arangelov
Browse files

Add DevicePolicyManager#getPolicyManagedProfiles system api

That way the logic to get a managed profile can be
customizable by OEMs.

Fixes: 214473624
Test: manual
Test: CTS tests to be added in a follow-up CL
Change-Id: Id183e987d2cb04040db028b9913188267d1a9a84
parent 7940baa7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1088,6 +1088,7 @@ package android.app.admin {
    method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public android.os.UserHandle getDeviceOwnerUser();
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_ADMIN_POLICY}) public java.util.List<java.lang.String> getPermittedAccessibilityServices(int);
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_ADMIN_POLICY}) public java.util.List<java.lang.String> getPermittedInputMethodsForCurrentUser();
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public java.util.List<android.os.UserHandle> getPolicyManagedProfiles(@NonNull android.os.UserHandle);
    method @Nullable public android.content.ComponentName getProfileOwner() throws java.lang.IllegalArgumentException;
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS}) public String getProfileOwnerNameAsUser(int) throws java.lang.IllegalArgumentException;
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS}) public int getUserProvisioningState();
+23 −0
Original line number Diff line number Diff line
@@ -15841,6 +15841,29 @@ public class DevicePolicyManager {
        return devicePolicyManagementUpdaterConfig;
    }
    /**
     * Returns a {@link List} of managed profiles managed by some profile owner within the profile
     * group of the given user, or an empty {@link List} if there is not one.
     *
     * @param user the user whose profile group to look within to return managed profiles
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
    @NonNull
    public List<UserHandle> getPolicyManagedProfiles(@NonNull UserHandle user) {
        Objects.requireNonNull(user);
        if (mService != null) {
            try {
                return mService.getPolicyManagedProfiles(user);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return Collections.emptyList();
    }
    /**
     * Retrieves the package name for a given {@code deviceManagerConfig}.
     *
+2 −0
Original line number Diff line number Diff line
@@ -563,4 +563,6 @@ interface IDevicePolicyManager {
    ParcelableResource getString(String stringId);

    boolean shouldAllowBypassingDevicePolicyManagementRoleQualification();

    List<UserHandle> getPolicyManagedProfiles(in UserHandle userHandle);
}
+6 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.util.Slog;

import com.android.server.SystemService;

import java.util.Collections;
import java.util.List;

/**
@@ -200,4 +201,9 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {
    public boolean shouldAllowBypassingDevicePolicyManagementRoleQualification() {
        return false;
    }

    @Override
    public List<UserHandle> getPolicyManagedProfiles(UserHandle userHandle) {
        return Collections.emptyList();
    }
}
+18 −0
Original line number Diff line number Diff line
@@ -18830,4 +18830,22 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            return accounts.length == 0;
        });
    }
    @Override
    public List<UserHandle> getPolicyManagedProfiles(@NonNull UserHandle user) {
        Preconditions.checkCallAuthorization(hasCallingOrSelfPermission(
                android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS));
        int userId = user.getIdentifier();
        return mInjector.binderWithCleanCallingIdentity(() -> {
            List<UserInfo> userProfiles = mUserManager.getProfiles(userId);
            List<UserHandle> result = new ArrayList<>();
            for (int i = 0; i < userProfiles.size(); i++) {
                if (userProfiles.get(i).isManagedProfile() && hasProfileOwner(userId)) {
                    result.add(new UserHandle(userProfiles.get(i).id));
                }
            }
            return result;
        });
    }
}