Example usage for android.app.admin DevicePolicyManager isManagedProfile

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

Introduction

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

Prototype

public boolean isManagedProfile(@NonNull ComponentName admin) 

Source Link

Document

Return if this user is a managed profile of another user.

Usage

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

/**
 * Return {@code true} iff we are the profile owner of a managed profile.
 * Note that profile owner can be in primary user and secondary user too.
 *///w  ww  .ja  v a2s .  co m
@TargetApi(VERSION_CODES.N)
public static boolean isManagedProfileOwner(Context context) {
    final DevicePolicyManager dpm = getDevicePolicyManager(context);

    if (BuildCompat.isAtLeastN()) {
        try {
            return dpm.isManagedProfile(DeviceAdminReceiver.getComponentName(context));
        } catch (SecurityException ex) {
            // This is thrown if we are neither profile owner nor device owner.
            return false;
        }
    }
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    return isProfileOwner(context) && userManager.getUserProfiles().size() > 1;
}