diff --git a/36.diff.txt b/36.diff.txt new file mode 100644 index 0000000000000000000000000000000000000000..744a8930402c67f157f836c509a921589e67e358 --- /dev/null +++ b/36.diff.txt @@ -0,0 +1,1658 @@ +diff --git a/frameworks/kitsimpl/src/iuserauth_api7_callback.cpp b/frameworks/kitsimpl/src/iuserauth_api7_callback.cpp +new file mode 100644 +index 0000000000000000000000000000000000000000..b5340ec0fe18868c6ed6dd9685498f4027af7895 +--- /dev/null ++++ b/frameworks/kitsimpl/src/iuserauth_api7_callback.cpp +@@ -0,0 +1,120 @@ ++/* ++ * 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. ++ */ ++#include ++ ++#include "userauth_api7_hilog_wrapper.h" ++#include "userauth_api7_datamgr.h" ++#include "userauth_api7_info.h" ++#include "iuserauth_api7_callback.h" ++namespace OHOS { ++namespace UserIAM { ++namespace API7UserAuth { ++std::map g_convertResult = { ++ {UserAuth::SUCCESS, API7UserAuth::SUCCESS}, ++ {UserAuth::FAIL, API7UserAuth::GENERAL_ERROR}, ++ {UserAuth::GENERAL_ERROR, API7UserAuth::GENERAL_ERROR}, ++ {UserAuth::CANCELED, API7UserAuth::CANCELED}, ++ {UserAuth::TIMEOUT, API7UserAuth::TIMEOUT}, ++ {UserAuth::TYPE_NOT_SUPPORT, API7UserAuth::NO_SUPPORT}, ++ {UserAuth::TRUST_LEVEL_NOT_SUPPORT, API7UserAuth::NO_SUPPORT}, ++ {UserAuth::BUSY, API7UserAuth::BUSY}, ++ {UserAuth::INVALID_PARAMETERS, API7UserAuth::INVALID_PARAMETERS}, ++ {UserAuth::LOCKED, API7UserAuth::LOCKED}, ++ {UserAuth::NOT_ENROLLED, API7UserAuth::NOT_ENROLLED}, ++ {UserAuth::IPC_ERROR, API7UserAuth::GENERAL_ERROR}, ++ {UserAuth::INVALID_CONTEXTID, API7UserAuth::GENERAL_ERROR}, ++ {UserAuth::E_WRITE_PARCEL_ERROR, API7UserAuth::GENERAL_ERROR}, ++ {UserAuth::E_READ_PARCEL_ERROR, API7UserAuth::GENERAL_ERROR}, ++ {UserAuth::E_GET_POWER_SERVICE_FAILED, API7UserAuth::GENERAL_ERROR}, ++ {UserAuth::E_RET_UNDONE, API7UserAuth::GENERAL_ERROR}, ++ {UserAuth::E_RET_NOSERVER, API7UserAuth::GENERAL_ERROR}, ++}; ++ ++std::map g_convertTipInfo = { ++ { FACE_AUTH_TIP_TOO_BRIGHT, "the obtained facial image is too bright due to high illumination" }, ++ { FACE_AUTH_TIP_TOO_DARK, "the obtained facial image is too dark due to low illumination" }, ++ { FACE_AUTH_TIP_TOO_CLOSE, "the face is too close to the device" }, ++ { FACE_AUTH_TIP_TOO_FAR, "the face is too far away from the device" }, ++ { FACE_AUTH_TIP_TOO_HIGH, "the device is too high, and that only the upper part of the face is captured" }, ++ { FACE_AUTH_TIP_TOO_LOW, "the device is too low, and that only the lower part of the face is captured" }, ++ { FACE_AUTH_TIP_TOO_RIGHT, ++ "the device is deviated to the right, and that only the right part of the face is captured" }, ++ { FACE_AUTH_TIP_TOO_LEFT, ++ "the device is deviated to the left, and that only the left part of the face is captured" }, ++ { FACE_AUTH_TIP_TOO_MUCH_MOTION, "the face moves too fast during facial information collection" }, ++ { FACE_AUTH_TIP_POOR_GAZE, "the face is not facing the device" }, ++ { FACE_AUTH_TIP_NOT_DETECTED, "no face is detected" }, ++}; ++ ++IUserAuthAPI7Callback::IUserAuthAPI7Callback(std::shared_ptr& impl) ++{ ++ callback_ = impl; ++} ++ ++void IUserAuthAPI7Callback::onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) ++{ ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 onAcquireInfo is start"); ++ std::string tipOfInfo = ""; ++ if (UserAuthAPI7Datamgr::GetInstance().GetAPI7Tip()) { ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 GetAPI7Tip is on"); ++ API7UserAuth::Tip tipInfo; ++ tipInfo.errorCode = API7UserAuth::SUCCESS; ++ tipInfo.tipEvent = API7UserAuth::ACQUIRE; ++ tipInfo.tipCode = acquireInfo; ++ if (g_convertTipInfo.count(static_cast(acquireInfo)) == 0) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 g_convertTipInfo is 0"); ++ tipOfInfo = "other error"; ++ } else { ++ tipOfInfo = g_convertTipInfo[static_cast(acquireInfo)]; ++ } ++ callback_->TipCallback(tipInfo); ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 GetAPI7Tip is end"); ++ } ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 onAcquireInfo is end"); ++} ++ ++void IUserAuthAPI7Callback::onResult(const int32_t result, const UserAuth::AuthResult extraInfo) ++{ ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 onResult is start"); ++ AuthenticationResult authResult; ++ UserAuthAPI7Datamgr::GetInstance().API7DeleteContextID(); ++ callback_->API7OnResult(result); ++ if (UserAuthAPI7Datamgr::GetInstance().GetAPI7Tip()) { ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 GetAPI7Tip is on"); ++ API7UserAuth::Tip tipInfo; ++ if (result != UserAuth::SUCCESS) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 result is failed"); ++ tipInfo.errorCode = API7UserAuth::FAILED; ++ tipInfo.tipInfo = "FAILED"; ++ } else { ++ tipInfo.errorCode = API7UserAuth::SUCCESSED; ++ tipInfo.tipInfo = "SUCCESSED"; ++ } ++ tipInfo.tipEvent = API7UserAuth::RESULT; ++ if (g_convertResult.count(static_cast(result)) == 0) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 g_convertResult is 0"); ++ authResult = static_cast(result); ++ } else { ++ authResult = g_convertResult[static_cast(result)]; ++ } ++ tipInfo.tipCode = authResult; ++ callback_->TipCallback(tipInfo); ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 GetAPI7Tip is end"); ++ } ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 onResult is end"); ++} ++} ++} ++} +\ No newline at end of file +diff --git a/frameworks/kitsimpl/src/userauth.cpp b/frameworks/kitsimpl/src/userauth.cpp +index 796592ab037fef5f2b219fd75a0a742796648fdb..388caf35a73ee1b7c1cefe561118ed1e5233995e 100644 +--- a/frameworks/kitsimpl/src/userauth.cpp ++++ b/frameworks/kitsimpl/src/userauth.cpp +@@ -12,6 +12,8 @@ + * See the License for the specific language governing permissions and + * limitations under the License. + */ ++#include ++ + #include + #include + #include +@@ -107,9 +109,13 @@ void UserAuth::GetProperty(const GetPropertyRequest request, std::shared_ptronGetProperty(result); +- return ; ++ return; ++ } ++ sptr asyncStub = new (std::nothrow) UserAuthAsyncStub(callback); ++ if (asyncStub == nullptr) { ++ USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub failed, GetProperty IUserAuthCallback is nullptr"); ++ return; + } +- sptr asyncStub = new UserAuthAsyncStub(callback); + proxy_->GetProperty(request, asyncStub); + } + void UserAuth::SetProperty(const SetPropertyRequest request, std::shared_ptr callback) +@@ -124,7 +130,11 @@ void UserAuth::SetProperty(const SetPropertyRequest request, std::shared_ptronSetProperty(E_RET_NOSERVER); + return ; + } +- sptr asyncStub = new UserAuthAsyncStub(callback); ++ sptr asyncStub = new (std::nothrow) UserAuthAsyncStub(callback); ++ if (asyncStub == nullptr) { ++ USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub failed, SetProperty IUserAuthCallback is nullptr"); ++ return; ++ } + proxy_->SetProperty(request, asyncStub); + } + uint64_t UserAuth::Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel, +@@ -139,7 +149,11 @@ uint64_t UserAuth::Auth(const uint64_t challenge, const AuthType authType, const + if (proxy == nullptr) { + return E_RET_NOSERVER; + } +- sptr asyncStub = new UserAuthAsyncStub(callback); ++ sptr asyncStub = new (std::nothrow) UserAuthAsyncStub(callback); ++ if (asyncStub == nullptr) { ++ USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub failed, Auth IUserAuthCallback is nullptr"); ++ return GENERAL_ERROR; ++ } + uint64_t ret = proxy_->Auth(challenge, authType, authTurstLevel, asyncStub); + return ret; + } +@@ -155,7 +169,11 @@ uint64_t UserAuth::AuthUser(const int32_t userId, const uint64_t challenge, cons + if (proxy == nullptr) { + return E_RET_NOSERVER; + } +- sptr asyncStub = new UserAuthAsyncStub(callback); ++ sptr asyncStub = new (std::nothrow) UserAuthAsyncStub(callback); ++ if (asyncStub == nullptr) { ++ USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub failed, AuthUser IUserAuthCallback is nullptr"); ++ return GENERAL_ERROR; ++ } + uint64_t ret = proxy_->AuthUser(userId, challenge, authType, authTurstLevel, asyncStub); + return ret; + } +diff --git a/frameworks/kitsimpl/src/userauth_api7.cpp b/frameworks/kitsimpl/src/userauth_api7.cpp +new file mode 100644 +index 0000000000000000000000000000000000000000..89c44cd242cf33cc79846cd16df3e7b8a353b12c +--- /dev/null ++++ b/frameworks/kitsimpl/src/userauth_api7.cpp +@@ -0,0 +1,152 @@ ++/* ++ * 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. ++ */ ++#include ++ ++#include "userauth_info.h" ++#include "user_auth.h" ++#include "userauth_hilog_wrapper.h" ++#include "userauth_api7_hilog_wrapper.h" ++#include "userauth_api7_datamgr.h" ++#include "iuserauth_api7_callback.h" ++#include "userauth_api7.h" ++ ++namespace OHOS { ++namespace UserIAM { ++namespace API7UserAuth { ++std::map g_convertAuthType = { ++ { "FACE_ONLY", UserAuth::FACE }, ++}; ++std::map g_convertAuthTurstLevel = { ++ { "S1", UserAuth::ATL1 }, ++ { "S2", UserAuth::ATL2 }, ++ { "S3", UserAuth::ATL3 }, ++ { "S4", UserAuth::ATL4 }, ++}; ++ ++UserAuthAPI7 &UserAuthAPI7::GetAuthenticator() ++{ ++ static UserAuthAPI7 instance; ++ return instance; ++} ++ ++void UserAuthAPI7::Execute(std::string authtype, std::string trustLevel, std::shared_ptr callback) ++{ ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 execute is start"); ++ UserAuth::AuthType exeAuthType; ++ UserAuth::AuthTurstLevel authTurstLevel; ++ uint64_t contextID = 0; ++ ++ if (callback == nullptr) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 execute callback is Null"); ++ return; ++ } ++ ++ if (g_convertAuthType.count(authtype) == 0) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 execute g_convertAuthType is 0"); ++ callback->API7OnResult(NO_SUPPORT); ++ return; ++ } else { ++ exeAuthType = g_convertAuthType[authtype]; ++ } ++ ++ if (g_convertAuthTurstLevel.count(trustLevel) == 0) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 execute g_convertAuthTurstLevel is 0"); ++ callback->API7OnResult(NO_SUPPORT); ++ return; ++ } else { ++ authTurstLevel = g_convertAuthTurstLevel[trustLevel]; ++ } ++ ++ std::shared_ptr asyncStub = std::make_shared(callback); ++ if (asyncStub == nullptr) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "UserAuthCallback failed, IUserAuthAPI7Callback is nullptr"); ++ return; ++ } ++ contextID = UserAuth::UserAuth::GetInstance().Auth(CHALLENGE_INIT, exeAuthType, authTurstLevel, asyncStub); ++ if (contextID != CONTEXTID_INIT) { ++ UserAuthAPI7Datamgr::GetInstance().API7AddContextID(contextID); ++ } ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 execute is end"); ++} ++ ++int32_t UserAuthAPI7::Cancel() ++{ ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 cancel is start"); ++ uint64_t contextID = 0; ++ int32_t ret = API7UserAuth::GENERAL_ERROR; ++ ++ UserAuthAPI7Datamgr::GetInstance().API7GetContextID(contextID); ++ if (contextID != CONTEXTID_INIT) { ++ ret = UserAuth::UserAuth::GetInstance().CancelAuth(contextID); ++ if (ret != API7UserAuth::SUCCESS) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 cancel is error"); ++ } ++ UserAuthAPI7Datamgr::GetInstance().API7DeleteContextID(); ++ } ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 cancel is end"); ++ return ret; ++} ++ ++int32_t UserAuthAPI7::CheckAvailability(std::string authtype, std::string trustLevel) ++{ ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 checkAvailability is start"); ++ UserAuth::AuthType checkAuthType; ++ UserAuth::AuthTurstLevel authTurstLevel; ++ ++ if (g_convertAuthType.count(authtype) == 0) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 checkAvailability g_convertAuthType is 0"); ++ return AUTH_TYPE_NOT_SUPPORT; ++ } else { ++ checkAuthType = g_convertAuthType[authtype]; ++ } ++ ++ if (g_convertAuthTurstLevel.count(trustLevel) == 0) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 checkAvailability g_convertAuthTurstLevel is 0"); ++ return SECURE_LEVEL_NOT_SUPPORT; ++ } else { ++ authTurstLevel = g_convertAuthTurstLevel[trustLevel]; ++ } ++ ++ int32_t ret = UserAuth::UserAuth::GetInstance().GetAvailableStatus(checkAuthType, authTurstLevel); ++ if (ret != UserAuth::SUCCESS) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 checkAvailability is error "); ++ } ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 checkAvailability is end"); ++ return ret; ++} ++ ++void UserAuthAPI7::On(std::string tip, std::shared_ptr tipCallback) ++{ ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 On is start"); ++ std::string tipInfo = "tip"; ++ ++ if (!tipInfo.compare(tip)) { ++ USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 On is not tip"); ++ UserAuthAPI7Datamgr::GetInstance().SetAPI7Tip(false); ++ return; ++ } ++ UserAuthAPI7Datamgr::GetInstance().SetAPI7Tip(true); ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 On is end"); ++} ++ ++void UserAuthAPI7::Off(std::string tip, std::shared_ptr tipCallback) ++{ ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 Off is start"); ++ UserAuthAPI7Datamgr::GetInstance().SetAPI7Tip(false); ++ USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 Off is end"); ++} ++} // namespace userAuth ++} // namespace UserIam ++} // namespace OHOS +diff --git a/frameworks/kitsimpl/src/userauth_api7_datamgr.cpp b/frameworks/kitsimpl/src/userauth_api7_datamgr.cpp +new file mode 100644 +index 0000000000000000000000000000000000000000..7a31984a07c4879e12dc2edd39306a015b123fcc +--- /dev/null ++++ b/frameworks/kitsimpl/src/userauth_api7_datamgr.cpp +@@ -0,0 +1,55 @@ ++/* ++ * 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. ++ */ ++ ++#include "userauth_info.h" ++#include "userauth_hilog_wrapper.h" ++#include "userauth_api7_info.h" ++#include "userauth_api7_datamgr.h" ++ ++namespace OHOS { ++namespace UserIAM { ++namespace API7UserAuth { ++UserAuthAPI7Datamgr &UserAuthAPI7Datamgr::GetInstance() ++{ ++ static UserAuthAPI7Datamgr instance; ++ return instance; ++} ++ ++void UserAuthAPI7Datamgr::API7AddContextID(uint64_t contextID) ++{ ++ contextID_ = contextID; ++} ++ ++void UserAuthAPI7Datamgr::API7GetContextID(uint64_t &contextID) ++{ ++ contextID = contextID_; ++} ++ ++void UserAuthAPI7Datamgr::API7DeleteContextID() ++{ ++ contextID_= CONTEXTID_INIT; ++} ++ ++void UserAuthAPI7Datamgr::SetAPI7Tip(bool isTipOn) ++{ ++ isTipOn_ = isTipOn; ++} ++bool UserAuthAPI7Datamgr::GetAPI7Tip() ++{ ++ return isTipOn_; ++} ++} // namespace UserAuth ++} // namespace UserIam ++} // namespace OHOS +diff --git a/frameworks/kitsimpl/src/userauth_async_stub.cpp b/frameworks/kitsimpl/src/userauth_async_stub.cpp +index 4a7ee0545c4641fc42c23842ee12bfdf81d58c87..65ba5af589672a659b16f2fc9d467fc3c421d9e6 100644 +--- a/frameworks/kitsimpl/src/userauth_async_stub.cpp ++++ b/frameworks/kitsimpl/src/userauth_async_stub.cpp +@@ -13,6 +13,7 @@ + * limitations under the License. + */ + ++#include + #include + + #include "userauth_hilog_wrapper.h" +@@ -201,7 +202,7 @@ void UserAuthAsyncStub::onAcquireInfo(const int32_t module, const uint32_t acqui + + if (authCallback_ == nullptr) { + USERAUTH_HILOGE(MODULE_INNERKIT, "userauthAsyncStub onAcquireInfo callback is Null"); +- return ; ++ return; + } + + USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub module:%{public}d, acquireInfo:%{public}u", +@@ -234,8 +235,8 @@ void UserAuthAsyncStub::onExecutorPropertyInfo(const ExecutorProperty result) + } + + USERAUTH_HILOGD(MODULE_INNERKIT, +- "userauthAsyncStub result:%{public}d, sub:%{public}llu, remain:%{public}u, freeze:%{public}u", +- result.result, result.authSubType, result.remainTimes, result.freezingTime); ++ "userauthAsyncStub result:%{public}d, sub:%{public}" PRIu64 ", remain:%{public}u, freeze:%{public}u", ++ result.result, result.authSubType, result.remainTimes, result.freezingTime); + getPropCallback_->onGetProperty(result); + } + +diff --git a/frameworks/kitsimpl/src/userauth_proxy.cpp b/frameworks/kitsimpl/src/userauth_proxy.cpp +index 65c9093aca2e7059913c7f16b0316ef22f993ef5..92b2cbd2da779cbf840f6ff0c49073a0c4219be1 100644 +--- a/frameworks/kitsimpl/src/userauth_proxy.cpp ++++ b/frameworks/kitsimpl/src/userauth_proxy.cpp +@@ -12,6 +12,7 @@ + * See the License for the specific language governing permissions and + * limitations under the License. + */ ++#include + #include + #include + #include "userauth_hilog_wrapper.h" +@@ -44,7 +45,7 @@ int32_t UserAuthProxy::GetAvailableStatus(const AuthType authType, const AuthTur + } + bool ret = SendRequest(static_cast(IUserAuth::USER_AUTH_GET_AVAILABLE_STATUS), data, reply, option); + if (!ret) { +- USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret); ++ USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret); + return IPC_ERROR; + } + if (!reply.ReadInt32(result)) { +@@ -63,7 +64,7 @@ void UserAuthProxy::GetProperty(const GetPropertyRequest request, sptr(request.authType))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(request.authType))."); +@@ -82,8 +83,8 @@ void UserAuthProxy::GetProperty(const GetPropertyRequest request, sptronExecutorPropertyInfo(result); +- USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret); +- return ; ++ USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret); ++ return; + } + } + void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptr& callback) +@@ -95,7 +96,7 @@ void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptr(request.authType))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(request.authType))."); +@@ -117,8 +118,8 @@ void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptronSetExecutorProperty(result); +- USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret); +- return ; ++ USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret); ++ return; + } + } + +@@ -129,13 +130,13 @@ uint64_t UserAuthProxy::Auth(const uint64_t challenge, const AuthType authType, + u_int64_t result = SUCCESS; + MessageParcel data; + MessageParcel reply; +- MessageOption option; ++ MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { + USERAUTH_HILOGE(MODULE_INNERKIT, "userauth write descriptor failed!"); + return result; + } +- USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthProxy::Auth challenge = %{public}llu", challenge); ++ USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthProxy::Auth challenge = %{public}" PRIu64 "", challenge); + if (!data.WriteUint64(challenge)) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(challenge)."); + return E_READ_PARCEL_ERROR; +@@ -154,7 +155,7 @@ uint64_t UserAuthProxy::Auth(const uint64_t challenge, const AuthType authType, + } + bool ret = SendRequest(IUserAuth::USER_AUTH_AUTH, data, reply, option); + if (!ret) { +- USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret); ++ USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret); + return result; + } + if (!reply.ReadUint64(result)) { +@@ -172,7 +173,7 @@ uint64_t UserAuthProxy::AuthUser(const int32_t userId, const uint64_t challenge, + u_int64_t result = SUCCESS; + MessageParcel data; + MessageParcel reply; +- MessageOption option; ++ MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { + USERAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); +@@ -200,7 +201,7 @@ uint64_t UserAuthProxy::AuthUser(const int32_t userId, const uint64_t challenge, + } + bool ret = SendRequest(IUserAuth::USER_AUTH_AUTH_USER, data, reply, option); + if (!ret) { +- USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); ++ USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret); + return result; + } + if (!reply.ReadUint64(result)) { +@@ -229,7 +230,7 @@ int32_t UserAuthProxy::CancelAuth(const uint64_t contextId) + } + bool ret = SendRequest(IUserAuth::USER_AUTH_CANCEL_AUTH, data, reply, option); + if (!ret) { +- USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); ++ USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret); + return IPC_ERROR; + } + if (!reply.ReadInt32(result)) { +@@ -254,7 +255,7 @@ int32_t UserAuthProxy::GetVersion() + + bool ret = SendRequest(IUserAuth::USER_AUTH_GET_VERSION, data, reply, option); + if (!ret) { +- USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); ++ USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret); + return IPC_ERROR; + } + if (!reply.ReadInt32(result)) { +diff --git a/interfaces/innerkits/js/ohos.UserIAM.userAuth_API7.d.ts b/interfaces/innerkits/js/ohos.UserIAM.userAuth_API7.d.ts +new file mode 100644 +index 0000000000000000000000000000000000000000..5eca79f7b3ad0ddaed8745c2c8e4795eb85974a1 +--- /dev/null ++++ b/interfaces/innerkits/js/ohos.UserIAM.userAuth_API7.d.ts +@@ -0,0 +1,336 @@ ++/* ++ * 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. ++ */ ++ ++import{AsyncCallback} from './basic'; ++ ++/** ++ * User authentication ++ * @since 8 ++ * @sysCap SystemCapability.UserIAM.UserAuth.BiometricAuth ++ * @devices phone, tablet ++ * @permission ohos.permission.ACCESS_BIOMETRIC ++ */ ++declare namespace userIAM ++{ ++ class Authenticator ++ { ++ /** ++ * Execute authentication. ++ * @since 8 ++ * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth ++ * @param type Indicates the authentication type. ++ * @param level Indicates the security level. ++ * @return Returns authentication result, which is specified by AuthenticationResult. ++ */ ++ execute(type: string, level: string, callback: AsyncCallback): void; ++ execute(type:string, level:string): Promise; ++ ++ /** ++ * Cancels the current authentication. ++ * @since 8 ++ * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth ++ * @return Returns a cancel result, which is specified by Result. ++ */ ++ cancel(): number; ++ ++ /** ++ * Checks whether the device supports the specified authentication type and security level. ++ * @since 8 ++ * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth ++ * @param type Indicates the authentication type. ++ * @param level Indicates the security level. ++ * @return Returns a check result, which is specified by CheckAvailabilityResult. ++ */ ++ checkAvailability(type: AuthType, level: SecureLevel): number ++ ++ /** ++ * Registers an event callback. ++ * @since 8 ++ * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth ++ * @param type Indicates the event type. ++ * @param callback Indicates the authentication tip callback to register. ++ */ ++ on(type: "tip", callback: Callback) : void; ++ ++ /** ++ * Unregisters an event callback. ++ * @since 8 ++ * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth ++ * @param type Indicates the event type. ++ * @param callback Indicates the authentication tip callback to unregister. ++ */ ++ off(type: "tip", callback?: Callback) : void; ++ } ++ ++ /** ++ * Get Authenticator instance. ++ * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth ++ * @return Returns an Authenticator. ++ */ ++ function getAuthenticator(): Authenticator; ++ ++ /** ++ * Auth types ++ */ ++ type AuthType = "ALL" | "FACE_ONLY"; ++ ++ /** ++ * Secure levels ++ */ ++ type SecureLevel = "S1" | "S2" | "S3" | "S4"; ++ ++ interface Tip { ++ /** ++ * Indicates whether authentication tip is obtained, defined in Result. ++ * @since 8 ++ */ ++ errorCode: number; ++ ++ /** ++ * Indicates an authentication tip event, defined in TipEvent. ++ * @since 8 ++ */ ++ tipEvent: number; ++ ++ /** ++ * Indicates the return code of an authentication tip, defined in TipCode. ++ * @since 8 ++ */ ++ tipCode: number; ++ ++ /** ++ * Indicates the description of an authentication tip code. ++ * @since 8 ++ */ ++ tipInfo: string; ++ } ++ ++ export enum AuthenticationResult { ++ /** ++ * Indicates that the device does not support authentication. ++ */ ++ NO_SUPPORT = -1, ++ ++ /** ++ * Indicates that authentication is success. ++ */ ++ SUCCESS = 0, ++ ++ /** ++ * Indicates the authenticator fails to identify user. ++ */ ++ COMPARE_FAILURE = 1, ++ ++ /** ++ * Indicates that authentication has been canceled. ++ */ ++ CANCELED = 2, ++ ++ /** ++ * Indicates that authentication has timed out. ++ */ ++ TIMEOUT = 3, ++ ++ /** ++ * Indicates a failure to open the camera. ++ */ ++ CAMERA_FAIL = 4, ++ ++ /** ++ * Indicates that the authentication task is busy. Wait for a few seconds and try again. ++ */ ++ BUSY = 5, ++ ++ /** ++ * Indicates incorrect parameters. ++ */ ++ INVALID_PARAMETERS = 6, ++ ++ /** ++ * Indicates that the authenticator is locked. ++ */ ++ LOCKED = 7, ++ ++ /** ++ * Indicates that the user has not enrolled the authenticator. ++ */ ++ NOT_ENROLLED = 8, ++ ++ /** ++ * Indicates other errors. ++ */ ++ GENERAL_ERROR = 100, ++ } ++ ++ export enum Result { ++ /** ++ * Indicates that execute is success. ++ * @since 8 ++ */ ++ SUCCESS = 0, ++ ++ /** ++ * Indicates that execute is failed. ++ * @since 8 ++ */ ++ FAILED = 1, ++ } ++ ++ export enum CheckAvailabilityResult { ++ /** ++ * Indicates that the device supports the specified authentication type and security level. ++ * @since 8 ++ */ ++ SUPPORTED = 0, ++ ++ /** ++ * Indicates that the device does not support the specified authentication type. ++ * @since 8 ++ */ ++ AUTH_TYPE_NOT_SUPPORT = 1, ++ ++ /** ++ * Indicates that the device does not support the specified authentication security level. ++ * @since 8 ++ */ ++ SECURE_LEVEL_NOT_SUPPORT = 2, ++ ++ /** ++ * Indicates that the device does not support distributed authentication. ++ * @since 8 ++ */ ++ DISTRIBUTED_AUTH_NOT_SUPPORT = 3, ++ ++ /** ++ * Indicates that the device does not have the authentication credential. ++ * @since 8 ++ */ ++ NOT_ENROLLED = 4, ++ ++ /** ++ * Indicates that the number of parameters is incorrect. ++ * @since 8 ++ */ ++ PARAM_NUM_ERROR = 5, ++ } ++ ++ export enum TipEvent { ++ /** ++ * Enroll or authenticate result. ++ * @since 8 ++ */ ++ RESULT = 1, ++ ++ /** ++ * Cancel result. ++ * @since 8 ++ */ ++ CANCEL = 2, ++ ++ /** ++ * Prompt for user enroll and authentication. ++ * @since 8 ++ */ ++ ACQUIRE = 3, ++ ++ /** ++ * Busy. ++ * @since 8 ++ */ ++ BUSY = 4, ++ ++ /** ++ * Out of memory. ++ * @since 8 ++ */ ++ OUT_OF_MEM = 5, ++ ++ /** ++ * Index of a face authentication credential. ++ * @since 8 ++ */ ++ FACE_ID = 6, ++ } ++ ++ export enum TipCode { ++ /** ++ * Indicates that the obtained facial image is too bright due to high illumination. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_TOO_BRIGHT = 1, ++ ++ /** ++ * Indicates that the obtained facial image is too dark due to low illumination. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_TOO_DARK = 2, ++ ++ /** ++ * Indicates that the face is too close to the device. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_TOO_CLOSE = 3, ++ ++ /** ++ * Indicates that the face is too far away from the device. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_TOO_FAR = 4, ++ ++ /** ++ * Indicates that the device is too high, and that only the upper part of the face is captured. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_TOO_HIGH = 5, ++ ++ /** ++ * Indicates that the device is too low, and that only the lower part of the face is captured. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_TOO_LOW = 6, ++ ++ /** ++ * Indicates that the device is deviated to the right, and that only the right part of the face is captured. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_TOO_RIGHT = 7, ++ ++ /** ++ * Indicates that the device is deviated to the left, and that only the left part of the face is captured. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_TOO_LEFT = 8, ++ ++ /** ++ * Indicates that the face moves too fast during facial information collection. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_TOO_MUCH_MOTION = 9, ++ ++ /** ++ * Indicates that the face is not facing the device. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_POOR_GAZE = 10, ++ ++ /** ++ * Indicates that no face is detected. ++ * @since 8 ++ */ ++ FACE_AUTH_TIP_NOT_DETECTED = 11, ++ } ++} ++ ++export default userIAM; +\ No newline at end of file +diff --git a/interfaces/innerkits/native/BUILD.gn b/interfaces/innerkits/native/BUILD.gn +index e07ff2c54359d07e3119e446b0f339ce76e02bef..c85df30676dae30d7797a365e5c345ab0de22d72 100755 +--- a/interfaces/innerkits/native/BUILD.gn ++++ b/interfaces/innerkits/native/BUILD.gn +@@ -26,7 +26,10 @@ config("userauth_public_config") { + + ohos_shared_library("userauth_framework") { + sources = [ ++ "../../../frameworks/kitsimpl/src/iuserauth_api7_callback.cpp", + "../../../frameworks/kitsimpl/src/userauth.cpp", ++ "../../../frameworks/kitsimpl/src/userauth_api7.cpp", ++ "../../../frameworks/kitsimpl/src/userauth_api7_datamgr.cpp", + "../../../frameworks/kitsimpl/src/userauth_async_stub.cpp", + "../../../frameworks/kitsimpl/src/userauth_proxy.cpp", + ] +diff --git a/interfaces/innerkits/native/include/iuserauth_api7_callback.h b/interfaces/innerkits/native/include/iuserauth_api7_callback.h +new file mode 100644 +index 0000000000000000000000000000000000000000..2c5f1c4b4aedb0d535b7c974a7e4446bb1d3a504 +--- /dev/null ++++ b/interfaces/innerkits/native/include/iuserauth_api7_callback.h +@@ -0,0 +1,41 @@ ++/* ++ * 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. ++ */ ++ ++#ifndef IUSERAUTH_API7_CALLBACK_H ++#define IUSERAUTH_API7_CALLBACK_H ++ ++#include ++#include "userauth_info.h" ++#include "userauth_callback.h" ++#include "userauth_api7_callback.h" ++ ++ ++namespace OHOS { ++namespace UserIAM { ++namespace API7UserAuth { ++class IUserAuthAPI7Callback : public UserAuth::UserAuthCallback { ++public: ++ explicit IUserAuthAPI7Callback(std::shared_ptr& impl); ++ virtual ~IUserAuthAPI7Callback() = default; ++ ++ void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override; ++ void onResult(const int32_t result, const UserAuth::AuthResult extraInfo) override; ++private: ++ std::shared_ptr callback_ {nullptr}; ++}; ++} // namespace API7UserAuth ++} // namespace UserIAM ++} // namespace OHOS ++#endif // IUSERAUTH_API7_CALLBACK_H +\ No newline at end of file +diff --git a/interfaces/innerkits/native/include/userauth_api7.h b/interfaces/innerkits/native/include/userauth_api7.h +new file mode 100644 +index 0000000000000000000000000000000000000000..070fce2e869c2fa0992a1a48867f7b5c1ec23e4b +--- /dev/null ++++ b/interfaces/innerkits/native/include/userauth_api7.h +@@ -0,0 +1,41 @@ ++/* ++ * 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. ++ */ ++ ++#ifndef USERAUTH_API7_H ++#define USERAUTH_API7_H ++ ++#include ++ ++#include "userauth_api7_info.h" ++#include "userauth_api7_callback.h" ++ ++namespace OHOS { ++namespace UserIAM { ++namespace API7UserAuth { ++class UserAuthAPI7 { ++public: ++ UserAuthAPI7() = default; ++ ~UserAuthAPI7() = default; ++ static UserAuthAPI7 &GetAuthenticator(); ++ void Execute(std::string authtype, std::string trustLevel, std::shared_ptr callback); ++ int32_t Cancel(); ++ int32_t CheckAvailability(std::string authtype, std::string trustLevel); ++ void On(std::string tip, std::shared_ptr tipCallback); ++ void Off(std::string tip, std::shared_ptr tipCallback); ++}; ++} // namespace API7UserAuth ++} // namespace UserIAM ++} // namespace OHOS ++#endif // USERAUTH_API7_H +\ No newline at end of file +diff --git a/interfaces/innerkits/native/include/userauth_api7_callback.h b/interfaces/innerkits/native/include/userauth_api7_callback.h +new file mode 100644 +index 0000000000000000000000000000000000000000..c9d3dcb7abbed938356a384083fc255a45e02b6f +--- /dev/null ++++ b/interfaces/innerkits/native/include/userauth_api7_callback.h +@@ -0,0 +1,32 @@ ++/* ++ * 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. ++ */ ++ ++#ifndef USERAUTH_API7_CALLBACK_H ++#define USERAUTH_API7_CALLBACK_H ++ ++#include "userauth_api7_info.h" ++ ++namespace OHOS { ++namespace UserIAM { ++namespace API7UserAuth { ++class UserAuthAPI7Callback { ++public: ++ virtual void API7OnResult(const int32_t result) = 0; ++ virtual void TipCallback(const Tip result) = 0; ++}; ++} // namespace API7UserAuth ++} // namespace UserIAM ++} // namespace OHOS ++#endif // USERAUTH_API7_CALLBACK_H +\ No newline at end of file +diff --git a/interfaces/innerkits/native/include/userauth_api7_datamgr.h b/interfaces/innerkits/native/include/userauth_api7_datamgr.h +new file mode 100644 +index 0000000000000000000000000000000000000000..40d52c116665e7ae54607221f8831d4649e73ce8 +--- /dev/null ++++ b/interfaces/innerkits/native/include/userauth_api7_datamgr.h +@@ -0,0 +1,41 @@ ++/* ++ * 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. ++ */ ++ ++#ifndef USERAUTH_API7_DATAMGR_H ++#define USERAUTH_API7_DATAMGR_H ++ ++#include "userauth_api7_info.h" ++ ++namespace OHOS { ++namespace UserIAM { ++namespace API7UserAuth { ++class UserAuthAPI7Datamgr { ++public: ++ static UserAuthAPI7Datamgr &GetInstance(); ++ void API7AddContextID(uint64_t contextID); ++ void API7GetContextID(uint64_t &contextID); ++ void API7DeleteContextID(); ++ void SetAPI7Tip(bool isTipOn); ++ bool GetAPI7Tip(); ++private: ++ UserAuthAPI7Datamgr() = default; ++ ~UserAuthAPI7Datamgr() = default; ++ uint64_t contextID_ = CONTEXTID_INIT; ++ bool isTipOn_ = false; ++}; ++} // namespace API7UserAuth ++} // namespace UserIAM ++} // namespace OHOS ++#endif // USERAUTH_API7_DATAMGR_H +\ No newline at end of file +diff --git a/interfaces/innerkits/native/include/userauth_api7_hilog_wrapper.h b/interfaces/innerkits/native/include/userauth_api7_hilog_wrapper.h +new file mode 100644 +index 0000000000000000000000000000000000000000..517032c9682bb4a4b1d390fb5eeb2bb82df91be7 +--- /dev/null ++++ b/interfaces/innerkits/native/include/userauth_api7_hilog_wrapper.h +@@ -0,0 +1,72 @@ ++/* ++ * 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. ++ */ ++ ++#ifndef USERAUTH_API7_HILOG_WRAPPER_H ++#define USERAUTH_API7_HILOG_WRAPPER_H ++ ++#define CONFIG_HILOG ++#ifdef CONFIG_HILOG ++ ++#include "hilog/log.h" ++ ++namespace OHOS { ++namespace UserIAM { ++namespace API7UserAuth { ++#define filename__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) ++#define formated__(fmt, ...) "[%{public}s] %{public}s# " fmt, filename__, __FUNCTION__, ##__VA_ARGS__ ++ ++ ++#ifdef USERAUTH_API7_HILOGE ++#undef USERAUTH_API7_HILOGE ++#endif ++ ++#ifdef USERAUTH_API7_HILOGD ++#undef USERAUTH_API7_HILOGD ++#endif ++ ++// param of log interface, such as USERAUTH_API7_HILOGF. ++enum UserAuthAPI7SubModule { ++ MODULE_API7 = 0, ++ USERAUTHAPI7_MODULE_BUTT, ++}; ++ ++// 0xD002900: subsystem:distributeddatamgr module:distributedgallery, 8 bits reserved. ++static constexpr unsigned int BASE_USERAUTH_API7_DOMAIN_ID = 0xD002910; ++ ++enum UserAuthAPI7DomainId { ++ USERAUTH_API7_DOMAIN = BASE_USERAUTH_API7_DOMAIN_ID + MODULE_API7, ++ USERAUTH_API7_BUTT, ++}; ++ ++static constexpr OHOS::HiviewDFX::HiLogLabel L_LABEL[USERAUTHAPI7_MODULE_BUTT] = { ++ {LOG_CORE, USERAUTH_API7_DOMAIN, "UserAUTH_API7"}, ++}; ++ ++// In order to improve performance, do not check the module range. ++// Besides, make sure module is less than USERAUTH_API7_MODULE_BUTT. ++#define USERAUTH_API7_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(L_LABEL[module], formated__(__VA_ARGS__)) ++#define USERAUTH_API7_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(L_LABEL[module], formated__(__VA_ARGS__)) ++} // namespace UserAUTH_API7 ++} // namespace UserIAM ++} // namespace OHOS ++ ++#else ++ ++#define USERAUTH_API7_HILOGE(...) ++#define USERAUTH_API7_HILOGD(...) ++ ++#endif // CONFIG_HILOG ++ ++#endif // USERAUTH_API7_HILOG_WRAPPER_H +diff --git a/interfaces/innerkits/native/include/userauth_api7_info.h b/interfaces/innerkits/native/include/userauth_api7_info.h +new file mode 100644 +index 0000000000000000000000000000000000000000..445ce9bdbcd543f7c1df828052aa314ad59d6c4c +--- /dev/null ++++ b/interfaces/innerkits/native/include/userauth_api7_info.h +@@ -0,0 +1,150 @@ ++/* ++ * 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. ++ */ ++ ++#ifndef USERAUTH_API7_INFO_H ++#define USERAUTH_API7_INFO_H ++ ++#include ++ ++#define CONTEXTID_INIT 0 ++#define CHALLENGE_INIT 0 ++ ++namespace OHOS { ++namespace UserIAM { ++namespace API7UserAuth { ++// Authentication Result ++enum AuthenticationResult { ++ /** ++ * The device does not support the current authentication method. ++ */ ++ NO_SUPPORT = -1, ++ /** ++ * Authentication succeeded. ++ */ ++ SUCCESS = 0, ++ /** ++ * Alignment failed. ++ */ ++ COMPARE_FAILURE = 1, ++ /** ++ * User deauthentication. ++ */ ++ CANCELED = 2, ++ /** ++ * Authentication timed out. ++ */ ++ TIMEOUT = 3, ++ /** ++ * Failed to turn on camera. ++ */ ++ CAMERA_FAIL = 4, ++ /** ++ * The authentication service is busy, please try again later. ++ */ ++ BUSY = 5, ++ /** ++ * Authentication parameters are invalid. ++ */ ++ INVALID_PARAMETERS = 6, ++ /** ++ * Too many authentication failures, locked. ++ */ ++ LOCKED = 7, ++ /** ++ * Authentication credentials not entered. ++ */ ++ NOT_ENROLLED = 78, ++ /** ++ * other errors. ++ */ ++ GENERAL_ERROR = 100, ++}; ++// Device Certification Capability ++enum CheckAvailabilityResult { ++ // The device supports the specified authentication type and authentication security level ++ SUPPORTED = 0, ++ // The device does not support the specified authentication type ++ AUTH_TYPE_NOT_SUPPORT = 1, ++ // The device does not support the specified authentication security level ++ SECURE_LEVEL_NOT_SUPPORT = 2, ++ // The device does not support distributed authentication ++ DISTRIBUTED_AUTH_NOT_SUPPORT = 3, ++ // Authentication credentials are not entered in the device ++ NO_ENROLLED = 4, ++ // wrong number of parameters ++ PARAM_NUM_ERROR = 5, ++}; ++// Prompt events during authentication ++enum TipEvent { ++ // Entry or Certification Results ++ RESULT = 1, ++ // Entry or Certification Cancellation ++ CANCEL = 2, ++ // Prompt during entry or authentication ++ ACQUIRE = 3, ++ // Entry or authentication functions are occupied ++ ISBUSY = 4, ++ // Not enough storage ++ OUT_OF_MEM = 5, ++ // Face authentication credential index number ++ FACE_ID = 6, ++}; ++// Result ++enum Result { ++ // SUCCESSED ++ SUCCESSED = 0, ++ // FAILED ++ FAILED = 1, ++}; ++// Prompt code during authentication ++enum TipCode { ++ // The light is too strong, the acquired image is too bright ++ FACE_AUTH_TIP_TOO_BRIGHT = 1, ++ // The light is too dim, the acquired image is too dark ++ FACE_AUTH_TIP_TOO_DARK = 2, ++ // The face is too close to the device ++ FACE_AUTH_TIP_TOO_CLOSE = 3, ++ // The face is too far from the device ++ FACE_AUTH_TIP_TOO_FAR = 4, ++ // The device is too high, only the face obtained ++ FACE_AUTH_TIP_TOO_HIGH = 5, ++ // The device is too low, only the lower part of the face is obtained ++ FACE_AUTH_TIP_TOO_LOW = 6, ++ // The device is too far to the right, only the right part of the face is obtained ++ FACE_AUTH_TIP_TOO_RIGHT = 7, ++ // The device is too far to the left, only the left part of the face is obtained ++ FACE_AUTH_TIP_TOO_LEFT = 8, ++ // During image acquisition, the user's face moves too fast ++ FACE_AUTH_TIP_TOO_MUCH_MOTION = 9, ++ // no facing camera ++ FACE_AUTH_TIP_POOR_GAZE = 10, ++ // No face information detected ++ FACE_AUTH_TIP_NOT_DETECTED = 11, ++}; ++// Prompt information during the authentication process ++struct Tip { ++ // Whether the prompt information was successfully obtained ++ int32_t errorCode; ++ // Authentication prompt event ++ int32_t tipEvent; ++ // Authentication prompt event ++ int32_t tipCode; ++ // Description of the event prompt code of the authentication prompt ++ std::string tipInfo; ++}; ++} // namespace API7UserAuth ++} // namespace UserIam ++} // namespace OHOS ++#endif // USERAUTH_API7_INFO_H +diff --git a/services/src/userauth_adapter.cpp b/services/src/userauth_adapter.cpp +index 5cacdaad2af34adcac05a4422eee4c1502cff02b..02556c14692e8244c54ee041dcfb40e22890a7e9 100644 +--- a/services/src/userauth_adapter.cpp ++++ b/services/src/userauth_adapter.cpp +@@ -12,8 +12,8 @@ + * See the License for the specific language governing permissions and + * limitations under the License. + */ ++#include + +-#include "userauth_adapter.h" + #include "userauth_hilog_wrapper.h" + #include "userauth_info.h" + #include "auth_attributes.h" +@@ -22,10 +22,12 @@ + #include "useridm_info.h" + #include "userauth_datamgr.h" + #include "userauth_excallback_impl.h" ++#include "userauth_adapter.h" + + namespace OHOS { + namespace UserIAM { + namespace UserAuth { ++const int USERAUTH_VERSION = 1235; + UserAuthAdapter &UserAuthAdapter::GetInstance() + { + static UserAuthAdapter instance; +@@ -122,9 +124,6 @@ int32_t UserAuthAdapter::SetProPropAuthInfo(OHOS::UserIAM::AuthResPool::AuthAttr + setPropCallback->OnResult(ret, extraInfo); + return ret; + } +- if (ret != SUCCESS) { +- return ret; +- } + ret = authAttributes.SetUint64ArrayValue(AUTH_TEMPLATE_ID_LIST, templateIds); + if (ret != SUCCESS) { + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint64ArrayValue AUTH_TEMPLATE_ID_LIST ERROR!"); +@@ -212,7 +211,7 @@ int32_t UserAuthAdapter::Cancel(uint64_t sessionId) + int32_t UserAuthAdapter::GetVersion() + { + USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetVersion is start!"); +- int32_t version = 1235; ++ int32_t version = USERAUTH_VERSION; + + return version; + } +@@ -313,7 +312,7 @@ int32_t UserAuthAdapter::GetEachExecutorProp(GetPropertyRequest &requset, Execut + return INVALID_PARAMETERS; + } + } +- USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthAdapter::GetEachExecutorProp %{public}llu:%{public}u:%{public}u", ++ USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthAdapter::GetEachExecutorProp %{public}" PRIu64 ":%{public}u:%{public}u", + result.authSubType, result.remainTimes, result.freezingTime); + return ret; + } +@@ -365,21 +364,22 @@ int32_t UserAuthAdapter::SetExecutorProp(uint64_t callerUID, std::string pkgName + + int32_t UserAuthAdapter::coAuth(CoAuthInfo coAuthInfo, sptr& callback) + { +- USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth coAuthHandle is start!"); ++ USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth coAuth is start!"); + + std::shared_ptr coAuthCallback = + std::make_shared(callback, coAuthInfo, false); + OHOS::UserIAM::CoAuth::AuthInfo authInfo; + int32_t ret = authInfo.SetPkgName(coAuthInfo.pkgName); + if (ret != SUCCESS) { +- USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth pAuthInfo_ SetPkgName ERROR!"); ++ USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth authInfo SetPkgName ERROR!"); + return ret; + } + ret = authInfo.SetCallerUid(coAuthInfo.callerID); + if (ret != SUCCESS) { +- USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth pAuthInfo_ SetCallerUid ERROR!"); ++ USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth authInfo SetCallerUid ERROR!"); + return ret; + } ++ + ret = UserAuthCallbackImplCoAuth::SaveCoauthCallback(coAuthInfo.contextID, coAuthCallback); + if (ret != SUCCESS) { + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SaveCoauthCallback ERROR!"); +diff --git a/services/src/userauth_excallback_impl.cpp b/services/src/userauth_excallback_impl.cpp +index b5e8cbf4dc12b3c96105be25a3919a3124ac2329..9a8c1edec331fea9e89940b638af6a79ef00cfff 100644 +--- a/services/src/userauth_excallback_impl.cpp ++++ b/services/src/userauth_excallback_impl.cpp +@@ -20,6 +20,7 @@ + #include "userauth_async_proxy.h" + #include "securec.h" + ++#include + #include + #include + +@@ -32,7 +33,7 @@ UserAuthCallbackImplSetProp::UserAuthCallbackImplSetProp(const sptr lock(mutex_); +- USERAUTH_HILOGD(MODULE_SERVICE, "OnFinishHandle scheduleTokensize:%{public}d, resultCode:%{public}d", ++ USERAUTH_HILOGD(MODULE_SERVICE, "OnFinishHandle scheduleTokensize:%{public}d, resultCode:%{public}u", + scheduleToken.size(), resultCode); + callbackNowCount_++; + if (isResultDoneFlag_) { +@@ -258,7 +259,7 @@ int32_t UserAuthCallbackImplCoAuth::DeleteCoauthCallback(uint64_t contextId) + if (iter != saveCoauthCallback_.end()) { + saveCoauthCallback_.erase(iter); + resultCode = SUCCESS; +- USERAUTH_HILOGD(MODULE_SERVICE, "contextId XXXX%{public}04llx is deleted", contextId); ++ USERAUTH_HILOGD(MODULE_SERVICE, "contextId XXXX%{public}04" PRIx64 " is deleted", contextId); + } else { + resultCode = FAIL; + USERAUTH_HILOGE(MODULE_SERVICE, "contextId is not found and do not delete callback"); +@@ -272,7 +273,7 @@ UserAuthCallbackImplIDMGetPorp::UserAuthCallbackImplIDMGetPorp(const sptr ATL4 || authTurstLevel < ATL1) { + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService GetAvailableStatus AuthTurstLevel is NOT SUPPORT!"); + return result; +@@ -81,8 +83,8 @@ int32_t UserAuthService::GetAvailableStatus(const AuthType authType, const AuthT + + ret = userauthController_.GetAuthTrustLevel(userID, authType, authTurstLevelFromSys); + if (ret == SUCCESS) { +- USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthService iAuthTurstLevel_:%{public}d", authTurstLevelFromSys); +- USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthService authTurstLevel:%{public}d", authTurstLevel); ++ USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService iAuthTurstLevel_:%{public}u", authTurstLevelFromSys); ++ USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService authTurstLevel:%{public}u", authTurstLevel); + if (authTurstLevelFromSys < authTurstLevel) { + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService authTurstLevel is ERROR!"); + return result; +@@ -144,7 +146,7 @@ void UserAuthService::SetProperty(const SetPropertyRequest request, sptronSetExecutorProperty(ret); +- return ; ++ return; + } + } + +@@ -156,14 +158,20 @@ int32_t UserAuthService::GetCallingUserID(int32_t &userID) + } + Security::AccessToken::ATokenTypeEnum callingType = Security::AccessToken::AccessTokenKit::GetTokenType(tokenID); + if (callingType != Security::AccessToken::TOKEN_HAP) { +- USERAUTH_HILOGE(MODULE_SERVICE, "CallingType is not hap."); +- return TYPE_NOT_SUPPORT; ++ userID = 100; ++ return SUCCESS; ++ ++ // USERAUTH_HILOGE(MODULE_SERVICE, "CallingType is not hap."); ++ // return TYPE_NOT_SUPPORT; + } + Security::AccessToken::HapTokenInfo hapTokenInfo; + int result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenID, hapTokenInfo); + if (result != SUCCESS) { +- USERAUTH_HILOGE(MODULE_SERVICE, "Get hap token info failed."); +- return TYPE_NOT_SUPPORT; ++ userID = 100; ++ return SUCCESS; ++ ++ // USERAUTH_HILOGE(MODULE_SERVICE, "Get hap token info failed."); ++ // return TYPE_NOT_SUPPORT; + } + userID = (int32_t)hapTokenInfo.userID; + USERAUTH_HILOGE(MODULE_SERVICE, "GetCallingUserID is %{public}d", userID); +diff --git a/test/unittest/include/userauth_test.h b/test/unittest/include/userauth_test.h +index eb0908a704951e98e7480ed07e7e0e68c4b2fee1..e020c97aa0d1e5ecf66d18d81e6fe2e0324f7af8 100644 +--- a/test/unittest/include/userauth_test.h ++++ b/test/unittest/include/userauth_test.h +@@ -25,6 +25,11 @@ void UseriamUtTest_003(); + void UseriamUtTest_004(); + void UseriamUtTest_005(); + void UseriamUtTest_006(); ++void UseriamUtTest_007(); ++void UseriamUtTest_008(); ++void UseriamUtTest_009(); ++void UseriamUtTest_010(); ++void UseriamUtTest_011(); + } + } + } +diff --git a/test/unittest/src/userauth_test.cpp b/test/unittest/src/userauth_test.cpp +index cfd924135e6271f97f34a6adb34305eb45ba348e..127f97cea1b4ee38af9047db591f5303a168bc57 100644 +--- a/test/unittest/src/userauth_test.cpp ++++ b/test/unittest/src/userauth_test.cpp +@@ -17,6 +17,7 @@ + #include + #include + #include "user_auth.h" ++#include "userauth_api7.h" + #include "userauth_callback.h" + #include "userauth_info.h" + #include "userauth_test.h" +@@ -93,6 +94,25 @@ void TestSetPropCallback::onSetProperty(const int32_t result) + std::cout << "onSetProperty callback" << std::endl; + } + ++class TestUserAuthAPI7Callback : public API7UserAuth::UserAuthAPI7Callback { ++public: ++ TestUserAuthAPI7Callback() = default; ++ virtual ~TestUserAuthAPI7Callback() = default; ++ ++ void API7OnResult(const int32_t result) override; ++ void TipCallback(const API7UserAuth::Tip result) override; ++}; ++ ++void TestUserAuthAPI7Callback::API7OnResult(const int32_t result) ++{ ++ std::cout << "API7OnResult callback" << std::endl; ++} ++ ++void TestUserAuthAPI7Callback::TipCallback(const API7UserAuth::Tip result) ++{ ++ std::cout << "TipCallback callback" << std::endl; ++} ++ + HWTEST_F(UseriamUtTest, UseriamUtTest_001, TestSize.Level1) + { + AuthType authType = FACE; +@@ -145,6 +165,37 @@ HWTEST_F(UseriamUtTest, UseriamUtTest_006, TestSize.Level1) + uint64_t contextId = 123; + EXPECT_EQ(0, UserAuth::GetInstance().CancelAuth(contextId)); + } ++ ++HWTEST_F(UseriamUtTest, UseriamUtTest_007, TestSize.Level1) ++{ ++ std::shared_ptr callback = ++ std::make_shared(); ++ API7UserAuth::UserAuthAPI7::GetAuthenticator().Execute("FACE_ONLY", "S1", callback); ++} ++ ++HWTEST_F(UseriamUtTest, UseriamUtTest_008, TestSize.Level1) ++{ ++ EXPECT_EQ(0, API7UserAuth::UserAuthAPI7::GetAuthenticator().Cancel()); ++} ++ ++HWTEST_F(UseriamUtTest, UseriamUtTest_009, TestSize.Level1) ++{ ++ EXPECT_EQ(0, API7UserAuth::UserAuthAPI7::GetAuthenticator().CheckAvailability("FACE_ONLY", "S1")); ++} ++ ++HWTEST_F(UseriamUtTest, UseriamUtTest_010, TestSize.Level1) ++{ ++ std::shared_ptr callback = ++ std::make_shared(); ++ API7UserAuth::UserAuthAPI7::GetAuthenticator().On("tip", callback); ++} ++ ++HWTEST_F(UseriamUtTest, UseriamUtTest_011, TestSize.Level1) ++{ ++ std::shared_ptr callback = ++ std::make_shared(); ++ API7UserAuth::UserAuthAPI7::GetAuthenticator().Off("tip", callback); ++} + } + } + } diff --git a/frameworks/kitsimpl/src/iuserauth_api7_callback.cpp b/frameworks/kitsimpl/src/iuserauth_api7_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b5340ec0fe18868c6ed6dd9685498f4027af7895 --- /dev/null +++ b/frameworks/kitsimpl/src/iuserauth_api7_callback.cpp @@ -0,0 +1,120 @@ +/* + * 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. + */ +#include + +#include "userauth_api7_hilog_wrapper.h" +#include "userauth_api7_datamgr.h" +#include "userauth_api7_info.h" +#include "iuserauth_api7_callback.h" +namespace OHOS { +namespace UserIAM { +namespace API7UserAuth { +std::map g_convertResult = { + {UserAuth::SUCCESS, API7UserAuth::SUCCESS}, + {UserAuth::FAIL, API7UserAuth::GENERAL_ERROR}, + {UserAuth::GENERAL_ERROR, API7UserAuth::GENERAL_ERROR}, + {UserAuth::CANCELED, API7UserAuth::CANCELED}, + {UserAuth::TIMEOUT, API7UserAuth::TIMEOUT}, + {UserAuth::TYPE_NOT_SUPPORT, API7UserAuth::NO_SUPPORT}, + {UserAuth::TRUST_LEVEL_NOT_SUPPORT, API7UserAuth::NO_SUPPORT}, + {UserAuth::BUSY, API7UserAuth::BUSY}, + {UserAuth::INVALID_PARAMETERS, API7UserAuth::INVALID_PARAMETERS}, + {UserAuth::LOCKED, API7UserAuth::LOCKED}, + {UserAuth::NOT_ENROLLED, API7UserAuth::NOT_ENROLLED}, + {UserAuth::IPC_ERROR, API7UserAuth::GENERAL_ERROR}, + {UserAuth::INVALID_CONTEXTID, API7UserAuth::GENERAL_ERROR}, + {UserAuth::E_WRITE_PARCEL_ERROR, API7UserAuth::GENERAL_ERROR}, + {UserAuth::E_READ_PARCEL_ERROR, API7UserAuth::GENERAL_ERROR}, + {UserAuth::E_GET_POWER_SERVICE_FAILED, API7UserAuth::GENERAL_ERROR}, + {UserAuth::E_RET_UNDONE, API7UserAuth::GENERAL_ERROR}, + {UserAuth::E_RET_NOSERVER, API7UserAuth::GENERAL_ERROR}, +}; + +std::map g_convertTipInfo = { + { FACE_AUTH_TIP_TOO_BRIGHT, "the obtained facial image is too bright due to high illumination" }, + { FACE_AUTH_TIP_TOO_DARK, "the obtained facial image is too dark due to low illumination" }, + { FACE_AUTH_TIP_TOO_CLOSE, "the face is too close to the device" }, + { FACE_AUTH_TIP_TOO_FAR, "the face is too far away from the device" }, + { FACE_AUTH_TIP_TOO_HIGH, "the device is too high, and that only the upper part of the face is captured" }, + { FACE_AUTH_TIP_TOO_LOW, "the device is too low, and that only the lower part of the face is captured" }, + { FACE_AUTH_TIP_TOO_RIGHT, + "the device is deviated to the right, and that only the right part of the face is captured" }, + { FACE_AUTH_TIP_TOO_LEFT, + "the device is deviated to the left, and that only the left part of the face is captured" }, + { FACE_AUTH_TIP_TOO_MUCH_MOTION, "the face moves too fast during facial information collection" }, + { FACE_AUTH_TIP_POOR_GAZE, "the face is not facing the device" }, + { FACE_AUTH_TIP_NOT_DETECTED, "no face is detected" }, +}; + +IUserAuthAPI7Callback::IUserAuthAPI7Callback(std::shared_ptr& impl) +{ + callback_ = impl; +} + +void IUserAuthAPI7Callback::onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) +{ + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 onAcquireInfo is start"); + std::string tipOfInfo = ""; + if (UserAuthAPI7Datamgr::GetInstance().GetAPI7Tip()) { + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 GetAPI7Tip is on"); + API7UserAuth::Tip tipInfo; + tipInfo.errorCode = API7UserAuth::SUCCESS; + tipInfo.tipEvent = API7UserAuth::ACQUIRE; + tipInfo.tipCode = acquireInfo; + if (g_convertTipInfo.count(static_cast(acquireInfo)) == 0) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 g_convertTipInfo is 0"); + tipOfInfo = "other error"; + } else { + tipOfInfo = g_convertTipInfo[static_cast(acquireInfo)]; + } + callback_->TipCallback(tipInfo); + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 GetAPI7Tip is end"); + } + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 onAcquireInfo is end"); +} + +void IUserAuthAPI7Callback::onResult(const int32_t result, const UserAuth::AuthResult extraInfo) +{ + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 onResult is start"); + AuthenticationResult authResult; + UserAuthAPI7Datamgr::GetInstance().API7DeleteContextID(); + callback_->API7OnResult(result); + if (UserAuthAPI7Datamgr::GetInstance().GetAPI7Tip()) { + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 GetAPI7Tip is on"); + API7UserAuth::Tip tipInfo; + if (result != UserAuth::SUCCESS) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 result is failed"); + tipInfo.errorCode = API7UserAuth::FAILED; + tipInfo.tipInfo = "FAILED"; + } else { + tipInfo.errorCode = API7UserAuth::SUCCESSED; + tipInfo.tipInfo = "SUCCESSED"; + } + tipInfo.tipEvent = API7UserAuth::RESULT; + if (g_convertResult.count(static_cast(result)) == 0) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 g_convertResult is 0"); + authResult = static_cast(result); + } else { + authResult = g_convertResult[static_cast(result)]; + } + tipInfo.tipCode = authResult; + callback_->TipCallback(tipInfo); + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 GetAPI7Tip is end"); + } + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 onResult is end"); +} +} +} +} \ No newline at end of file diff --git a/frameworks/kitsimpl/src/userauth.cpp b/frameworks/kitsimpl/src/userauth.cpp index 796592ab037fef5f2b219fd75a0a742796648fdb..388caf35a73ee1b7c1cefe561118ed1e5233995e 100644 --- a/frameworks/kitsimpl/src/userauth.cpp +++ b/frameworks/kitsimpl/src/userauth.cpp @@ -12,6 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include + #include #include #include @@ -107,9 +109,13 @@ void UserAuth::GetProperty(const GetPropertyRequest request, std::shared_ptronGetProperty(result); - return ; + return; + } + sptr asyncStub = new (std::nothrow) UserAuthAsyncStub(callback); + if (asyncStub == nullptr) { + USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub failed, GetProperty IUserAuthCallback is nullptr"); + return; } - sptr asyncStub = new UserAuthAsyncStub(callback); proxy_->GetProperty(request, asyncStub); } void UserAuth::SetProperty(const SetPropertyRequest request, std::shared_ptr callback) @@ -124,7 +130,11 @@ void UserAuth::SetProperty(const SetPropertyRequest request, std::shared_ptronSetProperty(E_RET_NOSERVER); return ; } - sptr asyncStub = new UserAuthAsyncStub(callback); + sptr asyncStub = new (std::nothrow) UserAuthAsyncStub(callback); + if (asyncStub == nullptr) { + USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub failed, SetProperty IUserAuthCallback is nullptr"); + return; + } proxy_->SetProperty(request, asyncStub); } uint64_t UserAuth::Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel, @@ -139,7 +149,11 @@ uint64_t UserAuth::Auth(const uint64_t challenge, const AuthType authType, const if (proxy == nullptr) { return E_RET_NOSERVER; } - sptr asyncStub = new UserAuthAsyncStub(callback); + sptr asyncStub = new (std::nothrow) UserAuthAsyncStub(callback); + if (asyncStub == nullptr) { + USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub failed, Auth IUserAuthCallback is nullptr"); + return GENERAL_ERROR; + } uint64_t ret = proxy_->Auth(challenge, authType, authTurstLevel, asyncStub); return ret; } @@ -155,7 +169,11 @@ uint64_t UserAuth::AuthUser(const int32_t userId, const uint64_t challenge, cons if (proxy == nullptr) { return E_RET_NOSERVER; } - sptr asyncStub = new UserAuthAsyncStub(callback); + sptr asyncStub = new (std::nothrow) UserAuthAsyncStub(callback); + if (asyncStub == nullptr) { + USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub failed, AuthUser IUserAuthCallback is nullptr"); + return GENERAL_ERROR; + } uint64_t ret = proxy_->AuthUser(userId, challenge, authType, authTurstLevel, asyncStub); return ret; } diff --git a/frameworks/kitsimpl/src/userauth_api7.cpp b/frameworks/kitsimpl/src/userauth_api7.cpp new file mode 100644 index 0000000000000000000000000000000000000000..89c44cd242cf33cc79846cd16df3e7b8a353b12c --- /dev/null +++ b/frameworks/kitsimpl/src/userauth_api7.cpp @@ -0,0 +1,152 @@ +/* + * 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. + */ +#include + +#include "userauth_info.h" +#include "user_auth.h" +#include "userauth_hilog_wrapper.h" +#include "userauth_api7_hilog_wrapper.h" +#include "userauth_api7_datamgr.h" +#include "iuserauth_api7_callback.h" +#include "userauth_api7.h" + +namespace OHOS { +namespace UserIAM { +namespace API7UserAuth { +std::map g_convertAuthType = { + { "FACE_ONLY", UserAuth::FACE }, +}; +std::map g_convertAuthTurstLevel = { + { "S1", UserAuth::ATL1 }, + { "S2", UserAuth::ATL2 }, + { "S3", UserAuth::ATL3 }, + { "S4", UserAuth::ATL4 }, +}; + +UserAuthAPI7 &UserAuthAPI7::GetAuthenticator() +{ + static UserAuthAPI7 instance; + return instance; +} + +void UserAuthAPI7::Execute(std::string authtype, std::string trustLevel, std::shared_ptr callback) +{ + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 execute is start"); + UserAuth::AuthType exeAuthType; + UserAuth::AuthTurstLevel authTurstLevel; + uint64_t contextID = 0; + + if (callback == nullptr) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 execute callback is Null"); + return; + } + + if (g_convertAuthType.count(authtype) == 0) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 execute g_convertAuthType is 0"); + callback->API7OnResult(NO_SUPPORT); + return; + } else { + exeAuthType = g_convertAuthType[authtype]; + } + + if (g_convertAuthTurstLevel.count(trustLevel) == 0) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 execute g_convertAuthTurstLevel is 0"); + callback->API7OnResult(NO_SUPPORT); + return; + } else { + authTurstLevel = g_convertAuthTurstLevel[trustLevel]; + } + + std::shared_ptr asyncStub = std::make_shared(callback); + if (asyncStub == nullptr) { + USERAUTH_API7_HILOGE(MODULE_API7, "UserAuthCallback failed, IUserAuthAPI7Callback is nullptr"); + return; + } + contextID = UserAuth::UserAuth::GetInstance().Auth(CHALLENGE_INIT, exeAuthType, authTurstLevel, asyncStub); + if (contextID != CONTEXTID_INIT) { + UserAuthAPI7Datamgr::GetInstance().API7AddContextID(contextID); + } + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 execute is end"); +} + +int32_t UserAuthAPI7::Cancel() +{ + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 cancel is start"); + uint64_t contextID = 0; + int32_t ret = API7UserAuth::GENERAL_ERROR; + + UserAuthAPI7Datamgr::GetInstance().API7GetContextID(contextID); + if (contextID != CONTEXTID_INIT) { + ret = UserAuth::UserAuth::GetInstance().CancelAuth(contextID); + if (ret != API7UserAuth::SUCCESS) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 cancel is error"); + } + UserAuthAPI7Datamgr::GetInstance().API7DeleteContextID(); + } + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 cancel is end"); + return ret; +} + +int32_t UserAuthAPI7::CheckAvailability(std::string authtype, std::string trustLevel) +{ + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 checkAvailability is start"); + UserAuth::AuthType checkAuthType; + UserAuth::AuthTurstLevel authTurstLevel; + + if (g_convertAuthType.count(authtype) == 0) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 checkAvailability g_convertAuthType is 0"); + return AUTH_TYPE_NOT_SUPPORT; + } else { + checkAuthType = g_convertAuthType[authtype]; + } + + if (g_convertAuthTurstLevel.count(trustLevel) == 0) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 checkAvailability g_convertAuthTurstLevel is 0"); + return SECURE_LEVEL_NOT_SUPPORT; + } else { + authTurstLevel = g_convertAuthTurstLevel[trustLevel]; + } + + int32_t ret = UserAuth::UserAuth::GetInstance().GetAvailableStatus(checkAuthType, authTurstLevel); + if (ret != UserAuth::SUCCESS) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 checkAvailability is error "); + } + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 checkAvailability is end"); + return ret; +} + +void UserAuthAPI7::On(std::string tip, std::shared_ptr tipCallback) +{ + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 On is start"); + std::string tipInfo = "tip"; + + if (!tipInfo.compare(tip)) { + USERAUTH_API7_HILOGE(MODULE_API7, "userauthAPI7 On is not tip"); + UserAuthAPI7Datamgr::GetInstance().SetAPI7Tip(false); + return; + } + UserAuthAPI7Datamgr::GetInstance().SetAPI7Tip(true); + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 On is end"); +} + +void UserAuthAPI7::Off(std::string tip, std::shared_ptr tipCallback) +{ + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 Off is start"); + UserAuthAPI7Datamgr::GetInstance().SetAPI7Tip(false); + USERAUTH_API7_HILOGD(MODULE_API7, "userauthAPI7 Off is end"); +} +} // namespace userAuth +} // namespace UserIam +} // namespace OHOS diff --git a/frameworks/kitsimpl/src/userauth_api7_datamgr.cpp b/frameworks/kitsimpl/src/userauth_api7_datamgr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7a31984a07c4879e12dc2edd39306a015b123fcc --- /dev/null +++ b/frameworks/kitsimpl/src/userauth_api7_datamgr.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#include "userauth_info.h" +#include "userauth_hilog_wrapper.h" +#include "userauth_api7_info.h" +#include "userauth_api7_datamgr.h" + +namespace OHOS { +namespace UserIAM { +namespace API7UserAuth { +UserAuthAPI7Datamgr &UserAuthAPI7Datamgr::GetInstance() +{ + static UserAuthAPI7Datamgr instance; + return instance; +} + +void UserAuthAPI7Datamgr::API7AddContextID(uint64_t contextID) +{ + contextID_ = contextID; +} + +void UserAuthAPI7Datamgr::API7GetContextID(uint64_t &contextID) +{ + contextID = contextID_; +} + +void UserAuthAPI7Datamgr::API7DeleteContextID() +{ + contextID_= CONTEXTID_INIT; +} + +void UserAuthAPI7Datamgr::SetAPI7Tip(bool isTipOn) +{ + isTipOn_ = isTipOn; +} +bool UserAuthAPI7Datamgr::GetAPI7Tip() +{ + return isTipOn_; +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS diff --git a/frameworks/kitsimpl/src/userauth_async_stub.cpp b/frameworks/kitsimpl/src/userauth_async_stub.cpp index 4a7ee0545c4641fc42c23842ee12bfdf81d58c87..65ba5af589672a659b16f2fc9d467fc3c421d9e6 100644 --- a/frameworks/kitsimpl/src/userauth_async_stub.cpp +++ b/frameworks/kitsimpl/src/userauth_async_stub.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include "userauth_hilog_wrapper.h" @@ -201,7 +202,7 @@ void UserAuthAsyncStub::onAcquireInfo(const int32_t module, const uint32_t acqui if (authCallback_ == nullptr) { USERAUTH_HILOGE(MODULE_INNERKIT, "userauthAsyncStub onAcquireInfo callback is Null"); - return ; + return; } USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub module:%{public}d, acquireInfo:%{public}u", @@ -234,8 +235,8 @@ void UserAuthAsyncStub::onExecutorPropertyInfo(const ExecutorProperty result) } USERAUTH_HILOGD(MODULE_INNERKIT, - "userauthAsyncStub result:%{public}d, sub:%{public}llu, remain:%{public}u, freeze:%{public}u", - result.result, result.authSubType, result.remainTimes, result.freezingTime); + "userauthAsyncStub result:%{public}d, sub:%{public}" PRIu64 ", remain:%{public}u, freeze:%{public}u", + result.result, result.authSubType, result.remainTimes, result.freezingTime); getPropCallback_->onGetProperty(result); } diff --git a/frameworks/kitsimpl/src/userauth_proxy.cpp b/frameworks/kitsimpl/src/userauth_proxy.cpp index 65c9093aca2e7059913c7f16b0316ef22f993ef5..92b2cbd2da779cbf840f6ff0c49073a0c4219be1 100644 --- a/frameworks/kitsimpl/src/userauth_proxy.cpp +++ b/frameworks/kitsimpl/src/userauth_proxy.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include #include "userauth_hilog_wrapper.h" @@ -44,7 +45,7 @@ int32_t UserAuthProxy::GetAvailableStatus(const AuthType authType, const AuthTur } bool ret = SendRequest(static_cast(IUserAuth::USER_AUTH_GET_AVAILABLE_STATUS), data, reply, option); if (!ret) { - USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret); + USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret); return IPC_ERROR; } if (!reply.ReadInt32(result)) { @@ -63,7 +64,7 @@ void UserAuthProxy::GetProperty(const GetPropertyRequest request, sptr(request.authType))) { USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(request.authType))."); @@ -82,8 +83,8 @@ void UserAuthProxy::GetProperty(const GetPropertyRequest request, sptronExecutorPropertyInfo(result); - USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret); - return ; + USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret); + return; } } void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptr& callback) @@ -95,7 +96,7 @@ void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptr(request.authType))) { USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(request.authType))."); @@ -117,8 +118,8 @@ void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptronSetExecutorProperty(result); - USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret); - return ; + USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret); + return; } } @@ -129,13 +130,13 @@ uint64_t UserAuthProxy::Auth(const uint64_t challenge, const AuthType authType, u_int64_t result = SUCCESS; MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { USERAUTH_HILOGE(MODULE_INNERKIT, "userauth write descriptor failed!"); return result; } - USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthProxy::Auth challenge = %{public}llu", challenge); + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthProxy::Auth challenge = %{public}" PRIu64 "", challenge); if (!data.WriteUint64(challenge)) { USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(challenge)."); return E_READ_PARCEL_ERROR; @@ -154,7 +155,7 @@ uint64_t UserAuthProxy::Auth(const uint64_t challenge, const AuthType authType, } bool ret = SendRequest(IUserAuth::USER_AUTH_AUTH, data, reply, option); if (!ret) { - USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret); + USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret); return result; } if (!reply.ReadUint64(result)) { @@ -172,7 +173,7 @@ uint64_t UserAuthProxy::AuthUser(const int32_t userId, const uint64_t challenge, u_int64_t result = SUCCESS; MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { USERAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); @@ -200,7 +201,7 @@ uint64_t UserAuthProxy::AuthUser(const int32_t userId, const uint64_t challenge, } bool ret = SendRequest(IUserAuth::USER_AUTH_AUTH_USER, data, reply, option); if (!ret) { - USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); + USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret); return result; } if (!reply.ReadUint64(result)) { @@ -229,7 +230,7 @@ int32_t UserAuthProxy::CancelAuth(const uint64_t contextId) } bool ret = SendRequest(IUserAuth::USER_AUTH_CANCEL_AUTH, data, reply, option); if (!ret) { - USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); + USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret); return IPC_ERROR; } if (!reply.ReadInt32(result)) { @@ -254,7 +255,7 @@ int32_t UserAuthProxy::GetVersion() bool ret = SendRequest(IUserAuth::USER_AUTH_GET_VERSION, data, reply, option); if (!ret) { - USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); + USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret); return IPC_ERROR; } if (!reply.ReadInt32(result)) { diff --git a/interfaces/innerkits/js/ohos.UserIAM.userAuth_API7.d.ts b/interfaces/innerkits/js/ohos.UserIAM.userAuth_API7.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..5eca79f7b3ad0ddaed8745c2c8e4795eb85974a1 --- /dev/null +++ b/interfaces/innerkits/js/ohos.UserIAM.userAuth_API7.d.ts @@ -0,0 +1,336 @@ +/* + * 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. + */ + +import{AsyncCallback} from './basic'; + +/** + * User authentication + * @since 8 + * @sysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @devices phone, tablet + * @permission ohos.permission.ACCESS_BIOMETRIC + */ +declare namespace userIAM +{ + class Authenticator + { + /** + * Execute authentication. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @param type Indicates the authentication type. + * @param level Indicates the security level. + * @return Returns authentication result, which is specified by AuthenticationResult. + */ + execute(type: string, level: string, callback: AsyncCallback): void; + execute(type:string, level:string): Promise; + + /** + * Cancels the current authentication. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @return Returns a cancel result, which is specified by Result. + */ + cancel(): number; + + /** + * Checks whether the device supports the specified authentication type and security level. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @param type Indicates the authentication type. + * @param level Indicates the security level. + * @return Returns a check result, which is specified by CheckAvailabilityResult. + */ + checkAvailability(type: AuthType, level: SecureLevel): number + + /** + * Registers an event callback. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @param type Indicates the event type. + * @param callback Indicates the authentication tip callback to register. + */ + on(type: "tip", callback: Callback) : void; + + /** + * Unregisters an event callback. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @param type Indicates the event type. + * @param callback Indicates the authentication tip callback to unregister. + */ + off(type: "tip", callback?: Callback) : void; + } + + /** + * Get Authenticator instance. + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @return Returns an Authenticator. + */ + function getAuthenticator(): Authenticator; + + /** + * Auth types + */ + type AuthType = "ALL" | "FACE_ONLY"; + + /** + * Secure levels + */ + type SecureLevel = "S1" | "S2" | "S3" | "S4"; + + interface Tip { + /** + * Indicates whether authentication tip is obtained, defined in Result. + * @since 8 + */ + errorCode: number; + + /** + * Indicates an authentication tip event, defined in TipEvent. + * @since 8 + */ + tipEvent: number; + + /** + * Indicates the return code of an authentication tip, defined in TipCode. + * @since 8 + */ + tipCode: number; + + /** + * Indicates the description of an authentication tip code. + * @since 8 + */ + tipInfo: string; + } + + export enum AuthenticationResult { + /** + * Indicates that the device does not support authentication. + */ + NO_SUPPORT = -1, + + /** + * Indicates that authentication is success. + */ + SUCCESS = 0, + + /** + * Indicates the authenticator fails to identify user. + */ + COMPARE_FAILURE = 1, + + /** + * Indicates that authentication has been canceled. + */ + CANCELED = 2, + + /** + * Indicates that authentication has timed out. + */ + TIMEOUT = 3, + + /** + * Indicates a failure to open the camera. + */ + CAMERA_FAIL = 4, + + /** + * Indicates that the authentication task is busy. Wait for a few seconds and try again. + */ + BUSY = 5, + + /** + * Indicates incorrect parameters. + */ + INVALID_PARAMETERS = 6, + + /** + * Indicates that the authenticator is locked. + */ + LOCKED = 7, + + /** + * Indicates that the user has not enrolled the authenticator. + */ + NOT_ENROLLED = 8, + + /** + * Indicates other errors. + */ + GENERAL_ERROR = 100, + } + + export enum Result { + /** + * Indicates that execute is success. + * @since 8 + */ + SUCCESS = 0, + + /** + * Indicates that execute is failed. + * @since 8 + */ + FAILED = 1, + } + + export enum CheckAvailabilityResult { + /** + * Indicates that the device supports the specified authentication type and security level. + * @since 8 + */ + SUPPORTED = 0, + + /** + * Indicates that the device does not support the specified authentication type. + * @since 8 + */ + AUTH_TYPE_NOT_SUPPORT = 1, + + /** + * Indicates that the device does not support the specified authentication security level. + * @since 8 + */ + SECURE_LEVEL_NOT_SUPPORT = 2, + + /** + * Indicates that the device does not support distributed authentication. + * @since 8 + */ + DISTRIBUTED_AUTH_NOT_SUPPORT = 3, + + /** + * Indicates that the device does not have the authentication credential. + * @since 8 + */ + NOT_ENROLLED = 4, + + /** + * Indicates that the number of parameters is incorrect. + * @since 8 + */ + PARAM_NUM_ERROR = 5, + } + + export enum TipEvent { + /** + * Enroll or authenticate result. + * @since 8 + */ + RESULT = 1, + + /** + * Cancel result. + * @since 8 + */ + CANCEL = 2, + + /** + * Prompt for user enroll and authentication. + * @since 8 + */ + ACQUIRE = 3, + + /** + * Busy. + * @since 8 + */ + BUSY = 4, + + /** + * Out of memory. + * @since 8 + */ + OUT_OF_MEM = 5, + + /** + * Index of a face authentication credential. + * @since 8 + */ + FACE_ID = 6, + } + + export enum TipCode { + /** + * Indicates that the obtained facial image is too bright due to high illumination. + * @since 8 + */ + FACE_AUTH_TIP_TOO_BRIGHT = 1, + + /** + * Indicates that the obtained facial image is too dark due to low illumination. + * @since 8 + */ + FACE_AUTH_TIP_TOO_DARK = 2, + + /** + * Indicates that the face is too close to the device. + * @since 8 + */ + FACE_AUTH_TIP_TOO_CLOSE = 3, + + /** + * Indicates that the face is too far away from the device. + * @since 8 + */ + FACE_AUTH_TIP_TOO_FAR = 4, + + /** + * Indicates that the device is too high, and that only the upper part of the face is captured. + * @since 8 + */ + FACE_AUTH_TIP_TOO_HIGH = 5, + + /** + * Indicates that the device is too low, and that only the lower part of the face is captured. + * @since 8 + */ + FACE_AUTH_TIP_TOO_LOW = 6, + + /** + * Indicates that the device is deviated to the right, and that only the right part of the face is captured. + * @since 8 + */ + FACE_AUTH_TIP_TOO_RIGHT = 7, + + /** + * Indicates that the device is deviated to the left, and that only the left part of the face is captured. + * @since 8 + */ + FACE_AUTH_TIP_TOO_LEFT = 8, + + /** + * Indicates that the face moves too fast during facial information collection. + * @since 8 + */ + FACE_AUTH_TIP_TOO_MUCH_MOTION = 9, + + /** + * Indicates that the face is not facing the device. + * @since 8 + */ + FACE_AUTH_TIP_POOR_GAZE = 10, + + /** + * Indicates that no face is detected. + * @since 8 + */ + FACE_AUTH_TIP_NOT_DETECTED = 11, + } +} + +export default userIAM; \ No newline at end of file diff --git a/interfaces/innerkits/native/BUILD.gn b/interfaces/innerkits/native/BUILD.gn index e07ff2c54359d07e3119e446b0f339ce76e02bef..c85df30676dae30d7797a365e5c345ab0de22d72 100755 --- a/interfaces/innerkits/native/BUILD.gn +++ b/interfaces/innerkits/native/BUILD.gn @@ -26,7 +26,10 @@ config("userauth_public_config") { ohos_shared_library("userauth_framework") { sources = [ + "../../../frameworks/kitsimpl/src/iuserauth_api7_callback.cpp", "../../../frameworks/kitsimpl/src/userauth.cpp", + "../../../frameworks/kitsimpl/src/userauth_api7.cpp", + "../../../frameworks/kitsimpl/src/userauth_api7_datamgr.cpp", "../../../frameworks/kitsimpl/src/userauth_async_stub.cpp", "../../../frameworks/kitsimpl/src/userauth_proxy.cpp", ] diff --git a/interfaces/innerkits/native/include/iuserauth_api7_callback.h b/interfaces/innerkits/native/include/iuserauth_api7_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..2c5f1c4b4aedb0d535b7c974a7e4446bb1d3a504 --- /dev/null +++ b/interfaces/innerkits/native/include/iuserauth_api7_callback.h @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#ifndef IUSERAUTH_API7_CALLBACK_H +#define IUSERAUTH_API7_CALLBACK_H + +#include +#include "userauth_info.h" +#include "userauth_callback.h" +#include "userauth_api7_callback.h" + + +namespace OHOS { +namespace UserIAM { +namespace API7UserAuth { +class IUserAuthAPI7Callback : public UserAuth::UserAuthCallback { +public: + explicit IUserAuthAPI7Callback(std::shared_ptr& impl); + virtual ~IUserAuthAPI7Callback() = default; + + void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override; + void onResult(const int32_t result, const UserAuth::AuthResult extraInfo) override; +private: + std::shared_ptr callback_ {nullptr}; +}; +} // namespace API7UserAuth +} // namespace UserIAM +} // namespace OHOS +#endif // IUSERAUTH_API7_CALLBACK_H \ No newline at end of file diff --git a/interfaces/innerkits/native/include/userauth_api7.h b/interfaces/innerkits/native/include/userauth_api7.h new file mode 100644 index 0000000000000000000000000000000000000000..070fce2e869c2fa0992a1a48867f7b5c1ec23e4b --- /dev/null +++ b/interfaces/innerkits/native/include/userauth_api7.h @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#ifndef USERAUTH_API7_H +#define USERAUTH_API7_H + +#include + +#include "userauth_api7_info.h" +#include "userauth_api7_callback.h" + +namespace OHOS { +namespace UserIAM { +namespace API7UserAuth { +class UserAuthAPI7 { +public: + UserAuthAPI7() = default; + ~UserAuthAPI7() = default; + static UserAuthAPI7 &GetAuthenticator(); + void Execute(std::string authtype, std::string trustLevel, std::shared_ptr callback); + int32_t Cancel(); + int32_t CheckAvailability(std::string authtype, std::string trustLevel); + void On(std::string tip, std::shared_ptr tipCallback); + void Off(std::string tip, std::shared_ptr tipCallback); +}; +} // namespace API7UserAuth +} // namespace UserIAM +} // namespace OHOS +#endif // USERAUTH_API7_H \ No newline at end of file diff --git a/interfaces/innerkits/native/include/userauth_api7_callback.h b/interfaces/innerkits/native/include/userauth_api7_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..c9d3dcb7abbed938356a384083fc255a45e02b6f --- /dev/null +++ b/interfaces/innerkits/native/include/userauth_api7_callback.h @@ -0,0 +1,32 @@ +/* + * 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. + */ + +#ifndef USERAUTH_API7_CALLBACK_H +#define USERAUTH_API7_CALLBACK_H + +#include "userauth_api7_info.h" + +namespace OHOS { +namespace UserIAM { +namespace API7UserAuth { +class UserAuthAPI7Callback { +public: + virtual void API7OnResult(const int32_t result) = 0; + virtual void TipCallback(const Tip result) = 0; +}; +} // namespace API7UserAuth +} // namespace UserIAM +} // namespace OHOS +#endif // USERAUTH_API7_CALLBACK_H \ No newline at end of file diff --git a/interfaces/innerkits/native/include/userauth_api7_datamgr.h b/interfaces/innerkits/native/include/userauth_api7_datamgr.h new file mode 100644 index 0000000000000000000000000000000000000000..40d52c116665e7ae54607221f8831d4649e73ce8 --- /dev/null +++ b/interfaces/innerkits/native/include/userauth_api7_datamgr.h @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#ifndef USERAUTH_API7_DATAMGR_H +#define USERAUTH_API7_DATAMGR_H + +#include "userauth_api7_info.h" + +namespace OHOS { +namespace UserIAM { +namespace API7UserAuth { +class UserAuthAPI7Datamgr { +public: + static UserAuthAPI7Datamgr &GetInstance(); + void API7AddContextID(uint64_t contextID); + void API7GetContextID(uint64_t &contextID); + void API7DeleteContextID(); + void SetAPI7Tip(bool isTipOn); + bool GetAPI7Tip(); +private: + UserAuthAPI7Datamgr() = default; + ~UserAuthAPI7Datamgr() = default; + uint64_t contextID_ = CONTEXTID_INIT; + bool isTipOn_ = false; +}; +} // namespace API7UserAuth +} // namespace UserIAM +} // namespace OHOS +#endif // USERAUTH_API7_DATAMGR_H \ No newline at end of file diff --git a/interfaces/innerkits/native/include/userauth_api7_hilog_wrapper.h b/interfaces/innerkits/native/include/userauth_api7_hilog_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..517032c9682bb4a4b1d390fb5eeb2bb82df91be7 --- /dev/null +++ b/interfaces/innerkits/native/include/userauth_api7_hilog_wrapper.h @@ -0,0 +1,72 @@ +/* + * 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. + */ + +#ifndef USERAUTH_API7_HILOG_WRAPPER_H +#define USERAUTH_API7_HILOG_WRAPPER_H + +#define CONFIG_HILOG +#ifdef CONFIG_HILOG + +#include "hilog/log.h" + +namespace OHOS { +namespace UserIAM { +namespace API7UserAuth { +#define filename__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) +#define formated__(fmt, ...) "[%{public}s] %{public}s# " fmt, filename__, __FUNCTION__, ##__VA_ARGS__ + + +#ifdef USERAUTH_API7_HILOGE +#undef USERAUTH_API7_HILOGE +#endif + +#ifdef USERAUTH_API7_HILOGD +#undef USERAUTH_API7_HILOGD +#endif + +// param of log interface, such as USERAUTH_API7_HILOGF. +enum UserAuthAPI7SubModule { + MODULE_API7 = 0, + USERAUTHAPI7_MODULE_BUTT, +}; + +// 0xD002900: subsystem:distributeddatamgr module:distributedgallery, 8 bits reserved. +static constexpr unsigned int BASE_USERAUTH_API7_DOMAIN_ID = 0xD002910; + +enum UserAuthAPI7DomainId { + USERAUTH_API7_DOMAIN = BASE_USERAUTH_API7_DOMAIN_ID + MODULE_API7, + USERAUTH_API7_BUTT, +}; + +static constexpr OHOS::HiviewDFX::HiLogLabel L_LABEL[USERAUTHAPI7_MODULE_BUTT] = { + {LOG_CORE, USERAUTH_API7_DOMAIN, "UserAUTH_API7"}, +}; + +// In order to improve performance, do not check the module range. +// Besides, make sure module is less than USERAUTH_API7_MODULE_BUTT. +#define USERAUTH_API7_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(L_LABEL[module], formated__(__VA_ARGS__)) +#define USERAUTH_API7_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(L_LABEL[module], formated__(__VA_ARGS__)) +} // namespace UserAUTH_API7 +} // namespace UserIAM +} // namespace OHOS + +#else + +#define USERAUTH_API7_HILOGE(...) +#define USERAUTH_API7_HILOGD(...) + +#endif // CONFIG_HILOG + +#endif // USERAUTH_API7_HILOG_WRAPPER_H diff --git a/interfaces/innerkits/native/include/userauth_api7_info.h b/interfaces/innerkits/native/include/userauth_api7_info.h new file mode 100644 index 0000000000000000000000000000000000000000..445ce9bdbcd543f7c1df828052aa314ad59d6c4c --- /dev/null +++ b/interfaces/innerkits/native/include/userauth_api7_info.h @@ -0,0 +1,150 @@ +/* + * 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. + */ + +#ifndef USERAUTH_API7_INFO_H +#define USERAUTH_API7_INFO_H + +#include + +#define CONTEXTID_INIT 0 +#define CHALLENGE_INIT 0 + +namespace OHOS { +namespace UserIAM { +namespace API7UserAuth { +// Authentication Result +enum AuthenticationResult { + /** + * The device does not support the current authentication method. + */ + NO_SUPPORT = -1, + /** + * Authentication succeeded. + */ + SUCCESS = 0, + /** + * Alignment failed. + */ + COMPARE_FAILURE = 1, + /** + * User deauthentication. + */ + CANCELED = 2, + /** + * Authentication timed out. + */ + TIMEOUT = 3, + /** + * Failed to turn on camera. + */ + CAMERA_FAIL = 4, + /** + * The authentication service is busy, please try again later. + */ + BUSY = 5, + /** + * Authentication parameters are invalid. + */ + INVALID_PARAMETERS = 6, + /** + * Too many authentication failures, locked. + */ + LOCKED = 7, + /** + * Authentication credentials not entered. + */ + NOT_ENROLLED = 78, + /** + * other errors. + */ + GENERAL_ERROR = 100, +}; +// Device Certification Capability +enum CheckAvailabilityResult { + // The device supports the specified authentication type and authentication security level + SUPPORTED = 0, + // The device does not support the specified authentication type + AUTH_TYPE_NOT_SUPPORT = 1, + // The device does not support the specified authentication security level + SECURE_LEVEL_NOT_SUPPORT = 2, + // The device does not support distributed authentication + DISTRIBUTED_AUTH_NOT_SUPPORT = 3, + // Authentication credentials are not entered in the device + NO_ENROLLED = 4, + // wrong number of parameters + PARAM_NUM_ERROR = 5, +}; +// Prompt events during authentication +enum TipEvent { + // Entry or Certification Results + RESULT = 1, + // Entry or Certification Cancellation + CANCEL = 2, + // Prompt during entry or authentication + ACQUIRE = 3, + // Entry or authentication functions are occupied + ISBUSY = 4, + // Not enough storage + OUT_OF_MEM = 5, + // Face authentication credential index number + FACE_ID = 6, +}; +// Result +enum Result { + // SUCCESSED + SUCCESSED = 0, + // FAILED + FAILED = 1, +}; +// Prompt code during authentication +enum TipCode { + // The light is too strong, the acquired image is too bright + FACE_AUTH_TIP_TOO_BRIGHT = 1, + // The light is too dim, the acquired image is too dark + FACE_AUTH_TIP_TOO_DARK = 2, + // The face is too close to the device + FACE_AUTH_TIP_TOO_CLOSE = 3, + // The face is too far from the device + FACE_AUTH_TIP_TOO_FAR = 4, + // The device is too high, only the face obtained + FACE_AUTH_TIP_TOO_HIGH = 5, + // The device is too low, only the lower part of the face is obtained + FACE_AUTH_TIP_TOO_LOW = 6, + // The device is too far to the right, only the right part of the face is obtained + FACE_AUTH_TIP_TOO_RIGHT = 7, + // The device is too far to the left, only the left part of the face is obtained + FACE_AUTH_TIP_TOO_LEFT = 8, + // During image acquisition, the user's face moves too fast + FACE_AUTH_TIP_TOO_MUCH_MOTION = 9, + // no facing camera + FACE_AUTH_TIP_POOR_GAZE = 10, + // No face information detected + FACE_AUTH_TIP_NOT_DETECTED = 11, +}; +// Prompt information during the authentication process +struct Tip { + // Whether the prompt information was successfully obtained + int32_t errorCode; + // Authentication prompt event + int32_t tipEvent; + // Authentication prompt event + int32_t tipCode; + // Description of the event prompt code of the authentication prompt + std::string tipInfo; +}; +} // namespace API7UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // USERAUTH_API7_INFO_H diff --git a/services/src/userauth_adapter.cpp b/services/src/userauth_adapter.cpp index 5cacdaad2af34adcac05a4422eee4c1502cff02b..02556c14692e8244c54ee041dcfb40e22890a7e9 100644 --- a/services/src/userauth_adapter.cpp +++ b/services/src/userauth_adapter.cpp @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include -#include "userauth_adapter.h" #include "userauth_hilog_wrapper.h" #include "userauth_info.h" #include "auth_attributes.h" @@ -22,10 +22,12 @@ #include "useridm_info.h" #include "userauth_datamgr.h" #include "userauth_excallback_impl.h" +#include "userauth_adapter.h" namespace OHOS { namespace UserIAM { namespace UserAuth { +const int USERAUTH_VERSION = 1235; UserAuthAdapter &UserAuthAdapter::GetInstance() { static UserAuthAdapter instance; @@ -122,9 +124,6 @@ int32_t UserAuthAdapter::SetProPropAuthInfo(OHOS::UserIAM::AuthResPool::AuthAttr setPropCallback->OnResult(ret, extraInfo); return ret; } - if (ret != SUCCESS) { - return ret; - } ret = authAttributes.SetUint64ArrayValue(AUTH_TEMPLATE_ID_LIST, templateIds); if (ret != SUCCESS) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint64ArrayValue AUTH_TEMPLATE_ID_LIST ERROR!"); @@ -212,7 +211,7 @@ int32_t UserAuthAdapter::Cancel(uint64_t sessionId) int32_t UserAuthAdapter::GetVersion() { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetVersion is start!"); - int32_t version = 1235; + int32_t version = USERAUTH_VERSION; return version; } @@ -313,7 +312,7 @@ int32_t UserAuthAdapter::GetEachExecutorProp(GetPropertyRequest &requset, Execut return INVALID_PARAMETERS; } } - USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthAdapter::GetEachExecutorProp %{public}llu:%{public}u:%{public}u", + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthAdapter::GetEachExecutorProp %{public}" PRIu64 ":%{public}u:%{public}u", result.authSubType, result.remainTimes, result.freezingTime); return ret; } @@ -365,21 +364,22 @@ int32_t UserAuthAdapter::SetExecutorProp(uint64_t callerUID, std::string pkgName int32_t UserAuthAdapter::coAuth(CoAuthInfo coAuthInfo, sptr& callback) { - USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth coAuthHandle is start!"); + USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth coAuth is start!"); std::shared_ptr coAuthCallback = std::make_shared(callback, coAuthInfo, false); OHOS::UserIAM::CoAuth::AuthInfo authInfo; int32_t ret = authInfo.SetPkgName(coAuthInfo.pkgName); if (ret != SUCCESS) { - USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth pAuthInfo_ SetPkgName ERROR!"); + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth authInfo SetPkgName ERROR!"); return ret; } ret = authInfo.SetCallerUid(coAuthInfo.callerID); if (ret != SUCCESS) { - USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth pAuthInfo_ SetCallerUid ERROR!"); + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth authInfo SetCallerUid ERROR!"); return ret; } + ret = UserAuthCallbackImplCoAuth::SaveCoauthCallback(coAuthInfo.contextID, coAuthCallback); if (ret != SUCCESS) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SaveCoauthCallback ERROR!"); diff --git a/services/src/userauth_excallback_impl.cpp b/services/src/userauth_excallback_impl.cpp index b5e8cbf4dc12b3c96105be25a3919a3124ac2329..9a8c1edec331fea9e89940b638af6a79ef00cfff 100644 --- a/services/src/userauth_excallback_impl.cpp +++ b/services/src/userauth_excallback_impl.cpp @@ -20,6 +20,7 @@ #include "userauth_async_proxy.h" #include "securec.h" +#include #include #include @@ -32,7 +33,7 @@ UserAuthCallbackImplSetProp::UserAuthCallbackImplSetProp(const sptr lock(mutex_); - USERAUTH_HILOGD(MODULE_SERVICE, "OnFinishHandle scheduleTokensize:%{public}d, resultCode:%{public}d", + USERAUTH_HILOGD(MODULE_SERVICE, "OnFinishHandle scheduleTokensize:%{public}d, resultCode:%{public}u", scheduleToken.size(), resultCode); callbackNowCount_++; if (isResultDoneFlag_) { @@ -258,7 +259,7 @@ int32_t UserAuthCallbackImplCoAuth::DeleteCoauthCallback(uint64_t contextId) if (iter != saveCoauthCallback_.end()) { saveCoauthCallback_.erase(iter); resultCode = SUCCESS; - USERAUTH_HILOGD(MODULE_SERVICE, "contextId XXXX%{public}04llx is deleted", contextId); + USERAUTH_HILOGD(MODULE_SERVICE, "contextId XXXX%{public}04" PRIx64 " is deleted", contextId); } else { resultCode = FAIL; USERAUTH_HILOGE(MODULE_SERVICE, "contextId is not found and do not delete callback"); @@ -272,7 +273,7 @@ UserAuthCallbackImplIDMGetPorp::UserAuthCallbackImplIDMGetPorp(const sptr ATL4 || authTurstLevel < ATL1) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService GetAvailableStatus AuthTurstLevel is NOT SUPPORT!"); return result; @@ -81,8 +83,8 @@ int32_t UserAuthService::GetAvailableStatus(const AuthType authType, const AuthT ret = userauthController_.GetAuthTrustLevel(userID, authType, authTurstLevelFromSys); if (ret == SUCCESS) { - USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthService iAuthTurstLevel_:%{public}d", authTurstLevelFromSys); - USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthService authTurstLevel:%{public}d", authTurstLevel); + USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService iAuthTurstLevel_:%{public}u", authTurstLevelFromSys); + USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService authTurstLevel:%{public}u", authTurstLevel); if (authTurstLevelFromSys < authTurstLevel) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService authTurstLevel is ERROR!"); return result; @@ -144,7 +146,7 @@ void UserAuthService::SetProperty(const SetPropertyRequest request, sptronSetExecutorProperty(ret); - return ; + return; } } diff --git a/test/unittest/include/userauth_test.h b/test/unittest/include/userauth_test.h index eb0908a704951e98e7480ed07e7e0e68c4b2fee1..e020c97aa0d1e5ecf66d18d81e6fe2e0324f7af8 100644 --- a/test/unittest/include/userauth_test.h +++ b/test/unittest/include/userauth_test.h @@ -25,6 +25,11 @@ void UseriamUtTest_003(); void UseriamUtTest_004(); void UseriamUtTest_005(); void UseriamUtTest_006(); +void UseriamUtTest_007(); +void UseriamUtTest_008(); +void UseriamUtTest_009(); +void UseriamUtTest_010(); +void UseriamUtTest_011(); } } } diff --git a/test/unittest/src/userauth_test.cpp b/test/unittest/src/userauth_test.cpp index cfd924135e6271f97f34a6adb34305eb45ba348e..127f97cea1b4ee38af9047db591f5303a168bc57 100644 --- a/test/unittest/src/userauth_test.cpp +++ b/test/unittest/src/userauth_test.cpp @@ -17,6 +17,7 @@ #include #include #include "user_auth.h" +#include "userauth_api7.h" #include "userauth_callback.h" #include "userauth_info.h" #include "userauth_test.h" @@ -93,6 +94,25 @@ void TestSetPropCallback::onSetProperty(const int32_t result) std::cout << "onSetProperty callback" << std::endl; } +class TestUserAuthAPI7Callback : public API7UserAuth::UserAuthAPI7Callback { +public: + TestUserAuthAPI7Callback() = default; + virtual ~TestUserAuthAPI7Callback() = default; + + void API7OnResult(const int32_t result) override; + void TipCallback(const API7UserAuth::Tip result) override; +}; + +void TestUserAuthAPI7Callback::API7OnResult(const int32_t result) +{ + std::cout << "API7OnResult callback" << std::endl; +} + +void TestUserAuthAPI7Callback::TipCallback(const API7UserAuth::Tip result) +{ + std::cout << "TipCallback callback" << std::endl; +} + HWTEST_F(UseriamUtTest, UseriamUtTest_001, TestSize.Level1) { AuthType authType = FACE; @@ -145,6 +165,37 @@ HWTEST_F(UseriamUtTest, UseriamUtTest_006, TestSize.Level1) uint64_t contextId = 123; EXPECT_EQ(0, UserAuth::GetInstance().CancelAuth(contextId)); } + +HWTEST_F(UseriamUtTest, UseriamUtTest_007, TestSize.Level1) +{ + std::shared_ptr callback = + std::make_shared(); + API7UserAuth::UserAuthAPI7::GetAuthenticator().Execute("FACE_ONLY", "S1", callback); +} + +HWTEST_F(UseriamUtTest, UseriamUtTest_008, TestSize.Level1) +{ + EXPECT_EQ(0, API7UserAuth::UserAuthAPI7::GetAuthenticator().Cancel()); +} + +HWTEST_F(UseriamUtTest, UseriamUtTest_009, TestSize.Level1) +{ + EXPECT_EQ(0, API7UserAuth::UserAuthAPI7::GetAuthenticator().CheckAvailability("FACE_ONLY", "S1")); +} + +HWTEST_F(UseriamUtTest, UseriamUtTest_010, TestSize.Level1) +{ + std::shared_ptr callback = + std::make_shared(); + API7UserAuth::UserAuthAPI7::GetAuthenticator().On("tip", callback); +} + +HWTEST_F(UseriamUtTest, UseriamUtTest_011, TestSize.Level1) +{ + std::shared_ptr callback = + std::make_shared(); + API7UserAuth::UserAuthAPI7::GetAuthenticator().Off("tip", callback); +} } } }