blob: d328dd896a7667870fb15f15a94a7972adbbfc77 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
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) {
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(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 {
Toast.makeText(context, R.string.trust_apps_no_lock_error, Toast.LENGTH_LONG)
.show();
}
}
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;
}
}
}
|