android.support.v4.hardware.fingerprint.FingerprintManagerCompat Java Examples

The following examples show how to use android.support.v4.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: FingerAuth.java    From FingerAuth with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    failedCount = 0;

    authenticationCallback = new FingerprintManagerCompat.AuthenticationCallback() {
        @Override
        public void onAuthenticationFailed() {
            failedCount++;
            if (failedCount == maxFailedCount) {
                failedCount = 0;
                if (onFingerAuthListener != null) {
                    cancelSignal();
                    onFingerAuthListener.onError();
                }
            } else {
                onFingerAuthListener.onFailure();
            }
        }

        @Override
        public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
            if (onFingerAuthListener != null) {
                cancelSignal();
                onFingerAuthListener.onSuccess();
            }
        }
    };

    fingerprintManagerCompat = FingerprintManagerCompat.from(context);
    cancellationSignal = new CancellationSignal();

    fingerprintManagerCompat.authenticate(null, 0, cancellationSignal, authenticationCallback, null);
}
 
Example #2
Source File: FingerAuth.java    From FingerAuth with Apache License 2.0 5 votes vote down vote up
public static boolean hasFingerprintSupport(Context context) {
    FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.from(context);
    boolean hardwareSupport = fingerprintManager.isHardwareDetected();

    boolean secureSupport = true;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        if (keyguardManager!=null)
            secureSupport = keyguardManager.isKeyguardSecure();
    }

    boolean hasPwd = fingerprintManager.hasEnrolledFingerprints();
    return hardwareSupport && secureSupport && hasPwd;
}
 
Example #3
Source File: MyAuthCallback.java    From AndroidFingerPrintDemo with Apache License 2.0 5 votes vote down vote up
@Override
public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
    super.onAuthenticationSucceeded(result);

    if (handler != null) {
        handler.obtainMessage(MainActivity.MSG_AUTH_SUCCESS).sendToTarget();
    }
}
 
Example #4
Source File: MainActivity.java    From journaldev with MIT License 5 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.button:
            managerCompat = FingerprintManagerCompat.from(MainActivity.this);

            if (managerCompat.isHardwareDetected() && managerCompat.hasEnrolledFingerprints()) {
                showFingerPrintDialog();
            } else {
                Toast.makeText(getApplicationContext(), "Fingerprint not supported", Toast.LENGTH_SHORT).show();
            }
            break;
    }
}
 
Example #5
Source File: FingerprintUiHelper.java    From KernelAdiutor 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 KernelAdiutor 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 #7
Source File: FingerprintUtils.java    From FingerprintDialogCompat with Apache License 2.0 4 votes vote down vote up
public static boolean isFingerprintEnroled(@NonNull final Context context) {
    FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.from(context);
    return fingerprintManager.hasEnrolledFingerprints();
}
 
Example #8
Source File: CryptoObjectHelper.java    From AndroidFingerPrintDemo with Apache License 2.0 4 votes vote down vote up
public FingerprintManagerCompat.CryptoObject buildCryptoObject() throws Exception
{
    Cipher cipher = createCipher(true);
    return new FingerprintManagerCompat.CryptoObject(cipher);
}
 
Example #9
Source File: Utils.java    From always-on-amoled with GNU General Public License v3.0 4 votes vote down vote up
public static boolean hasFingerprintSensor(Context context) {
    FingerprintManagerCompat manager = FingerprintManagerCompat.from(context);
    return manager.isHardwareDetected() && manager.hasEnrolledFingerprints();
}
 
Example #10
Source File: SettingsFragment.java    From KernelAdiutor 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);

    if (Utils.DONATED) {
        getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW));
    }

    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_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 #11
Source File: FingerprintUiHelper.java    From KernelAdiutor with GNU General Public License v3.0 4 votes vote down vote up
public FingerprintUiHelperBuilder(FingerprintManagerCompat fingerprintManagerCompat) {
    mFingerprintManagerCompat = fingerprintManagerCompat;
}
 
Example #12
Source File: FingerprintUiHelper.java    From KernelAdiutor 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 #13
Source File: FingerprintUtils.java    From FingerprintDialogCompat with Apache License 2.0 2 votes vote down vote up
/**
 * Check if the device have supported hardware fir the finger print scanner.
 *
 * @param context instance of the caller.
 * @return true if device have the hardware.
 */
public static boolean isSupportedHardware(@NonNull final Context context) {
    FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.from(context);
    return fingerprintManager.isHardwareDetected();
}