!64 新增UserAuth napi部分Enum实现

Merge pull request !64 from 王旭/master
This commit is contained in:
openharmony_ci
2022-03-03 06:15:15 +00:00
committed by Gitee
3 changed files with 279 additions and 6 deletions
+45 -1
View File
@@ -21,13 +21,57 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
enum AuthMethod {
PIN_ONLY = 0xF,
FACE_ONLY = 0xF0
};
enum Module {
FACE_AUTH = 1
};
enum FaceTipsCode {
FACE_AUTH_TIP_TOO_BRIGHT = 1,
FACE_AUTH_TIP_TOO_DARK = 2,
FACE_AUTH_TIP_TOO_CLOSE = 3,
FACE_AUTH_TIP_TOO_FAR = 4,
FACE_AUTH_TIP_TOO_HIGH = 5,
FACE_AUTH_TIP_TOO_LOW = 6,
FACE_AUTH_TIP_TOO_RIGHT = 7,
FACE_AUTH_TIP_TOO_LEFT = 8,
FACE_AUTH_TIP_TOO_MUCH_MOTION = 9,
FACE_AUTH_TIP_POOR_GAZE = 10,
FACE_AUTH_TIP_NOT_DETECTED = 11,
};
enum FingerprintTips {
FINGERPRINT_TIP_GOOD = 0,
FINGERPRINT_TIP_IMAGER_DIRTY = 1,
FINGERPRINT_TIP_INSUFFICIENT = 2,
FINGERPRINT_TIP_PARTIAL = 3,
FINGERPRINT_TIP_TOO_FAST = 4,
FINGERPRINT_TIP_TOO_SLOW = 5
};
napi_value AuthTypeConstructor(napi_env env);
napi_value AuthSubTypeConstructor(napi_env env);
napi_value AuthTrustLevelConstructor(napi_env env);
napi_value GetPropertyTypeConstructor(napi_env env);
napi_value SetPropertyTypeConstructor(napi_env env);
napi_value AuthMethodConstructor(napi_env env);
napi_value ModuleConstructor(napi_env env);
napi_value ResultCodeConstructor(napi_env env);
napi_value FaceTipsCodeConstructor(napi_env env);
napi_value FingerprintTipsConstructor(napi_env env);
/**
* @brief Napi initialization
*
* @param env
* @param exports
*/
void Init(napi_env env, napi_value exports);
napi_value UserAuthInit(napi_env env, napi_value exports);
napi_value EnumExport(napi_env env, napi_value exports);
/**
* @brief Get the Ctor object
@@ -196,13 +196,224 @@ napi_value CancelAuth(napi_env env, napi_callback_info info)
return userAuthImpl->CancelAuth(env, info);
}
napi_value AuthTypeConstructor(napi_env env)
{
napi_value authType = nullptr;
napi_value pin = nullptr;
napi_value face = nullptr;
NAPI_CALL(env, napi_create_object(env, &authType));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthType::PIN, &pin));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthType::FACE, &face));
NAPI_CALL(env, napi_set_named_property(env, authType, "PIN", pin));
NAPI_CALL(env, napi_set_named_property(env, authType, "FACE", face));
return authType;
}
napi_value AuthSubTypeConstructor(napi_env env)
{
napi_value authSubType = nullptr;
napi_value pinSix = nullptr;
napi_value pinNumber = nullptr;
napi_value pinMixed = nullptr;
napi_value face2d = nullptr;
napi_value face3d = nullptr;
NAPI_CALL(env, napi_create_object(env, &authSubType));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthSubType::PIN_SIX, &pinSix));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthSubType::PIN_NUMBER, &pinNumber));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthSubType::PIN_MIXED, &pinMixed));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthSubType::FACE_2D, &face2d));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthSubType::FACE_3D, &face3d));
NAPI_CALL(env, napi_set_named_property(env, authSubType, "PIN_SIX", pinSix));
NAPI_CALL(env, napi_set_named_property(env, authSubType, "PIN_NUMBER", pinNumber));
NAPI_CALL(env, napi_set_named_property(env, authSubType, "PIN_MIXED", pinMixed));
NAPI_CALL(env, napi_set_named_property(env, authSubType, "FACE_2D", face2d));
NAPI_CALL(env, napi_set_named_property(env, authSubType, "FACE_3D", face3d));
return authSubType;
}
napi_value AuthTrustLevelConstructor(napi_env env)
{
napi_value authTrustLevel = nullptr;
napi_value atl1 = nullptr;
napi_value atl2 = nullptr;
napi_value atl3 = nullptr;
napi_value atl4 = nullptr;
NAPI_CALL(env, napi_create_object(env, &authTrustLevel));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthTurstLevel::ATL1, &atl1));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthTurstLevel::ATL2, &atl2));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthTurstLevel::ATL3, &atl3));
NAPI_CALL(env, napi_create_int32(env, (int32_t)AuthTurstLevel::ATL4, &atl4));
NAPI_CALL(env, napi_set_named_property(env, authTrustLevel, "ATL1", atl1));
NAPI_CALL(env, napi_set_named_property(env, authTrustLevel, "ATL2", atl2));
NAPI_CALL(env, napi_set_named_property(env, authTrustLevel, "ATL3", atl3));
NAPI_CALL(env, napi_set_named_property(env, authTrustLevel, "ATL4", atl4));
return authTrustLevel;
}
napi_value GetPropertyTypeConstructor(napi_env env)
{
napi_value getPropertyType = nullptr;
napi_value authSubType = nullptr;
napi_value remainTimes = nullptr;
napi_value freezingTime = nullptr;
NAPI_CALL(env, napi_create_object(env, &getPropertyType));
NAPI_CALL(env, napi_create_int32(env, (int32_t)GetPropertyType::AUTH_SUB_TYPE, &authSubType));
NAPI_CALL(env, napi_create_int32(env, (int32_t)GetPropertyType::REMAIN_TIMES, &remainTimes));
NAPI_CALL(env, napi_create_int32(env, (int32_t)GetPropertyType::FREEZING_TIME, &freezingTime));
NAPI_CALL(env, napi_set_named_property(env, getPropertyType, "AUTH_SUB_TYPE", authSubType));
NAPI_CALL(env, napi_set_named_property(env, getPropertyType, "REMAIN_TIMES", remainTimes));
NAPI_CALL(env, napi_set_named_property(env, getPropertyType, "FREEZING_TIME", freezingTime));
return getPropertyType;
}
napi_value SetPropertyTypeConstructor(napi_env env)
{
napi_value setPropertyType = nullptr;
napi_value initAlgorithm = nullptr;
NAPI_CALL(env, napi_create_object(env, &setPropertyType));
NAPI_CALL(env, napi_create_int32(env, (int32_t)SetPropertyType::INIT_ALGORITHM, &initAlgorithm));
NAPI_CALL(env, napi_set_named_property(env, setPropertyType, "INIT_ALGORITHM", initAlgorithm));
return setPropertyType;
}
napi_value AuthMethodConstructor(napi_env env)
{
napi_value authMethod = nullptr;
napi_value pinOnly = nullptr;
napi_value faceOnly = nullptr;
NAPI_CALL(env, napi_create_object(env, &authMethod));
NAPI_CALL(env, napi_create_int32(env, AuthMethod::PIN_ONLY, &pinOnly));
NAPI_CALL(env, napi_create_int32(env, AuthMethod::FACE_ONLY, &faceOnly));
NAPI_CALL(env, napi_set_named_property(env, authMethod, "PIN_ONLY", pinOnly));
NAPI_CALL(env, napi_set_named_property(env, authMethod, "FACE_ONLY", faceOnly));
return authMethod;
}
napi_value ModuleConstructor(napi_env env)
{
napi_value module = nullptr;
napi_value faceAuth = nullptr;
NAPI_CALL(env, napi_create_object(env, &module));
NAPI_CALL(env, napi_create_int32(env, Module::FACE_AUTH, &faceAuth));
NAPI_CALL(env, napi_set_named_property(env, module, "FACE_AUTH", faceAuth));
return module;
}
napi_value ResultCodeConstructor(napi_env env)
{
napi_value resultCode = nullptr;
napi_value success = nullptr;
napi_value fail = nullptr;
napi_value generalError = nullptr;
napi_value canceled = nullptr;
napi_value timeout = nullptr;
napi_value typeNotSupport = nullptr;
napi_value trustLevelNotSupport = nullptr;
napi_value busy = nullptr;
napi_value invalidParameters = nullptr;
napi_value locked = nullptr;
napi_value notEnrolled = nullptr;
NAPI_CALL(env, napi_create_object(env, &resultCode));
NAPI_CALL(env, napi_create_int32(env, ResultCode::SUCCESS, &success));
NAPI_CALL(env, napi_create_int32(env, ResultCode::FAIL, &fail));
NAPI_CALL(env, napi_create_int32(env, ResultCode::GENERAL_ERROR, &generalError));
NAPI_CALL(env, napi_create_int32(env, ResultCode::CANCELED, &canceled));
NAPI_CALL(env, napi_create_int32(env, ResultCode::TIMEOUT, &timeout));
NAPI_CALL(env, napi_create_int32(env, ResultCode::TYPE_NOT_SUPPORT, &typeNotSupport));
NAPI_CALL(env, napi_create_int32(env, ResultCode::TRUST_LEVEL_NOT_SUPPORT, &trustLevelNotSupport));
NAPI_CALL(env, napi_create_int32(env, ResultCode::BUSY, &busy));
NAPI_CALL(env, napi_create_int32(env, ResultCode::INVALID_PARAMETERS, &invalidParameters));
NAPI_CALL(env, napi_create_int32(env, ResultCode::LOCKED, &locked));
NAPI_CALL(env, napi_create_int32(env, ResultCode::NOT_ENROLLED, &notEnrolled));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "SUCCESS", success));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "FAIL", fail));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "GENERAL_ERROR", generalError));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "CANCELED", canceled));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "TIMEOUT", timeout));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "TYPE_NOT_SUPPORT", typeNotSupport));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "TRUST_LEVEL_NOT_SUPPORT", trustLevelNotSupport));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "BUSY", busy));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "INVALID_PARAMETERS", invalidParameters));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "LOCKED", locked));
NAPI_CALL(env, napi_set_named_property(env, resultCode, "NOT_ENROLLED", notEnrolled));
return resultCode;
}
napi_value FaceTipsCodeConstructor(napi_env env)
{
napi_value faceTipsCode = nullptr;
napi_value faceAuthTipTooBright = nullptr;
napi_value faceAuthTipTooDark = nullptr;
napi_value faceAuthTipTooClose = nullptr;
napi_value faceAuthTipTooFar = nullptr;
napi_value faceAuthTipTooHigh = nullptr;
napi_value faceAuthTipTooLow = nullptr;
napi_value faceAuthTipTooRight = nullptr;
napi_value faceAuthTipTooLeft = nullptr;
napi_value faceAuthTipTooMuchMotion = nullptr;
napi_value faceAuthTipPoorGaze = nullptr;
napi_value faceAuthTipNotDetected = nullptr;
NAPI_CALL(env, napi_create_object(env, &faceTipsCode));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_TOO_BRIGHT, &faceAuthTipTooBright));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_TOO_DARK, &faceAuthTipTooDark));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_TOO_CLOSE, &faceAuthTipTooClose));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_TOO_FAR, &faceAuthTipTooFar));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_TOO_HIGH, &faceAuthTipTooHigh));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_TOO_LOW, &faceAuthTipTooLow));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_TOO_RIGHT, &faceAuthTipTooRight));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_TOO_LEFT, &faceAuthTipTooLeft));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_TOO_MUCH_MOTION, &faceAuthTipTooMuchMotion));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_POOR_GAZE, &faceAuthTipPoorGaze));
NAPI_CALL(env, napi_create_int32(env, FaceTipsCode::FACE_AUTH_TIP_NOT_DETECTED, &faceAuthTipNotDetected));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_TOO_BRIGHT", faceAuthTipTooBright));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_TOO_DARK", faceAuthTipTooDark));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_TOO_CLOSE", faceAuthTipTooClose));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_TOO_FAR", faceAuthTipTooFar));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_TOO_HIGH", faceAuthTipTooHigh));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_TOO_LOW", faceAuthTipTooLow));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_TOO_RIGHT", faceAuthTipTooRight));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_TOO_LEFT", faceAuthTipTooLeft));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode,
"FACE_AUTH_TIP_TOO_MUCH_MOTION", faceAuthTipTooMuchMotion));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_POOR_GAZE", faceAuthTipPoorGaze));
NAPI_CALL(env, napi_set_named_property(env, faceTipsCode, "FACE_AUTH_TIP_NOT_DETECTED", faceAuthTipNotDetected));
return faceTipsCode;
}
napi_value FingerprintTipsConstructor(napi_env env)
{
napi_value fingerprintTips = nullptr;
napi_value fingerprintTipGood = nullptr;
napi_value fingerprintTipImagerDirty = nullptr;
napi_value fingerprintTipInsufficient = nullptr;
napi_value fingerprintTipPartial = nullptr;
napi_value fingerprintTipTooFast = nullptr;
napi_value fingerprintTipTooSlow = nullptr;
NAPI_CALL(env, napi_create_object(env, &fingerprintTips));
NAPI_CALL(env, napi_create_int32(env, FingerprintTips::FINGERPRINT_TIP_GOOD, &fingerprintTipGood));
NAPI_CALL(env, napi_create_int32(env, FingerprintTips::FINGERPRINT_TIP_IMAGER_DIRTY, &fingerprintTipImagerDirty));
NAPI_CALL(env, napi_create_int32(env, FingerprintTips::FINGERPRINT_TIP_INSUFFICIENT, &fingerprintTipInsufficient));
NAPI_CALL(env, napi_create_int32(env, FingerprintTips::FINGERPRINT_TIP_PARTIAL, &fingerprintTipPartial));
NAPI_CALL(env, napi_create_int32(env, FingerprintTips::FINGERPRINT_TIP_TOO_FAST, &fingerprintTipTooFast));
NAPI_CALL(env, napi_create_int32(env, FingerprintTips::FINGERPRINT_TIP_TOO_SLOW, &fingerprintTipTooSlow));
NAPI_CALL(env, napi_set_named_property(env, fingerprintTips, "FINGERPRINT_TIP_GOOD", fingerprintTipGood));
NAPI_CALL(env, napi_set_named_property(env, fingerprintTips,
"FINGERPRINT_TIP_IMAGER_DIRTY", fingerprintTipImagerDirty));
NAPI_CALL(env, napi_set_named_property(env, fingerprintTips,
"FINGERPRINT_TIP_INSUFFICIENT", fingerprintTipInsufficient));
NAPI_CALL(env, napi_set_named_property(env, fingerprintTips, "FINGERPRINT_TIP_PARTIAL", fingerprintTipPartial));
NAPI_CALL(env, napi_set_named_property(env, fingerprintTips, "FINGERPRINT_TIP_TOO_FAST", fingerprintTipTooFast));
NAPI_CALL(env, napi_set_named_property(env, fingerprintTips, "FINGERPRINT_TIP_TOO_SLOW", fingerprintTipTooSlow));
return fingerprintTips;
}
/**
* @brief Napi initialization
*
* @param env
* @param exports
*/
void Init(napi_env env, napi_value exports)
napi_value UserAuthInit(napi_env env, napi_value exports)
{
USERAUTH_HILOGI(MODULE_JS_NAPI, "%{public}s, start.", __func__);
napi_status status;
@@ -213,13 +424,30 @@ void Init(napi_env env, napi_value exports)
status = napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
if (status != napi_ok) {
USERAUTH_HILOGE(MODULE_JS_NAPI, "napi_define_properties faild");
return;
}
status = napi_set_named_property(env, exports, "UserAuth", GetCtor(env));
if (status != napi_ok) {
USERAUTH_HILOGE(MODULE_JS_NAPI, "napi_set_named_property faild");
}
return exports;
}
napi_value EnumExport(napi_env env, napi_value exports)
{
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("AuthType", AuthTypeConstructor(env)),
DECLARE_NAPI_PROPERTY("AuthSubType", AuthSubTypeConstructor(env)),
DECLARE_NAPI_PROPERTY("AuthTrustLevel", AuthTrustLevelConstructor(env)),
DECLARE_NAPI_PROPERTY("GetPropertyType", GetPropertyTypeConstructor(env)),
DECLARE_NAPI_PROPERTY("SetPropertyType", SetPropertyTypeConstructor(env)),
DECLARE_NAPI_PROPERTY("AuthMethod", AuthMethodConstructor(env)),
DECLARE_NAPI_PROPERTY("Module", ModuleConstructor(env)),
DECLARE_NAPI_PROPERTY("ResultCode", ResultCodeConstructor(env)),
DECLARE_NAPI_PROPERTY("FaceTipsCode", FaceTipsCodeConstructor(env)),
DECLARE_NAPI_PROPERTY("FingerprintTips", FingerprintTipsConstructor(env)),
};
napi_define_properties(env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors);
return exports;
}
napi_value Constructor(napi_env env, napi_callback_info info)
+3 -2
View File
@@ -610,8 +610,9 @@ napi_value UserAuthImpl::CancelAuth(napi_env env, napi_callback_info info)
static napi_value ModuleInit(napi_env env, napi_value exports)
{
OHOS::UserIAM::UserAuth::Init(env, exports);
return exports;
napi_value val = UserAuthInit(env, exports);
val = EnumExport(env, val);
return val;
}
extern "C" __attribute__((constructor)) void RegisterModule(void)
{