Example usage for android.hardware.fingerprint FingerprintManager isHardwareDetected

List of usage examples for android.hardware.fingerprint FingerprintManager isHardwareDetected

Introduction

In this page you can find the example usage for android.hardware.fingerprint FingerprintManager isHardwareDetected.

Prototype

@Deprecated
@RequiresPermission(USE_FINGERPRINT)
public boolean isHardwareDetected() 

Source Link

Document

Determine if fingerprint hardware is present and functional.

Usage

From source file:com.tozny.e3db.android.KeyStoreManager.java

@SuppressLint({ "MissingPermission", "NewApi" })
private static void checkArgs(Context context, KeyAuthentication protection,
        KeyAuthenticator keyAuthenticator) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        if (protection.authenticationType() == FINGERPRINT || protection.authenticationType() == LOCK_SCREEN)
            throw new IllegalArgumentException(
                    protection.authenticationType().toString() + " not supported below API 23.");
    }//from  w  ww.  j ava 2  s  .c o m

    if (protection.authenticationType() == PASSWORD || protection.authenticationType() == FINGERPRINT
            || protection.authenticationType() == LOCK_SCREEN) {
        if (keyAuthenticator == null) {
            throw new IllegalArgumentException("KeyAuthenticator can't be null for key protection type: "
                    + protection.authenticationType().toString());
        }
    }

    if (protection.authenticationType() == FINGERPRINT) {
        if (PermissionChecker.checkSelfPermission(context,
                Manifest.permission.USE_FINGERPRINT) != PermissionChecker.PERMISSION_GRANTED)
            throw new IllegalArgumentException(
                    protection.authenticationType().toString() + " permission not granted.");

        // Some devices support fingerprint but the support library doesn't recognize it, so
        // we use the actual FingerprintManager here. (https://stackoverflow.com/a/45181416/169359)
        FingerprintManager mgr = context.getSystemService(FingerprintManager.class);
        if (mgr == null || !mgr.isHardwareDetected())
            throw new IllegalArgumentException(
                    protection.authenticationType().toString() + " hardware not available.");
    }

    if (protection.authenticationType() == LOCK_SCREEN) {
        if (protection.validUntilSecondsSinceUnlock() < 1)
            throw new IllegalArgumentException("secondsSinceUnlock must be greater than 0.");
    }
}

From source file:io.digibyte.tools.util.Utils.java

public static boolean isFingerprintEnrolled(Context app) {
    FingerprintManager fingerprintManager = (FingerprintManager) app.getSystemService(FINGERPRINT_SERVICE);
    // Device doesn't support fingerprint authentication
    return ActivityCompat.checkSelfPermission(app,
            Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED
            && fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints();
}

From source file:com.tozny.e3db.android.KeyAuthentication.java

/**
 * Indicates if the device and SDK support the given type of key authentication.
 * @param ctx Application context./*from   w  w  w .j  a v a2s . c om*/
 * @param authentication Authentication type.
 * @return {@code true} if the authencation type is supported; {@code false} otherwise.
 */
@SuppressLint("MissingPermission")
public static boolean protectionTypeSupported(Context ctx, KeyAuthenticationType authentication) {
    switch (authentication) {
    case NONE:
    case PASSWORD:
        return true;
    case LOCK_SCREEN:
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
    case FINGERPRINT:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            // Some devices support fingerprint but the support library doesn't recognize it, so
            // we use the actual FingerprintManager here. (https://stackoverflow.com/a/45181416/169359)
            FingerprintManager mgr = ctx.getSystemService(FingerprintManager.class);
            if (mgr != null) {
                return PermissionChecker.checkSelfPermission(ctx,
                        Manifest.permission.USE_FINGERPRINT) == PermissionChecker.PERMISSION_GRANTED
                        && mgr.isHardwareDetected() && mgr.hasEnrolledFingerprints();
            }
        }
        return false;
    default:
        throw new IllegalStateException("Unhandled authentication type: " + authentication);
    }
}

From source file:com.owncloud.android.ui.activity.FingerprintActivity.java

