androidx.core.hardware.fingerprint.FingerprintManagerCompat Java Examples

The following examples show how to use androidx.core.hardware.fingerprint.FingerprintManagerCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SmartLockHelper.java    From samples-android with Apache License 2.0 6 votes vote down vote up
@Deprecated
@TargetApi(M)
private void showFingerprint(Activity activity, FingerprintDialogCallbacks callback, Cipher cipher) {
    if (mFingerprintDialog != null && activity.getFragmentManager().findFragmentByTag(FINGERPRINT_DIALOG_TAG) == null) {
        FingerprintManagerCompat.CryptoObject cryptoObject = new FingerprintManagerCompat.CryptoObject(cipher);
        mFingerprintDialog.init(cryptoObject, new FingerprintDialog.FingerprintDialogCallbacks() {
            @Override
            public void onFingerprintSuccess() {
                callback.onFingerprintSuccess(null);
            }

            @Override
            public void onFingerprintError(String error) {
                callback.onFingerprintError(error);
            }

            @Override
            public void onFingerprintCancel() {
                callback.onFingerprintCancel();
            }
        });
        mFingerprintDialog.show(activity.getFragmentManager(), FINGERPRINT_DIALOG_TAG);
    }
}
 
Example #2
Source File: PFFingerprintAuthDialogFragment.java    From PFLockScreen-Android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    getDialog().setTitle(getString(R.string.sign_in_pf));
    View v = inflater.inflate(R.layout.view_pf_fingerprint_dialog_container, container,
            false);
    mCancelButton = v.findViewById(R.id.cancel_button);
    mCancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dismiss();
        }
    });

    mFingerprintContent = v.findViewById(R.id.fingerprint_container);


    FingerprintManagerCompat manager = FingerprintManagerCompat.from(getContext());
    mFingerprintCallback = new PFFingerprintUIHelper(manager,
            (ImageView) v.findViewById(R.id.fingerprint_icon),
            (TextView) v.findViewById(R.id.fingerprint_status),
            mAuthListener);
    updateStage();
    return v;
}
 
Example #3
Source File: PFFingerprintUIHelper.java    From PFLockScreen-Android with Apache License 2.0 5 votes vote down vote up
public PFFingerprintUIHelper(FingerprintManagerCompat fingerprintManager,
                             ImageView icon, TextView errorTextView,
                             PFFingerprintAuthListener callback) {
    super();
    mFingerprintManager = fingerprintManager;
    mIcon = icon;
    mErrorTextView = errorTextView;
    mCallback = callback;
}
 
Example #4
Source File: FingerprintUiHelper.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
public void startListening(FingerprintManagerCompat.CryptoObject cryptoObject) {
    if (!mListening) {
        mListening = true;
        mCancellationSignal = new CancellationSignal();
        mSelfCancelled = false;
        mFingerprintManagerCompat
                .authenticate(cryptoObject, 0, mCancellationSignal, this, null);
        mSwirlView.setState(SwirlView.State.ON);
    }
}
 
Example #5
Source File: FingerprintUiHelper.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor for {@link FingerprintUiHelper}. This method is expected to be called from
 * only the {@link FingerprintUiHelperBuilder} class.
 */
private FingerprintUiHelper(FingerprintManagerCompat fingerprintManagerCompat, SwirlView swirlView,
                            Callback callback) {
    mFingerprintManagerCompat = fingerprintManagerCompat;
    mSwirlView = swirlView;
    mCallback = callback;
}
 
Example #6
Source File: FingerprintUiHelper.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor for {@link FingerprintUiHelper}. This method is expected to be called from
 * only the {@link FingerprintUiHelperBuilder} class.
 */
private FingerprintUiHelper(FingerprintManagerCompat fingerprintManagerCompat, SwirlView swirlView,
                            Callback callback) {
    mFingerprintManagerCompat = fingerprintManagerCompat;
    mSwirlView = swirlView;
    mCallback = callback;
}
 
Example #7
Source File: FingerprintDialog.java    From samples-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Do not create a new Fragment when the Activity is re-created such as orientation changes.
    setRetainInstance(true);

    mContext = getActivity().getApplicationContext();
    mFingerprintManagerCompat = FingerprintManagerCompat.from(mContext);
    this.setCancelable(false);
}
 
Example #8
Source File: MainActivity.java    From android-biometricprompt with Apache License 2.0 5 votes vote down vote up
/**
 * Indicate whether this device can authenticate the user with biometrics
 * @return true if there are any available biometric sensors and biometrics are enrolled on the device, if not, return false
 */
