/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package co.infinum.goldfinger.crypto;
import co.infinum.goldfinger.Goldfinger;
import co.infinum.goldfinger.MissingHardwareException;
import co.infinum.goldfinger.FaceAuthResult;
import ohos.aafwk.ability.Ability;
import ohos.biometrics.authentication.BiometricAuthentication;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* A reprint module that authenticates fingerprint using the marshmallow Imprint API.
* <p/>
* This module supports most phones running Marshmallow.
* <p/>
* The values of error codes provided by the api overlap for fatal and non-fatal authentication
* failures. Fatal error code constants start with FINGERPRINT_ERROR, and non-fatal error codes
* start with FINGERPRINT_ACQUIRED.
*/
public class MarshmallowReprintModule implements ReprintModule {
public static final int TAG = 1;
private final Ability context;
private Goldfinger.Logger logger;
private BiometricAuthentication.SecureLevel level;
private BiometricAuthentication.AuthType type;
private boolean isLocalAuth;
private BiometricAuthentication mBiometricAuthentication;
private Goldfinger.Callback listener;
private Goldfinger.RestartPredicate restartPredicate;
private int reStartCount = 5;
private String key;
private String value;
private static final int POOL_CORE_SIZE = 2;
private static final int POOL_MAX_SIZE = 5;
private static final int NO_FACE_RET = -1;
private static final int KEEP_ALIVE_TIME = 3;
private static final int QUEUE_SIZE = 6;
private static final int RET_NOT_SUPPORTED = 1;
private static final int RET_SAFE_LEVEL_NOT_SUPPORTED = 2;
private static final int RET_NOT_LOCAL = 3;
public MarshmallowReprintModule(Ability context, Goldfinger.Logger logger) {
this.context = context;
this.logger = logger;
}
private BiometricAuthentication getBiometricAuthentication() {
try {
return BiometricAuthentication.getInstance(context);
} catch (IllegalAccessException e) {
e.printStackTrace();
return null;
}
}
@Override
public int tag() {
return TAG;
}
@Override
public void init(BiometricAuthentication.AuthType type, BiometricAuthentication.SecureLevel level) {
this.level = level;
this.type = type;
}
/**
* 检验设备是否有人脸识别功能
* BiometricAuthentication.AuthType中有三个类别
* 分别为AUTH_TYPE_BIOMETRIC_FINGERPRINT_ONLY指纹识别
* AUTH_TYPE_BIOMETRIC_FACE_ONLY脸部识别
* AUTH_TYPE_BIOMETRIC_ALL指纹和面部
* BiometricAuthentication.SecureLevel 2D人脸识别建议使用SECURE_LEVEL_S2,3D人脸识别建议使用SECURE_LEVEL_S3
*
* @return retChkAuthAvb 0是支持,1是不支持,2安全级别不支持 3不是本地认证 4无人脸录入
*/
@Override
public int isHardwarePresent() {
try {
mBiometricAuthentication = getBiometricAuthentication();
if (mBiometricAuthentication == null) {
return FaceAuthResult.ERROR_UNKNOWN;
}
int retChkAuthAvb = mBiometricAuthentication.checkAuthenticationAvailability(
type, level, true);
return retChkAuthAvb;
} catch (Exception e) {
logger.logException(e, "MarshmallowReprintModule: isHardwareDetected failed unexpectedly");
return FaceAuthResult.ERROR_UNKNOWN;
}
}
@Override
public void authenticate(final BiometricAuthentication mBiometricAuthentication,
final Goldfinger.Callback listener,
final Goldfinger.RestartPredicate restartPredicate) {
this.mBiometricAuthentication = mBiometricAuthentication;
this.listener = listener;
this.restartPredicate = restartPredicate;
authenticate(mBiometricAuthentication, listener, restartPredicate, 5, null, null);
}
@Override
public void authenticate(BiometricAuthentication mBiometricAuthentication, Goldfinger.Callback listener, Goldfinger.RestartPredicate restartPredicate, String key, String value) {
this.mBiometricAuthentication = mBiometricAuthentication;
this.listener = listener;
this.restartPredicate = restartPredicate;
this.key = key;
this.value = value;
authenticate(mBiometricAuthentication, listener, restartPredicate, 5, key, value);
}
/**
* 取消 人脸识别
*
* @return 成功
*/
@Override
public int cancelAuthentication() {
mBiometricAuthentication = getBiometricAuthentication();
if (mBiometricAuthentication == null) {
return FaceAuthResult.ERROR_UNKNOWN;
}
return mBiometricAuthentication.cancelAuthenticationAction();
}
void authenticate(final BiometricAuthentication mBiometricAuthentication,
final Goldfinger.Callback listener,
final Goldfinger.RestartPredicate restartPredicate,
int restartCount,
String key,
String value) throws SecurityException {
this.mBiometricAuthentication = mBiometricAuthentication;
this.listener = listener;
this.restartPredicate = restartPredicate;
this.reStartCount = restartCount;
this.key = key;
this.value = value;
if (mBiometricAuthentication == null) {
listener.onError(new MissingHardwareException(FaceAuthResult.getString(context, ResourceTable.String_ERROR_UNKNOWN)));
return;
}
ThreadPoolExecutor pool = new ThreadPoolExecutor(
POOL_CORE_SIZE, POOL_MAX_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(QUEUE_SIZE), new ThreadPoolExecutor.DiscardOldestPolicy());
pool.submit(runnable);
}
/**
* 新建线程进行认证,避免阻塞其他任务
*/
private Runnable runnable = new Runnable() {
@Override
public void run() {
// 开始认证
int retExcAuth = mBiometricAuthentication.execAuthenticationAction(
type,
level,
isLocalAuth,
false,
null);
// LogUtil.LogE("retExcAuth:"+retExcAuth);
//获得认证过程中的提示信息
BiometricAuthentication.AuthenticationTips mTips = mBiometricAuthentication.getAuthenticationTips();
if (listener == null) {
listener.onResult(new Goldfinger.Result(Goldfinger.Type.ERROR, FaceAuthResult.ERROR_UNKNOWN, value, "AuthenticationListener is null", mTips.tipValue, TAG));
return;
}
if (mTips.tipValue == 0) {//成功回调
listener.onResult(new Goldfinger.Result(Goldfinger.Type.SUCCESS, FaceAuthResult.AUTH_SUCCESS, value, "认证成功", mTips.errorCode, TAG));
} else if (mTips.tipValue == 1) {//验证失败 不是本人
listener.onResult(new Goldfinger.Result(Goldfinger.Type.ERROR, FaceAuthResult.AUTH_FAIL, value, mTips.tipInfo, mTips.errorCode, TAG));
} else if (mTips.tipValue == 3) {//超时
int i = reStartCount + 1;
if (i <= reStartCount)
没有合适的资源?快使用搜索试试~ 我知道了~
基于sdk6,DevEco Studio2.2 beta1简化身份人脸验证实现
共78个文件
java:32个
xml:12个
json:9个
1 下载量 55 浏览量
2024-04-02
10:22:39
上传
评论
收藏 149KB ZIP 举报
温馨提示
基于sdk6,DevEco Studio2.2 beta1简化身份人脸验证实现
资源推荐
资源详情
资源评论
收起资源包目录
Ohos-Goldfinger-master.zip (78个子文件)
Ohos-Goldfinger-master
gradle.properties 549B
gradle
wrapper
gradle-wrapper.jar 57KB
gradle-wrapper.properties 194B
changelog.md 166B
LICENSE 11KB
gradlew.bat 3KB
rx
src
main
resources
base
element
string.json 80B
java
co
infinum
goldfinger
rx
RxGoldfingerCallback.java 1KB
RxGoldfinger.java 3KB
RxGoldfingerImpl.java 2KB
config.json 499B
proguard-rules.pro 45B
build.gradle 515B
.gitignore 7B
build.gradle 917B
settings.gradle 35B
core
src
main
resources
base
element
string.json 2KB
java
co
infinum
goldfinger
FaceAuthResult.java 4KB
crypto
ReprintModule.java 3KB
MarshmallowReprintModule.java 8KB
GoldfingerImpl.java 6KB
MissingHardwareException.java 346B
Goldfinger.java 7KB
AuthenticationResult.java 3KB
RestartPredicates.java 2KB
util
LogUtils.java 2KB
config.json 505B
proguard-rules.pro 45B
build.gradle 433B
.gitignore 7B
gradlew 6KB
.gitignore 4KB
example
src
ohosTest
java
co
infinum
goldfinger
example
ExampleOhosTest.java 404B
config.json 896B
main
resources
base
media
ic_camera_photo.png 9KB
water.png 2KB
ic_camera_switch.png 4KB
loading.png 2KB
ic_camera_back.png 4KB
icon.png 7KB
element
pattern.json 592B
string.json 280B
color.json 530B
graphic
gray_round_corner_bg.xml 246B
selector_button.xml 298B
background_ability_main.xml 176B
layout
switch_button.xml 647B
progress.xml 714B
ability_open_camera.xml 2KB
ability_payment.xml 742B
ability_settings.xml 2KB
ability_main.xml 555B
ability_choose_implementation.xml 1KB
ability_set_pin.xml 1KB
ability_login.xml 2KB
java
co
infinum
goldfinger
example
SettingsAbility.java 2KB
SharedPrefs.java 2KB
BasePaymentAbility.java 2KB
MockLoginService.java 818B
RxLoginAbility.java 2KB
PaymentAbility.java 2KB
RxPaymentAbility.java 1KB
SetPinAbility.java 3KB
MyApplication.java 273B
ChooseImplementationAbility.java 608B
MainAbility.java 456B
slice
ChooseImplementationAbilitySlice.java 3KB
BaseLoginAbility.java 6KB
BaseSettingsAbility.java 5KB
RxSettingsAbility.java 1KB
SimpleTextWatcher.java 459B
widget
SwitchCompat.java 2KB
ProgressDialog.java 1KB
LoginAbility.java 2KB
config.json 5KB
proguard-rules.pro 45B
build.gradle 799B
.gitignore 7B
共 78 条
- 1
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6705
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Javascript和Python的微商城项目设计源码 - MicroMall
- 基于Java的网上订餐系统设计源码 - online ordering system
- 基于Javascript的超级美眉网络资源管理应用模块设计源码
- 基于Typescript和PHP的编程知识储备库设计源码 - study-php
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
- 基于Vue和微信小程序的监理日志系统设计源码 - supervisionLog
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功