!306 新增Hitrace和Hidumper实现

Merge pull request !306 from 王旭/master
This commit is contained in:
openharmony_ci 2022-07-03 13:19:42 +00:00 committed by Gitee
commit 2789690b8f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
38 changed files with 306 additions and 13 deletions

View File

@ -19,6 +19,7 @@ config("userauth_executors_public_config") {
ohos_shared_library("userauth_executors") {
sources = [
"//base/useriam/user_auth_framework/dfx/src/iam_hitrace_helper.cpp",
"src/async_command/async_command_base.cpp",
"src/async_command/auth_command.cpp",
"src/async_command/custom_command.cpp",
@ -43,6 +44,7 @@ ohos_shared_library("userauth_executors") {
"//base/useriam/user_auth_framework/interfaces/inner_api/common/",
"//base/useriam/user_auth_framework/common/utils",
"//base/useriam/user_auth_framework/common/logs",
"//base/useriam/user_auth_framework/dfx/inc",
"//base/useriam/user_auth_framework/services/common_defines/types",
]
@ -57,6 +59,7 @@ ohos_shared_library("userauth_executors") {
"hdf_core:libhdf_ipc_adapter",
"hdf_core:libhdf_utils",
"hdf_core:libhdi",
"hitrace_native:hitrace_meter",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
"samgr_standard:samgr_proxy",

View File

@ -16,6 +16,8 @@
#ifndef AUTH_COMMAND_H
#define AUTH_COMMAND_H
#include "iam_hitrace_helper.h"
#include "async_command_base.h"
namespace OHOS {
@ -35,6 +37,7 @@ protected:
private:
uint32_t transNum_ = 1;
std::shared_ptr<UserIam::UserAuth::Attributes> attributes_;
std::shared_ptr<UserIam::UserAuth::IamHitraceHelper> iamHitraceHelper_;
};
} // namespace UserAuth
} // namespace UserIAM

View File

@ -16,6 +16,8 @@
#ifndef ENROLL_COMMAND_H
#define ENROLL_COMMAND_H
#include "iam_hitrace_helper.h"
#include "async_command_base.h"
namespace OHOS {
@ -35,6 +37,7 @@ protected:
private:
uint32_t transNum_ = 1;
std::shared_ptr<UserIam::UserAuth::Attributes> attributes_;
std::shared_ptr<UserIam::UserAuth::IamHitraceHelper> iamHitraceHelper_;
};
} // namespace UserAuth
} // namespace UserIAM

View File

@ -16,6 +16,8 @@
#ifndef IDENTIFY_COMMAND_H
#define IDENTIFY_COMMAND_H
#include "iam_hitrace_helper.h"
#include "async_command_base.h"
namespace OHOS {
@ -35,6 +37,7 @@ protected:
private:
uint32_t transNum_ = 1;
std::shared_ptr<UserIam::UserAuth::Attributes> attributes_;
std::shared_ptr<UserIam::UserAuth::IamHitraceHelper> iamHitraceHelper_;
};
} // namespace UserAuth
} // namespace UserIAM

View File

