@since 2021-04-12 /
public class MainAbilitySlice extends AbilitySlice {
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;
private EventRunner runner;
private MyEventHandle myEventHandle;
private BiometricAuthentication mBiometricAuthentication;
/*
新建线程进行认证,制止壅闭其他任务
*/
private Runnable runnable = new Runnable() {
private void initHandler() {
runner = EventRunner.getMainEventRunner();
if (runner == null) {
return;
}
myEventHandle = new MyEventHandle(runner);
}
打开相机slice
*/
public class OpenCameraSlice extends AbilitySlice implements PermissionBridge.OnPermissionStateListener {
private static final String TAG = OpenCameraSlice.class.getName();
CameraStateCallbackImpl
*/
class CameraStateCallbackImpl extends CameraStateCallback {
CameraStateCallbackImpl() {
}
@Override
public void onCreated(Camera camera) {
// 获取预览
previewSurface = surfaceProvider.getSurfaceOps().get().getSurface();
if (previewSurface == null) {
LogUtils.error(TAG, “create camera filed, preview surface is null”);
return;
}
// Wait until the preview surface is created.
try {
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException exception) {
LogUtils.warn(TAG, “Waiting to be interrupted”);
}
CameraConfig.Builder cameraConfigBuilder = camera.getCameraConfigBuilder();
// 设置预览
cameraConfigBuilder.addSurface(previewSurface);
camera.configure(cameraConfigBuilder.build());
cameraDevice = camera;
enableImageGroup();
}
@Override
public void onConfigured(Camera camera) {
FrameConfig.Builder framePreviewConfigBuilder
= camera.getFrameConfigBuilder(Camera.FrameConfigType.FRAME_CONFIG_PREVIEW);
framePreviewConfigBuilder.addSurface(previewSurface);
// 开启循环捕捉
camera.triggerLoopingCapture(framePreviewConfigBuilder.build());
}
private void enableImageGroup() {
if (!exitImage.isEnabled()) {
exitImage.setEnabled(true);
switchCameraImage.setEnabled(true);
}
}
}
/**
SurfaceCallBack
*/
class SurfaceCallBack implements SurfaceOps.Callback {
@Override
public void surfaceCreated(SurfaceOps callbackSurfaceOps) {
if (callbackSurfaceOps != null) {
callbackSurfaceOps.setFixedSize(SCREEN_HEIGHT, SCREEN_WIDTH);
}
openCamera();
}
@Override
public void surfaceChanged(SurfaceOps callbackSurfaceOps, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceOps callbackSurfaceOps) {
}
}
@Override
public void onStop() {
cameraDevice.release();
}
}
3.com/huawei/cookbook/util/FaceAuthResult.java
package com.huawei.cookbook.util;
/**
人脸认证返回码
@since 2021-04-12 /
public class FaceAuthResult {
/*
认证乐成 /
public static final int AUTH_SUCCESS = 0;
/*
认证失败 /
public static final int AUTH_FAIL = 1;
/*
取消认证 /
public static final int AUTH_CANCLE = 2;
/*
认证超时 /
public static final int AUTH_TIME_OUT = 3;
/*
打开相机失败 /
public static final int AUTH_OPEN_CAMERA_FAIL = 4;
/*
busy,可能上一个认证没有结束 /
public static final int AUTH_BUSY = 5;
/*
入参错误 /
public static final int AUTH_PARAM_ERROR = 6;
/*
人脸认证锁定(达到错误认证次数了) /
public static final int AUTH_FACE_LOCKED = 7;
/*
没有录入人脸 /
public static final int AUTH_NO_FACE = 8;
/*
不支持2D人脸识别。 /
public static final int AUTH_2D_NOT_SUPPORTED = 9;
/*
安全级别不支持 /
public static final int AUTH_SAFE_LEVEL_NOT_SUPPORTED = 10;
/*
不是当地认证 /
public static final int AUTH_NOT_LOCAL = 11;
/*
其他问题
*/
public static final int AUTH_OTHER_ERROR = 100;