Search in sources :

Example 76 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by crdroidandroid.

the class RestrictedLockUtils method checkIfMaximumTimeToLockIsSet.

/**
     * Checks if any admin has set maximum time to lock.
     *
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} if no admin has set this restriction. If multiple admins has set this, then
     * the admin component will be set to {@code null} and userId to {@link UserHandle#USER_NULL}
     */
public static EnforcedAdmin checkIfMaximumTimeToLockIsSet(Context context) {
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
    EnforcedAdmin enforcedAdmin = null;
    final int userId = UserHandle.myUserId();
    final UserManager um = UserManager.get(context);
    final List<UserInfo> profiles = um.getProfiles(userId);
    final int profilesSize = profiles.size();
    // enabled.
    for (int i = 0; i < profilesSize; i++) {
        final UserInfo userInfo = profiles.get(i);
        final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id);
        if (admins == null) {
            continue;
        }
        for (ComponentName admin : admins) {
            if (dpm.getMaximumTimeToLock(admin, userInfo.id) > 0) {
                if (enforcedAdmin == null) {
                    enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                } else {
                    return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                }
                // has set policy on the parent admin.
                continue;
            }
            if (userInfo.isManagedProfile()) {
                // If userInfo.id is a managed profile, we also need to look at
                // the policies set on the parent.
                final DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo);
                if (parentDpm.getMaximumTimeToLock(admin, userInfo.id) > 0) {
                    if (enforcedAdmin == null) {
                        enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                    } else {
                        return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                    }
                }
            }
        }
    }
    return enforcedAdmin;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils) UserInfo(android.content.pm.UserInfo) ComponentName(android.content.ComponentName)

Example 77 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by crdroidandroid.

the class RestrictedLockUtils method checkIfRestrictionEnforced.

/**
     * Checks if a restriction is enforced on a user and returns the enforced admin and
     * admin userId.
     *
     * @param userRestriction Restriction to check
     * @param userId User which we need to check if restriction is enforced on.
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} If the restriction is not set. If the restriction is set by both device owner
     * and profile owner, then the admin component will be set to {@code null} and userId to
     * {@link UserHandle#USER_NULL}.
     */
public static EnforcedAdmin checkIfRestrictionEnforced(Context context, String userRestriction, int userId) {
    DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    UserManager um = UserManager.get(context);
    int restrictionSource = um.getUserRestrictionSource(userRestriction, UserHandle.of(userId));
    // If the restriction is not enforced or enforced only by system then return null
    if (restrictionSource == UserManager.RESTRICTION_NOT_SET || restrictionSource == UserManager.RESTRICTION_SOURCE_SYSTEM) {
        return null;
    }
    final boolean enforcedByProfileOwner = (restrictionSource & UserManager.RESTRICTION_SOURCE_PROFILE_OWNER) != 0;
    final boolean enforcedByDeviceOwner = (restrictionSource & UserManager.RESTRICTION_SOURCE_DEVICE_OWNER) != 0;
    if (enforcedByProfileOwner) {
        return getProfileOwner(context, userId);
    } else if (enforcedByDeviceOwner) {
        // When the restriction is enforced by device owner, return the device owner admin only
        // if the admin is for the {@param userId} otherwise return a default EnforcedAdmin.
        final EnforcedAdmin deviceOwner = getDeviceOwner(context);
        return deviceOwner.userId == userId ? deviceOwner : EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
    }
    return null;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager)

Example 78 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by crdroidandroid.

the class RestrictedLockUtils method checkIfRemoteContactSearchDisallowed.

/**
     * @param context
     * @param userId user id of a managed profile.
     * @return is remote contacts search disallowed.
     */
