Search in sources :

Example 31 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project android-fingerprint-authentication by multidots.

the class FingerPrintAuthHelper method startAuth.

/**
 * Start the finger print authentication by enabling the finger print sensor.
 * Note: Use this function in the onResume() of the activity/fragment. Never forget to call {@link #stopAuth()}
 * in onPause() of the activity/fragment.
 */
@TargetApi(Build.VERSION_CODES.M)
public void startAuth() {
    if (isScanning)
        stopAuth();
    // check if the device supports the finger print hardware?
    if (!checkFingerPrintAvailability(mContext))
        return;
    FingerprintManager fingerprintManager = (FingerprintManager) mContext.getSystemService(Context.FINGERPRINT_SERVICE);
    FingerprintManager.CryptoObject cryptoObject = getCryptoObject();
    if (cryptoObject == null) {
        mCallback.onAuthFailed(AuthErrorCodes.NON_RECOVERABLE_ERROR, ERROR_FAILED_TO_INIT_CHIPPER);
    } else {
        mCancellationSignal = new CancellationSignal();
        // noinspection MissingPermission
        fingerprintManager.authenticate(cryptoObject, mCancellationSignal, 0, new FingerprintManager.AuthenticationCallback() {

            @Override
            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                mCallback.onAuthFailed(AuthErrorCodes.NON_RECOVERABLE_ERROR, errString.toString());
            }

            @Override
            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                mCallback.onAuthFailed(AuthErrorCodes.RECOVERABLE_ERROR, helpString.toString());
            }

            @Override
            public void onAuthenticationFailed() {
                mCallback.onAuthFailed(AuthErrorCodes.CANNOT_RECOGNIZE_ERROR, null);
            }

            @Override
            public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
                mCallback.onAuthSuccess(result.getCryptoObject());
            }
        }, null);
    }
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) CancellationSignal(android.os.CancellationSignal) TargetApi(android.annotation.TargetApi)

Example 32 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project platform_packages_apps_Settings by BlissRoms.

the class FingerprintEnrollFinish method onResume.

@Override
protected void onResume() {
    super.onResume();
    Button addButton = (Button) findViewById(R.id.add_another_button);
    final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
    boolean hideAddAnother = false;
    if (fpm != null) {
        int enrolled = fpm.getEnrolledFingerprints(mUserId).size();
        int max = getResources().getInteger(com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
        hideAddAnother = enrolled >= max;
    }
    if (hideAddAnother) {
        // Don't show "Add" button if too many fingerprints already added
        addButton.setVisibility(View.INVISIBLE);
    } else {
        addButton.setOnClickListener(this);
    }
}
Also used : Button(android.widget.Button) FingerprintManager(android.hardware.fingerprint.FingerprintManager)

Example 33 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project platform_packages_apps_Settings by BlissRoms.

the class SecuritySettingsTest method testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint.

@Test
public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
    final FingerprintManager fpm = mock(FingerprintManager.class);
    when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(false);
    mSummaryProvider.setListening(true);
    verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) Test(org.junit.Test)

Example 34 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project platform_packages_apps_Settings by BlissRoms.

the class SecuritySettingsTest method testSummaryProvider_hasFingerPrint_hasStaticSummary.

@Test
public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
    final FingerprintManager fpm = mock(FingerprintManager.class);
    when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
    // Cast to Object to workaround a robolectric casting bug
    when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
    when(fpm.isHardwareDetected()).thenReturn(true);
    mSummaryProvider.setListening(true);
    verify(mContext).getString(R.string.security_dashboard_summary);
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) Test(org.junit.Test)

Example 35 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project afwall by ukanth.

the class SecPreferenceFragment method checkFingerprintDeviceSupport.

@TargetApi(Build.VERSION_CODES.M)
private void checkFingerprintDeviceSupport() {
    // Initializing both Android Keyguard Manager and Fingerprint Manager
    KeyguardManager keyguardManager = (KeyguardManager) globalContext.getSystemService(KEYGUARD_SERVICE);
    FingerprintManager fingerprintManager = (FingerprintManager) globalContext.getSystemService(FINGERPRINT_SERVICE);
    ListPreference itemList = (ListPreference) findPreference("passSetting");
    // Check whether the device has a Fingerprint sensor.
    if (!fingerprintManager.isHardwareDetected()) {
        Api.toast(globalContext, getString(R.string.device_with_no_fingerprint_sensor));
        itemList.setValueIndex(0);
    } else {
        // Checks whether fingerprint permission is set on manifest
        if (ActivityCompat.checkSelfPermission(globalContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            Api.toast(globalContext, getString(R.string.fingerprint_permission_manifest_missing));
            itemList.setValueIndex(0);
        } else {
            // Check whether at least one fingerprint is registered
            if (!fingerprintManager.hasEnrolledFingerprints()) {
                Api.toast(globalContext, getString(R.string.register_at_least_one_fingerprint));
                itemList.setValueIndex(0);
            } else {
                // Checks whether lock screen security is enabled or not
                if (!keyguardManager.isKeyguardSecure()) {
                    Api.toast(globalContext, getString(R.string.lock_screen_not_enabled));
                    itemList.setValueIndex(0);
                } else {
                    // Anything is ok
                    if (!G.isFingerprintEnabled()) {
                        G.isFingerprintEnabled(true);
                        // make sure we set the index
                        itemList.setValueIndex(3);
                        Api.toast(globalContext, getString(R.string.fingerprint_enabled_successfully));
                    }
                    return;
                }
            }
        }
    }
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) ListPreference(android.preference.ListPreference) KeyguardManager(android.app.KeyguardManager) TargetApi(android.annotation.TargetApi)

Aggregations

FingerprintManager (android.hardware.fingerprint.FingerprintManager)82 Test (org.junit.Test)18 Intent (android.content.Intent)11 ComponentName (android.content.ComponentName)8 Button (android.widget.Button)8 KeyguardManager (android.app.KeyguardManager)7 Context (android.content.Context)7 Fingerprint (android.hardware.fingerprint.Fingerprint)7 UserManager (android.os.UserManager)7 Preference (android.support.v7.preference.Preference)7 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)7 SpannableString (android.text.SpannableString)7 TextPaint (android.text.TextPaint)7 LockPatternUtils (com.android.internal.widget.LockPatternUtils)7 FingerprintEnrollSuggestionActivity (com.android.settings.Settings.FingerprintEnrollSuggestionActivity)6 FingerprintSuggestionActivity (com.android.settings.fingerprint.FingerprintSuggestionActivity)6 WallpaperSuggestionActivity (com.android.settings.wallpaper.WallpaperSuggestionActivity)6 TwoTargetPreference (com.android.settingslib.TwoTargetPreference)6 FooterPreference (com.android.settingslib.widget.FooterPreference)6 FaceManager (android.hardware.face.FaceManager)5