@ -29,7 +29,8 @@ namespace UserAuth {
AuthCommand::AuthCommand(std::weak_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<UserIam::UserAuth::Attributes> attributes, sptr<IExecutorMessenger> executorMessenger)
: AsyncCommandBase("AUTH", scheduleId, executor, executorMessenger),
attributes_(attributes)
attributes_(attributes),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("AuthCommand"))
{
}
@ -48,7 +49,7 @@ ResultCode AuthCommand::SendRequest()
uint64_t callerUid = 0;
bool getCallerUidRet = attributes_->GetUint64Value(UserIam::UserAuth::Attributes::ATTR_CALLER_UID, callerUid);
IF_FALSE_LOGE_AND_RETURN_VAL(getCallerUidRet == true, ResultCode::GENERAL_ERROR);
UserIam::UserAuth::IamHitraceHelper traceHelper("hdi Authenticate");
ResultCode ret = hdi->Authenticate(scheduleId_, callerUid, templateIdList, extraInfo, shared_from_this());
IAM_LOGI("%{public}s authenticate result %{public}d", GetDescription(), ret);
return ret;
@ -66,6 +67,7 @@ void AuthCommand::OnResultInner(ResultCode result, const std::vector<uint8_t> &e
bool setAuthResultRet =
authAttributes->SetUint8ArrayValue(UserIam::UserAuth::Attributes::ATTR_RESULT, nonConstExtraInfo);
IF_FALSE_LOGE_AND_RETURN(setAuthResultRet == true);
iamHitraceHelper_ = nullptr;
int32_t ret = MessengerFinish(scheduleId_, ALL_IN_ONE, result, authAttributes);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("%{public}s call finish fail", GetDescription());

View File

@ -30,7 +30,8 @@ namespace UserAuth {
EnrollCommand::EnrollCommand(std::weak_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<UserIam::UserAuth::Attributes> attributes, sptr<IExecutorMessenger> executorMessenger)
: AsyncCommandBase("ENROLL", scheduleId, executor, executorMessenger),
attributes_(attributes)
attributes_(attributes),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("EnrollCommand"))
{
}
@ -45,6 +46,7 @@ ResultCode EnrollCommand::SendRequest()
bool getCallerUidRet = attributes_->GetUint64Value(UserIam::UserAuth::Attributes::ATTR_CALLER_UID, callerUid);
IF_FALSE_LOGE_AND_RETURN_VAL(getCallerUidRet == true, ResultCode::GENERAL_ERROR);
std::vector<uint8_t> extraInfo;
UserIam::UserAuth::IamHitraceHelper traceHelper("hdi Enroll");
ResultCode ret = hdi->Enroll(scheduleId_, callerUid, extraInfo, shared_from_this());
IAM_LOGI("%{public}s enroll result %{public}d", GetDescription(), ret);
return ret;
@ -61,6 +63,7 @@ void EnrollCommand::OnResultInner(ResultCode result, const std::vector<uint8_t>
bool setAuthResultRet =
authAttributes->SetUint8ArrayValue(UserIam::UserAuth::Attributes::ATTR_RESULT, nonConstExtraInfo);
IF_FALSE_LOGE_AND_RETURN(setAuthResultRet == true);
iamHitraceHelper_ = nullptr;
int32_t ret = MessengerFinish(scheduleId_, ALL_IN_ONE, result, authAttributes);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("%{public}s call finish fail", GetDescription());

View File

@ -28,7 +28,8 @@ namespace UserAuth {
IdentifyCommand::IdentifyCommand(std::weak_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<UserIam::UserAuth::Attributes> attributes, sptr<IExecutorMessenger> executorMessenger)
: AsyncCommandBase("IDENTIFY", scheduleId, executor, executorMessenger),
attributes_(attributes)
attributes_(attributes),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("IdentifyCommand"))
{
}
@ -43,6 +44,7 @@ ResultCode IdentifyCommand::SendRequest()
std::vector<uint8_t> extraInfo;
bool getCallerUidRet = attributes_->GetUint64Value(UserIam::UserAuth::Attributes::ATTR_CALLER_UID, callerUid);
IF_FALSE_LOGE_AND_RETURN_VAL(getCallerUidRet == true, ResultCode::GENERAL_ERROR);
UserIam::UserAuth::IamHitraceHelper traceHelper("hdi Identify");
ResultCode ret = hdi->Identify(scheduleId_, callerUid, extraInfo, shared_from_this());
IAM_LOGI("%{public}s identify result %{public}d", GetDescription(), ret);
return ret;
@ -60,6 +62,7 @@ void IdentifyCommand::OnResultInner(ResultCode result, const std::vector<uint8_t
bool setAuthResultRet =
authAttributes->SetUint8ArrayValue(UserIam::UserAuth::Attributes::ATTR_RESULT, nonConstExtraInfo);
IF_FALSE_LOGE_AND_RETURN(setAuthResultRet == true);
iamHitraceHelper_ = nullptr;
int32_t ret = MessengerFinish(scheduleId_, ALL_IN_ONE, result, authAttributes);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("%{public}s call finish fail", GetDescription());

View File

@ -27,6 +27,7 @@
#include "iam_para2str.h"
#include "iam_ptr.h"
#include "iam_types.h"
#include "iam_hitrace_helper.h"
#include "identify_command.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
@ -211,7 +212,9 @@ ResultCode FrameworkExecutorCallback::ProcessDeleteTemplateCommand(
bool getAuthTemplateIdRet = properties->GetUint64Value(UserIam::UserAuth::Attributes::ATTR_TEMPLATE_ID, templateId);
IF_FALSE_LOGE_AND_RETURN_VAL(getAuthTemplateIdRet == true, ResultCode::GENERAL_ERROR);
std::vector<uint64_t> templateIdList;
templateIdList.push_back(templateId);
UserIam::UserAuth::IamHitraceHelper traceHelper("hdi Delete");
return hdi->Delete(templateIdList);
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2022 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 IAM_HI_TRACE_HELPER_H
#define IAM_HI_TRACE_HELPER_H
#include <cstdint>
#include <string>
#include "nocopyable.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class IamHitraceHelper final : public NoCopyable {
public:
explicit IamHitraceHelper(std::string value);
~IamHitraceHelper() override;
private:
int32_t GetHiTraceTaskId();
int32_t taskId_;
std::string value_;
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // IAM_HI_TRACE_HELPER_H

View File

@ -16,12 +16,14 @@
#ifndef TRACE_H
#define TRACE_H
#include "nocopyable.h"
#include "context_callback.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class Trace {
class Trace final : public NoCopyable {
private:
static Trace trace;
static void ProcessCredChangeEvent(const ContextCallbackNotifyListener::MetaData &metaData);

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2022 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 "iam_hitrace_helper.h"
#include <atomic>
#include "hitrace_meter.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
IamHitraceHelper::IamHitraceHelper(std::string value)
: taskId_(GetHiTraceTaskId()),
value_(std::move(value))
{
StartAsyncTrace(HITRACE_TAG_OHOS, value_, taskId_);
}
IamHitraceHelper::~IamHitraceHelper()
{
FinishAsyncTrace(HITRACE_TAG_OHOS, value_, taskId_);
}
int32_t IamHitraceHelper::GetHiTraceTaskId()
{
static std::atomic<int32_t> taskId(0);
return taskId++;
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -22,6 +22,7 @@ ohos_shared_library("userauth") {
"inc",
"//base/useriam/user_auth_framework/common/utils",
"//base/useriam/user_auth_framework/common/logs",
"//base/useriam/user_auth_framework/dfx/inc",
]
sources = [
@ -56,6 +57,7 @@ ohos_shared_library("userauth_napi") {
include_dirs = [
"inc",
"//base/useriam/user_auth_framework/common/utils",
"//base/useriam/user_auth_framework/dfx/inc",
]
sources = [

View File

@ -27,9 +27,11 @@ ohos_shared_library("userauth_framework") {
"inc",
"//base/useriam/user_auth_framework/common/utils",
"//base/useriam/user_auth_framework/common/logs",
"//base/useriam/user_auth_framework/dfx/inc",
]
sources = [
"//base/useriam/user_auth_framework/dfx/src/iam_hitrace_helper.cpp",
"src/user_auth.cpp",
"src/user_auth_native.cpp",
"src/userauth_async_stub.cpp",
@ -41,6 +43,7 @@ ohos_shared_library("userauth_framework") {
]
external_deps = [
"hitrace_native:hitrace_meter",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr_standard:samgr_proxy",

View File

@ -18,6 +18,9 @@
#include <iremote_stub.h>
#include <nocopyable.h>
#include "iam_hitrace_helper.h"
#include "iuserauth_callback.h"
#include "userauth_callback.h"
@ -50,6 +53,7 @@ private:
std::shared_ptr<UserIdentifyCallback> identifyCallback_ {nullptr};
std::shared_ptr<SetPropCallback> setPropCallback_ {nullptr};
std::shared_ptr<GetPropCallback> getPropCallback_ {nullptr};
std::shared_ptr<UserIam::UserAuth::IamHitraceHelper> iamHitraceHelper_;
};
} // namespace UserAuth
} // namespace UserIAM

View File

@ -19,6 +19,7 @@
#include <message_parcel.h>
#include "iam_logger.h"
#include "iam_ptr.h"
#include "iuser_auth.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_SDK
@ -26,11 +27,15 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr<UserAuthCallback> &impl) : authCallback_(impl)
UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr<UserAuthCallback> &impl)
: authCallback_(impl),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("UserAuth InnerKit"))
{
}
UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr<UserIdentifyCallback> &impl) : identifyCallback_(impl)
UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr<UserIdentifyCallback> &impl)
: identifyCallback_(impl),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("UserAuth InnerKit"))
{
}
@ -249,6 +254,8 @@ void UserAuthAsyncStub::onAuthResult(const int32_t result, const AuthResult &ext
return;
}
iamHitraceHelper_= nullptr;
IAM_LOGD("userauthAsyncStub result:%{public}d, remain:%{public}u, freeze:%{public}u",
result, extraInfo.remainTimes, extraInfo.freezingTime);
authCallback_->onResult(result, extraInfo);
@ -263,6 +270,8 @@ void UserAuthAsyncStub::onIdentifyResult(const int32_t result, const IdentifyRes
return;
}
iamHitraceHelper_= nullptr;
IAM_LOGD("UserAuthAsyncStub identify result:%{public}d, user id:%{public}d",
result, extraInfo.userId);
identifyCallback_->onResult(result, extraInfo);

View File

@ -30,9 +30,11 @@ ohos_shared_library("useridm_framework") {
"//base/useriam/user_auth_framework/interfaces/inner_api/user_idm",
"//base/useriam/user_auth_framework/common/utils",
"//base/useriam/user_auth_framework/common/logs",
"//base/useriam/user_auth_framework/dfx/inc",
]
sources = [
"//base/useriam/user_auth_framework/dfx/src/iam_hitrace_helper.cpp",
"src/user_idm.cpp",
"src/useridm_callback_stub.cpp",
"src/useridm_client.cpp",
@ -44,6 +46,7 @@ ohos_shared_library("useridm_framework") {
public_configs = [ ":useridm_public_config" ]
external_deps = [
"hitrace_native:hitrace_meter",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr_standard:samgr_proxy",

View File

@ -17,6 +17,9 @@
#define USERIDM_CALLBACK_STUB_H
#include <iremote_stub.h>
#include "iam_hitrace_helper.h"
#include "iuseridm_callback.h"
#include "useridm_info.h"
#include "useridm_callback.h"
@ -29,10 +32,8 @@ namespace UserAuthDomain = OHOS::UserIAM::UserAuth;
class UserIDMCallbackStub : public IRemoteStub<IIDMCallback> {
public:
explicit UserIDMCallbackStub(const std::shared_ptr<IDMCallback> &impl)
:callback_(impl), idmCallback_(nullptr) {}
explicit UserIDMCallbackStub(const std::shared_ptr<UserAuthDomain::IdmCallback> &impl)
:callback_(nullptr), idmCallback_(impl) {}
explicit UserIDMCallbackStub(const std::shared_ptr<IDMCallback> &impl);
explicit UserIDMCallbackStub(const std::shared_ptr<UserAuthDomain::IdmCallback> &impl);
~UserIDMCallbackStub() override = default;
void OnResult(int32_t result, RequestResult reqRet) override;
@ -45,6 +46,7 @@ private:
std::shared_ptr<IDMCallback> callback_;
std::shared_ptr<UserAuthDomain::IdmCallback> idmCallback_;
std::shared_ptr<UserIam::UserAuth::IamHitraceHelper> iamHitraceHelper_;
};
} // namespace UserIDM
} // namespace UserIAM

View File

@ -18,6 +18,7 @@
#include <message_parcel.h>
#include "iam_logger.h"
#include "iam_ptr.h"
#define LOG_LABEL Common::LABEL_USER_IDM_SDK
@ -26,6 +27,20 @@ namespace UserIAM {
namespace UserIDM {
namespace UserAuthDomain = OHOS::UserIAM::UserAuth;
UserIDMCallbackStub::UserIDMCallbackStub(const std::shared_ptr<IDMCallback> &impl)
: callback_(impl),
idmCallback_(nullptr),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("IDM InnerKit"))
{
}
UserIDMCallbackStub::UserIDMCallbackStub(const std::shared_ptr<UserAuthDomain::IdmCallback> &impl)
: callback_(nullptr),
idmCallback_(impl),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("IDM InnerKit"))
{
}
int32_t UserIDMCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
@ -76,6 +91,7 @@ int32_t UserIDMCallbackStub::OnAcquireInfoStub(MessageParcel& data, MessageParce
void UserIDMCallbackStub::OnResult(int32_t result, RequestResult reqRet)
{
IAM_LOGD("UserIDMCallbackStub OnResult start");
iamHitraceHelper_ = nullptr;
if (callback_ != nullptr) {
callback_->OnResult(result, reqRet);
return;

View File

@ -36,6 +36,7 @@ ohos_shared_library("userauthservice") {
remove_configs = [ "//build/config/compiler:no_exceptions" ]
sources = [
"//base/useriam/user_auth_framework/dfx/src/iam_hitrace_helper.cpp",
"//base/useriam/user_auth_framework/dfx/src/trace.cpp",
"base/src/finite_state_machine_builder.cpp",
"base/src/finite_state_machine_impl.cpp",
@ -87,6 +88,7 @@ ohos_shared_library("userauthservice") {
"access_token:libaccesstoken_sdk",
"drivers_interface_user_auth:libuser_auth_proxy_1.0",
"hilog_native:libhilog",
"hitrace_native:hitrace_meter",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",

View File

@ -28,6 +28,22 @@ enum AuthType : uint32_t {
FINGERPRINT = 4,
};
inline const char *AuthTypeToStr(AuthType authType)
{
switch (authType) {
case ALL:
return "All";
case PIN:
return "Pin";
case FACE:
return "Face";
case FINGERPRINT:
return "Fingerprint";
default:
return "";
}
}
enum PinSubType : uint64_t {
PIN_SIX = 10000,
PIN_NUMBER = 10001,

View File

@ -14,6 +14,8 @@
*/
#include "context_callback_impl.h"
#include <sstream>
#include "iam_check.h"
#include "iam_logger.h"
#include "iam_ptr.h"
@ -27,6 +29,9 @@ ContextCallbackImpl::ContextCallbackImpl(sptr<IdmCallback> idmCallback, Operatio
{
metaData_.operationType = operationType;
metaData_.startTime = std::chrono::steady_clock::now();
std::ostringstream ss;
ss << "IDM(operation:" << operationType << ")";
iamHitraceHelper_ = UserIAM::Common::MakeShared<IamHitraceHelper>(ss.str());
}
ContextCallbackImpl::ContextCallbackImpl(sptr<UserAuthCallback> userAuthCallback, OperationType operationType)
@ -34,6 +39,9 @@ ContextCallbackImpl::ContextCallbackImpl(sptr<UserAuthCallback> userAuthCallback
{
metaData_.operationType = operationType;
metaData_.startTime = std::chrono::steady_clock::now();
std::ostringstream ss;
ss << "UserAuth(operation:" << operationType << ")";
iamHitraceHelper_ = UserIAM::Common::MakeShared<IamHitraceHelper>(ss.str());
}
void ContextCallbackImpl::onAcquireInfo(ExecutorRole src, int32_t moduleType,
@ -71,6 +79,7 @@ void ContextCallbackImpl::OnResult(int32_t resultCode, Attributes &finalResult)
}
metaData_.endTime = std::chrono::steady_clock::now();
iamHitraceHelper_ = nullptr;
if (idmCallback_ != nullptr) {
idmCallback_->OnResult(resultCode, finalResult);
}

View File

@ -16,6 +16,8 @@
#ifndef CONTEXT_CALLBACK_IMPL_H
#define CONTEXT_CALLBACK_IMPL_H
#include "iam_hitrace_helper.h"
#include "context_callback.h"
namespace OHOS {
@ -42,6 +44,7 @@ private:
sptr<UserAuthCallback> userAuthCallback_;
Context::ContextStopCallback stopCallback_ {nullptr};
ContextCallbackNotifyListener::MetaData metaData_;
std::shared_ptr<IamHitraceHelper> iamHitraceHelper_;
};
} // namespace UserAuth
} // namespace UserIam

View File

@ -41,6 +41,7 @@ public:
virtual void DeleteAll() = 0;
virtual std::weak_ptr<ResourceNode> Select(uint64_t executorIndex) const = 0;
virtual uint32_t GetPoolSize() const = 0;
virtual void Enumerate(std::function<void(const std::weak_ptr<ResourceNode> &)> action) const = 0;
virtual bool RegisterResourceNodePoolListener(const std::shared_ptr<ResourceNodePoolListener> &listener) = 0;
virtual bool DeregisterResourceNodePoolListener(const std::shared_ptr<ResourceNodePoolListener> &listener) = 0;
};

View File

@ -16,6 +16,7 @@
#include "hdi_wrapper.h"
#include "iam_logger.h"
#include "iam_hitrace_helper.h"
#include "schedule_node_helper.h"
#define LOG_LABEL UserIAM::Common::LABEL_USER_AUTH_SA
@ -69,6 +70,7 @@ bool AuthenticationImpl::Start(std::vector<std::shared_ptr<ScheduleNode>> &sched
.challenge = challenge_,
};
std::vector<HdiScheduleInfo> infos;
IamHitraceHelper traceHelper("hdi BeginAuthentication");
auto result = hdi->BeginAuthentication(contextId_, solution, infos);
if (result != HDF_SUCCESS) {
IAM_LOGE("hdi BeginAuthentication failed, err is %{public}d", result);

View File

@ -17,6 +17,7 @@
#include "hdi_wrapper.h"
#include "iam_logger.h"
#include "iam_ptr.h"
#include "iam_hitrace_helper.h"
#include "credential_info_impl.h"
#include "schedule_node_helper.h"
@ -73,6 +74,7 @@ bool EnrollmentImpl::Start(std::vector<std::shared_ptr<ScheduleNode>> &scheduleL
.authType = static_cast<HdiAuthType>(authType_),
.executorSensorHint = executorSensorHint_,
};
IamHitraceHelper traceHelper("hdi BeginEnrollment");
auto result = hdi->BeginEnrollment(userId_, authToken_, param, info);
if (result != HDF_SUCCESS) {
IAM_LOGE("hdi BeginEnrollment failed, err is %{public}d", result);

View File

@ -16,6 +16,7 @@
#include "hdi_wrapper.h"
#include "iam_logger.h"
#include "iam_hitrace_helper.h"
#include "schedule_node_helper.h"
#define LOG_LABEL UserIAM::Common::LABEL_USER_AUTH_SA
@ -60,6 +61,7 @@ bool IdentificationImpl::Start(std::vector<std::shared_ptr<ScheduleNode>> &sched
}
HdiScheduleInfo info;
IamHitraceHelper traceHelper("hdi BeginIdentification");
auto result =
hdi->BeginIdentification(contextId_, static_cast<HdiAuthType>(authType_), challenge_, executorIndex_, info);
if (result != HDF_SUCCESS) {

View File

@ -35,6 +35,7 @@ public:
void DeleteAll() override;
std::weak_ptr<ResourceNode> Select(uint64_t executorIndex) const override;
uint32_t GetPoolSize() const override;
void Enumerate(std::function<void(const std::weak_ptr<ResourceNode> &)> action) const override;
bool RegisterResourceNodePoolListener(const std::shared_ptr<ResourceNodePoolListener> &listener) override;
bool DeregisterResourceNodePoolListener(const std::shared_ptr<ResourceNodePoolListener> &listener) override;
@ -118,6 +119,18 @@ std::weak_ptr<ResourceNode> ResourceNodePoolImpl::Select(uint64_t executorIndex)
return result;
}
void ResourceNodePoolImpl::Enumerate(std::function<void(const std::weak_ptr<ResourceNode> &)> action) const
{
if (action == nullptr) {
IAM_LOGE("action is nullptr");
return;
}
std::lock_guard<std::mutex> lock(poolMutex_);
for (auto &node : resourceNodeMap_) {
action(node.second);
}
}
uint32_t ResourceNodePoolImpl::GetPoolSize() const
{
std::lock_guard<std::mutex> lock(poolMutex_);

View File

@ -16,6 +16,7 @@
#include "resource_node_utils.h"
#include "iam_logger.h"
#include "iam_hitrace_helper.h"
#include "resource_node_pool.h"
#define LOG_LABEL UserIAM::Common::LABEL_USER_AUTH_SA
@ -41,7 +42,7 @@ int32_t ResourceNodeUtils::NotifyExecutorToDeleteTemplates(const std::vector<std
Attributes properties;
properties.SetUint32Value(Attributes::ATTR_PROPERTY_MODE, PROPERTY_MODE_DEL);
properties.SetUint64Value(Attributes::ATTR_TEMPLATE_ID, info->GetTemplateId());
IamHitraceHelper traceHelper("NotifyExecutorToDeleteTemplates");
int32_t ret = resourceNode->SetProperty(properties);
if (ret != SUCCESS) {
IAM_LOGE("failed to set property to ****%{public}hx", static_cast<uint16_t>(executorIndex));

View File

@ -118,6 +118,7 @@ ScheduleNode::State ScheduleNodeImpl::GetCurrentScheduleState() const
bool ScheduleNodeImpl::StartSchedule()
{
iamHitraceHelper_ = UserIAM::Common::MakeShared<IamHitraceHelper>(GetDescription());
{
std::lock_guard<std::mutex> lock(mutex_);
if (!TryKickMachine(E_START_AUTH)) {
@ -216,7 +217,9 @@ std::string ScheduleNodeImpl::GetDescription() const
std::stringstream stream;
std::string name;
stream << "schedule:****" << std::hex << static_cast<uint16_t>(GetScheduleId());
auto verifier = info_.verifier.lock();
stream << "schedule type:" << (verifier ? AuthTypeToStr(verifier->GetAuthType()) : "nullptr") <<
" id:******" << std::hex << static_cast<uint16_t>(GetScheduleId());
stream >> name;
return name;
}
@ -367,6 +370,8 @@ void ScheduleNodeImpl::OnScheduleFinished(FiniteStateMachine &machine, uint32_t
return;
}
iamHitraceHelper_ = nullptr;
auto result = result_.value();
info_.callback->OnScheduleStoped(result.first, result.second);
info_.callback = nullptr;

View File

@ -21,6 +21,8 @@
#include <mutex>
#include <optional>
#include "iam_hitrace_helper.h"
#include "finite_state_machine.h"
#include "resource_node.h"
#include "schedule_node.h"
@ -94,6 +96,7 @@ private:
ScheduleInfo info_;
std::shared_ptr<FiniteStateMachine> machine_;
std::mutex mutex_;
std::shared_ptr<IamHitraceHelper> iamHitraceHelper_;
// result
std::optional<std::pair<ResultCode, std::shared_ptr<Attributes>>> result_;
};

View File

@ -23,6 +23,7 @@
#include "enrolled_info_impl.h"
#include "iam_logger.h"
#include "iam_ptr.h"
#include "iam_hitrace_helper.h"
#include "result_code.h"
#include "secure_user_info.h"
#include "secure_user_info_impl.h"
@ -112,6 +113,7 @@ int32_t UserIdmDatabaseImpl::DeleteCredentialInfo(int32_t userId, uint64_t crede
}
HdiCredentialInfo hdiInfo = {};
IamHitraceHelper traceHelper("hdi DeleteCredential");
int32_t ret = hdi->DeleteCredential(userId, credentialId, authToken, hdiInfo);
if (ret != HDF_SUCCESS) {
IAM_LOGE("failed to delete credential, error code : %{public}d", ret);
@ -137,6 +139,7 @@ int32_t UserIdmDatabaseImpl::DeleteUser(int32_t userId, const std::vector<uint8_
}
std::vector<HdiCredentialInfo> hdiInfos;
IamHitraceHelper traceHelper("hdi DeleteUser");
int32_t ret = hdi->DeleteUser(userId, authToken, hdiInfos);
if (ret != HDF_SUCCESS) {
IAM_LOGE("failed to delete user, error code : %{public}d", ret);
@ -164,6 +167,7 @@ int32_t UserIdmDatabaseImpl::DeleteUserEnforce(int32_t userId, std::vector<std::
}
std::vector<HdiCredentialInfo> hdiInfos;
IamHitraceHelper traceHelper("hdi EnforceDeleteUser");
int32_t ret = hdi->EnforceDeleteUser(userId, hdiInfos);
if (ret != HDF_SUCCESS) {
IAM_LOGE("failed to enforce delete user, error code : %{public}d", ret);

View File

@ -32,6 +32,7 @@ public:
~CoAuthService() override = default;
void OnStart() override;
void OnStop() override;
int Dump(int fd, const std::vector<std::u16string> &args) override;
uint64_t ExecutorRegister(const ExecutorRegisterInfo &info, sptr<ExecutorCallback> &callback) override;
private:

View File

@ -37,6 +37,7 @@ public:
~UserIdmService() override = default;
void OnStart() override;
void OnStop() override;
int Dump(int fd, const std::vector<std::u16string> &args) override;
int32_t OpenSession(std::optional<int32_t> userId, std::vector<uint8_t> &challenge) override;
void CloseSession(std::optional<int32_t> userId) override;
int32_t GetCredentialInfo(std::optional<int32_t> userId, AuthType authType,

View File

@ -18,6 +18,8 @@
#include <cinttypes>
#include <thread>
#include "string_ex.h"
#include "executor_messenger_service.h"
#include "hdi_wrapper.h"
#include "iam_logger.h"
@ -104,6 +106,36 @@ void CoAuthService::Init()
RelativeTimer::GetInstance().Register(Init, DEFER_TIME);
}
}
int CoAuthService::Dump(int fd, const std::vector<std::u16string> &args)
{
IAM_LOGI("start");
if (fd < 0) {
IAM_LOGE("invalid parameters");
dprintf(fd, "Invalid parameters.\n");
return INVALID_PARAMETERS;
}
std::string arg0 = (args.empty() ? "" : Str16ToStr8(args[0]));
if (arg0.empty() || arg0.compare("-h") == 0) {
dprintf(fd, "Usage:\n");
dprintf(fd, " -h: command help.\n");
dprintf(fd, " -l: resource pool dump.\n");
return SUCCESS;
}
if (arg0.compare("-l") == 0) {
ResourceNodePool::Instance().Enumerate([fd](const std::weak_ptr<ResourceNode> &node) {
auto nodeTmp = node.lock();
if (nodeTmp != nullptr) {
dprintf(fd, "ExecutorIndex is: %" PRIx64 ".\n", nodeTmp->GetExecutorIndex());
dprintf(fd, "ExecutorType is: %s.\n", AuthTypeToStr(nodeTmp->GetAuthType()));
}
});
return SUCCESS;
}
IAM_LOGE("invalid option");
dprintf(fd, "Invalid option\n");
return FAIL;
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -14,6 +14,9 @@
*/
#include "user_idm_service.h"
#include "string_ex.h"
#include "accesstoken_kit.h"
#include "context_factory.h"
@ -441,6 +444,45 @@ void UserIdmService::DelCredential(std::optional<int32_t> userId, uint64_t crede
contextCallback->OnResult(ret, extraInfo);
}
int UserIdmService::Dump(int fd, const std::vector<std::u16string> &args)
{
IAM_LOGI("start");
if (fd < 0) {
IAM_LOGE("invalid parameters");
dprintf(fd, "Invalid parameters.\n");
return INVALID_PARAMETERS;
}
std::string arg0 = (args.empty() ? "" : Str16ToStr8(args[0]));
if (arg0.empty() || arg0.compare("-h") == 0) {
dprintf(fd, "Usage:\n");
dprintf(fd, " -h: command help.\n");
dprintf(fd, " -l: active user info dump.\n");
return SUCCESS;
}
if (arg0.compare("-l") == 0) {
std::optional<int32_t> activeUserId;
if (IpcCommon::GetActiveAccountId(activeUserId) != SUCCESS) {
dprintf(fd, "Internal error.\n");
IAM_LOGE("failed to get active id");
return GENERAL_ERROR;
}
dprintf(fd, "Active user is %d\n", activeUserId.value());
auto userInfo = UserIdmDatabase::Instance().GetSecUserInfo(activeUserId.value());
if (userInfo != nullptr) {
auto enrolledInfo = userInfo->GetEnrolledInfo();
for (auto &info : enrolledInfo) {
if (info != nullptr) {
dprintf(fd, "AuthType %s is enrolled.\n", AuthTypeToStr(info->GetAuthType()));
}
}
}
return SUCCESS;
}
IAM_LOGE("invalid option");
dprintf(fd, "Invalid option\n");
return FAIL;
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -25,6 +25,7 @@ ohos_unittest("iam_executors_test") {
"//base/useriam/user_auth_framework/interfaces/inner_api/common/",
"//base/useriam/user_auth_framework/common/utils",
"//base/useriam/user_auth_framework/common/logs",
"//base/useriam/user_auth_framework/dfx/inc",
"//base/useriam/user_auth_framework/services/common_defines/types",
]

View File

@ -18,6 +18,7 @@ ohos_unittest("iam_inner_api_test") {
include_dirs = [
"inc",
"//base/useriam/user_auth_framework/common/logs",
"//base/useriam/user_auth_framework/dfx/inc",
"//base/useriam/user_auth_framework/frameworks/user_idm/inc",
"//base/useriam/user_auth_framework/interfaces/inner_api/user_idm",
]

View File

@ -18,6 +18,7 @@ ohos_unittest("iam_services_test") {
include_dirs = [
"inc",
"mocks",
"//base/useriam/user_auth_framework/dfx/inc",
"//base/useriam/user_auth_framework/services/base/inc",
"//base/useriam/user_auth_framework/services/core/inc",
"//base/useriam/user_auth_framework/services/core/src",
@ -29,6 +30,8 @@ ohos_unittest("iam_services_test") {
]
sources = [
"//base/useriam/user_auth_framework/dfx/src/iam_hitrace_helper.cpp",
"//base/useriam/user_auth_framework/dfx/src/trace.cpp",
"//base/useriam/user_auth_framework/services/base/src/finite_state_machine_builder.cpp",
"//base/useriam/user_auth_framework/services/base/src/finite_state_machine_impl.cpp",
"//base/useriam/user_auth_framework/services/base/src/relative_timer.cpp",
@ -104,6 +107,7 @@ ohos_unittest("iam_services_test") {
"access_token:libaccesstoken_sdk",
"drivers_interface_user_auth:libuser_auth_proxy_1.0",
"hilog_native:libhilog",
"hitrace_native:hitrace_meter",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",