Search in sources :

Example 81 with KeyguardManager

use of android.app.KeyguardManager in project QR-Code-Based-Attendance-System by ishan0445.

the class FingerprintActivity method onCreate.

@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fingerprint);
    // Initializing both Android Keyguard Manager and Fingerprint Manager
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
    textView = (TextView) findViewById(R.id.errorText);
    // Check whether the device has a Fingerprint sensor.
    if (!fingerprintManager.isHardwareDetected()) {
        /**
         * An error message will be displayed if the device does not contain the fingerprint hardware.
         * However if you plan to implement a default authentication method,
         * you can redirect the user to a default authentication activity from here.
         * Example:
         * Intent intent = new Intent(this, DefaultAuthenticationActivity.class);
         * startActivity(intent);
         */
        textView.setText("Your Device does not have a Fingerprint Sensor");
    } else {
        // Checks whether fingerprint permission is set on manifest
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            textView.setText("Fingerprint authentication permission not enabled");
        } else {
            // Check whether at least one fingerprint is registered
            if (!fingerprintManager.hasEnrolledFingerprints()) {
                textView.setText("Register at least one fingerprint in Settings");
            } else {
                // Checks whether lock screen security is enabled or not
                if (!keyguardManager.isKeyguardSecure()) {
                    textView.setText("Lock screen security not enabled in Settings");
                } else {
                    generateKey();
                    if (cipherInit()) {
                        FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
                        FingerprintHandler helper = new FingerprintHandler(this);
                        helper.startAuth(fingerprintManager, cryptoObject);
                    }
                }
            }
        }
    }
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) KeyguardManager(android.app.KeyguardManager) RequiresApi(android.support.annotation.RequiresApi)

Example 82 with KeyguardManager

use of android.app.KeyguardManager in project afwall by ukanth.

the class SecPreferenceFragment method canUserFingerPrint.

@TargetApi(Build.VERSION_CODES.M)
private boolean canUserFingerPrint() {
    KeyguardManager keyguardManager = (KeyguardManager) globalContext.getSystemService(KEYGUARD_SERVICE);
    FingerprintManager fingerprintManager = (FingerprintManager) globalContext.getSystemService(FINGERPRINT_SERVICE);
    return fingerprintManager.isHardwareDetected() && ActivityCompat.checkSelfPermission(globalContext, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED && fingerprintManager.hasEnrolledFingerprints() && keyguardManager.isKeyguardSecure();
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) KeyguardManager(android.app.KeyguardManager) TargetApi(android.annotation.TargetApi)

Example 83 with KeyguardManager

use of android.app.KeyguardManager in project platform_packages_apps_Settings by BlissRoms.

the class Utils method confirmWorkProfileCredentials.

private static boolean confirmWorkProfileCredentials(Context context, int userId) {
    final KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    final Intent unlockIntent = km.createConfirmDeviceCredentialIntent(null, null, userId);
    if (unlockIntent != null) {
        context.startActivity(unlockIntent);
        return true;
    } else {
        return false;
    }
}
Also used : Intent(android.content.Intent) KeyguardManager(android.app.KeyguardManager)

Example 84 with KeyguardManager

use of android.app.KeyguardManager 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 85 with KeyguardManager

use of android.app.KeyguardManager in project KJFrameForAndroid by kymjs.

the class SystemTool method isSleeping.

/**
 * 判断手机是否处理睡眠
 */
public static boolean isSleeping(Context context) {
    KeyguardManager kgMgr = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    boolean isSleeping = kgMgr.inKeyguardRestrictedInputMode();
    return isSleeping;
}
Also used : KeyguardManager(android.app.KeyguardManager)

Aggregations

KeyguardManager (android.app.KeyguardManager)94 Intent (android.content.Intent)44 PendingIntent (android.app.PendingIntent)18 PowerManager (android.os.PowerManager)17 Context (android.content.Context)12 SuppressLint (android.annotation.SuppressLint)10 IIntentSender (android.content.IIntentSender)10 IntentSender (android.content.IntentSender)10 FingerprintManager (android.hardware.fingerprint.FingerprintManager)7 Resources (android.content.res.Resources)5 TelephonyManager (android.telephony.TelephonyManager)5 TargetApi (android.annotation.TargetApi)4 ConnectivityManager (android.net.ConnectivityManager)4 RemoteException (android.os.RemoteException)4 Activity (android.app.Activity)3 NotificationManager (android.app.NotificationManager)3 Bitmap (android.graphics.Bitmap)3 NetworkInfo (android.net.NetworkInfo)3 DialogFragment (android.app.DialogFragment)2 Notification (android.app.Notification)2