public static EnforcedAdmin checkIfRemoteContactSearchDisallowed(Context context, int userId) {
    DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    EnforcedAdmin admin = getProfileOwner(context, userId);
    if (admin == null) {
        return null;
    }
    UserHandle userHandle = UserHandle.of(userId);
    if (dpm.getCrossProfileContactsSearchDisabled(userHandle) && dpm.getCrossProfileCallerIdDisabled(userHandle)) {
        return admin;
    }
    return null;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserHandle(android.os.UserHandle)

Example 79 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by crdroidandroid.

the class RestrictedLockUtils method getProfileOwner.

private static EnforcedAdmin getProfileOwner(Context context, int userId) {
    if (userId == UserHandle.USER_NULL) {
        return null;
    }
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    ComponentName adminComponent = dpm.getProfileOwnerAsUser(userId);
    if (adminComponent != null) {
        return new EnforcedAdmin(adminComponent, userId);
    }
    return null;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ComponentName(android.content.ComponentName)

Example 80 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by crdroidandroid.

the class RestrictedLockUtils method checkIfKeyguardFeaturesDisabled.

/**
     * Checks if keyguard features are disabled by policy.
     *
     * @param keyguardFeatures Could be any of keyguard features that can be
     * disabled by {@link android.app.admin.DevicePolicyManager#setKeyguardDisabledFeatures}.
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} If the notification features are not disabled. If the restriction is set by
     * multiple admins, then the admin component will be set to {@code null} and userId to
     * {@link UserHandle#USER_NULL}.
     */
public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context, int keyguardFeatures, int userId) {
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
    LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
    EnforcedAdmin enforcedAdmin = null;
    if (um.getUserInfo(userId).isManagedProfile()) {
        final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId);
        if (admins == null) {
            return null;
        }
        for (ComponentName admin : admins) {
            if ((dpm.getKeyguardDisabledFeatures(admin, userId) & keyguardFeatures) != 0) {
                if (enforcedAdmin == null) {
                    enforcedAdmin = new EnforcedAdmin(admin, userId);
                } else {
                    return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                }
            }
        }
    } else {
        // user that do not use a separate work challenge.
        for (UserInfo userInfo : um.getProfiles(userId)) {
            final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id);
            if (admins == null) {
                continue;
            }
            final boolean isSeparateProfileChallengeEnabled = lockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id);
            for (ComponentName admin : admins) {
                if (!isSeparateProfileChallengeEnabled) {
                    if ((dpm.getKeyguardDisabledFeatures(admin, userInfo.id) & keyguardFeatures) != 0) {
                        if (enforcedAdmin == null) {
                            enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                        } else {
                            return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                        }
                        // has set policy on the parent admin.
                        continue;
                    }
                }
                if (userInfo.isManagedProfile()) {
                    // If userInfo.id is a managed profile, we also need to look at
                    // the policies set on the parent.
                    DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo);
                    if ((parentDpm.getKeyguardDisabledFeatures(admin, userInfo.id) & keyguardFeatures) != 0) {
                        if (enforcedAdmin == null) {
                            enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                        } else {
                            return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                        }
                    }
                }
            }
        }
    }
    return enforcedAdmin;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils) ComponentName(android.content.ComponentName) UserInfo(android.content.pm.UserInfo)

Aggregations

DevicePolicyManager (android.app.admin.DevicePolicyManager)159 ComponentName (android.content.ComponentName)45 UserManager (android.os.UserManager)29 UserInfo (android.content.pm.UserInfo)25 RemoteException (android.os.RemoteException)24 LockPatternUtils (com.android.internal.widget.LockPatternUtils)19 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)14 PersistableBundle (android.os.PersistableBundle)8 PendingIntent (android.app.PendingIntent)6 IBinder (android.os.IBinder)6 UserHandle (android.os.UserHandle)6 IPackageManager (android.content.pm.IPackageManager)5 Uri (android.net.Uri)5 VrManagerInternal (com.android.server.vr.VrManagerInternal)5 ResolveInfo (android.content.pm.ResolveInfo)4 Point (android.graphics.Point)4 Binder (android.os.Binder)4 KeyStore (android.security.KeyStore)4 ArraySet (android.util.ArraySet)4