diff options
Diffstat (limited to 'services/devicepolicy/java')
-rw-r--r-- | services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | 126 |
1 files changed, 126 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 35fdef9..5d88a57 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -3390,6 +3390,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) { @@ -3601,4 +3688,43 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } return false; } + + @Override + public void setGlobalSetting(ComponentName who, String setting, String value) { + final ContentResolver contentResolver = mContext.getContentResolver(); + + synchronized (this) { + if (who == null) { + throw new NullPointerException("ComponentName is null"); + } + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); + + long id = Binder.clearCallingIdentity(); + try { + Settings.Global.putString(contentResolver, setting, value); + } finally { + restoreCallingIdentity(id); + } + } + } + + @Override + public void setSecureSetting(ComponentName who, String setting, String value) { + int callingUserId = UserHandle.getCallingUserId(); + final ContentResolver contentResolver = mContext.getContentResolver(); + + synchronized (this) { + if (who == null) { + throw new NullPointerException("ComponentName is null"); + } + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); + + long id = Binder.clearCallingIdentity(); + try { + Settings.Secure.putStringForUser(contentResolver, setting, value, callingUserId); + } finally { + restoreCallingIdentity(id); + } + } + } } |