final static public boolean isFingerprintCapable(Context context) {
    try {/*from  ww  w  .  j a  va2s . c om*/
        FingerprintManager fingerprintManager = (FingerprintManager) context
                .getSystemService(Context.FINGERPRINT_SERVICE);

        if (ActivityCompat.checkSelfPermission(context,
                Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return fingerprintManager.isHardwareDetected();
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}

From source file:com.owncloud.android.ui.activity.FingerprintActivity.java

final static public boolean isFingerprintReady(Context context) {
    try {//from  w w w.j  a  va 2  s . com
        FingerprintManager fingerprintManager = (FingerprintManager) context
                .getSystemService(Context.FINGERPRINT_SERVICE);

        if (ActivityCompat.checkSelfPermission(context,
                Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints();
        }
    } catch (Exception e) {
        return false;
    }

    return false;
}

From source file:io.digibyte.tools.util.Utils.java

public static boolean isFingerprintAvailable(Context app) {
    FingerprintManager fingerprintManager = (FingerprintManager) app.getSystemService(FINGERPRINT_SERVICE);
    if (fingerprintManager == null)
        return false;
    // Device doesn't support fingerprint authentication
    if (ActivityCompat.checkSelfPermission(app,
            Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(app, "Fingerprint authentication permission not enabled", Toast.LENGTH_LONG).show();
        return false;
    }// w  w  w.j  a  v  a 2 s.  co  m
    return fingerprintManager.isHardwareDetected();
}

From source file:de.j4velin.encrypter.MainActivity.java

private Requirement getMissingRequirement() {
    FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[] { Manifest.permission.USE_FINGERPRINT }, REQUEST_PERMISSION);
        return Requirement.FINGERPRINT_PERMISSION;
    } else if (!fingerprintManager.isHardwareDetected()) {
        return Requirement.FINGERPRINT_SENSOR;
    } else if (!fingerprintManager.hasEnrolledFingerprints()) {
        return Requirement.FINGERPRINT_SETUP;
    } else if (!((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).isDeviceSecure()) {
        return Requirement.DEVICE_SECURE;
    } else {//from   w w w .j a v  a  2 s .co  m
        return null;
    }
}

From source file:com.breadwallet.presenter.fragments.FragmentSettings.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The last two arguments ensure LayoutParams are inflated
    // properly./*ww w.  j  a  v a  2s. c o  m*/

    View rootView = inflater.inflate(R.layout.fragment_settings, container, false);

    app = MainActivity.app;
    fragmentSettings = this;
    initList();
    RelativeLayout about = (RelativeLayout) rootView.findViewById(R.id.about);
    TextView currencyName = (TextView) rootView.findViewById(R.id.three_letters_currency);
    RelativeLayout changePassword = (RelativeLayout) rootView.findViewById(R.id.change_password);
    final String tmp = SharedPreferencesManager.getIso(getActivity());
    currencyName.setText(tmp);
    RelativeLayout localCurrency = (RelativeLayout) rootView.findViewById(R.id.local_currency);
    RelativeLayout recoveryPhrase = (RelativeLayout) rootView.findViewById(R.id.recovery_phrase);
    RelativeLayout startRecoveryWallet = (RelativeLayout) rootView.findViewById(R.id.start_recovery_wallet);
    RelativeLayout fingerprintLimit = (RelativeLayout) rootView.findViewById(R.id.fingerprint_limit);
    RelativeLayout earlyAccess = (RelativeLayout) rootView.findViewById(R.id.early_access);
    RelativeLayout line5 = (RelativeLayout) rootView.findViewById(R.id.settings_line_5);
    TextView theLimit = (TextView) rootView.findViewById(R.id.fingerprint_limit_text);
    RelativeLayout rescan = (RelativeLayout) rootView.findViewById(R.id.rescan_blockchain);

    theLimit.setText(BRStringFormatter.getFormattedCurrencyString("BTC",
            PassCodeManager.getInstance().getLimit(getActivity())));
    FingerprintManager mFingerprintManager;
    mFingerprintManager = (FingerprintManager) getActivity().getSystemService(Context.FINGERPRINT_SERVICE);
    boolean useFingerPrint;
    useFingerPrint = ActivityCompat.checkSelfPermission(getActivity(),
            Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED
            && mFingerprintManager.isHardwareDetected() && mFingerprintManager.hasEnrolledFingerprints();

    if (!useFingerPrint) {
        fingerprintLimit.setVisibility(View.GONE);
        line5.setVisibility(View.GONE);
    }

    fingerprintLimit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (BRAnimator.checkTheMultipressingAvailability()) {
                ((BreadWalletApp) getActivity().getApplicationContext()).promptForAuthentication(getActivity(),
                        BRConstants.AUTH_FOR_LIMIT, null, null, null, null, false);
            }
        }
    });

    startRecoveryWallet.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (BRAnimator.checkTheMultipressingAvailability()) {
                BRAnimator.pressWipeWallet(app, new FragmentWipeWallet());
                app.activityButtonsEnable(false);
            }
        }
    });
    recoveryPhrase.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BRWalletManager.getInstance(getActivity()).animateSavePhraseFlow();
        }
    });
    about.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (BRAnimator.checkTheMultipressingAvailability()) {
                BRAnimator.animateSlideToLeft(app, new FragmentAbout(), fragmentSettings);
            }
        }
    });
    localCurrency.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (BRAnimator.checkTheMultipressingAvailability()) {
                BRAnimator.animateSlideToLeft(app, new FragmentCurrency(), fragmentSettings);
            }
        }
    });
    changePassword.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (BRAnimator.checkTheMultipressingAvailability()) {
                final android.app.FragmentManager fm = getActivity().getFragmentManager();
                new PasswordDialogFragment().show(fm, PasswordDialogFragment.class.getName());
            }
        }
    }

    );

    rescan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (BRAnimator.checkTheMultipressingAvailability()) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        BRAnimator.goToMainActivity(fragmentSettings);
                        BRPeerManager.getInstance(getActivity()).rescan();
                        SharedPreferencesManager.putStartHeight(getActivity(), 0);
                    }
                }).start();
            }

        }
    }

    );
    //keep it hidden until finished
    if (!PLATFORM_ON) {
        earlyAccess.setVisibility(View.GONE);
        rootView.findViewById(R.id.early_access_separator).setVisibility(View.GONE);
        rootView.findViewById(R.id.early_access_separator2).setVisibility(View.GONE);

    } else {
        earlyAccess.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (BRAnimator.checkTheMultipressingAvailability()) {

                    BRAnimator.animateSlideToLeft(app, new FragmentWebView(), fragmentSettings);
                }
            }
        });
    }
    return rootView;
}

