Search in sources :

Example 61 with DevicePolicyManager

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

the class RestrictedLockUtils method checkIfAccessibilityServiceDisallowed.

public static EnforcedAdmin checkIfAccessibilityServiceDisallowed(Context context, String packageName, int userId) {
    DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    EnforcedAdmin admin = getProfileOrDeviceOwner(context, userId);
    boolean permitted = true;
    if (admin != null) {
        permitted = dpm.isAccessibilityServicePermittedByAdmin(admin.component, packageName, userId);
    }
    int managedProfileId = getManagedProfileId(context, userId);
    EnforcedAdmin profileAdmin = getProfileOrDeviceOwner(context, managedProfileId);
    boolean permittedByProfileAdmin = true;
    if (profileAdmin != null) {
        permittedByProfileAdmin = dpm.isAccessibilityServicePermittedByAdmin(profileAdmin.component, packageName, managedProfileId);
    }
    if (!permitted && !permittedByProfileAdmin) {
        return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
    } else if (!permitted) {
        return admin;
    } else if (!permittedByProfileAdmin) {
        return profileAdmin;
    }
    return null;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager)

Example 62 with DevicePolicyManager

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

the class RestrictedLockUtils method getDeviceOwner.

public static EnforcedAdmin getDeviceOwner(Context context) {
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    ComponentName adminComponent = dpm.getDeviceOwnerComponentOnAnyUser();
    if (adminComponent != null) {
        return new EnforcedAdmin(adminComponent, dpm.getDeviceOwnerUserId());
    }
    return null;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ComponentName(android.content.ComponentName)

Example 63 with DevicePolicyManager

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

the class RestrictedLockUtils method checkIfAutoTimeRequired.

/**
     * Checks if {@link android.app.admin.DevicePolicyManager#setAutoTimeRequired} is enforced
     * on the device.
     *
     * @return EnforcedAdmin Object containing the device owner component and
     * userId the device owner is running as, or {@code null} setAutoTimeRequired is not enforced.
     */
public static EnforcedAdmin checkIfAutoTimeRequired(Context context) {
    DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null || !dpm.getAutoTimeRequired()) {
        return null;
    }
    ComponentName adminComponent = dpm.getDeviceOwnerComponentOnCallingUser();
    return new EnforcedAdmin(adminComponent, UserHandle.myUserId());
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ComponentName(android.content.ComponentName)

Example 64 with DevicePolicyManager

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

the class KeyguardBottomAreaView method isCameraDisabledByDpm.

private boolean isCameraDisabledByDpm() {
    final DevicePolicyManager dpm = (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm != null && mPhoneStatusBar != null) {
        try {
            final int userId = ActivityManagerNative.getDefault().getCurrentUser().id;
            final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId);
            final boolean disabledBecauseKeyguardSecure = (disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0 && mPhoneStatusBar.isKeyguardSecure();
            return dpm.getCameraDisabled(null) || disabledBecauseKeyguardSecure;
        } catch (RemoteException e) {
            Log.e(TAG, "Can't get userId", e);
        }
    }
    return false;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) RemoteException(android.os.RemoteException)

Example 65 with DevicePolicyManager

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

the class LockPatternUtils method saveLockPassword.

/**
     * Save a lock password.  Does not ensure that the password is as good
     * as the requested mode, but will adjust the mode to be as good as the
     * password.
     * @param password The password to save
     * @param savedPassword The previously saved lock password, or null if none
     * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
     * @param userHandle The userId of the user to change the password for
     */
public void saveLockPassword(String password, String savedPassword, int quality, int userHandle) {
    try {
        DevicePolicyManager dpm = getDevicePolicyManager();
        if (password == null || password.length() < MIN_LOCK_PASSWORD_SIZE) {
            throw new IllegalArgumentException("password must not be null and at least " + "of length " + MIN_LOCK_PASSWORD_SIZE);
        }
        final int computedQuality = computePasswordQuality(password);
        setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality), userHandle);
        getLockSettings().setLockPassword(password, savedPassword, userHandle);
        // Update the device encryption password.
        if (userHandle == UserHandle.USER_SYSTEM && LockPatternUtils.isDeviceEncryptionEnabled()) {
            if (!shouldEncryptWithCredentials(true)) {
                clearEncryptionPassword();
            } else {
                boolean numeric = computedQuality == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
                boolean numericComplex = computedQuality == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
                int type = numeric || numericComplex ? StorageManager.CRYPT_TYPE_PIN : StorageManager.CRYPT_TYPE_PASSWORD;
                updateEncryptionPassword(type, password);
            }
        }
        // Add the password to the password history. We assume all
        // password hashes have the same length for simplicity of implementation.
        String passwordHistory = getString(PASSWORD_HISTORY_KEY, userHandle);
        if (passwordHistory == null) {
            passwordHistory = "";
        }
        int passwordHistoryLength = getRequestedPasswordHistoryLength(userHandle);
        if (passwordHistoryLength == 0) {
            passwordHistory = "";
        } else {
            byte[] hash = passwordToHash(password, userHandle);
            passwordHistory = new String(hash, StandardCharsets.UTF_8) + "," + passwordHistory;
            // Cut it to contain passwordHistoryLength hashes
            // and passwordHistoryLength -1 commas.
            passwordHistory = passwordHistory.substring(0, Math.min(hash.length * passwordHistoryLength + passwordHistoryLength - 1, passwordHistory.length()));
        }
        setString(PASSWORD_HISTORY_KEY, passwordHistory, userHandle);
        onAfterChangingPassword(userHandle);
    } catch (RemoteException re) {
        // Cant do much
        Log.e(TAG, "Unable to save lock password " + re);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) RemoteException(android.os.RemoteException)

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