private boolean canAuthenticateWithBiometrics() {
    // Check whether the fingerprint can be used for authentication (Android M to P)
    if (Build.VERSION.SDK_INT < 29) {
        FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(this);
        return fingerprintManagerCompat.hasEnrolledFingerprints() && fingerprintManagerCompat.isHardwareDetected();
    } else {    // Check biometric manager (from Android Q)
        BiometricManager biometricManager = this.getSystemService(BiometricManager.class);
        if (biometricManager != null) {
            return biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS;
        }
        return false;
    }
}
 
Example #9
Source File: FingerprintUiHelper.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
public void startListening(FingerprintManagerCompat.CryptoObject cryptoObject) {
    if (!mListening) {
        mListening = true;
        mCancellationSignal = new CancellationSignal();
        mSelfCancelled = false;
        mFingerprintManagerCompat
                .authenticate(cryptoObject, 0, mCancellationSignal, this, null);
        mSwirlView.setState(SwirlView.State.ON);
    }
}
 
Example #10
Source File: BiometricLoginUtils.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private static boolean canUseFingerprint(@NonNull Activity activity){
    Context context = getApplicationContext();
    if (fingerprintPermissionGranted(activity)) {
        return FingerprintManagerCompat.from(context).isHardwareDetected();
    }
    return false;
}
 
Example #11
Source File: PFFingerprintUIHelper.java    From PFLockScreen-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
    mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
    mIcon.setImageResource(R.drawable.ic_fingerprint_success_pf);
    mErrorTextView.setTextColor(
            mErrorTextView.getResources().getColor(R.color.success_color, null));
    mErrorTextView.setText(
            mErrorTextView.getResources().getString(R.string.fingerprint_success_pf));
    mIcon.postDelayed(new Runnable() {
        @Override
        public void run() {
            mCallback.onAuthenticated();
        }
    }, SUCCESS_DELAY_MILLIS);
}
 
Example #12
Source File: PFFingerprintUIHelper.java    From PFLockScreen-Android with Apache License 2.0 5 votes vote down vote up
public void startListening(FingerprintManagerCompat.CryptoObject cryptoObject) {
    if (!isFingerprintAuthAvailable()) {
        return;
    }
    mCancellationSignal = new CancellationSignal();
    mSelfCancelled = false;
    // The line below prevents the false positive inspection from Android Studio
    // noinspection ResourceType
    mFingerprintManager.authenticate(
            cryptoObject, 0, mCancellationSignal, this, null);
    mIcon.setImageResource(R.drawable.ic_fp_40px_pf);
}
 
Example #13
Source File: FingerprintUiHelper.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
    mSwirlView.setState(SwirlView.State.OFF);
    mSwirlView.postDelayed(mCallback::onAuthenticated, 100);
}
 
Example #14
Source File: BiometricManagerV23.java    From smart-farmer-android with Apache License 2.0 4 votes vote down vote up
public void displayBiometricPromptV23(final BiometricCallback biometricCallback) {

        if (initCipher()) {

            cryptoObject = new FingerprintManagerCompat.CryptoObject(cipher);
            FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(context);

            fingerprintManagerCompat.authenticate(cryptoObject, 0, mCancellationSignalV23,
                    new FingerprintManagerCompat.AuthenticationCallback() {
                        @Override
                        public void onAuthenticationError(int errMsgId, CharSequence errString) {
                            super.onAuthenticationError(errMsgId, errString);
                            updateStatus(String.valueOf(errString));
                            biometricCallback.onAuthenticationError(errMsgId, errString);
                        }

                        @Override
                        public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                            super.onAuthenticationHelp(helpMsgId, helpString);
                            updateStatus(String.valueOf(helpString));
                            biometricCallback.onAuthenticationHelp(helpMsgId, helpString);
                        }

                        @Override
                        public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
                            super.onAuthenticationSucceeded(result);
                            dismissDialog();
                            biometricCallback.onAuthenticationSuccessful(result.getCryptoObject().getCipher());
                        }


                        @Override
                        public void onAuthenticationFailed() {
                            super.onAuthenticationFailed();
                            updateStatus(context.getString(R.string.biometric_failed));
                            biometricCallback.onAuthenticationFailed();
                        }
                    }, null);

            displayBiometricDialog(biometricCallback);
        }
    }
 
Example #15
Source File: FingerprintUiHelper.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
public FingerprintUiHelperBuilder(FingerprintManagerCompat fingerprintManagerCompat) {
    mFingerprintManagerCompat = fingerprintManagerCompat;
}
 