From source file:com.amaze.carbonfilemanager.fragments.preference_fragments.Preffrag.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    utilsProvider = (UtilitiesProviderInterface) getActivity();

    PreferenceUtils.reset();//w ww .j a  v  a 2  s. c o  m
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    for (String PREFERENCE_KEY : PREFERENCE_KEYS) {
        findPreference(PREFERENCE_KEY).setOnPreferenceClickListener(this);
    }

    gplus = (CheckBox) findPreference("plus_pic");

    if (BuildConfig.IS_VERSION_FDROID)
        gplus.setEnabled(false);

    // crypt master password
    final EditTextPreference masterPasswordPreference = (EditTextPreference) findPreference(
            PREFERENCE_CRYPT_MASTER_PASSWORD);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        // encryption feature not available
        masterPasswordPreference.setEnabled(false);
    }

    if (sharedPref.getBoolean(PREFERENCE_CRYPT_FINGERPRINT, false)) {
        masterPasswordPreference.setEnabled(false);
    }

    CheckBox checkBoxFingerprint = (CheckBox) findPreference(PREFERENCE_CRYPT_FINGERPRINT);

    try {

        // finger print sensor
        final FingerprintManager fingerprintManager = (FingerprintManager) getActivity()
                .getSystemService(Context.FINGERPRINT_SERVICE);

        final KeyguardManager keyguardManager = (KeyguardManager) getActivity()
                .getSystemService(Context.KEYGUARD_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && fingerprintManager.isHardwareDetected()) {

            checkBoxFingerprint.setEnabled(true);
        }

        checkBoxFingerprint.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {

                if (ActivityCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(getActivity(),
                            getResources().getString(R.string.crypt_fingerprint_no_permission),
                            Toast.LENGTH_LONG).show();
                    return false;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                        && !fingerprintManager.hasEnrolledFingerprints()) {
                    Toast.makeText(getActivity(),
                            getResources().getString(R.string.crypt_fingerprint_not_enrolled),
                            Toast.LENGTH_LONG).show();
                    return false;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                        && !keyguardManager.isKeyguardSecure()) {
                    Toast.makeText(getActivity(),
                            getResources().getString(R.string.crypt_fingerprint_no_security), Toast.LENGTH_LONG)
                            .show();
                    return false;
                }

                masterPasswordPreference.setEnabled(false);
                return true;
            }
        });
    } catch (NoClassDefFoundError error) {
        error.printStackTrace();

        // fingerprint manager class not defined in the framework
        checkBoxFingerprint.setEnabled(false);
    }

    // Hide root preference
    Preference mRootMode = findPreference("rootmode");
    PreferenceCategory mMisc = (PreferenceCategory) findPreference("misc");
    mMisc.removePreference(mRootMode);

}

From source file:com.android.launcher3.Utilities.java

@TargetApi(23)
public static boolean checkFingerprintHardwareAndPermission(Context context,
        FingerprintManager fingerprintManager) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ActivityCompat.checkSelfPermission(context,
                Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED) {
            if (fingerprintManager != null) {
                if (fingerprintManager.isHardwareDetected()) {
                    return true;
                }//  w  w w  . j  a  va 2s  .  c o m
            } else {
                return false;
            }
        }
    }
    return false;
}