summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java40
-rw-r--r--core/java/android/app/admin/IDevicePolicyManager.aidl1
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java20
3 files changed, 61 insertions, 0 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 4c70c914ff21..3df11f6f5691 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -81,6 +81,9 @@ import android.app.Activity;
import android.app.IServiceConnection;
import android.app.KeyguardManager;
import android.app.admin.SecurityLog.SecurityEvent;
+import android.app.compat.CompatChanges;
+import android.compat.annotation.ChangeId;
+import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.Context;
@@ -9118,6 +9121,19 @@ public class DevicePolicyManager {
}
/**
+ * For apps targeting {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} and above, the
+ * {@link #isDeviceOwnerApp} method will use the user contained within the
+ * context.
+ * For apps targeting an SDK version <em>below</em> this, the user of the calling process will
+ * be used (Process.myUserHandle()).
+ *
+ * @hide
+ */
+ @ChangeId
+ @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
+ public static final long IS_DEVICE_OWNER_USER_AWARE = 307233716L;
+
+ /**
* Used to determine if a particular package has been registered as a Device Owner app.
* A device owner app is a special device admin that cannot be deactivated by the user, once
* activated as a device admin. It also cannot be uninstalled. To check whether a particular
@@ -9130,8 +9146,13 @@ public class DevicePolicyManager {
* app, if any.
* @return whether or not the package is registered as the device owner app.
*/
+ @UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
public boolean isDeviceOwnerApp(String packageName) {
throwIfParentInstance("isDeviceOwnerApp");
+ if (android.permission.flags.Flags.roleControllerInSystemServer()
+ && CompatChanges.isChangeEnabled(IS_DEVICE_OWNER_USER_AWARE)) {
+ return isDeviceOwnerAppOnContextUser(packageName);
+ }
return isDeviceOwnerAppOnCallingUser(packageName);
}
@@ -9192,6 +9213,24 @@ public class DevicePolicyManager {
return packageName.equals(deviceOwner.getPackageName());
}
+ private boolean isDeviceOwnerAppOnContextUser(String packageName) {
+ if (packageName == null) {
+ return false;
+ }
+ ComponentName deviceOwner = null;
+ if (mService != null) {
+ try {
+ deviceOwner = mService.getDeviceOwnerComponentOnUser(myUserId());
+ } catch (RemoteException re) {
+ throw re.rethrowFromSystemServer();
+ }
+ }
+ if (deviceOwner == null) {
+ return false;
+ }
+ return packageName.equals(deviceOwner.getPackageName());
+ }
+
private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
if (mService != null) {
try {
@@ -9608,6 +9647,7 @@ public class DevicePolicyManager {
* @param packageName The package name of the app to compare with the registered profile owner.
* @return Whether or not the package is registered as the profile owner.
*/
+ @UserHandleAware
public boolean isProfileOwnerApp(String packageName) {
throwIfParentInstance("isProfileOwnerApp");
if (mService != null) {
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 6fe40be041cc..575fa4cac0b8 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -179,6 +179,7 @@ interface IDevicePolicyManager {
boolean setDeviceOwner(in ComponentName who, int userId, boolean setProfileOwnerOnCurrentUserIfNecessary);
ComponentName getDeviceOwnerComponent(boolean callingUserOnly);
+ ComponentName getDeviceOwnerComponentOnUser(int userId);
boolean hasDeviceOwner();
String getDeviceOwnerName();
void clearDeviceOwner(String packageName);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 34d67551d49f..9b62a2c41655 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -9667,6 +9667,26 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
}
+ @Override
+ public ComponentName getDeviceOwnerComponentOnUser(int userId) {
+ if (!mHasFeature) {
+ return null;
+ }
+ if (mInjector.userHandleGetCallingUserId() != userId) {
+ Preconditions.checkCallAuthorization(canManageUsers(getCallerIdentity())
+ || hasCallingOrSelfPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS));
+ }
+ synchronized (getLockObject()) {
+ // There is only ever one device owner on a device so if the passed userId is the same
+ // as the device owner userId we know that the componentName returned by
+ // getDeviceOwnerComponent will be the correct one.
+ if (mOwners.getDeviceOwnerUserId() == userId || userId == UserHandle.USER_ALL) {
+ return mOwners.getDeviceOwnerComponent();
+ }
+ }
+ return null;
+ }
+
private int getDeviceOwnerUserIdUncheckedLocked() {
return mOwners.hasDeviceOwner() ? mOwners.getDeviceOwnerUserId() : UserHandle.USER_NULL;
}