Example usage for android.support.v4.hardware.fingerprint FingerprintManagerCompat from

List of usage examples for android.support.v4.hardware.fingerprint FingerprintManagerCompat from

Introduction

In this page you can find the example usage for android.support.v4.hardware.fingerprint FingerprintManagerCompat from.

Prototype

public static FingerprintManagerCompat from(Context context) 

Source Link

Document

Get a FingerprintManagerCompat instance for a provided context.

Usage

From source file:com.example.android.fingerprintdialog.FingerprintModule.java

@Provides
public FingerprintManagerCompat providesFingerprintManager(Context context) {
    return FingerprintManagerCompat.from(context);
}

From source file:com.mtramin.rxfingerprint.FingerprintObservable.java

@Override
public void call(AsyncEmitter<T> asyncEmitter) {
    if (!RxFingerprint.isAvailable(context)) {
        asyncEmitter.onError(new IllegalAccessException(
                "Fingerprint authentication is not available on this device! Ensure that the device has a Fingerprint sensor and enrolled Fingerprints by calling RxFingerprint#available(Context) first"));
    }//  w  ww . j  a v  a  2s  .  c  o  m

    AuthenticationCallback callback = createAuthenticationCallback(asyncEmitter);
    cancellationSignal = new CancellationSignal();
    FingerprintManagerCompat.CryptoObject cryptoObject = initCryptoObject(asyncEmitter);
    FingerprintManagerCompat.from(context).authenticate(cryptoObject, 0, cancellationSignal, callback, null);

    asyncEmitter.setSubscription(Subscriptions.create(() -> {
        if (cancellationSignal != null && !cancellationSignal.isCanceled()) {
            cancellationSignal.cancel();
        }
    }));

}

From source file:alexander.martinz.fingerprintfuzzer.FingerPrinter.java

public FingerPrinter(@NonNull Context context, FingerprinterCallback authenticationCallback,
        @Nullable String keyName) {
    this.context = context;
    this.cryptoHelper = new CryptoHelper(context, keyName);

    this.keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    this.fingerprintManager = FingerprintManagerCompat.from(context);

    this.authenticationCallback = authenticationCallback;
}

From source file:at.amartinz.hardware.security.Fingerprinter.java

public Fingerprinter(@NonNull Context context, FingerprinterCallback authenticationCallback,
        @Nullable String keyName) {
    this.context = context;
    this.cryptoHelper = new CryptoHelper(context, keyName);

    this.keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    this.fingerprintManager = FingerprintManagerCompat.from(context);

    this.authenticationCallback = authenticationCallback;
}

From source file:com.jefftharris.passwdsafe.SavedPasswordsMgr.java

/**
 * Constructor
 */
public SavedPasswordsMgr(Context ctx) {
    itsFingerprintMgr = FingerprintManagerCompat.from(ctx);
    itsContext = ctx;
}

From source file:io.flutter.plugins.localauth.AuthenticationHelper.java

AuthenticationHelper(Activity activity, MethodCall call, AuthCompletionHandler completionHandler) {
    this.activity = activity;
    this.completionHandler = completionHandler;
    this.call = call;
    this.keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
    this.fingerprintManager = FingerprintManagerCompat.from(activity);
}

From source file:de.schildbach.wallet.util.FingerprintHelper.java

@TargetApi(Build.VERSION_CODES.M)
public boolean init() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        log.info("This Android version does not support fingerprint authentication");
        return false;
    }/*from   w  ww.  j av  a 2 s.co  m*/

    KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(KEYGUARD_SERVICE);
    fingerprintManager = FingerprintManagerCompat.from(context);

    if (!keyguardManager.isKeyguardSecure()) {
        log.info("User hasn't enabled Lock Screen");
        return false;
    }

    if (!hasPermission()) {
        log.info("User hasn't granted permission to use Fingerprint");
        return false;
    }

    if (!fingerprintManager.hasEnrolledFingerprints()) {
        log.info("User hasn't registered any fingerprints");
        return false;
    }

    if (!initKeyStore()) {
        return false;
    }
    return true;
}

