Search in sources :

Example 61 with UserManager

use of android.os.UserManager in project android_frameworks_base by AOSPA.

the class MtpDevice method open.

/**
     * Opens the MTP device.  Once the device is open it takes ownership of the
     * {@link android.hardware.usb.UsbDeviceConnection}.
     * The connection will be closed when you call {@link #close()}
     * The connection will also be closed if this method fails.
     *
     * @param connection an open {@link android.hardware.usb.UsbDeviceConnection} for the device
     * @return true if the device was successfully opened.
     */
public boolean open(UsbDeviceConnection connection) {
    boolean result = false;
    Context context = connection.getContext();
    if (context != null) {
        UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        if (!userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
            result = native_open(mDevice.getDeviceName(), connection.getFileDescriptor());
        }
    }
    if (!result) {
        connection.close();
    }
    return result;
}
Also used : Context(android.content.Context) UserManager(android.os.UserManager)

Example 62 with UserManager

use of android.os.UserManager in project android_frameworks_base by AOSPA.

the class BaseSettingsProviderTest method setContext.

@Override
public void setContext(Context context) {
    super.setContext(context);
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    List<UserInfo> users = userManager.getUsers();
    final int userCount = users.size();
    for (int i = 0; i < userCount; i++) {
        UserInfo user = users.get(i);
        if (!user.isPrimary() && !user.isManagedProfile()) {
            mSecondaryUserId = user.id;
            break;
        }
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 63 with UserManager

use of android.os.UserManager in project android_frameworks_base by AOSPA.

the class RestrictedLockUtils method checkIfPasswordQualityIsSet.

/**
     * Checks if an admin has enforced minimum password quality requirements on the given user.
     *
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} if no quality requirements are set. If the requirements are set by
     * multiple device admins, then the admin component will be set to {@code null} and userId to
     * {@link UserHandle#USER_NULL}.
     *
     */
public static EnforcedAdmin checkIfPasswordQualityIsSet(Context context, int userId) {
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
    EnforcedAdmin enforcedAdmin = null;
    if (lockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {
        // userId is managed profile and has a separate challenge, only consider
        // the admins in that user.
        final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId);
        if (admins == null) {
            return null;
        }
        for (ComponentName admin : admins) {
            if (dpm.getPasswordQuality(admin, userId) > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                if (enforcedAdmin == null) {
                    enforcedAdmin = new EnforcedAdmin(admin, userId);
                } else {
                    return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                }
            }
        }
    } else {
        // Return all admins for this user and the profiles that are visible from this
        // user that do not use a separate work challenge.
        final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
        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.getPasswordQuality(admin, userInfo.id) > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                        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.getPasswordQuality(admin, userInfo.id) > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                        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)

Example 64 with UserManager

use of android.os.UserManager in project android_frameworks_base by AOSPA.

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 65 with UserManager

use of android.os.UserManager in project android_frameworks_base by AOSPA.

the class RestrictedLockUtils method isAdminInCurrentUserOrProfile.

public static boolean isAdminInCurrentUserOrProfile(Context context, ComponentName admin) {
    DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    UserManager um = UserManager.get(context);
    for (UserInfo userInfo : um.getProfiles(UserHandle.myUserId())) {
        if (dpm.isAdminActiveAsUser(admin, userInfo.id)) {
            return true;
        }
    }
    return false;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Aggregations

UserManager (android.os.UserManager)587 UserInfo (android.content.pm.UserInfo)209 UserHandle (android.os.UserHandle)83 Context (android.content.Context)75 Intent (android.content.Intent)67 Test (org.junit.Test)60 PackageManager (android.content.pm.PackageManager)59 ComponentName (android.content.ComponentName)54 RemoteException (android.os.RemoteException)54 View (android.view.View)54 ArrayList (java.util.ArrayList)50 DevicePolicyManager (android.app.admin.DevicePolicyManager)37 Preference (android.support.v7.preference.Preference)32 TextView (android.widget.TextView)31 ImageView (android.widget.ImageView)29 IOException (java.io.IOException)29 Bitmap (android.graphics.Bitmap)26 Bundle (android.os.Bundle)25 ShadowUserManager (com.android.settings.testutils.shadow.ShadowUserManager)25 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)24