summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Antoan Angelov <arangelov@google.com> 2022-03-20 20:08:50 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-03-20 20:08:50 +0000
commita443dccaadda95690e47f7066ecaa132f73646d3 (patch)
treebc8fb2a4254b3e4dd00d90891276c54ad4b503f4
parent2dab094eea47eb1eb62f45d9c27358febbb7de07 (diff)
parent69bb632cb8b093129db0d0022bdb5f5b5747a921 (diff)
Merge "Add DevicePolicyManager#getPolicyManagedProfiles system api" into tm-dev
-rw-r--r--core/api/system-current.txt1
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java23
-rw-r--r--core/java/android/app/admin/IDevicePolicyManager.aidl2
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java6
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java18
5 files changed, 50 insertions, 0 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 94efd92539e0..0a748142d65e 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -1090,6 +1090,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();
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 6298a265ce1d..487674066815 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -15379,6 +15379,29 @@ public class DevicePolicyManager {
}
/**
+ * 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}.
*
* <p>Valid configs look like:
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 64241aa3312f..8a9ef4bf9e0e 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -563,4 +563,6 @@ interface IDevicePolicyManager {
ParcelableResource getString(String stringId);
boolean shouldAllowBypassingDevicePolicyManagementRoleQualification();
+
+ List<UserHandle> getPolicyManagedProfiles(in UserHandle userHandle);
}
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java b/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java
index edfd6ed5f63d..834f65fa9e97 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java
@@ -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();
+ }
}
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 1288587b049e..1052d1dead87 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -18837,4 +18837,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;
+ });
+ }
}