From source file:com.grarak.kerneladiutor.activities.SecurityActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_security);

    final String password = Utils.decodeString(getIntent().getStringExtra(PASSWORD_INTENT));
    AppCompatEditText editText = (AppCompatEditText) findViewById(R.id.edittext);
    mPasswordWrong = findViewById(R.id.password_wrong);
    editText.addTextChangedListener(new TextWatcher() {
        @Override/*from w w w . j a v a  2s.  c om*/
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.toString().equals(password)) {
                mPasswordWrong.setVisibility(View.GONE);
                setResult(1);
                finish();
            } else {
                mPasswordWrong.setVisibility(editable.toString().isEmpty() ? View.GONE : View.VISIBLE);
            }
        }
    });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Prefs.getBoolean("fingerprint", false, this)) {
        mFingerprintManagerCompat = FingerprintManagerCompat.from(this);
        if (mFingerprintManagerCompat.isHardwareDetected()
                && mFingerprintManagerCompat.hasEnrolledFingerprints()
                && getSystemService(KeyguardManager.class).isDeviceSecure()) {
            loadFingerprint();
        }
    }
}

From source file:com.keepassdroid.fingerprint.FingerPrintHelper.java

public FingerPrintHelper(final Context context, final FingerPrintCallback fingerPrintCallback) {

    if (!isFingerprintSupported()) {
        // really not much to do when no fingerprint support found
        setInitOk(false);/*from   www  . j a v a  2  s . co  m*/
        return;
    }
    this.fingerprintManager = FingerprintManagerCompat.from(context);
    this.keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    this.fingerPrintCallback = fingerPrintCallback;

    if (hasEnrolledFingerprints()) {
        try {
            this.keyStore = KeyStore.getInstance("AndroidKeyStore");
            this.keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
            this.cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/"
                    + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
            this.cryptoObject = new FingerprintManagerCompat.CryptoObject(cipher);
            setInitOk(true);
        } catch (final Exception e) {
            setInitOk(false);
            fingerPrintCallback.onException();
        }
    }
}

From source file:org.thoughtcrime.securesms.PassphrasePromptActivity.java

private void initializeResources() {

    ImageButton okButton = findViewById(R.id.ok_button);
    Toolbar toolbar = findViewById(R.id.toolbar);

    showButton = findViewById(R.id.passphrase_visibility);
    hideButton = findViewById(R.id.passphrase_visibility_off);
    visibilityToggle = findViewById(R.id.button_toggle);
    passphraseText = findViewById(R.id.passphrase_edit);
    passphraseAuthContainer = findViewById(R.id.password_auth_container);
    fingerprintPrompt = findViewById(R.id.fingerprint_auth_container);
    lockScreenButton = findViewById(R.id.lock_screen_auth_container);
    fingerprintManager = FingerprintManagerCompat.from(this);
    fingerprintCancellationSignal = new CancellationSignal();
    fingerprintListener = new FingerprintListener();

    setSupportActionBar(toolbar);// w  w  w  .  jav  a2  s  .  co  m
    getSupportActionBar().setTitle("");

    SpannableString hint = new SpannableString(
            "  " + getString(R.string.PassphrasePromptActivity_enter_passphrase));
    hint.setSpan(new RelativeSizeSpan(0.9f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

    passphraseText.setHint(hint);
    okButton.setOnClickListener(new OkButtonClickListener());
    showButton.setOnClickListener(new ShowButtonOnClickListener());
    hideButton.setOnClickListener(new HideButtonOnClickListener());
    passphraseText.setOnEditorActionListener(new PassphraseActionListener());
    passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
            EditorInfo.IME_ACTION_DONE);

    fingerprintPrompt.setImageResource(R.drawable.ic_fingerprint_white_48dp);
    fingerprintPrompt.getBackground().setColorFilter(getResources().getColor(R.color.signal_primary),
            PorterDuff.Mode.SRC_IN);

    lockScreenButton.setOnClickListener(v -> resumeScreenLock());
}