Search in sources :

Example 1 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project cw-omnibus by commonsguy.

the class AdminReceiver method onPasswordChanged.

@Override
public void onPasswordChanged(Context ctxt, Intent intent) {
    DevicePolicyManager mgr = (DevicePolicyManager) ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
    int msgId;
    if (mgr.isActivePasswordSufficient()) {
        msgId = R.string.compliant;
    } else {
        msgId = R.string.not_compliant;
    }
    Toast.makeText(ctxt, msgId, Toast.LENGTH_LONG).show();
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager)

Example 2 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project cw-omnibus by commonsguy.

the class AdminReceiver method onEnabled.

@Override
public void onEnabled(Context ctxt, Intent intent) {
    ComponentName cn = new ComponentName(ctxt, AdminReceiver.class);
    DevicePolicyManager mgr = (DevicePolicyManager) ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
    mgr.setPasswordQuality(cn, DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
    onPasswordChanged(ctxt, intent);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ComponentName(android.content.ComponentName)

Example 3 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ComponentName cn = new ComponentName(this, AdminReceiver.class);
    DevicePolicyManager mgr = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
    if (mgr.isAdminActive(cn)) {
        int msgId;
        if (mgr.isActivePasswordSufficient()) {
            msgId = R.string.compliant;
        } else {
            msgId = R.string.not_compliant;
        }
        Toast.makeText(this, msgId, Toast.LENGTH_LONG).show();
    } else {
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cn);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.device_admin_explanation));
        startActivity(intent);
    }
    finish();
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 4 with DevicePolicyManager

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

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)

Example 5 with DevicePolicyManager

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

the class LockPatternUtils method saveLockPattern.

/**
     * Save a lock pattern.
     * @param pattern The new pattern to save.
     * @param savedPattern The previously saved pattern, converted to String format
     * @param userId the user whose pattern is to be saved.
     */
public void saveLockPattern(List<LockPatternView.Cell> pattern, String savedPattern, int userId) {
    try {
        if (pattern == null || pattern.size() < MIN_LOCK_PATTERN_SIZE) {
            throw new IllegalArgumentException("pattern must not be null and at least " + MIN_LOCK_PATTERN_SIZE + " dots long.");
        }
        setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
        getLockSettings().setLockPattern(patternToString(pattern, userId), savedPattern, userId);
        DevicePolicyManager dpm = getDevicePolicyManager();
        // Update the device encryption password.
        if (userId == UserHandle.USER_SYSTEM && LockPatternUtils.isDeviceEncryptionEnabled()) {
            if (!shouldEncryptWithCredentials(true)) {
                clearEncryptionPassword();
            } else {
                String stringPattern = patternToString(pattern, userId);
                updateEncryptionPassword(StorageManager.CRYPT_TYPE_PATTERN, stringPattern);
            }
        }
        setBoolean(PATTERN_EVER_CHOSEN_KEY, true, userId);
        onAfterChangingPassword(userId);
    } catch (RemoteException re) {
        Log.e(TAG, "Couldn't save lock pattern " + re);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) RemoteException(android.os.RemoteException)

Aggregations

DevicePolicyManager (android.app.admin.DevicePolicyManager)286 ComponentName (android.content.ComponentName)75 Intent (android.content.Intent)39 UserManager (android.os.UserManager)36 UserInfo (android.content.pm.UserInfo)32 RemoteException (android.os.RemoteException)30 Activity (android.app.Activity)25 PackageManager (android.content.pm.PackageManager)22 LockPatternUtils (com.android.internal.widget.LockPatternUtils)19 UserHandle (android.os.UserHandle)13 IBinder (android.os.IBinder)12 DevicePolicyManagerWrapperImpl (com.android.settings.enterprise.DevicePolicyManagerWrapperImpl)12 IPackageManager (android.content.pm.IPackageManager)11 ArrayList (java.util.ArrayList)10 SpannableString (android.text.SpannableString)9 TextView (android.widget.TextView)9 RestrictedLockUtils (com.android.settingslib.RestrictedLockUtils)9 PendingIntent (android.app.PendingIntent)8 ContentResolver (android.content.ContentResolver)8 PersistableBundle (android.os.PersistableBundle)8