diff options
author | Sander Alewijnse <salewijnse@google.com> | 2014-02-24 10:16:26 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-02-24 10:16:28 +0000 |
commit | 627de95925b58e7602374a66ceba76200592ec11 (patch) | |
tree | 75706e01659c2bced546151dc6d41b0a1b0d0ce1 /services/devicepolicy | |
parent | 12b97f5d2b15194ed6673c9838b13c8312157709 (diff) | |
parent | f475ca33d9232785710aaa438f17915029dfa83b (diff) | |
download | frameworks_base-627de95925b58e7602374a66ceba76200592ec11.zip frameworks_base-627de95925b58e7602374a66ceba76200592ec11.tar.gz frameworks_base-627de95925b58e7602374a66ceba76200592ec11.tar.bz2 |
Merge "Enables a profile owner or device owner to set and clear default intent handler activities."
Diffstat (limited to 'services/devicepolicy')
-rw-r--r-- | services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index f9a5e5d..f186b2c 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -2965,4 +2965,66 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } } } + + private boolean isProfileOwner(String packageName, int userId) { + String profileOwnerPackage = getProfileOwner(userId); + // TODO: make public and connect with isProfileOwnerApp in DPM + return profileOwnerPackage != null && profileOwnerPackage.equals(packageName); + } + + public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter, + ComponentName activity) { + int callingUserId = UserHandle.getCallingUserId(); + Slog.d(LOG_TAG,"called by user " + callingUserId); + synchronized (this) { + ActiveAdmin aa = getActiveAdminUncheckedLocked(admin, callingUserId); + if (aa == null) { + throw new SecurityException("No active admin " + admin); + } else { + if (isProfileOwner(admin.getPackageName(), callingUserId) + || isDeviceOwner(admin.getPackageName())) { + IPackageManager pm = AppGlobals.getPackageManager(); + long id = Binder.clearCallingIdentity(); + try { + pm.addPersistentPreferredActivity(filter, activity, callingUserId); + } catch (RemoteException re) { + // Shouldn't happen + } finally { + restoreCallingIdentity(id); + } + } else { + throw new SecurityException("Admin " + admin + + "is not device owner or profile owner" ); + } + } + } + } + + public void clearPackagePersistentPreferredActivities(ComponentName admin, + String packageName) { + int callingUserId = UserHandle.getCallingUserId(); + Slog.d(LOG_TAG,"called by user " + callingUserId); + synchronized (this) { + ActiveAdmin aa = getActiveAdminUncheckedLocked(admin, callingUserId); + if (aa == null) { + throw new SecurityException("No active admin " + admin); + } else { + if (isProfileOwner(admin.getPackageName(), callingUserId) + || isDeviceOwner(admin.getPackageName())) { + IPackageManager pm = AppGlobals.getPackageManager(); + long id = Binder.clearCallingIdentity(); + try{ + pm.clearPackagePersistentPreferredActivities(packageName, callingUserId); + } catch (RemoteException re) { + // Shouldn't happen + } finally { + restoreCallingIdentity(id); + } + } else { + throw new SecurityException("Admin " + admin + + "is not device owner or profile owner" ); + } + } + } + } } |