!217 优化UserAuth Executors代码实现

Merge pull request !217 from Tianshi Liu/update_code
This commit is contained in:
openharmony_ci
2022-06-10 10:02:53 +00:00
committed by Gitee
20 changed files with 276 additions and 222 deletions
@@ -22,16 +22,19 @@
#include "co_auth_defines.h"
#include "executor.h"
#include "iexecutor_messenger.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
using namespace AuthResPool;
class AsyncCommandBase : public std::enable_shared_from_this<AsyncCommandBase>,
public IAsyncCommand,
public IExecuteCallback,
public NoCopyable {
public:
AsyncCommandBase(std::string type, uint64_t scheduleId, std::shared_ptr<Executor> executor);
AsyncCommandBase(std::string type, uint64_t scheduleId, std::weak_ptr<Executor> executor,
sptr<IExecutorMessenger> executorMessenger);
~AsyncCommandBase() override = default;
void OnHdiDisconnect() override;
@@ -44,14 +47,20 @@ protected:
static uint32_t GenerateCommandId();
virtual ResultCode SendRequest() = 0;
virtual void OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo) = 0;
std::shared_ptr<IAuthExecutorHdi> GetExecutorHdi();
int32_t MessengerSendData(
uint64_t scheduleId, uint64_t transNum, int32_t srcType, int32_t dstType, std::shared_ptr<AuthMessage> msg);
int32_t MessengerFinish(
uint64_t scheduleId, int32_t srcType, int32_t resultCode, std::shared_ptr<AuthAttributes> finalResult);
const char *GetDescription();
uint64_t scheduleId_;
std::shared_ptr<Executor> executor_;
uint32_t commandId_;
private:
void EndProcess();
std::string description_;
std::weak_ptr<Executor> executor_;
sptr<IExecutorMessenger> executorMessenger_;
};
} // namespace UserAuth
} // namespace UserIAM
@@ -23,8 +23,8 @@ namespace UserIAM {
namespace UserAuth {
class AuthCommand : public AsyncCommandBase {
public:
AuthCommand(std::shared_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
AuthCommand(std::weak_ptr<Executor> executor, uint64_t scheduleId, std::shared_ptr<AuthAttributes> commandAttrs,
sptr<IExecutorMessenger> executorMessenger);
~AuthCommand() override = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
@@ -35,7 +35,7 @@ protected:
private:
uint32_t transNum_ = 1;
std::shared_ptr<AuthResPool::AuthAttributes> attributes_;
std::shared_ptr<AuthAttributes> attributes_;
};
} // namespace UserAuth
} // namespace UserIAM
@@ -25,7 +25,7 @@ namespace UserIAM {
namespace UserAuth {
class CustomCommand : public AsyncCommandBase {
public:
CustomCommand(std::shared_ptr<Executor> executor, std::shared_ptr<AuthResPool::AuthAttributes> attributes);
CustomCommand(std::weak_ptr<Executor> executor, std::shared_ptr<AuthAttributes> attributes);
~CustomCommand() override = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
@@ -37,7 +37,7 @@ protected:
ResultCode SendRequest() override;
private:
std::shared_ptr<AuthResPool::AuthAttributes> attributes_;
std::shared_ptr<AuthAttributes> attributes_;
ResultCode result_ = ResultCode::GENERAL_ERROR;
std::promise<void> promise_;
std::future<void> future_;
@@ -23,8 +23,8 @@ namespace UserIAM {
namespace UserAuth {
class EnrollCommand : public AsyncCommandBase {
public:
EnrollCommand(std::shared_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
EnrollCommand(std::weak_ptr<Executor> executor, uint64_t scheduleId, std::shared_ptr<AuthAttributes> commandAttrs,
sptr<IExecutorMessenger> executorMessenger);
~EnrollCommand() override = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
@@ -35,7 +35,7 @@ protected:
private:
uint32_t transNum_ = 1;
std::shared_ptr<AuthResPool::AuthAttributes> attributes_;
std::shared_ptr<AuthAttributes> attributes_;
};
} // namespace UserAuth
} // namespace UserIAM
@@ -23,8 +23,8 @@ namespace UserIAM {
namespace UserAuth {
class IdentifyCommand : public AsyncCommandBase {
public:
IdentifyCommand(std::shared_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
IdentifyCommand(std::weak_ptr<Executor> executor, uint64_t scheduleId, std::shared_ptr<AuthAttributes> commandAttrs,
sptr<IExecutorMessenger> executorMessenger);
~IdentifyCommand() override = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
@@ -35,7 +35,7 @@ protected:
private:
uint32_t transNum_ = 1;
std::shared_ptr<AuthResPool::AuthAttributes> attributes_;
std::shared_ptr<AuthAttributes> attributes_;
};
} // namespace UserAuth
} // namespace UserIAM
+1 -1
View File
@@ -37,7 +37,7 @@ public:
void OnFrameworkReady();
private:
std::recursive_mutex mutex_;
std::mutex mutex_;
std::string serviceName_;
HdiConfig hdiConfig_;
std::vector<std::shared_ptr<Executor>> executorList_;
+22 -20
View File
@@ -34,37 +34,39 @@ using namespace HDI::ServiceManager::V1_0;
class DriverManager : public Singleton<DriverManager> {
public:
friend SystemAbilityStatusListener;
int32_t Start(const std::map<std::string, HdiConfig> &hdiName2Config);
void OnFrameworkReady();
void OnAllHdiDisconnect();
void SubscribeHdiDriverStatus();
std::shared_ptr<Driver> GetDriverByServiceName(const std::string &serviceName);
private:
class HdiServiceStatusListener : public ServStatListenerStub {
public:
using StatusCallback = std::function<void(const ServiceStatus &)>;
explicit HdiServiceStatusListener(StatusCallback callback) : callback_(std::move(callback))
{
}
virtual ~HdiServiceStatusListener() = default;
void OnReceive(const ServiceStatus &status) override
{
callback_(status);
}
private:
StatusCallback callback_;
};
class HdiServiceStatusListener;
bool HdiConfigIsValid(const std::map<std::string, HdiConfig> &hdiName2Config);
void SubscribeHdiDriverStatus();
void SubscribeHdiManagerServiceStatus();
void SubscribeFrameworkReadyEvent();
void OnAllHdiDisconnect();
void OnAllHdiConnect();
std::recursive_mutex mutex_;
bool started = false;
std::mutex mutex_;
std::map<std::string, std::shared_ptr<Driver>> serviceName2Driver_;
std::map<std::string, HdiConfig> hdiName2Config_;
};
class DriverManager ::HdiServiceStatusListener : public ServStatListenerStub {
public:
using StatusCallback = std::function<void(const ServiceStatus &)>;
explicit HdiServiceStatusListener(StatusCallback callback) : callback_(std::move(callback))
{
}
virtual ~HdiServiceStatusListener() = default;
void OnReceive(const ServiceStatus &status) override
{
callback_(status);
}
private:
StatusCallback callback_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
+4 -5
View File
@@ -23,14 +23,15 @@
#include "nocopyable.h"
#include "executor_callback.h"
#include "iasync_command.h"
#include "iauth_executor_hdi.h"
#include "iexecute_callback.h"
#include "iexecutor_messenger.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
using namespace AuthResPool;
class Executor : public std::enable_shared_from_this<Executor>, public NoCopyable {
public:
Executor(std::shared_ptr<IAuthExecutorHdi> executorHdi, uint16_t hdiId);
@@ -39,8 +40,6 @@ public:
void OnHdiConnect();
void OnHdiDisconnect();
void OnFrameworkReady();
void SetExecutorMessenger(const sptr<AuthResPool::IExecutorMessenger> &messenger);
sptr<AuthResPool::IExecutorMessenger> GetExecutorMessenger();
void AddCommand(std::shared_ptr<IAsyncCommand> command);
void RemoveCommand(std::shared_ptr<IAsyncCommand> command);
std::shared_ptr<IAuthExecutorHdi> GetExecutorHdi();
@@ -49,8 +48,8 @@ public:
private:
void RegisterExecutorCallback(ExecutorInfo &executorInfo);
void RespondCallbackOnDisconnect();
sptr<AuthResPool::IExecutorMessenger> executorMessenger_;
std::recursive_mutex mutex_;
std::shared_ptr<ExecutorCallback> executorCallback_;
std::mutex mutex_;
std::set<std::shared_ptr<IAsyncCommand>> command2Respond_;
std::shared_ptr<IAuthExecutorHdi> executorHdi_;
std::string description_;
@@ -17,6 +17,7 @@
#define FRAMEWORK_EXECUTOR_CALLBACK_H
#include <cstdint>
#include <string>
#include "nocopyable.h"
@@ -29,42 +30,44 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
using namespace AuthResPool;
enum ScheduleMode {
SCHEDULE_MODE_ENROLL = 0,
SCHEDULE_MODE_AUTH = 1,
};
class FrameworkExecutorCallback : public AuthResPool::ExecutorCallback, public NoCopyable {
class FrameworkExecutorCallback : public ExecutorCallback, public NoCopyable {
public:
explicit FrameworkExecutorCallback(std::shared_ptr<Executor> executor);
explicit FrameworkExecutorCallback(std::weak_ptr<Executor> executor);
~FrameworkExecutorCallback() override = default;
int32_t OnBeginExecute(uint64_t scheduleId, std::vector<uint8_t> &publicKey,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs) override;
int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> consumerAttr) override;
int32_t OnSetProperty(std::shared_ptr<AuthResPool::AuthAttributes> properties) override;
void OnMessengerReady(const sptr<AuthResPool::IExecutorMessenger> &messenger, std::vector<uint8_t> &publicKey,
int32_t OnBeginExecute(
uint64_t scheduleId, std::vector<uint8_t> &publicKey, std::shared_ptr<AuthAttributes> commandAttrs) override;
int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr<AuthAttributes> consumerAttr) override;
int32_t OnSetProperty(std::shared_ptr<AuthAttributes> properties) override;
void OnMessengerReady(const sptr<IExecutorMessenger> &messenger, std::vector<uint8_t> &publicKey,
std::vector<uint64_t> &templateIds) override;
int32_t OnGetProperty(std::shared_ptr<AuthResPool::AuthAttributes> conditions,
std::shared_ptr<AuthResPool::AuthAttributes> values) override;
int32_t OnGetProperty(std::shared_ptr<AuthAttributes> conditions, std::shared_ptr<AuthAttributes> values) override;
private:
ResultCode OnBeginExecuteInner(uint64_t scheduleId, std::vector<uint8_t> &publicKey,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
ResultCode OnEndExecuteInner(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> consumerAttr);
ResultCode OnSetPropertyInner(std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode OnGetPropertyInner(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values);
ResultCode ProcessEnrollCommand(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode ProcessAuthCommand(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode ProcessIdentifyCommand(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties);
static uint32_t GenerateExecutorCallbackId();
ResultCode OnBeginExecuteInner(
uint64_t scheduleId, std::vector<uint8_t> &publicKey, std::shared_ptr<AuthAttributes> commandAttrs);
ResultCode OnEndExecuteInner(uint64_t scheduleId, std::shared_ptr<AuthAttributes> consumerAttr);
ResultCode OnSetPropertyInner(std::shared_ptr<AuthAttributes> properties);
ResultCode OnGetPropertyInner(std::shared_ptr<AuthAttributes> conditions, std::shared_ptr<AuthAttributes> values);
ResultCode ProcessEnrollCommand(uint64_t scheduleId, std::shared_ptr<AuthAttributes> properties);
ResultCode ProcessAuthCommand(uint64_t scheduleId, std::shared_ptr<AuthAttributes> properties);
ResultCode ProcessIdentifyCommand(uint64_t scheduleId, std::shared_ptr<AuthAttributes> properties);
ResultCode ProcessCancelCommand(uint64_t scheduleId);
ResultCode ProcessDeleteTemplateCommand(std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode ProcessCustomCommand(std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode ProcessDeleteTemplateCommand(std::shared_ptr<AuthAttributes> properties);
ResultCode ProcessCustomCommand(std::shared_ptr<AuthAttributes> properties);
ResultCode ProcessGetTemplateCommand(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values);
std::shared_ptr<Executor> executor_;
std::shared_ptr<AuthAttributes> conditions, std::shared_ptr<AuthAttributes> values);
const char *GetDescription();
sptr<IExecutorMessenger> executorMessenger_;
std::weak_ptr<Executor> executor_;
std::string description_;
};
} // namespace UserAuth
} // namespace UserIAM
@@ -29,13 +29,15 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
AsyncCommandBase::AsyncCommandBase(std::string type, uint64_t scheduleId, std::shared_ptr<Executor> executor)
AsyncCommandBase::AsyncCommandBase(
std::string type, uint64_t scheduleId, std::weak_ptr<Executor> executor, sptr<IExecutorMessenger> executorMessenger)
: scheduleId_(scheduleId),
executor_(executor),
commandId_(GenerateCommandId())
executorMessenger_(executorMessenger)
{
auto commandId = GenerateCommandId();
std::ostringstream ss;
ss << "Command(type:" << type << ", id:" << commandId_ << ", scheduleId:" << GET_MASKED_STRING(scheduleId_) << ")";
ss << "Command(type:" << type << ", id:" << commandId << ", scheduleId:" << GET_MASKED_STRING(scheduleId_) << ")";
description_ = ss.str();
}
@@ -49,9 +51,12 @@ void AsyncCommandBase::OnHdiDisconnect()
ResultCode AsyncCommandBase::StartProcess()
{
IAM_LOGI("%{public}s start process", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
executor_->AddCommand(shared_from_this());
auto executor = executor_.lock();
if (executor == nullptr) {
IAM_LOGE("executor has been released, start process fail");
return ResultCode::GENERAL_ERROR;
}
executor->AddCommand(shared_from_this());
ResultCode ret = SendRequest();
if (ret != ResultCode::SUCCESS) {
IAM_LOGE("send request failed");
@@ -76,8 +81,12 @@ void AsyncCommandBase::OnResult(ResultCode result, const std::vector<uint8_t> &e
void AsyncCommandBase::EndProcess()
{
IAM_LOGI("%{public}s end process", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
executor_->RemoveCommand(shared_from_this());
auto executor = executor_.lock();
if (executor == nullptr) {
IAM_LOGI("executor has been released, command has been removed, no need remove again");
return;
}
executor->RemoveCommand(shared_from_this());
}
const char *AsyncCommandBase::GetDescription()
@@ -90,9 +99,38 @@ uint32_t AsyncCommandBase::GenerateCommandId()
static std::mutex mutex;
static uint32_t commandId = 0;
std::lock_guard<std::mutex> guard(mutex);
// commandId is only used in log, uint32 overflow or duplicate is ok
++commandId;
return commandId;
}
std::shared_ptr<IAuthExecutorHdi> AsyncCommandBase::GetExecutorHdi()
{
auto executor = executor_.lock();
if (executor == nullptr) {
IAM_LOGE("executor has been released, get executor hdi fail");
return nullptr;
}
return executor->GetExecutorHdi();
}
int32_t AsyncCommandBase::MessengerSendData(
uint64_t scheduleId, uint64_t transNum, int32_t srcType, int32_t dstType, std::shared_ptr<AuthMessage> msg)
{
auto messenger = executorMessenger_;
IF_FALSE_LOGE_AND_RETURN_VAL(messenger != nullptr, USERAUTH_ERROR);
return messenger->SendData(scheduleId, transNum, srcType, dstType, msg);
}
int32_t AsyncCommandBase::MessengerFinish(
uint64_t scheduleId, int32_t srcType, int32_t resultCode, std::shared_ptr<AuthAttributes> finalResult)
{
auto messenger = executorMessenger_;
IF_FALSE_LOGE_AND_RETURN_VAL(messenger != nullptr, USERAUTH_ERROR);
int32_t ret = messenger->Finish(scheduleId, srcType, resultCode, finalResult);
executorMessenger_ = nullptr;
return ret;
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
@@ -26,9 +26,9 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
AuthCommand::AuthCommand(
std::shared_ptr<Executor> executor, uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> attributes)
: AsyncCommandBase("AUTH", scheduleId, executor),
AuthCommand::AuthCommand(std::weak_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthAttributes> attributes, sptr<IExecutorMessenger> executorMessenger)
: AsyncCommandBase("AUTH", scheduleId, executor, executorMessenger),
attributes_(attributes)
{
}
@@ -37,19 +37,18 @@ ResultCode AuthCommand::SendRequest()
{
IAM_LOGI("%{public}s send request start", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
auto hdi = GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
std::vector<uint64_t> tempalteIdList;
std::vector<uint64_t> templateIdList;
std::vector<uint8_t> extraInfo;
uint64_t templateId = 0;
attributes_->GetUint64Value(AUTH_TEMPLATE_ID, templateId);
uint64_t callerUid;
attributes_->GetUint64Value(AUTH_CALLER_UID, callerUid);
tempalteIdList.push_back(templateId);
templateIdList.push_back(templateId);
ResultCode ret = hdi->Authenticate(scheduleId_, callerUid, tempalteIdList, extraInfo, shared_from_this());
ResultCode ret = hdi->Authenticate(scheduleId_, callerUid, templateIdList, extraInfo, shared_from_this());
IAM_LOGI("%{public}s authenticate result %{public}d", GetDescription(), ret);
return ret;
}
@@ -57,34 +56,28 @@ ResultCode AuthCommand::SendRequest()
void AuthCommand::OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on result start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
auto authAttributes = Common::MakeShared<AuthResPool::AuthAttributes>();
auto authAttributes = Common::MakeShared<AuthAttributes>();
IF_FALSE_LOGE_AND_RETURN(authAttributes != nullptr);
authAttributes->SetUint32Value(AUTH_RESULT_CODE, result);
authAttributes->SetUint8ArrayValue(AUTH_RESULT, nonConstExtraInfo);
int32_t ret = executorMessenger->Finish(scheduleId_, ALL_IN_ONE, result, authAttributes);
int32_t ret = MessengerFinish(scheduleId_, ALL_IN_ONE, result, authAttributes);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("%{public}s call fininsh fail", GetDescription());
IAM_LOGE("%{public}s call finish fail", GetDescription());
return;
}
IAM_LOGI("%{public}s call fininsh success result %{public}d", GetDescription(), result);
IAM_LOGI("%{public}s call finish success result %{public}d", GetDescription(), result);
}
void AuthCommand::OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on acquire info start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
auto msg = Common::MakeShared<AuthResPool::AuthMessage>(nonConstExtraInfo);
auto msg = Common::MakeShared<AuthMessage>(nonConstExtraInfo);
IF_FALSE_LOGE_AND_RETURN(msg != nullptr);
int32_t ret = executorMessenger->SendData(scheduleId_, transNum_, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg);
int32_t ret = MessengerSendData(scheduleId_, transNum_, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg);
++transNum_;
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("%{public}s call SendData fail", GetDescription());
@@ -25,9 +25,8 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
CustomCommand::CustomCommand(
std::shared_ptr<Executor> executor, std::shared_ptr<AuthResPool::AuthAttributes> attributes)
: AsyncCommandBase("CUSTOM", 0, executor),
CustomCommand::CustomCommand(std::weak_ptr<Executor> executor, std::shared_ptr<AuthAttributes> attributes)
: AsyncCommandBase("CUSTOM", 0, executor, nullptr),
attributes_(attributes)
{
}
@@ -37,12 +36,10 @@ ResultCode CustomCommand::SendRequest()
static const size_t MAX_TEMPLATE_LIST_LEN = 1000;
IAM_LOGI("%{public}s send request start", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
auto hdi = GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
future_ = promise_.get_future();
uint32_t commandId = 0;
attributes_->GetUint32Value(AUTH_PROPERTY_MODE, commandId);
std::vector<uint64_t> templateIdList;
@@ -27,9 +27,9 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
EnrollCommand::EnrollCommand(
std::shared_ptr<Executor> executor, uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> attributes)
: AsyncCommandBase("ENROLL", scheduleId, executor),
EnrollCommand::EnrollCommand(std::weak_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthAttributes> attributes, sptr<IExecutorMessenger> executorMessenger)
: AsyncCommandBase("ENROLL", scheduleId, executor, executorMessenger),
attributes_(attributes)
{
}
@@ -38,8 +38,7 @@ ResultCode EnrollCommand::SendRequest()
{
IAM_LOGI("%{public}s send request start", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
auto hdi = GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
std::vector<uint8_t> extraInfo;
@@ -56,34 +55,28 @@ ResultCode EnrollCommand::SendRequest()
void EnrollCommand::OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on result start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
auto authAttributes = Common::MakeShared<AuthResPool::AuthAttributes>();
auto authAttributes = Common::MakeShared<AuthAttributes>();
IF_FALSE_LOGE_AND_RETURN(authAttributes != nullptr);
authAttributes->SetUint32Value(AUTH_RESULT_CODE, result);
authAttributes->SetUint8ArrayValue(AUTH_RESULT, nonConstExtraInfo);
int32_t ret = executorMessenger->Finish(scheduleId_, ALL_IN_ONE, result, authAttributes);
int32_t ret = MessengerFinish(scheduleId_, ALL_IN_ONE, result, authAttributes);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("%{public}s call fininsh fail", GetDescription());
IAM_LOGE("%{public}s call finish fail", GetDescription());
return;
}
IAM_LOGI("%{public}s call fininsh success result %{public}d", GetDescription(), result);
IAM_LOGI("%{public}s call finish success result %{public}d", GetDescription(), result);
}
void EnrollCommand::OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on acquire info start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
auto msg = Common::MakeShared<AuthResPool::AuthMessage>(nonConstExtraInfo);
auto msg = Common::MakeShared<AuthMessage>(nonConstExtraInfo);
IF_FALSE_LOGE_AND_RETURN(msg != nullptr);
int32_t ret = executorMessenger->SendData(scheduleId_, transNum_, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg);
int32_t ret = MessengerSendData(scheduleId_, transNum_, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg);
++transNum_;
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("%{public}s call SendData fail", GetDescription());
@@ -25,9 +25,9 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
IdentifyCommand::IdentifyCommand(
std::shared_ptr<Executor> executor, uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> attributes)
: AsyncCommandBase("IDENTIFY", scheduleId, executor),
IdentifyCommand::IdentifyCommand(std::weak_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthAttributes> attributes, sptr<IExecutorMessenger> executorMessenger)
: AsyncCommandBase("IDENTIFY", scheduleId, executor, executorMessenger),
attributes_(attributes)
{
}
@@ -36,17 +36,16 @@ ResultCode IdentifyCommand::SendRequest()
{
IAM_LOGI("%{public}s send request start", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
auto hdi = GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
std::vector<uint64_t> tempalteIdList;
std::vector<uint64_t> templateIdList;
std::vector<uint8_t> extraInfo;
uint64_t templateId = 0;
attributes_->GetUint64Value(AUTH_TEMPLATE_ID, templateId);
uint64_t callerUid;
attributes_->GetUint64Value(AUTH_CALLER_UID, callerUid);
tempalteIdList.push_back(templateId);
templateIdList.push_back(templateId);
ResultCode ret = hdi->Identify(scheduleId_, callerUid, extraInfo, shared_from_this());
IAM_LOGI("%{public}s identify result %{public}d", GetDescription(), ret);
@@ -56,34 +55,28 @@ ResultCode IdentifyCommand::SendRequest()
void IdentifyCommand::OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on result start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
auto authAttributes = Common::MakeShared<AuthResPool::AuthAttributes>();
auto authAttributes = Common::MakeShared<AuthAttributes>();
IF_FALSE_LOGE_AND_RETURN(authAttributes != nullptr);
authAttributes->SetUint32Value(AUTH_RESULT_CODE, result);
authAttributes->SetUint8ArrayValue(AUTH_RESULT, nonConstExtraInfo);
int32_t ret = executorMessenger->Finish(scheduleId_, ALL_IN_ONE, result, authAttributes);
int32_t ret = MessengerFinish(scheduleId_, ALL_IN_ONE, result, authAttributes);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("%{public}s call fininsh fail", GetDescription());
IAM_LOGE("%{public}s call finish fail", GetDescription());
return;
}
IAM_LOGI("%{public}s call fininsh success result %{public}d", GetDescription(), result);
IAM_LOGI("%{public}s call finish success result %{public}d", GetDescription(), result);
}
void IdentifyCommand::OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on acquire info start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
auto msg = Common::MakeShared<AuthResPool::AuthMessage>(nonConstExtraInfo);
auto msg = Common::MakeShared<AuthMessage>(nonConstExtraInfo);
IF_FALSE_LOGE_AND_RETURN(msg != nullptr);
int32_t ret = executorMessenger->SendData(scheduleId_, transNum_, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg);
int32_t ret = MessengerSendData(scheduleId_, transNum_, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg);
++transNum_;
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("%{public}s call SendData fail", GetDescription());
+3 -3
View File
@@ -36,7 +36,7 @@ void Driver::OnHdiConnect()
{
IAM_LOGI("start");
OnHdiDisconnect();
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
std::vector<std::shared_ptr<IAuthExecutorHdi>> executorHdiList;
IF_FALSE_LOGE_AND_RETURN(hdiConfig_.driver != nullptr);
hdiConfig_.driver->GetExecutorList(executorHdiList);
@@ -57,7 +57,7 @@ void Driver::OnHdiConnect()
void Driver::OnHdiDisconnect()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
for (const auto &executor : executorList_) {
if (executor == nullptr) {
IAM_LOGE("executor is null");
@@ -72,7 +72,7 @@ void Driver::OnHdiDisconnect()
void Driver::OnFrameworkReady()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
for (const auto &executor : executorList_) {
if (executor == nullptr) {
IAM_LOGE("executor is null");
+23 -24
View File
@@ -40,7 +40,12 @@ int32_t DriverManager::Start(const std::map<std::string, HdiConfig> &hdiName2Con
IAM_LOGE("service config is not valid");
return USERAUTH_ERROR;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
if (started) {
IAM_LOGE("driver manager already started");
return USERAUTH_ERROR;
}
started = true;
hdiName2Config_ = hdiName2Config;
serviceName2Driver_.clear();
for (auto const &pair : hdiName2Config) {
@@ -54,7 +59,6 @@ int32_t DriverManager::Start(const std::map<std::string, HdiConfig> &hdiName2Con
}
SubscribeHdiManagerServiceStatus();
SubscribeFrameworkReadyEvent();
OnAllHdiConnect();
IAM_LOGI("success");
return USERAUTH_SUCCESS;
}
@@ -86,16 +90,13 @@ void DriverManager::SubscribeHdiDriverStatus()
return;
}
auto listener = new (std::nothrow) HdiServiceStatusListener([this](const ServiceStatus &status) {
std::lock_guard<std::recursive_mutex> lock(this->mutex_);
auto driverIter = this->serviceName2Driver_.find(status.serviceName);
if (driverIter == this->serviceName2Driver_.end()) {
auto listener = new (std::nothrow) HdiServiceStatusListener([](const ServiceStatus &status) {
auto driver = DriverManager::GetInstance().GetDriverByServiceName(status.serviceName);
if (driver == nullptr) {
return;
}
IAM_LOGI("service %{public}s receive status %{public}d", status.serviceName.c_str(), status.status);
auto driver = driverIter->second;
IF_FALSE_LOGE_AND_RETURN(driver != nullptr);
switch (status.status) {
case SERVIE_STATUS_START:
IAM_LOGI("service %{public}s status change to start", status.serviceName.c_str());
@@ -164,7 +165,7 @@ void DriverManager::SubscribeFrameworkReadyEvent()
void DriverManager::OnAllHdiDisconnect()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
for (auto const &pair : serviceName2Driver_) {
if (pair.second == nullptr) {
IAM_LOGE("pair.second is null");
@@ -175,24 +176,10 @@ void DriverManager::OnAllHdiDisconnect()
IAM_LOGI("success");
}
void DriverManager::OnAllHdiConnect()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto const &pair : serviceName2Driver_) {
if (pair.second == nullptr) {
IAM_LOGE("pair.second is null");
continue;
}
pair.second->OnHdiConnect();
}
IAM_LOGI("success");
}
void DriverManager::OnFrameworkReady()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
for (auto const &pair : serviceName2Driver_) {
if (pair.second == nullptr) {
IAM_LOGE("pair.second is null");
@@ -200,6 +187,18 @@ void DriverManager::OnFrameworkReady()
}
pair.second->OnFrameworkReady();
}
IAM_LOGI("success");
}
std::shared_ptr<Driver> DriverManager::GetDriverByServiceName(const std::string &serviceName)
{
IAM_LOGI("start");
std::lock_guard<std::mutex> lock(mutex_);
auto driverIter = serviceName2Driver_.find(serviceName);
if (driverIter == serviceName2Driver_.end()) {
return nullptr;
}
return driverIter->second;
}
} // namespace UserAuth
} // namespace UserIAM
+13 -20
View File
@@ -47,7 +47,7 @@ Executor::Executor(std::shared_ptr<IAuthExecutorHdi> executorHdi, uint16_t hdiId
void Executor::OnHdiConnect()
{
IAM_LOGI("%{public}s start", GetDescription());
// register resource pool depends on hdi start, after hid connect re-register resource pool
// register resource pool depends on hdi connect, after hid connect re-register resource pool
OnFrameworkReady();
}
@@ -79,30 +79,23 @@ void Executor::RegisterExecutorCallback(ExecutorInfo &executorInfo)
IAM_LOGI("%{public}s start", GetDescription());
auto combineResult = Common::CombineShortToInt(hdiId_, static_cast<uint16_t>(executorInfo.executorId));
executorInfo.executorId = static_cast<int32_t>(combineResult);
auto executorCallback = Common::MakeShared<FrameworkExecutorCallback>(shared_from_this());
IF_FALSE_LOGE_AND_RETURN(executorCallback != nullptr);
UserIAM::AuthResPool::ExecutorMgr::GetInstance().Register(executorInfo, executorCallback);
if (executorCallback_ == nullptr) {
std::lock_guard<std::mutex> lock(mutex_);
if (executorCallback_ == nullptr) {
auto localExecutorCallback = Common::MakeShared<FrameworkExecutorCallback>(weak_from_this());
IF_FALSE_LOGE_AND_RETURN(localExecutorCallback != nullptr);
executorCallback_ = localExecutorCallback;
}
}
ExecutorMgr::GetInstance().Register(executorInfo, executorCallback_);
IAM_LOGI(
"register executor callback ok, executor id %{public}s", GET_MASKED_STRING(executorInfo.executorId).c_str());
}
void Executor::SetExecutorMessenger(const sptr<AuthResPool::IExecutorMessenger> &messenger)
{
IAM_LOGI("%{public}s start", GetDescription());
executorMessenger_ = messenger;
return;
}
sptr<AuthResPool::IExecutorMessenger> Executor::GetExecutorMessenger()
{
IAM_LOGI("%{public}s start", GetDescription());
return executorMessenger_;
}
void Executor::AddCommand(std::shared_ptr<IAsyncCommand> command)
{
IAM_LOGI("%{public}s start", GetDescription());
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
IF_FALSE_LOGE_AND_RETURN(command != nullptr);
command2Respond_.insert(command);
}
@@ -110,14 +103,14 @@ void Executor::AddCommand(std::shared_ptr<IAsyncCommand> command)
void Executor::RemoveCommand(std::shared_ptr<IAsyncCommand> command)
{
IAM_LOGI("%{public}s start", GetDescription());
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
command2Respond_.erase(command);
}
void Executor::RespondCallbackOnDisconnect()
{
IAM_LOGI("%{public}s start", GetDescription());
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
for (auto it = command2Respond_.begin(); it != command2Respond_.end();) {
auto cmdToProc = it;
++it;
@@ -15,6 +15,9 @@
#include "framework_executor_callback.h"
#include <mutex>
#include <sstream>
#include "auth_command.h"
#include "custom_command.h"
#include "enroll_command.h"
@@ -29,18 +32,22 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
FrameworkExecutorCallback::FrameworkExecutorCallback(std::shared_ptr<Executor> executor) : executor_(executor)
FrameworkExecutorCallback::FrameworkExecutorCallback(std::weak_ptr<Executor> executor) : executor_(executor)
{
uint32_t callbackId = GenerateExecutorCallbackId();
std::ostringstream ss;
ss << "ExecutorCallback(Id:" << callbackId << ")";
description_ = ss.str();
}
int32_t FrameworkExecutorCallback::OnBeginExecute(
uint64_t scheduleId, std::vector<uint8_t> &publicKey, std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs)
uint64_t scheduleId, std::vector<uint8_t> &publicKey, std::shared_ptr<AuthAttributes> commandAttrs)
{
return OnBeginExecuteInner(scheduleId, publicKey, commandAttrs);
}
ResultCode FrameworkExecutorCallback::OnBeginExecuteInner(
uint64_t scheduleId, std::vector<uint8_t> &publicKey, std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs)
uint64_t scheduleId, std::vector<uint8_t> &publicKey, std::shared_ptr<AuthAttributes> commandAttrs)
{
static_cast<void>(publicKey);
IF_FALSE_LOGE_AND_RETURN_VAL(commandAttrs != nullptr, ResultCode::GENERAL_ERROR);
@@ -48,7 +55,7 @@ ResultCode FrameworkExecutorCallback::OnBeginExecuteInner(
IF_FALSE_LOGE_AND_RETURN_VAL(
commandAttrs->GetUint32Value(AUTH_SCHEDULE_MODE, commandId) == USERAUTH_SUCCESS, ResultCode::GENERAL_ERROR);
IAM_LOGI("start process cmd %{public}u", commandId);
IAM_LOGI("%{public}s start process cmd %{public}u", GetDescription(), commandId);
ResultCode ret = ResultCode::GENERAL_ERROR;
switch (commandId) {
case SCHEDULE_MODE_ENROLL:
@@ -65,21 +72,20 @@ ResultCode FrameworkExecutorCallback::OnBeginExecuteInner(
return ret;
}
int32_t FrameworkExecutorCallback::OnEndExecute(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> consumerAttr)
int32_t FrameworkExecutorCallback::OnEndExecute(uint64_t scheduleId, std::shared_ptr<AuthAttributes> consumerAttr)
{
return OnEndExecuteInner(scheduleId, consumerAttr);
}
ResultCode FrameworkExecutorCallback::OnEndExecuteInner(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> consumerAttr)
uint64_t scheduleId, std::shared_ptr<AuthAttributes> consumerAttr)
{
IF_FALSE_LOGE_AND_RETURN_VAL(consumerAttr != nullptr, ResultCode::GENERAL_ERROR);
uint32_t commandId = 0;
IF_FALSE_LOGE_AND_RETURN_VAL(
consumerAttr->GetUint32Value(AUTH_SCHEDULE_MODE, commandId) == USERAUTH_SUCCESS, ResultCode::GENERAL_ERROR);
IAM_LOGI("start process cmd %{public}u", commandId);
IAM_LOGI("%{public}s start process cmd %{public}u", GetDescription(), commandId);
ResultCode ret = ResultCode::GENERAL_ERROR;
switch (commandId) {
case SCHEDULE_MODE_AUTH:
@@ -96,30 +102,34 @@ ResultCode FrameworkExecutorCallback::OnEndExecuteInner(
return ret;
}
void FrameworkExecutorCallback::OnMessengerReady(const sptr<AuthResPool::IExecutorMessenger> &messenger,
std::vector<uint8_t> &publicKey, std::vector<uint64_t> &templateIds)
void FrameworkExecutorCallback::OnMessengerReady(
const sptr<IExecutorMessenger> &messenger, std::vector<uint8_t> &publicKey, std::vector<uint64_t> &templateIds)
{
IAM_LOGI("start");
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto hdi = executor_->GetExecutorHdi();
IAM_LOGI("%{public}s start", GetDescription());
auto executor = executor_.lock();
if (executor == nullptr) {
IAM_LOGE("executor has been released, process failed");
return;
}
auto hdi = executor->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN(hdi != nullptr);
executor_->SetExecutorMessenger(messenger);
executorMessenger_ = messenger;
std::vector<uint8_t> extraInfo;
hdi->OnRegisterFinish(templateIds, publicKey, extraInfo);
}
int32_t FrameworkExecutorCallback::OnSetProperty(std::shared_ptr<AuthResPool::AuthAttributes> properties)
int32_t FrameworkExecutorCallback::OnSetProperty(std::shared_ptr<AuthAttributes> properties)
{
return OnSetPropertyInner(properties);
}
ResultCode FrameworkExecutorCallback::OnSetPropertyInner(std::shared_ptr<AuthResPool::AuthAttributes> properties)
ResultCode FrameworkExecutorCallback::OnSetPropertyInner(std::shared_ptr<AuthAttributes> properties)
{
IF_FALSE_LOGE_AND_RETURN_VAL(properties != nullptr, ResultCode::GENERAL_ERROR);
uint32_t commandId = 0;
IF_FALSE_LOGE_AND_RETURN_VAL(
properties->GetUint32Value(AUTH_PROPERTY_MODE, commandId) == USERAUTH_SUCCESS, ResultCode::GENERAL_ERROR);
IAM_LOGI("start process cmd %{public}u", commandId);
IAM_LOGI("%{public}s start process cmd %{public}u", GetDescription(), commandId);
ResultCode ret = ResultCode::GENERAL_ERROR;
if (commandId == PROPERMODE_DELETE) {
ret = ProcessDeleteTemplateCommand(properties);
@@ -131,15 +141,15 @@ ResultCode FrameworkExecutorCallback::OnSetPropertyInner(std::shared_ptr<AuthRes
}
int32_t FrameworkExecutorCallback::OnGetProperty(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values)
std::shared_ptr<AuthAttributes> conditions, std::shared_ptr<AuthAttributes> values)
{
return OnGetPropertyInner(conditions, values);
}
ResultCode FrameworkExecutorCallback::OnGetPropertyInner(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values)
std::shared_ptr<AuthAttributes> conditions, std::shared_ptr<AuthAttributes> values)
{
IAM_LOGI("start");
IAM_LOGI("%{public}s start", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(conditions != nullptr, ResultCode::GENERAL_ERROR);
uint32_t commandId = 0;
IF_FALSE_LOGE_AND_RETURN_VAL(
@@ -154,55 +164,62 @@ ResultCode FrameworkExecutorCallback::OnGetPropertyInner(
}
ResultCode FrameworkExecutorCallback::ProcessEnrollCommand(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties)
uint64_t scheduleId, std::shared_ptr<AuthAttributes> properties)
{
auto command = Common::MakeShared<EnrollCommand>(executor_, scheduleId, properties);
auto command = Common::MakeShared<EnrollCommand>(executor_, scheduleId, properties, executorMessenger_);
IF_FALSE_LOGE_AND_RETURN_VAL(command != nullptr, ResultCode::GENERAL_ERROR);
return command->StartProcess();
}
ResultCode FrameworkExecutorCallback::ProcessAuthCommand(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties)
uint64_t scheduleId, std::shared_ptr<AuthAttributes> properties)
{
auto command = Common::MakeShared<AuthCommand>(executor_, scheduleId, properties);
auto command = Common::MakeShared<AuthCommand>(executor_, scheduleId, properties, executorMessenger_);
IF_FALSE_LOGE_AND_RETURN_VAL(command != nullptr, ResultCode::GENERAL_ERROR);
return command->StartProcess();
}
ResultCode FrameworkExecutorCallback::ProcessIdentifyCommand(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties)
uint64_t scheduleId, std::shared_ptr<AuthAttributes> properties)
{
auto command = Common::MakeShared<IdentifyCommand>(executor_, scheduleId, properties);
auto command = Common::MakeShared<IdentifyCommand>(executor_, scheduleId, properties, executorMessenger_);
IF_FALSE_LOGE_AND_RETURN_VAL(command != nullptr, ResultCode::GENERAL_ERROR);
return command->StartProcess();
}
ResultCode FrameworkExecutorCallback::ProcessCancelCommand(uint64_t scheduleId)
{
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
auto executor = executor_.lock();
if (executor == nullptr) {
IAM_LOGE("executor has been released, process failed");
return ResultCode::GENERAL_ERROR;
}
auto hdi = executor->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
hdi->Cancel(scheduleId);
return ResultCode::SUCCESS;
}
ResultCode FrameworkExecutorCallback::ProcessDeleteTemplateCommand(
std::shared_ptr<AuthResPool::AuthAttributes> properties)
ResultCode FrameworkExecutorCallback::ProcessDeleteTemplateCommand(std::shared_ptr<AuthAttributes> properties)
{
IAM_LOGI("start");
IF_FALSE_LOGE_AND_RETURN_VAL(properties != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
auto executor = executor_.lock();
if (executor == nullptr) {
IAM_LOGE("executor has been released, process failed");
return ResultCode::GENERAL_ERROR;
}
auto hdi = executor->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
uint64_t templateId = 0;
properties->GetUint64Value(AUTH_TEMPLATE_ID, templateId);
std::vector<uint64_t> tempalteIdList;
tempalteIdList.push_back(templateId);
hdi->Delete(tempalteIdList);
std::vector<uint64_t> templateIdList;
templateIdList.push_back(templateId);
hdi->Delete(templateIdList);
return ResultCode::SUCCESS;
}
ResultCode FrameworkExecutorCallback::ProcessCustomCommand(std::shared_ptr<AuthResPool::AuthAttributes> properties)
ResultCode FrameworkExecutorCallback::ProcessCustomCommand(std::shared_ptr<AuthAttributes> properties)
{
auto command = Common::MakeShared<CustomCommand>(executor_, properties);
IF_FALSE_LOGE_AND_RETURN_VAL(command != nullptr, ResultCode::GENERAL_ERROR);
@@ -216,13 +233,17 @@ ResultCode FrameworkExecutorCallback::ProcessCustomCommand(std::shared_ptr<AuthR
}
ResultCode FrameworkExecutorCallback::ProcessGetTemplateCommand(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values)
std::shared_ptr<AuthAttributes> conditions, std::shared_ptr<AuthAttributes> values)
{
IAM_LOGI("start");
IF_FALSE_LOGE_AND_RETURN_VAL(conditions != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(values != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
auto executor = executor_.lock();
if (executor == nullptr) {
IAM_LOGE("executor has been released, process failed");
return ResultCode::GENERAL_ERROR;
}
auto hdi = executor->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
uint64_t templateId = 0;
conditions->GetUint64Value(AUTH_TEMPLATE_ID, templateId);
@@ -235,6 +256,21 @@ ResultCode FrameworkExecutorCallback::ProcessGetTemplateCommand(
values->SetUint32Value(AUTH_REMAIN_COUNT, templateInfo.remainTimes);
return ResultCode::SUCCESS;
}
uint32_t FrameworkExecutorCallback::GenerateExecutorCallbackId()
{
static std::mutex mutex;
static uint32_t callbackId = 0;
std::lock_guard<std::mutex> guard(mutex);
// callbackId is only used in log, uint32 overflow or duplicate is ok
++callbackId;
return callbackId;
}
const char *FrameworkExecutorCallback::GetDescription()
{
return description_.c_str();
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
@@ -29,7 +29,7 @@ sptr<SystemAbilityStatusListener> SystemAbilityStatusListener::instance_ = nullp
sptr<SystemAbilityStatusListener> SystemAbilityStatusListener::GetInstance()
{
if (instance_ == nullptr) {
std::lock_guard<std::mutex> gurard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
if (instance_ == nullptr) {
instance_ = new (std::nothrow) SystemAbilityStatusListener();
if (instance_ == nullptr) {
+1 -2
View File
@@ -26,12 +26,11 @@ namespace OHOS {
namespace UserIAM {
namespace Common {
using namespace std;
const uint64_t UINT64_MASK = 0xffff;
const int32_t MASK_WIDTH = 4;
static inline std::string GetMaskedString(uint16_t val)
{
std::ostringstream ss;
ss << "0xXXXX" << std::setfill('0') << std::setw(MASK_WIDTH) << std::hex << (val & UINT64_MASK);
ss << "0xXXXX" << std::setfill('0') << std::setw(MASK_WIDTH) << std::hex << val;
return ss.str();
}