Java Code Examples for android.app.admin.DevicePolicyManager#setApplicationRestrictions()

The following examples show how to use android.app.admin.DevicePolicyManager#setApplicationRestrictions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the persistent device owner state by setting a special app restriction on GmsCore and
 * notifies GmsCore about the change by sending a broadcast.
 *
 * @param state The device owner state to be preserved across factory resets. If null, the
 * persistent device owner state and the corresponding restiction are cleared.
 */
@TargetApi(VERSION_CODES.O)
public static void setPersistentDoStateWithApplicationRestriction(
        Context context, DevicePolicyManager dpm, ComponentName admin, String state) {
    Bundle restrictions = dpm.getApplicationRestrictions(admin, GMSCORE_PACKAGE);
    if (state == null) {
        // Clear the restriction
        restrictions.remove(PERSISTENT_DEVICE_OWNER_STATE);
    } else {
        // Set the restriction
        restrictions.putString(PERSISTENT_DEVICE_OWNER_STATE, state);
    }
    dpm.setApplicationRestrictions(admin, GMSCORE_PACKAGE, restrictions);
    Intent broadcastIntent = new Intent(BROADCAST_ACTION_FRP_CONFIG_CHANGED);
    broadcastIntent.setPackage(GMSCORE_PACKAGE);
    broadcastIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    context.sendBroadcast(broadcastIntent);
}
 
Example 2
Source File: AppRestrictionEnforcerFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Saves all the restrictions.
 *
 * @param activity The activity.
 */
private void saveRestrictions(Activity activity) {
    DevicePolicyManager devicePolicyManager
            = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    devicePolicyManager.setApplicationRestrictions(
            EnforcerDeviceAdminReceiver.getComponentName(activity),
            Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, mCurrentRestrictions);
}
 
Example 3
Source File: BasicManagedProfileFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Clears restrictions to Chrome
 */
private void clearChromeRestrictions() {
    final Activity activity = getActivity();
    if (null == activity) {
        return;
    }
    final DevicePolicyManager manager =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    // In order to clear restrictions, pass null as the restriction Bundle for
    // setApplicationRestrictions
    manager.setApplicationRestrictions
            (BasicDeviceAdminReceiver.getComponentName(activity),
                    PACKAGE_NAME_CHROME, null);
    Toast.makeText(activity, R.string.cleared, Toast.LENGTH_SHORT).show();
}
 
Example 4
Source File: AppRestrictionsProxyHandler.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
private void setApplicationRestrictions(String packageName, Bundle appRestrictions){
    if (packageName == null) {
        throw new IllegalArgumentException("packageName cannot be null.");
    }
    if (appRestrictions == null) {
        throw new IllegalArgumentException("applicationRestrictions bundle " +
                "cannot be null.");
    }
    Log.d(TAG, "Setting application restrictions for package " + packageName);
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager)
            mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
    devicePolicyManager.setApplicationRestrictions(mAdmin, packageName,
            appRestrictions);
}
 
Example 5
Source File: AppRestrictionEnforcerFragment.java    From android-AppRestrictionEnforcer with Apache License 2.0 5 votes vote down vote up
/**
 * Saves all the restrictions.
 *
 * @param activity The activity.
 */
private void saveRestrictions(Activity activity) {
    DevicePolicyManager devicePolicyManager
            = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    devicePolicyManager.setApplicationRestrictions(
            EnforcerDeviceAdminReceiver.getComponentName(activity),
            Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, mCurrentRestrictions);
}
 
Example 6
Source File: BasicManagedProfileFragment.java    From android-BasicManagedProfile with Apache License 2.0 5 votes vote down vote up
/**
 * Clears restrictions to Chrome
 */
private void clearChromeRestrictions() {
    final Activity activity = getActivity();
    if (null == activity) {
        return;
    }
    final DevicePolicyManager manager =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    // In order to clear restrictions, pass null as the restriction Bundle for
    // setApplicationRestrictions
    manager.setApplicationRestrictions
            (BasicDeviceAdminReceiver.getComponentName(activity),
                    PACKAGE_NAME_CHROME, null);
    Toast.makeText(activity, R.string.cleared, Toast.LENGTH_SHORT).show();
}