summaryrefslogtreecommitdiffstats
path: root/services/devicepolicy
diff options
context:
space:
mode:
authorJulia Reynolds <juliacr@google.com>2014-05-14 12:23:08 -0400
committerJulia Reynolds <juliacr@google.com>2014-05-20 17:59:58 -0400
commit966881e8951f9bb297689745dcaecfdc13432656 (patch)
treeeec01a15176dfa4015517291c673e964b2a15232 /services/devicepolicy
parent3fff22173c7010467ce9e134e89b367e311d122b (diff)
downloadframeworks_base-966881e8951f9bb297689745dcaecfdc13432656.zip
frameworks_base-966881e8951f9bb297689745dcaecfdc13432656.tar.gz
frameworks_base-966881e8951f9bb297689745dcaecfdc13432656.tar.bz2
Add Device/Profile Owner gated apis for setting/getting blocked packages.
DMAgent currently needs to live in /system/priv-app in order to (among other things) set and get blocked packages. These APIs will get us closer to being able to move DMAgent out of priv-app. Bug: 14945334 Change-Id: I108e2013c67409dca554acf78e3a710745900706
Diffstat (limited to 'services/devicepolicy')
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java87
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 e2cd4e2..a561fed 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) {