Example usage for android.app.admin DevicePolicyManager isProvisioningAllowed

List of usage examples for android.app.admin DevicePolicyManager isProvisioningAllowed

Introduction

In this page you can find the example usage for android.app.admin DevicePolicyManager isProvisioningAllowed.

Prototype

public boolean isProvisioningAllowed(@NonNull String action) 

Source Link

Document

Returns whether it is possible for the caller to initiate provisioning of a managed profile or device, setting itself as the device or profile owner.

Usage

From source file:com.afwsamples.testdpc.common.ProvisioningStateUtil.java

/**
 * @param action Action to be checked//from w w  w .ja  va  2  s . c om
 * @param context Calling activity's context
 * @return true, if provisioning is allowed for corresponding action
 */
@TargetApi(Build.VERSION_CODES.N)
public static boolean isProvisioningAllowed(Context context, String action) {
    if (BuildCompat.isAtLeastN()) {
        DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        return dpm.isProvisioningAllowed(action);
    } else {
        if (ACTION_PROVISION_MANAGED_DEVICE.equals(action)) {
            return (Build.VERSION.SDK_INT == Build.VERSION_CODES.M)
                    ? isDeviceUnprovisionedAndNoDeviceOwner(context)
                    : false;
        }
        if (ACTION_PROVISION_MANAGED_PROFILE.equals(action)) {
            return true;
        }
        return false;
    }
}