diff options
author | Robin Lee <rgl@google.com> | 2015-04-30 14:18:22 +0100 |
---|---|---|
committer | Robin Lee <rgl@google.com> | 2015-04-30 18:01:46 +0000 |
commit | ddd553f2aee4f3821a2f17636bb86d9fa5af9bd7 (patch) | |
tree | cc57bdb8984030c2a03ac4217b22b3e8311fa9e4 /services/devicepolicy/java/com/android | |
parent | fcda22b1fe33370922a53d6562aa15366818bd45 (diff) | |
download | frameworks_base-ddd553f2aee4f3821a2f17636bb86d9fa5af9bd7.zip frameworks_base-ddd553f2aee4f3821a2f17636bb86d9fa5af9bd7.tar.gz frameworks_base-ddd553f2aee4f3821a2f17636bb86d9fa5af9bd7.tar.bz2 |
Device policy: use owner label instead of name
Managed provisioning does not currently set a meaningful profile owner
name. This changes to use the application label as returned by
PackageManager.getApplicationLabel which should be more descriptive.
Bug: 20679292
Change-Id: I5a0e87ef05b62879a73814e6d338e8b984b81c94
Diffstat (limited to 'services/devicepolicy/java/com/android')
-rw-r--r-- | services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index f801d2d..c886c4c 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -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. @@ -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++) { @@ -4444,13 +4444,37 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { return null; } mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null); + ComponentName profileOwner = getProfileOwner(userHandle); + if (profileOwner == null) { + return null; + } + return getApplicationLabel(profileOwner.getPackageName(), userHandle); + } - synchronized (this) { - if (mDeviceOwner != null) { - return mDeviceOwner.getProfileOwnerName(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); } - return null; } /** |