Example #16
Source File: MaxLockPreferenceFragment.java    From MaxLock with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("WorldReadableFiles")
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle paramBundle) {
    super.onCreate(paramBundle);
    if (getArguments() != null) {
        screen = Screen.valueOf(getArguments().getString(Screen.KEY, Screen.MAIN.toString()));
    } else {
        screen = Screen.MAIN;
    }
    prefs = MLPreferences.getPreferences(getActivity());
    setTitle();
    if (screen == Screen.IMOD) {
        getPreferenceManager().setSharedPreferencesName(Common.PREFS_APPS);
    }
    addPreferencesFromResource(screen.preferenceXML);
    switch (screen) {
        case MAIN:
            updateImplementationStatus();
            PreferenceCategory catAppUI = (PreferenceCategory) findPreference(Common.CATEGORY_APPLICATION_UI);
            CheckBoxPreference useDark = (CheckBoxPreference) findPreference(Common.USE_DARK_STYLE);
            if (!useDark.isChecked()) {
                catAppUI.removePreference(findPreference(Common.USE_AMOLED_BLACK));
            }
            if (SDK_INT >= Build.VERSION_CODES.O) {
                catAppUI.removePreference(findPreference(Common.NEW_APP_NOTIFICATION));
            }
            break;
        case TYPE:
            FingerprintManagerCompat fpm = FingerprintManagerCompat.from(getActivity());
            if (!fpm.isHardwareDetected()) {
                getPreferenceScreen().removePreference(findPreference(Common.SHADOW_FINGERPRINT));
                getPreferenceScreen().removePreference(findPreference(Common.CATEGORY_FINGERPRINT));
            } else {
                CheckBoxPreference disableFP = (CheckBoxPreference) findPreference(Common.DISABLE_FINGERPRINT);
                if (!fpm.hasEnrolledFingerprints() && !disableFP.isChecked()) {
                    disableFP.setSummary(disableFP.getSummary() + getResources().getString(R.string.pref_fingerprint_summary_non_enrolled));
                }
            }
            break;
        case UI:
            ListPreference lp = (ListPreference) findPreference(Common.BACKGROUND);
            findPreference(Common.BACKGROUND_COLOR).setEnabled(lp.getValue().equals("color"));
            lp.setOnPreferenceChangeListener((preference, newValue) -> {
                if (preference.getKey().equals(Common.BACKGROUND)) {
                    if (newValue.toString().equals("custom")) {
                        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                        intent.setType("image/*");
                        startActivityForResult(intent, WALLPAPER_REQUEST_CODE);
                    } else
                        FileUtils.deleteQuietly(new File(getActivity().getFilesDir(), "background"));
                    findPreference(Common.BACKGROUND_COLOR).setEnabled(newValue.toString().equals("color"));
                }
                return true;
            });
            break;
        case OPTIONS:
            Preference el = findPreference(Common.ENABLE_LOGGING);
            el.setEnabled(prefs.getBoolean(Common.ENABLE_PRO, false));
            if (!prefs.getBoolean(Common.ENABLE_PRO, false)) {
                el.setSummary(R.string.toast_pro_required);
            }
            if (MLImplementation.getImplementation(prefs) != MLImplementation.DEFAULT) {
                PreferenceCategory catOther = (PreferenceCategory) findPreference(Common.CATEGORY_OTHER);
                catOther.removePreference(findPreference(Common.HIDE_RECENTS_THUMBNAILS));
            }
            break;
        case IMOD:
            // I.Mod - Pro setup
            Preference iModDelayGlobal = findPreference(Common.ENABLE_DELAY_GENERAL);
            Preference iModDelayPerApp = findPreference(Common.ENABLE_DELAY_PER_APP);
            iModDelayGlobal.setEnabled(prefs.getBoolean(Common.ENABLE_PRO, false));
            iModDelayPerApp.setEnabled(prefs.getBoolean(Common.ENABLE_PRO, false));
            if (!prefs.getBoolean(Common.ENABLE_PRO, false)) {
                iModDelayGlobal.setTitle(R.string.pref_delay_needpro);
                iModDelayPerApp.setTitle(R.string.pref_delay_needpro);
            }
            break;
    }
}
 
Example #17
Source File: SettingsFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onCreatePreferences(Bundle bundle, String s) {
        addPreferencesFromResource(R.xml.settings);

        SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
        if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
            getPreferenceScreen().removePreference(forceEnglish);
        } else {
            forceEnglish.setOnPreferenceChangeListener(this);
        }
