<commit_before>package com.itachi1706.cheesecakeutilities.Features.FingerprintAuth;

import android.Manifest;
import android.annotation.TargetApi;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;

import java.util.concurrent.Executor;

import androidx.biometrics.BiometricPrompt;
import androidx.core.content.ContextCompat;
import androidx.core.hardware.fingerprint.FingerprintManagerCompat;

/**
 * Created by Kenneth on 14/12/2018.
 * for com.itachi1706.appupdater.extlib.fingerprint in CheesecakeUtilities
 */
public class BiometricCompatHelper {

    private BiometricCompatHelper() {
        throw new IllegalStateException("Utility class. Do not instantiate");
    }

    public static final String APP_BIOMETRIC_COMPAT_ENABLED = "app_bio_compat_enable";

    /**
     * Check if we need to authenticate with Fingerprint through the BiometricPromptCompat API
     * @param sp Shared Preference Object
     * @return true if require fingerprint, false otherwise
     */
    public static boolean requireFPAuth(SharedPreferences sp) {
        return sp.getBoolean(APP_BIOMETRIC_COMPAT_ENABLED, false);
    }

    @TargetApi(Build.VERSION_CODES.M)
    public static boolean isBiometricFPRegistered(Context context) throws NullPointerException {
        if (!isBiometricAuthFPAvailable(context)) return false;
        //noinspection ResourceType

        KeyguardManager km = context.getSystemService(KeyguardManager.class);
        if (km == null) {
            Log.e("BioCompat", "Keyguard died!");
            return false;
        }
        FingerprintManagerCompat fpCompat = FingerprintManagerCompat.from(context);
        return km.isKeyguardSecure() && fpCompat.hasEnrolledFingerprints();
    }

    public static Executor getBiometricExecutor() {
        return Runnable::run;
    }

    public static boolean isBiometricAuthFPAvailable(Context context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
        int granted = ContextCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
            int granted2 = ContextCompat.checkSelfPermission(context, Manifest.permission.USE_BIOMETRIC);
            if (granted2 != PackageManager.PERMISSION_GRANTED) return false;
        }
        if (granted != PackageManager.PERMISSION_GRANTED) return false;

        FingerprintManagerCompat fpCompat = FingerprintManagerCompat.from(context);
        return fpCompat.isHardwareDetected() && fpCompat.hasEnrolledFingerprints();
    }

    public static BiometricPrompt.PromptInfo createPromptObject() {
        return createPromptObject("Sign In", null, "Confirm fingerprint to continue");
    }

    public static BiometricPrompt.PromptInfo createPromptObject(String title, String subtitle, String description) {
        return createPromptObject(title, subtitle, description, "Cancel");
    }

    public static BiometricPrompt.PromptInfo createPromptObject(String title, String subtitle, String description, String negativeBtn) {
        return new BiometricPrompt.PromptInfo.Builder().setTitle(title).setSubtitle(subtitle).setDescription(description).setNegativeButtonText(negativeBtn).build();
    }
}
<commit_msg>Added helper methods for screen lock validation<commit_after>package com.itachi1706.cheesecakeutilities.Features.FingerprintAuth;

import android.Manifest;
import android.annotation.TargetApi;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;

import java.util.concurrent.Executor;

import androidx.biometrics.BiometricPrompt;
import androidx.core.content.ContextCompat;
import androidx.core.hardware.fingerprint.FingerprintManagerCompat;

/**
 * Created by Kenneth on 14/12/2018.
 * for com.itachi1706.appupdater.extlib.fingerprint in CheesecakeUtilities
 */
public class BiometricCompatHelper {

    private BiometricCompatHelper() {
        throw new IllegalStateException("Utility class. Do not instantiate");
    }

    public static final String APP_BIOMETRIC_COMPAT_ENABLED = "app_bio_compat_enable", SCREEN_LOCK_ENABLED = "app_screen_lock_protection";

    /**
     * Check if we need to authenticate with Fingerprint through the BiometricPromptCompat API
     * @param sp Shared Preference Object
     * @return true if require fingerprint, false otherwise
     */
    public static boolean requireFPAuth(SharedPreferences sp) {
        return sp.getBoolean(APP_BIOMETRIC_COMPAT_ENABLED, false);
    }

    @TargetApi(Build.VERSION_CODES.M)
    public static boolean isBiometricFPRegistered(Context context) throws NullPointerException {
        if (!isBiometricAuthFPAvailable(context)) return false;
        //noinspection ResourceType

        KeyguardManager km = context.getSystemService(KeyguardManager.class);
        if (km == null) {
            Log.e("BioCompat", "Keyguard died!");
            return false;
        }
        FingerprintManagerCompat fpCompat = FingerprintManagerCompat.from(context);
        return km.isKeyguardSecure() && fpCompat.hasEnrolledFingerprints();
    }

    public static Executor getBiometricExecutor() {
        return Runnable::run;
    }

    public static boolean isBiometricAuthFPAvailable(Context context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
        int granted = ContextCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
            int granted2 = ContextCompat.checkSelfPermission(context, Manifest.permission.USE_BIOMETRIC);
            if (granted2 != PackageManager.PERMISSION_GRANTED) return false;
        }
        if (granted != PackageManager.PERMISSION_GRANTED) return false;

        FingerprintManagerCompat fpCompat = FingerprintManagerCompat.from(context);
        return fpCompat.isHardwareDetected() && fpCompat.hasEnrolledFingerprints();
    }

    public static BiometricPrompt.PromptInfo createPromptObject() {
        return createPromptObject("Sign In", null, "Confirm fingerprint to continue");
    }

    public static BiometricPrompt.PromptInfo createPromptObject(String title, String subtitle, String description) {
        return createPromptObject(title, subtitle, description, "Cancel");
    }

    public static BiometricPrompt.PromptInfo createPromptObject(String title, String subtitle, String description, String negativeBtn) {
        return new BiometricPrompt.PromptInfo.Builder().setTitle(title).setSubtitle(subtitle).setDescription(description).setNegativeButtonText(negativeBtn).build();
    }

    public static boolean isScreenLockEnabled(Context context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return false; // Not supported prior to Lollipop

        KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        if (km == null) {
            Log.e("BioCompat", "Keyguard died!");
            return false;
        }

        return km.isKeyguardSecure();
    }

    public static boolean isScreenLockProtectionEnabled(Context context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return false; // Not supported prior to Lollipop

        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        if (!sp.contains(SCREEN_LOCK_ENABLED) || !sp.getBoolean(SCREEN_LOCK_ENABLED, false)) return false;
        return isScreenLockEnabled(context);
    }
}

{'fraction_non_alphanumeric': 0.08367451381780962, 'fraction_numerical': 0.004605936540429887, 'mean_word_length': 4.125901639344263, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6726117', 'n_tokens_mistral': 2197, 'n_tokens_neox': 2146, 'n_words': 463}