summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/lineage/LineageUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/lineage/LineageUtils.java')
-rw-r--r--src/com/android/launcher3/lineage/LineageUtils.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/com/android/launcher3/lineage/LineageUtils.java b/src/com/android/launcher3/lineage/LineageUtils.java
new file mode 100644
index 000000000..75a9252dd
--- /dev/null
+++ b/src/com/android/launcher3/lineage/LineageUtils.java
@@ -0,0 +1,78 @@
+package com.android.launcher3.lineage;
+
+import android.app.KeyguardManager;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.hardware.biometrics.BiometricPrompt;
+import android.os.CancellationSignal;
+import android.os.Handler;
+import android.os.Looper;
+import android.widget.Toast;
+
+import com.android.launcher3.R;
+
+public class LineageUtils {
+
+ /**
+ * 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 title the {@code String} which will be shown as the pompt title
+ * @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, String title, Runnable successRunnable) {
+ if (hasSecureKeyguard(context)) {
+ 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(title);
+
+ final KeyguardManager keyguardManager = context.getSystemService(KeyguardManager.class);
+
+ 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 {
+ // Notify the user a secure keyguard is required for protected apps,
+ // but allow to set hidden apps
+ Toast.makeText(context, R.string.trust_apps_no_lock_error, Toast.LENGTH_LONG)
+ .show();
+ successRunnable.run();
+ }
+ }
+
+ public static boolean hasSecureKeyguard(Context context) {
+ final KeyguardManager keyguardManager = context.getSystemService(KeyguardManager.class);
+ return keyguardManager != null && keyguardManager.isKeyguardSecure();
+ }
+
+ public static boolean hasPackageInstalled(Context context, String pkgName) {
+ try {
+ ApplicationInfo ai = context.getPackageManager().getApplicationInfo(pkgName, 0);
+ return ai.enabled;
+ } catch (PackageManager.NameNotFoundException e) {
+ return false;
+ }
+ }
+}