summaryrefslogtreecommitdiffstats
path: root/services/devicepolicy
diff options
context:
space:
mode:
authorSander Alewijnse <salewijnse@google.com>2014-02-17 15:13:58 +0000
committerSander Alewijnse <salewijnse@google.com>2014-02-21 15:24:20 +0000
commitf475ca33d9232785710aaa438f17915029dfa83b (patch)
treeca3ac28738e66281dc97546a9132a45cca69bc8f /services/devicepolicy
parentc4f6c351e18380e712d5d365d2a13cfa5674daf7 (diff)
downloadframeworks_base-f475ca33d9232785710aaa438f17915029dfa83b.zip
frameworks_base-f475ca33d9232785710aaa438f17915029dfa83b.tar.gz
frameworks_base-f475ca33d9232785710aaa438f17915029dfa83b.tar.bz2
Enables a profile owner or device owner to set and clear default intent handler activities.
Those intent handlers are persistent preferences. They will remain the default intent handler even if the set of potential event handlers for the intent filter changes and if the intent preferences are reset. Change-Id: Id0cfae46f93c10d89e441f272096a205ec518dd0
Diffstat (limited to 'services/devicepolicy')
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java62
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 12f0114..92ed75b 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -2966,4 +2966,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" );
+ }
+ }
+ }
+ }
}