Search in sources :

Example 1 with BiometricPrompt

use of android.hardware.biometrics.BiometricPrompt in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiDppUtils method showLockScreen.

/**
 * Shows authentication screen to confirm credentials (pin, pattern or password) for the current
 * user of the device.
 *
 * @param context The {@code Context} used to get {@code KeyguardManager} service
 * @param successRunnable The {@code Runnable} which will be executed if the user does not setup
 *                        device security or if lock screen is unlocked
 */
public static void showLockScreen(Context context, Runnable successRunnable) {
    final KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    if (keyguardManager.isKeyguardSecure()) {
        final BiometricPrompt.AuthenticationCallback authenticationCallback = new BiometricPrompt.AuthenticationCallback() {

            @Override
            public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
                successRunnable.run();
            }

            @Override
            public void onAuthenticationError(int errorCode, CharSequence errString) {
            // Do nothing
            }
        };
        final BiometricPrompt.Builder builder = new BiometricPrompt.Builder(context).setTitle(context.getText(R.string.wifi_dpp_lockscreen_title));
        if (keyguardManager.isDeviceSecure()) {
            builder.setDeviceCredentialAllowed(true);
        }
        final BiometricPrompt bp = builder.build();
        final Handler handler = new Handler(Looper.getMainLooper());
        bp.authenticate(new CancellationSignal(), runnable -> handler.post(runnable), authenticationCallback);
    } else {
        successRunnable.run();
    }
}
Also used : BiometricPrompt(android.hardware.biometrics.BiometricPrompt) Handler(android.os.Handler) KeyguardManager(android.app.KeyguardManager) CancellationSignal(android.os.CancellationSignal)

Example 2 with BiometricPrompt

use of android.hardware.biometrics.BiometricPrompt in project android_packages_apps_Settings by omnirom.

the class WifiDppUtils method showLockScreen.

/**
 * Shows authentication screen to confirm credentials (pin, pattern or password) for the current
 * user of the device.
 *
 * @param context The {@code Context} used to get {@code KeyguardManager} service
 * @param successRunnable The {@code Runnable} which will be executed if the user does not setup
 *                        device security or if lock screen is unlocked
 */
public static void showLockScreen(Context context, Runnable successRunnable) {
    final KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    if (keyguardManager.isKeyguardSecure()) {
        final BiometricPrompt.AuthenticationCallback authenticationCallback = new BiometricPrompt.AuthenticationCallback() {

            @Override
            public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
                successRunnable.run();
            }

            @Override
            public void onAuthenticationError(int errorCode, CharSequence errString) {
            // Do nothing
            }
        };
        final BiometricPrompt.Builder builder = new BiometricPrompt.Builder(context).setTitle(context.getText(R.string.wifi_dpp_lockscreen_title));
        if (keyguardManager.isDeviceSecure()) {
            builder.setDeviceCredentialAllowed(true);
        }
        final BiometricPrompt bp = builder.build();
        final Handler handler = new Handler(Looper.getMainLooper());
        bp.authenticate(new CancellationSignal(), runnable -> handler.post(runnable), authenticationCallback);
    } else {
        successRunnable.run();
    }
}
Also used : BiometricPrompt(android.hardware.biometrics.BiometricPrompt) Handler(android.os.Handler) KeyguardManager(android.app.KeyguardManager) CancellationSignal(android.os.CancellationSignal)

Aggregations

KeyguardManager (android.app.KeyguardManager)2 BiometricPrompt (android.hardware.biometrics.BiometricPrompt)2 CancellationSignal (android.os.CancellationSignal)2 Handler (android.os.Handler)2