Example usage for android.app.admin DevicePolicyManager RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT

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

Introduction

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

Prototype

int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT

To view the source code for android.app.admin DevicePolicyManager RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT.

Click Source Link

Document

Flag for #resetPasswordWithToken and #resetPassword : don't ask for user credentials on device boot.

Usage

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

/**
 * Shows a prompt to ask for a password to reset to and to set whether this requires
 * re-entry before any further changes and/or whether the password needs to be entered during
 * boot to start the user./*from ww  w . j a v a  2 s .  c o  m*/
 */
private void showResetPasswordPrompt() {
    View dialogView = getActivity().getLayoutInflater().inflate(R.layout.reset_password_dialog, null);

    final EditText passwordView = (EditText) dialogView.findViewById(R.id.password);
    final CheckBox requireEntry = (CheckBox) dialogView.findViewById(R.id.require_password_entry_checkbox);
    final CheckBox requireOnBoot = (CheckBox) dialogView.findViewById(R.id.require_password_on_boot_checkbox);

    DialogInterface.OnClickListener resetListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            String password = passwordView.getText().toString();
            if (TextUtils.isEmpty(password)) {
                password = null;
            }

            int flags = 0;
            flags |= requireEntry.isChecked() ? DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY : 0;
            flags |= requireOnBoot.isChecked()
                    ? DevicePolicyManager.RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT
                    : 0;

            boolean ok = false;
            try {
                ok = mDevicePolicyManager.resetPassword(password, flags);
            } catch (IllegalArgumentException | IllegalStateException | SecurityException e) {
                // Not allowed to set password or trying to set a bad password, eg. 2 characters
                // where system minimum length is 4.
                Log.w(TAG, "Failed to reset password", e);
            }
            showToast(ok ? R.string.password_reset_success : R.string.password_reset_failed);
        }
    };

    new AlertDialog.Builder(getActivity()).setTitle(R.string.reset_password).setView(dialogView)
            .setPositiveButton(android.R.string.ok, resetListener)
            .setNegativeButton(android.R.string.cancel, null).show();
}