diff options
author | Julia Reynolds <juliacr@google.com> | 2014-05-20 22:19:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-20 22:19:02 +0000 |
commit | 37f4e44ae614987c5ed953a1829c7181bb775e1f (patch) | |
tree | a7a9e720a5a374029e8d06f10662dfd0afdbe021 /services/devicepolicy | |
parent | 4d40452154a3a9cf04abaa8451792c85ade2ad6f (diff) | |
parent | 966881e8951f9bb297689745dcaecfdc13432656 (diff) | |
download | frameworks_base-37f4e44ae614987c5ed953a1829c7181bb775e1f.zip frameworks_base-37f4e44ae614987c5ed953a1829c7181bb775e1f.tar.gz frameworks_base-37f4e44ae614987c5ed953a1829c7181bb775e1f.tar.bz2 |
Merge "Add Device/Profile Owner gated apis for setting/getting blocked packages."
Diffstat (limited to 'services/devicepolicy')
-rw-r--r-- | services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | 87 |
1 files changed, 87 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 773ccb3..bc7742f 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -3384,6 +3384,93 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } @Override + public boolean setApplicationBlocked(ComponentName who, String packageName, + boolean blocked) { + int callingUserId = UserHandle.getCallingUserId(); + synchronized (this) { + if (who == null) { + throw new NullPointerException("ComponentName is null"); + } + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); + + long id = Binder.clearCallingIdentity(); + try { + IPackageManager pm = AppGlobals.getPackageManager(); + return pm.setApplicationBlockedSettingAsUser(packageName, blocked, callingUserId); + } catch (RemoteException re) { + // shouldn't happen + Slog.e(LOG_TAG, "Failed to setApplicationBlockedSetting", re); + } finally { + restoreCallingIdentity(id); + } + return false; + } + } + + @Override + public int setApplicationsBlocked(ComponentName who, Intent intent, boolean blocked) { + int callingUserId = UserHandle.getCallingUserId(); + synchronized (this) { + if (who == null) { + throw new NullPointerException("ComponentName is null"); + } + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); + + long id = Binder.clearCallingIdentity(); + try { + IPackageManager pm = AppGlobals.getPackageManager(); + List<ResolveInfo> activitiesToEnable = pm.queryIntentActivities(intent, + intent.resolveTypeIfNeeded(mContext.getContentResolver()), + PackageManager.GET_DISABLED_COMPONENTS + | PackageManager.GET_UNINSTALLED_PACKAGES, + callingUserId); + + if (DBG) Slog.d(LOG_TAG, "Enabling activities: " + activitiesToEnable); + int numberOfAppsUnblocked = 0; + if (activitiesToEnable != null) { + for (ResolveInfo info : activitiesToEnable) { + if (info.activityInfo != null) { + numberOfAppsUnblocked++; + pm.setApplicationBlockedSettingAsUser(info.activityInfo.packageName, + blocked, callingUserId); + } + } + } + return numberOfAppsUnblocked; + } catch (RemoteException re) { + // shouldn't happen + Slog.e(LOG_TAG, "Failed to setApplicationsBlockedSettingsWithIntent", re); + } finally { + restoreCallingIdentity(id); + } + return 0; + } + } + + @Override + public boolean isApplicationBlocked(ComponentName who, String packageName) { + int callingUserId = UserHandle.getCallingUserId(); + synchronized (this) { + if (who == null) { + throw new NullPointerException("ComponentName is null"); + } + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); + + long id = Binder.clearCallingIdentity(); + try { + IPackageManager pm = AppGlobals.getPackageManager(); + return pm.getApplicationBlockedSettingAsUser(packageName, callingUserId); + } catch (RemoteException re) { + // shouldn't happen + Slog.e(LOG_TAG, "Failed to getApplicationBlockedSettingAsUser", re); + } finally { + restoreCallingIdentity(id); + } + return false; + } + } + + @Override public void enableSystemApp(ComponentName who, String packageName) { synchronized (this) { if (who == null) { |