/*
        if (Utils.hideStartActivity()) {
            ((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
                    .removePreference(findPreference(KEY_MATERIAL_ICON));
        } else {
            findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
        }
*/
        findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this);
        findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this);
        findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this);
        findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
        findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
        findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
        findPreference(KEY_PRIMARY_COLOR).setOnPreferenceClickListener(this);
        findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
        findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
        findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
        findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);

        if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
            findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
        } else {
            ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(
                    findPreference(KEY_LAST_KMSG));
        }

        findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
        findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
        findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
                || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
            ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference(
                    findPreference(KEY_FINGERPRINT));
        } else {
            mFingerprint = findPreference(KEY_FINGERPRINT);
            mFingerprint.setEnabled(!AppSettings.getPassword(getActivity()).isEmpty());
        }

        NavigationActivity activity = (NavigationActivity) getActivity();
        PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
        for (NavigationActivity.NavigationFragment navigationFragment : activity.getFragments()) {
            Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
            int id = navigationFragment.mId;

            if (fragmentClass != null && fragmentClass != SettingsFragment.class) {
                SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(
                        new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
                switchPreference.setSummary(getString(id));
                switchPreference.setKey(fragmentClass.getSimpleName() + "_enabled");
                switchPreference.setChecked(AppSettings.isFragmentEnabled(fragmentClass, getActivity()));
                switchPreference.setOnPreferenceChangeListener(this);
                switchPreference.setPersistent(true);
                sectionsCategory.addPreference(switchPreference);
            }
        }
    }
 
Example #18
Source File: FingerprintUiHelper.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
    mSwirlView.setState(SwirlView.State.OFF);
    mSwirlView.postDelayed(mCallback::onAuthenticated, 100);
}
 
Example #19
Source File: FingerprintUiHelper.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 4 votes vote down vote up
public FingerprintUiHelperBuilder(FingerprintManagerCompat fingerprintManagerCompat) {
    mFingerprintManagerCompat = fingerprintManagerCompat;
}
 
Example #20
Source File: FingerprintDialog.java    From samples-android with Apache License 2.0 4 votes vote down vote up
public void init(FingerprintManagerCompat.CryptoObject object, FingerprintDialogCallbacks fingerprintDialogCallbacks) {
    mCryptoObject = object;
    mFingerprintDialogCallbacks = new WeakReference<>(fingerprintDialogCallbacks);
}
 
Example #21
Source File: PFFingerprintPinCodeHelper.java    From PFLockScreen-Android with Apache License 2.0 4 votes vote down vote up
private boolean isFingerPrintReady(Context context) {
    return FingerprintManagerCompat.from(context).hasEnrolledFingerprints();
}
 
Example #22
Source File: PFFingerprintPinCodeHelper.java    From PFLockScreen-Android with Apache License 2.0 4 votes vote down vote up
private boolean isFingerPrintAvailable(Context context) {
    return FingerprintManagerCompat.from(context).isHardwareDetected();
}
 
Example #23
Source File: PFLockScreenFragment.java    From PFLockScreen-Android with Apache License 2.0 4 votes vote down vote up
private boolean isFingerprintsExists(Context context) {
    return FingerprintManagerCompat.from(context).hasEnrolledFingerprints();
}
 
Example #24
Source File: PFLockScreenFragment.java    From PFLockScreen-Android with Apache License 2.0 4 votes vote down vote up
private boolean isFingerprintApiAvailable(Context context) {
    return FingerprintManagerCompat.from(context).isHardwareDetected();
}
 
Example #25
Source File: BiometricUtils.java    From smart-farmer-android with Apache License 2.0 2 votes vote down vote up
/**
 * Condition II: Check if the device has fingerprint sensors.
 * Note: If you marked android.hardware.fingerprint as something that
 * your app requires (android:required="true"), then you don't need
 * to perform this check.
 */
public static boolean isHardwareSupported(Context context) {
    FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.from(context);
    return fingerprintManager.isHardwareDetected();
}
 
Example #26
Source File: BiometricUtils.java    From smart-farmer-android with Apache License 2.0 2 votes vote down vote up
/**
 * Condition III: Fingerprint authentication can be matched with a
 * registered fingerprint of the user. So we need to perform this check
 * in order to enable fingerprint authentication
 */
public static boolean isFingerprintAvailable(Context context) {
    FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.from(context);
    return fingerprintManager.hasEnrolledFingerprints();
}