Example usage for android.app.admin DevicePolicyManager RESET_PASSWORD_REQUIRE_ENTRY

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

Introduction

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

Prototype

int RESET_PASSWORD_REQUIRE_ENTRY

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

Click Source Link

Document

Flag for #resetPasswordWithToken and #resetPassword : don't allow other admins to change the password again until the user has entered it.

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   www  . jav  a2  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();
}