!1037 fix ai review

Merge pull request !1037 from 陈伟健/master
This commit is contained in:
openharmony_ci 2024-09-14 07:36:03 +00:00 committed by Gitee
commit 74e50cce90
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
22 changed files with 116 additions and 139 deletions

View File

@ -71,7 +71,6 @@ ohos_source_set("iam_utils") {
]
sources = [
"utils/iam_mem.cpp",
"utils/iam_time.cpp",
"utils/xcollie_helper.cpp",
]

View File

@ -1,50 +0,0 @@
/*
* 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_mem.h"
#include <cstdint>
#include <vector>
#include "securec.h"
namespace OHOS {
namespace UserIam {
namespace Common {
int32_t UnpackUint64(const std::vector<uint8_t> &src, size_t index, uint64_t &data)
{
if ((src.size() < index) || (src.size() - index < sizeof(uint64_t))) {
return 1;
}
if (memcpy_s(static_cast<void *>(&data), sizeof(uint64_t), &src[index], sizeof(uint64_t)) != 0) {
return 1;
}
return 0;
}
int32_t UnpackInt32(const std::vector<uint8_t> &src, size_t index, int32_t &data)
{
if ((src.size() < index) || (src.size() - index < sizeof(int32_t))) {
return 1;
}
if (memcpy_s(static_cast<void *>(&data), sizeof(int32_t), &src[index], sizeof(int32_t)) != 0) {
return 1;
}
return 0;
}
} // namespace Common
} // namespace UserIam
} // namespace OHOS

View File

@ -22,16 +22,6 @@
namespace OHOS {
namespace UserIam {
namespace Common {
template <typename T>
inline void Pack(std::vector<uint8_t> &dst, const T &data)
{
const uint8_t *src = static_cast<const uint8_t *>(static_cast<const void *>(&data));
dst.insert(dst.end(), src, src + sizeof(T));
}
int32_t UnpackUint64(const std::vector<uint8_t> &src, size_t index, uint64_t &data);
int32_t UnpackInt32(const std::vector<uint8_t> &src, size_t index, int32_t &data);
inline uint32_t CombineUint16ToUint32(uint16_t upper, uint16_t lower)
{
return (static_cast<uint32_t>(upper) << 16U) | lower;

View File

@ -53,7 +53,7 @@ const std::map<int32_t, AuthenticationResult> g_result2ExecuteResult = {
{ResultCode::PIN_EXPIRED, AuthenticationResult::GENERAL_ERROR},
};
void DestoryWork(uv_work_t *work)
void DestroyWork(uv_work_t *work)
{
if (work == nullptr) {
return;
@ -74,32 +74,32 @@ void OnCallbackV6Work(uv_work_t *work, int status)
ResultCallbackV6Holder *resultHolder = reinterpret_cast<ResultCallbackV6Holder *>(work->data);
if (resultHolder == nullptr || resultHolder->callback == nullptr) {
IAM_LOGE("resultHolder is invalid");
DestoryWork(work);
DestroyWork(work);
return;
}
napi_handle_scope scope = nullptr;
napi_open_handle_scope(resultHolder->env, &scope);
if (scope == nullptr) {
IAM_LOGE("scope is invalid");
DestoryWork(work);
DestroyWork(work);
return;
}
napi_status ret = resultHolder->callback->DoPromise(resultHolder->result);
if (ret != napi_ok) {
IAM_LOGE("DoPromise fail %{public}d", ret);
napi_close_handle_scope(resultHolder->env, scope);
DestoryWork(work);
DestroyWork(work);
return;
}
ret = resultHolder->callback->DoCallback(resultHolder->result);
if (ret != napi_ok) {
IAM_LOGE("DoCallback fail %{public}d", ret);
napi_close_handle_scope(resultHolder->env, scope);
DestoryWork(work);
DestroyWork(work);
return;
}
napi_close_handle_scope(resultHolder->env, scope);
DestoryWork(work);
DestroyWork(work);
return;
}
}
@ -197,7 +197,7 @@ void UserAuthCallbackV6::OnResult(int32_t result, const Attributes &extraInfo)
work->data = reinterpret_cast<void *>(resultHolder);
if (uv_queue_work_with_qos(loop, work, [](uv_work_t *work) {}, OnCallbackV6Work, uv_qos_user_initiated) != 0) {
IAM_LOGE("uv_queue_work_with_qos fail");
DestoryWork(work);
DestroyWork(work);
}
}
} // namespace UserAuth

View File

@ -15,7 +15,6 @@
#include "iam_logger.h"
#include "user_auth_impl.h"
#include "auth_instance_v9.h"
#include "nlohmann/json.hpp"
#include "user_auth_impl.h"

View File

@ -31,7 +31,7 @@ struct CallbackHolder {
napi_env env;
};
void DestoryWork(uv_work_t *work)
void DestroyWork(uv_work_t *work)
{
if (work == nullptr) {
return;
@ -52,25 +52,25 @@ void OnWork(uv_work_t *work, int status)
CallbackHolder *holder = reinterpret_cast<CallbackHolder *>(work->data);
if (holder == nullptr || holder->callback == nullptr) {
IAM_LOGE("holder is invalid");
DestoryWork(work);
DestroyWork(work);
return;
}
napi_handle_scope scope = nullptr;
napi_open_handle_scope(holder->env, &scope);
if (scope == nullptr) {
IAM_LOGE("scope is invalid");
DestoryWork(work);
DestroyWork(work);
return;
}
napi_status ret = holder->callback->DoCommandCallback(holder->cmdData);
if (ret != napi_ok) {
IAM_LOGE("DoResultCallback fail %{public}d", ret);
napi_close_handle_scope(holder->env, scope);
DestoryWork(work);
DestroyWork(work);
return;
}
napi_close_handle_scope(holder->env, scope);
DestoryWork(work);
DestroyWork(work);
}
}
@ -152,7 +152,7 @@ void UserAuthWidgetCallback::SendCommand(const std::string &cmdData)
work->data = reinterpret_cast<void *>(holder);
if (uv_queue_work_with_qos(loop, work, [](uv_work_t *work) {}, OnWork, uv_qos_user_initiated) != 0) {
IAM_LOGE("uv_queue_work_with_qos fail");
DestoryWork(work);
DestroyWork(work);
}
}
} // namespace UserAuth

View File

@ -34,9 +34,6 @@ const std::string VERSION = "version";
UserAuthWidgetMgr::UserAuthWidgetMgr(napi_env env) : callback_(Common::MakeShared<UserAuthWidgetCallback>(env))
{
if (callback_ == nullptr) {
IAM_LOGE("get null callback");
}
}
UserAuthResultCode UserAuthWidgetMgr::Init(napi_env env, napi_callback_info info)

View File

@ -47,12 +47,12 @@ extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_UserAuth
}
extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_UserAuthExtensionAbility_GetABCCode(
const char **buf, int *buflen)
const char **buf, int *bufLen)
{
if (buf != nullptr) {
*buf = _binary_user_auth_extension_ability_abc_start;
}
if (buflen != nullptr) {
*buflen = _binary_user_auth_extension_ability_abc_end - _binary_user_auth_extension_ability_abc_start;
if (bufLen != nullptr) {
*bufLen = _binary_user_auth_extension_ability_abc_end - _binary_user_auth_extension_ability_abc_start;
}
}

View File

@ -59,7 +59,7 @@ void CallbackManagerImpl::OnServiceDeath()
IAM_LOGI("start");
std::lock_guard<std::mutex> lock(mutex_);
for (const auto &item : callbackActionMap_) {
if (item.second) {
if (item.second != nullptr) {
item.second();
}
}

View File

@ -103,7 +103,7 @@ struct RemoteConnectFaultTrace {
bool ack = false;
};
void ReportSystemFault(const std::string &timeString, const std::string &moudleName);
void ReportSystemFault(const std::string &timeString, const std::string &moduleName);
void ReportSecurityTemplateChange(const TemplateChangeTrace &info);
void ReportBehaviorCredManager(const UserCredManagerTrace &info);
void ReportSecurityCredChange(const UserCredChangeTrace &info);

View File

@ -69,15 +69,15 @@ static std::string MaskForStringId(const std::string &id)
return id.substr(0, MASK_WIDTH) + "**" + id.substr(id.length() - MASK_WIDTH, id.length());
}
void ReportSystemFault(const std::string &timeString, const std::string &moudleName)
void ReportSystemFault(const std::string &timeString, const std::string &moduleName)
{
int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_SYSTEM_FAULT",
HiSysEvent::EventType::FAULT,
STR_HAPPEN_TIME, timeString,
STR_MODULE_NAME, moudleName);
STR_MODULE_NAME, moduleName);
if (ret != 0) {
IAM_LOGE("hisysevent write failed! ret %{public}d, timeString %{public}s, moudleName %{public}s.",
ret, timeString.c_str(), moudleName.c_str());
IAM_LOGE("hisysevent write failed! ret %{public}d, timeString %{public}s, moduleName %{public}s.",
ret, timeString.c_str(), moduleName.c_str());
}
}

View File

@ -52,7 +52,7 @@ int32_t CoAuthProxy::WriteExecutorInfo(const ExecutorRegisterInfo &info, Message
return WRITE_PARCEL_ERROR;
}
if (!data.WriteUint32(info.maxTemplateAcl)) {
IAM_LOGE("failed to write esl");
IAM_LOGE("failed to write maxTemplateAcl");
return WRITE_PARCEL_ERROR;
}
if (!data.WriteUInt8Vector(info.publicKey)) {

View File

@ -117,7 +117,7 @@ int32_t CoAuthStub::ReadExecutorRegisterInfo(ExecutorRegisterInfo &executorInfo,
return READ_PARCEL_ERROR;
}
if (!data.ReadUint32(executorInfo.maxTemplateAcl)) {
IAM_LOGE("failed to read esl");
IAM_LOGE("failed to read maxTemplateAcl");
return READ_PARCEL_ERROR;
}
if (!data.ReadUInt8Vector(&executorInfo.publicKey)) {
@ -125,11 +125,11 @@ int32_t CoAuthStub::ReadExecutorRegisterInfo(ExecutorRegisterInfo &executorInfo,
return READ_PARCEL_ERROR;
}
if (!data.ReadString(executorInfo.deviceUdid)) {
IAM_LOGE("failed to read publicKey");
IAM_LOGE("failed to read deviceUdid");
return READ_PARCEL_ERROR;
}
if (!data.ReadUInt8Vector(&executorInfo.signedRemoteExecutorInfo)) {
IAM_LOGE("failed to read publicKey");
IAM_LOGE("failed to read signedRemoteExecutorInfo");
return READ_PARCEL_ERROR;
}

View File

@ -67,7 +67,7 @@ void ContextAppStateObserverManager::SubscribeAppState(const std::shared_ptr<Con
IAM_LOGE("GetAppManagerInstance failed");
return;
}
appStateObserver_ = new (std::nothrow) ContextAppStateObserver(contextId, bundleName);
if (appStateObserver_ == nullptr) {
IAM_LOGE("get appStateObserver failed");

View File

@ -33,7 +33,7 @@ namespace OHOS {
namespace UserIam {
namespace UserAuth {
namespace {
constexpr uint32_t TIME_OUT_MS = 3 * 60 * 1000; // 3min
constexpr uint32_t SETUP_CONNECTION_TIME_OUT_MS = 3 * 60 * 1000; // 3min
}
class RemoteAuthContextMessageCallback : public ConnectionListener, public NoCopyable {
public:
@ -132,7 +132,7 @@ bool RemoteAuthContext::OnStart()
IF_FALSE_LOGE_AND_RETURN(sharedThis != nullptr);
OnTimeOut();
},
TIME_OUT_MS);
SETUP_CONNECTION_TIME_OUT_MS);
if (needSetupConnection_) {
IAM_LOGI("%{public}s SetupConnection", GetDescription());

View File

@ -16,17 +16,17 @@
#include "remote_auth_service.h"
#include "iam_check.h"
#include "iam_defines.h"
#include "iam_logger.h"
#include "iam_para2str.h"
#include "iam_ptr.h"
#include "context_factory.h"
#include "context_helper.h"
#include "context_pool.h"
#include "device_manager_util.h"
#include "hdi_wrapper.h"
#include "iam_defines.h"
#include "iam_para2str.h"
#include "iam_ptr.h"
#include "remote_executor_stub.h"
#include "remote_iam_callback.h"
#include "remote_msg_util.h"

View File

@ -15,9 +15,12 @@
#include <map>
#include "iam_common_defines.h"
#include "iam_logger.h"
#include "user_auth_common_defines.h"
#include "widget_json.h"
#define LOG_TAG "USER_AUTH_SA"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
@ -132,42 +135,65 @@ void GetJsonCmd(nlohmann::json &jsonCommand, const WidgetCommand &command)
// utils
AuthType Str2AuthType(const std::string &strAuthType)
{
std::map<std::string, AuthType> authTypeMap;
authTypeMap.emplace(std::make_pair(AUTH_TYPE_ALL, AuthType::ALL));
authTypeMap.emplace(std::make_pair(AUTH_TYPE_PIN, AuthType::PIN));
authTypeMap.emplace(std::make_pair(AUTH_TYPE_FACE, AuthType::FACE));
authTypeMap.emplace(std::make_pair(AUTH_TYPE_FINGER_PRINT, AuthType::FINGERPRINT));
auto result = AuthType::ALL;
if (authTypeMap.find(strAuthType) != authTypeMap.end()) {
result = authTypeMap[strAuthType];
AuthType authType = AuthType::ALL;
if (strAuthType.compare(AUTH_TYPE_ALL) == 0) {
authType = AuthType::ALL;
} else if (strAuthType.compare(AUTH_TYPE_PIN) == 0) {
authType = AuthType::PIN;
} else if (strAuthType.compare(AUTH_TYPE_FACE) == 0) {
authType = AuthType::FACE;
} else if (strAuthType.compare(AUTH_TYPE_FINGER_PRINT) == 0) {
authType = AuthType::FINGERPRINT;
} else {
IAM_LOGE("strAuthType: %{public}s", strAuthType.c_str());
}
return result;
return authType;
}
std::string AuthType2Str(const AuthType &authType)
{
std::map<int32_t, std::string> authTypeMap;
authTypeMap.emplace(std::make_pair(AuthType::ALL, AUTH_TYPE_ALL));
authTypeMap.emplace(std::make_pair(AuthType::PIN, AUTH_TYPE_PIN));
authTypeMap.emplace(std::make_pair(AuthType::FACE, AUTH_TYPE_FACE));
authTypeMap.emplace(std::make_pair(AuthType::FINGERPRINT, AUTH_TYPE_FINGER_PRINT));
std::string result = "";
if (authTypeMap.find(authType) != authTypeMap.end()) {
result = authTypeMap[authType];
std::string strAuthType = "";
switch (authType) {
case AuthType::ALL: {
strAuthType = AUTH_TYPE_ALL;
break;
}
case AuthType::PIN: {
strAuthType = AUTH_TYPE_PIN;
break;
}
case AuthType::FACE: {
strAuthType = AUTH_TYPE_FACE;
break;
}
case AuthType::FINGERPRINT: {
strAuthType = AUTH_TYPE_FINGER_PRINT;
break;
}
default: {
IAM_LOGE("authType: %{public}u", authType);
}
}
return result;
return strAuthType;
}
std::string WinModeType2Str(const WindowModeType &winModeType)
{
std::map<int32_t, std::string> winModeTypeMap;
winModeTypeMap.emplace(std::make_pair(WindowModeType::DIALOG_BOX, WINDOW_MODE_DIALOG));
winModeTypeMap.emplace(std::make_pair(WindowModeType::FULLSCREEN, WINDOW_MODE_FULLSCREEN));
std::string result = "";
if (winModeTypeMap.find(winModeType) != winModeTypeMap.end()) {
result = winModeTypeMap[winModeType];
std::string strWinModeType = "";
switch (winModeType) {
case WindowModeType::DIALOG_BOX: {
strWinModeType = WINDOW_MODE_DIALOG;
break;
}
case WindowModeType::FULLSCREEN: {
strWinModeType = WINDOW_MODE_FULLSCREEN;
break;
}
default: {
IAM_LOGE("winModeType: %{public}u", winModeType);
}
}
return result;
return strWinModeType;
}
std::vector<AuthType> WidgetNotice::AuthTypeList() const
@ -181,19 +207,37 @@ std::vector<AuthType> WidgetNotice::AuthTypeList() const
std::string PinSubType2Str(const PinSubType &subType)
{
std::map<PinSubType, std::string> pinSubTypeMap;
pinSubTypeMap.emplace(std::make_pair(PinSubType::PIN_SIX, PIN_SUB_TYPE_SIX));
pinSubTypeMap.emplace(std::make_pair(PinSubType::PIN_NUMBER, PIN_SUB_TYPE_NUM));
pinSubTypeMap.emplace(std::make_pair(PinSubType::PIN_MIXED, PIN_SUB_TYPE_MIX));
pinSubTypeMap.emplace(std::make_pair(PinSubType::PIN_FOUR, PIN_SUB_TYPE_FOUR));
pinSubTypeMap.emplace(std::make_pair(PinSubType::PIN_PATTERN, PIN_SUB_TYPE_PATTERN));
pinSubTypeMap.emplace(std::make_pair(PinSubType::PIN_MAX, PIN_SUB_TYPE_MAX));
std::string result = "";
if (pinSubTypeMap.find(subType) != pinSubTypeMap.end()) {
result = pinSubTypeMap[subType];
std::string strPinSubType = "";
switch (subType) {
case PinSubType::PIN_SIX: {
strPinSubType = PIN_SUB_TYPE_SIX;
break;
}
case PinSubType::PIN_NUMBER: {
strPinSubType = PIN_SUB_TYPE_NUM;
break;
}
case PinSubType::PIN_MIXED: {
strPinSubType = PIN_SUB_TYPE_MIX;
break;
}
case PinSubType::PIN_FOUR: {
strPinSubType = PIN_SUB_TYPE_FOUR;
break;
}
case PinSubType::PIN_PATTERN: {
strPinSubType = PIN_SUB_TYPE_PATTERN;
break;
}
case PinSubType::PIN_MAX: {
strPinSubType = PIN_SUB_TYPE_MAX;
break;
}
default: {
IAM_LOGE("subType: %{public}u", subType);
}
}
return result;
return strPinSubType;
}
void to_json(nlohmann::json &jsonNotice, const WidgetNotice &notice)

View File

@ -28,7 +28,7 @@ namespace UserAuth {
int32_t ResourceNodeUtils::NotifyExecutorToDeleteTemplates(
const std::vector<std::shared_ptr<CredentialInfoInterface>> &infos, std::string changeReasonTrace)
{
if (infos.size() == 0) {
if (infos.empty()) {
IAM_LOGE("bad infos, infos size is 0");
return INVALID_PARAMETERS;
}

View File

@ -23,7 +23,6 @@
#include "auth_event_listener_manager.h"
#include "auth_widget_helper.h"
#include "context_factory.h"
#include "auth_common.h"
#include "context_helper.h"
#include "hdi_wrapper.h"
#include "iam_check.h"

View File

@ -36,7 +36,7 @@ std::shared_ptr<BaseSocket> SocketFactory::CreateClientSocket(const int32_t sock
}
clientSocket->SetConnectionName(connectionName);
clientSocket->SetNetworkId(connectionName);
clientSocket->SetNetworkId(networkId);
return clientSocket;
}

View File

@ -75,7 +75,7 @@ void SoftBusManager::Start()
{
IAM_LOGD("start.");
std::unique_lock<std::recursive_mutex> lock(mutex_);
if (inited_ == true) {
if (inited_) {
IAM_LOGI("already initialized, skip");
return;
}
@ -96,7 +96,7 @@ void SoftBusManager::Stop()
{
IAM_LOGD("start.");
std::unique_lock<std::recursive_mutex> lock(mutex_);
if (inited_ == false) {
if (!inited_) {
IAM_LOGI("not inited, skip");
return;
}

View File

@ -483,7 +483,6 @@ ohos_source_set("iam_utils_fuzzer") {
]
sources = [
"../../../common/utils/iam_mem.cpp",
"../../../common/utils/iam_time.cpp",
"../../../common/utils/xcollie_helper.cpp",
]