Loading core/java/android/app/admin/DevicePolicyManager.java +3 −3 Original line number Diff line number Diff line Loading @@ -2926,7 +2926,7 @@ public class DevicePolicyManager { * the user has already been set up. */ @SystemApi public boolean setActiveProfileOwner(ComponentName admin, String ownerName) public boolean setActiveProfileOwner(ComponentName admin, @Deprecated String ownerName) throws IllegalArgumentException { if (mService != null) { try { Loading Loading @@ -2992,8 +2992,8 @@ public class DevicePolicyManager { * @throws IllegalArgumentException if admin is null, the package isn't installed, or the * preconditions mentioned are not met. */ public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle) throws IllegalArgumentException { public boolean setProfileOwner(ComponentName admin, @Deprecated String ownerName, int userHandle) throws IllegalArgumentException { if (admin == null) { throw new NullPointerException("admin cannot be null"); } Loading services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +32 −8 Original line number Diff line number Diff line Loading @@ -4065,11 +4065,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null); synchronized (this) { if (mDeviceOwner != null) { return mDeviceOwner.getDeviceOwnerName(); if (mDeviceOwner == null || !mDeviceOwner.hasDeviceOwner()) { return null; } String deviceOwnerPackage = mDeviceOwner.getDeviceOwnerPackageName(); return getApplicationLabel(deviceOwnerPackage, UserHandle.USER_OWNER); } return null; } // Returns the active device owner or null if there is no device owner. Loading Loading @@ -4426,7 +4427,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (profileOwner == null) { return null; } DevicePolicyData policy = getUserData(userHandle); final int n = policy.mAdminList.size(); for (int i = 0; i < n; i++) { Loading @@ -4444,14 +4444,38 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { return null; } mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null); synchronized (this) { if (mDeviceOwner != null) { return mDeviceOwner.getProfileOwnerName(userHandle); ComponentName profileOwner = getProfileOwner(userHandle); if (profileOwner == null) { return null; } return getApplicationLabel(profileOwner.getPackageName(), userHandle); } /** * Canonical name for a given package. */ private String getApplicationLabel(String packageName, int userHandle) { long token = Binder.clearCallingIdentity(); try { final Context userContext; try { UserHandle handle = new UserHandle(userHandle); userContext = mContext.createPackageContextAsUser(packageName, 0, handle); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(LOG_TAG, packageName + " is not installed for user " + userHandle, nnfe); return null; } ApplicationInfo appInfo = userContext.getApplicationInfo(); CharSequence result = null; if (appInfo != null) { PackageManager pm = userContext.getPackageManager(); result = pm.getApplicationLabel(appInfo); } return result != null ? result.toString() : null; } finally { Binder.restoreCallingIdentity(token); } } /** * The profile owner can only be set by adb or an app with the MANAGE_PROFILE_AND_DEVICE_OWNERS Loading Loading
core/java/android/app/admin/DevicePolicyManager.java +3 −3 Original line number Diff line number Diff line Loading @@ -2926,7 +2926,7 @@ public class DevicePolicyManager { * the user has already been set up. */ @SystemApi public boolean setActiveProfileOwner(ComponentName admin, String ownerName) public boolean setActiveProfileOwner(ComponentName admin, @Deprecated String ownerName) throws IllegalArgumentException { if (mService != null) { try { Loading Loading @@ -2992,8 +2992,8 @@ public class DevicePolicyManager { * @throws IllegalArgumentException if admin is null, the package isn't installed, or the * preconditions mentioned are not met. */ public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle) throws IllegalArgumentException { public boolean setProfileOwner(ComponentName admin, @Deprecated String ownerName, int userHandle) throws IllegalArgumentException { if (admin == null) { throw new NullPointerException("admin cannot be null"); } Loading
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +32 −8 Original line number Diff line number Diff line Loading @@ -4065,11 +4065,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null); synchronized (this) { if (mDeviceOwner != null) { return mDeviceOwner.getDeviceOwnerName(); if (mDeviceOwner == null || !mDeviceOwner.hasDeviceOwner()) { return null; } String deviceOwnerPackage = mDeviceOwner.getDeviceOwnerPackageName(); return getApplicationLabel(deviceOwnerPackage, UserHandle.USER_OWNER); } return null; } // Returns the active device owner or null if there is no device owner. Loading Loading @@ -4426,7 +4427,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (profileOwner == null) { return null; } DevicePolicyData policy = getUserData(userHandle); final int n = policy.mAdminList.size(); for (int i = 0; i < n; i++) { Loading @@ -4444,14 +4444,38 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { return null; } mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null); synchronized (this) { if (mDeviceOwner != null) { return mDeviceOwner.getProfileOwnerName(userHandle); ComponentName profileOwner = getProfileOwner(userHandle); if (profileOwner == null) { return null; } return getApplicationLabel(profileOwner.getPackageName(), userHandle); } /** * Canonical name for a given package. */ private String getApplicationLabel(String packageName, int userHandle) { long token = Binder.clearCallingIdentity(); try { final Context userContext; try { UserHandle handle = new UserHandle(userHandle); userContext = mContext.createPackageContextAsUser(packageName, 0, handle); } catch (PackageManager.NameNotFoundException nnfe) { Log.w(LOG_TAG, packageName + " is not installed for user " + userHandle, nnfe); return null; } ApplicationInfo appInfo = userContext.getApplicationInfo(); CharSequence result = null; if (appInfo != null) { PackageManager pm = userContext.getPackageManager(); result = pm.getApplicationLabel(appInfo); } return result != null ? result.toString() : null; } finally { Binder.restoreCallingIdentity(token); } } /** * The profile owner can only be set by adb or an app with the MANAGE_PROFILE_AND_DEVICE_OWNERS Loading