diff --git a/frameworks/common/include/accesstoken_log.h b/frameworks/common/include/accesstoken_log.h index 3a6144b3de478abf73151fe9e5a868276f6a9786..287faccff5a34c4bbd7941708e92287d28fa82ee 100644 --- a/frameworks/common/include/accesstoken_log.h +++ b/frameworks/common/include/accesstoken_log.h @@ -16,91 +16,51 @@ #ifndef ACCESSTOKEN_LOG_H #define ACCESSTOKEN_LOG_H -#ifdef HILOG_ENABLE - #include "hilog/log.h" -/* define LOG_TAG as "security_*" at your submodule, * means your submodule name such as "security_dac" */ -#undef LOG_TAG -#undef LOG_DOMAIN +#define ATM_DOMAIN 0xD005A01 +#define ATM_TAG "ATM" -static constexpr unsigned int SECURITY_DOMAIN_ACCESSTOKEN = 0xD005A01; -static constexpr unsigned int SECURITY_DOMAIN_PRIVACY = 0xD005A02; +#define PRI_DOMAIN 0xD005A02 +#define PRI_TAG "PRIVACY" -#define ACCESSTOKEN_LOG_FATAL(label, fmt, ...) \ - ((void)HILOG_IMPL(label.type, LOG_FATAL, label.domain, label.tag, \ - "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) -#define ACCESSTOKEN_LOG_ERROR(label, fmt, ...) \ - ((void)HILOG_IMPL(label.type, LOG_ERROR, label.domain, label.tag, \ +#define LOGF(domain, tag, fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, domain, tag, \ + "[%{upblic}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) +#define LOGE(domain, tag, fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, domain, tag, \ "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) -#define ACCESSTOKEN_LOG_WARN(label, fmt, ...) \ - ((void)HILOG_IMPL(label.type, LOG_WARN, label.domain, label.tag, \ +#define LOGW(domain, tag, fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, domain, tag, \ "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) -#define ACCESSTOKEN_LOG_INFO(label, fmt, ...) \ - ((void)HILOG_IMPL(label.type, LOG_INFO, label.domain, label.tag, \ +#define LOGI(domain, tag, fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, domain, tag, \ "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) -#define ACCESSTOKEN_LOG_DEBUG(label, fmt, ...) \ - ((void)HILOG_IMPL(label.type, LOG_DEBUG, label.domain, label.tag, \ +#define LOGD(domain, tag, fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, domain, tag, \ "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) -#define IF_FALSE_PRINT_LOG(label, cond, fmt, ...) \ - do { \ - if (!(cond)) { \ - ACCESSTOKEN_LOG_ERROR(label, fmt, ##__VA_ARGS__); \ - } \ - } while (0) - -#define IF_FALSE_RETURN_LOG(label, cond, fmt, ...) \ - do { \ - if (!(cond)) { \ - ACCESSTOKEN_LOG_ERROR(label, fmt, ##__VA_ARGS__); \ - return; \ - } \ - } while (0) - -#define IF_FALSE_RETURN_VALUE_LOG(label, cond, retVal, fmt, ...) \ - do { \ - if (!(cond)) { \ - ACCESSTOKEN_LOG_ERROR(label, fmt, ##__VA_ARGS__); \ - return retVal; \ - } \ - } while (0) -#else - -#include -#include - -/* define LOG_TAG as "security_*" at your submodule, * means your submodule name such as "security_dac" */ -#undef LOG_TAG - -#define ACCESSTOKEN_LOG_DEBUG(fmt, ...) printf("[%s] debug: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) -#define ACCESSTOKEN_LOG_INFO(fmt, ...) printf("[%s] info: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) -#define ACCESSTOKEN_LOG_WARN(fmt, ...) printf("[%s] warn: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) -#define ACCESSTOKEN_LOG_ERROR(fmt, ...) printf("[%s] error: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) -#define ACCESSTOKEN_LOG_FATAL(fmt, ...) printf("[%s] fatal: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) - -#define IF_FALSE_PRINT_LOG(cond, fmt, ...) \ +#define IF_FALSE_PRINT_LOG(domain, tag, cond, fmt, ...) \ do { \ if (!(cond)) { \ - ACCESSTOKEN_LOG_ERROR(fmt, ##__VA_ARGS__); \ + LOGE(domain, tag, fmt, ##__VA_ARGS__); \ } \ } while (0) -#define IF_FALSE_RETURN_LOG(cond, fmt, ...) \ +#define IF_FALSE_RETURN_LOG(domain, tag, cond, fmt, ...) \ do { \ if (!(cond)) { \ - ACCESSTOKEN_LOG_ERROR(fmt, ##__VA_ARGS__); \ + LOGE(domain, tag, fmt, ##__VA_ARGS__); \ return; \ } \ } while (0) -#define IF_FALSE_RETURN_VALUE_LOG(cond, retVal, fmt, ...) \ +#define IF_FALSE_RETURN_VALUE_LOG(domain, tag, cond, ret, fmt, ...) \ do { \ if (!(cond)) { \ - ACCESSTOKEN_LOG_ERROR(fmt, ##__VA_ARGS__); \ - return retVal; \ + LOGE(domain, tag, fmt, ##__VA_ARGS__); \ + return ret; \ } \ } while (0) -#endif // HILOG_ENABLE #endif // ACCESSTOKEN_LOG_H diff --git a/frameworks/common/src/data_validator.cpp b/frameworks/common/src/data_validator.cpp index 7cabba045d234e902fd0f9ee104b0983a587ae6d..57ee8b9677a0d066c907b28f1326738e6fd631b2 100644 --- a/frameworks/common/src/data_validator.cpp +++ b/frameworks/common/src/data_validator.cpp @@ -24,10 +24,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "DataValidator"}; -} // namespace - bool DataValidator::IsBundleNameValid(const std::string& bundleName) { return !bundleName.empty() && (bundleName.length() <= MAX_LENGTH); @@ -46,7 +42,8 @@ bool DataValidator::IsDescValid(const std::string& desc) bool DataValidator::IsPermissionNameValid(const std::string& permissionName) { if (permissionName.empty() || (permissionName.length() > MAX_LENGTH)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid perm length(%{public}d).", static_cast(permissionName.length())); + LOGE(ATM_DOMAIN, ATM_TAG, + "Invalid perm length(%{public}d).", static_cast(permissionName.length())); return false; } return true; @@ -91,7 +88,8 @@ bool DataValidator::IsProcessNameValid(const std::string& processName) bool DataValidator::IsDeviceIdValid(const std::string& deviceId) { if (deviceId.empty() || (deviceId.length() > MAX_LENGTH)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid deviceId length(%{public}d).", static_cast(deviceId.length())); + LOGE(ATM_DOMAIN, ATM_TAG, + "Invalid deviceId length(%{public}d).", static_cast(deviceId.length())); return false; } return true; @@ -118,7 +116,7 @@ bool DataValidator::IsPermissionFlagValid(uint32_t flag) bool DataValidator::IsTokenIDValid(AccessTokenID id) { if (id == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid token."); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid token."); return false; } return true; @@ -142,7 +140,7 @@ bool DataValidator::IsPermissionUsedFlagValid(uint32_t flag) bool DataValidator::IsPermissionUsedTypeValid(uint32_t type) { if ((type != NORMAL_TYPE) && (type != PICKER_TYPE) && (type != SECURITY_COMPONENT_TYPE)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid type(%{public}d).", type); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid type(%{public}d).", type); return false; } return true; @@ -152,7 +150,7 @@ bool DataValidator::IsPolicyTypeValid(uint32_t type) { PolicyType policyType = static_cast(type); if ((policyType != EDM) && (policyType != PRIVACY) && (policyType != TEMPORARY)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid type(%{public}d).", type); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid type(%{public}d).", type); return false; } return true; @@ -162,7 +160,7 @@ bool DataValidator::IsCallerTypeValid(uint32_t type) { CallerType callerType = static_cast(type); if ((callerType != MICROPHONE) && (callerType != CAMERA)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid type(%{public}d).", type); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid type(%{public}d).", type); return false; } return true; @@ -173,7 +171,7 @@ bool DataValidator::IsHapCaller(AccessTokenID id) AccessTokenIDInner *idInner = reinterpret_cast(&id); ATokenTypeEnum type = static_cast(idInner->type); if (type != TOKEN_HAP) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Not hap(%{public}d).", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Not hap(%{public}d).", id); return false; } return true; diff --git a/frameworks/common/src/json_parser.cpp b/frameworks/common/src/json_parser.cpp index 67f60c287019725ed44f28fb83ef318f871b2c7a..c3f45aa050ebd3220b79a0301e62850e7f98812e 100644 --- a/frameworks/common/src/json_parser.cpp +++ b/frameworks/common/src/json_parser.cpp @@ -29,7 +29,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "JsonParser"}; constexpr int MAX_NATIVE_CONFIG_FILE_SIZE = 5 * 1024 * 1024; // 5M constexpr size_t BUFFER_SIZE = 1024; } @@ -78,24 +77,24 @@ int32_t JsonParser::ReadCfgFile(const std::string& file, std::string& rawData) } int32_t fd = open(filePath, O_RDONLY); if (fd < 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Open failed errno %{public}d.", errno); + LOGE(ATM_DOMAIN, ATM_TAG, "Open failed errno %{public}d.", errno); return ERR_FILE_OPERATE_FAILED; } struct stat statBuffer; if (fstat(fd, &statBuffer) != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fstat failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Fstat failed."); close(fd); return ERR_FILE_OPERATE_FAILED; } if (statBuffer.st_size == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Config file size is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Config file size is invalid."); close(fd); return ERR_PARAM_INVALID; } if (statBuffer.st_size > MAX_NATIVE_CONFIG_FILE_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Config file size is too large."); + LOGE(ATM_DOMAIN, ATM_TAG, "Config file size is too large."); close(fd); return ERR_OVERSIZE; } @@ -116,18 +115,18 @@ int32_t JsonParser::ReadCfgFile(const std::string& file, std::string& rawData) bool JsonParser::IsDirExsit(const std::string& file) { if (file.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "File path is empty"); + LOGE(ATM_DOMAIN, ATM_TAG, "File path is empty"); return false; } struct stat buf; if (stat(file.c_str(), &buf) != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get file attributes failed, errno %{public}d.", errno); + LOGE(ATM_DOMAIN, ATM_TAG, "Get file attributes failed, errno %{public}d.", errno); return false; } if (!S_ISDIR(buf.st_mode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "File mode is not directory."); + LOGE(ATM_DOMAIN, ATM_TAG, "File mode is not directory."); return false; } diff --git a/frameworks/js/napi/accesstoken/src/napi_atmanager.cpp b/frameworks/js/napi/accesstoken/src/napi_atmanager.cpp index 57b9795ce3ab90d736549452fbe56bb3007493ae..c95567d3045fb50273ab4e683fc8a908f90bb619 100644 --- a/frameworks/js/napi/accesstoken/src/napi_atmanager.cpp +++ b/frameworks/js/napi/accesstoken/src/napi_atmanager.cpp @@ -31,9 +31,6 @@ std::mutex g_lockCache; std::map g_cache; static PermissionParamCache g_paramCache; namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenAbilityAccessCtrl" -}; static const char* PERMISSION_STATUS_CHANGE_KEY = "accesstoken.permission.change"; static const char* REGISTER_PERMISSION_STATE_CHANGE_TYPE = "permissionStateChange"; static const char* REGISTER_SELF_PERMISSION_STATE_CHANGE_TYPE = "selfPermissionStateChange"; @@ -92,7 +89,7 @@ static void NotifyPermStateChanged(RegisterPermStateChangeWorker* registerPermSt napi_create_object(registerPermStateChangeData->env, &result)); if (!ConvertPermStateChangeInfo(registerPermStateChangeData->env, result, registerPermStateChangeData->result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ConvertPermStateChangeInfo failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "ConvertPermStateChangeInfo failed"); return; } @@ -110,7 +107,7 @@ static void NotifyPermStateChanged(RegisterPermStateChangeWorker* registerPermSt static void UvQueueWorkPermStateChanged(uv_work_t* work, int status) { if (work == nullptr || work->data == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Work == nullptr || work->data == nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Work == nullptr || work->data == nullptr"); return; } std::unique_ptr uvWorkPtr {work}; @@ -121,17 +118,17 @@ static void UvQueueWorkPermStateChanged(uv_work_t* work, int status) napi_handle_scope scope = nullptr; napi_open_handle_scope(registerPermStateChangeData->env, &scope); if (scope == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to open scope"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to open scope"); return; } NotifyPermStateChanged(registerPermStateChangeData); napi_close_handle_scope(registerPermStateChangeData->env, scope); - ACCESSTOKEN_LOG_DEBUG(LABEL, "UvQueueWorkPermStateChanged end"); + LOGD(ATM_DOMAIN, ATM_TAG, "UvQueueWorkPermStateChanged end"); }; static bool IsPermissionFlagValid(uint32_t flag) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Permission flag is %{public}d", flag); + LOGD(ATM_DOMAIN, ATM_TAG, "Permission flag is %{public}d", flag); return (flag == PermissionFlag::PERMISSION_USER_SET) || (flag == PermissionFlag::PERMISSION_USER_FIXED) || (flag == PermissionFlag::PERMISSION_ALLOW_THIS_TIME); }; @@ -153,32 +150,32 @@ void RegisterPermStateChangeScopePtr::PermStateChangeCallback(PermStateChangeInf { std::lock_guard lock(validMutex_); if (!valid_) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Object is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Object is invalid."); return; } uv_loop_s* loop = nullptr; NAPI_CALL_RETURN_VOID(env_, napi_get_uv_event_loop(env_, &loop)); if (loop == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Loop instance is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Loop instance is nullptr"); return; } uv_work_t* work = new (std::nothrow) uv_work_t; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for work!"); return; } std::unique_ptr uvWorkPtr {work}; RegisterPermStateChangeWorker* registerPermStateChangeWorker = new (std::nothrow) RegisterPermStateChangeWorker(); if (registerPermStateChangeWorker == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for RegisterPermStateChangeWorker!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for RegisterPermStateChangeWorker!"); return; } std::unique_ptr workPtr {registerPermStateChangeWorker}; registerPermStateChangeWorker->env = env_; registerPermStateChangeWorker->ref = ref_; registerPermStateChangeWorker->result = result; - ACCESSTOKEN_LOG_DEBUG(LABEL, + LOGD(ATM_DOMAIN, ATM_TAG, "result permStateChangeType = %{public}d, tokenID = %{public}d, permissionName = %{public}s", result.permStateChangeType, result.tokenID, result.permissionName.c_str()); registerPermStateChangeWorker->subscriber = shared_from_this(); @@ -211,10 +208,10 @@ PermStateChangeContext::~PermStateChangeContext() void UvQueueWorkDeleteRef(uv_work_t *work, int32_t status) { if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Work == nullptr : %{public}d", work == nullptr); + LOGE(ATM_DOMAIN, ATM_TAG, "Work == nullptr : %{public}d", work == nullptr); return; } else if (work->data == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Work->data == nullptr : %{public}d", work->data == nullptr); + LOGE(ATM_DOMAIN, ATM_TAG, "Work->data == nullptr : %{public}d", work->data == nullptr); return; } RegisterPermStateChangeWorker* registerPermStateChangeWorker = @@ -227,7 +224,7 @@ void UvQueueWorkDeleteRef(uv_work_t *work, int32_t status) delete registerPermStateChangeWorker; registerPermStateChangeWorker = nullptr; delete work; - ACCESSTOKEN_LOG_DEBUG(LABEL, "UvQueueWorkDeleteRef end"); + LOGD(ATM_DOMAIN, ATM_TAG, "UvQueueWorkDeleteRef end"); } void RegisterPermStateChangeScopePtr::DeleteNapiRef() @@ -235,12 +232,12 @@ void RegisterPermStateChangeScopePtr::DeleteNapiRef() uv_loop_s* loop = nullptr; NAPI_CALL_RETURN_VOID(env_, napi_get_uv_event_loop(env_, &loop)); if (loop == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Loop instance is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Loop instance is nullptr"); return; } uv_work_t* work = new (std::nothrow) uv_work_t; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for work!"); return; } @@ -248,7 +245,7 @@ void RegisterPermStateChangeScopePtr::DeleteNapiRef() RegisterPermStateChangeWorker* registerPermStateChangeWorker = new (std::nothrow) RegisterPermStateChangeWorker(); if (registerPermStateChangeWorker == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for RegisterPermStateChangeWorker!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for RegisterPermStateChangeWorker!"); return; } std::unique_ptr workPtr {registerPermStateChangeWorker}; @@ -258,7 +255,7 @@ void RegisterPermStateChangeScopePtr::DeleteNapiRef() work->data = reinterpret_cast(registerPermStateChangeWorker); NAPI_CALL_RETURN_VOID(env_, uv_queue_work_with_qos(loop, work, [](uv_work_t* work) {}, UvQueueWorkDeleteRef, uv_qos_default)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "DeleteNapiRef"); + LOGD(ATM_DOMAIN, ATM_TAG, "DeleteNapiRef"); uvWorkPtr.release(); workPtr.release(); } @@ -272,7 +269,7 @@ void NapiAtManager::SetNamedProperty(napi_env env, napi_value dstObj, const int3 napi_value NapiAtManager::Init(napi_env env, napi_value exports) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Enter init."); + LOGD(ATM_DOMAIN, ATM_TAG, "Enter init."); napi_property_descriptor descriptor[] = { DECLARE_NAPI_FUNCTION("createAtManager", CreateAtManager) }; @@ -353,7 +350,7 @@ void NapiAtManager::CreateObjects(napi_env env, napi_value exports) napi_value NapiAtManager::JsConstructor(napi_env env, napi_callback_info cbinfo) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Enter JsConstructor"); + LOGD(ATM_DOMAIN, ATM_TAG, "Enter JsConstructor"); napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, cbinfo, nullptr, nullptr, &thisVar, nullptr)); @@ -362,17 +359,17 @@ napi_value NapiAtManager::JsConstructor(napi_env env, napi_callback_info cbinfo) napi_value NapiAtManager::CreateAtManager(napi_env env, napi_callback_info cbInfo) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Enter CreateAtManager"); + LOGD(ATM_DOMAIN, ATM_TAG, "Enter CreateAtManager"); napi_value instance = nullptr; napi_value cons = nullptr; NAPI_CALL(env, napi_get_reference_value(env, g_atManagerRef_, &cons)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Get a reference to the global variable g_atManagerRef_ complete"); + LOGD(ATM_DOMAIN, ATM_TAG, "Get a reference to the global variable g_atManagerRef_ complete"); NAPI_CALL(env, napi_new_instance(env, cons, 0, nullptr, &instance)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "New the js instance complete"); + LOGD(ATM_DOMAIN, ATM_TAG, "New the js instance complete"); return instance; } @@ -409,7 +406,7 @@ bool NapiAtManager::ParseInputVerifyPermissionOrGetFlag(const napi_env env, cons return false; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID = %{public}d, permissionName = %{public}s", asyncContext.tokenId, + LOGD(ATM_DOMAIN, ATM_TAG, "TokenID = %{public}d, permissionName = %{public}s", asyncContext.tokenId, asyncContext.permissionName.c_str()); return true; } @@ -429,7 +426,8 @@ void NapiAtManager::VerifyAccessTokenComplete(napi_env env, napi_status status, std::unique_ptr context {asyncContext}; napi_value result; - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenId = %{public}d, permissionName = %{public}s, verify result = %{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, + "TokenId = %{public}d, permissionName = %{public}s, verify result = %{public}d.", asyncContext->tokenId, asyncContext->permissionName.c_str(), asyncContext->result); NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, asyncContext->result, &result)); // verify result @@ -438,11 +436,11 @@ void NapiAtManager::VerifyAccessTokenComplete(napi_env env, napi_status status, napi_value NapiAtManager::VerifyAccessToken(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "VerifyAccessToken begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "VerifyAccessToken begin."); auto* asyncContext = new (std::nothrow) AtManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "New struct failed."); return nullptr; } @@ -463,7 +461,7 @@ napi_value NapiAtManager::VerifyAccessToken(napi_env env, napi_callback_info inf reinterpret_cast(asyncContext), &(asyncContext->work))); NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_default)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "VerifyAccessToken end."); + LOGD(ATM_DOMAIN, ATM_TAG, "VerifyAccessToken end."); context.release(); return result; } @@ -504,11 +502,11 @@ void NapiAtManager::CheckAccessTokenComplete(napi_env env, napi_status status, v napi_value NapiAtManager::CheckAccessToken(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "CheckAccessToken begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "CheckAccessToken begin."); auto* asyncContext = new (std::nothrow) AtManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(ATM_DOMAIN, ATM_TAG, "New struct fail."); return nullptr; } @@ -529,7 +527,7 @@ napi_value NapiAtManager::CheckAccessToken(napi_env env, napi_callback_info info reinterpret_cast(asyncContext), &(asyncContext->work))); NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_default)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "CheckAccessToken end."); + LOGD(ATM_DOMAIN, ATM_TAG, "CheckAccessToken end."); context.release(); return result; } @@ -538,14 +536,14 @@ std::string NapiAtManager::GetPermParamValue() { long long sysCommitId = GetSystemCommitId(); if (sysCommitId == g_paramCache.sysCommitIdCache) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "SysCommitId = %{public}lld", sysCommitId); + LOGD(ATM_DOMAIN, ATM_TAG, "SysCommitId = %{public}lld", sysCommitId); return g_paramCache.sysParamCache; } g_paramCache.sysCommitIdCache = sysCommitId; if (g_paramCache.handle == PARAM_DEFAULT_VALUE) { int32_t handle = static_cast(FindParameter(PERMISSION_STATUS_CHANGE_KEY)); if (handle == PARAM_DEFAULT_VALUE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "FindParameter failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "FindParameter failed"); return "-1"; } g_paramCache.handle = handle; @@ -556,7 +554,7 @@ std::string NapiAtManager::GetPermParamValue() char value[NapiContextCommon::VALUE_MAX_LEN] = {0}; auto ret = GetParameterValue(g_paramCache.handle, value, NapiContextCommon::VALUE_MAX_LEN - 1); if (ret < 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Return default value, ret=%{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Return default value, ret=%{public}d", ret); return "-1"; } std::string resStr(value); @@ -577,7 +575,7 @@ void NapiAtManager::UpdatePermissionCache(AtManagerAsyncContext* asyncContext) asyncContext->tokenId, asyncContext->permissionName); iter->second.status = asyncContext->result; iter->second.paramValue = currPara; - ACCESSTOKEN_LOG_DEBUG(LABEL, "Param changed currPara %{public}s", currPara.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "Param changed currPara %{public}s", currPara.c_str()); } else { asyncContext->result = iter->second.status; } @@ -585,7 +583,7 @@ void NapiAtManager::UpdatePermissionCache(AtManagerAsyncContext* asyncContext) asyncContext->result = AccessTokenKit::VerifyAccessToken(asyncContext->tokenId, asyncContext->permissionName); g_cache[asyncContext->permissionName].status = asyncContext->result; g_cache[asyncContext->permissionName].paramValue = GetPermParamValue(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "G_cacheParam set %{public}s", + LOGD(ATM_DOMAIN, ATM_TAG, "G_cacheParam set %{public}s", g_cache[asyncContext->permissionName].paramValue.c_str()); } } @@ -595,7 +593,7 @@ napi_value NapiAtManager::VerifyAccessTokenSync(napi_env env, napi_callback_info static uint64_t selfTokenId = GetSelfTokenID(); auto* asyncContext = new (std::nothrow) AtManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(ATM_DOMAIN, ATM_TAG, "New struct fail."); return nullptr; } @@ -618,7 +616,7 @@ napi_value NapiAtManager::VerifyAccessTokenSync(napi_env env, napi_callback_info asyncContext->result = AccessTokenKit::VerifyAccessToken(asyncContext->tokenId, asyncContext->permissionName); napi_value result = nullptr; NAPI_CALL(env, napi_create_int32(env, asyncContext->result, &result)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "VerifyAccessTokenSync end."); + LOGD(ATM_DOMAIN, ATM_TAG, "VerifyAccessTokenSync end."); return result; } @@ -678,7 +676,7 @@ bool NapiAtManager::ParseInputGrantOrRevokePermission(const napi_env env, const } } - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID = %{public}d, permissionName = %{public}s, flag = %{public}d", + LOGD(ATM_DOMAIN, ATM_TAG, "TokenID = %{public}d, permissionName = %{public}s, flag = %{public}d", asyncContext.tokenId, asyncContext.permissionName.c_str(), asyncContext.flag); return true; } @@ -704,7 +702,7 @@ void NapiAtManager::GrantUserGrantedPermissionExecute(napi_env env, void *data) return; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermissionName = %{public}s, grantmode = %{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "PermissionName = %{public}s, grantmode = %{public}d.", asyncContext->permissionName.c_str(), permissionDef.grantMode); if (!IsPermissionFlagValid(asyncContext->flag)) { @@ -717,7 +715,7 @@ void NapiAtManager::GrantUserGrantedPermissionExecute(napi_env env, void *data) } else { asyncContext->result = ERR_PERMISSION_NOT_EXIST; } - ACCESSTOKEN_LOG_DEBUG(LABEL, + LOGD(ATM_DOMAIN, ATM_TAG, "tokenId = %{public}d, permissionName = %{public}s, flag = %{public}d, grant result = %{public}d.", asyncContext->tokenId, asyncContext->permissionName.c_str(), asyncContext->flag, asyncContext->result); } @@ -737,11 +735,11 @@ void NapiAtManager::GrantUserGrantedPermissionComplete(napi_env env, napi_status napi_value NapiAtManager::GetVersion(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetVersion begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "GetVersion begin."); auto* asyncContext = new (std::nothrow) AtManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(ATM_DOMAIN, ATM_TAG, "New struct fail."); return nullptr; } std::unique_ptr context {asyncContext}; @@ -757,7 +755,7 @@ napi_value NapiAtManager::GetVersion(napi_env env, napi_callback_info info) NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_default)); context.release(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetVersion end."); + LOGD(ATM_DOMAIN, ATM_TAG, "GetVersion end."); return result; } @@ -774,7 +772,7 @@ void NapiAtManager::GetVersionExecute(napi_env env, void *data) return; } asyncContext->result = static_cast(version); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Version result = %{public}d.", asyncContext->result); + LOGD(ATM_DOMAIN, ATM_TAG, "Version result = %{public}d.", asyncContext->result); } void NapiAtManager::GetVersionComplete(napi_env env, napi_status status, void *data) @@ -782,7 +780,7 @@ void NapiAtManager::GetVersionComplete(napi_env env, napi_status status, void *d AtManagerAsyncContext* asyncContext = reinterpret_cast(data); std::unique_ptr context {asyncContext}; napi_value result = nullptr; - ACCESSTOKEN_LOG_DEBUG(LABEL, "Version result = %{public}d.", asyncContext->result); + LOGD(ATM_DOMAIN, ATM_TAG, "Version result = %{public}d.", asyncContext->result); NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, asyncContext->result, &result)); ReturnPromiseResult(env, asyncContext->errorCode, asyncContext->deferred, result); @@ -790,11 +788,11 @@ void NapiAtManager::GetVersionComplete(napi_env env, napi_status status, void *d napi_value NapiAtManager::GrantUserGrantedPermission(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GrantUserGrantedPermission begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "GrantUserGrantedPermission begin."); auto* context = new (std::nothrow) AtManagerAsyncContext(env); // for async work deliver data if (context == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(ATM_DOMAIN, ATM_TAG, "New struct fail."); return nullptr; } @@ -821,7 +819,7 @@ napi_value NapiAtManager::GrantUserGrantedPermission(napi_env env, napi_callback NAPI_CALL(env, napi_queue_async_work_with_qos(env, context->work, napi_qos_default)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "GrantUserGrantedPermission end."); + LOGD(ATM_DOMAIN, ATM_TAG, "GrantUserGrantedPermission end."); contextPtr.release(); return result; } @@ -847,7 +845,7 @@ void NapiAtManager::RevokeUserGrantedPermissionExecute(napi_env env, void *data) return; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermissionName = %{public}s, grantmode = %{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "PermissionName = %{public}s, grantmode = %{public}d.", asyncContext->permissionName.c_str(), permissionDef.grantMode); if (!IsPermissionFlagValid(asyncContext->flag)) { @@ -860,7 +858,7 @@ void NapiAtManager::RevokeUserGrantedPermissionExecute(napi_env env, void *data) } else { asyncContext->result = ERR_PERMISSION_NOT_EXIST; } - ACCESSTOKEN_LOG_DEBUG(LABEL, + LOGD(ATM_DOMAIN, ATM_TAG, "tokenId = %{public}d, permissionName = %{public}s, flag = %{public}d, revoke result = %{public}d.", asyncContext->tokenId, asyncContext->permissionName.c_str(), asyncContext->flag, asyncContext->result); } @@ -880,11 +878,11 @@ void NapiAtManager::RevokeUserGrantedPermissionComplete(napi_env env, napi_statu napi_value NapiAtManager::RevokeUserGrantedPermission(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "RevokeUserGrantedPermission begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "RevokeUserGrantedPermission begin."); auto* asyncContext = new (std::nothrow) AtManagerAsyncContext(env); // for async work deliver data if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(ATM_DOMAIN, ATM_TAG, "New struct fail."); return nullptr; } @@ -909,7 +907,7 @@ napi_value NapiAtManager::RevokeUserGrantedPermission(napi_env env, napi_callbac reinterpret_cast(asyncContext), &(asyncContext->work))); NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_default)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "RevokeUserGrantedPermission end."); + LOGD(ATM_DOMAIN, ATM_TAG, "RevokeUserGrantedPermission end."); context.release(); return result; } @@ -935,11 +933,11 @@ void NapiAtManager::GetPermissionFlagsComplete(napi_env env, napi_status status, napi_value NapiAtManager::GetPermissionFlags(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionFlags begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "GetPermissionFlags begin."); auto* asyncContext = new (std::nothrow) AtManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(ATM_DOMAIN, ATM_TAG, "New struct fail."); return nullptr; } @@ -960,7 +958,7 @@ napi_value NapiAtManager::GetPermissionFlags(napi_env env, napi_callback_info in // add async work handle to the napi queue and wait for result napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_default); - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionFlags end."); + LOGD(ATM_DOMAIN, ATM_TAG, "GetPermissionFlags end."); context.release(); return result; } @@ -1067,11 +1065,11 @@ void NapiAtManager::GetPermissionRequestToggleStatusComplete(napi_env env, napi_ napi_value NapiAtManager::SetPermissionRequestToggleStatus(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "SetPermissionRequestToggleStatus begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "SetPermissionRequestToggleStatus begin."); auto* asyncContext = new (std::nothrow) AtManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New asyncContext failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "New asyncContext failed."); return nullptr; } @@ -1092,18 +1090,18 @@ napi_value NapiAtManager::SetPermissionRequestToggleStatus(napi_env env, napi_ca // add async work handle to the napi queue and wait for result NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_default)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "SetPermissionRequestToggleStatus end."); + LOGD(ATM_DOMAIN, ATM_TAG, "SetPermissionRequestToggleStatus end."); context.release(); return result; } napi_value NapiAtManager::GetPermissionRequestToggleStatus(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionRequestToggleStatus begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "GetPermissionRequestToggleStatus begin."); auto* asyncContext = new (std::nothrow) AtManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New asyncContext failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "New asyncContext failed."); return nullptr; } @@ -1124,7 +1122,7 @@ napi_value NapiAtManager::GetPermissionRequestToggleStatus(napi_env env, napi_ca // add async work handle to the napi queue and wait for result NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_default)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionRequestToggleStatus end."); + LOGD(ATM_DOMAIN, ATM_TAG, "GetPermissionRequestToggleStatus end."); context.release(); return result; } @@ -1203,9 +1201,11 @@ bool NapiAtManager::FillPermStateChangeInfo(const napi_env env, const napi_value new (std::nothrow) std::shared_ptr( registerPermStateChangeInfo.subscriber); if (subscriber == nullptr) { + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create subscriber"); return false; } napi_wrap(env, thisVar, reinterpret_cast(subscriber), [](napi_env nev, void *data, void *hint) { + LOGD(ATM_DOMAIN, ATM_TAG, "RegisterPermStateChangeScopePtr delete"); std::shared_ptr* subscriber = static_cast*>(data); if (subscriber != nullptr && *subscriber != nullptr) { @@ -1225,13 +1225,13 @@ bool NapiAtManager::ParseInputToRegister(const napi_env env, const napi_callback napi_value thisVar = nullptr; NAPI_CALL_BASE(env, napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, nullptr), false); if (thisVar == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ThisVar is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "ThisVar is nullptr"); return false; } napi_valuetype valueTypeOfThis = napi_undefined; NAPI_CALL_BASE(env, napi_typeof(env, thisVar, &valueTypeOfThis), false); if (valueTypeOfThis == napi_undefined) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ThisVar is undefined"); + LOGE(ATM_DOMAIN, ATM_TAG, "ThisVar is undefined"); return false; } std::string type; @@ -1260,7 +1260,7 @@ napi_value NapiAtManager::RegisterPermStateChangeCallback(napi_env env, napi_cal RegisterPermStateChangeInfo* registerPermStateChangeInfo = new (std::nothrow) RegisterPermStateChangeInfo(); if (registerPermStateChangeInfo == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for subscribeCBInfo!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for subscribeCBInfo!"); return nullptr; } std::unique_ptr callbackPtr {registerPermStateChangeInfo}; @@ -1268,7 +1268,7 @@ napi_value NapiAtManager::RegisterPermStateChangeCallback(napi_env env, napi_cal return nullptr; } if (IsExistRegister(env, registerPermStateChangeInfo)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Subscribe failed. The current subscriber has been existed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Subscribe failed. The current subscriber has been existed"); std::string errMsg = GetErrorMessage(JsErrorCode::JS_ERROR_PARAM_INVALID); NAPI_CALL(env, napi_throw(env, GenerateBusinessError(env, JsErrorCode::JS_ERROR_PARAM_INVALID, errMsg))); return nullptr; @@ -1280,7 +1280,7 @@ napi_value NapiAtManager::RegisterPermStateChangeCallback(napi_env env, napi_cal result = AccessTokenKit::RegisterSelfPermStateChangeCallback(registerPermStateChangeInfo->subscriber); } if (result != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RegisterPermStateChangeCallback failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "RegisterPermStateChangeCallback failed"); registerPermStateChangeInfo->errCode = result; int32_t jsCode = NapiContextCommon::GetJsErrorCode(result); std::string errMsg = GetErrorMessage(jsCode); @@ -1290,7 +1290,7 @@ napi_value NapiAtManager::RegisterPermStateChangeCallback(napi_env env, napi_cal { std::lock_guard lock(g_lockForPermStateChangeRegisters); g_permStateChangeRegisters.emplace_back(registerPermStateChangeInfo); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Add g_PermStateChangeRegisters.size = %{public}zu", + LOGD(ATM_DOMAIN, ATM_TAG, "Add g_PermStateChangeRegisters.size = %{public}zu", g_permStateChangeRegisters.size()); } callbackPtr.release(); @@ -1306,7 +1306,7 @@ bool NapiAtManager::ParseInputToUnregister(const napi_env env, napi_callback_inf napi_ref callback = nullptr; std::string errMsg; if (napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, nullptr) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Napi_get_cb_info failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Napi_get_cb_info failed"); return false; } // 1: off required minnum argc @@ -1355,7 +1355,7 @@ napi_value NapiAtManager::UnregisterPermStateChangeCallback(napi_env env, napi_c UnregisterPermStateChangeInfo* unregisterPermStateChangeInfo = new (std::nothrow) UnregisterPermStateChangeInfo(); if (unregisterPermStateChangeInfo == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for subscribeCBInfo!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for subscribeCBInfo!"); return nullptr; } std::unique_ptr callbackPtr {unregisterPermStateChangeInfo}; @@ -1364,7 +1364,7 @@ napi_value NapiAtManager::UnregisterPermStateChangeCallback(napi_env env, napi_c } std::vector batchPermStateChangeRegisters; if (!FindAndGetSubscriberInVector(unregisterPermStateChangeInfo, batchPermStateChangeRegisters, env)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Unsubscribe failed. The current subscriber does not exist"); + LOGE(ATM_DOMAIN, ATM_TAG, "Unsubscribe failed. The current subscriber does not exist"); std::string errMsg = GetErrorMessage(JsErrorCode::JS_ERROR_PARAM_INVALID); NAPI_CALL(env, napi_throw(env, GenerateBusinessError(env, JsErrorCode::JS_ERROR_PARAM_INVALID, errMsg))); @@ -1382,7 +1382,7 @@ napi_value NapiAtManager::UnregisterPermStateChangeCallback(napi_env env, napi_c if (result == RET_SUCCESS) { DeleteRegisterFromVector(scopeInfo, env, item->callbackRef); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Batch UnregisterPermActiveChangeCompleted failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Batch UnregisterPermActiveChangeCompleted failed"); int32_t jsCode = NapiContextCommon::GetJsErrorCode(result); std::string errMsg = GetErrorMessage(jsCode); NAPI_CALL(env, napi_throw(env, GenerateBusinessError(env, jsCode, errMsg))); @@ -1412,7 +1412,7 @@ bool NapiAtManager::FindAndGetSubscriberInVector(UnregisterPermStateChangeInfo* PermStateChangeScope scopeInfo; item->subscriber->GetScope(scopeInfo); if (scopeInfo.tokenIDs == targetTokenIDs && scopeInfo.permList == targetPermList) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Find subscriber in map"); + LOGD(ATM_DOMAIN, ATM_TAG, "Find subscriber in map"); unregisterPermStateChangeInfo->subscriber = item->subscriber; batchPermStateChangeRegisters.emplace_back(item); } @@ -1472,7 +1472,7 @@ bool NapiAtManager::IsExistRegister(const napi_env env, const RegisterPermStateC return true; } } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Cannot find subscriber in vector"); + LOGD(ATM_DOMAIN, ATM_TAG, "Cannot find subscriber in vector"); return false; } @@ -1488,7 +1488,7 @@ void NapiAtManager::DeleteRegisterFromVector(const PermStateChangeScope& scopeIn (*item)->subscriber->GetScope(stateChangeScope); if ((stateChangeScope.tokenIDs == targetTokenIDs) && (stateChangeScope.permList == targetPermList) && CompareCallbackRef(env, (*item)->callbackRef, subscriberRef, (*item)->threadId_)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Find subscribers in vector, delete"); + LOGD(ATM_DOMAIN, ATM_TAG, "Find subscribers in vector, delete"); delete *item; *item = nullptr; g_permStateChangeRegisters.erase(item); @@ -1508,7 +1508,7 @@ EXTERN_C_START */ static napi_value Init(napi_env env, napi_value exports) { - ACCESSTOKEN_LOG_DEBUG(OHOS::Security::AccessToken::LABEL, "Register end, start init."); + LOGD(ATM_DOMAIN, ATM_TAG, "Register end, start init."); OHOS::Security::AccessToken::NapiAtManager::Init(env, exports); return exports; } diff --git a/frameworks/js/napi/accesstoken/src/napi_context_common.cpp b/frameworks/js/napi/accesstoken/src/napi_context_common.cpp index b5f7dd089f81528e5855efda0747251274b14b39..7f16e753c4e1cc6ccd67aa90c95c9a3297d58a00 100644 --- a/frameworks/js/napi/accesstoken/src/napi_context_common.cpp +++ b/frameworks/js/napi/accesstoken/src/napi_context_common.cpp @@ -17,12 +17,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AtManagerAsyncWorkData" -}; -} - int32_t NapiContextCommon::GetJsErrorCode(int32_t errCode) { int32_t jsCode; @@ -68,7 +62,8 @@ int32_t NapiContextCommon::GetJsErrorCode(int32_t errCode) jsCode = JS_ERROR_INNER; break; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetJsErrorCode nativeCode(%{public}d) jsCode(%{public}d).", errCode, jsCode); + LOGD(ATM_DOMAIN, ATM_TAG, + "GetJsErrorCode nativeCode(%{public}d) jsCode(%{public}d).", errCode, jsCode); return jsCode; } @@ -80,7 +75,7 @@ AtManagerAsyncWorkData::AtManagerAsyncWorkData(napi_env envValue) AtManagerAsyncWorkData::~AtManagerAsyncWorkData() { if (env == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid env"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid env"); return; } std::unique_ptr workPtr = std::make_unique(); @@ -88,7 +83,7 @@ AtManagerAsyncWorkData::~AtManagerAsyncWorkData() uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env, &loop); if ((loop == nullptr) || (workPtr == nullptr) || (workDataRel == nullptr)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to init execution environment"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to init execution environment"); return; } workDataRel->env = env; @@ -98,12 +93,12 @@ AtManagerAsyncWorkData::~AtManagerAsyncWorkData() NAPI_CALL_RETURN_VOID(env, uv_queue_work_with_qos(loop, workPtr.get(), [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Work is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Work is nullptr"); return; } auto workDataRel = reinterpret_cast(work->data); if (workDataRel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WorkDataRel is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "WorkDataRel is nullptr"); delete work; return; } diff --git a/frameworks/js/napi/accesstoken/src/napi_request_global_switch_on_setting.cpp b/frameworks/js/napi/accesstoken/src/napi_request_global_switch_on_setting.cpp index 21aa58ac586e7529e7e4afd5048e37cc9ed34e54..8571cf8efb2b280922eab72e4b75d3f04db7f839 100644 --- a/frameworks/js/napi/accesstoken/src/napi_request_global_switch_on_setting.cpp +++ b/frameworks/js/napi/accesstoken/src/napi_request_global_switch_on_setting.cpp @@ -25,9 +25,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "NapiRequestGlobalSwitch" -}; const std::string GLOBAL_SWITCH_KEY = "ohos.user.setting.global_switch"; const std::string GLOBAL_SWITCH_RESULT_KEY = "ohos.user.setting.global_switch.result"; const std::string RESULT_ERROR_KEY = "ohos.user.setting.error_code"; @@ -77,12 +74,12 @@ static napi_value GetContext( bool stageMode = false; napi_status status = OHOS::AbilityRuntime::IsStageContext(env, value, stageMode); if (status != napi_ok || !stageMode) { - ACCESSTOKEN_LOG_ERROR(LABEL, "It is not a stage mode."); + LOGE(ATM_DOMAIN, ATM_TAG, "It is not a stage mode."); return nullptr; } else { auto context = AbilityRuntime::GetStageModeContext(env, value); if (context == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to Get application context."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Get application context."); return nullptr; } asyncContext->abilityContext = @@ -90,11 +87,11 @@ static napi_value GetContext( if (asyncContext->abilityContext != nullptr) { asyncContext->uiAbilityFlag = true; } else { - ACCESSTOKEN_LOG_WARN(LABEL, "Failed to convert to ability context."); + LOGW(ATM_DOMAIN, ATM_TAG, "Failed to convert to ability context."); asyncContext->uiExtensionContext = AbilityRuntime::Context::ConvertTo(context); if (asyncContext->uiExtensionContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to convert to ui extension context."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to convert to ui extension context."); return nullptr; } } @@ -123,7 +120,7 @@ static int32_t TransferToJsErrorCode(int32_t errCode) jsCode = JS_ERROR_INNER; break; } - ACCESSTOKEN_LOG_INFO(LABEL, "dialog error(%{public}d) jsCode(%{public}d).", errCode, jsCode); + LOGI(ATM_DOMAIN, ATM_TAG, "dialog error(%{public}d) jsCode(%{public}d).", errCode, jsCode); return jsCode; } @@ -131,13 +128,13 @@ static void ResultCallbackJSThreadWorker(uv_work_t* work, int32_t status) { (void)status; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Uv_queue_work_with_qos input work is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Uv_queue_work_with_qos input work is nullptr"); return; } std::unique_ptr uvWorkPtr {work}; SwitchOnSettingResultCallback *retCB = reinterpret_cast(work->data); if (retCB == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RetCB is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "RetCB is nullptr"); return; } std::unique_ptr callbackPtr {retCB}; @@ -149,7 +146,7 @@ static void ResultCallbackJSThreadWorker(uv_work_t* work, int32_t status) napi_handle_scope scope = nullptr; napi_open_handle_scope(asyncContext->env, &scope); if (scope == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Napi_open_handle_scope failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Napi_open_handle_scope failed"); return; } napi_value requestResult = nullptr; @@ -164,7 +161,7 @@ static void GlobalSwitchResultsCallbackUI(int32_t jsCode, { auto* retCB = new (std::nothrow) SwitchOnSettingResultCallback(); if (retCB == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for work!"); return; } @@ -176,12 +173,12 @@ static void GlobalSwitchResultsCallbackUI(int32_t jsCode, uv_loop_s* loop = nullptr; NAPI_CALL_RETURN_VOID(data->env, napi_get_uv_event_loop(data->env, &loop)); if (loop == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Loop instance is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Loop instance is nullptr"); return; } uv_work_t* work = new (std::nothrow) uv_work_t; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for work!"); return; } std::unique_ptr uvWorkPtr {work}; @@ -198,17 +195,17 @@ void SwitchOnSettingUICallback::ReleaseHandler(int32_t code) { std::lock_guard lock(g_lockFlag); if (this->reqContext_->releaseFlag) { - ACCESSTOKEN_LOG_WARN(LABEL, "Callback has executed."); + LOGW(ATM_DOMAIN, ATM_TAG, "Callback has executed."); return; } this->reqContext_->releaseFlag = true; } Ace::UIContent* uiContent = GetUIContent(this->reqContext_); if (uiContent == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get ui content failed!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get ui content failed!"); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "Close uiextension component"); + LOGI(ATM_DOMAIN, ATM_TAG, "Close uiextension component"); uiContent->CloseModalUIExtension(this->sessionId_); if (code == -1) { this->reqContext_->errorCode = code; @@ -238,7 +235,7 @@ void SwitchOnSettingUICallback::OnResult(int32_t resultCode, const AAFwk::Want& { this->reqContext_->errorCode = result.GetIntParam(RESULT_ERROR_KEY, 0); this->reqContext_->switchStatus = result.GetBoolParam(GLOBAL_SWITCH_RESULT_KEY, 0); - ACCESSTOKEN_LOG_INFO(LABEL, "ResultCode is %{public}d, errorCode=%{public}d, switchStatus=%{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "ResultCode is %{public}d, errorCode=%{public}d, switchStatus=%{public}d", resultCode, this->reqContext_->errorCode, this->reqContext_->switchStatus); ReleaseHandler(0); } @@ -248,7 +245,7 @@ void SwitchOnSettingUICallback::OnResult(int32_t resultCode, const AAFwk::Want& */ void SwitchOnSettingUICallback::OnReceive(const AAFwk::WantParams& receive) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called!"); } /* @@ -257,7 +254,7 @@ void SwitchOnSettingUICallback::OnReceive(const AAFwk::WantParams& receive) */ void SwitchOnSettingUICallback::OnRelease(int32_t releaseCode) { - ACCESSTOKEN_LOG_INFO(LABEL, "ReleaseCode is %{public}d", releaseCode); + LOGI(ATM_DOMAIN, ATM_TAG, "ReleaseCode is %{public}d", releaseCode); ReleaseHandler(-1); } @@ -267,7 +264,7 @@ void SwitchOnSettingUICallback::OnRelease(int32_t releaseCode) */ void SwitchOnSettingUICallback::OnError(int32_t code, const std::string& name, const std::string& message) { - ACCESSTOKEN_LOG_INFO(LABEL, "Code is %{public}d, name is %{public}s, message is %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "Code is %{public}d, name is %{public}s, message is %{public}s", code, name.c_str(), message.c_str()); ReleaseHandler(-1); @@ -279,7 +276,7 @@ void SwitchOnSettingUICallback::OnError(int32_t code, const std::string& name, c */ void SwitchOnSettingUICallback::OnRemoteReady(const std::shared_ptr& uiProxy) { - ACCESSTOKEN_LOG_INFO(LABEL, "Connect to UIExtensionAbility successfully."); + LOGI(ATM_DOMAIN, ATM_TAG, "Connect to UIExtensionAbility successfully."); } /* @@ -287,7 +284,7 @@ void SwitchOnSettingUICallback::OnRemoteReady(const std::shared_ptrresult = RET_FAILED; return RET_FAILED; } @@ -324,10 +321,11 @@ static int32_t CreateUIExtension(const Want &want, std::shared_ptrCreateModalUIExtension(want, uiExtensionCallbacks, config); - ACCESSTOKEN_LOG_INFO(LABEL, "Create end, sessionId: %{public}d, tokenId: %{public}d, switchType: %{public}d.", + LOGI(ATM_DOMAIN, ATM_TAG, + "Create end, sessionId: %{public}d, tokenId: %{public}d, switchType: %{public}d.", sessionId, asyncContext->tokenId, asyncContext->switchType); if (sessionId == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create component, sessionId is 0."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create component, sessionId is 0."); asyncContext->result = RET_FAILED; return RET_FAILED; } @@ -339,7 +337,7 @@ static int32_t StartUIExtension(std::shared_ptr { AAFwk::Want want; AccessTokenKit::GetPermissionManagerInfo(asyncContext->info); - ACCESSTOKEN_LOG_INFO(LABEL, "bundleName: %{public}s, globalSwitchAbilityName: %{public}s.", + LOGI(ATM_DOMAIN, ATM_TAG, "bundleName: %{public}s, globalSwitchAbilityName: %{public}s.", asyncContext->info.grantBundleName.c_str(), asyncContext->info.globalSwitchAbilityName.c_str()); want.SetElementName(asyncContext->info.grantBundleName, asyncContext->info.globalSwitchAbilityName); want.SetParam(GLOBAL_SWITCH_KEY, asyncContext->switchType); @@ -350,7 +348,7 @@ static int32_t StartUIExtension(std::shared_ptr napi_value NapiRequestGlobalSwitch::RequestGlobalSwitch(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "RequestGlobalSwitch begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "RequestGlobalSwitch begin."); // use handle to protect asyncContext std::shared_ptr asyncContext = std::make_shared(env); @@ -375,7 +373,7 @@ napi_value NapiRequestGlobalSwitch::RequestGlobalSwitch(napi_env env, napi_callb NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncContextHandle->asyncContextPtr->work, napi_qos_user_initiated)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "RequestGlobalSwitch end."); + LOGD(ATM_DOMAIN, ATM_TAG, "RequestGlobalSwitch end."); asyncContextHandle.release(); return result; } @@ -388,7 +386,7 @@ bool NapiRequestGlobalSwitch::ParseRequestGlobalSwitch(const napi_env& env, napi_value thisVar = nullptr; if (napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, nullptr) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Napi_get_cb_info failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Napi_get_cb_info failed"); return false; } if (argc < NapiContextCommon::MAX_PARAMS_TWO - 1) { @@ -406,7 +404,8 @@ bool NapiRequestGlobalSwitch::ParseRequestGlobalSwitch(const napi_env& env, env, napi_throw(env, GenerateBusinessError(env, JsErrorCode::JS_ERROR_PARAM_ILLEGAL, errMsg)), false); return false; } - ACCESSTOKEN_LOG_INFO(LABEL, "AsyncContext.uiAbilityFlag is: %{public}d.", asyncContext->uiAbilityFlag); + LOGI(ATM_DOMAIN, ATM_TAG, + "AsyncContext.uiAbilityFlag is: %{public}d.", asyncContext->uiAbilityFlag); // argv[1] : type if (!ParseInt32(env, argv[1], asyncContext->switchType)) { @@ -443,23 +442,23 @@ void NapiRequestGlobalSwitch::RequestGlobalSwitchExecute(napi_env env, void* dat } static AccessTokenID currToken = static_cast(GetSelfTokenID()); if (asyncContextHandle->asyncContextPtr->tokenId != currToken) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "The context(token=%{public}d) is not belong to the current application(currToken=%{public}d).", asyncContextHandle->asyncContextPtr->tokenId, currToken); asyncContextHandle->asyncContextPtr->result = ERR_PARAM_INVALID; return; } - ACCESSTOKEN_LOG_INFO(LABEL, "Start to pop ui extension dialog"); + LOGI(ATM_DOMAIN, ATM_TAG, "Start to pop ui extension dialog"); StartUIExtension(asyncContextHandle->asyncContextPtr); if (asyncContextHandle->asyncContextPtr->result != JsErrorCode::JS_OK) { - ACCESSTOKEN_LOG_WARN(LABEL, "Failed to pop uiextension dialog."); + LOGW(ATM_DOMAIN, ATM_TAG, "Failed to pop uiextension dialog."); } } void NapiRequestGlobalSwitch::RequestGlobalSwitchComplete(napi_env env, napi_status status, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "RequestGlobalSwitchComplete begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "RequestGlobalSwitchComplete begin."); RequestGlobalSwitchAsyncContextHandle* asyncContextHandle = reinterpret_cast(data); if (asyncContextHandle == nullptr || asyncContextHandle->asyncContextPtr == nullptr) { diff --git a/frameworks/js/napi/accesstoken/src/napi_request_permission.cpp b/frameworks/js/napi/accesstoken/src/napi_request_permission.cpp index 72b3ef84b02a5d947e36d761db78b2eabf5eca10..6016a7a014fd95df490e919ae929295763f48e1a 100644 --- a/frameworks/js/napi/accesstoken/src/napi_request_permission.cpp +++ b/frameworks/js/napi/accesstoken/src/napi_request_permission.cpp @@ -31,9 +31,6 @@ std::mutex g_lockFlag; std::map>> RequestAsyncInstanceControl::instanceIdMap_; std::mutex RequestAsyncInstanceControl::instanceIdMutex_; namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "NapiRequestPermission" -}; const std::string PERMISSION_KEY = "ohos.user.grant.permission"; const std::string STATE_KEY = "ohos.user.grant.permission.state"; const std::string RESULT_KEY = "ohos.user.grant.permission.result"; @@ -106,7 +103,7 @@ static void GetInstanceId(std::shared_ptr& asyncContext) auto task = [asyncContext]() { Ace::UIContent* uiContent = GetUIContent(asyncContext); if (uiContent == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get ui content failed!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get ui content failed!"); return; } asyncContext->uiContentFlag = true; @@ -121,7 +118,7 @@ static void GetInstanceId(std::shared_ptr& asyncContext) #else task(); #endif - ACCESSTOKEN_LOG_INFO(LABEL, "Instance id: %{public}d, uiContentFlag: %{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "Instance id: %{public}d, uiContentFlag: %{public}d", asyncContext->instanceId, asyncContext->uiContentFlag); } @@ -132,7 +129,7 @@ static void CreateUIExtensionMainThread(std::shared_ptr& as auto task = [asyncContext, want, uiExtensionCallbacks, uiExtCallback]() { Ace::UIContent* uiContent = GetUIContent(asyncContext); if (uiContent == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get ui content failed!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get ui content failed!"); asyncContext->result = RET_FAILED; asyncContext->uiExtensionFlag = false; return; @@ -142,10 +139,11 @@ static void CreateUIExtensionMainThread(std::shared_ptr& as config.isProhibitBack = true; int32_t sessionId = uiContent->CreateModalUIExtension(want, uiExtensionCallbacks, config); - ACCESSTOKEN_LOG_INFO(LABEL, "Create end, sessionId: %{public}d, tokenId: %{public}d, permNum: %{public}zu", + LOGI(ATM_DOMAIN, ATM_TAG, + "Create end, sessionId: %{public}d, tokenId: %{public}d, permNum: %{public}zu", sessionId, asyncContext->tokenId, asyncContext->permissionList.size()); if (sessionId == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Create component failed, sessionId is 0"); + LOGE(ATM_DOMAIN, ATM_TAG, "Create component failed, sessionId is 0"); asyncContext->result = RET_FAILED; asyncContext->uiExtensionFlag = false; return; @@ -161,7 +159,7 @@ static void CreateUIExtensionMainThread(std::shared_ptr& as #else task(); #endif - ACCESSTOKEN_LOG_INFO(LABEL, "Instance id: %{public}d", asyncContext->instanceId); + LOGI(ATM_DOMAIN, ATM_TAG, "Instance id: %{public}d", asyncContext->instanceId); } static void CloseModalUIExtensionMainThread(std::shared_ptr& asyncContext, int32_t sessionId) @@ -169,12 +167,12 @@ static void CloseModalUIExtensionMainThread(std::shared_ptr auto task = [asyncContext, sessionId]() { Ace::UIContent* uiContent = GetUIContent(asyncContext); if (uiContent == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get ui content failed!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get ui content failed!"); asyncContext->result = RET_FAILED; return; } uiContent->CloseModalUIExtension(sessionId); - ACCESSTOKEN_LOG_INFO(LABEL, "Close end, sessionId: %{public}d", sessionId); + LOGI(ATM_DOMAIN, ATM_TAG, "Close end, sessionId: %{public}d", sessionId); }; #ifdef EVENTHANDLER_ENABLE if (asyncContext->handler_ != nullptr) { @@ -185,7 +183,7 @@ static void CloseModalUIExtensionMainThread(std::shared_ptr #else task(); #endif - ACCESSTOKEN_LOG_INFO(LABEL, "Instance id: %{public}d", asyncContext->instanceId); + LOGI(ATM_DOMAIN, ATM_TAG, "Instance id: %{public}d", asyncContext->instanceId); } static napi_value GetContext( @@ -194,12 +192,12 @@ static napi_value GetContext( bool stageMode = false; napi_status status = OHOS::AbilityRuntime::IsStageContext(env, value, stageMode); if (status != napi_ok || !stageMode) { - ACCESSTOKEN_LOG_ERROR(LABEL, "It is not a stage mode"); + LOGE(ATM_DOMAIN, ATM_TAG, "It is not a stage mode"); return nullptr; } else { auto context = AbilityRuntime::GetStageModeContext(env, value); if (context == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get context failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get context failed"); return nullptr; } asyncContext->abilityContext = @@ -210,12 +208,12 @@ static napi_value GetContext( asyncContext->tokenId = asyncContext->abilityContext->GetApplicationInfo()->accessTokenId; asyncContext->bundleName = asyncContext->abilityContext->GetApplicationInfo()->bundleName; } else { - ACCESSTOKEN_LOG_WARN(LABEL, "Convert to ability context failed"); + LOGW(ATM_DOMAIN, ATM_TAG, "Convert to ability context failed"); asyncContext->uiExtensionContext = AbilityRuntime::Context::ConvertTo(context); if ((asyncContext->uiExtensionContext == nullptr) || (asyncContext->uiExtensionContext->GetApplicationInfo() == nullptr)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Convert to ui extension context failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Convert to ui extension context failed"); return nullptr; } asyncContext->tokenId = asyncContext->uiExtensionContext->GetApplicationInfo()->accessTokenId; @@ -275,36 +273,36 @@ static void ResultCallbackJSThreadWorker(uv_work_t* work, int32_t status) { (void)status; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Uv_queue_work_with_qos input work is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Uv_queue_work_with_qos input work is nullptr"); return; } std::unique_ptr uvWorkPtr {work}; ResultCallback *retCB = reinterpret_cast(work->data); if (retCB == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RetCB is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "RetCB is nullptr"); return; } std::unique_ptr callbackPtr {retCB}; int32_t result = JsErrorCode::JS_OK; if (retCB->data->result != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Result is: %{public}d", retCB->data->result); + LOGE(ATM_DOMAIN, ATM_TAG, "Result is: %{public}d", retCB->data->result); result = RET_FAILED; } if (retCB->grantResults.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GrantResults empty"); + LOGE(ATM_DOMAIN, ATM_TAG, "GrantResults empty"); result = RET_FAILED; } napi_handle_scope scope = nullptr; napi_open_handle_scope(retCB->data->env, &scope); if (scope == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Napi_open_handle_scope failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Napi_open_handle_scope failed"); return; } napi_value requestResult = WrapRequestResult( retCB->data->env, retCB->permissions, retCB->grantResults, retCB->dialogShownResults, retCB->errorReasons); if (requestResult == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Wrap requestResult failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Wrap requestResult failed"); result = RET_FAILED; } @@ -335,7 +333,7 @@ static void RequestResultsHandler(const std::vector& permissionList { auto* retCB = new (std::nothrow) ResultCallback(); if (retCB == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for work!"); return; } @@ -353,12 +351,12 @@ static void RequestResultsHandler(const std::vector& permissionList uv_loop_s* loop = nullptr; NAPI_CALL_RETURN_VOID(data->env, napi_get_uv_event_loop(data->env, &loop)); if (loop == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Loop instance is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Loop instance is nullptr"); return; } uv_work_t* work = new (std::nothrow) uv_work_t; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for work!"); return; } std::unique_ptr uvWorkPtr {work}; @@ -373,7 +371,7 @@ static void RequestResultsHandler(const std::vector& permissionList void AuthorizationResult::GrantResultsCallback(const std::vector& permissionList, const std::vector& grantResults) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called."); + LOGI(ATM_DOMAIN, ATM_TAG, "Called."); std::shared_ptr asyncContext = data_; if (asyncContext == nullptr) { return; @@ -383,7 +381,7 @@ void AuthorizationResult::GrantResultsCallback(const std::vector& p void AuthorizationResult::WindowShownCallback() { - ACCESSTOKEN_LOG_INFO(LABEL, "Called."); + LOGI(ATM_DOMAIN, ATM_TAG, "Called."); std::shared_ptr asyncContext = data_; if (asyncContext == nullptr) { @@ -393,11 +391,11 @@ void AuthorizationResult::WindowShownCallback() Ace::UIContent* uiContent = GetUIContent(asyncContext); // get uiContent failed when request or when callback called if ((uiContent == nullptr) || !(asyncContext->uiContentFlag)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get ui content failed!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get ui content failed!"); return; } RequestAsyncInstanceControl::ExecCallback(asyncContext->instanceId); - ACCESSTOKEN_LOG_DEBUG(LABEL, "OnRequestPermissionsFromUser async callback is called end"); + LOGD(ATM_DOMAIN, ATM_TAG, "OnRequestPermissionsFromUser async callback is called end"); } static void CreateServiceExtension(std::shared_ptr asyncContext) @@ -406,14 +404,14 @@ static void CreateServiceExtension(std::shared_ptr asyncCon return; } if (!asyncContext->uiAbilityFlag) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UIExtension ability can not pop service ablility window!"); + LOGE(ATM_DOMAIN, ATM_TAG, "UIExtension ability can not pop service ablility window!"); asyncContext->needDynamicRequest = false; asyncContext->result = RET_FAILED; return; } sptr remoteObject = new (std::nothrow) AccessToken::AuthorizationResult(asyncContext); if (remoteObject == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Create window failed!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Create window failed!"); asyncContext->needDynamicRequest = false; asyncContext->result = RET_FAILED; return; @@ -438,7 +436,7 @@ static void CreateServiceExtension(std::shared_ptr asyncCon int32_t ret = AAFwk::AbilityManagerClient::GetInstance()->RequestDialogService( want, asyncContext->abilityContext->GetToken()); - ACCESSTOKEN_LOG_INFO(LABEL, "Request end, ret: %{public}d, tokenId: %{public}d, permNum: %{public}zu", + LOGI(ATM_DOMAIN, ATM_TAG, "Request end, ret: %{public}d, tokenId: %{public}d, permNum: %{public}zu", ret, asyncContext->tokenId, asyncContext->permissionList.size()); } @@ -459,20 +457,20 @@ bool NapiRequestPermission::IsDynamicRequest(std::shared_ptrtokenId, asyncContext->info.grantBundleName.c_str(), asyncContext->info.grantAbilityName.c_str(), asyncContext->info.grantServiceAbilityName.c_str()); for (const auto& permState : permList) { - ACCESSTOKEN_LOG_INFO(LABEL, "Permission: %{public}s: state: %{public}d, errorReason: %{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "Permission: %{public}s: state: %{public}d, errorReason: %{public}d", permState.permissionName.c_str(), permState.state, permState.errorReason); asyncContext->permissionsState.emplace_back(permState.state); asyncContext->dialogShownResults.emplace_back(permState.state == TypePermissionOper::DYNAMIC_OPER); asyncContext->errorReasons.emplace_back(permState.errorReason); } if (permList.size() != asyncContext->permissionList.size()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Returned permList size: %{public}zu.", permList.size()); + LOGE(ATM_DOMAIN, ATM_TAG, "Returned permList size: %{public}zu.", permList.size()); return false; } return ret == TypePermissionOper::DYNAMIC_OPER; @@ -483,7 +481,7 @@ void UIExtensionCallback::ReleaseHandler(int32_t code) { std::lock_guard lock(g_lockFlag); if (this->reqContext_->releaseFlag) { - ACCESSTOKEN_LOG_WARN(LABEL, "Callback has executed."); + LOGW(ATM_DOMAIN, ATM_TAG, "Callback has executed."); return; } this->reqContext_->releaseFlag = true; @@ -512,7 +510,7 @@ void UIExtensionCallback::SetSessionId(int32_t sessionId) */ void UIExtensionCallback::OnResult(int32_t resultCode, const AAFwk::Want& result) { - ACCESSTOKEN_LOG_INFO(LABEL, "ResultCode is %{public}d", resultCode); + LOGI(ATM_DOMAIN, ATM_TAG, "ResultCode is %{public}d", resultCode); this->reqContext_->permissionList = result.GetStringArrayParam(PERMISSION_KEY); this->reqContext_->permissionsState = result.GetIntArrayParam(RESULT_KEY); ReleaseHandler(0); @@ -523,7 +521,7 @@ void UIExtensionCallback::OnResult(int32_t resultCode, const AAFwk::Want& result */ void UIExtensionCallback::OnReceive(const AAFwk::WantParams& receive) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called!"); } /* @@ -532,7 +530,7 @@ void UIExtensionCallback::OnReceive(const AAFwk::WantParams& receive) */ void UIExtensionCallback::OnRelease(int32_t releaseCode) { - ACCESSTOKEN_LOG_INFO(LABEL, "ReleaseCode is %{public}d", releaseCode); + LOGI(ATM_DOMAIN, ATM_TAG, "ReleaseCode is %{public}d", releaseCode); ReleaseHandler(-1); } @@ -542,7 +540,7 @@ void UIExtensionCallback::OnRelease(int32_t releaseCode) */ void UIExtensionCallback::OnError(int32_t code, const std::string& name, const std::string& message) { - ACCESSTOKEN_LOG_INFO(LABEL, "Code is %{public}d, name is %{public}s, message is %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "Code is %{public}d, name is %{public}s, message is %{public}s", code, name.c_str(), message.c_str()); ReleaseHandler(-1); @@ -554,7 +552,7 @@ void UIExtensionCallback::OnError(int32_t code, const std::string& name, const s */ void UIExtensionCallback::OnRemoteReady(const std::shared_ptr& uiProxy) { - ACCESSTOKEN_LOG_INFO(LABEL, "Connect to UIExtensionAbility successfully."); + LOGI(ATM_DOMAIN, ATM_TAG, "Connect to UIExtensionAbility successfully."); } /* @@ -562,7 +560,7 @@ void UIExtensionCallback::OnRemoteReady(const std::shared_ptr asyncContext) napi_value NapiRequestPermission::RequestPermissionsFromUser(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "RequestPermissionsFromUser begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "RequestPermissionsFromUser begin."); // use handle to protect asyncContext std::shared_ptr asyncContext = std::make_shared(env); @@ -625,7 +623,7 @@ napi_value NapiRequestPermission::RequestPermissionsFromUser(napi_env env, napi_ NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncContextHandle->asyncContextPtr->work, napi_qos_user_initiated)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "RequestPermissionsFromUser end."); + LOGD(ATM_DOMAIN, ATM_TAG, "RequestPermissionsFromUser end."); asyncContextHandle.release(); return result; } @@ -638,7 +636,7 @@ bool NapiRequestPermission::ParseRequestPermissionFromUser(const napi_env& env, napi_value thisVar = nullptr; if (napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, nullptr) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Napi_get_cb_info failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Napi_get_cb_info failed"); return false; } if (argc < NapiContextCommon::MAX_PARAMS_THREE - 1) { @@ -656,7 +654,8 @@ bool NapiRequestPermission::ParseRequestPermissionFromUser(const napi_env& env, env, napi_throw(env, GenerateBusinessError(env, JsErrorCode::JS_ERROR_PARAM_ILLEGAL, errMsg)), false); return false; } - ACCESSTOKEN_LOG_INFO(LABEL, "AsyncContext.uiAbilityFlag is: %{public}d.", asyncContext->uiAbilityFlag); + LOGI(ATM_DOMAIN, ATM_TAG, + "AsyncContext.uiAbilityFlag is: %{public}d.", asyncContext->uiAbilityFlag); // argv[1] : permissionList if (!ParseStringArray(env, argv[1], asyncContext->permissionList) || @@ -687,21 +686,21 @@ void NapiRequestPermission::RequestPermissionsFromUserExecute(napi_env env, void RequestAsyncContextHandle* asyncContextHandle = reinterpret_cast(data); static AccessTokenID selfTokenID = static_cast(GetSelfTokenID()); if (asyncContextHandle->asyncContextPtr->tokenId != selfTokenID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "The context tokenID: %{public}d, selfTokenID: %{public}d.", + LOGE(ATM_DOMAIN, ATM_TAG, "The context tokenID: %{public}d, selfTokenID: %{public}d.", asyncContextHandle->asyncContextPtr->tokenId, selfTokenID); asyncContextHandle->asyncContextPtr->result = RET_FAILED; return; } if (!IsDynamicRequest(asyncContextHandle->asyncContextPtr)) { - ACCESSTOKEN_LOG_INFO(LABEL, "It does not need to request permission"); + LOGI(ATM_DOMAIN, ATM_TAG, "It does not need to request permission"); asyncContextHandle->asyncContextPtr->needDynamicRequest = false; return; } GetInstanceId(asyncContextHandle->asyncContextPtr); // service extension dialog if (asyncContextHandle->asyncContextPtr->info.grantBundleName == ORI_PERMISSION_MANAGER_BUNDLE_NAME) { - ACCESSTOKEN_LOG_INFO(LABEL, "Pop service extension dialog, uiContentFlag=%{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "Pop service extension dialog, uiContentFlag=%{public}d", asyncContextHandle->asyncContextPtr->uiContentFlag); if (asyncContextHandle->asyncContextPtr->uiContentFlag) { RequestAsyncInstanceControl::AddCallbackByInstanceId(asyncContextHandle->asyncContextPtr); @@ -709,14 +708,14 @@ void NapiRequestPermission::RequestPermissionsFromUserExecute(napi_env env, void CreateServiceExtension(asyncContextHandle->asyncContextPtr); } } else if (asyncContextHandle->asyncContextPtr->instanceId == -1) { - ACCESSTOKEN_LOG_INFO(LABEL, "Pop service extension dialog, instanceId is -1."); + LOGI(ATM_DOMAIN, ATM_TAG, "Pop service extension dialog, instanceId is -1."); CreateServiceExtension(asyncContextHandle->asyncContextPtr); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "REQUEST_PERMISSIONS_FROM_USER", HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "BUNDLENAME", asyncContextHandle->asyncContextPtr->bundleName, "UIEXTENSION_FLAG", false); } else { - ACCESSTOKEN_LOG_INFO(LABEL, "Pop ui extension dialog"); + LOGI(ATM_DOMAIN, ATM_TAG, "Pop ui extension dialog"); asyncContextHandle->asyncContextPtr->uiExtensionFlag = true; RequestAsyncInstanceControl::AddCallbackByInstanceId(asyncContextHandle->asyncContextPtr); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "REQUEST_PERMISSIONS_FROM_USER", @@ -724,7 +723,8 @@ void NapiRequestPermission::RequestPermissionsFromUserExecute(napi_env env, void "BUNDLENAME", asyncContextHandle->asyncContextPtr->bundleName, "UIEXTENSION_FLAG", asyncContextHandle->asyncContextPtr->uiExtensionFlag); if (!asyncContextHandle->asyncContextPtr->uiExtensionFlag) { - ACCESSTOKEN_LOG_WARN(LABEL, "Pop uiextension dialog fail, start to pop service extension dialog."); + LOGW(ATM_DOMAIN, ATM_TAG, + "Pop uiextension dialog fail, start to pop service extension dialog."); RequestAsyncInstanceControl::AddCallbackByInstanceId(asyncContextHandle->asyncContextPtr); } } @@ -740,14 +740,14 @@ void NapiRequestPermission::RequestPermissionsFromUserComplete(napi_env env, nap } if ((asyncContextHandle->asyncContextPtr->permissionsState.empty()) && (asyncContextHandle->asyncContextPtr->result == JsErrorCode::JS_OK)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GrantResults empty"); + LOGE(ATM_DOMAIN, ATM_TAG, "GrantResults empty"); asyncContextHandle->asyncContextPtr->result = RET_FAILED; } napi_value requestResult = WrapRequestResult(env, asyncContextHandle->asyncContextPtr->permissionList, asyncContextHandle->asyncContextPtr->permissionsState, asyncContextHandle->asyncContextPtr->dialogShownResults, asyncContextHandle->asyncContextPtr->errorReasons); if (requestResult == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Wrap requestResult failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Wrap requestResult failed"); if (asyncContextHandle->asyncContextPtr->result == JsErrorCode::JS_OK) { asyncContextHandle->asyncContextPtr->result = RET_FAILED; } @@ -765,11 +765,11 @@ void NapiRequestPermission::RequestPermissionsFromUserComplete(napi_env env, nap napi_value NapiRequestPermission::GetPermissionsStatus(napi_env env, napi_callback_info info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionsStatus begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "GetPermissionsStatus begin."); auto* asyncContext = new (std::nothrow) RequestAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(ATM_DOMAIN, ATM_TAG, "New struct fail."); return nullptr; } @@ -790,7 +790,7 @@ napi_value NapiRequestPermission::GetPermissionsStatus(napi_env env, napi_callba // add async work handle to the napi queue and wait for result napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_default); - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionsStatus end."); + LOGD(ATM_DOMAIN, ATM_TAG, "GetPermissionsStatus end."); context.release(); return result; } @@ -828,7 +828,8 @@ bool NapiRequestPermission::ParseInputToGetQueryResult(const napi_env& env, cons env, napi_throw(env, GenerateBusinessError(env, JsErrorCode::JS_ERROR_PARAM_ILLEGAL, errMsg)), false); return false; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID = %{public}d, permissionList size = %{public}zu", asyncContext.tokenId, + LOGD(ATM_DOMAIN, ATM_TAG, + "TokenID = %{public}d, permissionList size = %{public}zu", asyncContext.tokenId, asyncContext.permissionList.size()); return true; } @@ -839,18 +840,19 @@ void NapiRequestPermission::GetPermissionsStatusExecute(napi_env env, void *data std::vector permList; for (const auto& permission : asyncContext->permissionList) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Permission: %{public}s.", permission.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "Permission: %{public}s.", permission.c_str()); PermissionListState permState; permState.permissionName = permission; permState.state = INVALID_OPER; permList.emplace_back(permState); } - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermList size: %{public}zu, asyncContext->permissionList size: %{public}zu.", + LOGD(ATM_DOMAIN, ATM_TAG, + "PermList size: %{public}zu, asyncContext->permissionList size: %{public}zu.", permList.size(), asyncContext->permissionList.size()); asyncContext->result = AccessTokenKit::GetPermissionsStatus(asyncContext->tokenId, permList); for (const auto& permState : permList) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Permission: %{public}s", permState.permissionName.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "Permission: %{public}s", permState.permissionName.c_str()); asyncContext->permissionQueryResults.emplace_back(permState.state); } } @@ -861,7 +863,7 @@ void NapiRequestPermission::GetPermissionsStatusComplete(napi_env env, napi_stat std::unique_ptr callbackPtr {asyncContext}; if ((asyncContext->permissionQueryResults.empty()) && asyncContext->result == JsErrorCode::JS_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionQueryResults empty"); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionQueryResults empty"); asyncContext->result = RET_FAILED; } napi_value result; @@ -883,7 +885,7 @@ void RequestAsyncInstanceControl::CheckDynamicRequest( asyncContext->dialogShownResults.clear(); asyncContext->errorReasons.clear(); if (!NapiRequestPermission::IsDynamicRequest(asyncContext)) { - ACCESSTOKEN_LOG_INFO(LABEL, "It does not need to request permission exsion"); + LOGI(ATM_DOMAIN, ATM_TAG, "It does not need to request permission exsion"); RequestResultsHandler(asyncContext->permissionList, asyncContext->permissionsState, asyncContext); return; } @@ -892,13 +894,13 @@ void RequestAsyncInstanceControl::CheckDynamicRequest( void RequestAsyncInstanceControl::AddCallbackByInstanceId(std::shared_ptr& asyncContext) { - ACCESSTOKEN_LOG_INFO(LABEL, "InstanceId: %{public}d", asyncContext->instanceId); + LOGI(ATM_DOMAIN, ATM_TAG, "InstanceId: %{public}d", asyncContext->instanceId); { std::lock_guard lock(instanceIdMutex_); auto iter = instanceIdMap_.find(asyncContext->instanceId); // id is existed mean a pop window is showing, add context to waiting queue if (iter != instanceIdMap_.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "InstanceId: %{public}d has existed.", asyncContext->instanceId); + LOGI(ATM_DOMAIN, ATM_TAG, "InstanceId: %{public}d has existed.", asyncContext->instanceId); instanceIdMap_[asyncContext->instanceId].emplace_back(asyncContext); return; } @@ -921,11 +923,12 @@ void RequestAsyncInstanceControl::ExecCallback(int32_t id) std::lock_guard lock(instanceIdMutex_); auto iter = instanceIdMap_.find(id); if (iter == instanceIdMap_.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "Id: %{public}d not existed.", id); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}d not existed.", id); return; } while (!iter->second.empty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "Id: %{public}d, map size: %{public}zu.", id, iter->second.size()); + LOGI(ATM_DOMAIN, ATM_TAG, + "Id: %{public}d, map size: %{public}zu.", id, iter->second.size()); asyncContext = iter->second[0]; iter->second.erase(iter->second.begin()); CheckDynamicRequest(asyncContext, isDynamic); @@ -934,7 +937,7 @@ void RequestAsyncInstanceControl::ExecCallback(int32_t id) } } if (iter->second.empty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "Id: %{public}d, map is empty", id); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}d, map is empty", id); instanceIdMap_.erase(id); } } diff --git a/frameworks/js/napi/accesstoken/src/napi_request_permission_on_setting.cpp b/frameworks/js/napi/accesstoken/src/napi_request_permission_on_setting.cpp index dc66816689b40a23ff533a5b68711f2f5d8e11df..c6354691187dd052be2c684f4dbd15ee3fc7ef42 100644 --- a/frameworks/js/napi/accesstoken/src/napi_request_permission_on_setting.cpp +++ b/frameworks/js/napi/accesstoken/src/napi_request_permission_on_setting.cpp @@ -25,9 +25,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "NapiRequestPermissionOnSetting" -}; const std::string PERMISSION_KEY = "ohos.user.setting.permission"; const std::string PERMISSION_RESULT_KEY = "ohos.user.setting.permission.result"; const std::string RESULT_ERROR_KEY = "ohos.user.setting.error_code"; @@ -79,12 +76,12 @@ static napi_value GetContext( bool stageMode = false; napi_status status = OHOS::AbilityRuntime::IsStageContext(env, value, stageMode); if (status != napi_ok || !stageMode) { - ACCESSTOKEN_LOG_ERROR(LABEL, "It is not a stage mode."); + LOGE(ATM_DOMAIN, ATM_TAG, "It is not a stage mode."); return nullptr; } else { auto context = AbilityRuntime::GetStageModeContext(env, value); if (context == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to Get application context."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Get application context."); return nullptr; } asyncContext->abilityContext = @@ -92,11 +89,11 @@ static napi_value GetContext( if (asyncContext->abilityContext != nullptr) { asyncContext->uiAbilityFlag = true; } else { - ACCESSTOKEN_LOG_WARN(LABEL, "Failed to convert to ability context."); + LOGW(ATM_DOMAIN, ATM_TAG, "Failed to convert to ability context."); asyncContext->uiExtensionContext = AbilityRuntime::Context::ConvertTo(context); if (asyncContext->uiExtensionContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to convert to ui extension context."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to convert to ui extension context."); return nullptr; } } @@ -143,7 +140,7 @@ static int32_t TransferToJsErrorCode(int32_t errCode) jsCode = JS_ERROR_INNER; break; } - ACCESSTOKEN_LOG_INFO(LABEL, "dialog error(%{public}d) jsCode(%{public}d).", errCode, jsCode); + LOGI(ATM_DOMAIN, ATM_TAG, "dialog error(%{public}d) jsCode(%{public}d).", errCode, jsCode); return jsCode; } @@ -151,13 +148,13 @@ static void ResultCallbackJSThreadWorker(uv_work_t* work, int32_t status) { (void)status; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Uv_queue_work_with_qos input work is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Uv_queue_work_with_qos input work is nullptr"); return; } std::unique_ptr uvWorkPtr {work}; PermissonOnSettingResultCallback *retCB = reinterpret_cast(work->data); if (retCB == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RetCB is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "RetCB is nullptr"); return; } std::unique_ptr callbackPtr {retCB}; @@ -170,12 +167,12 @@ static void ResultCallbackJSThreadWorker(uv_work_t* work, int32_t status) napi_handle_scope scope = nullptr; napi_open_handle_scope(asyncContext->env, &scope); if (scope == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Napi_open_handle_scope failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Napi_open_handle_scope failed"); return; } napi_value requestResult = WrapRequestResult(asyncContext->env, retCB->stateList); if ((result == JS_OK) && (requestResult == nullptr)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Wrap requestResult failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Wrap requestResult failed"); result = JS_ERROR_INNER; } @@ -188,7 +185,7 @@ static void PermissionResultsCallbackUI(int32_t jsCode, { auto* retCB = new (std::nothrow) PermissonOnSettingResultCallback(); if (retCB == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for work!"); return; } @@ -200,12 +197,12 @@ static void PermissionResultsCallbackUI(int32_t jsCode, uv_loop_s* loop = nullptr; NAPI_CALL_RETURN_VOID(data->env, napi_get_uv_event_loop(data->env, &loop)); if (loop == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Loop instance is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Loop instance is nullptr"); return; } uv_work_t* work = new (std::nothrow) uv_work_t; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Insufficient memory for work!"); return; } std::unique_ptr uvWorkPtr {work}; @@ -222,17 +219,17 @@ void PermissonOnSettingUICallback::ReleaseHandler(int32_t code) { std::lock_guard lock(g_lockFlag); if (this->reqContext_->releaseFlag) { - ACCESSTOKEN_LOG_WARN(LABEL, "Callback has executed."); + LOGW(ATM_DOMAIN, ATM_TAG, "Callback has executed."); return; } this->reqContext_->releaseFlag = true; } Ace::UIContent* uiContent = GetUIContent(this->reqContext_); if (uiContent == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get ui content failed!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get ui content failed!"); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "Close uiextension component"); + LOGI(ATM_DOMAIN, ATM_TAG, "Close uiextension component"); uiContent->CloseModalUIExtension(this->sessionId_); if (code == -1) { this->reqContext_->errorCode = code; @@ -262,7 +259,7 @@ void PermissonOnSettingUICallback::OnResult(int32_t resultCode, const AAFwk::Wan { this->reqContext_->errorCode = result.GetIntParam(RESULT_ERROR_KEY, 0); this->reqContext_->stateList = result.GetIntArrayParam(PERMISSION_RESULT_KEY); - ACCESSTOKEN_LOG_INFO(LABEL, "ResultCode is %{public}d, errorCode=%{public}d, listSize=%{public}zu", + LOGI(ATM_DOMAIN, ATM_TAG, "ResultCode is %{public}d, errorCode=%{public}d, listSize=%{public}zu", resultCode, this->reqContext_->errorCode, this->reqContext_->stateList.size()); ReleaseHandler(0); } @@ -272,7 +269,7 @@ void PermissonOnSettingUICallback::OnResult(int32_t resultCode, const AAFwk::Wan */ void PermissonOnSettingUICallback::OnReceive(const AAFwk::WantParams& receive) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called!"); } /* @@ -281,7 +278,7 @@ void PermissonOnSettingUICallback::OnReceive(const AAFwk::WantParams& receive) */ void PermissonOnSettingUICallback::OnRelease(int32_t releaseCode) { - ACCESSTOKEN_LOG_INFO(LABEL, "ReleaseCode is %{public}d", releaseCode); + LOGI(ATM_DOMAIN, ATM_TAG, "ReleaseCode is %{public}d", releaseCode); ReleaseHandler(-1); } @@ -291,7 +288,7 @@ void PermissonOnSettingUICallback::OnRelease(int32_t releaseCode) */ void PermissonOnSettingUICallback::OnError(int32_t code, const std::string& name, const std::string& message) { - ACCESSTOKEN_LOG_INFO(LABEL, "Code is %{public}d, name is %{public}s, message is %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "Code is %{public}d, name is %{public}s, message is %{public}s", code, name.c_str(), message.c_str()); ReleaseHandler(-1); @@ -303,7 +300,7 @@ void PermissonOnSettingUICallback::OnError(int32_t code, const std::string& name */ void PermissonOnSettingUICallback::OnRemoteReady(const std::shared_ptr& uiProxy) { - ACCESSTOKEN_LOG_INFO(LABEL, "Connect to UIExtensionAbility successfully."); + LOGI(ATM_DOMAIN, ATM_TAG, "Connect to UIExtensionAbility successfully."); } /* @@ -311,7 +308,7 @@ void PermissonOnSettingUICallback::OnRemoteReady(const std::shared_ptrresult = RET_FAILED; return RET_FAILED; } @@ -348,10 +345,11 @@ static int32_t CreateUIExtension(const Want &want, std::shared_ptrCreateModalUIExtension(want, uiExtensionCallbacks, config); - ACCESSTOKEN_LOG_INFO(LABEL, "Create end, sessionId: %{public}d, tokenId: %{public}d, permSize: %{public}zu.", + LOGI(ATM_DOMAIN, ATM_TAG, + "Create end, sessionId: %{public}d, tokenId: %{public}d, permSize: %{public}zu.", sessionId, asyncContext->tokenId, asyncContext->permissionList.size()); if (sessionId == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create component, sessionId is 0."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create component, sessionId is 0."); asyncContext->result = RET_FAILED; return RET_FAILED; } @@ -363,7 +361,7 @@ static int32_t StartUIExtension(std::shared_ptrinfo); - ACCESSTOKEN_LOG_INFO(LABEL, "bundleName: %{public}s, permStateAbilityName: %{public}s.", + LOGI(ATM_DOMAIN, ATM_TAG, "bundleName: %{public}s, permStateAbilityName: %{public}s.", asyncContext->info.grantBundleName.c_str(), asyncContext->info.permStateAbilityName.c_str()); want.SetElementName(asyncContext->info.grantBundleName, asyncContext->info.permStateAbilityName); want.SetParam(PERMISSION_KEY, asyncContext->permissionList); @@ -373,7 +371,7 @@ static int32_t StartUIExtension(std::shared_ptr asyncContext = std::make_shared(env); @@ -398,7 +396,7 @@ napi_value NapiRequestPermissionOnSetting::RequestPermissionOnSetting(napi_env e NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncContextHandle->asyncContextPtr->work, napi_qos_user_initiated)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "RequestPermissionOnSetting end."); + LOGD(ATM_DOMAIN, ATM_TAG, "RequestPermissionOnSetting end."); asyncContextHandle.release(); return result; } @@ -411,7 +409,7 @@ bool NapiRequestPermissionOnSetting::ParseRequestPermissionOnSetting(const napi_ napi_value thisVar = nullptr; if (napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, nullptr) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Napi_get_cb_info failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Napi_get_cb_info failed"); return false; } if (argc < NapiContextCommon::MAX_PARAMS_TWO - 1) { @@ -429,7 +427,8 @@ bool NapiRequestPermissionOnSetting::ParseRequestPermissionOnSetting(const napi_ env, napi_throw(env, GenerateBusinessError(env, JsErrorCode::JS_ERROR_PARAM_ILLEGAL, errMsg)), false); return false; } - ACCESSTOKEN_LOG_INFO(LABEL, "AsyncContext.uiAbilityFlag is: %{public}d.", asyncContext->uiAbilityFlag); + LOGI(ATM_DOMAIN, ATM_TAG, + "AsyncContext.uiAbilityFlag is: %{public}d.", asyncContext->uiAbilityFlag); // argv[1] : permissionList if (!ParseStringArray(env, argv[1], asyncContext->permissionList) || @@ -467,23 +466,23 @@ void NapiRequestPermissionOnSetting::RequestPermissionOnSettingExecute(napi_env } static AccessTokenID currToken = static_cast(GetSelfTokenID()); if (asyncContextHandle->asyncContextPtr->tokenId != currToken) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "The context(token=%{public}d) is not belong to the current application(currToken=%{public}d).", asyncContextHandle->asyncContextPtr->tokenId, currToken); asyncContextHandle->asyncContextPtr->result = ERR_PARAM_INVALID; return; } - ACCESSTOKEN_LOG_INFO(LABEL, "Start to pop ui extension dialog"); + LOGI(ATM_DOMAIN, ATM_TAG, "Start to pop ui extension dialog"); StartUIExtension(asyncContextHandle->asyncContextPtr); if (asyncContextHandle->asyncContextPtr->result != JsErrorCode::JS_OK) { - ACCESSTOKEN_LOG_WARN(LABEL, "Failed to pop uiextension dialog."); + LOGW(ATM_DOMAIN, ATM_TAG, "Failed to pop uiextension dialog."); } } void NapiRequestPermissionOnSetting::RequestPermissionOnSettingComplete(napi_env env, napi_status status, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "RequestPermissionOnSettingComplete begin."); + LOGD(ATM_DOMAIN, ATM_TAG, "RequestPermissionOnSettingComplete begin."); RequestOnSettingAsyncContextHandle* asyncContextHandle = reinterpret_cast(data); if (asyncContextHandle == nullptr || asyncContextHandle->asyncContextPtr == nullptr) { diff --git a/frameworks/js/napi/common/src/napi_common.cpp b/frameworks/js/napi/common/src/napi_common.cpp index f1e3f165618c22edd4e2e7ca4ad446384a92581f..09efb654e7a5fa0f08c408b1570db29ad9030c54 100644 --- a/frameworks/js/napi/common/src/napi_common.cpp +++ b/frameworks/js/napi/common/src/napi_common.cpp @@ -18,15 +18,11 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "CommonNapi"}; -} // namespace - bool IsCurrentThread(std::thread::id threadId) { std::thread::id currentThread = std::this_thread::get_id(); if (threadId != currentThread) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Napi_ref can not be compared,different threadId"); + LOGE(ATM_DOMAIN, ATM_TAG, "Napi_ref can not be compared,different threadId"); return false; } return true; @@ -53,7 +49,7 @@ bool CheckType(const napi_env& env, const napi_value& value, const napi_valuetyp napi_valuetype valuetype = napi_undefined; napi_typeof(env, value, &valuetype); if (valuetype != type) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Value type dismatch, [%{public}d]->[%{public}d]", valuetype, type); + LOGE(ATM_DOMAIN, ATM_TAG, "Value type dismatch, [%{public}d]->[%{public}d]", valuetype, type); return false; } return true; @@ -66,7 +62,7 @@ bool ParseBool(const napi_env& env, const napi_value& value, bool& result) } if (napi_get_value_bool(env, value, &result) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get value bool"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get value bool"); return false; } return true; @@ -78,7 +74,7 @@ bool ParseInt32(const napi_env& env, const napi_value& value, int32_t& result) return false; } if (napi_get_value_int32(env, value, &result) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get value int32"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get value int32"); return false; } return true; @@ -90,7 +86,7 @@ bool ParseInt64(const napi_env& env, const napi_value& value, int64_t& result) return false; } if (napi_get_value_int64(env, value, &result) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get value int64"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get value int64"); return false; } return true; @@ -102,7 +98,7 @@ bool ParseUint32(const napi_env& env, const napi_value& value, uint32_t& result) return false; } if (napi_get_value_uint32(env, value, &result) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get value uint32"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get value uint32"); return false; } return true; @@ -115,13 +111,13 @@ bool ParseString(const napi_env& env, const napi_value& value, std::string& resu } size_t size; if (napi_get_value_string_utf8(env, value, nullptr, 0, &size) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get string size"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get string size"); return false; } result.reserve(size + 1); result.resize(size); if (napi_get_value_string_utf8(env, value, result.data(), size + 1, &size) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get value string"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get value string"); return false; } return true; @@ -136,10 +132,10 @@ bool ParseStringArray(const napi_env& env, const napi_value& value, std::vector< uint32_t length = 0; napi_get_array_length(env, value, &length); - ACCESSTOKEN_LOG_INFO(LABEL, "Array size is %{public}d", length); + LOGI(ATM_DOMAIN, ATM_TAG, "Array size is %{public}d", length); if (length == 0) { - ACCESSTOKEN_LOG_INFO(LABEL, "Array is empty"); + LOGI(ATM_DOMAIN, ATM_TAG, "Array is empty"); return true; } @@ -213,7 +209,7 @@ bool ParseCallback(const napi_env& env, const napi_value& value, napi_ref& resul return false; } if (napi_create_reference(env, value, 1, &result) != napi_ok) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get value callback"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get value callback"); return false; } return true; diff --git a/frameworks/js/napi/privacy/src/napi_context_common.cpp b/frameworks/js/napi/privacy/src/napi_context_common.cpp index 66e29103d9a8bf1274bfcfa043c75b008459aedf..45e239c623a01ca3b928d384f31208a6b9f79f30 100644 --- a/frameworks/js/napi/privacy/src/napi_context_common.cpp +++ b/frameworks/js/napi/privacy/src/napi_context_common.cpp @@ -17,9 +17,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyContextCommonNapi"}; -} // namespace PrivacyAsyncWorkData::PrivacyAsyncWorkData(napi_env envValue) { env = envValue; @@ -56,10 +53,10 @@ PermActiveStatusPtr::~PermActiveStatusPtr() void UvQueueWorkDeleteRef(uv_work_t *work, int32_t status) { if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Work == nullptr : %{public}d", work == nullptr); + LOGE(PRI_DOMAIN, PRI_TAG, "Work == nullptr : %{public}d", work == nullptr); return; } else if (work->data == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Work->data == nullptr : %{public}d", work->data == nullptr); + LOGE(PRI_DOMAIN, PRI_TAG, "Work->data == nullptr : %{public}d", work->data == nullptr); return; } PermActiveStatusWorker* permActiveStatusWorker = @@ -72,7 +69,7 @@ void UvQueueWorkDeleteRef(uv_work_t *work, int32_t status) delete permActiveStatusWorker; permActiveStatusWorker = nullptr; delete work; - ACCESSTOKEN_LOG_DEBUG(LABEL, "UvQueueWorkDeleteRef end"); + LOGD(PRI_DOMAIN, PRI_TAG, "UvQueueWorkDeleteRef end"); } void PermActiveStatusPtr::DeleteNapiRef() @@ -80,12 +77,12 @@ void PermActiveStatusPtr::DeleteNapiRef() uv_loop_s* loop = nullptr; NAPI_CALL_RETURN_VOID(env_, napi_get_uv_event_loop(env_, &loop)); if (loop == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Loop instance is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "Loop instance is nullptr"); return; } uv_work_t* work = new (std::nothrow) uv_work_t; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Insufficient memory for work!"); return; } @@ -93,7 +90,7 @@ void PermActiveStatusPtr::DeleteNapiRef() PermActiveStatusWorker* permActiveStatusWorker = new (std::nothrow) PermActiveStatusWorker(); if (permActiveStatusWorker == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for RegisterPermStateChangeWorker!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Insufficient memory for RegisterPermStateChangeWorker!"); return; } std::unique_ptr workPtr {permActiveStatusWorker}; @@ -103,7 +100,7 @@ void PermActiveStatusPtr::DeleteNapiRef() work->data = reinterpret_cast(permActiveStatusWorker); NAPI_CALL_RETURN_VOID(env_, uv_queue_work_with_qos(loop, work, [](uv_work_t* work) {}, UvQueueWorkDeleteRef, uv_qos_default)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "DeleteNapiRef"); + LOGD(PRI_DOMAIN, PRI_TAG, "DeleteNapiRef"); uvWorkPtr.release(); workPtr.release(); } @@ -123,25 +120,25 @@ void PermActiveStatusPtr::ActiveStatusChangeCallback(ActiveChangeResponse& resul uv_loop_s* loop = nullptr; NAPI_CALL_RETURN_VOID(env_, napi_get_uv_event_loop(env_, &loop)); if (loop == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Loop instance is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "Loop instance is nullptr"); return; } uv_work_t* work = new (std::nothrow) uv_work_t; if (work == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for work!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Insufficient memory for work!"); return; } std::unique_ptr uvWorkPtr {work}; PermActiveStatusWorker* permActiveStatusWorker = new (std::nothrow) PermActiveStatusWorker(); if (permActiveStatusWorker == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for RegisterPermStateChangeWorker!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Insufficient memory for RegisterPermStateChangeWorker!"); return; } std::unique_ptr workPtr {permActiveStatusWorker}; permActiveStatusWorker->env = env_; permActiveStatusWorker->ref = ref_; permActiveStatusWorker->result = result; - ACCESSTOKEN_LOG_DEBUG(LABEL, + LOGD(PRI_DOMAIN, PRI_TAG, "result: tokenID = %{public}d, permissionName = %{public}s, type = %{public}d", result.tokenID, result.permissionName.c_str(), result.type); permActiveStatusWorker->subscriber = shared_from_this(); @@ -156,7 +153,7 @@ void UvQueueWorkActiveStatusChange(uv_work_t* work, int status) { (void)status; if (work == nullptr || work->data == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Work == nullptr || work->data == nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "Work == nullptr || work->data == nullptr"); return; } std::unique_ptr uvWorkPtr {work}; @@ -166,7 +163,7 @@ void UvQueueWorkActiveStatusChange(uv_work_t* work, int status) napi_handle_scope scope = nullptr; napi_open_handle_scope(permActiveStatusData->env, &scope); if (scope == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Scope is null"); + LOGE(PRI_DOMAIN, PRI_TAG, "Scope is null"); return; } NotifyChangeResponse(permActiveStatusData); @@ -179,7 +176,7 @@ void NotifyChangeResponse(const PermActiveStatusWorker* permActiveStatusData) NAPI_CALL_RETURN_VOID(permActiveStatusData->env, napi_create_object(permActiveStatusData->env, &result)); if (!ConvertActiveChangeResponse(permActiveStatusData->env, result, permActiveStatusData->result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ConvertActiveChangeResponse failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "ConvertActiveChangeResponse failed"); return; } napi_value undefined = nullptr; diff --git a/frameworks/js/napi/privacy/src/permission_record_manager_napi.cpp b/frameworks/js/napi/privacy/src/permission_record_manager_napi.cpp index 1bbb563dc6287a27a2751f745ffde43fb037ffce..af59df17f98de084f77321efaac6187c99faca8d 100644 --- a/frameworks/js/napi/privacy/src/permission_record_manager_napi.cpp +++ b/frameworks/js/napi/privacy/src/permission_record_manager_napi.cpp @@ -44,10 +44,6 @@ static constexpr int32_t THIRD_PARAM = 2; static constexpr int32_t FOURTH_PARAM = 3; static constexpr int32_t FIFTH_PARAM = 4; -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PermissionRecordManagerNapi"}; -} // namespace - static int32_t GetJsErrorCode(int32_t errCode) { int32_t jsCode; @@ -95,7 +91,7 @@ static int32_t GetJsErrorCode(int32_t errCode) jsCode = JS_ERROR_INNER; break; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetJsErrorCode nativeCode(%{public}d) jsCode(%{public}d).", errCode, jsCode); + LOGD(PRI_DOMAIN, PRI_TAG, "GetJsErrorCode nativeCode(%{public}d) jsCode(%{public}d).", errCode, jsCode); return jsCode; } @@ -521,7 +517,7 @@ static bool ParseGetPermissionUsedRecords( static void AddPermissionUsedRecordExecute(napi_env env, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "AddPermissionUsedRecord execute."); + LOGD(PRI_DOMAIN, PRI_TAG, "AddPermissionUsedRecord execute."); RecordManagerAsyncContext* asyncContext = reinterpret_cast(data); if (asyncContext == nullptr) { return; @@ -538,7 +534,7 @@ static void AddPermissionUsedRecordExecute(napi_env env, void* data) static void AddPermissionUsedRecordComplete(napi_env env, napi_status status, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "AddPermissionUsedRecord complete."); + LOGD(PRI_DOMAIN, PRI_TAG, "AddPermissionUsedRecord complete."); RecordManagerAsyncContext* asyncContext = reinterpret_cast(data); std::unique_ptr callbackPtr {asyncContext}; @@ -552,11 +548,11 @@ static void AddPermissionUsedRecordComplete(napi_env env, napi_status status, vo napi_value AddPermissionUsedRecord(napi_env env, napi_callback_info cbinfo) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "AddPermissionUsedRecord begin."); + LOGD(PRI_DOMAIN, PRI_TAG, "AddPermissionUsedRecord begin."); auto *asyncContext = new (std::nothrow) RecordManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(PRI_DOMAIN, PRI_TAG, "New struct fail."); return nullptr; } @@ -589,7 +585,7 @@ napi_value AddPermissionUsedRecord(napi_env env, napi_callback_info cbinfo) static void StartUsingPermissionExecute(napi_env env, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "StartUsingPermission execute."); + LOGD(PRI_DOMAIN, PRI_TAG, "StartUsingPermission execute."); RecordManagerAsyncContext* asyncContext = reinterpret_cast(data); if (asyncContext == nullptr) { return; @@ -601,7 +597,7 @@ static void StartUsingPermissionExecute(napi_env env, void* data) static void StartUsingPermissionComplete(napi_env env, napi_status status, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "StartUsingPermission complete."); + LOGD(PRI_DOMAIN, PRI_TAG, "StartUsingPermission complete."); RecordManagerAsyncContext* asyncContext = reinterpret_cast(data); std::unique_ptr callbackPtr{asyncContext}; @@ -615,10 +611,10 @@ static void StartUsingPermissionComplete(napi_env env, napi_status status, void* napi_value StartUsingPermission(napi_env env, napi_callback_info cbinfo) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "StartUsingPermission begin."); + LOGD(PRI_DOMAIN, PRI_TAG, "StartUsingPermission begin."); auto *asyncContext = new (std::nothrow) RecordManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(PRI_DOMAIN, PRI_TAG, "New struct fail."); return nullptr; } @@ -651,7 +647,7 @@ napi_value StartUsingPermission(napi_env env, napi_callback_info cbinfo) static void StopUsingPermissionExecute(napi_env env, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "StopUsingPermission execute."); + LOGD(PRI_DOMAIN, PRI_TAG, "StopUsingPermission execute."); RecordManagerAsyncContext* asyncContext = reinterpret_cast(data); if (asyncContext == nullptr) { return; @@ -663,7 +659,7 @@ static void StopUsingPermissionExecute(napi_env env, void* data) static void StopUsingPermissionComplete(napi_env env, napi_status status, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "StopUsingPermission complete."); + LOGD(PRI_DOMAIN, PRI_TAG, "StopUsingPermission complete."); RecordManagerAsyncContext* asyncContext = reinterpret_cast(data); std::unique_ptr callbackPtr{asyncContext}; @@ -677,11 +673,11 @@ static void StopUsingPermissionComplete(napi_env env, napi_status status, void* napi_value StopUsingPermission(napi_env env, napi_callback_info cbinfo) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "StopUsingPermission begin."); + LOGD(PRI_DOMAIN, PRI_TAG, "StopUsingPermission begin."); auto *asyncContext = new (std::nothrow) RecordManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(PRI_DOMAIN, PRI_TAG, "New struct fail."); return nullptr; } @@ -714,7 +710,7 @@ napi_value StopUsingPermission(napi_env env, napi_callback_info cbinfo) static void GetPermissionUsedRecordsExecute(napi_env env, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionUsedRecords execute."); + LOGD(PRI_DOMAIN, PRI_TAG, "GetPermissionUsedRecords execute."); RecordManagerAsyncContext* asyncContext = reinterpret_cast(data); if (asyncContext == nullptr) { return; @@ -725,7 +721,7 @@ static void GetPermissionUsedRecordsExecute(napi_env env, void* data) static void GetPermissionUsedRecordsComplete(napi_env env, napi_status status, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionUsedRecords complete."); + LOGD(PRI_DOMAIN, PRI_TAG, "GetPermissionUsedRecords complete."); RecordManagerAsyncContext* asyncContext = reinterpret_cast(data); std::unique_ptr callbackPtr{asyncContext}; @@ -741,10 +737,10 @@ static void GetPermissionUsedRecordsComplete(napi_env env, napi_status status, v napi_value GetPermissionUsedRecords(napi_env env, napi_callback_info cbinfo) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionUsedRecords begin."); + LOGD(PRI_DOMAIN, PRI_TAG, "GetPermissionUsedRecords begin."); auto *asyncContext = new (std::nothrow) RecordManagerAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(PRI_DOMAIN, PRI_TAG, "New struct fail."); return nullptr; } @@ -950,7 +946,7 @@ napi_value RegisterPermActiveChangeCallback(napi_env env, napi_callback_info cbI RegisterPermActiveChangeContext* registerPermActiveChangeContext = new (std::nothrow) RegisterPermActiveChangeContext(); if (registerPermActiveChangeContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for registerPermActiveChangeContext!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Insufficient memory for registerPermActiveChangeContext!"); return nullptr; } std::unique_ptr callbackPtr {registerPermActiveChangeContext}; @@ -958,14 +954,14 @@ napi_value RegisterPermActiveChangeCallback(napi_env env, napi_callback_info cbI return nullptr; } if (IsExistRegister(registerPermActiveChangeContext)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Subscribe failed. The current subscriber has been existed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Subscribe failed. The current subscriber has been existed"); std::string errMsg = GetErrorMessage(JsErrorCode::JS_ERROR_PARAM_INVALID); NAPI_CALL(env, napi_throw(env, GenerateBusinessError(env, JsErrorCode::JS_ERROR_PARAM_INVALID, errMsg))); return nullptr; } int32_t result = PrivacyKit::RegisterPermActiveStatusCallback(registerPermActiveChangeContext->subscriber); if (result != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RegisterPermActiveStatusCallback failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "RegisterPermActiveStatusCallback failed"); int32_t jsCode = GetJsErrorCode(result); std::string errMsg = GetErrorMessage(jsCode); NAPI_CALL(env, napi_throw(env, GenerateBusinessError(env, jsCode, errMsg))); @@ -974,7 +970,7 @@ napi_value RegisterPermActiveChangeCallback(napi_env env, napi_callback_info cbI { std::lock_guard lock(g_lockForPermActiveChangeSubscribers); if (g_permActiveChangeSubscribers.size() >= MAX_CALLBACK_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Subscribers size has reached max value"); + LOGE(PRI_DOMAIN, PRI_TAG, "Subscribers size has reached max value"); return nullptr; } g_permActiveChangeSubscribers.emplace_back(registerPermActiveChangeContext); @@ -988,7 +984,7 @@ napi_value UnregisterPermActiveChangeCallback(napi_env env, napi_callback_info c UnregisterPermActiveChangeContext* unregisterPermActiveChangeContext = new (std::nothrow) UnregisterPermActiveChangeContext(); if (unregisterPermActiveChangeContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Insufficient memory for unregisterPermActiveChangeContext!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Insufficient memory for unregisterPermActiveChangeContext!"); return nullptr; } std::unique_ptr callbackPtr {unregisterPermActiveChangeContext}; @@ -997,7 +993,7 @@ napi_value UnregisterPermActiveChangeCallback(napi_env env, napi_callback_info c } std::vector batchPermActiveChangeSubscribers; if (!FindAndGetSubscriber(unregisterPermActiveChangeContext, batchPermActiveChangeSubscribers)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Unsubscribe failed. The current subscriber does not exist"); + LOGE(PRI_DOMAIN, PRI_TAG, "Unsubscribe failed. The current subscriber does not exist"); std::string errMsg = GetErrorMessage(JsErrorCode::JS_ERROR_PARAM_INVALID); NAPI_CALL(env, napi_throw(env, GenerateBusinessError(env, JsErrorCode::JS_ERROR_PARAM_INVALID, errMsg))); return nullptr; @@ -1007,7 +1003,7 @@ napi_value UnregisterPermActiveChangeCallback(napi_env env, napi_callback_info c if (result == RET_SUCCESS) { DeleteRegisterInVector(item); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "UnregisterPermActiveChangeCompleted failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "UnregisterPermActiveChangeCompleted failed"); int32_t jsCode = GetJsErrorCode(result); std::string errMsg = GetErrorMessage(jsCode); NAPI_CALL(env, napi_throw(env, GenerateBusinessError(env, jsCode, errMsg))); @@ -1058,7 +1054,7 @@ static bool ParseGetPermissionUsedType(const napi_env env, const napi_callback_i static void GetPermissionUsedTypeInfosExecute(napi_env env, void* data) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionUsedTypeInfos execute."); + LOGD(PRI_DOMAIN, PRI_TAG, "GetPermissionUsedTypeInfos execute."); PermissionUsedTypeAsyncContext* asyncContext = reinterpret_cast(data); if (asyncContext == nullptr) { @@ -1088,7 +1084,7 @@ static void ConvertPermissionUsedTypeInfo(const napi_env& env, napi_value& value static void ProcessPermissionUsedTypeInfoResult(const napi_env& env, napi_value& value, const std::vector& results) { - ACCESSTOKEN_LOG_INFO(LABEL, "Size is %{public}zu", results.size()); + LOGI(PRI_DOMAIN, PRI_TAG, "Size is %{public}zu", results.size()); size_t index = 0; NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &value)); for (const auto& result : results) { @@ -1102,7 +1098,7 @@ static void ProcessPermissionUsedTypeInfoResult(const napi_env& env, napi_value& static void GetPermissionUsedTypeInfosComplete(napi_env env, napi_status status, void* data) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetPermissionUsedTypeInfos complete."); + LOGI(PRI_DOMAIN, PRI_TAG, "GetPermissionUsedTypeInfos complete."); PermissionUsedTypeAsyncContext* asyncContext = reinterpret_cast(data); std::unique_ptr callbackPtr{asyncContext}; @@ -1122,11 +1118,11 @@ static void GetPermissionUsedTypeInfosComplete(napi_env env, napi_status status, napi_value GetPermissionUsedTypeInfos(napi_env env, napi_callback_info cbinfo) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetPermissionUsedTypeInfos begin."); + LOGI(PRI_DOMAIN, PRI_TAG, "GetPermissionUsedTypeInfos begin."); auto *asyncContext = new (std::nothrow) PermissionUsedTypeAsyncContext(env); if (asyncContext == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New struct fail."); + LOGE(PRI_DOMAIN, PRI_TAG, "New struct fail."); return nullptr; } diff --git a/frameworks/privacy/include/privacy_camera_service_ipc_interface_code.h b/frameworks/privacy/include/privacy_camera_service_ipc_interface_code.h deleted file mode 100644 index 254e81b32e7fba73dca9a3f2dba473c305570bd8..0000000000000000000000000000000000000000 --- a/frameworks/privacy/include/privacy_camera_service_ipc_interface_code.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2023 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 PRIVACY_CAMERA_SERVICE_IPC_INTERFACE_CODE_H -#define PRIVACY_CAMERA_SERVICE_IPC_INTERFACE_CODE_H - -namespace OHOS { -namespace Security { -namespace AccessToken { -enum PrivacyCameraServiceInterfaceCode { - CAMERA_SERVICE_IS_CAMERA_MUTED = 13, - CAMERA_SERVICE_MUTE_CAMERA_PERSIST = 22, -}; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS - -#endif // PRIVACY_CAMERA_SERVICE_IPC_INTERFACE_CODE_H diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_callback_stubs.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_callback_stubs.cpp index bfa1c4dde208004fab0d4bad2f0c009a155002bf..1e206e5eb002ccfa384c50bfe58c214ef58aea8f 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_callback_stubs.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_callback_stubs.cpp @@ -30,9 +30,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenCallbackStubs" -}; #ifdef TOKEN_SYNC_ENABLE static const int32_t ACCESSTOKEN_UID = 3020; #endif // TOKEN_SYNC_ENABLE @@ -41,10 +38,11 @@ static const int32_t ACCESSTOKEN_UID = 3020; int32_t PermissionStateChangeCallbackStub::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code); + LOGD(ATM_DOMAIN, ATM_TAG, "Entry, code: 0x%{public}x", code); std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != IPermissionStateCallback::GetDescriptor()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, + "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); return ERROR_IPC_REQUEST_FAIL; } @@ -53,7 +51,7 @@ int32_t PermissionStateChangeCallbackStub::OnRemoteRequest( PermStateChangeInfo result; sptr resultSptr = data.ReadParcelable(); if (resultSptr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail"); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable fail"); return ERR_READ_PARCEL_FAILED; } @@ -68,10 +66,10 @@ int32_t PermissionStateChangeCallbackStub::OnRemoteRequest( int32_t TokenSyncCallbackStub::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called."); + LOGI(ATM_DOMAIN, ATM_TAG, "Called."); std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != ITokenSyncCallback::GetDescriptor()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get unexpect descriptor, descriptor = %{public}s", + LOGE(ATM_DOMAIN, ATM_TAG, "Get unexpect descriptor, descriptor = %{public}s", Str16ToStr8(descriptor).c_str()); return ERROR_IPC_REQUEST_FAIL; } @@ -95,7 +93,7 @@ int32_t TokenSyncCallbackStub::OnRemoteRequest( void TokenSyncCallbackStub::GetRemoteHapTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied, func = %{public}s", __func__); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied, func = %{public}s", __func__); reply.WriteInt32(ERR_IDENTITY_CHECK_FAILED); return; } @@ -110,7 +108,7 @@ void TokenSyncCallbackStub::GetRemoteHapTokenInfoInner(MessageParcel& data, Mess void TokenSyncCallbackStub::DeleteRemoteHapTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied, func = %{public}s", __func__); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied, func = %{public}s", __func__); reply.WriteInt32(ERR_IDENTITY_CHECK_FAILED); return; } @@ -123,7 +121,7 @@ void TokenSyncCallbackStub::DeleteRemoteHapTokenInfoInner(MessageParcel& data, M void TokenSyncCallbackStub::UpdateRemoteHapTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied, func = %{public}s", __func__); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied, func = %{public}s", __func__); reply.WriteInt32(ERR_IDENTITY_CHECK_FAILED); return; } diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_callbacks.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_callbacks.cpp index 164badc90b4d699a959066ff56ae096b1b5b4706..e4b27ce14682d33c3b4d90cfee2b6da783b65c93 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_callbacks.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_callbacks.cpp @@ -21,10 +21,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenCallbacks" -}; - PermissionStateChangeCallback::PermissionStateChangeCallback( const std::shared_ptr& customizedCallback) : customizedCallback_(customizedCallback) @@ -36,7 +32,7 @@ PermissionStateChangeCallback::~PermissionStateChangeCallback() void PermissionStateChangeCallback::PermStateChangeCallback(PermStateChangeInfo& result) { if (customizedCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "CustomizedCallback_ is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "CustomizedCallback_ is nullptr"); return; } @@ -57,7 +53,7 @@ TokenSyncCallback::~TokenSyncCallback() int32_t TokenSyncCallback::GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) { if (tokenSyncCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get nullptr, name = tokenSyncCallback_."); + LOGE(ATM_DOMAIN, ATM_TAG, "Get nullptr, name = tokenSyncCallback_."); return TOKEN_SYNC_PARAMS_INVALID; } return tokenSyncCallback_->GetRemoteHapTokenInfo(deviceID, tokenID); @@ -66,7 +62,7 @@ int32_t TokenSyncCallback::GetRemoteHapTokenInfo(const std::string& deviceID, Ac int32_t TokenSyncCallback::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) { if (tokenSyncCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get nullptr, name = tokenSyncCallback_."); + LOGE(ATM_DOMAIN, ATM_TAG, "Get nullptr, name = tokenSyncCallback_."); return TOKEN_SYNC_PARAMS_INVALID; } return tokenSyncCallback_->DeleteRemoteHapTokenInfo(tokenID); @@ -75,7 +71,7 @@ int32_t TokenSyncCallback::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) int32_t TokenSyncCallback::UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo) { if (tokenSyncCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get nullptr, name = tokenSyncCallback_."); + LOGE(ATM_DOMAIN, ATM_TAG, "Get nullptr, name = tokenSyncCallback_."); return TOKEN_SYNC_PARAMS_INVALID; } return tokenSyncCallback_->UpdateRemoteHapTokenInfo(tokenInfo); diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_death_recipient.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_death_recipient.cpp index 095981870380b80fe7e1068bfc8903106b0ac157..5169c0dce6aa496453b2a25c75988dd4a293231d 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_death_recipient.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_death_recipient.cpp @@ -19,14 +19,9 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenDeathRecipient"}; -} // namespace - void AccessTokenDeathRecipient::OnRemoteDied(const wptr& object) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called", __func__); + LOGI(ATM_DOMAIN, ATM_TAG, "%{public}s called", __func__); AccessTokenManagerClient::GetInstance().OnRemoteDiedHandle(); } } // namespace AccessToken diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp index 61dc6f00cdcf1f3eca602fa6ad5841f3aa1364be..13d7fc988144af6de69ae525b2b1aebd6285e6ee 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp @@ -33,7 +33,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenKit"}; static const uint64_t SYSTEM_APP_MASK = (static_cast(1) << 32); static const uint64_t TOKEN_ID_LOWMASK = 0xffffffff; static const int INVALID_DLP_TOKEN_FLAG = -1; @@ -43,10 +42,10 @@ static const int FIRSTCALLER_TOKENID_DEFAULT = 0; PermUsedTypeEnum AccessTokenKit::GetPermissionUsedType( AccessTokenID tokenID, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d, permissionName=%{public}s.", + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, permissionName=%{public}s.", tokenID, permissionName.c_str()); if ((tokenID == INVALID_TOKENID) || (!DataValidator::IsPermissionNameValid(permissionName))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Input param failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Input param failed."); return PermUsedTypeEnum::INVALID_USED_TYPE; } return AccessTokenManagerClient::GetInstance().GetPermissionUsedType(tokenID, permissionName); @@ -55,14 +54,14 @@ PermUsedTypeEnum AccessTokenKit::GetPermissionUsedType( int AccessTokenKit::GrantPermissionForSpecifiedTime( AccessTokenID tokenID, const std::string& permissionName, uint32_t onceTime) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID=%{public}d, permissionName=%{public}s, onceTime=%{public}d.", + LOGI(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, permissionName=%{public}s, onceTime=%{public}d.", tokenID, permissionName.c_str(), onceTime); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid tokenID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid tokenID"); return AccessTokenError::ERR_PARAM_INVALID; } if (!DataValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid permissionName"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid permissionName"); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().GrantPermissionForSpecifiedTime(tokenID, permissionName, onceTime); @@ -71,13 +70,13 @@ int AccessTokenKit::GrantPermissionForSpecifiedTime( AccessTokenIDEx AccessTokenKit::AllocHapToken(const HapInfoParams& info, const HapPolicyParams& policy) { AccessTokenIDEx res = {0}; - ACCESSTOKEN_LOG_INFO(LABEL, "UserID: %{public}d, bundleName :%{public}s, \ + LOGI(ATM_DOMAIN, ATM_TAG, "UserID: %{public}d, bundleName :%{public}s, \ permList: %{public}zu, stateList: %{public}zu", info.userID, info.bundleName.c_str(), policy.permList.size(), policy.permStateList.size()); if ((!DataValidator::IsUserIdValid(info.userID)) || !DataValidator::IsAppIDDescValid(info.appIDDesc) || !DataValidator::IsBundleNameValid(info.bundleName) || !DataValidator::IsAplNumValid(policy.apl) || !DataValidator::IsDomainValid(policy.domain) || !DataValidator::IsDlpTypeValid(info.dlpType)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Input param failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Input param failed"); return res; } return AccessTokenManagerClient::GetInstance().AllocHapToken(info, policy); @@ -93,13 +92,13 @@ int32_t AccessTokenKit::InitHapToken(const HapInfoParams& info, HapPolicyParams& int32_t AccessTokenKit::InitHapToken(const HapInfoParams& info, HapPolicyParams& policy, AccessTokenIDEx& fullTokenId, HapInfoCheckResult& result) { - ACCESSTOKEN_LOG_INFO(LABEL, "UserID: %{public}d, bundleName :%{public}s, \ + LOGI(ATM_DOMAIN, ATM_TAG, "UserID: %{public}d, bundleName :%{public}s, \ permList: %{public}zu, stateList: %{public}zu", info.userID, info.bundleName.c_str(), policy.permList.size(), policy.permStateList.size()); if ((!DataValidator::IsUserIdValid(info.userID)) || !DataValidator::IsAppIDDescValid(info.appIDDesc) || !DataValidator::IsBundleNameValid(info.bundleName) || !DataValidator::IsAplNumValid(policy.apl) || !DataValidator::IsDomainValid(policy.domain) || !DataValidator::IsDlpTypeValid(info.dlpType)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Input param failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Input param failed"); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().InitHapToken(info, policy, fullTokenId, result); @@ -107,12 +106,12 @@ permList: %{public}zu, stateList: %{public}zu", AccessTokenID AccessTokenKit::AllocLocalTokenID(const std::string& remoteDeviceID, AccessTokenID remoteTokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeviceID=%{public}s, tokenID=%{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "DeviceID=%{public}s, Id=%{public}d", ConstantCommon::EncryptDevId(remoteDeviceID).c_str(), remoteTokenID); #ifdef DEBUG_API_PERFORMANCE - ACCESSTOKEN_LOG_DEBUG(LABEL, "Api_performance:start call"); + LOGD(ATM_DOMAIN, ATM_TAG, "Api_performance:start call"); AccessTokenID resID = AccessTokenManagerClient::GetInstance().AllocLocalTokenID(remoteDeviceID, remoteTokenID); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Api_performance:end call"); + LOGD(ATM_DOMAIN, ATM_TAG, "Api_performance:end call"); return resID; #else return AccessTokenManagerClient::GetInstance().AllocLocalTokenID(remoteDeviceID, remoteTokenID); @@ -129,12 +128,12 @@ int32_t AccessTokenKit::UpdateHapToken( int32_t AccessTokenKit::UpdateHapToken(AccessTokenIDEx& tokenIdEx, const UpdateHapInfoParams& info, const HapPolicyParams& policy, HapInfoCheckResult& result) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d, isSystemApp: %{public}d, \ + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID: %{public}d, isSystemApp: %{public}d, \ permList: %{public}zu, stateList: %{public}zu", tokenIdEx.tokenIdExStruct.tokenID, info.isSystemApp, policy.permList.size(), policy.permStateList.size()); if ((tokenIdEx.tokenIdExStruct.tokenID == INVALID_TOKENID) || (!DataValidator::IsAppIDDescValid(info.appIDDesc)) || (!DataValidator::IsAplNumValid(policy.apl))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Input param failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Input param failed"); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().UpdateHapToken(tokenIdEx, info, policy, result); @@ -142,7 +141,7 @@ permList: %{public}zu, stateList: %{public}zu", int AccessTokenKit::DeleteToken(AccessTokenID tokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID=%{public}d.", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (tokenID == INVALID_TOKENID) { return AccessTokenError::ERR_PARAM_INVALID; } @@ -151,9 +150,9 @@ int AccessTokenKit::DeleteToken(AccessTokenID tokenID) ATokenTypeEnum AccessTokenKit::GetTokenType(AccessTokenID tokenID) __attribute__((no_sanitize("cfi"))) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid."); return TOKEN_INVALID; } return AccessTokenManagerClient::GetInstance().GetTokenType(tokenID); @@ -161,9 +160,9 @@ ATokenTypeEnum AccessTokenKit::GetTokenType(AccessTokenID tokenID) __attribute__ ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return TOKEN_INVALID; } AccessTokenIDInner *idInner = reinterpret_cast(&tokenID); @@ -173,9 +172,9 @@ ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID) ATokenTypeEnum AccessTokenKit::GetTokenType(FullTokenID tokenID) { AccessTokenID id = tokenID & TOKEN_ID_LOWMASK; - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", id); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", id); if (id == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return TOKEN_INVALID; } return AccessTokenManagerClient::GetInstance().GetTokenType(id); @@ -184,9 +183,9 @@ ATokenTypeEnum AccessTokenKit::GetTokenType(FullTokenID tokenID) ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(FullTokenID tokenID) { AccessTokenID id = tokenID & TOKEN_ID_LOWMASK; - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", id); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", id); if (id == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return TOKEN_INVALID; } AccessTokenIDInner *idInner = reinterpret_cast(&id); @@ -196,10 +195,10 @@ ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(FullTokenID tokenID) AccessTokenID AccessTokenKit::GetHapTokenID( int32_t userID, const std::string& bundleName, int32_t instIndex) __attribute__((no_sanitize("cfi"))) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "UserID=%{public}d, bundleName=%{public}s, instIndex=%{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "UserID=%{public}d, bundleName=%{public}s, instIndex=%{public}d.", userID, bundleName.c_str(), instIndex); if ((!DataValidator::IsUserIdValid(userID)) || (!DataValidator::IsBundleNameValid(bundleName))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Hap token param check failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Hap token param check failed"); return INVALID_TOKENID; } AccessTokenIDEx tokenIdEx = @@ -210,10 +209,10 @@ AccessTokenID AccessTokenKit::GetHapTokenID( AccessTokenIDEx AccessTokenKit::GetHapTokenIDEx(int32_t userID, const std::string& bundleName, int32_t instIndex) { AccessTokenIDEx tokenIdEx = {0}; - ACCESSTOKEN_LOG_DEBUG(LABEL, "UserID=%{public}d, bundleName=%{public}s, instIndex=%{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "UserID=%{public}d, bundleName=%{public}s, instIndex=%{public}d.", userID, bundleName.c_str(), instIndex); if ((!DataValidator::IsUserIdValid(userID)) || (!DataValidator::IsBundleNameValid(bundleName))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Hap token param check failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Hap token param check failed"); return tokenIdEx; } return AccessTokenManagerClient::GetInstance().GetHapTokenID(userID, bundleName, instIndex); @@ -222,9 +221,9 @@ AccessTokenIDEx AccessTokenKit::GetHapTokenIDEx(int32_t userID, const std::strin int AccessTokenKit::GetHapTokenInfo( AccessTokenID tokenID, HapTokenInfo& hapTokenInfoRes) __attribute__((no_sanitize("cfi"))) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (GetTokenTypeFlag(tokenID) != TOKEN_HAP) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID =%{public}d is invalid", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id =%{public}d is invalid", tokenID); return AccessTokenError::ERR_PARAM_INVALID; } @@ -234,9 +233,9 @@ int AccessTokenKit::GetHapTokenInfo( int AccessTokenKit::GetNativeTokenInfo( AccessTokenID tokenID, NativeTokenInfo& nativeTokenInfoRes) __attribute__((no_sanitize("cfi"))) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (GetTokenTypeFlag(tokenID) != TOKEN_NATIVE && GetTokenTypeFlag(tokenID) != TOKEN_SHELL) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID =%{public}d is invalid", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id =%{public}d is invalid", tokenID); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().GetNativeTokenInfo(tokenID, nativeTokenInfoRes); @@ -245,15 +244,15 @@ int AccessTokenKit::GetNativeTokenInfo( PermissionOper AccessTokenKit::GetSelfPermissionsState(std::vector& permList, PermissionGrantInfo& info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermList.size=%{public}zu.", permList.size()); + LOGD(ATM_DOMAIN, ATM_TAG, "PermList.size=%{public}zu.", permList.size()); return AccessTokenManagerClient::GetInstance().GetSelfPermissionsState(permList, info); } int32_t AccessTokenKit::GetPermissionsStatus(AccessTokenID tokenID, std::vector& permList) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d, permList.size=%{public}zu.", tokenID, permList.size()); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, permList.size=%{public}zu.", tokenID, permList.size()); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().GetPermissionsStatus(tokenID, permList); @@ -261,10 +260,10 @@ int32_t AccessTokenKit::GetPermissionsStatus(AccessTokenID tokenID, std::vector< int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName, bool crossIpc) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d, permissionName=%{public}s, crossIpc=%{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, permissionName=%{public}s, crossIpc=%{public}d.", tokenID, permissionName.c_str(), crossIpc); if (!DataValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName is invalid"); return PERMISSION_DENIED; } @@ -283,7 +282,7 @@ int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& int AccessTokenKit::VerifyAccessToken( AccessTokenID callerTokenID, AccessTokenID firstTokenID, const std::string& permissionName, bool crossIpc) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "CallerToken=%{public}d, firstToken=%{public}d, permissionName=%{public}s.", + LOGD(ATM_DOMAIN, ATM_TAG, "Caller=%{public}d, firstToken=%{public}d, permissionName=%{public}s.", callerTokenID, firstTokenID, permissionName.c_str()); int ret = AccessTokenKit::VerifyAccessToken(callerTokenID, permissionName, crossIpc); if (ret != PERMISSION_GRANTED) { @@ -297,7 +296,7 @@ int AccessTokenKit::VerifyAccessToken( int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d, permissionName=%{public}s.", + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, permissionName=%{public}s.", tokenID, permissionName.c_str()); uint32_t code; if (!TransferPermissionToOpcode(permissionName, code)) { @@ -314,7 +313,7 @@ int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& int AccessTokenKit::VerifyAccessToken( AccessTokenID callerTokenID, AccessTokenID firstTokenID, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "CallerToken=%{public}d, firstToken=%{public}d, permissionName=%{public}s.", + LOGD(ATM_DOMAIN, ATM_TAG, "Caller=%{public}d, firstToken=%{public}d, permissionName=%{public}s.", callerTokenID, firstTokenID, permissionName.c_str()); int ret = AccessTokenKit::VerifyAccessToken(callerTokenID, permissionName); if (ret != PERMISSION_GRANTED) { @@ -372,14 +371,14 @@ int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::vector& permDefList) __attribute__((no_sanitize("cfi"))) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return AccessTokenError::ERR_PARAM_INVALID; } @@ -399,9 +398,9 @@ int AccessTokenKit::GetDefPermissions( int AccessTokenKit::GetReqPermissions( AccessTokenID tokenID, std::vector& reqPermList, bool isSystemGrant) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d, isSystemGrant=%{public}d.", tokenID, isSystemGrant); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, isSystemGrant=%{public}d.", tokenID, isSystemGrant); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return AccessTokenError::ERR_PARAM_INVALID; } @@ -410,14 +409,14 @@ int AccessTokenKit::GetReqPermissions( int AccessTokenKit::GetPermissionFlag(AccessTokenID tokenID, const std::string& permissionName, uint32_t& flag) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d, permissionName=%{public}s.", + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, permissionName=%{public}s.", tokenID, permissionName.c_str()); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return AccessTokenError::ERR_PARAM_INVALID; } if (!DataValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName is invalid"); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().GetPermissionFlag(tokenID, permissionName, flag); @@ -425,18 +424,18 @@ int AccessTokenKit::GetPermissionFlag(AccessTokenID tokenID, const std::string& int AccessTokenKit::GrantPermission(AccessTokenID tokenID, const std::string& permissionName, uint32_t flag) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d, permissionName=%{public}s, flag=%{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, permissionName=%{public}s, flag=%{public}d.", tokenID, permissionName.c_str(), flag); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return AccessTokenError::ERR_PARAM_INVALID; } if (!DataValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName is invalid"); return AccessTokenError::ERR_PARAM_INVALID; } if (!DataValidator::IsPermissionFlagValid(flag)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Flag is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "Flag is invalid"); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().GrantPermission(tokenID, permissionName, flag); @@ -444,18 +443,18 @@ int AccessTokenKit::GrantPermission(AccessTokenID tokenID, const std::string& pe int AccessTokenKit::RevokePermission(AccessTokenID tokenID, const std::string& permissionName, uint32_t flag) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d, permissionName=%{public}s, flag=%{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, permissionName=%{public}s, flag=%{public}d.", tokenID, permissionName.c_str(), flag); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid tokenID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid tokenID"); return AccessTokenError::ERR_PARAM_INVALID; } if (!DataValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid permissionName"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid permissionName"); return AccessTokenError::ERR_PARAM_INVALID; } if (!DataValidator::IsPermissionFlagValid(flag)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid flag"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid flag"); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().RevokePermission(tokenID, permissionName, flag); @@ -463,9 +462,9 @@ int AccessTokenKit::RevokePermission(AccessTokenID tokenID, const std::string& p int AccessTokenKit::ClearUserGrantedPermissionState(AccessTokenID tokenID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "Id is invalid"); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().ClearUserGrantedPermissionState(tokenID); @@ -474,18 +473,18 @@ int AccessTokenKit::ClearUserGrantedPermissionState(AccessTokenID tokenID) int32_t AccessTokenKit::SetPermissionRequestToggleStatus(const std::string& permissionName, uint32_t status, int32_t userID = 0) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermissionName=%{public}s, status=%{public}d, userID=%{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "PermissionName=%{public}s, status=%{public}d, userID=%{public}d.", permissionName.c_str(), status, userID); if (!DataValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName is invalid."); return AccessTokenError::ERR_PARAM_INVALID; } if (!DataValidator::IsToggleStatusValid(status)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Toggle status is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Toggle status is invalid."); return AccessTokenError::ERR_PARAM_INVALID; } if (!DataValidator::IsUserIdValid(userID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UserID is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "UserID is invalid."); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().SetPermissionRequestToggleStatus(permissionName, status, userID); @@ -494,14 +493,14 @@ int32_t AccessTokenKit::SetPermissionRequestToggleStatus(const std::string& perm int32_t AccessTokenKit::GetPermissionRequestToggleStatus(const std::string& permissionName, uint32_t& status, int32_t userID = 0) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermissionName=%{public}s, userID=%{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "PermissionName=%{public}s, userID=%{public}d.", permissionName.c_str(), userID); if (!DataValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName is invalid."); return AccessTokenError::ERR_PARAM_INVALID; } if (!DataValidator::IsUserIdValid(userID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UserID is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "UserID is invalid."); return AccessTokenError::ERR_PARAM_INVALID; } return AccessTokenManagerClient::GetInstance().GetPermissionRequestToggleStatus(permissionName, status, userID); @@ -510,14 +509,14 @@ int32_t AccessTokenKit::GetPermissionRequestToggleStatus(const std::string& perm int32_t AccessTokenKit::RegisterPermStateChangeCallback( const std::shared_ptr& callback) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called"); return AccessTokenManagerClient::GetInstance().RegisterPermStateChangeCallback(callback, SYSTEM_REGISTER_TYPE); } int32_t AccessTokenKit::UnRegisterPermStateChangeCallback( const std::shared_ptr& callback) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called"); return AccessTokenManagerClient::GetInstance().UnRegisterPermStateChangeCallback(callback, SYSTEM_REGISTER_TYPE); } @@ -535,9 +534,9 @@ int32_t AccessTokenKit::UnRegisterSelfPermStateChangeCallback( int32_t AccessTokenKit::GetHapDlpFlag(AccessTokenID tokenID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "Id is invalid"); return INVALID_DLP_TOKEN_FLAG; } AccessTokenIDInner *idInner = reinterpret_cast(&tokenID); @@ -555,9 +554,9 @@ int32_t AccessTokenKit::ReloadNativeTokenInfo() int AccessTokenKit::GetHapTokenInfoExtension(AccessTokenID tokenID, HapTokenInfoExt& info) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (GetTokenTypeFlag(tokenID) != TOKEN_HAP) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID =%{public}d is invalid.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id =%{public}d is invalid.", tokenID); return AccessTokenError::ERR_PARAM_INVALID; } @@ -567,7 +566,7 @@ int AccessTokenKit::GetHapTokenInfoExtension(AccessTokenID tokenID, HapTokenInfo AccessTokenID AccessTokenKit::GetNativeTokenId(const std::string& processName) { if (!DataValidator::IsProcessNameValid(processName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ProcessName is invalid, processName=%{public}s", processName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Process is invalid, processName=%{public}s", processName.c_str()); return INVALID_TOKENID; } return AccessTokenManagerClient::GetInstance().GetNativeTokenId(processName); @@ -576,9 +575,9 @@ AccessTokenID AccessTokenKit::GetNativeTokenId(const std::string& processName) #ifdef TOKEN_SYNC_ENABLE int AccessTokenKit::GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSync& hapSync) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d.", tokenID); if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "Id is invalid"); return AccessTokenError::ERR_PARAM_INVALID; } @@ -588,47 +587,47 @@ int AccessTokenKit::GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInf int AccessTokenKit::SetRemoteHapTokenInfo(const std::string& deviceID, const HapTokenInfoForSync& hapSync) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "DeviceID=%{public}s, tokenID=%{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "DeviceID=%{public}s, Id=%{public}d.", ConstantCommon::EncryptDevId(deviceID).c_str(), hapSync.baseInfo.tokenID); return AccessTokenManagerClient::GetInstance().SetRemoteHapTokenInfo(deviceID, hapSync); } int AccessTokenKit::DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "DeviceID=%{public}s, tokenID=%{public}d.", + LOGD(ATM_DOMAIN, ATM_TAG, "DeviceID=%{public}s, Id=%{public}d.", ConstantCommon::EncryptDevId(deviceID).c_str(), tokenID); return AccessTokenManagerClient::GetInstance().DeleteRemoteToken(deviceID, tokenID); } int AccessTokenKit::DeleteRemoteDeviceTokens(const std::string& deviceID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "DeviceID=%{public}s.", ConstantCommon::EncryptDevId(deviceID).c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "DeviceID=%{public}s.", ConstantCommon::EncryptDevId(deviceID).c_str()); return AccessTokenManagerClient::GetInstance().DeleteRemoteDeviceTokens(deviceID); } AccessTokenID AccessTokenKit::GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "DeviceID=%{public}s., tokenID=%{public}d", + LOGD(ATM_DOMAIN, ATM_TAG, "DeviceID=%{public}s., Id=%{public}d", ConstantCommon::EncryptDevId(deviceID).c_str(), tokenID); return AccessTokenManagerClient::GetInstance().GetRemoteNativeTokenID(deviceID, tokenID); } int32_t AccessTokenKit::RegisterTokenSyncCallback(const std::shared_ptr& syncCallback) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Call RegisterTokenSyncCallback."); + LOGD(ATM_DOMAIN, ATM_TAG, "Call RegisterTokenSyncCallback."); return AccessTokenManagerClient::GetInstance().RegisterTokenSyncCallback(syncCallback); } int32_t AccessTokenKit::UnRegisterTokenSyncCallback() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Call UnRegisterTokenSyncCallback."); + LOGD(ATM_DOMAIN, ATM_TAG, "Call UnRegisterTokenSyncCallback."); return AccessTokenManagerClient::GetInstance().UnRegisterTokenSyncCallback(); } #endif void AccessTokenKit::DumpTokenInfo(const AtmToolsParamInfo& info, std::string& dumpInfo) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID=%{public}d, bundleName=%{public}s, processName=%{public}s.", + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, bundleName=%{public}s, processName=%{public}s.", info.tokenId, info.bundleName.c_str(), info.processName.c_str()); AccessTokenManagerClient::GetInstance().DumpTokenInfo(info, dumpInfo); } @@ -651,19 +650,19 @@ void AccessTokenKit::GetPermissionManagerInfo(PermissionGrantInfo& info) int32_t AccessTokenKit::InitUserPolicy( const std::vector& userList, const std::vector& permList) { - ACCESSTOKEN_LOG_INFO(LABEL, "Enter."); + LOGI(ATM_DOMAIN, ATM_TAG, "Enter."); return AccessTokenManagerClient::GetInstance().InitUserPolicy(userList, permList); } int32_t AccessTokenKit::UpdateUserPolicy(const std::vector& userList) { - ACCESSTOKEN_LOG_INFO(LABEL, "Enter."); + LOGI(ATM_DOMAIN, ATM_TAG, "Enter."); return AccessTokenManagerClient::GetInstance().UpdateUserPolicy(userList); } int32_t AccessTokenKit::ClearUserPolicy() { - ACCESSTOKEN_LOG_INFO(LABEL, "Enter."); + LOGI(ATM_DOMAIN, ATM_TAG, "Enter."); return AccessTokenManagerClient::GetInstance().ClearUserPolicy(); } diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp index 4e8af1eaa426d54bdc7fba62ed3ecf53223afc60..1d53bf40fa762dafeddf4317619281be0d8934eb 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp @@ -30,14 +30,11 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenManagerClient" -}; static constexpr int32_t VALUE_MAX_LEN = 32; static const char* ACCESS_TOKEN_SERVICE_INIT_KEY = "accesstoken.permission.init"; std::recursive_mutex g_instanceMutex; -} // namespace static const uint32_t MAX_CALLBACK_MAP_SIZE = 200; +} // namespace AccessTokenManagerClient& AccessTokenManagerClient::GetInstance() { @@ -57,7 +54,7 @@ AccessTokenManagerClient::AccessTokenManagerClient() AccessTokenManagerClient::~AccessTokenManagerClient() { - ACCESSTOKEN_LOG_ERROR(LABEL, "~AccessTokenManagerClient"); + LOGE(ATM_DOMAIN, ATM_TAG, "~AccessTokenManagerClient"); std::lock_guard lock(proxyMutex_); ReleaseProxy(); } @@ -67,7 +64,7 @@ PermUsedTypeEnum AccessTokenManagerClient::GetPermissionUsedType( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return PermUsedTypeEnum::INVALID_USED_TYPE; } return proxy->GetPermissionUsedType(tokenID, permissionName); @@ -82,15 +79,15 @@ int AccessTokenManagerClient::VerifyAccessToken(AccessTokenID tokenID, const std char value[VALUE_MAX_LEN] = {0}; int32_t ret = GetParameter(ACCESS_TOKEN_SERVICE_INIT_KEY, "", value, VALUE_MAX_LEN - 1); if ((ret < 0) || (static_cast(std::atoll(value)) != 0)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "At service has been started, ret=%{public}d.", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "At service has been started, ret=%{public}d.", ret); return PERMISSION_DENIED; } AccessTokenIDInner *idInner = reinterpret_cast(&tokenID); if (static_cast(idInner->type) == TOKEN_NATIVE) { - ACCESSTOKEN_LOG_INFO(LABEL, "At service has not been started."); + LOGI(ATM_DOMAIN, ATM_TAG, "At service has not been started."); return PERMISSION_GRANTED; } - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return PERMISSION_DENIED; } @@ -110,7 +107,7 @@ int AccessTokenManagerClient::GetDefPermission( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } PermissionDefParcel permissionDefParcel; @@ -123,7 +120,7 @@ int AccessTokenManagerClient::GetDefPermissions(AccessTokenID tokenID, std::vect { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } std::vector parcelList; @@ -140,7 +137,7 @@ int AccessTokenManagerClient::GetReqPermissions( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } std::vector parcelList; @@ -157,7 +154,7 @@ int AccessTokenManagerClient::GetPermissionFlag( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->GetPermissionFlag(tokenID, permissionName, flag); @@ -168,13 +165,13 @@ PermissionOper AccessTokenManagerClient::GetSelfPermissionsState(std::vectorGrantPermission(tokenID, permissionName, flag); @@ -246,7 +243,7 @@ int AccessTokenManagerClient::RevokePermission(AccessTokenID tokenID, const std: { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->RevokePermission(tokenID, permissionName, flag); @@ -257,7 +254,7 @@ int AccessTokenManagerClient::GrantPermissionForSpecifiedTime( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->GrantPermissionForSpecifiedTime(tokenID, permissionName, onceTime); @@ -267,7 +264,7 @@ int AccessTokenManagerClient::ClearUserGrantedPermissionState(AccessTokenID toke { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->ClearUserGrantedPermissionState(tokenID); @@ -278,7 +275,7 @@ int32_t AccessTokenManagerClient::SetPermissionRequestToggleStatus(const std::st { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->SetPermissionRequestToggleStatus(permissionName, status, userID); @@ -289,7 +286,7 @@ int32_t AccessTokenManagerClient::GetPermissionRequestToggleStatus(const std::st { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->GetPermissionRequestToggleStatus(permissionName, status, userID); @@ -301,18 +298,18 @@ int32_t AccessTokenManagerClient::CreatePermStateChangeCallback( { std::lock_guard lock(callbackMutex_); if (callbackMap_.size() == MAX_CALLBACK_MAP_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "The maximum number of callback has been reached"); + LOGE(ATM_DOMAIN, ATM_TAG, "The maximum number of callback has been reached"); return AccessTokenError::ERR_CALLBACKS_EXCEED_LIMITATION; } auto goalCallback = callbackMap_.find(customizedCb); if (goalCallback != callbackMap_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Already has the same callback"); + LOGE(ATM_DOMAIN, ATM_TAG, "Already has the same callback"); return AccessTokenError::ERR_CALLBACK_ALREADY_EXIST; } else { callback = new (std::nothrow) PermissionStateChangeCallback(customizedCb); if (!callback) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Memory allocation for callback failed!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Memory allocation for callback failed!"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } } @@ -323,7 +320,7 @@ int32_t AccessTokenManagerClient::RegisterPermStateChangeCallback( const std::shared_ptr& customizedCb, RegisterPermChangeType type) { if (customizedCb == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "CustomizedCb is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "CustomizedCb is nullptr"); return AccessTokenError::ERR_PARAM_INVALID; } @@ -334,7 +331,7 @@ int32_t AccessTokenManagerClient::RegisterPermStateChangeCallback( } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } @@ -342,7 +339,7 @@ int32_t AccessTokenManagerClient::RegisterPermStateChangeCallback( customizedCb->GetScope(scopeParcel.scope); if (scopeParcel.scope.permList.size() > PERMS_LIST_SIZE_MAX) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermList scope oversize"); + LOGE(ATM_DOMAIN, ATM_TAG, "PermList scope oversize"); return AccessTokenError::ERR_PARAM_INVALID; } if (type == SYSTEM_REGISTER_TYPE) { @@ -370,14 +367,14 @@ int32_t AccessTokenManagerClient::UnRegisterPermStateChangeCallback( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } std::lock_guard lock(callbackMutex_); auto goalCallback = callbackMap_.find(customizedCb); if (goalCallback == callbackMap_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GoalCallback already is not exist"); + LOGE(ATM_DOMAIN, ATM_TAG, "GoalCallback already is not exist"); return AccessTokenError::ERR_INTERFACE_NOT_USED_TOGETHER; } int32_t result; @@ -397,7 +394,7 @@ AccessTokenIDEx AccessTokenManagerClient::AllocHapToken(const HapInfoParams& inf AccessTokenIDEx tokenIdEx = { 0 }; auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return tokenIdEx; } HapInfoParcel hapInfoParcel; @@ -413,7 +410,7 @@ int32_t AccessTokenManagerClient::InitHapToken(const HapInfoParams& info, HapPol { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return AccessTokenError::ERR_SERVICE_ABNORMAL; } HapInfoParcel hapInfoParcel; @@ -428,7 +425,7 @@ int AccessTokenManagerClient::DeleteToken(AccessTokenID tokenID) { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->DeleteToken(tokenID); @@ -438,7 +435,7 @@ ATokenTypeEnum AccessTokenManagerClient::GetTokenType(AccessTokenID tokenID) { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return TOKEN_INVALID; } return static_cast(proxy->GetTokenType(tokenID)); @@ -450,7 +447,7 @@ AccessTokenIDEx AccessTokenManagerClient::GetHapTokenID( AccessTokenIDEx result = {0}; auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return result; } return proxy->GetHapTokenID(userID, bundleName, instIndex); @@ -461,7 +458,7 @@ AccessTokenID AccessTokenManagerClient::AllocLocalTokenID( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return INVALID_TOKENID; } return proxy->AllocLocalTokenID(remoteDeviceID, remoteTokenID); @@ -472,7 +469,7 @@ int32_t AccessTokenManagerClient::UpdateHapToken(AccessTokenIDEx& tokenIdEx, con { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } HapPolicyParcel hapPolicyParcel; @@ -484,7 +481,7 @@ int AccessTokenManagerClient::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInf { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } HapTokenInfoParcel hapTokenInfoParcel; @@ -498,7 +495,7 @@ int AccessTokenManagerClient::GetNativeTokenInfo(AccessTokenID tokenID, NativeTo { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } NativeTokenInfoParcel nativeTokenInfoParcel; @@ -512,7 +509,7 @@ int32_t AccessTokenManagerClient::ReloadNativeTokenInfo() { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->ReloadNativeTokenInfo(); @@ -523,7 +520,7 @@ int AccessTokenManagerClient::GetHapTokenInfoExtension(AccessTokenID tokenID, Ha { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return AccessTokenError::ERR_SERVICE_ABNORMAL; } @@ -537,7 +534,7 @@ AccessTokenID AccessTokenManagerClient::GetNativeTokenId(const std::string& proc { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return INVALID_TOKENID; } return proxy->GetNativeTokenId(processName); @@ -548,7 +545,7 @@ int AccessTokenManagerClient::GetHapTokenInfoFromRemote(AccessTokenID tokenID, H { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } @@ -562,7 +559,7 @@ int AccessTokenManagerClient::SetRemoteHapTokenInfo(const std::string& deviceID, { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } @@ -577,7 +574,7 @@ int AccessTokenManagerClient::DeleteRemoteToken(const std::string& deviceID, Acc { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } @@ -589,7 +586,7 @@ AccessTokenID AccessTokenManagerClient::GetRemoteNativeTokenID(const std::string { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return INVALID_TOKENID; } @@ -601,7 +598,7 @@ int AccessTokenManagerClient::DeleteRemoteDeviceTokens(const std::string& device { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } @@ -614,12 +611,12 @@ int32_t AccessTokenManagerClient::RegisterTokenSyncCallback( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return AccessTokenError::ERR_SERVICE_ABNORMAL; } if (syncCallback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Input callback is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Input callback is null."); return AccessTokenError::ERR_PARAM_INVALID; } @@ -638,7 +635,7 @@ int32_t AccessTokenManagerClient::UnRegisterTokenSyncCallback() { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return AccessTokenError::ERR_SERVICE_ABNORMAL; } std::lock_guard lock(tokenSyncCallbackMutex_); @@ -655,7 +652,7 @@ void AccessTokenManagerClient::DumpTokenInfo(const AtmToolsParamInfo& info, std: { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return; } @@ -668,7 +665,7 @@ int32_t AccessTokenManagerClient::GetVersion(uint32_t& version) { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return AccessTokenError::ERR_SERVICE_ABNORMAL; } @@ -680,13 +677,13 @@ void AccessTokenManagerClient::InitProxy() if (proxy_ == nullptr || proxy_->AsObject() == nullptr || proxy_->AsObject()->IsObjectDead()) { auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (sam == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbilityManager is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "GetSystemAbilityManager is null"); return; } sptr accesstokenSa = sam->GetSystemAbility(IAccessTokenManager::SA_ID_ACCESSTOKEN_MANAGER_SERVICE); if (accesstokenSa == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbility %{public}d is null", + LOGE(ATM_DOMAIN, ATM_TAG, "GetSystemAbility %{public}d is null", IAccessTokenManager::SA_ID_ACCESSTOKEN_MANAGER_SERVICE); return; } @@ -697,7 +694,7 @@ void AccessTokenManagerClient::InitProxy() } proxy_ = new AccessTokenManagerProxy(accesstokenSa); if (proxy_ == nullptr || proxy_->AsObject() == nullptr || proxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Iface_cast get null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Iface_cast get null"); } } } @@ -730,7 +727,7 @@ int32_t AccessTokenManagerClient::SetPermDialogCap(const HapBaseInfo& hapBaseInf { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } HapBaseInfoParcel hapBaseInfoParcel; @@ -742,7 +739,7 @@ void AccessTokenManagerClient::GetPermissionManagerInfo(PermissionGrantInfo& inf { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return; } PermissionGrantInfoParcel infoParcel; @@ -755,7 +752,7 @@ int32_t AccessTokenManagerClient::InitUserPolicy( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->InitUserPolicy(userList, permList); @@ -765,7 +762,7 @@ int32_t AccessTokenManagerClient::ClearUserPolicy() { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->ClearUserPolicy(); @@ -775,7 +772,7 @@ int32_t AccessTokenManagerClient::UpdateUserPolicy(const std::vector& { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return AccessTokenError::ERR_SERVICE_ABNORMAL; } return proxy->UpdateUserPolicy(userList); diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp index f5572980ea1bc2c72eb21d5c42f8e52d84df62e5..98b2f1e384e8f494b522d4970a74d0fff6d11c94 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp @@ -25,7 +25,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "ATMProxy"}; static const int MAX_PERMISSION_SIZE = 1000; static const int32_t MAX_USER_POLICY_SIZE = 1024; } @@ -44,13 +43,14 @@ bool AccessTokenManagerProxy::SendRequest( sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Code: %{public}d remote service null.", code); + LOGE(ATM_DOMAIN, ATM_TAG, "Code: %{public}d remote service null.", code); return false; } int32_t requestResult = remote->SendRequest( static_cast(code), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Code: %{public}d request fail, result: %{public}d", code, requestResult); + LOGE(ATM_DOMAIN, ATM_TAG, + "Code: %{public}d request fail, result: %{public}d", code, requestResult); return false; } return true; @@ -61,15 +61,15 @@ PermUsedTypeEnum AccessTokenManagerProxy::GetPermissionUsedType( { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return PermUsedTypeEnum::INVALID_USED_TYPE; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return PermUsedTypeEnum::INVALID_USED_TYPE; } if (!data.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return PermUsedTypeEnum::INVALID_USED_TYPE; } @@ -80,11 +80,11 @@ PermUsedTypeEnum AccessTokenManagerProxy::GetPermissionUsedType( int32_t ret; if (!reply.ReadInt32(ret)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32t failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32t failed."); return PermUsedTypeEnum::INVALID_USED_TYPE; } PermUsedTypeEnum result = static_cast(ret); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (type=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (type=%{public}d).", result); return result; } @@ -92,15 +92,15 @@ int AccessTokenManagerProxy::VerifyAccessToken(AccessTokenID tokenID, const std: { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return PERMISSION_DENIED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return PERMISSION_DENIED; } if (!data.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return PERMISSION_DENIED; } @@ -110,7 +110,7 @@ int AccessTokenManagerProxy::VerifyAccessToken(AccessTokenID tokenID, const std: } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Result from server (status=%{public}d).", result); + LOGD(ATM_DOMAIN, ATM_TAG, "Result from server (status=%{public}d).", result); return result; } @@ -119,15 +119,15 @@ int AccessTokenManagerProxy::VerifyAccessToken(AccessTokenID tokenID, { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteStringVector(permissionList)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteStringVector failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteStringVector failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -137,7 +137,7 @@ int AccessTokenManagerProxy::VerifyAccessToken(AccessTokenID tokenID, } if (!reply.ReadInt32Vector(&permStateList)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32Vector failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32Vector failed."); return ERR_READ_PARCEL_FAILED; } @@ -149,11 +149,11 @@ int AccessTokenManagerProxy::GetDefPermission( { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -163,13 +163,13 @@ int AccessTokenManagerProxy::GetDefPermission( } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); if (result != RET_SUCCESS) { return result; } sptr resultSptr = reply.ReadParcelable(); if (resultSptr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed."); return ERR_READ_PARCEL_FAILED; } permissionDefResult = *resultSptr; @@ -181,11 +181,11 @@ int AccessTokenManagerProxy::GetDefPermissions(AccessTokenID tokenID, { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -195,13 +195,13 @@ int AccessTokenManagerProxy::GetDefPermissions(AccessTokenID tokenID, } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); if (result != RET_SUCCESS) { return result; } uint32_t defPermSize = reply.ReadUint32(); if (defPermSize > MAX_PERMISSION_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Size(%{public}u) is oversize.", defPermSize); + LOGE(ATM_DOMAIN, ATM_TAG, "Size(%{public}u) is oversize.", defPermSize); return ERR_OVERSIZE; } for (uint32_t i = 0; i < defPermSize; i++) { @@ -218,15 +218,15 @@ int AccessTokenManagerProxy::GetReqPermissions( { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteInt32(isSystemGrant)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -236,13 +236,13 @@ int AccessTokenManagerProxy::GetReqPermissions( } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Result from server (error=%{public}d).", result); + LOGD(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); if (result != RET_SUCCESS) { return result; } uint32_t reqPermSize = reply.ReadUint32(); if (reqPermSize > MAX_PERMISSION_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Size(%{public}u) is oversize.", reqPermSize); + LOGE(ATM_DOMAIN, ATM_TAG, "Size(%{public}u) is oversize.", reqPermSize); return ERR_OVERSIZE; } for (uint32_t i = 0; i < reqPermSize; i++) { @@ -259,19 +259,19 @@ int32_t AccessTokenManagerProxy::SetPermissionRequestToggleStatus(const std::str { MessageParcel sendData; if (!sendData.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!sendData.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return ERR_WRITE_PARCEL_FAILED; } if (!sendData.WriteUint32(status)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } if (!sendData.WriteInt32(userID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -281,7 +281,7 @@ int32_t AccessTokenManagerProxy::SetPermissionRequestToggleStatus(const std::str } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); return result; } @@ -290,15 +290,15 @@ int32_t AccessTokenManagerProxy::GetPermissionRequestToggleStatus(const std::str { MessageParcel sendData; if (!sendData.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!sendData.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return ERR_WRITE_PARCEL_FAILED; } if (!sendData.WriteInt32(userID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -311,7 +311,8 @@ int32_t AccessTokenManagerProxy::GetPermissionRequestToggleStatus(const std::str if (result == RET_SUCCESS) { status = reply.ReadUint32(); } - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d, status=%{public}d).", result, status); + LOGI(ATM_DOMAIN, ATM_TAG, + "Result from server (error=%{public}d, status=%{public}d).", result, status); return result; } @@ -319,15 +320,15 @@ int AccessTokenManagerProxy::GetPermissionFlag(AccessTokenID tokenID, const std: { MessageParcel sendData; if (!sendData.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!sendData.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } if (!sendData.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -340,7 +341,7 @@ int AccessTokenManagerProxy::GetPermissionFlag(AccessTokenID tokenID, const std: if (result == RET_SUCCESS) { flag = reply.ReadUint32(); } - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d, flag=%{public}d).", result, flag); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d, flag=%{public}d).", result, flag); return result; } @@ -349,16 +350,16 @@ PermissionOper AccessTokenManagerProxy::GetSelfPermissionsState(std::vector(reply.ReadInt32()); size_t size = reply.ReadUint32(); if (size != permListParcel.size()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Size(%{public}zu) from server is not equal inputSize(%{public}zu)!", + LOGE(ATM_DOMAIN, ATM_TAG, "Size(%{public}zu) from server is not equal inputSize(%{public}zu)!", size, permListParcel.size()); return INVALID_OPER; } if (size > MAX_PERMISSION_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Size(%{public}zu) is oversize.", size); + LOGE(ATM_DOMAIN, ATM_TAG, "Size(%{public}zu) is oversize.", size); return INVALID_OPER; } for (uint32_t i = 0; i < size; i++) { @@ -389,12 +390,12 @@ PermissionOper AccessTokenManagerProxy::GetSelfPermissionsState(std::vector resultSptr = reply.ReadParcelable(); if (resultSptr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed."); return INVALID_OPER; } infoParcel = *resultSptr; - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (status=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (status=%{public}d).", result); return result; } @@ -403,20 +404,20 @@ int32_t AccessTokenManagerProxy::GetPermissionsStatus(AccessTokenID tokenID, { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(permListParcel.size())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } for (const auto& permission : permListParcel) { if (!data.WriteParcelable(&permission)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteParcelable failed."); return ERR_WRITE_PARCEL_FAILED; } } @@ -427,13 +428,13 @@ int32_t AccessTokenManagerProxy::GetPermissionsStatus(AccessTokenID tokenID, } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); if (result != RET_SUCCESS) { return result; } size_t size = reply.ReadUint32(); if (size != permListParcel.size()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Size(%{public}zu) from server is not equal inputSize(%{public}zu)!", + LOGE(ATM_DOMAIN, ATM_TAG, "Size(%{public}zu) from server is not equal inputSize(%{public}zu)!", size, permListParcel.size()); return ERR_SIZE_NOT_EQUAL; } @@ -450,19 +451,19 @@ int AccessTokenManagerProxy::GrantPermission(AccessTokenID tokenID, const std::s { MessageParcel inData; if (!inData.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!inData.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } if (!inData.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return ERR_WRITE_PARCEL_FAILED; } if (!inData.WriteUint32(flag)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -472,7 +473,7 @@ int AccessTokenManagerProxy::GrantPermission(AccessTokenID tokenID, const std::s } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); return result; } @@ -480,19 +481,19 @@ int AccessTokenManagerProxy::RevokePermission(AccessTokenID tokenID, const std:: { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(flag)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -502,7 +503,7 @@ int AccessTokenManagerProxy::RevokePermission(AccessTokenID tokenID, const std:: } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); return result; } @@ -511,19 +512,19 @@ int AccessTokenManagerProxy::GrantPermissionForSpecifiedTime( { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(onceTime)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -534,10 +535,10 @@ int AccessTokenManagerProxy::GrantPermissionForSpecifiedTime( int32_t result; if (!reply.ReadInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return ERR_READ_PARCEL_FAILED; } - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (result=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (result=%{public}d).", result); return result; } @@ -545,11 +546,11 @@ int AccessTokenManagerProxy::ClearUserGrantedPermissionState(AccessTokenID token { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -559,7 +560,7 @@ int AccessTokenManagerProxy::ClearUserGrantedPermissionState(AccessTokenID token } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); return result; } @@ -568,15 +569,15 @@ int32_t AccessTokenManagerProxy::RegisterPermStateChangeCallback( { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteParcelable(&scope)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteParcelable failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteRemoteObject(callback)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteRemoteObject failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteRemoteObject failed."); return ERR_WRITE_PARCEL_FAILED; } MessageParcel reply; @@ -586,10 +587,10 @@ int32_t AccessTokenManagerProxy::RegisterPermStateChangeCallback( int32_t ret; if (!reply.ReadInt32(ret)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return ERR_READ_PARCEL_FAILED; } - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", ret); return ret; } @@ -597,11 +598,11 @@ int32_t AccessTokenManagerProxy::UnRegisterPermStateChangeCallback(const sptr reply.GetReadPosition()) { - IF_FALSE_RETURN_VALUE_LOG(LABEL, reply.ReadString(resultInfo.permCheckResult.permissionName), + IF_FALSE_RETURN_VALUE_LOG(ATM_DOMAIN, ATM_TAG, reply.ReadString(resultInfo.permCheckResult.permissionName), ERR_READ_PARCEL_FAILED, "ReadString faild."); int32_t rule; - IF_FALSE_RETURN_VALUE_LOG(LABEL, reply.ReadInt32(rule), + IF_FALSE_RETURN_VALUE_LOG(ATM_DOMAIN, ATM_TAG, reply.ReadInt32(rule), ERR_READ_PARCEL_FAILED, "ReadString faild."); resultInfo.permCheckResult.rule = static_cast(rule); } } - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d, id=%{public}llu).", + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d, id=%{public}llu).", result, fullTokenId.tokenIDEx); return result; } @@ -765,12 +766,12 @@ int AccessTokenManagerProxy::DeleteToken(AccessTokenID tokenID) { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -780,7 +781,7 @@ int AccessTokenManagerProxy::DeleteToken(AccessTokenID tokenID) } int result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d, id=%{public}u).", result, tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d, id=%{public}u).", result, tokenID); return result; } @@ -788,12 +789,12 @@ int AccessTokenManagerProxy::GetTokenType(AccessTokenID tokenID) { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenID"); return ERR_WRITE_PARCEL_FAILED; } @@ -803,7 +804,7 @@ int AccessTokenManagerProxy::GetTokenType(AccessTokenID tokenID) } int result = reply.ReadInt32(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Result from server (type=%{public}d).", result); + LOGD(ATM_DOMAIN, ATM_TAG, "Result from server (type=%{public}d).", result); return result; } @@ -812,20 +813,20 @@ AccessTokenIDEx AccessTokenManagerProxy::GetHapTokenID(int32_t userID, const std AccessTokenIDEx tokenIdEx = {0}; MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return tokenIdEx; } if (!data.WriteInt32(userID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenID"); return tokenIdEx; } if (!data.WriteString(bundleName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write dcap"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write dcap"); return tokenIdEx; } if (!data.WriteInt32(instIndex)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write dcap"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write dcap"); return tokenIdEx; } MessageParcel reply; @@ -834,7 +835,7 @@ AccessTokenIDEx AccessTokenManagerProxy::GetHapTokenID(int32_t userID, const std } tokenIdEx.tokenIDEx = reply.ReadUint64(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Result from server (id=%{public}llu).", tokenIdEx.tokenIDEx); + LOGD(ATM_DOMAIN, ATM_TAG, "Result from server (id=%{public}llu).", tokenIdEx.tokenIDEx); return tokenIdEx; } @@ -843,16 +844,16 @@ AccessTokenID AccessTokenManagerProxy::AllocLocalTokenID( { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return 0; } if (!data.WriteString(remoteDeviceID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write dcap"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write dcap"); return 0; } if (!data.WriteUint32(remoteTokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write dcap"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write dcap"); return 0; } MessageParcel reply; @@ -861,7 +862,7 @@ AccessTokenID AccessTokenManagerProxy::AllocLocalTokenID( } AccessTokenID result = reply.ReadUint32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (id=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (id=%{public}d).", result); return result; } @@ -869,11 +870,11 @@ int AccessTokenManagerProxy::GetNativeTokenInfo(AccessTokenID tokenID, NativeTok { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -883,13 +884,13 @@ int AccessTokenManagerProxy::GetNativeTokenInfo(AccessTokenID tokenID, NativeTok } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Result from server (error=%{public}d).", result); + LOGD(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); if (result != RET_SUCCESS) { return result; } sptr resultSptr = reply.ReadParcelable(); if (resultSptr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail"); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable fail"); return ERR_READ_PARCEL_FAILED; } nativeTokenInfoRes = *resultSptr; @@ -900,11 +901,11 @@ int AccessTokenManagerProxy::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -914,13 +915,13 @@ int AccessTokenManagerProxy::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Result from server (error=%{public}d).", result); + LOGD(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); if (result != RET_SUCCESS) { return result; } sptr resultSptr = reply.ReadParcelable(); if (resultSptr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed."); return ERR_READ_PARCEL_FAILED; } hapTokenInfoRes = *resultSptr; @@ -933,31 +934,31 @@ int32_t AccessTokenManagerProxy::UpdateHapToken(AccessTokenIDEx& tokenIdEx, cons AccessTokenID tokenID = tokenIdEx.tokenIdExStruct.tokenID; MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write tokenID failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write tokenID failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteBool(info.isSystemApp)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write isSystemApp failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write isSystemApp failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteString(info.appIDDesc)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write appIDDesc failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write appIDDesc failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteInt32(info.apiVersion)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write apiVersion failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write apiVersion failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteString(info.appDistributionType)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write appDistributionType failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write appDistributionType failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteParcelable(&policyParcel)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write policyParcel failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write policyParcel failed."); return ERR_WRITE_PARCEL_FAILED; } @@ -968,15 +969,15 @@ int32_t AccessTokenManagerProxy::UpdateHapToken(AccessTokenIDEx& tokenIdEx, cons int32_t result = reply.ReadInt32(); tokenIdEx.tokenIdExStruct.tokenAttr = reply.ReadUint32(); if (result != RET_SUCCESS && reply.GetDataSize() > reply.GetReadPosition()) { - IF_FALSE_RETURN_VALUE_LOG(LABEL, reply.ReadString(resultInfo.permCheckResult.permissionName), + IF_FALSE_RETURN_VALUE_LOG(ATM_DOMAIN, ATM_TAG, reply.ReadString(resultInfo.permCheckResult.permissionName), ERR_READ_PARCEL_FAILED, "ReadString faild."); int32_t rule; - IF_FALSE_RETURN_VALUE_LOG(LABEL, reply.ReadInt32(rule), + IF_FALSE_RETURN_VALUE_LOG(ATM_DOMAIN, ATM_TAG, reply.ReadInt32(rule), ERR_READ_PARCEL_FAILED, "ReadString faild."); resultInfo.permCheckResult.rule = static_cast(rule); } - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); return result; } @@ -985,7 +986,7 @@ int32_t AccessTokenManagerProxy::ReloadNativeTokenInfo() { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } MessageParcel reply; @@ -994,7 +995,7 @@ int32_t AccessTokenManagerProxy::ReloadNativeTokenInfo() } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); return result; } @@ -1005,11 +1006,11 @@ int AccessTokenManagerProxy::GetHapTokenInfoExtension(AccessTokenID tokenID, { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 fail"); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 fail"); return ERR_WRITE_PARCEL_FAILED; } @@ -1019,18 +1020,18 @@ int AccessTokenManagerProxy::GetHapTokenInfoExtension(AccessTokenID tokenID, } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); if (result != RET_SUCCESS) { return result; } sptr hapResult = reply.ReadParcelable(); if (hapResult == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable fail."); return ERR_READ_PARCEL_FAILED; } hapTokenInfoRes = *hapResult; if (!reply.ReadString(appID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadString fail."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadString fail."); return ERR_READ_PARCEL_FAILED; } @@ -1041,12 +1042,12 @@ AccessTokenID AccessTokenManagerProxy::GetNativeTokenId(const std::string& proce { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return INVALID_TOKENID; } if (!data.WriteString(processName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed."); return INVALID_TOKENID; } MessageParcel reply; @@ -1055,10 +1056,11 @@ AccessTokenID AccessTokenManagerProxy::GetNativeTokenId(const std::string& proce } AccessTokenID id; if (!reply.ReadUint32(id)) { - ACCESSTOKEN_LOG_INFO(LABEL, "ReadInt32 failed."); + LOGI(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return INVALID_TOKENID; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Result from server (process=%{public}s, id=%{public}d).", processName.c_str(), id); + LOGD(ATM_DOMAIN, ATM_TAG, + "Result from server (process=%{public}s, id=%{public}d).", processName.c_str(), id); return id; } @@ -1068,7 +1070,7 @@ int AccessTokenManagerProxy::GetHapTokenInfoFromRemote(AccessTokenID tokenID, { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenID)) { @@ -1081,13 +1083,13 @@ int AccessTokenManagerProxy::GetHapTokenInfoFromRemote(AccessTokenID tokenID, } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); if (result != RET_SUCCESS) { return result; } sptr hapResult = reply.ReadParcelable(); if (hapResult == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail"); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable fail"); return ERR_READ_PARCEL_FAILED; } hapSyncParcel = *hapResult; @@ -1099,7 +1101,7 @@ int AccessTokenManagerProxy::SetRemoteHapTokenInfo(const std::string& deviceID, { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteString(deviceID)) { @@ -1115,7 +1117,7 @@ int AccessTokenManagerProxy::SetRemoteHapTokenInfo(const std::string& deviceID, } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); return result; } @@ -1137,7 +1139,7 @@ int AccessTokenManagerProxy::DeleteRemoteToken(const std::string& deviceID, Acce } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); return result; } @@ -1145,7 +1147,7 @@ AccessTokenID AccessTokenManagerProxy::GetRemoteNativeTokenID(const std::string& { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return 0; } if (!data.WriteString(deviceID)) { @@ -1162,7 +1164,7 @@ AccessTokenID AccessTokenManagerProxy::GetRemoteNativeTokenID(const std::string& } AccessTokenID id = reply.ReadUint32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (id=%{public}d).", id); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (id=%{public}d).", id); return id; } @@ -1170,7 +1172,7 @@ int AccessTokenManagerProxy::DeleteRemoteDeviceTokens(const std::string& deviceI { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteString(deviceID)) { @@ -1183,7 +1185,7 @@ int AccessTokenManagerProxy::DeleteRemoteDeviceTokens(const std::string& deviceI } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server (error=%{public}d).", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server (error=%{public}d).", result); return result; } @@ -1191,11 +1193,11 @@ int32_t AccessTokenManagerProxy::RegisterTokenSyncCallback(const sptr parcel = reply.ReadParcelable(); if (parcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed."); return; } infoParcel = *parcel; @@ -1334,53 +1336,54 @@ int32_t AccessTokenManagerProxy::InitUserPolicy( { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write interface token failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write interface token failed."); return ERR_WRITE_PARCEL_FAILED; } size_t userLen = userList.size(); size_t permLen = permList.size(); if ((userLen == 0) || (userLen > MAX_USER_POLICY_SIZE) || (permLen == 0) || (permLen > MAX_USER_POLICY_SIZE)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UserLen %{public}zu or permLen %{public}zu is invalid", userLen, permLen); + LOGE(ATM_DOMAIN, ATM_TAG, + "UserLen %{public}zu or permLen %{public}zu is invalid", userLen, permLen); return ERR_PARAM_INVALID; } if (!data.WriteUint32(userLen)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write userLen size."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write userLen size."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(permLen)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permLen size."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write permLen size."); return ERR_WRITE_PARCEL_FAILED; } for (const auto& userInfo : userList) { if (!data.WriteInt32(userInfo.userId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write userId."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write userId."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteBool(userInfo.isActive)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write isActive."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write isActive."); return ERR_WRITE_PARCEL_FAILED; } } for (const auto& permission : permList) { if (!data.WriteString(permission)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permission."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write permission."); return ERR_WRITE_PARCEL_FAILED; } } MessageParcel reply; if (!SendRequest(AccessTokenInterfaceCode::INIT_USER_POLICY, data, reply)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read replay failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Read replay failed"); return ERR_SERVICE_ABNORMAL; } int32_t result; if (!reply.ReadInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read Int32 failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Read Int32 failed"); return AccessTokenError::ERR_READ_PARCEL_FAILED; } - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } @@ -1388,21 +1391,21 @@ int32_t AccessTokenManagerProxy::ClearUserPolicy() { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write interface token failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write interface token failed."); return ERR_WRITE_PARCEL_FAILED; } MessageParcel reply; if (!SendRequest(AccessTokenInterfaceCode::CLEAR_USER_POLICY, data, reply)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read replay failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Read replay failed"); return ERR_SERVICE_ABNORMAL; } int32_t result; if (!reply.ReadInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read Int32 failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Read Int32 failed"); return AccessTokenError::ERR_READ_PARCEL_FAILED; } - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } @@ -1410,43 +1413,43 @@ int32_t AccessTokenManagerProxy::UpdateUserPolicy(const std::vector& { MessageParcel data; if (!data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write interface token failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write interface token failed."); return ERR_WRITE_PARCEL_FAILED; } size_t userLen = userList.size(); if ((userLen == 0) || (userLen > MAX_USER_POLICY_SIZE)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UserLen %{public}zu is invalid.", userLen); + LOGE(ATM_DOMAIN, ATM_TAG, "UserLen %{public}zu is invalid.", userLen); return ERR_PARAM_INVALID; } if (!data.WriteUint32(userLen)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write userLen size."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write userLen size."); return ERR_WRITE_PARCEL_FAILED; } for (const auto& userInfo : userList) { if (!data.WriteInt32(userInfo.userId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write userId."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write userId."); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteBool(userInfo.isActive)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write isActive."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write isActive."); return ERR_WRITE_PARCEL_FAILED; } } MessageParcel reply; if (!SendRequest(AccessTokenInterfaceCode::UPDATE_USER_POLICY, data, reply)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read replay failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Read replay failed"); return ERR_SERVICE_ABNORMAL; } int32_t result; if (!reply.ReadInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read Int32 failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Read Int32 failed"); return AccessTokenError::ERR_READ_PARCEL_FAILED; } - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } } // namespace AccessToken diff --git a/interfaces/innerkits/accesstoken/src/tokenid_kit.cpp b/interfaces/innerkits/accesstoken/src/tokenid_kit.cpp index a28015b4398415d9c398fd655ee06fcb741d1157..eed3f47b75f4676c903b32cea15510a48001b6cc 100644 --- a/interfaces/innerkits/accesstoken/src/tokenid_kit.cpp +++ b/interfaces/innerkits/accesstoken/src/tokenid_kit.cpp @@ -24,14 +24,13 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TokenIdKit"}; static const uint64_t SYSTEM_APP_MASK = (static_cast(1) << 32); static const uint64_t TOKEN_ID_LOWMASK = 0xffffffff; } bool TokenIdKit::IsSystemAppByFullTokenID(uint64_t tokenId) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Called, tokenId=%{public}" PRId64, tokenId); + LOGD(ATM_DOMAIN, ATM_TAG, "Id=%{public}" PRId64, tokenId); return (tokenId & SYSTEM_APP_MASK) == SYSTEM_APP_MASK; } @@ -39,7 +38,7 @@ uint64_t TokenIdKit::GetRenderTokenID(uint64_t tokenId) { AccessTokenID id = tokenId & TOKEN_ID_LOWMASK; if (id == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return tokenId; } AccessTokenIDInner *idInner = reinterpret_cast(&id); diff --git a/interfaces/innerkits/accesstoken/test/unittest/HapTokenTest/update_hap_token_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/HapTokenTest/update_hap_token_test.cpp index 26dd9d980e0d212363539704f8ca3bbb31983e5c..7f09c606504a912821423ddd11376f43d1071b68 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/HapTokenTest/update_hap_token_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/HapTokenTest/update_hap_token_test.cpp @@ -43,8 +43,6 @@ const std::string OVER_SIZE_STR = "FBSURBVDiN7ZQ/S8NQFMVPxU/QCx06GBzrkqUZ42rBbHWUBDqYxSnUoTxXydCSycVsgltfBiFDR8HNdHGxY4nQQAPvMzwHsWn+KM" "vj3He5vIaUEjV0UAfe85X83KMBT7N75JEXVdSlfEAVfPRyZ5yfIrBoUkVlMU82Hkp8wu9ddt1vFew4sIiIiKwgzcXIvN7GTZOvpZ" "D3I1NZvmdCXz+XOv5wJANKHOVYjRTAghxIyh0FHKb+0QQH5+kXf2zkYGAG0oFr5RfnK8DAGkwY19wliRT2L448vjv0YGQFVa8VKd"; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "UpdateHapTokenTest"}; PermissionStateFull g_testPermReq = { .permissionName = "ohos.permission.MANAGE_HAP_TOKENID", @@ -121,7 +119,7 @@ void UpdateHapTokenTest::TearDownTestCase() void UpdateHapTokenTest::SetUp() { - ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUp ok."); setuid(0); } diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_extension_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_extension_test.cpp index ea9e8433653defd5e3f1f59285706acd139cac01..390b609eeb3c6c868928d5209b45bbdb44dbe87d 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_extension_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_extension_test.cpp @@ -44,8 +44,6 @@ static const std::string TEST_BUNDLE_NAME = "ohos"; static const std::string TEST_PERMISSION_NAME_ALPHA = "ohos.permission.ALPHA"; static const std::string TEST_PERMISSION_NAME_BETA = "ohos.permission.BETA"; static const int TEST_USER_ID = 0; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenKitExtensionTest"}; PermissionStateFull g_getPermissionReq = { .permissionName = "ohos.permission.GET_SENSITIVE_PERMISSIONS", @@ -496,7 +494,7 @@ void AccessTokenKitExtensionTest::SetUp() g_infoManagerTestInfoParms.bundleName, g_infoManagerTestInfoParms.instIndex); AccessTokenKit::DeleteToken(tokenID); - ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUp ok."); } void AccessTokenKitExtensionTest::TearDown() @@ -3064,19 +3062,19 @@ public: int32_t GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) const override { - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo called."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo called."); return FAKE_SYNC_RET; }; int32_t DeleteRemoteHapTokenInfo(AccessTokenID tokenID) const override { - ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteHapTokenInfo called."); + LOGI(ATM_DOMAIN, ATM_TAG, "DeleteRemoteHapTokenInfo called."); return FAKE_SYNC_RET; }; int32_t UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo) const override { - ACCESSTOKEN_LOG_INFO(LABEL, "UpdateRemoteHapTokenInfo called."); + LOGI(ATM_DOMAIN, ATM_TAG, "UpdateRemoteHapTokenInfo called."); return FAKE_SYNC_RET; }; }; diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/app_installation_optimized_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/app_installation_optimized_test.cpp index 02337045e058ffcf61cad76254c65f93a9ee4937..1349d0b456d9b235a16b431e6c74e92d944fff01 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/app_installation_optimized_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/app_installation_optimized_test.cpp @@ -38,8 +38,6 @@ const std::string APP_TRACKING_PERMISSION = "ohos.permission.APP_TRACKING_CONSEN const std::string ACCESS_BLUETOOTH_PERMISSION = "ohos.permission.ACCESS_BLUETOOTH"; static constexpr int32_t DEFAULT_API_VERSION = 8; static constexpr int32_t MAX_PERM_LIST_SIZE = 1024; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "AppInstallationOptimizedTest"}; PermissionStateFull g_tddPermReq = { .permissionName = MANAGE_HAP_TOKENID_PERMISSION, @@ -174,7 +172,7 @@ void AppInstallationOptimizedTest::TearDownTestCase() void AppInstallationOptimizedTest::SetUp() { - ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUp ok."); } void AppInstallationOptimizedTest::TearDown() diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/clone_app_permission_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/clone_app_permission_test.cpp index 8d6c3956c8eba291f5c3cc5df6389dfacd239a03..9cb564f091713f2376ba99dabb7ed49ebe30f79b 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/clone_app_permission_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/clone_app_permission_test.cpp @@ -32,8 +32,6 @@ static const std::string PERMISSION_FULL_CONTROL = "ohos.permission.WRITE_MEDIA" static const std::string PERMISSION_NOT_DISPLAYED = "ohos.permission.ANSWER_CALL"; static const std::string TEST_PERMISSION_GRANT = "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"; static const std::string TEST_PERMISSION_REVOKE = "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenKitExtensionTest"}; HapInfoParams g_infoParmsCommon = { .userID = 1, @@ -109,7 +107,7 @@ void CloneAppPermissionTest::TearDownTestCase() void CloneAppPermissionTest::SetUp() { - ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUp ok."); } void CloneAppPermissionTest::TearDown() @@ -151,7 +149,7 @@ void CloneAppPermissionTest::SetUpTestCase() EXPECT_NE(0, tokenIdEx.tokenIdExStruct.tokenID); EXPECT_EQ(true, TokenIdKit::IsSystemAppByFullTokenID(tokenIdEx.tokenIDEx)); EXPECT_EQ(0, SetSelfTokenID(tokenIdEx.tokenIDEx)); - ACCESSTOKEN_LOG_INFO(LABEL, "SetUpTestCase ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUpTestCase ok."); } static AccessTokenID AllocHapTokenId(HapInfoParams info, HapPolicyParams policy) diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/edm_policy_set_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/edm_policy_set_test.cpp index 804f23e24d75bdc08cd14b81567898ff7c75f1e2..2eed14ba3f17ee8c8d90822573bb3c55e4128499 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/edm_policy_set_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/edm_policy_set_test.cpp @@ -122,8 +122,6 @@ HapPolicyParams g_tddPolicyParams = { .domain = "test.domain2", .permStateList = {g_tddPermReq, g_tddPermGet, g_tddPermRevoke} }; - -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "EdmPolicySetTest"}; } void EdmPolicySetTest::TearDownTestCase() @@ -136,7 +134,7 @@ void EdmPolicySetTest::TearDownTestCase() void EdmPolicySetTest::SetUp() { - ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUp ok."); } void EdmPolicySetTest::TearDown() @@ -148,7 +146,7 @@ void EdmPolicySetTest::SetUpTestCase() g_selfShellTokenId = GetSelfTokenID(); AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(g_tddHapInfoParams, g_tddPolicyParams); SetSelfTokenID(tokenIdEx.tokenIDEx); - ACCESSTOKEN_LOG_INFO(LABEL, "SetUpTestCase ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUpTestCase ok."); } /** diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/remote_token_kit_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/remote_token_kit_test.cpp index 28f57b14168b94c74d9afb6cfb781dd9006f4441..49f21cff973257aca44db1c607eb32d67006f053 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/remote_token_kit_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/remote_token_kit_test.cpp @@ -26,8 +26,6 @@ using namespace testing::ext; using namespace OHOS::Security::AccessToken; namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "RemoteTokenKitTest"}; - static const std::string TEST_BUNDLE_NAME = "ohos"; static const std::string TEST_PKG_NAME = "com.softbus.test"; static const int TEST_USER_ID = 0; @@ -123,19 +121,19 @@ public: int32_t GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) const override { - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo called."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo called."); return FAKE_SYNC_RET; }; int32_t DeleteRemoteHapTokenInfo(AccessTokenID tokenID) const override { - ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteHapTokenInfo called."); + LOGI(ATM_DOMAIN, ATM_TAG, "DeleteRemoteHapTokenInfo called."); return FAKE_SYNC_RET; }; int32_t UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo) const override { - ACCESSTOKEN_LOG_INFO(LABEL, "UpdateRemoteHapTokenInfo called."); + LOGI(ATM_DOMAIN, ATM_TAG, "UpdateRemoteHapTokenInfo called."); return FAKE_SYNC_RET; }; }; @@ -193,7 +191,7 @@ void RemoteTokenKitTest::SetUp() ASSERT_NE(udid_, ""); #endif - ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUp ok."); } void RemoteTokenKitTest::TearDown() @@ -237,7 +235,7 @@ void RemoteTokenKitTest::AllocTestToken() const */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo001 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo001 start."); std::string deviceID1 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID1, 0x20100000); PermissionStateFull infoManagerTestState2 = { @@ -305,7 +303,7 @@ void SetRemoteHapTokenInfoWithWrongInfo(HapTokenInfo &wrongBaseInfo, const HapTo */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo002 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo002 start."); std::string deviceID2 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID2, 0x20100000); HapTokenInfo rightBaseInfo = { @@ -348,7 +346,7 @@ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo002, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo003, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo003 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo003 start."); std::string deviceID3 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID3, 0x20100000); @@ -389,7 +387,7 @@ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo003, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo004, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo004 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo004 start."); std::string deviceID4 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID4, 0x20100000); PermissionStateFull infoManagerTestState_4 = { @@ -435,7 +433,7 @@ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo004, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo005, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo005 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo005 start."); std::string deviceID5 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID5, 0x20100000); PermissionStateFull infoManagerTestState5 = { @@ -480,7 +478,7 @@ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo005, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo006, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo006 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo006 start."); std::string deviceID6 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID6, 0x20100000); PermissionStateFull infoManagerTestState6 = { @@ -533,7 +531,7 @@ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo006, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo007, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo007 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo007 start."); std::string deviceID7 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID7, 0x20100000); PermissionStateFull infoManagerTestState7 = { @@ -572,7 +570,7 @@ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo007, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo008, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo008 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo008 start."); std::string deviceID8 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID8, 0x20100000); int32_t DEFAULT_API_VERSION = 8; @@ -620,7 +618,7 @@ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo008, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo009, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo009 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo009 start."); std::string deviceID9 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID9, 0x20100000); PermissionStateFull infoManagerTestState9 = { @@ -665,7 +663,7 @@ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo009, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo010, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo009 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetRemoteHapTokenInfo009 start."); std::string deviceID = udid_; HapTokenInfo baseInfo = { .ver = 1, @@ -702,7 +700,7 @@ HWTEST_F(RemoteTokenKitTest, SetRemoteHapTokenInfo010, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceToken001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens001 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "DeleteRemoteDeviceTokens001 start."); std::string deviceID1 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID1, 0x20100000); PermissionStateFull infoManagerTestState_3 = { @@ -744,7 +742,7 @@ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceToken001, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceToken002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens001 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "DeleteRemoteDeviceTokens001 start."); std::string deviceID2 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID2, 0x20100000); PermissionStateFull infoManagerTestState_2 = { @@ -789,7 +787,7 @@ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceToken002, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceToken003, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceToken003 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "DeleteRemoteDeviceToken003 start."); std::string deviceID3 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID3, 0x20100000); @@ -805,7 +803,7 @@ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceToken003, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceTokens001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens001 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "DeleteRemoteDeviceTokens001 start."); std::string deviceID1 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID1, 0x20100000); AccessTokenKit::DeleteRemoteToken(deviceID1, 0x20100001); @@ -855,7 +853,7 @@ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceTokens001, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceTokens002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens002 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "DeleteRemoteDeviceTokens002 start."); std::string deviceID2 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID2, 0x20100000); AccessTokenKit::DeleteRemoteToken(deviceID2, 0x20100001); @@ -902,7 +900,7 @@ HWTEST_F(RemoteTokenKitTest, DeleteRemoteDeviceTokens002, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, GetHapTokenInfoFromRemote001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetHapTokenInfoFromRemote001 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetHapTokenInfoFromRemote001 start."); AccessTokenIDEx tokenIdEx = {0}; tokenIdEx = AccessTokenKit::AllocHapToken(g_infoManagerTestInfoParms, g_infoManagerTestPolicyPrams); AccessTokenID localTokenID = tokenIdEx.tokenIdExStruct.tokenID; @@ -947,7 +945,7 @@ HWTEST_F(RemoteTokenKitTest, GetHapTokenInfoFromRemote001, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, GetHapTokenInfoFromRemote002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetHapTokenInfoFromRemote002 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetHapTokenInfoFromRemote002 start."); std::string deviceID2 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID2, 0x20100000); PermissionStateFull infoManagerTestState2 = { @@ -985,7 +983,7 @@ HWTEST_F(RemoteTokenKitTest, GetHapTokenInfoFromRemote002, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, GetHapTokenInfoFromRemote003, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetHapTokenInfoFromRemote003 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetHapTokenInfoFromRemote003 start."); HapTokenInfoForSync infoSync; int ret = AccessTokenKit::GetHapTokenInfoFromRemote(0, infoSync); ASSERT_NE(ret, RET_SUCCESS); @@ -999,7 +997,7 @@ HWTEST_F(RemoteTokenKitTest, GetHapTokenInfoFromRemote003, TestSize.Level1) */ HWTEST_F(RemoteTokenKitTest, AllocLocalTokenID001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "AllocLocalTokenID001 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "AllocLocalTokenID001 start."); std::string deviceID1 = udid_; AccessTokenKit::DeleteRemoteToken(deviceID1, 0x20100000); PermissionStateFull infoManagerTestState_1 = { diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/share_permission_with_sandbox_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/share_permission_with_sandbox_test.cpp index e94defee89f4f54bd7b529fb93f597dcd461bb02..2d8f1f2cb02757bd3e953b991d991b390c05d727 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/share_permission_with_sandbox_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/share_permission_with_sandbox_test.cpp @@ -33,8 +33,6 @@ static const std::string PERMISSION_NONE = "ohos.permission.INTERNET"; static const std::string PERMISSION_NOT_DISPLAYED = "ohos.permission.ANSWER_CALL"; static const std::string TEST_PERMISSION_GRANT = "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"; static const std::string TEST_PERMISSION_REVOKE = "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenKitExtensionTest"}; HapInfoParams g_infoParmsCommon = { .userID = 1, @@ -136,7 +134,7 @@ void SharePermissionTest::SetUpTestCase() EXPECT_NE(0, tokenIdEx.tokenIdExStruct.tokenID); EXPECT_EQ(true, TokenIdKit::IsSystemAppByFullTokenID(tokenIdEx.tokenIDEx)); EXPECT_EQ(0, SetSelfTokenID(tokenIdEx.tokenIDEx)); - ACCESSTOKEN_LOG_INFO(LABEL, "SetUpTestCase ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUpTestCase ok."); } void SharePermissionTest::TearDownTestCase() @@ -148,7 +146,7 @@ void SharePermissionTest::TearDownTestCase() void SharePermissionTest::SetUp() { - ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUp ok."); } void SharePermissionTest::TearDown() diff --git a/interfaces/innerkits/privacy/src/on_permission_used_record_callback_stub.cpp b/interfaces/innerkits/privacy/src/on_permission_used_record_callback_stub.cpp index 7a84683ae1674a56f7d5f1a3f9fa028809aab240..33f7202fe50e6d21919a8d2c932e204c6795014f 100644 --- a/interfaces/innerkits/privacy/src/on_permission_used_record_callback_stub.cpp +++ b/interfaces/innerkits/privacy/src/on_permission_used_record_callback_stub.cpp @@ -24,19 +24,16 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "OnPermissionUsedRecordCallbackStub" -}; static constexpr int32_t RET_NOK = -1; } int32_t OnPermissionUsedRecordCallbackStub::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code); + LOGD(ATM_DOMAIN, ATM_TAG, "Entry, code: 0x%{public}x", code); std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != OnPermissionUsedRecordCallback::GetDescriptor()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); return ERROR_IPC_REQUEST_FAIL; } @@ -50,10 +47,10 @@ int32_t OnPermissionUsedRecordCallbackStub::OnRemoteRequest( } sptr resultSptr = data.ReadParcelable(); if (resultSptr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail"); + LOGE(PRI_DOMAIN, PRI_TAG, "ReadParcelable fail"); return RET_NOK; } - ACCESSTOKEN_LOG_INFO(LABEL, "ErrCode: %{public}d", errCode); + LOGI(ATM_DOMAIN, ATM_TAG, "ErrCode: %{public}d", errCode); OnQueried(errCode, resultSptr->result); } else { return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/interfaces/innerkits/privacy/src/perm_active_status_change_callback.cpp b/interfaces/innerkits/privacy/src/perm_active_status_change_callback.cpp index 09ffed6b5eae0d59c8fa7bf13bad3121ce207d38..1e3e84bf9ee8171b9f7afd2a0cbed39172df0295 100644 --- a/interfaces/innerkits/privacy/src/perm_active_status_change_callback.cpp +++ b/interfaces/innerkits/privacy/src/perm_active_status_change_callback.cpp @@ -21,9 +21,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PermissionActiveStatusChangeCallback" -}; PermActiveStatusChangeCallback::PermActiveStatusChangeCallback( const std::shared_ptr &customizedCallback) : customizedCallback_(customizedCallback) @@ -35,7 +32,7 @@ PermActiveStatusChangeCallback::~PermActiveStatusChangeCallback() void PermActiveStatusChangeCallback::ActiveStatusChangeCallback(ActiveChangeResponse& result) { if (customizedCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "CustomizedCallback_ is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "CustomizedCallback_ is nullptr"); return; } diff --git a/interfaces/innerkits/privacy/src/perm_active_status_change_callback_stub.cpp b/interfaces/innerkits/privacy/src/perm_active_status_change_callback_stub.cpp index 0198c49d12eb58ea97aa16161f5a275d5c5d7986..789240aa6528404b32a40c700a7fc6384de97526 100644 --- a/interfaces/innerkits/privacy/src/perm_active_status_change_callback_stub.cpp +++ b/interfaces/innerkits/privacy/src/perm_active_status_change_callback_stub.cpp @@ -23,19 +23,13 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PermActiveStatusChangeCallbackStub" -}; -} - int32_t PermActiveStatusChangeCallbackStub::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code); + LOGD(ATM_DOMAIN, ATM_TAG, "Entry, code: 0x%{public}x", code); std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != IPermActiveStatusCallback::GetDescriptor()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); return ERROR_IPC_REQUEST_FAIL; } @@ -43,7 +37,7 @@ int32_t PermActiveStatusChangeCallbackStub::OnRemoteRequest( if (msgCode == static_cast(PrivacyActiveChangeInterfaceCode::PERM_ACTIVE_STATUS_CHANGE)) { sptr resultSptr = data.ReadParcelable(); if (resultSptr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail"); + LOGE(PRI_DOMAIN, PRI_TAG, "ReadParcelable fail"); return ERR_READ_PARCEL_FAILED; } diff --git a/interfaces/innerkits/privacy/src/privacy_death_recipient.cpp b/interfaces/innerkits/privacy/src/privacy_death_recipient.cpp index 6322643b8be21f810ddb9927475e048c49d7e8be..3d2efc40bdf1aa3415103e991acf1ec91cde7c77 100644 --- a/interfaces/innerkits/privacy/src/privacy_death_recipient.cpp +++ b/interfaces/innerkits/privacy/src/privacy_death_recipient.cpp @@ -20,15 +20,9 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyDeathRecipient" -}; -} // namespace - void PrivacyDeathRecipient::OnRemoteDied(const wptr& object) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called", __func__); + LOGI(PRI_DOMAIN, PRI_TAG, "%{public}s called", __func__); PrivacyManagerClient::GetInstance().OnRemoteDiedHandle(); } } // namespace AccessToken diff --git a/interfaces/innerkits/privacy/src/privacy_manager_client.cpp b/interfaces/innerkits/privacy/src/privacy_manager_client.cpp index 9f5807c2bbfd4f79bd47b6f37721dc207b0000af..56989882b5a83a7bcbac7b2965567cca56876b7c 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_client.cpp +++ b/interfaces/innerkits/privacy/src/privacy_manager_client.cpp @@ -27,9 +27,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyManagerClient" -}; const static int32_t MAX_CALLBACK_SIZE = 200; const static int32_t MAX_PERM_LIST_SIZE = 1024; constexpr const char* CAMERA_PERMISSION_NAME = "ohos.permission.CAMERA"; @@ -54,7 +51,7 @@ PrivacyManagerClient::PrivacyManagerClient() PrivacyManagerClient::~PrivacyManagerClient() { - ACCESSTOKEN_LOG_ERROR(LABEL, "~PrivacyManagerClient"); + LOGE(PRI_DOMAIN, PRI_TAG, "~PrivacyManagerClient"); std::lock_guard lock(proxyMutex_); ReleaseProxy(); } @@ -63,7 +60,7 @@ int32_t PrivacyManagerClient::AddPermissionUsedRecord(const AddPermParamInfo& in { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } AddPermParamInfoParcel infoParcel; @@ -76,7 +73,7 @@ int32_t PrivacyManagerClient::StartUsingPermission( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } return proxy->StartUsingPermission(tokenID, pid, permissionName, type); @@ -88,12 +85,12 @@ int32_t PrivacyManagerClient::CreateStateChangeCbk(uint64_t id, std::lock_guard lock(stateCbkMutex_); auto iter = stateChangeCallbackMap_.find(id); if (iter != stateChangeCallbackMap_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, " Callback has been used."); + LOGE(PRI_DOMAIN, PRI_TAG, " Callback has been used."); return PrivacyError::ERR_CALLBACK_ALREADY_EXIST; } else { callbackWrap = new (std::nothrow) StateChangeCallback(callback); if (callbackWrap == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Memory allocation for callbackWrap failed!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Memory allocation for callbackWrap failed!"); return PrivacyError::ERR_MALLOC_FAILED; } } @@ -104,7 +101,7 @@ int32_t PrivacyManagerClient::StartUsingPermission(AccessTokenID tokenId, int32_ const std::string& permissionName, const std::shared_ptr& callback, PermissionUsedType type) { if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is nullptr."); + LOGE(PRI_DOMAIN, PRI_TAG, "Callback is nullptr."); return PrivacyError::ERR_PARAM_INVALID; } @@ -117,7 +114,7 @@ int32_t PrivacyManagerClient::StartUsingPermission(AccessTokenID tokenId, int32_ auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } @@ -125,7 +122,7 @@ int32_t PrivacyManagerClient::StartUsingPermission(AccessTokenID tokenId, int32_ if (result == RET_SUCCESS) { std::lock_guard lock(stateCbkMutex_); stateChangeCallbackMap_[id] = callbackWrap; - ACCESSTOKEN_LOG_INFO(LABEL, "CallbackObject added."); + LOGI(PRI_DOMAIN, PRI_TAG, "CallbackObject added."); } return result; } @@ -135,7 +132,7 @@ int32_t PrivacyManagerClient::StopUsingPermission( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } if (permissionName == CAMERA_PERMISSION_NAME) { @@ -154,7 +151,7 @@ int32_t PrivacyManagerClient::RemovePermissionUsedRecords(AccessTokenID tokenID) { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } return proxy->RemovePermissionUsedRecords(tokenID); @@ -165,7 +162,7 @@ int32_t PrivacyManagerClient::GetPermissionUsedRecords( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } @@ -182,7 +179,7 @@ int32_t PrivacyManagerClient::GetPermissionUsedRecords(const PermissionUsedReque { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } @@ -217,20 +214,20 @@ int32_t PrivacyManagerClient::RegisterPermActiveStatusCallback( const std::shared_ptr& callback) { if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "CustomizedCb is nullptr."); + LOGE(PRI_DOMAIN, PRI_TAG, "CustomizedCb is nullptr."); return PrivacyError::ERR_PARAM_INVALID; } sptr callbackWrap = nullptr; int32_t result = CreateActiveStatusChangeCbk(callback, callbackWrap); if (result != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create callback, err: %{public}d.", result); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to create callback, err: %{public}d.", result); return result; } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } std::vector permList; @@ -243,7 +240,7 @@ int32_t PrivacyManagerClient::RegisterPermActiveStatusCallback( if (result == RET_SUCCESS) { std::lock_guard lock(activeCbkMutex_); activeCbkMap_[callback] = callbackWrap; - ACCESSTOKEN_LOG_INFO(LABEL, "CallbackObject added."); + LOGI(PRI_DOMAIN, PRI_TAG, "CallbackObject added."); } return result; } @@ -253,14 +250,14 @@ int32_t PrivacyManagerClient::UnRegisterPermActiveStatusCallback( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } std::lock_guard lock(activeCbkMutex_); auto goalCallback = activeCbkMap_.find(callback); if (goalCallback == activeCbkMap_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GoalCallback already is not exist."); + LOGE(PRI_DOMAIN, PRI_TAG, "GoalCallback already is not exist."); return PrivacyError::ERR_CALLBACK_NOT_EXIST; } @@ -276,7 +273,7 @@ bool PrivacyManagerClient::IsAllowedUsingPermission(AccessTokenID tokenID, const { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return false; } return proxy->IsAllowedUsingPermission(tokenID, permissionName, pid); @@ -287,7 +284,7 @@ int32_t PrivacyManagerClient::RegisterSecCompEnhance(const SecCompEnhanceData& e { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_PARAM_INVALID; } SecCompEnhanceDataParcel registerParcel; @@ -299,7 +296,7 @@ int32_t PrivacyManagerClient::UpdateSecCompEnhance(int32_t pid, uint32_t seqNum) { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_PARAM_INVALID; } return proxy->UpdateSecCompEnhance(pid, seqNum); @@ -309,7 +306,7 @@ int32_t PrivacyManagerClient::GetSecCompEnhance(int32_t pid, SecCompEnhanceData& { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_PARAM_INVALID; } SecCompEnhanceDataParcel parcel; @@ -326,7 +323,7 @@ int32_t PrivacyManagerClient::GetSpecialSecCompEnhance(const std::string& bundle { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_PARAM_INVALID; } std::vector parcelList; @@ -346,7 +343,7 @@ int32_t PrivacyManagerClient::GetPermissionUsedTypeInfos(const AccessTokenID tok { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } @@ -365,7 +362,7 @@ int32_t PrivacyManagerClient::SetMutePolicy(uint32_t policyType, uint32_t caller { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } return proxy->SetMutePolicy(policyType, callerType, isMute); @@ -375,7 +372,7 @@ int32_t PrivacyManagerClient::SetHapWithFGReminder(uint32_t tokenId, bool isAllo { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } return proxy->SetHapWithFGReminder(tokenId, isAllowed); @@ -392,12 +389,12 @@ void PrivacyManagerClient::InitProxy() if (proxy_ == nullptr || proxy_->AsObject() == nullptr || proxy_->AsObject()->IsObjectDead()) { auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (sam == nullptr) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetSystemAbilityManager is null"); + LOGD(PRI_DOMAIN, PRI_TAG, "GetSystemAbilityManager is null"); return; } auto privacySa = sam->CheckSystemAbility(IPrivacyManager::SA_ID_PRIVACY_MANAGER_SERVICE); if (privacySa == nullptr) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "CheckSystemAbility %{public}d is null", + LOGD(PRI_DOMAIN, PRI_TAG, "CheckSystemAbility %{public}d is null", IPrivacyManager::SA_ID_PRIVACY_MANAGER_SERVICE); return; } @@ -408,7 +405,7 @@ void PrivacyManagerClient::InitProxy() } proxy_ = new PrivacyManagerProxy(privacySa); if (proxy_ == nullptr || proxy_->AsObject() == nullptr || proxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Iface_cast get null"); + LOGD(PRI_DOMAIN, PRI_TAG, "Iface_cast get null"); } } } diff --git a/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp b/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp index 2053973b5edc81ddac2fd5afb13be7a24391457b..02543491ab951647e1c420d2dfed05e8a381fb38 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp +++ b/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp @@ -22,10 +22,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyManagerProxy" -}; - #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE static const int MAX_SEC_COMP_ENHANCE_SIZE = 1000; #endif @@ -45,7 +41,7 @@ int32_t PrivacyManagerProxy::AddPermissionUsedRecord(const AddPermParamInfoParce MessageParcel addData; addData.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); if (!addData.WriteParcelable(&infoParcel)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(infoParcel)"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteParcelable(infoParcel)"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } @@ -54,7 +50,7 @@ int32_t PrivacyManagerProxy::AddPermissionUsedRecord(const AddPermParamInfoParce return PrivacyError::ERR_SERVICE_ABNORMAL; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } @@ -64,15 +60,15 @@ int32_t PrivacyManagerProxy::StartUsingPermission( MessageParcel startData; startData.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); if (!startData.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenID"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!startData.WriteInt32(pid)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write pid"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write pid"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!startData.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permissionName"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write permissionName"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } uint32_t usedType = static_cast(type); @@ -87,7 +83,7 @@ int32_t PrivacyManagerProxy::StartUsingPermission( } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } @@ -98,19 +94,19 @@ int32_t PrivacyManagerProxy::StartUsingPermission( MessageParcel data; data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenID"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteInt32(pid)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write pid"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write pid"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permissionName"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write permissionName"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteRemoteObject(callback)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write remote object."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write remote object."); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } uint32_t usedType = static_cast(type); @@ -121,12 +117,12 @@ int32_t PrivacyManagerProxy::StartUsingPermission( MessageParcel reply; if (!SendRequest(PrivacyInterfaceCode::START_USING_PERMISSION_CALLBACK, data, reply)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest fail"); + LOGE(ATM_DOMAIN, ATM_TAG, "SendRequest fail"); return PrivacyError::ERR_SERVICE_ABNORMAL; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } @@ -136,15 +132,15 @@ int32_t PrivacyManagerProxy::StopUsingPermission( MessageParcel stopData; stopData.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); if (!stopData.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenID"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!stopData.WriteInt32(pid)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write pid"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write pid"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!stopData.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permissionName"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write permissionName"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } @@ -154,7 +150,7 @@ int32_t PrivacyManagerProxy::StopUsingPermission( } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } @@ -163,7 +159,7 @@ int32_t PrivacyManagerProxy::RemovePermissionUsedRecords(AccessTokenID tokenID) MessageParcel data; data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteUint32(%{public}d)", tokenID); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } @@ -173,7 +169,7 @@ int32_t PrivacyManagerProxy::RemovePermissionUsedRecords(AccessTokenID tokenID) } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } @@ -183,7 +179,7 @@ int32_t PrivacyManagerProxy::GetPermissionUsedRecords(const PermissionUsedReques MessageParcel data; data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); if (!data.WriteParcelable(&request)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(request)"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteParcelable(request)"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } @@ -193,13 +189,13 @@ int32_t PrivacyManagerProxy::GetPermissionUsedRecords(const PermissionUsedReques } int32_t ret = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", ret); if (ret != RET_SUCCESS) { return ret; } sptr resultSptr = reply.ReadParcelable(); if (resultSptr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail"); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable fail"); return PrivacyError::ERR_READ_PARCEL_FAILED; } result = *resultSptr; @@ -212,11 +208,11 @@ int32_t PrivacyManagerProxy::GetPermissionUsedRecords(const PermissionUsedReques MessageParcel data; data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); if (!data.WriteParcelable(&request)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(request)"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteParcelable(request)"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteRemoteObject(callback->AsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteRemoteObject(callback)"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteRemoteObject(callback)"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } @@ -226,7 +222,7 @@ int32_t PrivacyManagerProxy::GetPermissionUsedRecords(const PermissionUsedReques } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } @@ -235,24 +231,24 @@ int32_t PrivacyManagerProxy::RegisterPermActiveStatusCallback( { MessageParcel data; if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write WriteInterfaceToken."); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } uint32_t listSize = permList.size(); if (!data.WriteUint32(listSize)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write listSize"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write listSize"); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } for (uint32_t i = 0; i < listSize; i++) { if (!data.WriteString(permList[i])) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permList[%{public}d], %{public}s", i, permList[i].c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write permList[%{public}d], %{public}s", i, permList[i].c_str()); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } } if (!data.WriteRemoteObject(callback)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write remote object."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write remote object."); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } MessageParcel reply; @@ -261,7 +257,7 @@ int32_t PrivacyManagerProxy::RegisterPermActiveStatusCallback( } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server data = %{public}d", result); return result; } @@ -269,11 +265,11 @@ int32_t PrivacyManagerProxy::UnRegisterPermActiveStatusCallback(const sptr MAX_SEC_COMP_ENHANCE_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Size = %{public}d get from request is invalid", size); + LOGE(ATM_DOMAIN, ATM_TAG, "Size = %{public}d get from request is invalid", size); return PrivacyError::ERR_OVERSIZE; } for (uint32_t i = 0; i < size; i++) { @@ -441,15 +437,15 @@ int32_t PrivacyManagerProxy::GetPermissionUsedTypeInfos(const AccessTokenID toke MessageParcel data; MessageParcel reply; if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write WriteInterfaceToken."); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteUint32(%{public}d)", tokenId); return false; } if (!data.WriteString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteString(%{public}s)", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteString(%{public}s)", permissionName.c_str()); return false; } @@ -458,14 +454,14 @@ int32_t PrivacyManagerProxy::GetPermissionUsedTypeInfos(const AccessTokenID toke } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server is %{public}d.", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server is %{public}d.", result); if (result != RET_SUCCESS) { return result; } uint32_t size = reply.ReadUint32(); if (size > MAX_PERMISSION_USED_TYPE_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed, results oversize %{public}d, please add query params!", size); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed, results oversize %{public}d, please add query params!", size); return PrivacyError::ERR_OVERSIZE; } for (uint32_t i = 0; i < size; i++) { @@ -482,27 +478,27 @@ int32_t PrivacyManagerProxy::SetMutePolicy(uint32_t policyType, uint32_t callerT MessageParcel data; MessageParcel reply; if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write WriteInterfaceToken."); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(policyType)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", policyType); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteUint32(%{public}d)", policyType); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(callerType)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", callerType); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteUint32(%{public}d)", callerType); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteBool(isMute)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteBool(%{public}d)", isMute); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteBool(%{public}d)", isMute); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!SendRequest(PrivacyInterfaceCode::SET_MUTE_POLICY, data, reply)) { return PrivacyError::ERR_SERVICE_ABNORMAL; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "result from server is %{public}d.", result); + LOGI(ATM_DOMAIN, ATM_TAG, "result from server is %{public}d.", result); return result; } @@ -511,24 +507,24 @@ int32_t PrivacyManagerProxy::SetHapWithFGReminder(uint32_t tokenId, bool isAllow MessageParcel data; MessageParcel reply; if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write WriteInterfaceToken."); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(tokenId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteUint32(%{public}d)", tokenId); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteBool(isAllowed)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteBool(%{public}d)", isAllowed); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to WriteBool(%{public}d)", isAllowed); return PrivacyError::ERR_WRITE_PARCEL_FAILED; } if (!SendRequest(PrivacyInterfaceCode::SET_HAP_WITH_FOREGROUND_REMINDER, data, reply)) { return PrivacyError::ERR_SERVICE_ABNORMAL; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Result from server is %{public}d.", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Result from server is %{public}d.", result); return result; } @@ -544,13 +540,13 @@ bool PrivacyManagerProxy::SendRequest( MessageOption option(flag); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service null."); return false; } int32_t result = remote->SendRequest(static_cast(code), data, reply, option); if (result != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest(code=%{public}d) fail, result: %{public}d", code, result); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest(code=%{public}d) fail, result: %{public}d", code, result); return false; } return true; diff --git a/interfaces/innerkits/privacy/src/state_change_callback.cpp b/interfaces/innerkits/privacy/src/state_change_callback.cpp index 9ed950d575d821790a60f5d0645f10c1aa454f51..ca3ec08c820d583fefb6619322086dcc7236c8e5 100644 --- a/interfaces/innerkits/privacy/src/state_change_callback.cpp +++ b/interfaces/innerkits/privacy/src/state_change_callback.cpp @@ -19,9 +19,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "StateChangeCallback" -}; StateChangeCallback::StateChangeCallback( const std::shared_ptr &customizedCallback) : customizedCallback_(customizedCallback) @@ -33,7 +30,7 @@ StateChangeCallback::~StateChangeCallback() void StateChangeCallback::StateChangeNotify(AccessTokenID tokenId, bool isShowing) { if (customizedCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "CustomizedCallback_ is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "CustomizedCallback_ is nullptr"); return; } diff --git a/interfaces/innerkits/privacy/src/state_change_callback_stub.cpp b/interfaces/innerkits/privacy/src/state_change_callback_stub.cpp index 2ebdb770e869a4839014b9f7424d1f4c76ecd472..9b1a502023a3b9e2ebc1ca80e5adffc15b3f9cc0 100644 --- a/interfaces/innerkits/privacy/src/state_change_callback_stub.cpp +++ b/interfaces/innerkits/privacy/src/state_change_callback_stub.cpp @@ -23,19 +23,13 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "StateChangeCallbackStub" -}; -} - int32_t StateChangeCallbackStub::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code); + LOGD(PRI_DOMAIN, PRI_TAG, "Entry, code: 0x%{public}x", code); std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != IStateChangeCallback::GetDescriptor()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); return ERROR_IPC_REQUEST_FAIL; } diff --git a/interfaces/innerkits/privacy/test/unittest/app_manager_client/app_manager_access_client.cpp b/interfaces/innerkits/privacy/test/unittest/app_manager_client/app_manager_access_client.cpp index 2aab421e634929313866b8096a3a946bec094b44..7e36190b1e273dd7b9c9826b1510836a5f33b504 100644 --- a/interfaces/innerkits/privacy/test/unittest/app_manager_client/app_manager_access_client.cpp +++ b/interfaces/innerkits/privacy/test/unittest/app_manager_client/app_manager_access_client.cpp @@ -23,9 +23,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AppManagerAccessClient" -}; std::recursive_mutex g_instanceMutex; } // namespace @@ -55,7 +52,7 @@ int32_t AppManagerAccessClient::GetForegroundApplications(std::vectorGetForegroundApplications(list); @@ -65,19 +62,19 @@ void AppManagerAccessClient::InitProxy() { auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (sam == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbilityManager is null"); + LOGE(PRI_DOMAIN, PRI_TAG, "GetSystemAbilityManager is null"); return; } auto appManagerSa = sam->GetSystemAbility(APP_MGR_SERVICE_ID); if (appManagerSa == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbility %{public}d is null", + LOGE(PRI_DOMAIN, PRI_TAG, "GetSystemAbility %{public}d is null", APP_MGR_SERVICE_ID); return; } proxy_ = new AppManagerAccessProxy(appManagerSa); if (proxy_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Iface_cast get null"); + LOGE(PRI_DOMAIN, PRI_TAG, "Iface_cast get null"); } } diff --git a/interfaces/innerkits/privacy/test/unittest/app_manager_client/app_manager_access_proxy.cpp b/interfaces/innerkits/privacy/test/unittest/app_manager_client/app_manager_access_proxy.cpp index 51666e0ff2bac18a9fdbe0c86f44390a5e613db4..3f97f168cef2c5f4bc8c389046b1a30d3bc3d0fa 100644 --- a/interfaces/innerkits/privacy/test/unittest/app_manager_client/app_manager_access_proxy.cpp +++ b/interfaces/innerkits/privacy/test/unittest/app_manager_client/app_manager_access_proxy.cpp @@ -20,7 +20,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AppManagerAccessProxy"}; static constexpr int32_t ERROR = -1; constexpr int32_t CYCLE_LIMIT = 1000; } @@ -31,18 +30,18 @@ int32_t AppManagerAccessProxy::GetForegroundApplications(std::vectorSendRequest( static_cast(IAppMgr::Message::GET_FOREGROUND_APPLICATIONS), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetForegroundApplications failed, error: %{public}d", error); + LOGE(PRI_DOMAIN, PRI_TAG, "GetForegroundApplications failed, error: %{public}d", error); return error; } uint32_t infoSize = reply.ReadUint32(); if (infoSize > CYCLE_LIMIT) { - ACCESSTOKEN_LOG_ERROR(LABEL, "InfoSize is too large"); + LOGE(PRI_DOMAIN, PRI_TAG, "InfoSize is too large"); return ERROR; } for (uint32_t i = 0; i < infoSize; i++) { diff --git a/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.h b/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.h index 3ef705195469c38eb1c4ca3b5d2d6f6cbfc183ba..313807dcdffc9750e1bd6670ae8998b6c80dd1ed 100644 --- a/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.h +++ b/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.h @@ -46,7 +46,6 @@ public: GTEST_LOG_(INFO) << "TestCallBack, code :" << code << ", bundleSize :" << result.bundleRecords.size(); } }; - std::string GetLocalDeviceUdid(); void BuildQueryRequest(AccessTokenID tokenId, const std::string& bundleName, const std::vector& permissionList, PermissionUsedRequest& request); void CheckPermissionUsedResult(const PermissionUsedRequest& request, const PermissionUsedResult& result, diff --git a/interfaces/innerkits/token_callback/src/token_callback_stub.cpp b/interfaces/innerkits/token_callback/src/token_callback_stub.cpp index e8d380ea86eb75694fae7a0789de4efc34c44b2e..c84a3c45f5b6d6c221265b5e656340c9c13c2adb 100644 --- a/interfaces/innerkits/token_callback/src/token_callback_stub.cpp +++ b/interfaces/innerkits/token_callback/src/token_callback_stub.cpp @@ -23,9 +23,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "TokenCallbackStub" -}; static const int32_t LIST_SIZE_MAX = 200; static const int32_t FAILED = -1; } @@ -38,10 +35,10 @@ static std::string to_utf8(std::u16string str16) int32_t TokenCallbackStub::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code); + LOGI(ATM_DOMAIN, ATM_TAG, "Entry, code: 0x%{public}x", code); std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != ITokenCallback::GetDescriptor()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); return ERROR_IPC_REQUEST_FAIL; } @@ -49,7 +46,7 @@ int32_t TokenCallbackStub::OnRemoteRequest( if (msgCode == ITokenCallback::GRANT_RESULT_CALLBACK) { uint32_t permListSize = data.ReadUint32(); if (permListSize > LIST_SIZE_MAX) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read permListSize fail %{public}u", permListSize); + LOGE(ATM_DOMAIN, ATM_TAG, "Read permListSize fail %{public}u", permListSize); return FAILED; } std::vector permList; @@ -61,7 +58,7 @@ int32_t TokenCallbackStub::OnRemoteRequest( uint32_t statusListSize = data.ReadUint32(); if (statusListSize != permListSize) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read statusListSize fail %{public}u", statusListSize); + LOGE(ATM_DOMAIN, ATM_TAG, "Read statusListSize fail %{public}u", statusListSize); return FAILED; } std::vector grantResults; diff --git a/interfaces/innerkits/tokensync/src/token_sync_kit.cpp b/interfaces/innerkits/tokensync/src/token_sync_kit.cpp index f66f2dd1c6bc063d98ad87737509e170c20ed6db..2a613bd3000b480c10c3a09e1bf1adb00f647d82 100644 --- a/interfaces/innerkits/tokensync/src/token_sync_kit.cpp +++ b/interfaces/innerkits/tokensync/src/token_sync_kit.cpp @@ -27,26 +27,22 @@ namespace Security { namespace AccessToken { using namespace std; -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TokenSyncKit"}; -} // namespace - int TokenSyncKit::GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called, deviceID=%{public}s tokenID=%{public}d", - __func__, ConstantCommon::EncryptDevId(deviceID).c_str(), tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "DeviceID=%{public}s Id=%{public}d", + ConstantCommon::EncryptDevId(deviceID).c_str(), tokenID); return TokenSyncManagerClient::GetInstance().GetRemoteHapTokenInfo(deviceID, tokenID); } int TokenSyncKit::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called, tokenID=%{public}d", __func__, tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id=%{public}d", tokenID); return TokenSyncManagerClient::GetInstance().DeleteRemoteHapTokenInfo(tokenID); } int TokenSyncKit::UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called tokenID=%{public}d", __func__, tokenInfo.baseInfo.tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id=%{public}d", tokenInfo.baseInfo.tokenID); return TokenSyncManagerClient::GetInstance().UpdateRemoteHapTokenInfo(tokenInfo); } } // namespace AccessToken diff --git a/interfaces/innerkits/tokensync/src/token_sync_manager_client.cpp b/interfaces/innerkits/tokensync/src/token_sync_manager_client.cpp index bc7133304de4a581618042f69857acf774807732..56a7b253b75985eec27dc95a59b0337a98d51d46 100644 --- a/interfaces/innerkits/tokensync/src/token_sync_manager_client.cpp +++ b/interfaces/innerkits/tokensync/src/token_sync_manager_client.cpp @@ -24,7 +24,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TokenSyncManagerClient"}; std::recursive_mutex g_instanceMutex; } // namespace @@ -46,15 +45,15 @@ TokenSyncManagerClient::TokenSyncManagerClient() TokenSyncManagerClient::~TokenSyncManagerClient() { - ACCESSTOKEN_LOG_ERROR(LABEL, "~TokenSyncManagerClient"); + LOGE(ATM_DOMAIN, ATM_TAG, "~TokenSyncManagerClient"); } int TokenSyncManagerClient::GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) const { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Called"); + LOGD(ATM_DOMAIN, ATM_TAG, "Called"); auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return TOKEN_SYNC_IPC_ERROR; } return proxy->GetRemoteHapTokenInfo(deviceID, tokenID); @@ -62,10 +61,10 @@ int TokenSyncManagerClient::GetRemoteHapTokenInfo(const std::string& deviceID, A int TokenSyncManagerClient::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) const { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Called"); + LOGD(ATM_DOMAIN, ATM_TAG, "Called"); auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return TOKEN_SYNC_IPC_ERROR; } return proxy->DeleteRemoteHapTokenInfo(tokenID); @@ -73,10 +72,10 @@ int TokenSyncManagerClient::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) cons int TokenSyncManagerClient::UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo) const { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Called"); + LOGD(ATM_DOMAIN, ATM_TAG, "Called"); auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return TOKEN_SYNC_IPC_ERROR; } return proxy->UpdateRemoteHapTokenInfo(tokenInfo); @@ -86,20 +85,20 @@ sptr TokenSyncManagerClient::GetProxy() const { auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (sam == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "GetSystemAbilityManager is null"); + LOGW(ATM_DOMAIN, ATM_TAG, "GetSystemAbilityManager is null"); return nullptr; } auto tokensyncSa = sam->GetSystemAbility(ITokenSyncManager::SA_ID_TOKENSYNC_MANAGER_SERVICE); if (tokensyncSa == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "GetSystemAbility %{public}d is null", + LOGW(ATM_DOMAIN, ATM_TAG, "GetSystemAbility %{public}d is null", ITokenSyncManager::SA_ID_TOKENSYNC_MANAGER_SERVICE); return nullptr; } auto proxy = new TokenSyncManagerProxy(tokensyncSa); if (proxy == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Iface_cast get null"); + LOGW(ATM_DOMAIN, ATM_TAG, "Iface_cast get null"); return nullptr; } return proxy; diff --git a/interfaces/innerkits/tokensync/src/token_sync_manager_proxy.cpp b/interfaces/innerkits/tokensync/src/token_sync_manager_proxy.cpp index 8876c2372411b06c8bc8f4632c7a8f555ff28cad..a88bbc5fb3f7c00e45ae5cf742c7c86740a53663 100644 --- a/interfaces/innerkits/tokensync/src/token_sync_manager_proxy.cpp +++ b/interfaces/innerkits/tokensync/src/token_sync_manager_proxy.cpp @@ -22,10 +22,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TokenSyncManagerProxy"}; -} - TokenSyncManagerProxy::TokenSyncManagerProxy(const sptr& impl) : IRemoteProxy(impl) {} @@ -37,11 +33,11 @@ int TokenSyncManagerProxy::GetRemoteHapTokenInfo(const std::string& deviceID, Ac MessageParcel data; data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor()); if (!data.WriteString(deviceID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write deviceID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write deviceID"); return TOKEN_SYNC_PARAMS_INVALID; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenID"); return TOKEN_SYNC_PARAMS_INVALID; } @@ -49,18 +45,18 @@ int TokenSyncManagerProxy::GetRemoteHapTokenInfo(const std::string& deviceID, Ac MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service null."); return TOKEN_SYNC_IPC_ERROR; } int32_t requestResult = remote->SendRequest(static_cast( TokenSyncInterfaceCode::GET_REMOTE_HAP_TOKEN_INFO), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result: %{public}d", requestResult); + LOGE(ATM_DOMAIN, ATM_TAG, "Send request fail, result: %{public}d", requestResult); return TOKEN_SYNC_IPC_ERROR; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Get result from server data = %{public}d", result); + LOGD(ATM_DOMAIN, ATM_TAG, "Get result from server data = %{public}d", result); return result; } @@ -69,7 +65,7 @@ int TokenSyncManagerProxy::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) MessageParcel data; data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor()); if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenID"); return TOKEN_SYNC_PARAMS_INVALID; } @@ -77,18 +73,18 @@ int TokenSyncManagerProxy::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service null."); return TOKEN_SYNC_IPC_ERROR; } int32_t requestResult = remote->SendRequest(static_cast( TokenSyncInterfaceCode::DELETE_REMOTE_HAP_TOKEN_INFO), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result: %{public}d", requestResult); + LOGE(ATM_DOMAIN, ATM_TAG, "Send request fail, result: %{public}d", requestResult); return TOKEN_SYNC_IPC_ERROR; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Get result from server data = %{public}d", result); + LOGD(ATM_DOMAIN, ATM_TAG, "Get result from server data = %{public}d", result); return result; } @@ -101,7 +97,7 @@ int TokenSyncManagerProxy::UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& t tokenInfoParcel.hapTokenInfoForSyncParams = tokenInfo; if (!data.WriteParcelable(&tokenInfoParcel)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenInfo"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenInfo"); return TOKEN_SYNC_PARAMS_INVALID; } @@ -109,18 +105,18 @@ int TokenSyncManagerProxy::UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& t MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service null."); return TOKEN_SYNC_IPC_ERROR; } int32_t requestResult = remote->SendRequest(static_cast( TokenSyncInterfaceCode::UPDATE_REMOTE_HAP_TOKEN_INFO), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result: %{public}d", requestResult); + LOGE(ATM_DOMAIN, ATM_TAG, "Send request fail, result: %{public}d", requestResult); return TOKEN_SYNC_IPC_ERROR; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Get result from server data = %{public}d", result); + LOGD(ATM_DOMAIN, ATM_TAG, "Get result from server data = %{public}d", result); return result; } } // namespace AccessToken diff --git a/services/accesstokenmanager/BUILD.gn b/services/accesstokenmanager/BUILD.gn index 8a9b7746654f815e9d31f7faa273e6e22d4a03f1..373a76fe31a624bb26bfb7f28162ac7a0662b4c1 100644 --- a/services/accesstokenmanager/BUILD.gn +++ b/services/accesstokenmanager/BUILD.gn @@ -76,7 +76,6 @@ if (is_standard_system) { "main/cpp/src/database/access_token_db_util.cpp", "main/cpp/src/database/access_token_open_callback.cpp", "main/cpp/src/database/data_translator.cpp", - "main/cpp/src/database/token_field_const.cpp", "main/cpp/src/dfx/hisysevent_adapter.cpp", "main/cpp/src/form_manager/form_instance.cpp", "main/cpp/src/form_manager/form_manager_access_client.cpp", diff --git a/services/accesstokenmanager/main/cpp/include/database/token_field_const.h b/services/accesstokenmanager/main/cpp/include/database/token_field_const.h index 5ec731a96998d4cf1bbef448d1b71aea079adcc3..d4932903a2ac0e74c6508654b97a81e852e609a8 100644 --- a/services/accesstokenmanager/main/cpp/include/database/token_field_const.h +++ b/services/accesstokenmanager/main/cpp/include/database/token_field_const.h @@ -23,35 +23,35 @@ namespace Security { namespace AccessToken { class TokenFiledConst { public: - const static std::string FIELD_TOKEN_ID; - const static std::string FIELD_USER_ID; - const static std::string FIELD_BUNDLE_NAME; - const static std::string FIELD_INST_INDEX; - const static std::string FIELD_DLP_TYPE; - const static std::string FIELD_APP_ID; - const static std::string FIELD_DEVICE_ID; - const static std::string FIELD_APL; - const static std::string FIELD_TOKEN_VERSION; - const static std::string FIELD_TOKEN_ATTR; - const static std::string FIELD_API_VERSION; - const static std::string FIELD_FORBID_PERM_DIALOG; - const static std::string FIELD_PROCESS_NAME; - const static std::string FIELD_DCAP; - const static std::string FIELD_NATIVE_ACLS; - const static std::string FIELD_PERMISSION_NAME; - const static std::string FIELD_GRANT_MODE; - const static std::string FIELD_AVAILABLE_LEVEL; - const static std::string FIELD_PROVISION_ENABLE; - const static std::string FIELD_DISTRIBUTED_SCENE_ENABLE; - const static std::string FIELD_LABEL; - const static std::string FIELD_LABEL_ID; - const static std::string FIELD_DESCRIPTION; - const static std::string FIELD_DESCRIPTION_ID; - const static std::string FIELD_AVAILABLE_TYPE; - const static std::string FIELD_GRANT_IS_GENERAL; - const static std::string FIELD_GRANT_STATE; - const static std::string FIELD_GRANT_FLAG; - const static std::string FIELD_REQUEST_TOGGLE_STATUS; + inline static constexpr const char* FIELD_TOKEN_ID = "token_id"; + inline static constexpr const char* FIELD_USER_ID = "user_id"; + inline static constexpr const char* FIELD_BUNDLE_NAME = "bundle_name"; + inline static constexpr const char* FIELD_INST_INDEX = "inst_index"; + inline static constexpr const char* FIELD_DLP_TYPE = "dlp_type"; + inline static constexpr const char* FIELD_APP_ID = "app_id"; + inline static constexpr const char* FIELD_DEVICE_ID = "device_id"; + inline static constexpr const char* FIELD_APL = "apl"; + inline static constexpr const char* FIELD_TOKEN_VERSION = "token_version"; + inline static constexpr const char* FIELD_TOKEN_ATTR = "token_attr"; + inline static constexpr const char* FIELD_API_VERSION = "api_version"; + inline static constexpr const char* FIELD_FORBID_PERM_DIALOG = "perm_dialog_cap_state"; + inline static constexpr const char* FIELD_PROCESS_NAME = "process_name"; + inline static constexpr const char* FIELD_DCAP = "dcap"; + inline static constexpr const char* FIELD_NATIVE_ACLS = "native_acls"; + inline static constexpr const char* FIELD_PERMISSION_NAME = "permission_name"; + inline static constexpr const char* FIELD_GRANT_MODE = "grant_mode"; + inline static constexpr const char* FIELD_AVAILABLE_LEVEL = "available_level"; + inline static constexpr const char* FIELD_PROVISION_ENABLE = "provision_enable"; + inline static constexpr const char* FIELD_DISTRIBUTED_SCENE_ENABLE = "distributed_scene_enable"; + inline static constexpr const char* FIELD_LABEL = "label"; + inline static constexpr const char* FIELD_LABEL_ID = "label_id"; + inline static constexpr const char* FIELD_DESCRIPTION = "description"; + inline static constexpr const char* FIELD_DESCRIPTION_ID = "description_id"; + inline static constexpr const char* FIELD_AVAILABLE_TYPE = "available_type"; + inline static constexpr const char* FIELD_GRANT_IS_GENERAL = "is_general"; + inline static constexpr const char* FIELD_GRANT_STATE = "grant_state"; + inline static constexpr const char* FIELD_GRANT_FLAG = "grant_flag"; + inline static constexpr const char* FIELD_REQUEST_TOGGLE_STATUS = "status"; }; } // namespace AccessToken } // namespace Security diff --git a/services/accesstokenmanager/main/cpp/include/token/native_token_receptor.h b/services/accesstokenmanager/main/cpp/include/token/native_token_receptor.h index 9acf14b622a8e16630e6fb0a216ca5b0fe2155b4..fecc0e8b75aad950780f2068f9cb34c7524fc8f7 100644 --- a/services/accesstokenmanager/main/cpp/include/token/native_token_receptor.h +++ b/services/accesstokenmanager/main/cpp/include/token/native_token_receptor.h @@ -30,9 +30,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -const std::string NATIVE_TOKEN_CONFIG_FILE = "/data/service/el0/access_token/nativetoken.json"; -constexpr int MAX_NATIVE_CONFIG_FILE_SIZE = 5 * 1024 * 1024; // 5M -constexpr size_t BUFFER_SIZE = 1024; class NativeTokenReceptor final { public: static NativeTokenReceptor& GetInstance(); diff --git a/services/accesstokenmanager/main/cpp/src/callback/accesstoken_callback_proxys.cpp b/services/accesstokenmanager/main/cpp/src/callback/accesstoken_callback_proxys.cpp index 6383119a09831ef5a9473f29ffaf40ac4f8a4006..039c62c0f64a97dfe385ade866f0e397b1d9c712 100644 --- a/services/accesstokenmanager/main/cpp/src/callback/accesstoken_callback_proxys.cpp +++ b/services/accesstokenmanager/main/cpp/src/callback/accesstoken_callback_proxys.cpp @@ -28,12 +28,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenCallbackProxys" -}; -} - PermissionStateChangeCallbackProxy::PermissionStateChangeCallbackProxy(const sptr& impl) : IRemoteProxy(impl) { } @@ -45,14 +39,14 @@ void PermissionStateChangeCallbackProxy::PermStateChangeCallback(PermStateChange { MessageParcel data; if (!data.WriteInterfaceToken(IPermissionStateCallback::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "write interfacetoken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "write interfacetoken failed."); return; } PermissionStateChangeInfoParcel resultParcel; resultParcel.changeInfo = result; if (!data.WriteParcelable(&resultParcel)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteParcelable failed."); return; } @@ -60,17 +54,17 @@ void PermissionStateChangeCallbackProxy::PermStateChangeCallback(PermStateChange MessageOption option(MessageOption::TF_ASYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service null."); return; } int32_t requestResult = remote->SendRequest( static_cast(AccesstokenStateChangeInterfaceCode::PERMISSION_STATE_CHANGE), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result: %{public}d", requestResult); + LOGE(ATM_DOMAIN, ATM_TAG, "Send request fail, result: %{public}d", requestResult); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "SendRequest success"); + LOGI(ATM_DOMAIN, ATM_TAG, "SendRequest success"); } #ifdef TOKEN_SYNC_ENABLE @@ -85,16 +79,16 @@ int32_t TokenSyncCallbackProxy::GetRemoteHapTokenInfo(const std::string& deviceI { MessageParcel data; if (!data.WriteInterfaceToken(ITokenSyncCallback::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "write interfacetoken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "write interfacetoken failed."); return TOKEN_SYNC_PARAMS_INVALID; } if (!data.WriteString(deviceID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write deviceID."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write deviceID."); return TOKEN_SYNC_PARAMS_INVALID; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenID."); return TOKEN_SYNC_PARAMS_INVALID; } @@ -102,18 +96,18 @@ int32_t TokenSyncCallbackProxy::GetRemoteHapTokenInfo(const std::string& deviceI MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service null."); return TOKEN_SYNC_IPC_ERROR; } int32_t requestResult = remote->SendRequest(static_cast( TokenSyncCallbackInterfaceCode::GET_REMOTE_HAP_TOKEN_INFO), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result = %{public}d.", requestResult); + LOGE(ATM_DOMAIN, ATM_TAG, "Send request fail, result = %{public}d.", requestResult); return TOKEN_SYNC_IPC_ERROR; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Get result from callback, data = %{public}d.", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Get result from callback, data = %{public}d.", result); return result; } @@ -121,11 +115,11 @@ int32_t TokenSyncCallbackProxy::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) { MessageParcel data; if (!data.WriteInterfaceToken(ITokenSyncCallback::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "write interfacetoken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "write interfacetoken failed."); return TOKEN_SYNC_PARAMS_INVALID; } if (!data.WriteUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenID."); return TOKEN_SYNC_PARAMS_INVALID; } @@ -133,18 +127,18 @@ int32_t TokenSyncCallbackProxy::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service null."); return TOKEN_SYNC_IPC_ERROR; } int32_t requestResult = remote->SendRequest(static_cast( TokenSyncCallbackInterfaceCode::DELETE_REMOTE_HAP_TOKEN_INFO), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result: %{public}d", requestResult); + LOGE(ATM_DOMAIN, ATM_TAG, "Send request fail, result: %{public}d", requestResult); return TOKEN_SYNC_IPC_ERROR; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Get result from callback, data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Get result from callback, data = %{public}d", result); return result; } @@ -152,7 +146,7 @@ int32_t TokenSyncCallbackProxy::UpdateRemoteHapTokenInfo(const HapTokenInfoForSy { MessageParcel data; if (!data.WriteInterfaceToken(ITokenSyncCallback::GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "write interfacetoken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "write interfacetoken failed."); return TOKEN_SYNC_PARAMS_INVALID; } @@ -160,7 +154,7 @@ int32_t TokenSyncCallbackProxy::UpdateRemoteHapTokenInfo(const HapTokenInfoForSy tokenInfoParcel.hapTokenInfoForSyncParams = tokenInfo; if (!data.WriteParcelable(&tokenInfoParcel)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenInfo."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenInfo."); return TOKEN_SYNC_PARAMS_INVALID; } @@ -168,18 +162,18 @@ int32_t TokenSyncCallbackProxy::UpdateRemoteHapTokenInfo(const HapTokenInfoForSy MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service null."); return TOKEN_SYNC_IPC_ERROR; } int32_t requestResult = remote->SendRequest(static_cast( TokenSyncCallbackInterfaceCode::UPDATE_REMOTE_HAP_TOKEN_INFO), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result = %{public}d", requestResult); + LOGE(ATM_DOMAIN, ATM_TAG, "Send request fail, result = %{public}d", requestResult); return TOKEN_SYNC_IPC_ERROR; } int32_t result = reply.ReadInt32(); - ACCESSTOKEN_LOG_INFO(LABEL, "Get result from callback, data = %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Get result from callback, data = %{public}d", result); return result; } #endif // TOKEN_SYNC_ENABLE diff --git a/services/accesstokenmanager/main/cpp/src/callback/callback_death_recipients.cpp b/services/accesstokenmanager/main/cpp/src/callback/callback_death_recipients.cpp index 3b9cfd08f82b12e0655530e55852b5af6a6f927d..43d69ee3b92e1d3d6b2c089cc515c886d632e46e 100644 --- a/services/accesstokenmanager/main/cpp/src/callback/callback_death_recipients.cpp +++ b/services/accesstokenmanager/main/cpp/src/callback/callback_death_recipients.cpp @@ -24,39 +24,33 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "CallbackDeathRecipients" -}; -} - void PermStateCallbackDeathRecipient::OnRemoteDied(const wptr& remote) { - ACCESSTOKEN_LOG_INFO(LABEL, "Enter"); + LOGI(ATM_DOMAIN, ATM_TAG, "Enter"); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote object is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote object is nullptr"); return; } sptr object = remote.promote(); if (object == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Object is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Object is nullptr"); return; } CallbackManager::GetInstance().RemoveCallback(object); - ACCESSTOKEN_LOG_INFO(LABEL, "End"); + LOGI(ATM_DOMAIN, ATM_TAG, "End"); } #ifdef TOKEN_SYNC_ENABLE void TokenSyncCallbackDeathRecipient::OnRemoteDied(const wptr& remote) { - ACCESSTOKEN_LOG_INFO(LABEL, "Call OnRemoteDied."); + LOGI(ATM_DOMAIN, ATM_TAG, "Call OnRemoteDied."); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote object is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote object is nullptr."); return; } TokenModifyNotifier::GetInstance().UnRegisterTokenSyncCallback(); - ACCESSTOKEN_LOG_INFO(LABEL, "Call UnRegisterTokenSyncCallback end."); + LOGI(ATM_DOMAIN, ATM_TAG, "Call UnRegisterTokenSyncCallback end."); } #endif // TOKEN_SYNC_ENABLE } // namespace AccessToken diff --git a/services/accesstokenmanager/main/cpp/src/callback/callback_manager.cpp b/services/accesstokenmanager/main/cpp/src/callback/callback_manager.cpp index bdb2c10c17dea03d946258274d181c9244d935b1..465cf182ea2bfe6cf0a756d39b713a7aaf1cc93e 100644 --- a/services/accesstokenmanager/main/cpp/src/callback/callback_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/callback/callback_manager.cpp @@ -29,7 +29,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "CallbackManager"}; static const uint32_t MAX_CALLBACK_SIZE = 1024; #ifndef RESOURCESCHEDULE_FFRT_ENABLE static const int MAX_PTHREAD_NAME_LEN = 15; // pthread name max length @@ -62,7 +61,7 @@ CallbackManager::~CallbackManager() int32_t CallbackManager::AddCallback(const PermStateChangeScope& scopeRes, const sptr& callback) { if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Input is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "Input is nullptr"); return AccessTokenError::ERR_PARAM_INVALID; } auto callbackScopePtr = std::make_shared(scopeRes); @@ -73,12 +72,12 @@ int32_t CallbackManager::AddCallback(const PermStateChangeScope& scopeRes, const std::lock_guard lock(mutex_); #endif if (callbackInfoList_.size() >= MAX_CALLBACK_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback size has reached limitation"); + LOGE(ATM_DOMAIN, ATM_TAG, "Callback size has reached limitation"); return AccessTokenError::ERR_CALLBACKS_EXCEED_LIMITATION; } int32_t ret = callback->AddDeathRecipient(callbackDeathRecipient_); if (ret != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "add death recipient failed ret is %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "add death recipient failed ret is %{public}d", ret); } CallbackRecord recordInstance; @@ -87,14 +86,14 @@ int32_t CallbackManager::AddCallback(const PermStateChangeScope& scopeRes, const callbackInfoList_.emplace_back(recordInstance); - ACCESSTOKEN_LOG_INFO(LABEL, "RecordInstance is added"); + LOGI(ATM_DOMAIN, ATM_TAG, "RecordInstance is added"); return RET_SUCCESS; } int32_t CallbackManager::RemoveCallback(const sptr& callback) { if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "Callback is nullptr."); return AccessTokenError::ERR_PARAM_INVALID; } @@ -106,7 +105,7 @@ int32_t CallbackManager::RemoveCallback(const sptr& callback) for (auto it = callbackInfoList_.begin(); it != callbackInfoList_.end(); ++it) { if (callback == (*it).callbackObject_) { - ACCESSTOKEN_LOG_INFO(LABEL, "Find callback"); + LOGI(ATM_DOMAIN, ATM_TAG, "Find callback"); if (callbackDeathRecipient_ != nullptr) { callback->RemoveDeathRecipient(callbackDeathRecipient_); } @@ -115,7 +114,7 @@ int32_t CallbackManager::RemoveCallback(const sptr& callback) break; } } - ACCESSTOKEN_LOG_INFO(LABEL, "CallbackInfoList_ %{public}u", (uint32_t)callbackInfoList_.size()); + LOGI(ATM_DOMAIN, ATM_TAG, "CallbackInfoList_ %{public}u", (uint32_t)callbackInfoList_.size()); return RET_SUCCESS; } @@ -146,20 +145,20 @@ void CallbackManager::ExecuteAllCallback(std::vector>& list, auto callbackSingle = [it, tokenID, permName, changeType]() { sptr callback = new PermissionStateChangeCallbackProxy(*it); if (callback != nullptr) { - ACCESSTOKEN_LOG_INFO(LABEL, "Callback execute"); + LOGI(ATM_DOMAIN, ATM_TAG, "Callback execute"); PermStateChangeInfo resInfo; resInfo.permStateChangeType = changeType; resInfo.permissionName = permName; resInfo.tokenID = tokenID; callback->PermStateChangeCallback(resInfo); - ACCESSTOKEN_LOG_INFO(LABEL, "Callback execute end"); + LOGI(ATM_DOMAIN, ATM_TAG, "Callback execute end"); } }; ffrt::submit(callbackSingle, {}, {}, ffrt::task_attr().qos(ffrt::qos_default)); #else sptr callback = new PermissionStateChangeCallbackProxy(*it); if (callback != nullptr) { - ACCESSTOKEN_LOG_INFO(LABEL, "Callback execute"); + LOGI(ATM_DOMAIN, ATM_TAG, "Callback execute"); PermStateChangeInfo resInfo; resInfo.permStateChangeType = changeType; resInfo.permissionName = permName; @@ -184,12 +183,12 @@ void CallbackManager::GetCallbackObjectList(AccessTokenID tokenID, const std::st for (auto it = callbackInfoList_.begin(); it != callbackInfoList_.end(); ++it) { std::shared_ptr scopePtr = (*it).scopePtr_; if (scopePtr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ScopePtr is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "ScopePtr is nullptr"); continue; } if (!CalledAccordingToTokenIdLlist(scopePtr->tokenIDs, tokenID) || !CalledAccordingToPermLlist(scopePtr->permList, permName)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, + LOGD(ATM_DOMAIN, ATM_TAG, "tokenID is %{public}u, permName is %{public}s", tokenID, permName.c_str()); continue; } @@ -199,9 +198,9 @@ void CallbackManager::GetCallbackObjectList(AccessTokenID tokenID, const std::st void CallbackManager::ExecuteCallbackAsync(AccessTokenID tokenID, const std::string& permName, int32_t changeType) { - ACCESSTOKEN_LOG_INFO(LABEL, "Entry"); + LOGI(ATM_DOMAIN, ATM_TAG, "Entry"); auto callbackStart = [this, tokenID, permName, changeType]() { - ACCESSTOKEN_LOG_INFO(LABEL, "CallbackStart"); + LOGI(ATM_DOMAIN, ATM_TAG, "CallbackStart"); #ifndef RESOURCESCHEDULE_FFRT_ENABLE std::string name = "AtmCallback"; pthread_setname_np(pthread_self(), name.substr(0, MAX_PTHREAD_NAME_LEN).c_str()); @@ -219,7 +218,7 @@ void CallbackManager::ExecuteCallbackAsync(AccessTokenID tokenID, const std::str std::packaged_task callbackTask(callbackStart); std::make_unique(std::move(callbackTask))->detach(); #endif - ACCESSTOKEN_LOG_DEBUG(LABEL, "The callback execution is complete"); + LOGD(ATM_DOMAIN, ATM_TAG, "The callback execution is complete"); } } // namespace AccessToken } // namespace Security diff --git a/services/accesstokenmanager/main/cpp/src/database/access_token_db.cpp b/services/accesstokenmanager/main/cpp/src/database/access_token_db.cpp index 28ce7aa1c5dd31271b3a95b79b4048897ae3f40f..00818db7494e7db795893c9c493f6b8d009e04ae 100644 --- a/services/accesstokenmanager/main/cpp/src/database/access_token_db.cpp +++ b/services/accesstokenmanager/main/cpp/src/database/access_token_db.cpp @@ -30,8 +30,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenDb"}; - constexpr const char* DATABASE_NAME = "access_token.db"; constexpr const char* ACCESSTOKEN_SERVICE_NAME = "accesstoken_service"; std::recursive_mutex g_instanceMutex; @@ -63,18 +61,18 @@ int32_t AccessTokenDb::RestoreAndInsertIfCorrupt(const int32_t resultCode, int64 return resultCode; } - ACCESSTOKEN_LOG_WARN(LABEL, "Detech database corrupt, restore from backup!"); + LOGW(ATM_DOMAIN, ACCESSTOKEN_TA, "Detech database corrupt, restore from backup!"); int32_t res = db->Restore(""); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Db restore failed, res is %{public}d.", res); + LOGE(ATM_DOMAIN, ATM_TAG, "Db restore failed, res is %{public}d.", res); return res; } - ACCESSTOKEN_LOG_INFO(LABEL, "Database restore success, try insert again!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Database restore success, try insert again!"); res = db->BatchInsert(outInsertNum, tableName, buckets); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to batch insert into table %{public}s again, res is %{public}d.", - tableName.c_str(), res); + LOGE(ATM_DOMAIN, ATM_TAG, + "Failed to batch insert into table %{public}s again, res is %{public}d.", tableName.c_str(), res); return res; } @@ -129,12 +127,12 @@ int32_t AccessTokenDb::Add(const AtmDataType type, const std::vector lock(this->rwLock_); auto db = GetRdb(); if (db == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "db is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "db is nullptr."); return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } int32_t res = db->BatchInsert(outInsertNum, tableName, buckets); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to batch insert into table %{public}s, res is %{public}d.", + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to batch insert into table %{public}s, res is %{public}d.", tableName.c_str(), res); int32_t result = RestoreAndInsertIfCorrupt(res, outInsertNum, tableName, buckets, db); if (result != NativeRdb::E_OK) { @@ -144,12 +142,12 @@ int32_t AccessTokenDb::Add(const AtmDataType type, const std::vectorRestore(""); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Db restore failed, res is %{public}d.", res); + LOGE(ATM_DOMAIN, ATM_TAG, "Db restore failed, res is %{public}d.", res); return res; } - ACCESSTOKEN_LOG_INFO(LABEL, "Database restore success, try delete again!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Database restore success, try delete again!"); res = db->Delete(deletedRows, predicates); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to delete record from table %{public}s again, res is %{public}d.", + LOGE(ATM_DOMAIN, ATM_TAG, + "Failed to delete record from table %{public}s again, res is %{public}d.", predicates.GetTableName().c_str(), res); return res; } @@ -197,13 +196,13 @@ int32_t AccessTokenDb::Remove(const AtmDataType type, const GenericValues& condi OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); auto db = GetRdb(); if (db == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "db is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "db is nullptr."); return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } int32_t res = db->Delete(deletedRows, predicates); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to delete record from table %{public}s, res is %{public}d.", + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to delete record from table %{public}s, res is %{public}d.", tableName.c_str(), res); int32_t result = RestoreAndDeleteIfCorrupt(res, deletedRows, predicates, db); if (result != NativeRdb::E_OK) { @@ -213,7 +212,7 @@ int32_t AccessTokenDb::Remove(const AtmDataType type, const GenericValues& condi } int64_t endTime = TimeUtil::GetCurrentTimestamp(); - ACCESSTOKEN_LOG_INFO(LABEL, "Remove cost %{public}" PRId64 + LOGI(ATM_DOMAIN, ATM_TAG, "Remove cost %{public}" PRId64 ", delete %{public}d records from table %{public}s.", endTime - beginTime, deletedRows, tableName.c_str()); return 0; @@ -227,17 +226,18 @@ int32_t AccessTokenDb::RestoreAndUpdateIfCorrupt(const int32_t resultCode, int32 return resultCode; } - ACCESSTOKEN_LOG_WARN(LABEL, "Detech database corrupt, restore from backup!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Detech database corrupt, restore from backup!"); int32_t res = db->Restore(""); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Db restore failed, res is %{public}d.", res); + LOGE(ATM_DOMAIN, ATM_TAG, "Db restore failed, res is %{public}d.", res); return res; } - ACCESSTOKEN_LOG_INFO(LABEL, "Database restore success, try update again!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Database restore success, try update again!"); res = db->Update(changedRows, bucket, predicates); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to update record from table %{public}s again, res is %{public}d.", + LOGE(ATM_DOMAIN, ATM_TAG, + "Failed to update record from table %{public}s again, res is %{public}d.", predicates.GetTableName().c_str(), res); return res; } @@ -270,13 +270,13 @@ int32_t AccessTokenDb::Modify(const AtmDataType type, const GenericValues& modif OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); auto db = GetRdb(); if (db == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "db is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "db is nullptr."); return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } int32_t res = db->Update(changedRows, bucket, predicates); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to update record from table %{public}s, res is %{public}d.", + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to update record from table %{public}s, res is %{public}d.", tableName.c_str(), res); int32_t result = RestoreAndUpdateIfCorrupt(res, changedRows, bucket, predicates, db); if (result != NativeRdb::E_OK) { @@ -286,7 +286,7 @@ int32_t AccessTokenDb::Modify(const AtmDataType type, const GenericValues& modif } int64_t endTime = TimeUtil::GetCurrentTimestamp(); - ACCESSTOKEN_LOG_INFO(LABEL, "Modify cost %{public}" PRId64 + LOGI(ATM_DOMAIN, ATM_TAG, "Modify cost %{public}" PRId64 ", update %{public}d records from table %{public}s.", endTime - beginTime, changedRows, tableName.c_str()); return 0; @@ -303,22 +303,22 @@ int32_t AccessTokenDb::RestoreAndQueryIfCorrupt(const NativeRdb::RdbPredicates& queryResultSet->Close(); queryResultSet = nullptr; - ACCESSTOKEN_LOG_WARN(LABEL, "Detech database corrupt, restore from backup!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Detech database corrupt, restore from backup!"); res = db->Restore(""); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Db restore failed, res is %{public}d.", res); + LOGE(ATM_DOMAIN, ATM_TAG, "Db restore failed, res is %{public}d.", res); return res; } - ACCESSTOKEN_LOG_INFO(LABEL, "Database restore success, try query again!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Database restore success, try query again!"); queryResultSet = db->Query(predicates, columns); if (queryResultSet == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to find records from table %{public}s again.", + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to find records from table %{public}s again.", predicates.GetTableName().c_str()); return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to get result count."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to get result count."); return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } } @@ -345,13 +345,13 @@ int32_t AccessTokenDb::Find(AtmDataType type, const GenericValues& conditionValu OHOS::Utils::UniqueReadGuard lock(this->rwLock_); auto db = GetRdb(); if (db == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "db is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "db is nullptr."); return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } auto queryResultSet = db->Query(predicates, columns); if (queryResultSet == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to find records from table %{public}s.", + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to find records from table %{public}s.", tableName.c_str()); return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } @@ -374,7 +374,7 @@ int32_t AccessTokenDb::Find(AtmDataType type, const GenericValues& conditionValu } int64_t endTime = TimeUtil::GetCurrentTimestamp(); - ACCESSTOKEN_LOG_INFO(LABEL, "Find cost %{public}" PRId64 + LOGI(ATM_DOMAIN, ATM_TAG, "Find cost %{public}" PRId64 ", query %{public}d records from table %{public}s.", endTime - beginTime, count, tableName.c_str()); return 0; @@ -388,14 +388,15 @@ int32_t AccessTokenDb::DeleteAndAddSingleTable(const GenericValues delCondition, int32_t deletedRows = 0; int32_t res = db->Delete(deletedRows, predicates); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to delete record from table %{public}s, res is %{public}d.", + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to delete record from table %{public}s, res is %{public}d.", tableName.c_str(), res); int32_t result = RestoreAndDeleteIfCorrupt(res, deletedRows, predicates, db); if (result != NativeRdb::E_OK) { return result; } } - ACCESSTOKEN_LOG_INFO(LABEL, "Delete %{public}d record from table %{public}s", deletedRows, tableName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, + "Delete %{public}d record from table %{public}s", deletedRows, tableName.c_str()); // if nothing to insert, no need to BatchInsert if (addValues.empty()) { @@ -407,7 +408,7 @@ int32_t AccessTokenDb::DeleteAndAddSingleTable(const GenericValues delCondition, int64_t outInsertNum = 0; res = db->BatchInsert(outInsertNum, tableName, buckets); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to batch insert into table %{public}s, res is %{public}d.", + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to batch insert into table %{public}s, res is %{public}d.", tableName.c_str(), res); int32_t result = RestoreAndInsertIfCorrupt(res, outInsertNum, tableName, buckets, db); if (result != NativeRdb::E_OK) { @@ -415,11 +416,11 @@ int32_t AccessTokenDb::DeleteAndAddSingleTable(const GenericValues delCondition, } } if (outInsertNum <= 0) { // rdb bug, adapt it - ACCESSTOKEN_LOG_ERROR(LABEL, "Insert count %{public}" PRId64 " abnormal.", outInsertNum); + LOGE(ATM_DOMAIN, ATM_TAG, "Insert count %{public}" PRId64 " abnormal.", outInsertNum); return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } - ACCESSTOKEN_LOG_INFO(LABEL, "Batch insert %{public}" PRId64 " records to table %{public}s.", outInsertNum, - tableName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, + "Batch insert %{public}" PRId64 " records to table %{public}s.", outInsertNum, tableName.c_str()); return 0; } @@ -463,7 +464,7 @@ int32_t AccessTokenDb::DeleteAndInsertHap(AccessTokenID tokenId, const std::vect OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); auto db = GetRdb(); if (db == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "db is nullptr."); + LOGE(ATM_DOMAIN, ACCESSTOKEN_TAGL, "db is nullptr."); return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } @@ -479,7 +480,7 @@ int32_t AccessTokenDb::DeleteAndInsertHap(AccessTokenID tokenId, const std::vect } int64_t endTime = TimeUtil::GetCurrentTimestamp(); - ACCESSTOKEN_LOG_ERROR(LABEL, "DeleteAndInsertHap cost %{public}" PRId64 ".", endTime - beginTime); + LOGE(ATM_DOMAIN, ATM_TAG, "DeleteAndInsertHap cost %{public}" PRId64 ".", endTime - beginTime); return 0; } diff --git a/services/accesstokenmanager/main/cpp/src/database/access_token_open_callback.cpp b/services/accesstokenmanager/main/cpp/src/database/access_token_open_callback.cpp index aee0c1b13001f280dffff51f8754303de8ecf3e7..617d93c32b971ababd154297674a2f778bb13f11 100644 --- a/services/accesstokenmanager/main/cpp/src/database/access_token_open_callback.cpp +++ b/services/accesstokenmanager/main/cpp/src/database/access_token_open_callback.cpp @@ -24,7 +24,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenOpenCallback"}; constexpr const char* INTEGER_STR = " integer not null,"; constexpr const char* TEXT_STR = " text not null,"; // back up name is xxx_slave fixed, can not be changed @@ -195,35 +194,35 @@ int32_t AccessTokenOpenCallback::CreatePermissionRequestToggleStatusTable(Native int32_t AccessTokenOpenCallback::OnCreate(NativeRdb::RdbStore& rdbStore) { - ACCESSTOKEN_LOG_INFO(LABEL, "DB OnCreate."); + LOGI(ATM_DOMAIN, ATM_TAG, "DB OnCreate."); int32_t res = CreateHapTokenInfoTable(rdbStore); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create table hap_token_info_table."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create table hap_token_info_table."); return res; } res = CreateNativeTokenInfoTable(rdbStore); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create table native_token_info_table."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create table native_token_info_table."); return res; } res = CreatePermissionDefinitionTable(rdbStore); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create table permission_definition_table."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create table permission_definition_table."); return res; } res = CreatePermissionStateTable(rdbStore); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create table permission_state_table."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create table permission_state_table."); return res; } res = CreatePermissionRequestToggleStatusTable(rdbStore); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create table permission_request_toggle_status_table."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create table permission_request_toggle_status_table."); return res; } @@ -233,14 +232,14 @@ int32_t AccessTokenOpenCallback::OnCreate(NativeRdb::RdbStore& rdbStore) } // if OnCreate solution found back up db, restore from backup, may be origin db has lost - ACCESSTOKEN_LOG_WARN(LABEL, "Detech origin database disappear, restore from backup!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Detech origin database disappear, restore from backup!"); res = rdbStore.Restore(""); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Db restore failed, res is %{public}d.", res); + LOGE(ATM_DOMAIN, ATM_TAG, "Db restore failed, res is %{public}d.", res); } - ACCESSTOKEN_LOG_WARN(LABEL, "Database restore from backup success!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Database restore from backup success!"); return 0; } @@ -255,7 +254,7 @@ int32_t AccessTokenOpenCallback::AddAvailableTypeColumn(NativeRdb::RdbStore& rdb TokenFiledConst::FIELD_AVAILABLE_TYPE + "=" + std::to_string(ATokenAvailableTypeEnum::NORMAL); int32_t checkRes = rdbStore.ExecuteSql(checkSql); - ACCESSTOKEN_LOG_INFO(LABEL, "Check result is %{public}d.", checkRes); + LOGI(ATM_DOMAIN, ATM_TAG, "Check result is %{public}d.", checkRes); if (checkRes == NativeRdb::E_OK) { // success means there exsit column available_type in table return NativeRdb::E_OK; @@ -266,7 +265,7 @@ int32_t AccessTokenOpenCallback::AddAvailableTypeColumn(NativeRdb::RdbStore& rdb TokenFiledConst::FIELD_AVAILABLE_TYPE + " integer default " + std::to_string(ATokenAvailableTypeEnum::NORMAL); int32_t res = rdbStore.ExecuteSql(sql); - ACCESSTOKEN_LOG_INFO(LABEL, "Insert column result is %{public}d.", res); + LOGI(ATM_DOMAIN, ATM_TAG, "Insert column result is %{public}d.", res); return res; } @@ -281,7 +280,7 @@ int32_t AccessTokenOpenCallback::AddRequestToggleStatusColumn(NativeRdb::RdbStor TokenFiledConst::FIELD_REQUEST_TOGGLE_STATUS + "=" + std::to_string(0); int32_t checkRes = rdbStore.ExecuteSql(checkSql); - ACCESSTOKEN_LOG_INFO(LABEL, "Check result is %{public}d.", checkRes); + LOGI(ATM_DOMAIN, ATM_TAG, "Check result is %{public}d.", checkRes); if (checkRes == NativeRdb::E_OK) { // success means there exsit column status in table return NativeRdb::E_OK; @@ -292,7 +291,7 @@ int32_t AccessTokenOpenCallback::AddRequestToggleStatusColumn(NativeRdb::RdbStor TokenFiledConst::FIELD_REQUEST_TOGGLE_STATUS + " integer default " + std::to_string(0); // 0: close int32_t res = rdbStore.ExecuteSql(sql); - ACCESSTOKEN_LOG_INFO(LABEL, "Insert column result is %{public}d.", res); + LOGI(ATM_DOMAIN, ATM_TAG, "Insert column result is %{public}d.", res); return res; } @@ -307,7 +306,7 @@ int32_t AccessTokenOpenCallback::AddPermDialogCapColumn(NativeRdb::RdbStore& rdb TokenFiledConst::FIELD_FORBID_PERM_DIALOG + "=" + std::to_string(0); int32_t checkRes = rdbStore.ExecuteSql(checkSql); - ACCESSTOKEN_LOG_INFO(LABEL, "Check result is %{public}d.", checkRes); + LOGI(ATM_DOMAIN, ATM_TAG, "Check result is %{public}d.", checkRes); if (checkRes == NativeRdb::E_OK) { // success means there exsit column perm_dialog_cap_state in table return NativeRdb::E_OK; @@ -318,7 +317,7 @@ int32_t AccessTokenOpenCallback::AddPermDialogCapColumn(NativeRdb::RdbStore& rdb TokenFiledConst::FIELD_FORBID_PERM_DIALOG + " integer default " + std::to_string(false); int32_t res = rdbStore.ExecuteSql(sql); - ACCESSTOKEN_LOG_INFO(LABEL, "Insert column result is %{public}d.", res); + LOGI(ATM_DOMAIN, ATM_TAG, "Insert column result is %{public}d.", res); return res; } @@ -330,13 +329,13 @@ int32_t AccessTokenOpenCallback::HandleUpdateWithFlag(NativeRdb::RdbStore& rdbSt if ((flag & FLAG_HANDLE_FROM_ONE_TO_TWO) == FLAG_HANDLE_FROM_ONE_TO_TWO) { res = AddAvailableTypeColumn(rdbStore); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to add column available_type."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to add column available_type."); return res; } res = AddPermDialogCapColumn(rdbStore); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to add column perm_dialog_cap_state."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to add column perm_dialog_cap_state."); return res; } } @@ -344,7 +343,7 @@ int32_t AccessTokenOpenCallback::HandleUpdateWithFlag(NativeRdb::RdbStore& rdbSt if ((flag & FLAG_HANDLE_FROM_TWO_TO_THREE) == FLAG_HANDLE_FROM_TWO_TO_THREE) { res = CreatePermissionRequestToggleStatusTable(rdbStore); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create table permission_request_toggle_status_table."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create table permission_request_toggle_status_table."); return res; } } @@ -352,7 +351,7 @@ int32_t AccessTokenOpenCallback::HandleUpdateWithFlag(NativeRdb::RdbStore& rdbSt if ((flag & FLAG_HANDLE_FROM_THREE_TO_FOUR) == FLAG_HANDLE_FROM_THREE_TO_FOUR) { res = AddRequestToggleStatusColumn(rdbStore); if (res != NativeRdb::E_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to add column status."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to add column status."); return res; } } @@ -449,8 +448,8 @@ int32_t AccessTokenOpenCallback::UpdateFromVersionThree(NativeRdb::RdbStore& rdb int32_t AccessTokenOpenCallback::OnUpgrade(NativeRdb::RdbStore& rdbStore, int32_t currentVersion, int32_t targetVersion) { - ACCESSTOKEN_LOG_INFO(LABEL, "DB OnUpgrade from currentVersion %{public}d to targetVersion %{public}d.", - currentVersion, targetVersion); + LOGI(ATM_DOMAIN, ATM_TAG, + "DB OnUpgrade from currentVersion %{public}d to targetVersion %{public}d.", currentVersion, targetVersion); int32_t res = 0; diff --git a/services/accesstokenmanager/main/cpp/src/database/data_translator.cpp b/services/accesstokenmanager/main/cpp/src/database/data_translator.cpp index f6432e200eaaedfb46d1f3211adabe106c2e4595..75c53cdf5157ab534a1a5a498f53cf863399d0df 100644 --- a/services/accesstokenmanager/main/cpp/src/database/data_translator.cpp +++ b/services/accesstokenmanager/main/cpp/src/database/data_translator.cpp @@ -27,10 +27,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "DataTranslator"}; -} - int DataTranslator::TranslationIntoGenericValues(const PermissionDef& inPermissionDef, GenericValues& outGenericValues) { outGenericValues.Put(TokenFiledConst::FIELD_PERMISSION_NAME, inPermissionDef.permissionName); @@ -55,7 +51,7 @@ int DataTranslator::TranslationIntoPermissionDef(const GenericValues& inGenericV outPermissionDef.grantMode = inGenericValues.GetInt(TokenFiledConst::FIELD_GRANT_MODE); int aplNum = inGenericValues.GetInt(TokenFiledConst::FIELD_AVAILABLE_LEVEL); if (!DataValidator::IsAplNumValid(aplNum)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Apl is wrong."); + LOGE(ATM_DOMAIN, ATM_TAG, "Apl is wrong."); return ERR_PARAM_INVALID; } outPermissionDef.availableLevel = static_cast(aplNum); @@ -76,7 +72,7 @@ int DataTranslator::TranslationIntoGenericValues(const PermissionStateFull& inPe { if (grantIndex >= inPermissionState.resDeviceID.size() || grantIndex >= inPermissionState.grantStatus.size() || grantIndex >= inPermissionState.grantFlags.size()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Perm status grant size is wrong"); + LOGE(ATM_DOMAIN, ATM_TAG, "Perm status grant size is wrong"); return ERR_PARAM_INVALID; } outGenericValues.Put(TokenFiledConst::FIELD_PERMISSION_NAME, inPermissionState.permissionName); @@ -95,7 +91,7 @@ int DataTranslator::TranslationIntoPermissionStateFull(const GenericValues& inGe ((inGenericValues.GetInt(TokenFiledConst::FIELD_GRANT_IS_GENERAL) == 1) ? true : false); outPermissionState.permissionName = inGenericValues.GetString(TokenFiledConst::FIELD_PERMISSION_NAME); if (!DataValidator::IsPermissionNameValid(outPermissionState.permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission name is wrong"); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission name is wrong"); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", HiviewDFX::HiSysEvent::EventType::FAULT, "CODE", LOAD_DATABASE_ERROR, "ERROR_REASON", "permission name error"); @@ -104,7 +100,7 @@ int DataTranslator::TranslationIntoPermissionStateFull(const GenericValues& inGe std::string devID = inGenericValues.GetString(TokenFiledConst::FIELD_DEVICE_ID); if (!DataValidator::IsDeviceIdValid(devID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "DevID is wrong"); + LOGE(ATM_DOMAIN, ATM_TAG, "DevID is wrong"); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", HiviewDFX::HiSysEvent::EventType::FAULT, "CODE", LOAD_DATABASE_ERROR, "ERROR_REASON", "permission deviceId error"); @@ -114,7 +110,7 @@ int DataTranslator::TranslationIntoPermissionStateFull(const GenericValues& inGe int grantFlag = (PermissionFlag)inGenericValues.GetInt(TokenFiledConst::FIELD_GRANT_FLAG); if (!PermissionValidator::IsPermissionFlagValid(grantFlag)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GrantFlag is wrong"); + LOGE(ATM_DOMAIN, ATM_TAG, "GrantFlag is wrong"); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", HiviewDFX::HiSysEvent::EventType::FAULT, "CODE", LOAD_DATABASE_ERROR, "ERROR_REASON", "permission grant flag error"); @@ -125,7 +121,7 @@ int DataTranslator::TranslationIntoPermissionStateFull(const GenericValues& inGe int grantStatus = (PermissionState)inGenericValues.GetInt(TokenFiledConst::FIELD_GRANT_STATE); if (!PermissionValidator::IsGrantStatusValid(grantStatus)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GrantStatus is wrong"); + LOGE(ATM_DOMAIN, ATM_TAG, "GrantStatus is wrong"); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", HiviewDFX::HiSysEvent::EventType::FAULT, "CODE", LOAD_DATABASE_ERROR, "ERROR_REASON", "permission grant status error"); diff --git a/services/accesstokenmanager/main/cpp/src/database/token_field_const.cpp b/services/accesstokenmanager/main/cpp/src/database/token_field_const.cpp deleted file mode 100644 index b27da70fbb61d322b6110df6eb543f8f92f47493..0000000000000000000000000000000000000000 --- a/services/accesstokenmanager/main/cpp/src/database/token_field_const.cpp +++ /dev/null @@ -1,51 +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 "token_field_const.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -const std::string TokenFiledConst::FIELD_TOKEN_ID = "token_id"; -const std::string TokenFiledConst::FIELD_USER_ID = "user_id"; -const std::string TokenFiledConst::FIELD_BUNDLE_NAME = "bundle_name"; -const std::string TokenFiledConst::FIELD_INST_INDEX = "inst_index"; -const std::string TokenFiledConst::FIELD_DLP_TYPE = "dlp_type"; -const std::string TokenFiledConst::FIELD_APP_ID = "app_id"; -const std::string TokenFiledConst::FIELD_DEVICE_ID = "device_id"; -const std::string TokenFiledConst::FIELD_APL = "apl"; -const std::string TokenFiledConst::FIELD_TOKEN_VERSION = "token_version"; -const std::string TokenFiledConst::FIELD_TOKEN_ATTR = "token_attr"; -const std::string TokenFiledConst::FIELD_API_VERSION = "api_version"; -const std::string TokenFiledConst::FIELD_FORBID_PERM_DIALOG = "perm_dialog_cap_state"; -const std::string TokenFiledConst::FIELD_PROCESS_NAME = "process_name"; -const std::string TokenFiledConst::FIELD_DCAP = "dcap"; -const std::string TokenFiledConst::FIELD_NATIVE_ACLS = "native_acls"; -const std::string TokenFiledConst::FIELD_PERMISSION_NAME = "permission_name"; -const std::string TokenFiledConst::FIELD_GRANT_MODE = "grant_mode"; -const std::string TokenFiledConst::FIELD_AVAILABLE_LEVEL = "available_level"; -const std::string TokenFiledConst::FIELD_PROVISION_ENABLE = "provision_enable"; -const std::string TokenFiledConst::FIELD_DISTRIBUTED_SCENE_ENABLE = "distributed_scene_enable"; -const std::string TokenFiledConst::FIELD_LABEL = "label"; -const std::string TokenFiledConst::FIELD_LABEL_ID = "label_id"; -const std::string TokenFiledConst::FIELD_DESCRIPTION = "description"; -const std::string TokenFiledConst::FIELD_DESCRIPTION_ID = "description_id"; -const std::string TokenFiledConst::FIELD_AVAILABLE_TYPE = "available_type"; -const std::string TokenFiledConst::FIELD_GRANT_IS_GENERAL = "is_general"; -const std::string TokenFiledConst::FIELD_GRANT_STATE = "grant_state"; -const std::string TokenFiledConst::FIELD_GRANT_FLAG = "grant_flag"; -const std::string TokenFiledConst::FIELD_REQUEST_TOGGLE_STATUS = "status"; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS diff --git a/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp b/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp index 4ec3b2618c3d3f4aeed2cf1eb931f24b6b02dca5..e582b7f8021281b6b989948edff7ec621e04d22e 100644 --- a/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp +++ b/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp @@ -22,8 +22,7 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AtmDfx"}; -static const std::string ACCESSTOKEN_PROCESS_NAME = "accesstoken_service"; +constexpr const char* ACCESSTOKEN_PROCESS_NAME = "accesstoken_service"; static constexpr char ADD_DOMAIN[] = "PERFORMANCE"; } @@ -36,7 +35,7 @@ void ReportSysEventPerformance() int32_t ret = HiSysEventWrite(ADD_DOMAIN, "CPU_SCENE_ENTRY", HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "PACKAGE_NAME", ACCESSTOKEN_PROCESS_NAME, "SCENE_ID", std::to_string(id).c_str(), "HAPPEN_TIME", time); if (ret != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to report performance, ret %{public}d.", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to report performance, ret %{public}d.", ret); } } @@ -46,7 +45,7 @@ void ReportSysEventServiceStart(int32_t pid, uint32_t hapSize, uint32_t nativeSi HiviewDFX::HiSysEvent::EventType::STATISTIC, "PID", pid, "HAP_SIZE", hapSize, "NATIVE_SIZE", nativeSize, "PERM_DEFINITION_SIZE", permDefSize); if (ret != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write hisysevent write, ret %{public}d.", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write hisysevent write, ret %{public}d.", ret); } } @@ -55,7 +54,7 @@ void ReportSysEventServiceStartError(SceneCode scene, const std::string& errMsg, int32_t ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "ACCESSTOKEN_SERVICE_START_ERROR", HiviewDFX::HiSysEvent::EventType::FAULT, "SCENE_CODE", scene, "ERROR_CODE", errCode, "ERROR_MSG", errMsg); if (ret != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write hisysevent write, ret %{public}d.", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write hisysevent write, ret %{public}d.", ret); } } } // namespace AccessToken diff --git a/services/accesstokenmanager/main/cpp/src/form_manager/form_instance.cpp b/services/accesstokenmanager/main/cpp/src/form_manager/form_instance.cpp index 77006681661baadcbe0ba9cbb2951ae28139d6fa..05d46e845b0979630147cbba24b4c7333948e092 100644 --- a/services/accesstokenmanager/main/cpp/src/form_manager/form_instance.cpp +++ b/services/accesstokenmanager/main/cpp/src/form_manager/form_instance.cpp @@ -20,28 +20,23 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "FormInstance" -}; -} bool FormInstance::ReadFromParcel(Parcel &parcel) { if (!parcel.ReadInt64(formId_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt64 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt64 failed."); return false; } std::u16string u16FormHostName; if (!parcel.ReadString16(u16FormHostName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadString16 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadString16 failed."); return false; } formHostName_ = Str16ToStr8(u16FormHostName); int32_t formVisiblity; if ((!parcel.ReadInt32(formVisiblity)) || (!parcel.ReadInt32(specification_))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return false; } formVisiblity_ = static_cast(formVisiblity); @@ -52,7 +47,7 @@ bool FormInstance::ReadFromParcel(Parcel &parcel) std::u16string u16FormName; if (!parcel.ReadString16(u16BundleName) || (!parcel.ReadString16(u16ModuleName)) || (!parcel.ReadString16(u16AbilityName)) || (!parcel.ReadString16(u16FormName))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadString16 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadString16 failed."); return false; } bundleName_ = Str16ToStr8(u16BundleName); @@ -62,19 +57,19 @@ bool FormInstance::ReadFromParcel(Parcel &parcel) int32_t formUsageState; if (!parcel.ReadInt32(formUsageState)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return false; } formUsageState_ = static_cast(formUsageState); std::u16string u16description; if (!parcel.ReadString16(u16description)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadString16 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadString16 failed."); return false; } description_ = Str16ToStr8(u16description); if ((!parcel.ReadInt32(appIndex_)) || (!parcel.ReadInt32(userId_))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return false; } @@ -84,42 +79,42 @@ bool FormInstance::ReadFromParcel(Parcel &parcel) bool FormInstance::Marshalling(Parcel &parcel) const { if (!parcel.WriteInt64(formId_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt64 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt64 failed."); return false; } if (!parcel.WriteString16(Str8ToStr16(formHostName_))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString16 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString16 failed."); return false; } if ((!parcel.WriteInt32(static_cast(formVisiblity_))) || (!parcel.WriteInt32(specification_))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return false; } if ((!parcel.WriteString16(Str8ToStr16(bundleName_))) || (!parcel.WriteString16(Str8ToStr16(moduleName_))) || (!parcel.WriteString16(Str8ToStr16(abilityName_))) || (!parcel.WriteString16(Str8ToStr16(formName_)))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString16 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString16 failed."); return false; } if (!parcel.WriteInt32(static_cast(formUsageState_))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return false; } if (!parcel.WriteString16(Str8ToStr16(description_))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString16 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString16 failed."); return false; } if (!parcel.WriteInt32(appIndex_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return false; } if (!parcel.WriteInt32(userId_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return false; } return true; diff --git a/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_client.cpp b/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_client.cpp index b3ba7baecf28b3fe779530e721865a131e7f2e02..21e0847f708a377fcd024abe755a7d9d1775f2a6 100644 --- a/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_client.cpp +++ b/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_client.cpp @@ -23,9 +23,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "FormManagerAccessClient" -}; std::recursive_mutex g_instanceMutex; } // namespace @@ -55,12 +52,12 @@ int32_t FormManagerAccessClient::RegisterAddObserver( const std::string &bundleName, const sptr &callerToken) { if (callerToken == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "Callback is nullptr."); return -1; } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return -1; } return proxy->RegisterAddObserver(bundleName, callerToken); @@ -70,12 +67,12 @@ int32_t FormManagerAccessClient::RegisterRemoveObserver( const std::string &bundleName, const sptr &callerToken) { if (callerToken == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "Callback is nullptr."); return -1; } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return -1; } return proxy->RegisterRemoveObserver(bundleName, callerToken); @@ -85,7 +82,7 @@ bool FormManagerAccessClient::HasFormVisible(const uint32_t tokenId) { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return false; } return proxy->HasFormVisible(tokenId); @@ -95,12 +92,12 @@ void FormManagerAccessClient::InitProxy() { auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (sam == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbilityManager is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "GetSystemAbilityManager is null."); return; } auto formManagerSa = sam->GetSystemAbility(FORM_MGR_SERVICE_ID); if (formManagerSa == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbility %{public}d is null.", + LOGE(ATM_DOMAIN, ATM_TAG, "GetSystemAbility %{public}d is null.", APP_MGR_SERVICE_ID); return; } @@ -112,7 +109,7 @@ void FormManagerAccessClient::InitProxy() proxy_ = new FormManagerAccessProxy(formManagerSa); if (proxy_ == nullptr || proxy_->AsObject() == nullptr || proxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Iface_cast get null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Iface_cast get null."); } } diff --git a/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_proxy.cpp b/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_proxy.cpp index 141cb3c50516e37269e8f3ddeebecd3acf3e1763..90b8a9b1f135a897a8fabab91113e93721bdfdc9 100644 --- a/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_proxy.cpp +++ b/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_proxy.cpp @@ -20,7 +20,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "FormManagerAccessProxy"}; static constexpr int32_t ERROR = -1; } @@ -31,26 +30,26 @@ int32_t FormManagerAccessProxy::RegisterAddObserver( MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERROR; } if (!data.WriteString(bundleName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write bundleName failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write bundleName failed."); return ERROR; } if (!data.WriteRemoteObject(callerToken)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write callerToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write callerToken failed."); return ERROR; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return ERROR; } int32_t error = remote->SendRequest( static_cast(IFormMgr::Message::FORM_MGR_REGISTER_ADD_OBSERVER), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RegisterAddObserver failed, error: %{public}d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "RegisterAddObserver failed, error: %{public}d", error); return ERROR; } return reply.ReadInt32(); @@ -63,26 +62,26 @@ int32_t FormManagerAccessProxy::RegisterRemoveObserver( MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERROR; } if (!data.WriteString(bundleName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write bundleName failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write bundleName failed."); return ERROR; } if (!data.WriteRemoteObject(callerToken)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write callerToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write callerToken failed."); return ERROR; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return ERROR; } int32_t error = remote->SendRequest( static_cast(IFormMgr::Message::FORM_MGR_REGISTER_REMOVE_OBSERVER), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UnregisterAddObserver failed, error: %d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "UnregisterAddObserver failed, error: %d", error); return error; } return reply.ReadInt32(); @@ -94,23 +93,23 @@ bool FormManagerAccessProxy::HasFormVisible(const uint32_t tokenId) MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return false; } if (!data.WriteUint32(tokenId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenId."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenId."); return false; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return false; } int32_t error = remote->SendRequest( static_cast(IFormMgr::Message::FORM_MGR_HAS_FORM_VISIBLE_WITH_TOKENID), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get form visibility failed, error: %{public}d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "Get form visibility failed, error: %{public}d", error); return false; } return reply.ReadBool(); diff --git a/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_death_recipient.cpp b/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_death_recipient.cpp index 9ad8b8231e60637c17be117364c9728295efaafc..5708cb7b3c0a9042d7589769b849c49e1888309f 100644 --- a/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_death_recipient.cpp +++ b/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_death_recipient.cpp @@ -20,15 +20,9 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "FormMgrDeathRecipient" -}; -} // namespace - void FormMgrDeathRecipient::OnRemoteDied(const wptr& object) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called", __func__); + LOGI(ATM_DOMAIN, ATM_TAG, "%{public}s called", __func__); FormManagerAccessClient::GetInstance().OnRemoteDiedHandle(); } } // namespace AccessToken diff --git a/services/accesstokenmanager/main/cpp/src/form_manager/form_status_change_callback.cpp b/services/accesstokenmanager/main/cpp/src/form_manager/form_status_change_callback.cpp index fc8c18e86c8cf48c41eff79e5ba7cb85d21b8dc3..aedaccfd1c7106714063092af62ad77ba95f9ad2 100644 --- a/services/accesstokenmanager/main/cpp/src/form_manager/form_status_change_callback.cpp +++ b/services/accesstokenmanager/main/cpp/src/form_manager/form_status_change_callback.cpp @@ -23,26 +23,23 @@ namespace Security { namespace AccessToken { namespace { static constexpr int32_t MAX_ALLOW_SIZE = 8 * 1024; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "FormStateObserverStub" -}; } FormStateObserverStub::FormStateObserverStub() { - ACCESSTOKEN_LOG_INFO(LABEL, "FormStateObserverStub Instance create."); + LOGI(ATM_DOMAIN, ATM_TAG, "FormStateObserverStub Instance create."); } FormStateObserverStub::~FormStateObserverStub() { - ACCESSTOKEN_LOG_INFO(LABEL, "FormStateObserverStub Instance destroy."); + LOGI(ATM_DOMAIN, ATM_TAG, "FormStateObserverStub Instance destroy."); } int32_t FormStateObserverStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { if (data.ReadInterfaceToken() != GetDescriptor()) { - ACCESSTOKEN_LOG_INFO(LABEL, "FormStateObserverStub: ReadInterfaceToken failed."); + LOGI(ATM_DOMAIN, ATM_TAG, "FormStateObserverStub: ReadInterfaceToken failed."); return ERROR_IPC_REQUEST_FAIL; } switch (static_cast(code)) { @@ -51,7 +48,7 @@ int32_t FormStateObserverStub::OnRemoteRequest( return NO_ERROR; } default: { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Default case code: %{public}d.", code); + LOGD(ATM_DOMAIN, ATM_TAG, "Default case code: %{public}d.", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } @@ -65,13 +62,13 @@ int32_t FormStateObserverStub::HandleNotifyWhetherFormsVisible(MessageParcel &da std::vector formInstances; int32_t infoSize = data.ReadInt32(); if (infoSize < 0 || infoSize > MAX_ALLOW_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid size: %{public}d.", infoSize); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid size: %{public}d.", infoSize); return ERR_OVERSIZE; } for (int32_t i = 0; i < infoSize; i++) { std::unique_ptr info(data.ReadParcelable()); if (info == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to Read Parcelable infos."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Read Parcelable infos."); return RET_FAILED; } formInstances.emplace_back(*info); diff --git a/services/accesstokenmanager/main/cpp/src/permission/dlp_permission_set_manager.cpp b/services/accesstokenmanager/main/cpp/src/permission/dlp_permission_set_manager.cpp index 23796da98fee41b50defbb670c77edf61f816017..b76b1f555fa75f95d93f3ce862734ec2f7b5076f 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/dlp_permission_set_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/dlp_permission_set_manager.cpp @@ -27,7 +27,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "DlpPermissionSetManager"}; std::recursive_mutex g_instanceMutex; } @@ -55,7 +54,7 @@ void DlpPermissionSetManager::ProcessDlpPermInfos(const std::vectorpermissionName); if (it != dlpPermissionModeMap_.end()) { - ACCESSTOKEN_LOG_WARN(LABEL, + LOGW(ATM_DOMAIN, ATM_TAG, "info for permission: %{public}s dlpMode %{public}d has been insert, please check!", iter->permissionName.c_str(), iter->dlpMode); continue; @@ -68,7 +67,7 @@ int32_t DlpPermissionSetManager::GetPermDlpMode(const std::string& permissionNam { auto it = dlpPermissionModeMap_.find(permissionName); if (it == dlpPermissionModeMap_.end()) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Can not find permission: %{public}s in dlp permission cfg", + LOGD(ATM_DOMAIN, ATM_TAG, "Can not find permission: %{public}s in dlp permission cfg", permissionName.c_str()); return DLP_PERM_ALL; } @@ -78,7 +77,7 @@ int32_t DlpPermissionSetManager::GetPermDlpMode(const std::string& permissionNam void DlpPermissionSetManager::UpdatePermStateWithDlpInfo(int32_t hapDlpType, std::vector& permStateList) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "DlpType: %{public}d", hapDlpType); + LOGD(ATM_DOMAIN, ATM_TAG, "DlpType: %{public}d", hapDlpType); for (auto iter = permStateList.begin(); iter != permStateList.end(); ++iter) { if (iter->grantStatus[0] == PERMISSION_DENIED) { continue; @@ -100,7 +99,7 @@ bool DlpPermissionSetManager::IsPermissionAvailableToDlpHap(int32_t hapDlpType, bool DlpPermissionSetManager::IsPermDlpModeAvailableToDlpHap(int32_t hapDlpType, int32_t permDlpMode) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "DlpType: %{public}d dlpMode %{public}d", hapDlpType, permDlpMode); + LOGD(ATM_DOMAIN, ATM_TAG, "DlpType: %{public}d dlpMode %{public}d", hapDlpType, permDlpMode); /* permission is available to all dlp hap */ if ((hapDlpType == DLP_COMMON) || (permDlpMode == DLP_PERM_ALL)) { diff --git a/services/accesstokenmanager/main/cpp/src/permission/dlp_permission_set_parser.cpp b/services/accesstokenmanager/main/cpp/src/permission/dlp_permission_set_parser.cpp index 90bb8f0bde724917b9a7b05e63e013b55575698d..c44be13b1a2472dab6b2867d585ba231a18556d0 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/dlp_permission_set_parser.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/dlp_permission_set_parser.cpp @@ -30,7 +30,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "DlpPermissionSetParser"}; std::recursive_mutex g_instanceMutex; } @@ -66,7 +65,7 @@ int32_t DlpPermissionSetParser::ParserDlpPermsRawData(const std::string& dlpPerm { nlohmann::json jsonRes = nlohmann::json::parse(dlpPermsRawData, nullptr, false); if (jsonRes.is_discarded()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "JsonRes is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "JsonRes is invalid."); return ERR_PARAM_INVALID; } @@ -82,24 +81,24 @@ int32_t DlpPermissionSetParser::ReadCfgFile(std::string& dlpPermsRawData) { int32_t fd = open(CLONE_PERMISSION_CONFIG_FILE.c_str(), O_RDONLY); if (fd < 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Open failed errno %{public}d.", errno); + LOGE(ATM_DOMAIN, ATM_TAG, "Open failed errno %{public}d.", errno); return ERR_FILE_OPERATE_FAILED; } struct stat statBuffer; if (fstat(fd, &statBuffer) != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fstat failed errno %{public}d.", errno); + LOGE(ATM_DOMAIN, ATM_TAG, "Fstat failed errno %{public}d.", errno); close(fd); return ERR_FILE_OPERATE_FAILED; } if (statBuffer.st_size == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Config file size is 0."); + LOGE(ATM_DOMAIN, ATM_TAG, "Config file size is 0."); close(fd); return ERR_PARAM_INVALID; } if (statBuffer.st_size > MAX_CLONE_PERMISSION_CONFIG_FILE_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Config file size is too large."); + LOGE(ATM_DOMAIN, ATM_TAG, "Config file size is too large."); close(fd); return ERR_OVERSIZE; } @@ -121,26 +120,26 @@ int32_t DlpPermissionSetParser::ReadCfgFile(std::string& dlpPermsRawData) int32_t DlpPermissionSetParser::Init() { if (ready_) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Dlp permission has been set."); + LOGE(ATM_DOMAIN, ATM_TAG, "Dlp permission has been set."); return RET_SUCCESS; } std::string dlpPermsRawData; int32_t ret = ReadCfgFile(dlpPermsRawData); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadCfgFile failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadCfgFile failed."); return ret; } std::vector dlpPerms; ret = ParserDlpPermsRawData(dlpPermsRawData, dlpPerms); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ParserDlpPermsRawData failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ParserDlpPermsRawData failed."); return ERR_FILE_OPERATE_FAILED; } DlpPermissionSetManager::GetInstance().ProcessDlpPermInfos(dlpPerms); ready_ = true; - ACCESSTOKEN_LOG_INFO(LABEL, "Init ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "Init ok."); return RET_SUCCESS; } diff --git a/services/accesstokenmanager/main/cpp/src/permission/permission_data_brief.cpp b/services/accesstokenmanager/main/cpp/src/permission/permission_data_brief.cpp index 1914fe401391953246cc888bc53a75f3b16098f2..debaf50f766ad12a1577b179ea2c946e1c6cdb50 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/permission_data_brief.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/permission_data_brief.cpp @@ -29,7 +29,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PermissionDataBrief"}; std::recursive_mutex g_briefInstanceMutex; PermissionDataBrief& PermissionDataBrief::GetInstance() @@ -51,11 +50,11 @@ int32_t PermissionDataBrief::AddBriefPermDataByTokenId( Utils::UniqueWriteGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter != requestedPermData_.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID %{public}d is cleared first.", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID %{public}d is cleared first.", tokenID); requestedPermData_.erase(tokenID); } requestedPermData_[tokenID] = listInput; - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID %{public}d is set.", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID %{public}d is set.", tokenID); return RET_SUCCESS; } @@ -64,7 +63,7 @@ int32_t PermissionDataBrief::DeleteBriefPermDataByTokenId(AccessTokenID tokenID) Utils::UniqueWriteGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID %{public}d is not exist.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID %{public}d is not exist.", tokenID); return ERR_TOKEN_INVALID; } requestedPermData_.erase(tokenID); @@ -76,7 +75,7 @@ int32_t PermissionDataBrief::DeleteBriefPermDataByTokenId(AccessTokenID tokenID) secCompData = secCompList_.erase(secCompData); } } - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID %{public}u is deleted.", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID %{public}u is deleted.", tokenID); return RET_SUCCESS; } @@ -85,7 +84,7 @@ int32_t PermissionDataBrief::SetBriefPermData(AccessTokenID tokenID, int32_t opC Utils::UniqueWriteGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID %{public}d is not exist.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID %{public}d is not exist.", tokenID); return ERR_TOKEN_INVALID; } auto it = std::find_if(iter->second.begin(), iter->second.end(), [opCode](BriefPermData data) { @@ -98,7 +97,7 @@ int32_t PermissionDataBrief::SetBriefPermData(AccessTokenID tokenID, int32_t opC } if (flag != PERMISSION_COMPONENT_SET) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission is not requested."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission is not requested."); return ERR_PERMISSION_NOT_EXIST; } // Set secComp permission without existing in state list. @@ -124,7 +123,7 @@ int32_t PermissionDataBrief::GetBriefPermDataByTokenId(AccessTokenID tokenID, st Utils::UniqueReadGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID %{public}d is not exist.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID %{public}d is not exist.", tokenID); return ERR_TOKEN_INVALID; } for (const auto& data : iter->second) { @@ -139,7 +138,7 @@ void PermissionDataBrief::GetGrantedPermByTokenId(AccessTokenID tokenID, Utils::UniqueReadGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID %{public}d is not exist.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID %{public}d is not exist.", tokenID); return; } for (const auto& data : iter->second) { @@ -149,7 +148,7 @@ void PermissionDataBrief::GetGrantedPermByTokenId(AccessTokenID tokenID, if (constrainedList.empty() || (std::find(constrainedList.begin(), constrainedList.end(), permission) == constrainedList.end())) { permissionList.emplace_back(permission); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Permission %{public}s is granted.", permission.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "Permission %{public}s is granted.", permission.c_str()); } } } @@ -159,7 +158,8 @@ void PermissionDataBrief::GetGrantedPermByTokenId(AccessTokenID tokenID, std::string permission; (void)TransferOpcodeToPermission(secCompData->permCode, permission); permissionList.emplace_back(permission); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Permission %{public}s is granted by secComp.", permission.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, + "Permission %{public}s is granted by secComp.", permission.c_str()); } } return; @@ -171,7 +171,7 @@ void PermissionDataBrief::GetPermStatusListByTokenId(AccessTokenID tokenID, Utils::UniqueReadGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID %{public}d is not exist.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID %{public}d is not exist.", tokenID); return; } for (const auto& data : iter->second) { @@ -207,7 +207,7 @@ PermUsedTypeEnum PermissionDataBrief::GetPermissionUsedType(AccessTokenID tokenI Utils::UniqueReadGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is not exist %{public}d.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is not exist %{public}d.", tokenID); return PermUsedTypeEnum::INVALID_USED_TYPE; } auto it = std::find_if(iter->second.begin(), iter->second.end(), [opCode](BriefPermData data) { @@ -218,7 +218,7 @@ PermUsedTypeEnum PermissionDataBrief::GetPermissionUsedType(AccessTokenID tokenI return PermUsedTypeEnum::SEC_COMPONENT_TYPE; } if (it->status == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission of %{public}d is requested, but not granted.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Perm of %{public}d is requested, but not granted.", tokenID); return PermUsedTypeEnum::INVALID_USED_TYPE; } return PermUsedTypeEnum::NORMAL_TYPE; @@ -234,17 +234,17 @@ PermUsedTypeEnum PermissionDataBrief::GetPermissionUsedType(AccessTokenID tokenI int32_t PermissionDataBrief::VerifyPermissionStatus(AccessTokenID tokenID, const std::string& permission) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "tokenID %{public}d, permissionName %{public}s.", tokenID, permission.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "Id %{public}d, permission %{public}s.", tokenID, permission.c_str()); uint32_t opCode; if (!TransferPermissionToOpcode(permission, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is invalid %{public}s.", permission.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName is invalid %{public}s.", permission.c_str()); return PERMISSION_DENIED; } Utils::UniqueReadGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is not exist %{public}d.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id is not exist %{public}d.", tokenID); return PERMISSION_DENIED; } auto it = std::find_if(iter->second.begin(), iter->second.end(), [opCode](BriefPermData data) { @@ -252,7 +252,7 @@ int32_t PermissionDataBrief::VerifyPermissionStatus(AccessTokenID tokenID, const }); if (it != iter->second.end()) { if (ConstantCommon::IsPermGrantedBySecComp(it->flag)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID: %{public}d, permission is granted by secComp", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id: %{public}d, permission is granted by secComp", tokenID); return PERMISSION_GRANTED; } if (it->status) { @@ -264,8 +264,8 @@ int32_t PermissionDataBrief::VerifyPermissionStatus(AccessTokenID tokenID, const std::list::iterator secCompData; for (secCompData = secCompList_.begin(); secCompData != secCompList_.end(); ++secCompData) { if ((secCompData->tokenId == tokenID) && (secCompData->permCode == opCode)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, - "TokenID: %{public}d, permission is not requested. While it is granted by secComp", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, + "Id: %{public}d, permission is not requested. While it is granted by secComp", tokenID); return PERMISSION_GRANTED; } } @@ -276,14 +276,14 @@ bool PermissionDataBrief::IsPermissionGrantedWithSecComp(AccessTokenID tokenID, { uint32_t opCode; if (!TransferPermissionToOpcode(permissionName, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is invalid %{public}s.", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName is invalid %{public}s.", permissionName.c_str()); return false; } Utils::UniqueReadGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is not exist %{public}d.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id is not exist %{public}d.", tokenID); return false; } auto it = std::find_if(iter->second.begin(), iter->second.end(), [opCode](BriefPermData data) { @@ -291,7 +291,7 @@ bool PermissionDataBrief::IsPermissionGrantedWithSecComp(AccessTokenID tokenID, }); if (it != iter->second.end()) { if (ConstantCommon::IsPermGrantedBySecComp(it->flag)) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d, permission is granted by secComp", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}d, permission is granted by secComp", tokenID); return true; } } @@ -309,14 +309,14 @@ int32_t PermissionDataBrief::QueryPermissionFlag(AccessTokenID tokenID, const st { uint32_t opCode; if (!TransferPermissionToOpcode(permissionName, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is invalid %{public}s.", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName is invalid %{public}s.", permissionName.c_str()); return AccessTokenError::ERR_PERMISSION_NOT_EXIST; } Utils::UniqueReadGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid %{public}u.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id is invalid %{public}u.", tokenID); return AccessTokenError::ERR_TOKENID_NOT_EXIST; } auto it = std::find_if(iter->second.begin(), iter->second.end(), [opCode](BriefPermData data) { @@ -326,7 +326,7 @@ int32_t PermissionDataBrief::QueryPermissionFlag(AccessTokenID tokenID, const st flag = it->flag; return RET_SUCCESS; } - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is not in requestedPerm list %{public}s.", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission(%{public}s) is not in requestList .", permissionName.c_str()); return AccessTokenError::ERR_PERMISSION_NOT_EXIST; } @@ -335,14 +335,14 @@ void PermissionDataBrief::SecCompGrantedPermListUpdated( { uint32_t opCode; if (!TransferPermissionToOpcode(permissionName, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName is invalid %{public}s.", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName is invalid %{public}s.", permissionName.c_str()); return; } Utils::UniqueWriteGuard infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenID); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid %{public}u.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id is invalid %{public}u.", tokenID); return; } @@ -369,7 +369,7 @@ void PermissionDataBrief::SecCompGrantedPermListUpdated( uint32_t newFlag = isAdded ? (oldFlag | PERMISSION_COMPONENT_SET) : (oldFlag & (~PERMISSION_COMPONENT_SET)); it->flag = newFlag; - ACCESSTOKEN_LOG_INFO(LABEL, "Update flag newFlag %{public}u, oldFlag %{public}u .", newFlag, oldFlag); + LOGI(ATM_DOMAIN, ATM_TAG, "Update newFlag %{public}u, oldFlag %{public}u .", newFlag, oldFlag); } return; } @@ -389,7 +389,7 @@ void PermissionDataBrief::ClearAllSecCompGrantedPermById(AccessTokenID tokenID) std::list::iterator secCompData; for (secCompData = secCompList_.begin(); secCompData != secCompList_.end();) { if (secCompData->tokenId == tokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID is cleared %{public}u.", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id is cleared %{public}u.", tokenID); secCompData = secCompList_.erase(secCompData); } else { ++secCompData; @@ -406,18 +406,18 @@ int32_t PermissionDataBrief::RefreshPermStateToKernel(const std::vector infoGuard(this->permissionStateDataLock_); auto iter = requestedPermData_.find(tokenId); if (iter == requestedPermData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is not exist in requestedPermData_ %{public}u.", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is not exist in requestedPermData_ %{public}u.", tokenId); return AccessTokenError::ERR_PARAM_INVALID; } @@ -429,19 +429,19 @@ int32_t PermissionDataBrief::RefreshPermStateToKernel(const std::vector cacheGuard(this->cacheLock_); auto it = permissionDefinitionMap_.find(info.permissionName); if (it != permissionDefinitionMap_.end()) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Info for permission: %{public}s has been insert, please check!", + LOGD(ATM_DOMAIN, ATM_TAG, "Info for permission: %{public}s has been insert, please check!", info.permissionName.c_str()); return false; } @@ -94,7 +91,7 @@ int PermissionDefinitionCache::FindByPermissionName(const std::string& permissio Utils::UniqueReadGuard cacheGuard(this->cacheLock_); auto it = permissionDefinitionMap_.find(permissionName); if (it == permissionDefinitionMap_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Can not find definition info for permission: %{public}s", + LOGE(ATM_DOMAIN, ATM_TAG, "Can not find definition info for permission: %{public}s", permissionName.c_str()); return AccessTokenError::ERR_PERMISSION_NOT_EXIST; } @@ -197,7 +194,7 @@ int32_t PermissionDefinitionCache::RestorePermDefInfo(std::vector AccessTokenID tokenId = (AccessTokenID)defValue.GetInt(TokenFiledConst::FIELD_TOKEN_ID); int32_t ret = DataTranslator::TranslationIntoPermissionDef(defValue, def); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId 0x%{public}x permDef is wrong.", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenId 0x%{public}x permDef is wrong.", tokenId); return ret; } Insert(def, tokenId); diff --git a/services/accesstokenmanager/main/cpp/src/permission/permission_definition_parser.cpp b/services/accesstokenmanager/main/cpp/src/permission/permission_definition_parser.cpp index 814af2e21232f8432b2adc7bf7ae1314907a8326..402533410f81e6474a9ac0079c47718c5ae71f7c 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/permission_definition_parser.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/permission_definition_parser.cpp @@ -37,30 +37,27 @@ namespace AccessToken { namespace { std::recursive_mutex g_instanceMutex; static const int32_t EXTENSION_PERMISSION_ID = 0; -static const std::string PERMISSION_NAME = "name"; -static const std::string PERMISSION_GRANT_MODE = "grantMode"; -static const std::string PERMISSION_AVAILABLE_LEVEL = "availableLevel"; -static const std::string PERMISSION_AVAILABLE_TYPE = "availableType"; -static const std::string PERMISSION_PROVISION_ENABLE = "provisionEnable"; -static const std::string PERMISSION_DISTRIBUTED_SCENE_ENABLE = "distributedSceneEnable"; -static const std::string PERMISSION_LABEL = "label"; -static const std::string PERMISSION_DESCRIPTION = "description"; -static const std::string AVAILABLE_TYPE_NORMAL_HAP = "NORMAL"; -static const std::string AVAILABLE_TYPE_SYSTEM_HAP = "SYSTEM"; -static const std::string AVAILABLE_TYPE_MDM = "MDM"; -static const std::string AVAILABLE_TYPE_SYSTEM_AND_MDM = "SYSTEM_AND_MDM"; -static const std::string AVAILABLE_TYPE_SERVICE = "SERVICE"; -static const std::string AVAILABLE_TYPE_ENTERPRISE_NORMAL = "ENTERPRISE_NORMAL"; -static const std::string AVAILABLE_LEVEL_NORMAL = "normal"; -static const std::string AVAILABLE_LEVEL_SYSTEM_BASIC = "system_basic"; -static const std::string AVAILABLE_LEVEL_SYSTEM_CORE = "system_core"; -static const std::string PERMISSION_GRANT_MODE_SYSTEM_GRANT = "system_grant"; -static const std::string PERMISSION_GRANT_MODE_USER_GRANT = "user_grant"; -static const std::string SYSTEM_GRANT_DEFINE_PERMISSION = "systemGrantPermissions"; -static const std::string USER_GRANT_DEFINE_PERMISSION = "userGrantPermissions"; -static const std::string DEFINE_PERMISSION_FILE = "/system/etc/access_token/permission_definitions.json"; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "PermissionDefinitionParser"}; +constexpr const char* PERMISSION_NAME = "name"; +constexpr const char* PERMISSION_GRANT_MODE = "grantMode"; +constexpr const char* PERMISSION_AVAILABLE_LEVEL = "availableLevel"; +constexpr const char* PERMISSION_AVAILABLE_TYPE = "availableType"; +constexpr const char* PERMISSION_PROVISION_ENABLE = "provisionEnable"; +constexpr const char* PERMISSION_DISTRIBUTED_SCENE_ENABLE = "distributedSceneEnable"; +constexpr const char* PERMISSION_LABEL = "label"; +constexpr const char* PERMISSION_DESCRIPTION = "description"; +constexpr const char* AVAILABLE_TYPE_NORMAL_HAP = "NORMAL"; +constexpr const char* AVAILABLE_TYPE_SYSTEM_HAP = "SYSTEM"; +constexpr const char* AVAILABLE_TYPE_MDM = "MDM"; +constexpr const char* AVAILABLE_TYPE_SYSTEM_AND_MDM = "SYSTEM_AND_MDM"; +constexpr const char* AVAILABLE_TYPE_SERVICE = "SERVICE"; +constexpr const char* AVAILABLE_TYPE_ENTERPRISE_NORMAL = "ENTERPRISE_NORMAL"; +constexpr const char* AVAILABLE_LEVEL_NORMAL = "normal"; +constexpr const char* AVAILABLE_LEVEL_SYSTEM_BASIC = "system_basic"; +constexpr const char* AVAILABLE_LEVEL_SYSTEM_CORE = "system_core"; +constexpr const char* PERMISSION_GRANT_MODE_SYSTEM_GRANT = "system_grant"; +constexpr const char* SYSTEM_GRANT_DEFINE_PERMISSION = "systemGrantPermissions"; +constexpr const char* USER_GRANT_DEFINE_PERMISSION = "userGrantPermissions"; +constexpr const char* DEFINE_PERMISSION_FILE = "/system/etc/access_token/permission_definitions.json"; } static bool GetPermissionApl(const std::string &apl, AccessToken::ATokenAplEnum& aplNum) @@ -77,7 +74,7 @@ static bool GetPermissionApl(const std::string &apl, AccessToken::ATokenAplEnum& aplNum = AccessToken::ATokenAplEnum::APL_NORMAL; return true; } - ACCESSTOKEN_LOG_ERROR(LABEL, "Apl: %{public}s is invalid.", apl.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Apl: %{public}s is invalid.", apl.c_str()); return false; } @@ -108,7 +105,7 @@ static bool GetPermissionAvailableType(const std::string &availableType, AccessT return true; } typeNum = AccessToken::ATokenAvailableTypeEnum::INVALID; - ACCESSTOKEN_LOG_ERROR(LABEL, "AvailableType: %{public}s is invalid.", availableType.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "AvailableType: %{public}s is invalid.", availableType.c_str()); return false; } @@ -177,7 +174,7 @@ static bool CheckPermissionDefRules(const PermissionDef& permDef) { // Extension permission support permission for service only. if (permDef.availableType != AccessToken::ATokenAvailableTypeEnum::SERVICE) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s is for hap.", permDef.permissionName.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "%{public}s is for hap.", permDef.permissionName.c_str()); return false; } return true; @@ -187,7 +184,7 @@ int32_t PermissionDefinitionParser::GetPermissionDefList(const nlohmann::json& j const std::string& type, std::vector& permDefList) { if ((json.find(type) == json.end()) || (!json.at(type).is_array())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Json is not array."); + LOGE(ATM_DOMAIN, ATM_TAG, "Json is not array."); return ERR_PARAM_INVALID; } @@ -195,13 +192,13 @@ int32_t PermissionDefinitionParser::GetPermissionDefList(const nlohmann::json& j for (auto it = JsonData.begin(); it != JsonData.end(); it++) { auto result = it->get(); if (!result.isSuccessful) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get permission def failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Get permission def failed."); return ERR_PERM_REQUEST_CFG_FAILED; } if (!CheckPermissionDefRules(result.permDef)) { continue; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s insert.", result.permDef.permissionName.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "%{public}s insert.", result.permDef.permissionName.c_str()); permDefList.emplace_back(result.permDef); } return RET_SUCCESS; @@ -212,37 +209,37 @@ int32_t PermissionDefinitionParser::ParserPermsRawData(const std::string& permsR { nlohmann::json jsonRes = nlohmann::json::parse(permsRawData, nullptr, false); if (jsonRes.is_discarded()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "JsonRes is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "JsonRes is invalid."); return ERR_PARAM_INVALID; } int32_t ret = GetPermissionDefList(jsonRes, permsRawData, SYSTEM_GRANT_DEFINE_PERMISSION, permDefList); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get system_grant permission def list failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Get system_grant permission def list failed."); return ret; } - ACCESSTOKEN_LOG_INFO(LABEL, "Get system_grant permission size=%{public}zu.", permDefList.size()); + LOGI(ATM_DOMAIN, ATM_TAG, "Get system_grant permission size=%{public}zu.", permDefList.size()); ret = GetPermissionDefList(jsonRes, permsRawData, USER_GRANT_DEFINE_PERMISSION, permDefList); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get user_grant permission def list failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Get user_grant permission def list failed."); return ret; } - ACCESSTOKEN_LOG_INFO(LABEL, "Get permission size=%{public}zu.", permDefList.size()); + LOGI(ATM_DOMAIN, ATM_TAG, "Get permission size=%{public}zu.", permDefList.size()); return RET_SUCCESS; } int32_t PermissionDefinitionParser::Init() { - ACCESSTOKEN_LOG_INFO(LABEL, "System permission set begin."); + LOGI(ATM_DOMAIN, ATM_TAG, "System permission set begin."); if (ready_) { - ACCESSTOKEN_LOG_ERROR(LABEL, " system permission has been set."); + LOGE(ATM_DOMAIN, ATM_TAG, " system permission has been set."); return RET_SUCCESS; } std::string permsRawData; int32_t ret = JsonParser::ReadCfgFile(DEFINE_PERMISSION_FILE, permsRawData); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadCfgFile failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadCfgFile failed."); ReportSysEventServiceStartError(INIT_PERM_DEF_JSON_ERROR, "ReadCfgFile fail.", ret); return ERR_FILE_OPERATE_FAILED; } @@ -250,7 +247,7 @@ int32_t PermissionDefinitionParser::Init() ret = ParserPermsRawData(permsRawData, permDefList); if (ret != RET_SUCCESS) { ReportSysEventServiceStartError(INIT_PERM_DEF_JSON_ERROR, "ParserPermsRawData fail.", ret); - ACCESSTOKEN_LOG_ERROR(LABEL, "ParserPermsRawData failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ParserPermsRawData failed."); return ret; } @@ -258,7 +255,7 @@ int32_t PermissionDefinitionParser::Init() PermissionDefinitionCache::GetInstance().Insert(perm, EXTENSION_PERMISSION_ID); } ready_ = true; - ACCESSTOKEN_LOG_INFO(LABEL, "Init ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "Init ok."); return RET_SUCCESS; } diff --git a/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp b/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp index a8000ec41601e62a917d515f3157c05bfd5de86c..b2b062c43c5c1c20caf907156ccfcecdcefcc473 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp @@ -48,7 +48,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PermissionManager"}; static const char* PERMISSION_STATUS_CHANGE_KEY = "accesstoken.permission.change"; static constexpr int32_t VALUE_MAX_LEN = 32; static constexpr int32_t BASE_USER_RANGE = 200000; @@ -91,7 +90,7 @@ PermissionManager::PermissionManager() char value[VALUE_MAX_LEN] = {0}; int32_t ret = GetParameter(PERMISSION_STATUS_CHANGE_KEY, "", value, VALUE_MAX_LEN - 1); if (ret < 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Return default value, ret=%{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Return default value, ret=%{public}d", ret); paramValue_ = 0; return; } @@ -106,7 +105,7 @@ void PermissionManager::AddDefPermissions(const std::vector& perm { std::vector permFilterList; PermissionValidator::FilterInvalidPermissionDef(permList, permFilterList); - ACCESSTOKEN_LOG_INFO(LABEL, "PermFilterList size: %{public}zu", permFilterList.size()); + LOGI(ATM_DOMAIN, ATM_TAG, "PermFilterList size: %{public}zu", permFilterList.size()); for (const auto& perm : permFilterList) { if (updateFlag) { PermissionDefinitionCache::GetInstance().Update(perm, tokenId); @@ -117,14 +116,14 @@ void PermissionManager::AddDefPermissions(const std::vector& perm PermissionDefinitionCache::GetInstance().Insert(perm, tokenId); } else { PermissionDefinitionCache::GetInstance().Update(perm, tokenId); - ACCESSTOKEN_LOG_INFO(LABEL, "Permission %{public}s has define", perm.permissionName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Permission %{public}s has define", perm.permissionName.c_str()); } } } void PermissionManager::RemoveDefPermissions(AccessTokenID tokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "tokenID: %{public}u", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "tokenID: %{public}u", tokenID); PermissionDefinitionCache::GetInstance().DeleteByToken(tokenID); } @@ -138,11 +137,11 @@ PermUsedTypeEnum PermissionManager::GetPermissionUsedType( { if ((tokenID == INVALID_TOKENID) || (TOKEN_HAP != AccessTokenIDManager::GetInstance().GetTokenIdTypeEnum(tokenID))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID: %{public}d is invalid.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id: %{public}d is invalid.", tokenID); return PermUsedTypeEnum::INVALID_USED_TYPE; } PermUsedTypeEnum ret = HapTokenInfoInner::GetPermissionUsedType(tokenID, permissionName); - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "Application %{public}u apply for %{public}s for type %{public}d.", tokenID, permissionName.c_str(), ret); return ret; } @@ -150,7 +149,7 @@ PermUsedTypeEnum PermissionManager::GetPermissionUsedType( int PermissionManager::GetDefPermission(const std::string& permissionName, PermissionDef& permissionDefResult) { if (!PermissionValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid params!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid params!"); return AccessTokenError::ERR_PARAM_INVALID; } return PermissionDefinitionCache::GetInstance().FindByPermissionName(permissionName, permissionDefResult); @@ -164,18 +163,18 @@ void PermissionManager::GetDefPermissions(AccessTokenID tokenID, std::vector& reqPermList, bool isSystemGrant) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, tokenID: %{public}u, isSystemGrant: %{public}d", + LOGD(ATM_DOMAIN, ATM_TAG, "%{public}s called, Id: %{public}u, isSystemGrant: %{public}d", __func__, tokenID, isSystemGrant); std::shared_ptr infoPtr = AccessTokenInfoManager::GetInstance().GetHapTokenInfoInner(tokenID); if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u is invalid.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u is invalid.", tokenID); return AccessTokenError::ERR_TOKENID_NOT_EXIST; } GrantMode mode = isSystemGrant ? SYSTEM_GRANT : USER_GRANT; std::vector tmpList; int32_t ret = infoPtr->GetPermissionStateList(tmpList); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetPermissionStateList failed, token %{public}u is invalid.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "GetPermissionStateList failed, Id %{public}u is invalid.", tokenID); return ret; } for (const auto& perm : tmpList) { @@ -193,7 +192,7 @@ static bool IsPermissionRequestedInHap(const std::vector& p { const std::string permission = permState.permissionName; if (!PermissionDefinitionCache::GetInstance().HasHapPermissionDefinitionForHap(permission)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "No definition for hap permission: %{public}s!", permission.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "No definition for hap permission: %{public}s!", permission.c_str()); permState.errorReason = PERM_INVALID; return false; } @@ -201,11 +200,11 @@ static bool IsPermissionRequestedInHap(const std::vector& p return permission == perm.permissionName; }); if (iter == permsList.end()) { - ACCESSTOKEN_LOG_WARN(LABEL, "Can not find permission: %{public}s define!", permission.c_str()); + LOGW(ATM_DOMAIN, ATM_TAG, "Can not find permission: %{public}s define!", permission.c_str()); permState.errorReason = PERM_NOT_DECLEARED; return false; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Find goal permission: %{public}s, status: %{public}d, flag: %{public}d", + LOGD(ATM_DOMAIN, ATM_TAG, "Find goal permission: %{public}s, status: %{public}d, flag: %{public}d", permission.c_str(), iter->grantStatus[0], iter->grantFlags[0]); status = iter->grantStatus[0]; flag = static_cast(iter->grantFlags[0]); @@ -218,7 +217,8 @@ static bool IsPermissionRestrictedByRules(const std::string& permission) // Specified apps can get the permission by pre-authorization instead of Pop-ups. auto iterator = std::find(g_notDisplayedPerms.begin(), g_notDisplayedPerms.end(), permission); if (iterator != g_notDisplayedPerms.end()) { - ACCESSTOKEN_LOG_WARN(LABEL, "Permission is not available to common apps: %{public}s!", permission.c_str()); + LOGW(ATM_DOMAIN, ATM_TAG, + "Permission is not available to common apps: %{public}s!", permission.c_str()); return true; } @@ -228,7 +228,7 @@ static bool IsPermissionRestrictedByRules(const std::string& permission) int32_t dlpType = AccessTokenInfoManager::GetInstance().GetHapTokenDlpType(callingTokenId); if ((dlpType != DLP_COMMON) && !DlpPermissionSetManager::GetInstance().IsPermissionAvailableToDlpHap(dlpType, permission)) { - ACCESSTOKEN_LOG_WARN(LABEL, + LOGW(ATM_DOMAIN, ATM_TAG, "callingTokenId is not allowed to grant dlp permission: %{public}s!", permission.c_str()); return true; } @@ -258,7 +258,7 @@ void PermissionManager::GetSelfPermissionState(const std::vector(paramValue_)); int32_t res = SetParameter(PERMISSION_STATUS_CHANGE_KEY, std::to_string(paramValue_).c_str()); if (res != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SetParameter failed %{public}d", res); + LOGE(ATM_DOMAIN, ATM_TAG, "SetParameter failed %{public}d", res); } } } @@ -427,7 +424,7 @@ void PermissionManager::ParamUpdate(const std::string& permissionName, uint32_t void PermissionManager::NotifyWhenPermissionStateUpdated(AccessTokenID tokenID, const std::string& permissionName, bool isGranted, uint32_t flag, const std::shared_ptr& infoPtr) { - ACCESSTOKEN_LOG_INFO(LABEL, "IsUpdated"); + LOGI(ATM_DOMAIN, ATM_TAG, "IsUpdated"); int32_t changeType = isGranted ? STATE_CHANGE_GRANTED : STATE_CHANGE_REVOKED; // set to kernel(grant/revoke) @@ -452,16 +449,17 @@ int32_t PermissionManager::UpdateTokenPermissionState( { std::shared_ptr infoPtr = AccessTokenInfoManager::GetInstance().GetHapTokenInfoInner(id); if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "tokenInfo is null, tokenId=%{public}u", id); + LOGE(ATM_DOMAIN, ATM_TAG, "tokenInfo is null, tokenId=%{public}u", id); return AccessTokenError::ERR_TOKENID_NOT_EXIST; } if (infoPtr->IsRemote()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote token can not update"); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote token can not update"); return AccessTokenError::ERR_IDENTITY_CHECK_FAILED; } if ((flag == PERMISSION_ALLOW_THIS_TIME) && isGranted) { if (!TempPermissionObserver::GetInstance().IsAllowGrantTempPermission(id, permission)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Id:%{public}d fail to grant permission:%{public}s", id, permission.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, + "Id:%{public}d fail to grant permission:%{public}s", id, permission.c_str()); return ERR_IDENTITY_CHECK_FAILED; } } @@ -471,7 +469,8 @@ int32_t PermissionManager::UpdateTokenPermissionState( if (hapDlpType != DLP_COMMON) { int32_t permDlpMode = DlpPermissionSetManager::GetInstance().GetPermDlpMode(permission); if (!DlpPermissionSetManager::GetInstance().IsPermDlpModeAvailableToDlpHap(hapDlpType, permDlpMode)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s cannot to be granted to %{public}u", permission.c_str(), id); + LOGD(ATM_DOMAIN, ATM_TAG, + "%{public}s cannot to be granted to %{public}u", permission.c_str(), id); return AccessTokenError::ERR_IDENTITY_CHECK_FAILED; } } @@ -487,9 +486,10 @@ int32_t PermissionManager::UpdateTokenPermissionState( NotifyWhenPermissionStateUpdated(id, permission, isGranted, flag, infoPtr); // To notify kill process when perm is revoke if (needKill && (!isGranted && !isSecCompGrantedBefore)) { - ACCESSTOKEN_LOG_INFO(LABEL, "(%{public}s) is revoked, kill process(%{public}u).", permission.c_str(), id); + LOGI(ATM_DOMAIN, ATM_TAG, + "(%{public}s) is revoked, kill process(%{public}u).", permission.c_str(), id); if ((ret = AppManagerAccessClient::GetInstance().KillProcessesByAccessTokenId(id)) != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "kill process failed, ret=%{public}d.", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "kill process failed, ret=%{public}d.", ret); } } } @@ -528,22 +528,21 @@ int32_t PermissionManager::CheckAndUpdatePermission(AccessTokenID tokenID, const bool isGranted, uint32_t flag) { if (!PermissionValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "permissionName: %{public}s, Invalid params!", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid permission: %{public}s!", permissionName.c_str()); return AccessTokenError::ERR_PARAM_INVALID; } if (!PermissionDefinitionCache::GetInstance().HasDefinition(permissionName)) { - ACCESSTOKEN_LOG_ERROR( - LABEL, "No definition for permission: %{public}s!", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "No definition for permission: %{public}s!", permissionName.c_str()); return AccessTokenError::ERR_PERMISSION_NOT_EXIST; } if (!PermissionValidator::IsPermissionFlagValid(flag)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "flag: %{public}d, Invalid params!", flag); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid flag: %{public}d!", flag); return AccessTokenError::ERR_PARAM_INVALID; } bool needKill = false; // To kill process when perm is revoke if (!isGranted && (flag != PERMISSION_ALLOW_THIS_TIME) && (flag != PERMISSION_COMPONENT_SET)) { - ACCESSTOKEN_LOG_INFO(LABEL, "Perm(%{public}s) is revoked, kill process(%{public}u).", + LOGI(ATM_DOMAIN, ATM_TAG, "Perm(%{public}s) is revoked, kill process(%{public}u).", permissionName.c_str(), tokenID); needKill = true; } @@ -553,26 +552,23 @@ int32_t PermissionManager::CheckAndUpdatePermission(AccessTokenID tokenID, const int32_t PermissionManager::GrantPermission(AccessTokenID tokenID, const std::string& permissionName, uint32_t flag) { - ACCESSTOKEN_LOG_INFO(LABEL, - "%{public}s called, tokenID: %{public}u, permissionName: %{public}s, flag: %{public}d", - __func__, tokenID, permissionName.c_str(), flag); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}u, permissionName: %{public}s, flag: %{public}d", + tokenID, permissionName.c_str(), flag); return CheckAndUpdatePermission(tokenID, permissionName, true, flag); } int32_t PermissionManager::RevokePermission(AccessTokenID tokenID, const std::string& permissionName, uint32_t flag) { - ACCESSTOKEN_LOG_INFO(LABEL, - "%{public}s called, tokenID: %{public}u, permissionName: %{public}s, flag: %{public}d", - __func__, tokenID, permissionName.c_str(), flag); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}u, permissionName: %{public}s, flag: %{public}d", + tokenID, permissionName.c_str(), flag); return CheckAndUpdatePermission(tokenID, permissionName, false, flag); } int32_t PermissionManager::GrantPermissionForSpecifiedTime( AccessTokenID tokenID, const std::string& permissionName, uint32_t onceTime) { - ACCESSTOKEN_LOG_INFO(LABEL, - "%{public}s called, tokenID: %{public}u, permissionName: %{public}s, onceTime: %{public}d", - __func__, tokenID, permissionName.c_str(), onceTime); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}u, permissionName: %{public}s, onceTime: %{public}d", + tokenID, permissionName.c_str(), onceTime); return ShortGrantManager::GetInstance().RefreshPermission(tokenID, permissionName, onceTime); } @@ -586,7 +582,7 @@ void PermissionManager::ScopeToString( std::string permStr; permStr = accumulate(permList.begin(), permList.end(), std::string(" ")); - ACCESSTOKEN_LOG_INFO(LABEL, "TokenidStr = %{public}s permStr =%{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "TokenidStr = %{public}s permStr =%{public}s", tokenidStr.c_str(), permStr.c_str()); } @@ -600,7 +596,7 @@ int32_t PermissionManager::ScopeFilter(const PermStateChangeScope& scopeSrc, Per tokenIdSet.insert(tokenId); continue; } - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId %{public}d invalid!", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenId %{public}d invalid!", tokenId); } std::set permSet; for (const auto& permissionName : scopeSrc.permList) { @@ -610,14 +606,14 @@ int32_t PermissionManager::ScopeFilter(const PermStateChangeScope& scopeSrc, Per permSet.insert(permissionName); continue; } - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission %{public}s invalid!", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission %{public}s invalid!", permissionName.c_str()); } if ((scopeRes.tokenIDs.empty()) && (!scopeSrc.tokenIDs.empty())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Valid tokenid size is 0!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Valid tokenid size is 0!"); return AccessTokenError::ERR_PARAM_INVALID; } if ((scopeRes.permList.empty()) && (!scopeSrc.permList.empty())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Valid permission size is 0!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Valid permission size is 0!"); return AccessTokenError::ERR_PARAM_INVALID; } ScopeToString(scopeRes.tokenIDs, scopeRes.permList); @@ -627,7 +623,7 @@ int32_t PermissionManager::ScopeFilter(const PermStateChangeScope& scopeSrc, Per int32_t PermissionManager::AddPermStateChangeCallback( const PermStateChangeScope& scope, const sptr& callback) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called"); PermStateChangeScope scopeRes; int32_t result = ScopeFilter(scope, scopeRes); if (result != RET_SUCCESS) { @@ -638,7 +634,7 @@ int32_t PermissionManager::AddPermStateChangeCallback( int32_t PermissionManager::RemovePermStateChangeCallback(const sptr& callback) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called"); return CallbackManager::GetInstance().RemoveCallback(callback); } @@ -648,14 +644,14 @@ bool PermissionManager::GetApiVersionByTokenId(AccessTokenID tokenID, int32_t& a AccessTokenIDInner *idInner = reinterpret_cast(&tokenID); ATokenTypeEnum tokenType = (ATokenTypeEnum)(idInner->type); if (tokenType != TOKEN_HAP) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid token type %{public}d", tokenType); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid token type %{public}d", tokenType); return false; } HapTokenInfo hapInfo; int ret = AccessTokenInfoManager::GetInstance().GetHapTokenInfo(tokenID, hapInfo); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get hap token info error!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get hap token info error!"); return false; } @@ -667,12 +663,12 @@ bool PermissionManager::GetApiVersionByTokenId(AccessTokenID tokenID, int32_t& a bool PermissionManager::IsPermissionVaild(const std::string& permissionName) { if (!PermissionValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_WARN(LABEL, "Invalid permissionName %{public}s", permissionName.c_str()); + LOGW(ATM_DOMAIN, ATM_TAG, "Invalid permission %{public}s", permissionName.c_str()); return false; } if (!PermissionDefinitionCache::GetInstance().HasDefinition(permissionName)) { - ACCESSTOKEN_LOG_WARN(LABEL, "Permission %{public}s has no definition ", permissionName.c_str()); + LOGW(ATM_DOMAIN, ATM_TAG, "Permission %{public}s has no definition ", permissionName.c_str()); return false; } return true; @@ -705,7 +701,7 @@ bool PermissionManager::GetLocationPermissionIndex(std::vector& gr const std::vector& grantedPermListAfter, AccessTokenID tokenID) { for (uint32_t i = 0; i < grantedPermListBefore.size(); i++) { - ACCESSTOKEN_LOG_INFO(LABEL, "grantedPermListBefore[i] %{public}s.", grantedPermListBefore[i].c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, + "grantedPermListBefore[i] %{public}s.", grantedPermListBefore[i].c_str()); auto it = find(grantedPermListAfter.begin(), grantedPermListAfter.end(), grantedPermListBefore[i]); if (it == grantedPermListAfter.end()) { CallbackManager::GetInstance().ExecuteCallbackAsync( @@ -797,7 +794,8 @@ void PermissionManager::NotifyUpdatedPermList(const std::vector& gr } } for (uint32_t i = 0; i < grantedPermListAfter.size(); i++) { - ACCESSTOKEN_LOG_INFO(LABEL, "grantedPermListAfter[i] %{public}s.", grantedPermListAfter[i].c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, + "grantedPermListAfter[i] %{public}s.", grantedPermListAfter[i].c_str()); auto it = find(grantedPermListBefore.begin(), grantedPermListBefore.end(), grantedPermListAfter[i]); if (it == grantedPermListBefore.end()) { CallbackManager::GetInstance().ExecuteCallbackAsync( @@ -843,8 +841,8 @@ void PermissionManager::AddPermToKernel(AccessTokenID tokenID, const std::shared policy->GetPermissionStateList(opCodeList, statusList); int32_t ret = AddPermissionToKernel(tokenID, opCodeList, statusList); if (ret != ACCESS_TOKEN_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AddPermissionToKernel(token=%{public}d), size=%{public}zu, err=%{public}d", - tokenID, opCodeList.size(), ret); + LOGE(ATM_DOMAIN, ATM_TAG, + "AddPermToKernel(id=%{public}u), size=%{public}zu, err=%{public}d", tokenID, opCodeList.size(), ret); } } @@ -856,8 +854,8 @@ void PermissionManager::AddPermToKernel(AccessTokenID tokenID) HapTokenInfoInner::GetPermStatusListByTokenId(tokenID, EmptyList, opCodeList, statusList); int32_t ret = AddPermissionToKernel(tokenID, opCodeList, statusList); if (ret != ACCESS_TOKEN_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AddPermissionToKernel(token=%{public}d), size=%{public}zu, err=%{public}d", - tokenID, opCodeList.size(), ret); + LOGE(ATM_DOMAIN, ATM_TAG, + "AddPermToKernel(id=%{public}u), size=%{public}zu, err=%{public}d", tokenID, opCodeList.size(), ret); } } @@ -877,16 +875,15 @@ void PermissionManager::AddPermToKernel(AccessTokenID tokenID, const std::vector HapTokenInfoInner::GetPermStatusListByTokenId(tokenID, permCodeList, opCodeList, statusList); int32_t ret = AddPermissionToKernel(tokenID, opCodeList, statusList); if (ret != ACCESS_TOKEN_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AddPermissionToKernel(token=%{public}d), size=%{public}zu, err=%{public}d", - tokenID, opCodeList.size(), ret); + LOGE(ATM_DOMAIN, ATM_TAG, + "AddPermToKernel(id=%{public}d), size=%{public}zu, err=%{public}d", tokenID, opCodeList.size(), ret); } } void PermissionManager::RemovePermFromKernel(AccessTokenID tokenID) { int32_t ret = RemovePermissionFromKernel(tokenID); - ACCESSTOKEN_LOG_INFO(LABEL, - "RemovePermissionFromKernel(token=%{public}d), err=%{public}d", tokenID, ret); + LOGI(ATM_DOMAIN, ATM_TAG, "RemovePermFromKernel(id=%{public}d), err=%{public}d", tokenID, ret); } void PermissionManager::SetPermToKernel( @@ -897,8 +894,7 @@ void PermissionManager::SetPermToKernel( return; } int32_t ret = SetPermissionToKernel(tokenID, code, isGranted); - ACCESSTOKEN_LOG_INFO(LABEL, - "SetPermissionToKernel(token=%{public}d, permission=(%{public}s), err=%{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "SetPermToKernel(id=%{public}d, permission=(%{public}s), err=%{public}d", tokenID, permissionName.c_str(), ret); } @@ -906,7 +902,8 @@ bool IsAclSatisfied(const PermissionDef& permDef, const HapPolicyParams& policy) { if (policy.apl < permDef.availableLevel) { if (!permDef.provisionEnable) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s provisionEnable is false.", permDef.permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, + "%{public}s provisionEnable is false.", permDef.permissionName.c_str()); return false; } auto isAclExist = std::any_of( @@ -914,7 +911,7 @@ bool IsAclSatisfied(const PermissionDef& permDef, const HapPolicyParams& policy) return permDef.permissionName == perm; }); if (!isAclExist) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s need acl.", permDef.permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "%{public}s need acl.", permDef.permissionName.c_str()); return false; } } @@ -925,12 +922,12 @@ bool IsPermAvailableRangeSatisfied(const PermissionDef& permDef, const std::stri { if (permDef.availableType == ATokenAvailableTypeEnum::MDM) { if (appDistributionType == "none") { - ACCESSTOKEN_LOG_INFO(LABEL, "Debug app use permission: %{public}s.", + LOGI(ATM_DOMAIN, ATM_TAG, "Debug app use permission: %{public}s.", permDef.permissionName.c_str()); return true; } if (appDistributionType != APP_DISTRIBUTION_TYPE_ENTERPRISE_MDM) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s is a mdm permission, the hap is not a mdm application.", + LOGE(ATM_DOMAIN, ATM_TAG, "%{public}s is mdm permission, the hap is not a mdm application.", permDef.permissionName.c_str()); return false; } @@ -945,7 +942,7 @@ bool IsUserGrantPermPreAuthorized(const std::vector &list, return info.permissionName == permissionName; }); if (iter == list.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "Permission(%{public}s) is not in the list", permissionName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Permission(%{public}s) is not in the list", permissionName.c_str()); return false; } @@ -961,7 +958,7 @@ bool PermissionManager::InitDlpPermissionList(const std::string& bundleName, int std::shared_ptr infoPtr = AccessTokenInfoManager::GetInstance().GetHapTokenInfoInner(tokenId.tokenIdExStruct.tokenID); if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u is invalid.", tokenId.tokenIdExStruct.tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u is invalid.", tokenId.tokenIdExStruct.tokenID); return false; } (void)infoPtr->GetPermissionStateList(initializedList); @@ -971,8 +968,8 @@ bool PermissionManager::InitDlpPermissionList(const std::string& bundleName, int bool PermissionManager::InitPermissionList(const std::string& appDistributionType, const HapPolicyParams& policy, std::vector& initializedList, HapInfoCheckResult& result) { - ACCESSTOKEN_LOG_INFO(LABEL, "Before, request perm list size: %{public}zu, preAuthorizationInfo size %{public}zu, " - "ACLRequestedList size %{public}zu.", + LOGI(ATM_DOMAIN, ATM_TAG, "Before, request permListSize: %{public}zu, " + "preAuthorizationSize %{public}zu, ACLRequestedList size %{public}zu.", policy.permStateList.size(), policy.preAuthorizationInfo.size(), policy.aclRequestedList.size()); for (auto state : policy.permStateList) { @@ -980,14 +977,14 @@ bool PermissionManager::InitPermissionList(const std::string& appDistributionTyp int32_t ret = PermissionManager::GetInstance().GetDefPermission( state.permissionName, permDef); if (ret != AccessToken::AccessTokenKitRet::RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get definition of %{public}s failed, ret = %{public}d.", + LOGE(ATM_DOMAIN, ATM_TAG, "Get definition of %{public}s failed, ret = %{public}d.", state.permissionName.c_str(), ret); continue; } if (!IsAclSatisfied(permDef, policy)) { result.permCheckResult.permissionName = state.permissionName; result.permCheckResult.rule = PERMISSION_ACL_RULE; - ACCESSTOKEN_LOG_ERROR(LABEL, "Acl of %{public}s is invalid.", permDef.permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Acl of %{public}s is invalid.", permDef.permissionName.c_str()); return false; } @@ -995,7 +992,7 @@ bool PermissionManager::InitPermissionList(const std::string& appDistributionTyp if (!IsPermAvailableRangeSatisfied(permDef, appDistributionType)) { result.permCheckResult.permissionName = state.permissionName; result.permCheckResult.rule = PERMISSION_EDM_RULE; - ACCESSTOKEN_LOG_ERROR(LABEL, "Available range of %{public}s is invalid.", permDef.permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Available range of %{public}s is invalid.", permDef.permissionName.c_str()); return false; } state.grantFlags[0] = PERMISSION_DEFAULT_FLAG; @@ -1018,7 +1015,7 @@ bool PermissionManager::InitPermissionList(const std::string& appDistributionTyp } initializedList.emplace_back(state); } - ACCESSTOKEN_LOG_INFO(LABEL, "After, request perm list size: %{public}zu.", initializedList.size()); + LOGI(ATM_DOMAIN, ATM_TAG, "After, request perm list size: %{public}zu.", initializedList.size()); return true; } diff --git a/services/accesstokenmanager/main/cpp/src/permission/permission_policy_set.cpp b/services/accesstokenmanager/main/cpp/src/permission/permission_policy_set.cpp index 52c11d33d338e5b512da31b908c5fe862feadee0..5c775fbd23a0df12ba8fd3ca4922dd831831f597 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/permission_policy_set.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/permission_policy_set.cpp @@ -32,13 +32,9 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PermissionPolicySet"}; -} - PermissionPolicySet::~PermissionPolicySet() { - ACCESSTOKEN_LOG_DEBUG(LABEL, + LOGD(ATM_DOMAIN, ATM_TAG, "%{public}s called, tokenID: 0x%{public}x destruction", __func__, tokenId_); } @@ -82,7 +78,7 @@ std::shared_ptr PermissionPolicySet::BuildPolicySetWithoutD PermissionValidator::FilterInvalidPermissionState( TOKEN_TYPE_BUTT, false, permStateList, policySet->permStateList_); policySet->tokenId_ = tokenId; - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d, permStateList_ size: %{public}zu", + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID: %{public}d, permStateList_ size: %{public}zu", tokenId, policySet->permStateList_.size()); std::vector list; GetPermissionBriefData(list, policySet->permStateList_); @@ -103,7 +99,7 @@ std::shared_ptr PermissionPolicySet::BuildPermissionPolicyS if (ret == RET_SUCCESS) { MergePermissionStateFull(policySet->permStateList_, state); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId 0%{public}u permState is wrong.", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenId 0%{public}u permState is wrong.", tokenId); } } } @@ -138,7 +134,7 @@ void PermissionPolicySet::Update(const std::vector& permSta { std::vector permStateFilterList; PermissionValidator::FilterInvalidPermissionState(TOKEN_HAP, true, permStateList, permStateFilterList); - ACCESSTOKEN_LOG_INFO(LABEL, "PermStateFilterList size: %{public}zu.", permStateFilterList.size()); + LOGI(ATM_DOMAIN, ATM_TAG, "PermStateFilterList size: %{public}zu.", permStateFilterList.size()); Utils::UniqueWriteGuard infoGuard(this->permPolicySetLock_); for (PermissionStateFull& permStateNew : permStateFilterList) { @@ -174,7 +170,7 @@ std::shared_ptr PermissionPolicySet::RestorePermissionPolic if (ret == RET_SUCCESS) { MergePermissionStateFull(policySet->permStateList_, state); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId 0x%{public}x permState is wrong.", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenId 0x%{public}x permState is wrong.", tokenId); } } } @@ -199,18 +195,18 @@ void PermissionPolicySet::MergePermissionStateFull(std::vectorresDeviceID.emplace_back(state.resDeviceID[0]); iter->grantStatus.emplace_back(state.grantStatus[0]); iter->grantFlags.emplace_back(state.grantFlags[0]); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Update permission: %{public}s.", state.permissionName.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "Update permission: %{public}s.", state.permissionName.c_str()); return; } } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Add permission: %{public}s.", state.permissionName.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "Add permission: %{public}s.", state.permissionName.c_str()); permStateList.emplace_back(state); } void PermissionPolicySet::StorePermissionState(std::vector& valueList) const { for (const auto& permissionState : permStateList_) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermissionName: %{public}s", permissionState.permissionName.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "PermissionName: %{public}s", permissionState.permissionName.c_str()); if (permissionState.isGeneral) { GenericValues genericValues; genericValues.Put(TokenFiledConst::FIELD_TOKEN_ID, static_cast(tokenId_)); @@ -249,12 +245,12 @@ int PermissionPolicySet::QueryPermissionFlag(const std::string& permissionName, flag = perm.grantFlags[0]; return RET_SUCCESS; } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission %{public}s is invalid", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission %{public}s is invalid", permissionName.c_str()); return AccessTokenError::ERR_PARAM_INVALID; } } } - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid params!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid params!"); return AccessTokenError::ERR_PERMISSION_NOT_EXIST; } @@ -274,20 +270,20 @@ int32_t PermissionPolicySet::UpdatePermStateList( }); if (iter != permStateList_.end()) { if ((static_cast(iter->grantFlags[0]) & PERMISSION_SYSTEM_FIXED) == PERMISSION_SYSTEM_FIXED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission fixed by system!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission fixed by system!"); return AccessTokenError::ERR_PARAM_INVALID; } iter->grantStatus[0] = isGranted ? PERMISSION_GRANTED : PERMISSION_DENIED; iter->grantFlags[0] = UpdateWithNewFlag(iter->grantFlags[0], flag); uint32_t opCode; if (!TransferPermissionToOpcode(permissionName, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "permissionName is invalid %{public}s.", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "permissionName is invalid %{public}s.", permissionName.c_str()); return AccessTokenError::ERR_PARAM_INVALID; } bool status = (iter->grantStatus[0] == PERMISSION_GRANTED) ? 1 : 0; return PermissionDataBrief::GetInstance().SetBriefPermData(tokenId_, opCode, status, iter->grantFlags[0]); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission not request!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission not request!"); return AccessTokenError::ERR_PARAM_INVALID; } return RET_SUCCESS; @@ -299,10 +295,10 @@ int32_t PermissionPolicySet::UpdateSecCompGrantedPermList( int32_t flag = 0; int32_t ret = QueryPermissionFlag(permissionName, flag); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Ret is %{public}d. flag is %{public}d", ret, flag); + LOGD(ATM_DOMAIN, ATM_TAG, "Ret is %{public}d. flag is %{public}d", ret, flag); // if the permission has been operated by user or the permission has been granted by system. if ((ConstantCommon::IsPermOperatedByUser(flag) || ConstantCommon::IsPermOperatedBySystem(flag))) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "The permission has been operated."); + LOGD(ATM_DOMAIN, ATM_TAG, "The permission has been operated."); if (isToGrant) { // The data included in requested perm list. int32_t status = PermissionDataBrief::GetInstance().VerifyPermissionStatus(tokenId_, permissionName); @@ -310,7 +306,7 @@ int32_t PermissionPolicySet::UpdateSecCompGrantedPermList( if (status == PERMISSION_GRANTED) { return RET_SUCCESS; } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission has been revoked by user."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission has been revoked by user."); return ERR_PERMISSION_DENIED; } } else { @@ -333,7 +329,7 @@ int32_t PermissionPolicySet::UpdatePermissionStatus( if (!ConstantCommon::IsPermGrantedBySecComp(flag)) { ret = UpdatePermStateList(permissionName, isGranted, flag); } else { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Permission is set by security component."); + LOGD(ATM_DOMAIN, ATM_TAG, "Permission is set by security component."); ret = UpdateSecCompGrantedPermList(permissionName, isGranted); } int32_t newStatus = PermissionDataBrief::GetInstance().VerifyPermissionStatus(tokenId_, permissionName); diff --git a/services/accesstokenmanager/main/cpp/src/permission/permission_validator.cpp b/services/accesstokenmanager/main/cpp/src/permission/permission_validator.cpp index ff5368af56982aa0566af3d253cc396430c23b32..dfcc19584f06585bbbd8a0e302738bf55bdd3258 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/permission_validator.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/permission_validator.cpp @@ -24,10 +24,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PermissionValidator"}; -} - bool PermissionValidator::IsGrantModeValid(int grantMode) { return grantMode == GrantMode::SYSTEM_GRANT || grantMode == GrantMode::USER_GRANT; @@ -61,31 +57,31 @@ bool PermissionValidator::IsToggleStatusValid(const uint32_t status) bool PermissionValidator::IsPermissionDefValid(const PermissionDef& permDef) { if (!DataValidator::IsLabelValid(permDef.label)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Label invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Label invalid."); return false; } if (!DataValidator::IsDescValid(permDef.description)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Desc invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Desc invalid."); return false; } if (!DataValidator::IsBundleNameValid(permDef.bundleName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "BundleName invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "BundleName invalid."); return false; } if (!DataValidator::IsPermissionNameValid(permDef.permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "PermissionName invalid."); return false; } if (!IsGrantModeValid(permDef.grantMode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GrantMode invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "GrantMode invalid."); return false; } if (!DataValidator::IsAvailableTypeValid(permDef.availableType)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AvailableType invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "AvailableType invalid."); return false; } if (!DataValidator::IsAplNumValid(permDef.availableLevel)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AvailableLevel invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "AvailableLevel invalid."); return false; } return true; @@ -93,10 +89,10 @@ bool PermissionValidator::IsPermissionDefValid(const PermissionDef& permDef) bool PermissionValidator::IsPermissionAvailable(ATokenTypeEnum tokenType, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenType is %{public}d.", tokenType); + LOGD(ATM_DOMAIN, ATM_TAG, "TokenType is %{public}d.", tokenType); if (tokenType == TOKEN_HAP) { if (!PermissionDefinitionCache::GetInstance().HasHapPermissionDefinitionForHap(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s is not defined for hap.", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "%{public}s is not defined for hap.", permissionName.c_str()); return false; } } @@ -113,7 +109,7 @@ bool PermissionValidator::IsPermissionStateValid(const PermissionStateFull& perm size_t grantStatSize = permState.grantStatus.size(); size_t grantFlagSize = permState.grantFlags.size(); if ((grantStatSize != resDevIdSize) || (grantFlagSize != resDevIdSize)) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "list size is invalid, grantStatSize %{public}zu, grantFlagSize %{public}zu, resDevIdSize %{public}zu.", grantStatSize, grantFlagSize, resDevIdSize); return false; @@ -121,7 +117,7 @@ bool PermissionValidator::IsPermissionStateValid(const PermissionStateFull& perm for (uint32_t i = 0; i < resDevIdSize; i++) { if (!IsGrantStatusValid(permState.grantStatus[i]) || !IsPermissionFlagValid(permState.grantFlags[i])) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GrantStatus or grantFlags is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "GrantStatus or grantFlags is invalid"); return false; } } diff --git a/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp b/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp index b6204f5de3f1f9d9a031a5f04ca9525628c0f33a..fa04194dde656eda57401905012f64f1e4e35105 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp @@ -27,11 +27,10 @@ namespace OHOS { namespace Security { namespace AccessToken { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "ShortGrantManager"}; std::recursive_mutex g_instanceMutex; static constexpr int32_t DEFAULT_MAX_TIME_MILLISECONDS = 30 * 60; // 30 minutes static constexpr int32_t DEFAULT_MAX_ONCE_TIME_MILLISECONDS = 5 * 60; // 5 minutes -static const std::string TASK_NAME_SHORT_GRANT_PERMISSION = "atm_permission_manager_short_grant"; +constexpr const char* TASK_NAME_SHORT_GRANT_PERMISSION = "atm_permission_manager_short_grant"; static const std::vector g_shortGrantPermission = { "ohos.permission.SHORT_TERM_WRITE_IMAGEVIDEO" }; @@ -51,7 +50,7 @@ ShortGrantManager& ShortGrantManager::GetInstance() void ShortPermAppManagerDeathCallback::NotifyAppManagerDeath() { - ACCESSTOKEN_LOG_INFO(LABEL, "ShortGrantManager AppManagerDeath called"); + LOGI(ATM_DOMAIN, ATM_TAG, "ShortGrantManager AppManagerDeath called"); ShortGrantManager::GetInstance().OnAppMgrRemoteDiedHandle(); } @@ -60,7 +59,7 @@ void ShortPermAppStateObserver::OnAppStopped(const AppStateData &appStateData) { if (appStateData.state == static_cast(ApplicationState::APP_STATE_TERMINATED)) { uint32_t tokenID = appStateData.accessTokenId; - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID:%{public}d died.", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d died.", tokenID); ShortGrantManager::GetInstance().ClearShortPermissionByTokenID(tokenID); } @@ -73,7 +72,7 @@ void ShortGrantManager::OnAppMgrRemoteDiedHandle() while (item != shortGrantData_.end()) { if (PermissionManager::GetInstance().UpdatePermission( item->tokenID, item->permissionName, false, PERMISSION_USER_FIXED, false) != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d revoke permission:%{public}s failed!", + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d revoke permission:%{public}s failed!", item->tokenID, item->permissionName.c_str()); } std::string taskName = TASK_NAME_SHORT_GRANT_PERMISSION + std::to_string(item->tokenID) + item->permissionName; @@ -81,7 +80,7 @@ void ShortGrantManager::OnAppMgrRemoteDiedHandle() ++item; } shortGrantData_.clear(); - ACCESSTOKEN_LOG_INFO(LABEL, "shortGrantData_ clear!"); + LOGI(ATM_DOMAIN, ATM_TAG, "shortGrantData_ clear!"); appStopCallBack_ = nullptr; } @@ -95,7 +94,7 @@ void ShortGrantManager::InitEventHandler() { auto eventRunner = AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT); if (!eventRunner) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create a shortGrantEventRunner."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create a shortGrantEventRunner."); return; } eventHandler_ = std::make_shared(eventRunner); @@ -116,15 +115,15 @@ bool ShortGrantManager::CancelTaskOfPermissionRevoking(const std::string& taskNa #ifdef EVENTHANDLER_ENABLE auto eventHandler = GetEventHandler(); if (eventHandler == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get EventHandler"); return false; } - ACCESSTOKEN_LOG_INFO(LABEL, "Revoke permission task name:%{public}s", taskName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Revoke permission task name:%{public}s", taskName.c_str()); eventHandler->ProxyRemoveTask(taskName); return true; #else - ACCESSTOKEN_LOG_WARN(LABEL, "EventHandler is not existed"); + LOGW(ATM_DOMAIN, ATM_TAG, "EventHandler is not existed"); return false; #endif } @@ -132,21 +131,21 @@ bool ShortGrantManager::CancelTaskOfPermissionRevoking(const std::string& taskNa int ShortGrantManager::RefreshPermission(AccessTokenID tokenID, const std::string& permission, uint32_t onceTime) { if (tokenID == 0 || onceTime == 0 || onceTime > DEFAULT_MAX_ONCE_TIME_MILLISECONDS || onceTime > maxTime_) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Input invalid, tokenID: %{public}d, onceTime %{public}u!", tokenID, onceTime); + LOGE(ATM_DOMAIN, ATM_TAG, + "Invalid param, id: %{public}d, onceTime %{public}u!", tokenID, onceTime); return AccessTokenError::ERR_PARAM_INVALID; } std::string taskName = TASK_NAME_SHORT_GRANT_PERMISSION + std::to_string(tokenID) + permission; std::unique_lock lck(shortGrantDataMutex_); - auto iter = std::find_if( shortGrantData_.begin(), shortGrantData_.end(), [tokenID, permission](const PermTimerData& data) { return data.tokenID == tokenID && data.permissionName == permission; }); - if (iter == shortGrantData_.end()) { auto iterator = std::find(g_shortGrantPermission.begin(), g_shortGrantPermission.end(), permission); if (iterator == g_shortGrantPermission.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission is not available to short grant: %{public}s!", permission.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, + "Permission is not available to short grant: %{public}s!", permission.c_str()); return AccessTokenError::ERR_PARAM_INVALID; } PermTimerData data; @@ -156,7 +155,7 @@ int ShortGrantManager::RefreshPermission(AccessTokenID tokenID, const std::strin data.revokeTimes = data.firstGrantTimes + onceTime; int32_t ret = PermissionManager::GetInstance().GrantPermission(tokenID, permission, PERMISSION_USER_FIXED); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GrantPermission failed result %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "GrantPermission failed result %{public}d", ret); return ret; } shortGrantData_.emplace_back(data); @@ -168,14 +167,14 @@ int ShortGrantManager::RefreshPermission(AccessTokenID tokenID, const std::strin uint32_t maxRemainedTime = maxTime_ - (GetCurrentTime() - iter->firstGrantTimes); uint32_t currRemainedTime = iter->revokeTimes > GetCurrentTime() ? (iter->revokeTimes - GetCurrentTime()) : 0; uint32_t cancelTimes = (maxRemainedTime > onceTime) ? onceTime : maxRemainedTime; - ACCESSTOKEN_LOG_INFO(LABEL, "currRemainedTime %{public}d", currRemainedTime); + LOGI(ATM_DOMAIN, ATM_TAG, "currRemainedTime %{public}d", currRemainedTime); if (cancelTimes > currRemainedTime) { iter->revokeTimes = GetCurrentTime() + cancelTimes; - ACCESSTOKEN_LOG_INFO(LABEL, "iter->revokeTimes %{public}d", iter->revokeTimes); + LOGI(ATM_DOMAIN, ATM_TAG, "iter->revokeTimes %{public}d", iter->revokeTimes); ShortGrantManager::GetInstance().CancelTaskOfPermissionRevoking(taskName); int32_t ret = PermissionManager::GetInstance().GrantPermission(tokenID, permission, PERMISSION_USER_FIXED); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GrantPermission failed result %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "GrantPermission failed result %{public}d", ret); return ret; } ShortGrantManager::GetInstance().ScheduleRevokeTask(iter->tokenID, iter->permissionName, taskName, cancelTimes); @@ -193,7 +192,7 @@ void ShortGrantManager::ClearShortPermissionData(AccessTokenID tokenID, const st // revoke without kill the app if (PermissionManager::GetInstance().UpdatePermission( tokenID, permission, false, PERMISSION_USER_FIXED, false) != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d revoke permission:%{public}s failed!", + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d revoke permission:%{public}s failed!", tokenID, permission.c_str()); return; } @@ -217,7 +216,7 @@ void ShortGrantManager::ClearShortPermissionByTokenID(AccessTokenID tokenID) if (item->tokenID == tokenID) { if (PermissionManager::GetInstance().UpdatePermission( tokenID, item->permissionName, false, PERMISSION_USER_FIXED, false) != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d revoke permission:%{public}s failed!", + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d revoke permission:%{public}s failed!", tokenID, item->permissionName.c_str()); return; } @@ -240,22 +239,22 @@ void ShortGrantManager::ScheduleRevokeTask(AccessTokenID tokenID, const std::str #ifdef EVENTHANDLER_ENABLE auto eventHandler = GetEventHandler(); if (eventHandler == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get EventHandler"); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "Add permission task name:%{public}s", taskName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Add permission task name:%{public}s", taskName.c_str()); std::function delayed = ([tokenID, permission]() { ShortGrantManager::GetInstance().ClearShortPermissionData(tokenID, permission); - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "Token: %{public}d, permission: %{public}s, delay revoke permission end.", tokenID, permission.c_str()); }); - ACCESSTOKEN_LOG_INFO(LABEL, "cancelTimes %{public}d", cancelTimes); + LOGI(ATM_DOMAIN, ATM_TAG, "cancelTimes %{public}d", cancelTimes); eventHandler->ProxyPostTask(delayed, taskName, cancelTimes * 1000); // 1000 means to ms return; #else - ACCESSTOKEN_LOG_WARN(LABEL, "eventHandler is not existed"); + LOGW(ATM_DOMAIN, ATM_TAG, "eventHandler is not existed"); return; #endif } @@ -281,7 +280,7 @@ void ShortGrantManager::RegisterAppStopListener() if (appManagerDeathCallback_ == nullptr) { appManagerDeathCallback_ = std::make_shared(); if (appManagerDeathCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register appManagerDeathCallback failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Register appManagerDeathCallback failed."); return; } AppManagerAccessClient::GetInstance().RegisterDeathCallback(appManagerDeathCallback_); @@ -292,12 +291,12 @@ void ShortGrantManager::RegisterAppStopListener() if (appStopCallBack_ == nullptr) { appStopCallBack_ = new (std::nothrow) ShortPermAppStateObserver(); if (appStopCallBack_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register appStopCallBack failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Register appStopCallBack failed."); return; } int ret = AppManagerAccessClient::GetInstance().RegisterApplicationStateObserver(appStopCallBack_); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_INFO(LABEL, "Register appStopCallBack %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Register appStopCallBack %{public}d.", ret); } } } @@ -309,7 +308,7 @@ void ShortGrantManager::UnRegisterAppStopListener() if (appStopCallBack_ != nullptr) { int32_t ret = AppManagerAccessClient::GetInstance().UnregisterApplicationStateObserver(appStopCallBack_); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_INFO(LABEL, "Unregister appStopCallback %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Unregister appStopCallback %{public}d.", ret); } appStopCallBack_= nullptr; } diff --git a/services/accesstokenmanager/main/cpp/src/permission/temp_permission_observer.cpp b/services/accesstokenmanager/main/cpp/src/permission/temp_permission_observer.cpp index 3f62ade578295bdcaaf2e64cc2caeb31bfb3bc65..c00ab09875fc35e88207030f85848a6dd1d14dab 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/temp_permission_observer.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/temp_permission_observer.cpp @@ -33,10 +33,9 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TempPermissionObserver"}; -static const std::string TASK_NAME_TEMP_PERMISSION = "atm_permission_manager_temp_permission"; -static const std::string FORM_INVISIBLE_NAME = "#0"; -static const std::string FORM_VISIBLE_NAME = "#1"; +constexpr const char* TASK_NAME_TEMP_PERMISSION = "atm_permission_manager_temp_permission"; +constexpr const char* FORM_INVISIBLE_NAME = "#0"; +constexpr const char* FORM_VISIBLE_NAME = "#1"; static constexpr int32_t ROOT_UID = 0; static constexpr int32_t FOREGROUND_FLAG = 0; static constexpr int32_t FORMS_FLAG = 1; @@ -71,10 +70,11 @@ void PermissionAppStateObserver::OnAppStateChanged(const AppStateData &appStateD uint32_t tokenID = appStateData.accessTokenId; std::vector list; if (!TempPermissionObserver::GetInstance().GetAppStateListByTokenID(tokenID, list)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID:%{public}d not use temp permission", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d not use temp permission", tokenID); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(accessTokenId=%{public}d, state=%{public}d)", tokenID, appStateData.state); + LOGI(ATM_DOMAIN, ATM_TAG, + "OnChange(Id=%{public}d, state=%{public}d)", tokenID, appStateData.state); if (appStateData.state == static_cast(ApplicationState::APP_STATE_FOREGROUND)) { TempPermissionObserver::GetInstance().ModifyAppState(tokenID, FOREGROUND_FLAG, true); std::string taskName = TASK_NAME_TEMP_PERMISSION + std::to_string(tokenID); @@ -82,11 +82,12 @@ void PermissionAppStateObserver::OnAppStateChanged(const AppStateData &appStateD } else if (appStateData.state == static_cast(ApplicationState::APP_STATE_BACKGROUND)) { TempPermissionObserver::GetInstance().ModifyAppState(tokenID, FOREGROUND_FLAG, false); if (list[FORMS_FLAG]) { - ACCESSTOKEN_LOG_WARN(LABEL, "%{public}d:tokenID has form, don't delayRevokePermission!", tokenID); + LOGW(ATM_DOMAIN, ATM_TAG, "Id:%{public}d has form, don't delayRevokePermission!", tokenID); return; } if (list[CONTINUOUS_TASK_FLAG]) { - ACCESSTOKEN_LOG_WARN(LABEL, "%{public}d:tokenID has continuoustask, don't delayRevokePermission!", tokenID); + LOGW(ATM_DOMAIN, ATM_TAG, + "Id:%{public}d has continuoustask, don't delayRevokePermission!", tokenID); return; } std::string taskName = TASK_NAME_TEMP_PERMISSION + std::to_string(tokenID); @@ -98,7 +99,7 @@ void PermissionAppStateObserver::OnAppStopped(const AppStateData &appStateData) { if (appStateData.state == static_cast(ApplicationState::APP_STATE_TERMINATED)) { uint32_t tokenID = appStateData.accessTokenId; - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID:%{public}d died.", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id:%{public}d died.", tokenID); // cancle task when process die std::string taskName = TASK_NAME_TEMP_PERMISSION + std::to_string(tokenID); TempPermissionObserver::GetInstance().CancleTaskOfPermissionRevoking(taskName); @@ -131,11 +132,11 @@ int32_t PermissionFormStateObserver::NotifyWhetherFormsVisible(const FormVisibil } std::vector list; if (!TempPermissionObserver::GetInstance().GetAppStateListByTokenID(tokenID, list)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d not use temp permission", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id:%{public}d not use temp permission", tokenID); continue; } - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s, tokenID: %{public}d, formVisiblity:%{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "%{public}s, Id: %{public}d, formVisiblity:%{public}d", formInstances[i].bundleName_.c_str(), tokenID, formInstances[i].formVisiblity_); if (formInstances[i].formVisiblity_ == FormVisibilityType::VISIBLE) { @@ -145,11 +146,13 @@ int32_t PermissionFormStateObserver::NotifyWhetherFormsVisible(const FormVisibil } else if (formInstances[i].formVisiblity_ == FormVisibilityType::INVISIBLE) { TempPermissionObserver::GetInstance().ModifyAppState(tokenID, FORMS_FLAG, false); if (list[FOREGROUND_FLAG]) { - ACCESSTOKEN_LOG_WARN(LABEL, "%{public}d:tokenID in foreground don't delayRevokePermission!", tokenID); + LOGW(ATM_DOMAIN, ATM_TAG, + "Id:%{public}d in foreground don't delayRevokePermission!", tokenID); continue; } if (list[CONTINUOUS_TASK_FLAG]) { - ACCESSTOKEN_LOG_WARN(LABEL, "%{public}d:tokenID has task, don't delayRevokePermission!", tokenID); + LOGW(ATM_DOMAIN, ATM_TAG, + "Id:%{public}d has task, don't delayRevokePermission!", tokenID); continue; } std::string taskName = TASK_NAME_TEMP_PERMISSION + std::to_string(tokenID); @@ -165,15 +168,15 @@ void PermissionBackgroundTaskObserver::OnContinuousTaskStart( AccessTokenID tokenID = static_cast(continuousTaskCallbackInfo->GetFullTokenId()); uint32_t typeId = continuousTaskCallbackInfo->GetTypeId(); if (static_cast(typeId) != BackgroundMode::LOCATION) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TypeId:%{public}d can not use temp permission", typeId); + LOGD(ATM_DOMAIN, ATM_TAG, "TypeId:%{public}d can not use temp permission", typeId); return; } std::vector list; if (!TempPermissionObserver::GetInstance().GetAppStateListByTokenID(tokenID, list)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID:%{public}d not use temp permission", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id:%{public}d not use temp permission", tokenID); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}d", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "%{public}d", tokenID); TempPermissionObserver::GetInstance().AddContinuousTask(tokenID); TempPermissionObserver::GetInstance().ModifyAppState(tokenID, CONTINUOUS_TASK_FLAG, true); std::string taskName = TASK_NAME_TEMP_PERMISSION + std::to_string(tokenID); @@ -186,23 +189,23 @@ void PermissionBackgroundTaskObserver::OnContinuousTaskStop( AccessTokenID tokenID = static_cast(continuousTaskCallbackInfo->GetFullTokenId()); uint32_t typeId = continuousTaskCallbackInfo->GetTypeId(); if (static_cast(typeId) != BackgroundMode::LOCATION) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TypeId:%{public}d can not use temp permission", typeId); + LOGD(ATM_DOMAIN, ATM_TAG, "TypeId:%{public}d can not use temp permission", typeId); return; } std::vector list; if (!TempPermissionObserver::GetInstance().GetAppStateListByTokenID(tokenID, list)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID:%{public}d not use temp permission", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id:%{public}d not use temp permission", tokenID); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}d", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "%{public}d", tokenID); TempPermissionObserver::GetInstance().DelContinuousTask(tokenID); if (TempPermissionObserver::GetInstance().FindContinuousTask(tokenID)) { - ACCESSTOKEN_LOG_WARN(LABEL, "Has continuous task don't delayRevokePermission!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Has continuous task don't delayRevokePermission!"); return; } TempPermissionObserver::GetInstance().ModifyAppState(tokenID, CONTINUOUS_TASK_FLAG, false); if (list[FOREGROUND_FLAG] || list[FORMS_FLAG]) { - ACCESSTOKEN_LOG_WARN(LABEL, "Has form or inForeground don't delayRevokePermission!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Has form or inForeground don't delayRevokePermission!"); return; } std::string taskName = TASK_NAME_TEMP_PERMISSION + std::to_string(tokenID); @@ -211,7 +214,7 @@ void PermissionBackgroundTaskObserver::OnContinuousTaskStop( #endif void PermissionAppManagerDeathCallback::NotifyAppManagerDeath() { - ACCESSTOKEN_LOG_INFO(LABEL, "TempPermissionObserver AppManagerDeath called"); + LOGI(ATM_DOMAIN, ATM_TAG, "TempPermissionObserver AppManagerDeath called"); TempPermissionObserver::GetInstance().OnAppMgrRemoteDiedHandle(); } @@ -232,11 +235,11 @@ void TempPermissionObserver::RegisterCallback() if (backgroundTaskCallback_ == nullptr) { backgroundTaskCallback_ = new (std::nothrow) PermissionBackgroundTaskObserver(); if (backgroundTaskCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register backgroundTaskCallback failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Register backgroundTaskCallback failed."); return; } int ret = BackgourndTaskManagerAccessClient::GetInstance().SubscribeBackgroundTask(backgroundTaskCallback_); - ACCESSTOKEN_LOG_INFO(LABEL, "Register backgroundTaskCallback %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Register backgroundTaskCallback %{public}d.", ret); } } #endif @@ -245,26 +248,26 @@ void TempPermissionObserver::RegisterCallback() if (formVisibleCallback_ == nullptr) { formVisibleCallback_ = new (std::nothrow) PermissionFormStateObserver(); if (formVisibleCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register formStateCallback failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Register formStateCallback failed."); return; } int ret = FormManagerAccessClient::GetInstance().RegisterAddObserver( FORM_VISIBLE_NAME, formVisibleCallback_->AsObject()); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_INFO(LABEL, "Register observer %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Register observer %{public}d.", ret); } } if (formInvisibleCallback_ == nullptr) { formInvisibleCallback_ = new (std::nothrow) PermissionFormStateObserver(); if (formInvisibleCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register formStateCallback failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Register formStateCallback failed."); formVisibleCallback_ = nullptr; return; } int ret = FormManagerAccessClient::GetInstance().RegisterAddObserver( FORM_INVISIBLE_NAME, formInvisibleCallback_->AsObject()); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_INFO(LABEL, "Register observer %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Register observer %{public}d.", ret); } } } @@ -278,12 +281,12 @@ void TempPermissionObserver::RegisterAppStatusListener() if (appStateCallback_ == nullptr) { appStateCallback_ = new (std::nothrow) PermissionAppStateObserver(); if (appStateCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register appStateCallback failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Register appStateCallback failed."); return; } int ret = AppManagerAccessClient::GetInstance().RegisterApplicationStateObserver(appStateCallback_); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_INFO(LABEL, "Register appStateCallback %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Register appStateCallback %{public}d.", ret); } } } @@ -293,7 +296,7 @@ void TempPermissionObserver::RegisterAppStatusListener() if (appManagerDeathCallback_ == nullptr) { appManagerDeathCallback_ = std::make_shared(); if (appManagerDeathCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register appManagerDeathCallback failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Register appManagerDeathCallback failed."); return; } AppManagerAccessClient::GetInstance().RegisterDeathCallback(appManagerDeathCallback_); @@ -308,7 +311,7 @@ void TempPermissionObserver::UnRegisterCallback() if (appStateCallback_ != nullptr) { int32_t ret = AppManagerAccessClient::GetInstance().UnregisterApplicationStateObserver(appStateCallback_); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_INFO(LABEL, "Unregister appStateCallback %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Unregister appStateCallback %{public}d.", ret); } appStateCallback_= nullptr; } @@ -320,7 +323,7 @@ void TempPermissionObserver::UnRegisterCallback() int32_t ret = BackgourndTaskManagerAccessClient::GetInstance().UnsubscribeBackgroundTask( backgroundTaskCallback_); if (ret != ERR_NONE) { - ACCESSTOKEN_LOG_INFO(LABEL, "Unregister appStateCallback %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Unregister appStateCallback %{public}d.", ret); } backgroundTaskCallback_= nullptr; } @@ -333,7 +336,7 @@ void TempPermissionObserver::UnRegisterCallback() FORM_VISIBLE_NAME, formVisibleCallback_); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_INFO(LABEL, "Unregister appStateCallback %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Unregister appStateCallback %{public}d.", ret); } formVisibleCallback_ = nullptr; } @@ -341,7 +344,7 @@ void TempPermissionObserver::UnRegisterCallback() int32_t ret = FormManagerAccessClient::GetInstance().RegisterRemoveObserver( FORM_INVISIBLE_NAME, formInvisibleCallback_); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_INFO(LABEL, "Unregister appStateCallback %{public}d.", ret); + LOGI(ATM_DOMAIN, ATM_TAG, "Unregister appStateCallback %{public}d.", ret); } formInvisibleCallback_ = nullptr; } @@ -364,7 +367,7 @@ void TempPermissionObserver::ModifyAppState(AccessTokenID tokenID, int32_t index std::unique_lock lck(tempPermissionMutex_); auto iter = tempPermTokenMap_.find(tokenID); if (iter == tempPermTokenMap_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d not exist in map", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d not exist in map", tokenID); return; } iter->second[index] = flag; @@ -375,7 +378,7 @@ bool TempPermissionObserver::GetTokenIDByBundle(const std::string &bundleName, A std::unique_lock lck(formTokenMutex_); auto iter = formTokenMap_.find(bundleName); if (iter == formTokenMap_.end()) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "BundleName:%{public}s not exist in map", bundleName.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "BundleName:%{public}s not exist in map", bundleName.c_str()); return false; } tokenID = iter->second; @@ -387,7 +390,7 @@ void TempPermissionObserver::AddContinuousTask(AccessTokenID tokenID) std::unique_lock lck(continuousTaskMutex_); auto iter = continuousTaskMap_.find(tokenID); if (iter == continuousTaskMap_.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID:%{public}d not exist in map", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d not exist in map", tokenID); continuousTaskMap_[tokenID] = 1; return; } @@ -399,11 +402,11 @@ void TempPermissionObserver::DelContinuousTask(AccessTokenID tokenID) std::unique_lock lck(continuousTaskMutex_); auto iter = continuousTaskMap_.find(tokenID); if (iter == continuousTaskMap_.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID:%{public}d not exist in map", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d not exist in map", tokenID); return; } continuousTaskMap_[tokenID]--; - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID:%{public}d has %{public}d tasks in map", + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d has %{public}d tasks in map", tokenID, continuousTaskMap_[tokenID]); if (continuousTaskMap_[tokenID] == 0) { continuousTaskMap_.erase(tokenID); @@ -415,10 +418,10 @@ bool TempPermissionObserver::FindContinuousTask(AccessTokenID tokenID) std::unique_lock lck(continuousTaskMutex_); auto iter = continuousTaskMap_.find(tokenID); if (iter == continuousTaskMap_.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID:%{public}d not exist in map", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d not exist in map", tokenID); return false; } - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID:%{public}d has %{public}d tasks in map", + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d has %{public}d tasks in map", tokenID, continuousTaskMap_[tokenID]); return true; } @@ -427,12 +430,13 @@ bool TempPermissionObserver::IsAllowGrantTempPermission(AccessTokenID tokenID, c { HapTokenInfo tokenInfo; if (AccessTokenInfoManager::GetInstance().GetHapTokenInfo(tokenID, tokenInfo) != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid tokenId(%{public}d)", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid Id(%{public}d)", tokenID); return false; } auto iterator = std::find(g_tempPermission.begin(), g_tempPermission.end(), permissionName); if (iterator == g_tempPermission.end()) { - ACCESSTOKEN_LOG_WARN(LABEL, "Permission is not available to temp grant: %{public}s!", permissionName.c_str()); + LOGW(ATM_DOMAIN, ATM_TAG, + "Permission is not available to temp grant: %{public}s!", permissionName.c_str()); return false; } return CheckPermissionState(tokenID, permissionName, tokenInfo.bundleName); @@ -463,7 +467,7 @@ bool TempPermissionObserver::CheckPermissionState(AccessTokenID tokenID, } #endif bool isFormVisible = FormManagerAccessClient::GetInstance().HasFormVisible(tokenID); - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID:%{public}d, isForeground:%{public}d, isFormVisible:%{public}d," + LOGI(ATM_DOMAIN, ATM_TAG, "Id:%{public}d, isForeground:%{public}d, isFormVisible:%{public}d," "isContinuousTaskExist:%{public}d", tokenID, isForeground, isFormVisible, isContinuousTaskExist); bool userEnable = true; @@ -492,7 +496,7 @@ void TempPermissionObserver::AddTempPermTokenToList(AccessTokenID tokenID, std::unique_lock lck(tempPermissionMutex_); tempPermTokenMap_[tokenID] = list; } - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID:%{public}d, permissionName:%{public}s", tokenID, permissionName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Id:%{public}d, permission:%{public}s", tokenID, permissionName.c_str()); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "GRANT_TEMP_PERMISSION", HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "TOKENID", tokenID, "PERMISSION_NAME", permissionName); @@ -507,15 +511,15 @@ bool TempPermissionObserver::GetPermissionStateFull(AccessTokenID tokenID, { std::shared_ptr infoPtr = AccessTokenInfoManager::GetInstance().GetHapTokenInfoInner(tokenID); if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u is invalid.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u is invalid.", tokenID); return false; } if (infoPtr->IsRemote()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "It is a remote hap token %{public}u!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "It is a remote hap token %{public}u!", tokenID); return false; } if (infoPtr->GetPermissionStateList(permissionStateFullList) != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetPermissionStateList failed, token %{public}u!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "GetPermissionStateList failed, token %{public}u!", tokenID); return false; } return true; @@ -525,7 +529,7 @@ void TempPermissionObserver::RevokeAllTempPermission(AccessTokenID tokenID) { std::vector list; if (!GetAppStateListByTokenID(tokenID, list)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d not exist in permList", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d not exist in permList", tokenID); return; } std::unique_lock lck(tempPermissionMutex_); @@ -536,14 +540,14 @@ void TempPermissionObserver::RevokeAllTempPermission(AccessTokenID tokenID) std::vector tmpList; if (!GetPermissionStateFull(tokenID, tmpList)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d get permission state full fail!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d get permission state full fail!", tokenID); return; } for (const auto& permissionState : tmpList) { if (permissionState.grantFlags[0] & PERMISSION_ALLOW_THIS_TIME) { if (PermissionManager::GetInstance().RevokePermission( tokenID, permissionState.permissionName, PERMISSION_ALLOW_THIS_TIME) != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d revoke permission:%{public}s failed!", + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d revoke permission:%{public}s failed!", tokenID, permissionState.permissionName.c_str()); return; } @@ -555,7 +559,7 @@ void TempPermissionObserver::RevokeTempPermission(AccessTokenID tokenID, const s { std::vector tmpList; if (!GetPermissionStateFull(tokenID, tmpList)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d get permission state full fail!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d get permission state full fail!", tokenID); return; } for (const auto& permissionState : tmpList) { @@ -563,7 +567,7 @@ void TempPermissionObserver::RevokeTempPermission(AccessTokenID tokenID, const s permissionState.permissionName == permissionName) { if (PermissionManager::GetInstance().RevokePermission( tokenID, permissionState.permissionName, PERMISSION_ALLOW_THIS_TIME) != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID:%{public}d revoke permission:%{public}s failed!", + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID:%{public}d revoke permission:%{public}s failed!", tokenID, permissionState.permissionName.c_str()); return; } @@ -584,7 +588,7 @@ void TempPermissionObserver::OnAppMgrRemoteDiedHandle() int32_t ret = PermissionManager::GetInstance().RevokePermission( iter->first, permissionState.permissionName, PERMISSION_ALLOW_THIS_TIME); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "revoke permission failed, TokenId=%{public}d, permission \ + LOGE(ATM_DOMAIN, ATM_TAG, "revoke permission failed, TokenId=%{public}d, permission \ name is %{public}s", iter->first, permissionState.permissionName.c_str()); } } @@ -592,7 +596,7 @@ void TempPermissionObserver::OnAppMgrRemoteDiedHandle() TempPermissionObserver::GetInstance().CancleTaskOfPermissionRevoking(taskName); } tempPermTokenMap_.clear(); - ACCESSTOKEN_LOG_INFO(LABEL, "TempPermTokenMap_ clear!"); + LOGI(ATM_DOMAIN, ATM_TAG, "TempPermTokenMap_ clear!"); appStateCallback_= nullptr; } @@ -601,7 +605,7 @@ void TempPermissionObserver::InitEventHandler() { auto eventRunner = AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT); if (!eventRunner) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create a recvRunner."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create a recvRunner."); return; } eventHandler_ = std::make_shared(eventRunner); @@ -622,20 +626,20 @@ bool TempPermissionObserver::DelayRevokePermission(AccessToken::AccessTokenID to #ifdef EVENTHANDLER_ENABLE auto eventHandler = GetEventHandler(); if (eventHandler == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get EventHandler"); return false; } - ACCESSTOKEN_LOG_INFO(LABEL, "Add permission task name:%{public}s", taskName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Add permission task name:%{public}s", taskName.c_str()); std::function delayed = ([tokenID]() { TempPermissionObserver::GetInstance().RevokeAllTempPermission(tokenID); - ACCESSTOKEN_LOG_INFO(LABEL, "Token: %{public}d, delay revoke permission end", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Token: %{public}d, delay revoke permission end", tokenID); }); eventHandler->ProxyPostTask(delayed, taskName, cancleTimes_); return true; #else - ACCESSTOKEN_LOG_WARN(LABEL, "Eventhandler is not existed"); + LOGW(ATM_DOMAIN, ATM_TAG, "Eventhandler is not existed"); return false; #endif } @@ -645,15 +649,15 @@ bool TempPermissionObserver::CancleTaskOfPermissionRevoking(const std::string& t #ifdef EVENTHANDLER_ENABLE auto eventHandler = GetEventHandler(); if (eventHandler == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get EventHandler"); return false; } - ACCESSTOKEN_LOG_INFO(LABEL, "Revoke permission task name:%{public}s", taskName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Revoke permission task name:%{public}s", taskName.c_str()); eventHandler->ProxyRemoveTask(taskName); return true; #else - ACCESSTOKEN_LOG_WARN(LABEL, "Eventhandler is not existed"); + LOGW(ATM_DOMAIN, ATM_TAG, "Eventhandler is not existed"); return false; #endif } @@ -663,7 +667,7 @@ void TempPermissionObserver::GetConfigValue() LibraryLoader loader(CONFIG_POLICY_LIBPATH); ConfigPolicyLoaderInterface* policy = loader.GetObject(); if (policy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Dlopen libaccesstoken_config_policy failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Dlopen libaccesstoken_config_policy failed."); return; } AccessTokenConfigValue value; @@ -673,7 +677,7 @@ void TempPermissionObserver::GetConfigValue() cancleTimes_ = DEFAULT_CANCLE_MILLISECONDS; } - ACCESSTOKEN_LOG_INFO(LABEL, "CancleTimes_ is %{public}d.", cancleTimes_); + LOGI(ATM_DOMAIN, ATM_TAG, "CancleTimes_ is %{public}d.", cancleTimes_); } } // namespace AccessToken } // namespace Security diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp index df4cb1d445b3fc032efedbb83da86c9e3ca04063..3db37a3a48666a93641faeb0c1c4c6ee848e65c9 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp @@ -53,9 +53,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "ATMServ" -}; static const char* ACCESS_TOKEN_SERVICE_INIT_KEY = "accesstoken.permission.init"; constexpr int32_t ERROR = -1; constexpr int TWO_ARGS = 2; @@ -71,29 +68,29 @@ const bool REGISTER_RESULT = AccessTokenManagerService::AccessTokenManagerService() : SystemAbility(SA_ID_ACCESSTOKEN_MANAGER_SERVICE, true), state_(ServiceRunningState::STATE_NOT_START) { - ACCESSTOKEN_LOG_INFO(LABEL, "AccessTokenManagerService()"); + LOGI(ATM_DOMAIN, ATM_TAG, "AccessTokenManagerService()"); } AccessTokenManagerService::~AccessTokenManagerService() { - ACCESSTOKEN_LOG_INFO(LABEL, "~AccessTokenManagerService()"); + LOGI(ATM_DOMAIN, ATM_TAG, "~AccessTokenManagerService()"); } void AccessTokenManagerService::OnStart() { if (state_ == ServiceRunningState::STATE_RUNNING) { - ACCESSTOKEN_LOG_INFO(LABEL, "AccessTokenManagerService has already started!"); + LOGI(ATM_DOMAIN, ATM_TAG, "AccessTokenManagerService has already started!"); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "AccessTokenManagerService is starting."); + LOGI(ATM_DOMAIN, ATM_TAG, "AccessTokenManagerService is starting."); if (!Initialize()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to initialize."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to initialize."); return; } state_ = ServiceRunningState::STATE_RUNNING; bool ret = Publish(DelayedSingleton::GetInstance().get()); if (!ret) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to publish service!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to publish service!"); ReportSysEventServiceStartError(SA_PUBLISH_FAILED, "Publish accesstoken_service fail.", ERROR); return; } @@ -102,12 +99,12 @@ void AccessTokenManagerService::OnStart() #ifdef TOKEN_SYNC_ENABLE (void)AddSystemAbilityListener(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); #endif - ACCESSTOKEN_LOG_INFO(LABEL, "Congratulations, AccessTokenManagerService start successfully!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Congratulations, AccessTokenManagerService start successfully!"); } void AccessTokenManagerService::OnStop() { - ACCESSTOKEN_LOG_INFO(LABEL, "Stop service."); + LOGI(ATM_DOMAIN, ATM_TAG, "Stop service."); state_ = ServiceRunningState::STATE_NOT_START; } @@ -131,7 +128,7 @@ void AccessTokenManagerService::OnRemoveSystemAbility(int32_t systemAbilityId, c PermUsedTypeEnum AccessTokenManagerService::GetPermissionUsedType( AccessTokenID tokenID, const std::string& permissionName) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID=%{public}d, permission=%{public}s", tokenID, permissionName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Id=%{public}d, permission=%{public}s", tokenID, permissionName.c_str()); return PermissionManager::GetInstance().GetPermissionUsedType(tokenID, permissionName); } @@ -141,7 +138,7 @@ int AccessTokenManagerService::VerifyAccessToken(AccessTokenID tokenID, const st StartTrace(HITRACE_TAG_ACCESS_CONTROL, "AccessTokenVerifyPermission"); #endif int32_t res = AccessTokenInfoManager::GetInstance().VerifyAccessToken(tokenID, permissionName); - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID: %{public}d, permission: %{public}s, res %{public}d", + LOGD(ATM_DOMAIN, ATM_TAG, "Id: %{public}d, permission: %{public}s, res %{public}d", tokenID, permissionName.c_str(), res); if ((res == PERMISSION_GRANTED) && (AccessTokenIDManager::GetInstance().GetTokenIdTypeEnum(tokenID) == TOKEN_HAP)) { @@ -168,13 +165,13 @@ int AccessTokenManagerService::VerifyAccessToken(AccessTokenID tokenID, int AccessTokenManagerService::GetDefPermission( const std::string& permissionName, PermissionDefParcel& permissionDefResult) { - ACCESSTOKEN_LOG_INFO(LABEL, "Permission: %{public}s", permissionName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Permission: %{public}s", permissionName.c_str()); return PermissionManager::GetInstance().GetDefPermission(permissionName, permissionDefResult.permissionDef); } int AccessTokenManagerService::GetDefPermissions(AccessTokenID tokenID, std::vector& permList) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}d", tokenID); std::vector permVec; PermissionManager::GetInstance().GetDefPermissions(tokenID, permVec); for (const auto& perm : permVec) { @@ -213,7 +210,7 @@ int32_t AccessTokenManagerService::GetPermissionsStatus(AccessTokenID tokenID, std::vector& reqPermList) { if (!AccessTokenInfoManager::GetInstance().IsTokenIdExist(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID=%{public}d does not exist", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id=%{public}d does not exist", tokenID); return ERR_TOKENID_NOT_EXIST; } PermissionOper ret = GetPermissionsState(tokenID, reqPermList); @@ -225,17 +222,17 @@ PermissionOper AccessTokenManagerService::GetPermissionsState(AccessTokenID toke { int32_t apiVersion = 0; if (!PermissionManager::GetInstance().GetApiVersionByTokenId(tokenID, apiVersion)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get api version error"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get api version error"); return INVALID_OPER; } - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d, apiVersion: %{public}d", tokenID, apiVersion); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}d, apiVersion: %{public}d", tokenID, apiVersion); bool needRes = false; std::vector permsList; int retUserGrant = PermissionManager::GetInstance().GetReqPermissions(tokenID, permsList, false); int retSysGrant = PermissionManager::GetInstance().GetReqPermissions(tokenID, permsList, true); if ((retSysGrant != RET_SUCCESS) || (retUserGrant != RET_SUCCESS)) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "GetReqPermissions failed, retUserGrant:%{public}d, retSysGrant:%{public}d", retUserGrant, retSysGrant); return INVALID_OPER; @@ -261,11 +258,11 @@ PermissionOper AccessTokenManagerService::GetPermissionsState(AccessTokenID toke if (static_cast(reqPermList[i].permsState.state) == DYNAMIC_OPER) { needRes = true; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Perm: %{public}s, state: %{public}d", + LOGD(ATM_DOMAIN, ATM_TAG, "Perm: %{public}s, state: %{public}d", reqPermList[i].permsState.permissionName.c_str(), reqPermList[i].permsState.state); } if (GetTokenType(tokenID) == TOKEN_HAP && AccessTokenInfoManager::GetInstance().GetPermDialogCap(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID=%{public}d is under control", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id=%{public}d is under control", tokenID); uint32_t size = reqPermList.size(); for (uint32_t i = 0; i < size; i++) { if (reqPermList[i].permsState.state != INVALID_OPER) { @@ -322,7 +319,7 @@ int AccessTokenManagerService::GrantPermissionForSpecifiedTime( int AccessTokenManagerService::ClearUserGrantedPermissionState(AccessTokenID tokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}d", tokenID); AccessTokenInfoManager::GetInstance().ClearUserGrantedPermissionState(tokenID); AccessTokenInfoManager::GetInstance().SetPermDialogCap(tokenID, false); return RET_SUCCESS; @@ -352,14 +349,14 @@ int32_t AccessTokenManagerService::UnRegisterSelfPermStateChangeCallback(const s AccessTokenIDEx AccessTokenManagerService::AllocHapToken(const HapInfoParcel& info, const HapPolicyParcel& policy) { - ACCESSTOKEN_LOG_INFO(LABEL, "BundleName: %{public}s", info.hapInfoParameter.bundleName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "BundleName: %{public}s", info.hapInfoParameter.bundleName.c_str()); AccessTokenIDEx tokenIdEx; tokenIdEx.tokenIDEx = 0LL; int ret = AccessTokenInfoManager::GetInstance().CreateHapTokenInfo( info.hapInfoParameter, policy.hapPolicyParameter, tokenIdEx); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Hap token info create failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Hap token info create failed"); } return tokenIdEx; } @@ -367,7 +364,7 @@ AccessTokenIDEx AccessTokenManagerService::AllocHapToken(const HapInfoParcel& in int32_t AccessTokenManagerService::InitHapToken(const HapInfoParcel& info, HapPolicyParcel& policy, AccessTokenIDEx& fullTokenId, HapInfoCheckResult& result) { - ACCESSTOKEN_LOG_INFO(LABEL, "Init hap %{public}s.", info.hapInfoParameter.bundleName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Init hap %{public}s.", info.hapInfoParameter.bundleName.c_str()); std::vector initializedList; if (info.hapInfoParameter.dlpType == DLP_COMMON) { if (!PermissionManager::GetInstance().InitPermissionList(info.hapInfoParameter.appDistributionType, @@ -393,21 +390,21 @@ int32_t AccessTokenManagerService::InitHapToken(const HapInfoParcel& info, HapPo int AccessTokenManagerService::DeleteToken(AccessTokenID tokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}d", tokenID); // only support hap token deletion return AccessTokenInfoManager::GetInstance().RemoveHapTokenInfo(tokenID); } int AccessTokenManagerService::GetTokenType(AccessTokenID tokenID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID: %{public}d", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id: %{public}d", tokenID); return AccessTokenIDManager::GetInstance().GetTokenIdType(tokenID); } AccessTokenIDEx AccessTokenManagerService::GetHapTokenID( int32_t userID, const std::string& bundleName, int32_t instIndex) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "UserID: %{public}d, bundle: %{public}s, instIndex: %{public}d", + LOGD(ATM_DOMAIN, ATM_TAG, "UserID: %{public}d, bundle: %{public}s, instIndex: %{public}d", userID, bundleName.c_str(), instIndex); return AccessTokenInfoManager::GetInstance().GetHapTokenID(userID, bundleName, instIndex); } @@ -415,7 +412,7 @@ AccessTokenIDEx AccessTokenManagerService::GetHapTokenID( AccessTokenID AccessTokenManagerService::AllocLocalTokenID( const std::string& remoteDeviceID, AccessTokenID remoteTokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "RemoteDeviceID: %{public}s, remoteTokenID: %{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "RemoteDeviceID: %{public}s, remoteTokenID: %{public}d", ConstantCommon::EncryptDevId(remoteDeviceID).c_str(), remoteTokenID); AccessTokenID tokenID = AccessTokenInfoManager::GetInstance().AllocLocalTokenID(remoteDeviceID, remoteTokenID); return tokenID; @@ -424,7 +421,7 @@ AccessTokenID AccessTokenManagerService::AllocLocalTokenID( int32_t AccessTokenManagerService::UpdateHapToken(AccessTokenIDEx& tokenIdEx, const UpdateHapInfoParams& info, const HapPolicyParcel& policyParcel, HapInfoCheckResult& result) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d", tokenIdEx.tokenIdExStruct.tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "Id: %{public}d", tokenIdEx.tokenIdExStruct.tokenID); std::vector InitializedList; if (!PermissionManager::GetInstance().InitPermissionList( info.appDistributionType, policyParcel.hapPolicyParameter, InitializedList, result)) { @@ -437,7 +434,7 @@ int32_t AccessTokenManagerService::UpdateHapToken(AccessTokenIDEx& tokenIdEx, co int AccessTokenManagerService::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfoParcel& infoParcel) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID: %{public}d", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id: %{public}d", tokenID); return AccessTokenInfoManager::GetInstance().GetHapTokenInfo(tokenID, infoParcel.hapTokenInfoParams); } @@ -445,10 +442,10 @@ int AccessTokenManagerService::GetHapTokenInfo(AccessTokenID tokenID, HapTokenIn int AccessTokenManagerService::GetHapTokenInfoExtension(AccessTokenID tokenID, HapTokenInfoParcel& hapTokenInfoRes, std::string& appID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID: %{public}d.", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id: %{public}d.", tokenID); int ret = AccessTokenInfoManager::GetInstance().GetHapTokenInfo(tokenID, hapTokenInfoRes.hapTokenInfoParams); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get hap token info extenstion failed, ret is %{public}d.", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Get hap token info extenstion failed, ret is %{public}d.", ret); return ret; } @@ -457,7 +454,7 @@ int AccessTokenManagerService::GetHapTokenInfoExtension(AccessTokenID tokenID, int AccessTokenManagerService::GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfoParcel& infoParcel) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenID: %{public}d", tokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Id: %{public}d", tokenID); NativeTokenInfoBase baseInfo; int32_t ret = AccessTokenInfoManager::GetInstance().GetNativeTokenInfo(tokenID, baseInfo); infoParcel.nativeTokenInfoParams.apl = baseInfo.apl; @@ -482,7 +479,7 @@ AccessTokenID AccessTokenManagerService::GetNativeTokenId(const std::string& pro int AccessTokenManagerService::GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSyncParcel& hapSyncParcel) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d", tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID: %{public}d", tokenID); return AccessTokenInfoManager::GetInstance().GetHapTokenInfoFromRemote(tokenID, hapSyncParcel.hapTokenInfoForSyncParams); @@ -491,7 +488,7 @@ int AccessTokenManagerService::GetHapTokenInfoFromRemote(AccessTokenID tokenID, int AccessTokenManagerService::SetRemoteHapTokenInfo(const std::string& deviceID, HapTokenInfoForSyncParcel& hapSyncParcel) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeviceID: %{public}s", ConstantCommon::EncryptDevId(deviceID).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "DeviceID: %{public}s", ConstantCommon::EncryptDevId(deviceID).c_str()); int ret = AccessTokenInfoManager::GetInstance().SetRemoteHapTokenInfo(deviceID, hapSyncParcel.hapTokenInfoForSyncParams); return ret; @@ -499,7 +496,7 @@ int AccessTokenManagerService::SetRemoteHapTokenInfo(const std::string& deviceID int AccessTokenManagerService::DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeviceID: %{public}s, token id %{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "DeviceID: %{public}s, token id %{public}d", ConstantCommon::EncryptDevId(deviceID).c_str(), tokenID); return AccessTokenInfoManager::GetInstance().DeleteRemoteToken(deviceID, tokenID); } @@ -507,7 +504,7 @@ int AccessTokenManagerService::DeleteRemoteToken(const std::string& deviceID, Ac AccessTokenID AccessTokenManagerService::GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeviceID: %{public}s, token id %{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "DeviceID: %{public}s, token id %{public}d", ConstantCommon::EncryptDevId(deviceID).c_str(), tokenID); return AccessTokenInfoManager::GetInstance().GetRemoteNativeTokenID(deviceID, tokenID); @@ -515,33 +512,33 @@ AccessTokenID AccessTokenManagerService::GetRemoteNativeTokenID(const std::strin int AccessTokenManagerService::DeleteRemoteDeviceTokens(const std::string& deviceID) { - ACCESSTOKEN_LOG_INFO(LABEL, "DeviceID: %{public}s", ConstantCommon::EncryptDevId(deviceID).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "DeviceID: %{public}s", ConstantCommon::EncryptDevId(deviceID).c_str()); return AccessTokenInfoManager::GetInstance().DeleteRemoteDeviceTokens(deviceID); } int32_t AccessTokenManagerService::RegisterTokenSyncCallback(const sptr& callback) { - ACCESSTOKEN_LOG_INFO(LABEL, "Call token sync callback registed."); + LOGI(ATM_DOMAIN, ATM_TAG, "Call token sync callback registed."); return TokenModifyNotifier::GetInstance().RegisterTokenSyncCallback(callback); } int32_t AccessTokenManagerService::UnRegisterTokenSyncCallback() { - ACCESSTOKEN_LOG_INFO(LABEL, "Call token sync callback unregisted."); + LOGI(ATM_DOMAIN, ATM_TAG, "Call token sync callback unregisted."); return TokenModifyNotifier::GetInstance().UnRegisterTokenSyncCallback(); } #endif void AccessTokenManagerService::DumpTokenInfo(const AtmToolsParamInfoParcel& infoParcel, std::string& dumpInfo) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called"); AccessTokenInfoManager::GetInstance().DumpTokenInfo(infoParcel.info, dumpInfo); } int32_t AccessTokenManagerService::GetVersion(uint32_t& version) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called"); version = DEFAULT_TOKEN_VERSION; return RET_SUCCESS; } @@ -625,13 +622,13 @@ void AccessTokenManagerService::AccessTokenServiceParamSet() const { int32_t res = SetParameter(ACCESS_TOKEN_SERVICE_INIT_KEY, std::to_string(1).c_str()); if (res != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SetParameter ACCESS_TOKEN_SERVICE_INIT_KEY 1 failed %{public}d", res); + LOGE(ATM_DOMAIN, ATM_TAG, "SetParameter 1 failed %{public}d", res); return; } // 2 is to tell others sa that at service is loaded. res = SetParameter(ACCESS_TOKEN_SERVICE_INIT_KEY, std::to_string(2).c_str()); if (res != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SetParameter ACCESS_TOKEN_SERVICE_INIT_KEY 2 failed %{public}d", res); + LOGE(ATM_DOMAIN, ATM_TAG, "SetParameter 2 failed %{public}d", res); return; } } @@ -641,7 +638,7 @@ void AccessTokenManagerService::GetConfigValue() LibraryLoader loader(CONFIG_POLICY_LIBPATH); ConfigPolicyLoaderInterface* policy = loader.GetObject(); if (policy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Dlopen libaccesstoken_config_policy failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Dlopen libaccesstoken_config_policy failed."); return; } AccessTokenConfigValue value; @@ -658,7 +655,7 @@ void AccessTokenManagerService::GetConfigValue() globalSwitchAbilityName_ = value.atConfig.globalSwitchAbilityName.empty() ? GLOBAL_SWITCH_SHEET_ABILITY_NAME : value.atConfig.globalSwitchAbilityName; } else { - ACCESSTOKEN_LOG_INFO(LABEL, "No config file or config file is not valid, use default values"); + LOGI(ATM_DOMAIN, ATM_TAG, "No config file or config file is not valid, use default values"); grantBundleName_ = GRANT_ABILITY_BUNDLE_NAME; grantAbilityName_ = GRANT_ABILITY_ABILITY_NAME; grantServiceAbilityName_ = GRANT_ABILITY_ABILITY_NAME; @@ -666,7 +663,7 @@ void AccessTokenManagerService::GetConfigValue() globalSwitchAbilityName_ = GLOBAL_SWITCH_SHEET_ABILITY_NAME; } - ACCESSTOKEN_LOG_INFO(LABEL, "GrantBundleName_ is %{public}s, grantAbilityName_ is %{public}s, \ + LOGI(ATM_DOMAIN, ATM_TAG, "GrantBundleName_ is %{public}s, grantAbilityName_ is %{public}s, \ permStateAbilityName_ is %{public}s, permStateAbilityName_ is %{public}s", grantBundleName_.c_str(), grantAbilityName_.c_str(), permStateAbilityName_.c_str(), permStateAbilityName_.c_str()); @@ -690,7 +687,7 @@ bool AccessTokenManagerService::Initialize() PermissionDefinitionParser::GetInstance().Init(); GetConfigValue(); TempPermissionObserver::GetInstance().GetConfigValue(); - ACCESSTOKEN_LOG_INFO(LABEL, "Initialize success"); + LOGI(ATM_DOMAIN, ATM_TAG, "Initialize success"); return true; } } // namespace AccessToken diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp index 4cdb076f0aadd731319c35f40f835d5dc2b1273b..a8df07f473e0213c798f9f12908d919a5988ce06 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp @@ -31,16 +31,15 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "ATMStub"}; -const std::string MANAGE_HAP_TOKENID_PERMISSION = "ohos.permission.MANAGE_HAP_TOKENID"; +constexpr const char* MANAGE_HAP_TOKENID_PERMISSION = "ohos.permission.MANAGE_HAP_TOKENID"; static const int32_t DUMP_CAPACITY_SIZE = 2 * 1024 * 1000; static const int MAX_PERMISSION_SIZE = 1000; static const int32_t MAX_USER_POLICY_SIZE = 1024; -const std::string GRANT_SENSITIVE_PERMISSIONS = "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"; -const std::string REVOKE_SENSITIVE_PERMISSIONS = "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"; -const std::string GET_SENSITIVE_PERMISSIONS = "ohos.permission.GET_SENSITIVE_PERMISSIONS"; -const std::string DISABLE_PERMISSION_DIALOG = "ohos.permission.DISABLE_PERMISSION_DIALOG"; -const std::string GRANT_SHORT_TERM_WRITE_MEDIAVIDEO = "ohos.permission.GRANT_SHORT_TERM_WRITE_MEDIAVIDEO"; +constexpr const char* GRANT_SENSITIVE_PERMISSIONS = "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"; +constexpr const char* REVOKE_SENSITIVE_PERMISSIONS = "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"; +constexpr const char* GET_SENSITIVE_PERMISSIONS = "ohos.permission.GET_SENSITIVE_PERMISSIONS"; +constexpr const char* DISABLE_PERMISSION_DIALOG = "ohos.permission.DISABLE_PERMISSION_DIALOG"; +constexpr const char* GRANT_SHORT_TERM_WRITE_MEDIAVIDEO = "ohos.permission.GRANT_SHORT_TERM_WRITE_MEDIAVIDEO"; #ifdef HICOLLIE_ENABLE constexpr uint32_t TIMEOUT = 40; // 40s @@ -53,10 +52,10 @@ int32_t AccessTokenManagerStub::OnRemoteRequest( MemoryGuard guard; uint32_t callingTokenID = IPCSkeleton::GetCallingTokenID(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Code %{public}u token %{public}u", code, callingTokenID); + LOGD(ATM_DOMAIN, ATM_TAG, "Code %{public}u id %{public}u", code, callingTokenID); std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != IAccessTokenManager::GetDescriptor()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); return ERROR_IPC_REQUEST_FAIL; } @@ -92,42 +91,44 @@ void AccessTokenManagerStub::DeleteTokenInfoInner(MessageParcel& data, MessagePa AccessTokenID callingTokenID = IPCSkeleton::GetCallingTokenID(); if (!IsPrivilegedCalling() && (VerifyAccessToken(callingTokenID, MANAGE_HAP_TOKENID_PERMISSION) == PERMISSION_DENIED)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(Id=%{public}d)", callingTokenID); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, + reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } AccessTokenID tokenID = data.ReadUint32(); int result = this->DeleteToken(tokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::GetPermissionUsedTypeInner(MessageParcel& data, MessageParcel& reply) { if (!IsNativeProcessCalling() && !IsPrivilegedCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, + "Permission denied(PRI_DOMAIN, PRI_TAG=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(static_cast(PermUsedTypeEnum::INVALID_USED_TYPE)), "WriteInt32 failed."); return; } uint32_t tokenID; if (!data.ReadUint32(tokenID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read tokenID."); - IF_FALSE_PRINT_LOG(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to read tokenID."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(static_cast(PermUsedTypeEnum::INVALID_USED_TYPE)), "WriteInt32 failed."); return; } std::string permissionName; if (!data.ReadString(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read permissionName."); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32( + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to read permissionName."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32( static_cast(PermUsedTypeEnum::INVALID_USED_TYPE)), "WriteInt32 failed."); return; } PermUsedTypeEnum result = this->GetPermissionUsedType(tokenID, permissionName); int32_t type = static_cast(result); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(type), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(type), "WriteInt32 failed."); } void AccessTokenManagerStub::VerifyAccessTokenInner(MessageParcel& data, MessageParcel& reply) @@ -135,7 +136,7 @@ void AccessTokenManagerStub::VerifyAccessTokenInner(MessageParcel& data, Message AccessTokenID tokenID = data.ReadUint32(); std::string permissionName = data.ReadString(); int result = this->VerifyAccessToken(tokenID, permissionName); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::VerifyAccessTokenWithListInner(MessageParcel& data, MessageParcel& reply) @@ -157,11 +158,12 @@ void AccessTokenManagerStub::GetDefPermissionInner(MessageParcel& data, MessageP std::string permissionName = data.ReadString(); PermissionDefParcel permissionDefParcel; int result = this->GetDefPermission(permissionName, permissionDefParcel); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - IF_FALSE_PRINT_LOG(LABEL, reply.WriteParcelable(&permissionDefParcel), "Write PermissionDefParcel fail."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, + reply.WriteParcelable(&permissionDefParcel), "Write PermissionDefParcel fail."); } void AccessTokenManagerStub::GetDefPermissionsInner(MessageParcel& data, MessageParcel& reply) @@ -170,12 +172,13 @@ void AccessTokenManagerStub::GetDefPermissionsInner(MessageParcel& data, Message std::vector permList; this->GetDefPermissions(tokenID, permList); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(RET_SUCCESS), "WriteInt32 failed."); - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, permList size: %{public}zu", __func__, permList.size()); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteUint32(permList.size()), "WriteUint32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(RET_SUCCESS), "WriteInt32 failed."); + LOGD(ATM_DOMAIN, ATM_TAG, "PermList size: %{public}zu", permList.size()); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteUint32(permList.size()), "WriteUint32 failed."); for (const auto& permDef : permList) { - IF_FALSE_RETURN_LOG(LABEL, reply.WriteParcelable(&permDef), "WriteParcelable fail."); + IF_FALSE_RETURN_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&permDef), "WriteParcelable fail."); } } @@ -186,14 +189,15 @@ void AccessTokenManagerStub::GetReqPermissionsInner(MessageParcel& data, Message std::vector permList; int result = this->GetReqPermissions(tokenID, permList, isSystemGrant); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermList size: %{public}zu", permList.size()); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(permList.size()), "WriteInt32 failed."); + LOGD(ATM_DOMAIN, ATM_TAG, "PermList size: %{public}zu", permList.size()); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(permList.size()), "WriteInt32 failed."); for (const auto& permDef : permList) { - IF_FALSE_RETURN_LOG(LABEL, reply.WriteParcelable(&permDef), "WriteParcelable fail."); + IF_FALSE_RETURN_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&permDef), "WriteParcelable fail."); } } @@ -202,13 +206,13 @@ void AccessTokenManagerStub::GetSelfPermissionsStateInner(MessageParcel& data, M std::vector permList; uint32_t size = 0; if (!data.ReadUint32(size)) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(INVALID_OPER), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(INVALID_OPER), "WriteInt32 failed."); return; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermList size read from client data is %{public}d.", size); + LOGD(ATM_DOMAIN, ATM_TAG, "PermList size read from client data is %{public}d.", size); if (size > MAX_PERMISSION_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermList size %{public}d is invalid", size); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(INVALID_OPER), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "PermList size %{public}d is invalid", size); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(INVALID_OPER), "WriteInt32 failed."); return; } for (uint32_t i = 0; i < size; i++) { @@ -219,26 +223,30 @@ void AccessTokenManagerStub::GetSelfPermissionsStateInner(MessageParcel& data, M } PermissionGrantInfoParcel infoParcel; PermissionOper result = this->GetSelfPermissionsState(permList, infoParcel); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteUint32(permList.size()), "WriteUint32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteUint32(permList.size()), "WriteUint32 failed."); for (const auto& perm : permList) { - IF_FALSE_RETURN_LOG(LABEL, reply.WriteParcelable(&perm), "WriteParcelable failed."); + IF_FALSE_RETURN_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&perm), "WriteParcelable failed."); } - IF_FALSE_PRINT_LOG(LABEL, reply.WriteParcelable(&infoParcel), "WriteParcelable failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&infoParcel), "WriteParcelable failed."); } void AccessTokenManagerStub::GetPermissionsStatusInner(MessageParcel& data, MessageParcel& reply) { unsigned int callingTokenID = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingTokenID) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } if (!IsPrivilegedCalling() && VerifyAccessToken(callingTokenID, GET_SENSITIVE_PERMISSIONS) == PERMISSION_DENIED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingTokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } @@ -246,13 +254,13 @@ void AccessTokenManagerStub::GetPermissionsStatusInner(MessageParcel& data, Mess std::vector permList; uint32_t size = 0; if (!data.ReadUint32(size)) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(INVALID_OPER), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(INVALID_OPER), "WriteInt32 failed."); return; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "PermList size read from client data is %{public}d.", size); + LOGD(ATM_DOMAIN, ATM_TAG, "PermList size read from client data is %{public}d.", size); if (size > MAX_PERMISSION_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermList size %{public}d is oversize", size); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(INVALID_OPER), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "PermList size %{public}d is oversize", size); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(INVALID_OPER), "WriteInt32 failed."); return; } for (uint32_t i = 0; i < size; i++) { @@ -263,13 +271,14 @@ void AccessTokenManagerStub::GetPermissionsStatusInner(MessageParcel& data, Mess } int32_t result = this->GetPermissionsStatus(tokenID, permList); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - IF_FALSE_RETURN_LOG(LABEL, reply.WriteUint32(permList.size()), "WriteUint32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteUint32(permList.size()), "WriteUint32 failed."); for (const auto& perm : permList) { - IF_FALSE_RETURN_LOG(LABEL, reply.WriteParcelable(&perm), "WriteParcelable failed."); + IF_FALSE_RETURN_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&perm), "WriteParcelable failed."); } } @@ -277,7 +286,8 @@ void AccessTokenManagerStub::GetPermissionFlagInner(MessageParcel& data, Message { unsigned int callingTokenID = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingTokenID) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } AccessTokenID tokenID = data.ReadUint32(); @@ -286,25 +296,27 @@ void AccessTokenManagerStub::GetPermissionFlagInner(MessageParcel& data, Message VerifyAccessToken(callingTokenID, GRANT_SENSITIVE_PERMISSIONS) == PERMISSION_DENIED && VerifyAccessToken(callingTokenID, REVOKE_SENSITIVE_PERMISSIONS) == PERMISSION_DENIED && VerifyAccessToken(callingTokenID, GET_SENSITIVE_PERMISSIONS) == PERMISSION_DENIED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingTokenID); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, + reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } uint32_t flag; int result = this->GetPermissionFlag(tokenID, permissionName, flag); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - IF_FALSE_PRINT_LOG(LABEL, reply.WriteUint32(flag), "WriteUint32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteUint32(flag), "WriteUint32 failed."); } void AccessTokenManagerStub::SetPermissionRequestToggleStatusInner(MessageParcel& data, MessageParcel& reply) { uint32_t callingTokenID = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingTokenID) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } @@ -315,19 +327,21 @@ void AccessTokenManagerStub::SetPermissionRequestToggleStatusInner(MessageParcel HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_VERIFY_REPORT", HiviewDFX::HiSysEvent::EventType::SECURITY, "CODE", VERIFY_PERMISSION_ERROR, "CALLER_TOKENID", callingTokenID, "PERMISSION_NAME", permissionName, "INTERFACE", "SetToggleStatus"); - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d).", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d).", callingTokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } int32_t result = this->SetPermissionRequestToggleStatus(permissionName, status, userID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::GetPermissionRequestToggleStatusInner(MessageParcel& data, MessageParcel& reply) { uint32_t callingTokenID = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingTokenID) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } @@ -338,24 +352,26 @@ void AccessTokenManagerStub::GetPermissionRequestToggleStatusInner(MessageParcel HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_VERIFY_REPORT", HiviewDFX::HiSysEvent::EventType::SECURITY, "CODE", VERIFY_PERMISSION_ERROR, "CALLER_TOKENID", callingTokenID, "PERMISSION_NAME", permissionName, "INTERFACE", "GetToggleStatus"); - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d).", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d).", callingTokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } uint32_t status; int32_t result = this->GetPermissionRequestToggleStatus(permissionName, status, userID); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(status), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(status), "WriteInt32 failed."); } void AccessTokenManagerStub::GrantPermissionInner(MessageParcel& data, MessageParcel& reply) { unsigned int callingTokenID = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingTokenID) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } AccessTokenID tokenID = data.ReadUint32(); @@ -366,19 +382,21 @@ void AccessTokenManagerStub::GrantPermissionInner(MessageParcel& data, MessagePa HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_VERIFY_REPORT", HiviewDFX::HiSysEvent::EventType::SECURITY, "CODE", VERIFY_PERMISSION_ERROR, "CALLER_TOKENID", callingTokenID, "PERMISSION_NAME", permissionName); - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingTokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } int result = this->GrantPermission(tokenID, permissionName, flag); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::RevokePermissionInner(MessageParcel& data, MessageParcel& reply) { unsigned int callingTokenID = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingTokenID) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } AccessTokenID tokenID = data.ReadUint32(); @@ -389,19 +407,21 @@ void AccessTokenManagerStub::RevokePermissionInner(MessageParcel& data, MessageP HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_VERIFY_REPORT", HiviewDFX::HiSysEvent::EventType::SECURITY, "CODE", VERIFY_PERMISSION_ERROR, "CALLER_TOKENID", callingTokenID, "PERMISSION_NAME", permissionName); - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingTokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } int result = this->RevokePermission(tokenID, permissionName, flag); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::GrantPermissionForSpecifiedTimeInner(MessageParcel& data, MessageParcel& reply) { unsigned int callingTokenID = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingTokenID) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } AccessTokenID tokenID = data.ReadUint32(); @@ -412,12 +432,13 @@ void AccessTokenManagerStub::GrantPermissionForSpecifiedTimeInner(MessageParcel& HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_VERIFY_REPORT", HiviewDFX::HiSysEvent::EventType::SECURITY, "CODE", VERIFY_PERMISSION_ERROR, "CALLER_TOKENID", callingTokenID, "PERMISSION_NAME", permissionName); - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingTokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } int result = this->GrantPermissionForSpecifiedTime(tokenID, permissionName, onceTime); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::ClearUserGrantedPermissionStateInner(MessageParcel& data, MessageParcel& reply) @@ -428,13 +449,14 @@ void AccessTokenManagerStub::ClearUserGrantedPermissionStateInner(MessageParcel& HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_VERIFY_REPORT", HiviewDFX::HiSysEvent::EventType::SECURITY, "CODE", VERIFY_PERMISSION_ERROR, "CALLER_TOKENID", callingTokenID); - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingTokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } AccessTokenID tokenID = data.ReadUint32(); int result = this->ClearUserGrantedPermissionState(tokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::AllocHapTokenInner(MessageParcel& data, MessageParcel& reply) @@ -443,16 +465,18 @@ void AccessTokenManagerStub::AllocHapTokenInner(MessageParcel& data, MessageParc AccessTokenID tokenID = IPCSkeleton::GetCallingTokenID(); if (!IsPrivilegedCalling() && (VerifyAccessToken(tokenID, MANAGE_HAP_TOKENID_PERMISSION) == PERMISSION_DENIED)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", tokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", tokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } sptr hapInfoParcel = data.ReadParcelable(); sptr hapPolicyParcel = data.ReadParcelable(); if (hapInfoParcel == nullptr || hapPolicyParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read hapPolicyParcel or hapInfoParcel fail"); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Read hapPolicyParcel or hapInfoParcel fail"); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } res = this->AllocHapToken(*hapInfoParcel, *hapPolicyParcel); @@ -464,16 +488,18 @@ void AccessTokenManagerStub::InitHapTokenInner(MessageParcel& data, MessageParce AccessTokenID tokenID = IPCSkeleton::GetCallingTokenID(); if (!IsPrivilegedCalling() && (VerifyAccessToken(tokenID, MANAGE_HAP_TOKENID_PERMISSION) == PERMISSION_DENIED)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", tokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", tokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } sptr hapInfoParcel = data.ReadParcelable(); sptr hapPolicyParcel = data.ReadParcelable(); if (hapInfoParcel == nullptr || hapPolicyParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read hapPolicyParcel or hapInfoParcel fail"); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Read hapPolicyParcel or hapInfoParcel fail"); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } int32_t res; @@ -481,7 +507,7 @@ void AccessTokenManagerStub::InitHapTokenInner(MessageParcel& data, MessageParce HapInfoCheckResult result; res = this->InitHapToken(*hapInfoParcel, *hapPolicyParcel, fullTokenId, result); if (!reply.WriteInt32(res)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 fail"); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 fail"); } if (res != RET_SUCCESS) { @@ -491,44 +517,48 @@ void AccessTokenManagerStub::InitHapTokenInner(MessageParcel& data, MessageParce IF_FALSE_RETURN_LOG( LABEL, reply.WriteInt32(result.permCheckResult.rule), "WriteInt32 failed."); } - ACCESSTOKEN_LOG_ERROR(LABEL, "Res error %{public}d.", res); + LOGE(ATM_DOMAIN, ATM_TAG, "Res error %{public}d.", res); return; } - IF_FALSE_PRINT_LOG(LABEL, reply.WriteUint64(fullTokenId.tokenIDEx), "WriteUint64 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteUint64(fullTokenId.tokenIDEx), "WriteUint64 failed."); } void AccessTokenManagerStub::GetTokenTypeInner(MessageParcel& data, MessageParcel& reply) { AccessTokenID tokenID = data.ReadUint32(); int result = this->GetTokenType(tokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::GetHapTokenIDInner(MessageParcel& data, MessageParcel& reply) { if (!IsNativeProcessCalling() && !IsPrivilegedCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(INVALID_TOKENID), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(INVALID_TOKENID), "WriteInt32 failed."); return; } int userID = data.ReadInt32(); std::string bundleName = data.ReadString(); int instIndex = data.ReadInt32(); AccessTokenIDEx tokenIdEx = this->GetHapTokenID(userID, bundleName, instIndex); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteUint64(tokenIdEx.tokenIDEx), "WriteUint64 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteUint64(tokenIdEx.tokenIDEx), "WriteUint64 failed."); } void AccessTokenManagerStub::AllocLocalTokenIDInner(MessageParcel& data, MessageParcel& reply) { if ((!IsNativeProcessCalling()) && !IsPrivilegedCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(INVALID_TOKENID), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(INVALID_TOKENID), "WriteInt32 failed."); return; } std::string remoteDeviceID = data.ReadString(); AccessTokenID remoteTokenID = data.ReadUint32(); AccessTokenID result = this->AllocLocalTokenID(remoteDeviceID, remoteTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteUint32(result), "WriteUint32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteUint32(result), "WriteUint32 failed."); } void AccessTokenManagerStub::UpdateHapTokenInner(MessageParcel& data, MessageParcel& reply) @@ -536,8 +566,9 @@ void AccessTokenManagerStub::UpdateHapTokenInner(MessageParcel& data, MessagePar AccessTokenID callingTokenID = IPCSkeleton::GetCallingTokenID(); if (!IsPrivilegedCalling() && (VerifyAccessToken(callingTokenID, MANAGE_HAP_TOKENID_PERMISSION) == PERMISSION_DENIED)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingTokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } UpdateHapInfoParams info; @@ -550,20 +581,22 @@ void AccessTokenManagerStub::UpdateHapTokenInner(MessageParcel& data, MessagePar tokenIdEx.tokenIdExStruct.tokenID = tokenID; sptr policyParcel = data.ReadParcelable(); if (policyParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PolicyParcel read faild"); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "PolicyParcel read faild"); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } + HapInfoCheckResult resultInfo; int32_t result = this->UpdateHapToken(tokenIdEx, info, *policyParcel, resultInfo); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteUint32(tokenIdEx.tokenIdExStruct.tokenAttr), "WriteUint32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteUint32(tokenIdEx.tokenIdExStruct.tokenAttr), "WriteUint32 failed."); if (result != RET_SUCCESS) { if (!resultInfo.permCheckResult.permissionName.empty()) { IF_FALSE_RETURN_LOG( - LABEL, reply.WriteString(resultInfo.permCheckResult.permissionName), "WriteString failed."); + ATM_DOMAIN, ATM_TAG, reply.WriteString(resultInfo.permCheckResult.permissionName), "WriteString failed."); IF_FALSE_RETURN_LOG( - LABEL, reply.WriteInt32(resultInfo.permCheckResult.rule), "WriteInt32 failed."); + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(resultInfo.permCheckResult.rule), "WriteInt32 failed."); } ACCESSTOKEN_LOG_ERROR(LABEL, "Res error %{public}d", result); return; @@ -573,104 +606,117 @@ void AccessTokenManagerStub::UpdateHapTokenInner(MessageParcel& data, MessagePar void AccessTokenManagerStub::GetHapTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsNativeProcessCalling() && !IsPrivilegedCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } HapTokenInfoParcel hapTokenInfoParcel; AccessTokenID tokenID = data.ReadUint32(); int result = this->GetHapTokenInfo(tokenID, hapTokenInfoParcel); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - IF_FALSE_PRINT_LOG(LABEL, reply.WriteParcelable(&hapTokenInfoParcel), "Write parcel failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&hapTokenInfoParcel), "Write parcel failed."); } void AccessTokenManagerStub::GetHapTokenInfoExtensionInner(MessageParcel& data, MessageParcel& reply) { if (!IsNativeProcessCalling() && !IsPrivilegedCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } HapTokenInfoParcel hapTokenInfoParcel; std::string appID; AccessTokenID tokenID = data.ReadUint32(); int result = this->GetHapTokenInfoExtension(tokenID, hapTokenInfoParcel, appID); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - IF_FALSE_RETURN_LOG(LABEL, reply.WriteParcelable(&hapTokenInfoParcel), "Write parcel failed."); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteString(appID), "Write string failed."); + IF_FALSE_RETURN_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&hapTokenInfoParcel), "Write parcel failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteString(appID), "Write string failed."); } void AccessTokenManagerStub::GetNativeTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsNativeProcessCalling() && !IsPrivilegedCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d).", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } AccessTokenID tokenID = data.ReadUint32(); NativeTokenInfoParcel nativeTokenInfoParcel; int result = this->GetNativeTokenInfo(tokenID, nativeTokenInfoParcel); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - IF_FALSE_PRINT_LOG(LABEL, reply.WriteParcelable(&nativeTokenInfoParcel), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&nativeTokenInfoParcel), "WriteInt32 failed."); } void AccessTokenManagerStub::RegisterPermStateChangeCallbackInner(MessageParcel& data, MessageParcel& reply) { uint32_t callingTokenID = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingTokenID) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } if (VerifyAccessToken(callingTokenID, GET_SENSITIVE_PERMISSIONS) == PERMISSION_DENIED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingTokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingTokenID); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } sptr scopeParcel = data.ReadParcelable(); if (scopeParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read scopeParcel fail"); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Read scopeParcel fail"); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } sptr callback = data.ReadRemoteObject(); if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read callback fail"); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Read callback fail"); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } int32_t result = this->RegisterPermStateChangeCallback(*scopeParcel, callback); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::UnRegisterPermStateChangeCallbackInner(MessageParcel& data, MessageParcel& reply) { uint32_t callingToken = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingToken) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } if (VerifyAccessToken(callingToken, GET_SENSITIVE_PERMISSIONS) == PERMISSION_DENIED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingToken); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingToken); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } sptr callback = data.ReadRemoteObject(); if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read callback fail"); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Read callback fail"); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } int32_t result = this->UnRegisterPermStateChangeCallback(callback); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::RegisterSelfPermStateChangeCallbackInner(MessageParcel& data, MessageParcel& reply) @@ -719,137 +765,149 @@ void AccessTokenManagerStub::UnRegisterSelfPermStateChangeCallbackInner(MessageP void AccessTokenManagerStub::ReloadNativeTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsPrivilegedCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteUint32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteUint32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } int32_t result = this->ReloadNativeTokenInfo(); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } #endif void AccessTokenManagerStub::GetNativeTokenIdInner(MessageParcel& data, MessageParcel& reply) { if (!IsNativeProcessCalling() && !IsPrivilegedCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteUint32(INVALID_TOKENID), "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteUint32(INVALID_TOKENID), "WriteUint32 failed."); return; } std::string processName; if (!data.ReadString(processName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadString fail, processName=%{public}s", processName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadString fail, processName=%{public}s", processName.c_str()); return; } AccessTokenID result = this->GetNativeTokenId(processName); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } #ifdef TOKEN_SYNC_ENABLE void AccessTokenManagerStub::GetHapTokenInfoFromRemoteInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } AccessTokenID tokenID = data.ReadUint32(); HapTokenInfoForSyncParcel hapTokenParcel; int result = this->GetHapTokenInfoFromRemote(tokenID, hapTokenParcel); - IF_FALSE_RETURN_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_RETURN_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - IF_FALSE_PRINT_LOG(LABEL, reply.WriteParcelable(&hapTokenParcel), "WriteParcelable failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&hapTokenParcel), "WriteParcelable failed."); } void AccessTokenManagerStub::SetRemoteHapTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } std::string deviceID = data.ReadString(); sptr hapTokenParcel = data.ReadParcelable(); if (hapTokenParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "HapTokenParcel read faild"); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "HapTokenParcel read faild"); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } int result = this->SetRemoteHapTokenInfo(deviceID, *hapTokenParcel); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::DeleteRemoteTokenInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } std::string deviceID = data.ReadString(); AccessTokenID tokenID = data.ReadUint32(); int result = this->DeleteRemoteToken(deviceID, tokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::GetRemoteNativeTokenIDInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(INVALID_TOKENID), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(INVALID_TOKENID), "WriteInt32 failed."); return; } std::string deviceID = data.ReadString(); AccessTokenID tokenID = data.ReadUint32(); AccessTokenID result = this->GetRemoteNativeTokenID(deviceID, tokenID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::DeleteRemoteDeviceTokensInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } std::string deviceID = data.ReadString(); int result = this->DeleteRemoteDeviceTokens(deviceID); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::RegisterTokenSyncCallbackInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied, tokenID=%{public}d", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied, id=%{public}d", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } sptr callback = data.ReadRemoteObject(); if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback read failed."); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Callback read failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } int32_t result = this->RegisterTokenSyncCallback(callback); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } void AccessTokenManagerStub::UnRegisterTokenSyncCallbackInner(MessageParcel& data, MessageParcel& reply) { if (!IsAccessTokenCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied, tokenID=%{public}d", IPCSkeleton::GetCallingTokenID()); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied, id=%{public}d", IPCSkeleton::GetCallingTokenID()); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } int32_t result = this->UnRegisterTokenSyncCallback(); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); } #endif @@ -857,38 +915,39 @@ void AccessTokenManagerStub::GetVersionInner(MessageParcel& data, MessageParcel& { uint32_t callingToken = IPCSkeleton::GetCallingTokenID(); if ((this->GetTokenType(callingToken) == TOKEN_HAP) && (!IsSystemAppCalling())) { - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_NOT_SYSTEM_APP), "WriteInt32 failed."); return; } uint32_t version; int32_t result = this->GetVersion(version); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(result), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(result), "WriteInt32 failed."); if (result != RET_SUCCESS) { return; } - IF_FALSE_PRINT_LOG(LABEL, reply.WriteUint32(version), "WriteUint32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteUint32(version), "WriteUint32 failed."); } void AccessTokenManagerStub::DumpTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsShellProcessCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", IPCSkeleton::GetCallingTokenID()); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", IPCSkeleton::GetCallingTokenID()); reply.WriteString(""); return; } sptr infoParcel = data.ReadParcelable(); if (infoParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read infoParcel fail"); + LOGE(ATM_DOMAIN, ATM_TAG, "Read infoParcel fail"); reply.WriteString("read infoParcel fail"); return; } std::string dumpInfo = ""; this->DumpTokenInfo(*infoParcel, dumpInfo); if (!reply.SetDataCapacity(DUMP_CAPACITY_SIZE)) { - ACCESSTOKEN_LOG_WARN(LABEL, "SetDataCapacity failed"); + LOGW(ATM_DOMAIN, ATM_TAG, "SetDataCapacity failed"); } if (!reply.WriteString(dumpInfo)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString failed"); } } @@ -896,35 +955,39 @@ void AccessTokenManagerStub::SetPermDialogCapInner(MessageParcel& data, MessageP { uint32_t callingToken = IPCSkeleton::GetCallingTokenID(); if (VerifyAccessToken(callingToken, DISABLE_PERMISSION_DIALOG) == PERMISSION_DENIED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingToken); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingToken); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } sptr hapBaseInfoParcel = data.ReadParcelable(); if (hapBaseInfoParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read hapBaseInfoParcel fail"); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Read hapBaseInfoParcel fail"); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } bool enable = data.ReadBool(); int32_t res = this->SetPermDialogCap(*hapBaseInfoParcel, enable); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(res), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(res), "WriteInt32 failed."); } void AccessTokenManagerStub::GetPermissionManagerInfoInner(MessageParcel& data, MessageParcel& reply) { PermissionGrantInfoParcel infoParcel; this->GetPermissionManagerInfo(infoParcel); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteParcelable(&infoParcel), "WriteParcelable failed."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteParcelable(&infoParcel), "WriteParcelable failed."); } void AccessTokenManagerStub::InitUserPolicyInner(MessageParcel& data, MessageParcel& reply) { uint32_t callingToken = IPCSkeleton::GetCallingTokenID(); if (VerifyAccessToken(callingToken, GET_SENSITIVE_PERMISSIONS) == PERMISSION_DENIED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingToken); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingToken); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } std::vector userList; @@ -932,20 +995,23 @@ void AccessTokenManagerStub::InitUserPolicyInner(MessageParcel& data, MessagePar uint32_t userSize = data.ReadUint32(); uint32_t permSize = data.ReadUint32(); if ((userSize > MAX_USER_POLICY_SIZE) || (permSize > MAX_USER_POLICY_SIZE)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Size %{public}u is invalid", userSize); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_OVERSIZE), "WriteParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Size %{public}u is invalid", userSize); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_OVERSIZE), "WriteParcelable failed."); return; } for (uint32_t i = 0; i < userSize; i++) { UserState userInfo; if (!data.ReadInt32(userInfo.userId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read userId."); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to read userId."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } if (!data.ReadBool(userInfo.isActive)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read isActive."); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to read isActive."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } userList.emplace_back(userInfo); @@ -953,60 +1019,65 @@ void AccessTokenManagerStub::InitUserPolicyInner(MessageParcel& data, MessagePar for (uint32_t i = 0; i < permSize; i++) { std::string permission; if (!data.ReadString(permission)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read permission."); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to read permission."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } permList.emplace_back(permission); } int32_t res = this->InitUserPolicy(userList, permList); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(res), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(res), "WriteInt32 failed."); } void AccessTokenManagerStub::UpdateUserPolicyInner(MessageParcel& data, MessageParcel& reply) { uint32_t callingToken = IPCSkeleton::GetCallingTokenID(); if (VerifyAccessToken(callingToken, GET_SENSITIVE_PERMISSIONS) == PERMISSION_DENIED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingToken); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingToken); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } std::vector userList; uint32_t userSize = data.ReadUint32(); if (userSize > MAX_USER_POLICY_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Size %{public}u is invalid", userSize); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_OVERSIZE), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Size %{public}u is invalid", userSize); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_OVERSIZE), "WriteInt32 failed."); return; } for (uint32_t i = 0; i < userSize; i++) { UserState userInfo; if (!data.ReadInt32(userInfo.userId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read userId."); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to read userId."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } if (!data.ReadBool(userInfo.isActive)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read isActive."); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to read isActive."); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_READ_PARCEL_FAILED), "WriteInt32 failed."); return; } userList.emplace_back(userInfo); } int32_t res = this->UpdateUserPolicy(userList); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(res), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(res), "WriteInt32 failed."); } void AccessTokenManagerStub::ClearUserPolicyInner(MessageParcel& data, MessageParcel& reply) { uint32_t callingToken = IPCSkeleton::GetCallingTokenID(); if (VerifyAccessToken(callingToken, GET_SENSITIVE_PERMISSIONS) == PERMISSION_DENIED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(tokenID=%{public}d)", callingToken); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(AccessTokenError::ERR_PERMISSION_DENIED), "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission denied(id=%{public}d)", callingToken); + IF_FALSE_PRINT_LOG( + ATM_DOMAIN, ATM_TAG, reply.WriteInt32(ERR_PERMISSION_DENIED), "WriteInt32 failed."); return; } int32_t res = this->ClearUserPolicy(); - IF_FALSE_PRINT_LOG(LABEL, reply.WriteInt32(res), "WriteInt32 failed."); + IF_FALSE_PRINT_LOG(ATM_DOMAIN, ATM_TAG, reply.WriteInt32(res), "WriteInt32 failed."); } bool AccessTokenManagerStub::IsPrivilegedCalling() const diff --git a/services/accesstokenmanager/main/cpp/src/token/accesstoken_id_manager.cpp b/services/accesstokenmanager/main/cpp/src/token/accesstoken_id_manager.cpp index 74acedbf83b2b43460dca44c635f480851b21f26..2c3c2ddefb60c79f56d46d8b6d202888bdb55aeb 100644 --- a/services/accesstokenmanager/main/cpp/src/token/accesstoken_id_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/accesstoken_id_manager.cpp @@ -25,7 +25,6 @@ namespace Security { namespace AccessToken { namespace { std::recursive_mutex g_instanceMutex; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenIDManager"}; } ATokenTypeEnum AccessTokenIDManager::GetTokenIdTypeEnum(AccessTokenID id) @@ -81,7 +80,7 @@ AccessTokenID AccessTokenIDManager::CreateTokenId(ATokenTypeEnum type, int32_t d { unsigned int rand = GetRandomUint32(); if (rand == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get random failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Get random failed"); return 0; } @@ -104,7 +103,7 @@ AccessTokenID AccessTokenIDManager::CreateAndRegisterTokenId(ATokenTypeEnum type for (int i = 0; i < MAX_CREATE_TOKEN_ID_RETRY; i++) { tokenId = CreateTokenId(type, dlpFlag, cloneFlag); if (tokenId == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Create tokenId failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Create tokenId failed"); return INVALID_TOKENID; } @@ -112,9 +111,10 @@ AccessTokenID AccessTokenIDManager::CreateAndRegisterTokenId(ATokenTypeEnum type if (ret == RET_SUCCESS) { break; } else if (i < MAX_CREATE_TOKEN_ID_RETRY - 1) { - ACCESSTOKEN_LOG_WARN(LABEL, "Reigster tokenId failed(error=%{public}d), maybe repeat, retry.", ret); + LOGW(ATM_DOMAIN, ATM_TAG, + "Reigster tokenId failed(error=%{public}d), maybe repeat, retry.", ret); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Reigster tokenId finally failed(error=%{public}d).", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Reigster tokenId finally failed(error=%{public}d).", ret); tokenId = INVALID_TOKENID; } } @@ -125,7 +125,7 @@ void AccessTokenIDManager::ReleaseTokenId(AccessTokenID id) { Utils::UniqueWriteGuard idGuard(this->tokenIdLock_); if (tokenIdSet_.count(id) == 0) { - ACCESSTOKEN_LOG_INFO(LABEL, "Id %{public}x is not exist", id); + LOGI(ATM_DOMAIN, ATM_TAG, "Id %{public}x is not exist", id); return; } tokenIdSet_.erase(id); diff --git a/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp b/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp index 44a156d3d3f60fd4cd2afe86c9a322f489fe4f42..7e334903f8c993eb5605e4bd7f1b6e25e8ee4304 100644 --- a/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp @@ -55,13 +55,12 @@ namespace Security { namespace AccessToken { namespace { std::recursive_mutex g_instanceMutex; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenInfoManager"}; static const unsigned int SYSTEM_APP_FLAG = 0x0001; #ifdef TOKEN_SYNC_ENABLE static const int MAX_PTHREAD_NAME_LEN = 15; // pthread name max length -static const std::string ACCESS_TOKEN_PACKAGE_NAME = "ohos.security.distributed_token_sync"; +constexpr const char* ACCESS_TOKEN_PACKAGE_NAME = "ohos.security.distributed_token_sync"; #endif -static const std::string DUMP_JSON_PATH = "/data/service/el1/public/access_token/nativetoken.log"; +constexpr const char* DUMP_JSON_PATH = "/data/service/el1/public/access_token/nativetoken.log"; } AccessTokenInfoManager::AccessTokenInfoManager() : hasInited_(false) {} @@ -75,7 +74,7 @@ AccessTokenInfoManager::~AccessTokenInfoManager() #ifdef TOKEN_SYNC_ENABLE int32_t ret = DistributedHardware::DeviceManager::GetInstance().UnInitDeviceManager(ACCESS_TOKEN_PACKAGE_NAME); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UnInitDeviceManager failed, code: %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "UnInitDeviceManager failed, code: %{public}d", ret); } #endif @@ -89,14 +88,15 @@ void AccessTokenInfoManager::Init() return; } - ACCESSTOKEN_LOG_INFO(LABEL, "Init begin!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Init begin!"); uint32_t hapSize = 0; uint32_t nativeSize = 0; InitHapTokenInfos(hapSize); InitNativeTokenInfos(nativeSize); uint32_t pefDefSize = PermissionDefinitionCache::GetInstance().GetDefPermissionsSize(); ReportSysEventServiceStart(getpid(), hapSize, nativeSize, pefDefSize); - ACCESSTOKEN_LOG_INFO(LABEL, "InitTokenInfo end, hapSize %{public}d, nativeSize %{public}d, pefDefSize %{public}d.", + LOGI(ATM_DOMAIN, ATM_TAG, + "InitTokenInfo end, hapSize %{public}d, nativeSize %{public}d, pefDefSize %{public}d.", hapSize, nativeSize, pefDefSize); hasInited_ = true; @@ -113,7 +113,7 @@ void AccessTokenInfoManager::InitDmCallback(void) int32_t ret = DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(ACCESS_TOKEN_PACKAGE_NAME, ptrDmInitCallback); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Initialize: InitDeviceManager error, result: %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Initialize: InitDeviceManager error, result: %{public}d", ret); } ACCESSTOKEN_LOG_INFO(LABEL, "device manager part init end"); return; @@ -146,7 +146,7 @@ void AccessTokenInfoManager::InitHapTokenInfos(uint32_t& hapSize) std::string bundle = tokenValue.GetString(TokenFiledConst::FIELD_BUNDLE_NAME); int result = AccessTokenIDManager::GetInstance().RegisterTokenId(tokenId, TOKEN_HAP); if (result != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId %{public}u add id failed, error=%{public}d.", tokenId, result); + LOGE(ATM_DOMAIN, ATM_TAG, "Add id=%{public}u failed, error=%{public}d.", tokenId, result); ReportSysEventServiceStartError(INIT_HAP_TOKENINFO_ERROR, "RegisterTokenId fail, " + bundle + std::to_string(tokenId), result); continue; @@ -155,20 +155,20 @@ void AccessTokenInfoManager::InitHapTokenInfos(uint32_t& hapSize) result = hap->RestoreHapTokenInfo(tokenId, tokenValue, permStateRes); if (result != RET_SUCCESS) { AccessTokenIDManager::GetInstance().ReleaseTokenId(tokenId); - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId %{public}u restore failed.", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u restore failed.", tokenId); continue; } result = AddHapTokenInfo(hap); if (result != RET_SUCCESS) { AccessTokenIDManager::GetInstance().ReleaseTokenId(tokenId); - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId %{public}u add failed.", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u add failed.", tokenId); ReportSysEventServiceStartError(INIT_HAP_TOKENINFO_ERROR, "AddHapTokenInfo fail, " + bundle + std::to_string(tokenId), result); continue; } hapSize++; - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, " Restore hap token %{public}u bundle name %{public}s user %{public}d," " permSize %{public}d, inst %{public}d ok!", tokenId, hap->GetBundleName().c_str(), hap->GetUserID(), hap->GetReqPermissionSize(), hap->GetInstIndex()); @@ -198,27 +198,27 @@ void AccessTokenInfoManager::InitNativeTokenInfos(uint32_t& nativeSize) if (result != RET_SUCCESS) { ReportSysEventServiceStartError(INIT_NATIVE_TOKENINFO_ERROR, "RegisterTokenId fail, " + process + std::to_string(tokenId), result); - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId %{public}u add failed, error=%{public}d.", tokenId, result); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u add failed, error=%{public}d.", tokenId, result); continue; } std::shared_ptr native = std::make_shared(); result = native->RestoreNativeTokenInfo(tokenId, nativeTokenValue, permStateRes); if (result != RET_SUCCESS) { AccessTokenIDManager::GetInstance().ReleaseTokenId(tokenId); - ACCESSTOKEN_LOG_ERROR(LABEL, "Id %{public}u restore failed.", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u restore failed.", tokenId); continue; } result = AddNativeTokenInfo(native); if (result != RET_SUCCESS) { AccessTokenIDManager::GetInstance().ReleaseTokenId(tokenId); - ACCESSTOKEN_LOG_ERROR(LABEL, "Id %{public}u add failed.", tokenId); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u add failed.", tokenId); ReportSysEventServiceStartError(INIT_NATIVE_TOKENINFO_ERROR, "AddNativeTokenInfo fail, " + process + std::to_string(tokenId), result); continue; } nativeSize++; - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "restore native token %{public}u process name %{public}s, permSize %{public}u ok!", tokenId, native->GetProcessName().c_str(), native->GetReqPermissionSize()); } @@ -241,7 +241,7 @@ std::string AccessTokenInfoManager::GetHapUniqueStr(const std::shared_ptr& info) { if (info == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token info is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Token info is null."); return AccessTokenError::ERR_PARAM_INVALID; } AccessTokenID id = info->GetTokenID(); @@ -249,7 +249,7 @@ int AccessTokenInfoManager::AddHapTokenInfo(const std::shared_ptr infoGuard(this->hapTokenInfoLock_); if (hapTokenInfoMap_.count(id) > 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u info has exist.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u info has exist.", id); return AccessTokenError::ERR_TOKENID_NOT_EXIST; } @@ -257,7 +257,7 @@ int AccessTokenInfoManager::AddHapTokenInfo(const std::shared_ptrsecond; } hapTokenIdMap_[hapUniqueKey] = id; @@ -278,7 +278,7 @@ int AccessTokenInfoManager::AddHapTokenInfo(const std::shared_ptr infoGuard(this->userPolicyLock_); if (!permPolicyList_.empty() && (std::find(inactiveUserList_.begin(), inactiveUserList_.end(), userId) != inactiveUserList_.end())) { - ACCESSTOKEN_LOG_INFO(LABEL, "Execute user policy."); + LOGI(ATM_DOMAIN, ATM_TAG, "Execute user policy."); PermissionManager::GetInstance().AddPermToKernel(id, permPolicyList_); return RET_SUCCESS; } @@ -290,19 +290,18 @@ int AccessTokenInfoManager::AddHapTokenInfo(const std::shared_ptr& info) { if (info == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token info is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Token info is null."); return AccessTokenError::ERR_PARAM_INVALID; } AccessTokenID id = info->GetTokenID(); Utils::UniqueWriteGuard infoGuard(this->nativeTokenInfoLock_); if (nativeTokenInfoMap_.count(id) > 0) { - ACCESSTOKEN_LOG_ERROR( - LABEL, "Token %{public}u has exist.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u has exist.", id); return AccessTokenError::ERR_TOKENID_HAS_EXISTED; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Token info is added %{public}u.", id); + LOGD(ATM_DOMAIN, ATM_TAG, "Token info is added %{public}u.", id); nativeTokenInfoMap_[id].processName = info->GetProcessName(); nativeTokenInfoMap_[id].apl = ATokenAplEnum(info->GetApl()); @@ -331,7 +330,7 @@ std::shared_ptr AccessTokenInfoManager::GetHapTokenInfoInner( std::vector permDefRes; AccessTokenDb::GetInstance().Find(AtmDataType::ACCESSTOKEN_PERMISSION_DEF, conditionValue, permDefRes); PermissionDefinitionCache::GetInstance().RestorePermDefInfo(permDefRes); // restore all permission definition - ACCESSTOKEN_LOG_INFO(LABEL, "Restore perm def size: %{public}zu, mapSize: %{public}zu.", + LOGI(ATM_DOMAIN, ATM_TAG, "Restore perm def size: %{public}zu, mapSize: %{public}zu.", permDefRes.size(), hapTokenInfoMap_.size()); } @@ -339,32 +338,34 @@ std::shared_ptr AccessTokenInfoManager::GetHapTokenInfoInner( std::vector hapTokenResults; int32_t ret = AccessTokenDb::GetInstance().Find(AtmDataType::ACCESSTOKEN_HAP_INFO, conditionValue, hapTokenResults); if (ret != RET_SUCCESS || hapTokenResults.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to find Id(%{public}u) from hap_token_table, err: %{public}d, " - "hapSize: %{public}zu, mapSize: %{public}zu.", id, ret, hapTokenResults.size(), hapTokenInfoMap_.size()); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to find Id(%{public}u) from hap_token_table, " + "err: %{public}d, hapSize: %{public}zu, mapSize: %{public}zu.", + id, ret, hapTokenResults.size(), hapTokenInfoMap_.size()); return nullptr; } std::vector permStateRes; ret = AccessTokenDb::GetInstance().Find(AtmDataType::ACCESSTOKEN_PERMISSION_STATE, conditionValue, permStateRes); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to find Id(%{public}u) from perm_state_table, err: %{public}d, " - "mapSize: %{public}zu.", id, ret, hapTokenInfoMap_.size()); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to find Id(%{public}u) from perm_state_table, " + "err: %{public}d, mapSize: %{public}zu.", id, ret, hapTokenInfoMap_.size()); return nullptr; } std::shared_ptr hap = std::make_shared(); ret = hap->RestoreHapTokenInfo(id, hapTokenResults[0], permStateRes); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Id %{public}u restore failed, err: %{public}d, mapSize: %{public}zu.", - id, ret, hapTokenInfoMap_.size()); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u restore failed, err: %{public}d, " + "mapSize: %{public}zu.", id, ret, hapTokenInfoMap_.size()); return nullptr; } AccessTokenIDManager::GetInstance().RegisterTokenId(id, TOKEN_HAP); hapTokenIdMap_[GetHapUniqueStr(hap)] = id; hapTokenInfoMap_[id] = hap; PermissionManager::GetInstance().AddPermToKernel(id); - ACCESSTOKEN_LOG_INFO(LABEL, " Token %{public}u is not found in map(mapSize: %{public}zu), begin load from DB," - " restore bundle %{public}s user %{public}d, idx %{public}d, permSize %{public}d.", id, hapTokenInfoMap_.size(), - hap->GetBundleName().c_str(), hap->GetUserID(), hap->GetInstIndex(), hap->GetReqPermissionSize()); + LOGI(ATM_DOMAIN, ATM_TAG, " Token %{public}u is not found in map(mapSize: %{public}zu), " + "begin load from DB, restore bundle %{public}s user %{public}d, idx %{public}d, permSize %{public}d.", + id, hapTokenInfoMap_.size(), hap->GetBundleName().c_str(), hap->GetUserID(), + hap->GetInstIndex(), hap->GetReqPermissionSize()); return hap; } @@ -375,7 +376,8 @@ int32_t AccessTokenInfoManager::GetHapTokenDlpType(AccessTokenID id) if ((iter != hapTokenInfoMap_.end()) && (iter->second != nullptr)) { return iter->second->GetDlpType(); } - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u is invalid, mapSize: %{public}zu.", id, hapTokenInfoMap_.size()); + LOGE(ATM_DOMAIN, ATM_TAG, + "Token %{public}u is invalid, mapSize: %{public}zu.", id, hapTokenInfoMap_.size()); return BUTT_DLP_TYPE; } @@ -400,8 +402,7 @@ int AccessTokenInfoManager::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& { std::shared_ptr infoPtr = GetHapTokenInfoInner(tokenID); if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_ERROR( - LABEL, "Token %{public}u is invalid.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u is invalid.", tokenID); return AccessTokenError::ERR_TOKENID_NOT_EXIST; } infoPtr->TranslateToHapTokenInfo(info); @@ -418,23 +419,23 @@ std::shared_ptr AccessTokenInfoManager::GetNativeTokenInfo int32_t ret = AccessTokenDb::GetInstance().Find( AtmDataType::ACCESSTOKEN_NATIVE_INFO, conditionValue, nativeTokenResults); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Id %{public}u find native info failed.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u find native info failed.", id); return nullptr; } if (nativeTokenResults.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Id %{public}u find native info empty.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u find native info empty.", id); return nullptr; } ret = AccessTokenDb::GetInstance().Find(AtmDataType::ACCESSTOKEN_PERMISSION_STATE, conditionValue, permStateRes); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Id %{public}u find permState info failed.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u find permState info failed.", id); return nullptr; } std::shared_ptr native = std::make_shared(); ret = native->RestoreNativeTokenInfo(id, nativeTokenResults[0], permStateRes); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Id %{public}u restore failed.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u restore failed.", id); return nullptr; } return native; @@ -445,7 +446,7 @@ int AccessTokenInfoManager::GetNativeTokenInfo(AccessTokenID tokenID, NativeToke Utils::UniqueReadGuard infoGuard(this->nativeTokenInfoLock_); auto iter = nativeTokenInfoMap_.find(tokenID); if (iter == nativeTokenInfoMap_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Id %{public}u is not exist.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u is not exist.", tokenID); return AccessTokenError::ERR_TOKENID_NOT_EXIST; } info.apl = iter->second.apl; @@ -457,7 +458,7 @@ int AccessTokenInfoManager::RemoveHapTokenInfo(AccessTokenID id) { ATokenTypeEnum type = AccessTokenIDManager::GetInstance().GetTokenIdType(id); if (type != TOKEN_HAP) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u is not hap.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u is not hap.", id); return ERR_PARAM_INVALID; } std::shared_ptr info; @@ -471,17 +472,17 @@ int AccessTokenInfoManager::RemoveHapTokenInfo(AccessTokenID id) AccessTokenIDManager::GetInstance().ReleaseTokenId(id); if (hapTokenInfoMap_.count(id) == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Hap token %{public}u no exist.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Hap token %{public}u no exist.", id); return ERR_TOKENID_NOT_EXIST; } info = hapTokenInfoMap_[id]; if (info == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Hap token %{public}u is null.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Hap token %{public}u is null.", id); return ERR_TOKEN_INVALID; } if (info->IsRemote()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote hap token %{public}u can not delete.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote hap token %{public}u can not delete.", id); return ERR_IDENTITY_CHECK_FAILED; } std::string HapUniqueKey = GetHapUniqueStr(info); @@ -492,7 +493,7 @@ int AccessTokenInfoManager::RemoveHapTokenInfo(AccessTokenID id) hapTokenInfoMap_.erase(id); } - ACCESSTOKEN_LOG_INFO(LABEL, "Remove hap token %{public}u ok!", id); + LOGI(ATM_DOMAIN, ATM_TAG, "Remove hap token %{public}u ok!", id); PermissionStateNotify(info, id); #ifdef TOKEN_SYNC_ENABLE TokenModifyNotifier::GetInstance().NotifyTokenDelete(id); @@ -509,22 +510,21 @@ int AccessTokenInfoManager::RemoveNativeTokenInfo(AccessTokenID id) { ATokenTypeEnum type = AccessTokenIDManager::GetInstance().GetTokenIdType(id); if ((type != TOKEN_NATIVE) && (type != TOKEN_SHELL)) { - ACCESSTOKEN_LOG_ERROR( - LABEL, "Token %{public}u is not native or shell.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u is not native or shell.", id); return ERR_PARAM_INVALID; } { Utils::UniqueWriteGuard infoGuard(this->nativeTokenInfoLock_); if (nativeTokenInfoMap_.count(id) == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Native token %{public}u is null.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Native token %{public}u is null.", id); return ERR_TOKENID_NOT_EXIST; } nativeTokenInfoMap_.erase(id); } AccessTokenIDManager::GetInstance().ReleaseTokenId(id); - ACCESSTOKEN_LOG_INFO(LABEL, "Remove native token %{public}u ok!", id); + LOGI(ATM_DOMAIN, ATM_TAG, "Remove native token %{public}u ok!", id); if (RemoveTokenInfoFromDb(id, false) != RET_SUCCESS) { return AccessTokenError::ERR_DATABASE_OPERATE_FAILED; } @@ -555,14 +555,14 @@ int AccessTokenInfoManager::CreateHapTokenInfo( if ((!DataValidator::IsUserIdValid(info.userID)) || (!DataValidator::IsBundleNameValid(info.bundleName)) || (!DataValidator::IsAppIDDescValid(info.appIDDesc)) || (!DataValidator::IsDomainValid(policy.domain)) || (!DataValidator::IsDlpTypeValid(info.dlpType))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Hap token param failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Hap token param failed"); return AccessTokenError::ERR_PARAM_INVALID; } int32_t dlpFlag = (info.dlpType > DLP_COMMON) ? 1 : 0; int32_t cloneFlag = ((dlpFlag == 0) && (info.instIndex) > 0) ? 1 : 0; AccessTokenID tokenId = AccessTokenIDManager::GetInstance().CreateAndRegisterTokenId(TOKEN_HAP, dlpFlag, cloneFlag); if (tokenId == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token Id create failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "Token Id create failed"); return ERR_TOKENID_CREATE_FAILED; } PermissionManager::GetInstance().AddDefPermissions(policy.permList, tokenId, false); @@ -582,13 +582,14 @@ int AccessTokenInfoManager::CreateHapTokenInfo( AddHapTokenInfoToDb(tokenId, tokenInfo, info.appIDDesc, policy.apl); int ret = AddHapTokenInfo(tokenInfo); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s add token info failed", info.bundleName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "%{public}s add token info failed", info.bundleName.c_str()); AccessTokenIDManager::GetInstance().ReleaseTokenId(tokenId); PermissionManager::GetInstance().RemoveDefPermissions(tokenId); RemoveTokenInfoFromDb(tokenId, true); return ret; } - ACCESSTOKEN_LOG_INFO(LABEL, "Create hap token %{public}u bundleName %{public}s user %{public}d inst %{public}d ok", + LOGI(ATM_DOMAIN, ATM_TAG, + "Create hap token %{public}u bundleName %{public}s user %{public}d inst %{public}d ok", tokenId, tokenInfo->GetBundleName().c_str(), tokenInfo->GetUserID(), tokenInfo->GetInstIndex()); AllocAccessTokenIDEx(info, tokenId, tokenIdEx); return RET_SUCCESS; @@ -615,7 +616,7 @@ AccessTokenIDEx AccessTokenInfoManager::GetHapTokenID(int32_t userID, const std: auto infoIter = hapTokenInfoMap_.find(tokenId); if (infoIter != hapTokenInfoMap_.end()) { if (infoIter->second == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "HapTokenInfoInner is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "HapTokenInfoInner is nullptr"); return tokenIdEx; } HapTokenInfo info = infoIter->second->GetHapInfoBasic(); @@ -629,7 +630,7 @@ AccessTokenIDEx AccessTokenInfoManager::GetHapTokenID(int32_t userID, const std: bool AccessTokenInfoManager::TryUpdateExistNativeToken(const std::shared_ptr& infoPtr) { if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Info is null."); + LOGW(ATM_DOMAIN, ATM_TAG, "Info is null."); return false; } @@ -648,8 +649,8 @@ bool AccessTokenInfoManager::TryUpdateExistNativeToken(const std::shared_ptr nativeTokenValues; for (const auto& infoPtr: tokenInfos) { if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Token info from libat is null"); + LOGW(ATM_DOMAIN, ATM_TAG, "Token info from libat is null"); continue; } if (!TryUpdateExistNativeToken(infoPtr)) { AccessTokenID id = infoPtr->GetTokenID(); std::string processName = infoPtr->GetProcessName(); ATokenTypeEnum type = AccessTokenIDManager::GetInstance().GetTokenIdTypeEnum(id); - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "Token %{public}u process name %{public}s is new, add to manager!", id, processName.c_str()); int ret = AccessTokenIDManager::GetInstance().RegisterTokenId(id, type); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token Id register fail, err=%{public}d.", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Token Id register fail, err=%{public}d.", ret); continue; } ret = AddNativeTokenInfo(infoPtr); if (ret != RET_SUCCESS) { AccessTokenIDManager::GetInstance().ReleaseTokenId(id); - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u process name %{public}s add to manager failed!", id, processName.c_str()); } infoPtr->TransferNativeInfo(nativeTokenValues); @@ -785,17 +786,17 @@ int32_t AccessTokenInfoManager::UpdateHapToken(AccessTokenIDEx& tokenIdEx, const { AccessTokenID tokenID = tokenIdEx.tokenIdExStruct.tokenID; if (!DataValidator::IsAppIDDescValid(info.appIDDesc)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u parm format error!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u parm format error!", tokenID); return AccessTokenError::ERR_PARAM_INVALID; } std::shared_ptr infoPtr = GetHapTokenInfoInner(tokenID); if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u is invalid, can not update!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u is invalid, can not update!", tokenID); return AccessTokenError::ERR_TOKENID_NOT_EXIST; } if (infoPtr->IsRemote()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote hap token %{public}u can not update!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote hap token %{public}u can not update!", tokenID); return ERR_IDENTITY_CHECK_FAILED; } if (info.isSystemApp) { @@ -821,7 +822,7 @@ int32_t AccessTokenInfoManager::UpdateHapToken(AccessTokenIDEx& tokenIdEx, const Utils::UniqueReadGuard infoGuard(this->userPolicyLock_); if (!permPolicyList_.empty() && (std::find(inactiveUserList_.begin(), inactiveUserList_.end(), userId) != inactiveUserList_.end())) { - ACCESSTOKEN_LOG_INFO(LABEL, "Execute user policy."); + LOGI(ATM_DOMAIN, ATM_TAG, "Execute user policy."); PermissionManager::GetInstance().AddPermToKernel(tokenID, permPolicyList_); return RET_SUCCESS; } @@ -835,8 +836,7 @@ int AccessTokenInfoManager::GetHapTokenSync(AccessTokenID tokenID, HapTokenInfoF { std::shared_ptr infoPtr = GetHapTokenInfoInner(tokenID); if (infoPtr == nullptr || infoPtr->IsRemote()) { - ACCESSTOKEN_LOG_ERROR( - LABEL, "Token %{public}u is invalid.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u is invalid.", tokenID); return ERR_IDENTITY_CHECK_FAILED; } hapSync.baseInfo = infoPtr->GetHapInfoBasic(); @@ -855,7 +855,7 @@ int AccessTokenInfoManager::UpdateRemoteHapTokenInfo(AccessTokenID mapID, HapTok { std::shared_ptr infoPtr = GetHapTokenInfoInner(mapID); if (infoPtr == nullptr || !infoPtr->IsRemote()) { - ACCESSTOKEN_LOG_INFO(LABEL, "Token %{public}u is null or not remote, can not update!", mapID); + LOGI(ATM_DOMAIN, ATM_TAG, "Token %{public}u is null or not remote, can not update!", mapID); return ERR_IDENTITY_CHECK_FAILED; } Utils::UniqueWriteGuard infoGuard(this->hapTokenInfoLock_); @@ -872,7 +872,7 @@ int AccessTokenInfoManager::CreateRemoteHapTokenInfo(AccessTokenID mapID, HapTok int ret = AddHapTokenInfo(hap); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Add local token failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Add local token failed."); return ret; } @@ -909,14 +909,16 @@ bool AccessTokenInfoManager::IsRemoteHapTokenValid(const std::string& deviceID, int AccessTokenInfoManager::SetRemoteHapTokenInfo(const std::string& deviceID, HapTokenInfoForSync& hapSync) { if (!IsRemoteHapTokenValid(deviceID, hapSync)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s parms invalid", ConstantCommon::EncryptDevId(deviceID).c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, + "Device %{public}s parms invalid", ConstantCommon::EncryptDevId(deviceID).c_str()); return ERR_IDENTITY_CHECK_FAILED; } AccessTokenID remoteID = hapSync.baseInfo.tokenID; AccessTokenID mapID = AccessTokenRemoteTokenManager::GetInstance().GetDeviceMappingTokenID(deviceID, remoteID); if (mapID != 0) { - ACCESSTOKEN_LOG_INFO(LABEL, "Device %{public}s token %{public}u update exist remote hap token %{public}u.", + LOGI(ATM_DOMAIN, ATM_TAG, + "Device %{public}s token %{public}u update exist remote hap token %{public}u.", ConstantCommon::EncryptDevId(deviceID).c_str(), remoteID, mapID); // update remote token mapping id hapSync.baseInfo.tokenID = mapID; @@ -925,7 +927,7 @@ int AccessTokenInfoManager::SetRemoteHapTokenInfo(const std::string& deviceID, H mapID = AccessTokenRemoteTokenManager::GetInstance().MapRemoteDeviceTokenToLocal(deviceID, remoteID); if (mapID == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s token %{public}u map failed.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s token %{public}u map failed.", ConstantCommon::EncryptDevId(deviceID).c_str(), remoteID); return ERR_TOKEN_MAP_FAILED; } @@ -936,13 +938,15 @@ int AccessTokenInfoManager::SetRemoteHapTokenInfo(const std::string& deviceID, H if (ret != RET_SUCCESS) { int result = AccessTokenRemoteTokenManager::GetInstance().RemoveDeviceMappingTokenID(deviceID, mapID); if (result != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "remove device map token id failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "remove device map token id failed"); } - ACCESSTOKEN_LOG_INFO(LABEL, "Device %{public}s token %{public}u map to local token %{public}u failed.", + LOGI(ATM_DOMAIN, ATM_TAG, + "Device %{public}s token %{public}u map to local token %{public}u failed.", ConstantCommon::EncryptDevId(deviceID).c_str(), remoteID, mapID); return ret; } - ACCESSTOKEN_LOG_INFO(LABEL, "Device %{public}s token %{public}u map to local token %{public}u success.", + LOGI(ATM_DOMAIN, ATM_TAG, + "Device %{public}s token %{public}u map to local token %{public}u success.", ConstantCommon::EncryptDevId(deviceID).c_str(), remoteID, mapID); return RET_SUCCESS; } @@ -950,13 +954,13 @@ int AccessTokenInfoManager::SetRemoteHapTokenInfo(const std::string& deviceID, H int AccessTokenInfoManager::DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID) { if (!DataValidator::IsDeviceIdValid(deviceID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s parms invalid.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s parms invalid.", ConstantCommon::EncryptDevId(deviceID).c_str()); return AccessTokenError::ERR_PARAM_INVALID; } AccessTokenID mapID = AccessTokenRemoteTokenManager::GetInstance().GetDeviceMappingTokenID(deviceID, tokenID); if (mapID == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s tokenId %{public}u is not mapped.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s tokenId %{public}u is not mapped.", ConstantCommon::EncryptDevId(deviceID).c_str(), tokenID); return ERR_TOKEN_MAP_FAILED; } @@ -965,20 +969,19 @@ int AccessTokenInfoManager::DeleteRemoteToken(const std::string& deviceID, Acces if (type == TOKEN_HAP) { Utils::UniqueWriteGuard infoGuard(this->hapTokenInfoLock_); if (hapTokenInfoMap_.count(mapID) == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Hap token %{public}u no exist.", mapID); + LOGE(ATM_DOMAIN, ATM_TAG, "Hap token %{public}u no exist.", mapID); return ERR_TOKEN_INVALID; } hapTokenInfoMap_.erase(mapID); } else if ((type == TOKEN_NATIVE) || (type == TOKEN_SHELL)) { Utils::UniqueWriteGuard infoGuard(this->nativeTokenInfoLock_); if (nativeTokenInfoMap_.count(mapID) == 0) { - ACCESSTOKEN_LOG_ERROR( - LABEL, "Native token %{public}u is null.", mapID); + LOGE(ATM_DOMAIN, ATM_TAG, "Native token %{public}u is null.", mapID); return ERR_TOKEN_INVALID; } nativeTokenInfoMap_.erase(mapID); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Mapping tokenId %{public}u type is unknown.", mapID); + LOGE(ATM_DOMAIN, ATM_TAG, "Mapping tokenId %{public}u type is unknown.", mapID); } return AccessTokenRemoteTokenManager::GetInstance().RemoveDeviceMappingTokenID(deviceID, tokenID); @@ -989,7 +992,7 @@ AccessTokenID AccessTokenInfoManager::GetRemoteNativeTokenID(const std::string& if ((!DataValidator::IsDeviceIdValid(deviceID)) || (tokenID == 0) || ((AccessTokenIDManager::GetInstance().GetTokenIdTypeEnum(tokenID) != TOKEN_NATIVE) && (AccessTokenIDManager::GetInstance().GetTokenIdTypeEnum(tokenID) != TOKEN_SHELL))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s parms invalid.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s parms invalid.", ConstantCommon::EncryptDevId(deviceID).c_str()); return 0; } @@ -999,22 +1002,22 @@ AccessTokenID AccessTokenInfoManager::GetRemoteNativeTokenID(const std::string& int AccessTokenInfoManager::DeleteRemoteDeviceTokens(const std::string& deviceID) { if (!DataValidator::IsDeviceIdValid(deviceID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s parms invalid.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s parms invalid.", ConstantCommon::EncryptDevId(deviceID).c_str()); return AccessTokenError::ERR_PARAM_INVALID; } std::vector remoteTokens; int ret = AccessTokenRemoteTokenManager::GetInstance().GetDeviceAllRemoteTokenID(deviceID, remoteTokens); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s have no remote token.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s have no remote token.", ConstantCommon::EncryptDevId(deviceID).c_str()); return ret; } for (AccessTokenID remoteID : remoteTokens) { ret = DeleteRemoteToken(deviceID, remoteID); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "delete remote token failed! deviceId=%{public}s, remoteId=%{public}d.", \ - deviceID.c_str(), remoteID); + LOGE(ATM_DOMAIN, ATM_TAG, + "delete remote token failed! deviceId=%{public}s, remoteId=%{public}d.", deviceID.c_str(), remoteID); } } return ret; @@ -1024,7 +1027,7 @@ AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remot AccessTokenID remoteTokenID) { if (!DataValidator::IsDeviceIdValid(remoteDeviceID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s parms invalid.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s parms invalid.", ConstantCommon::EncryptDevId(remoteDeviceID).c_str()); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_SYNC", HiviewDFX::HiSysEvent::EventType::FAULT, "CODE", TOKEN_SYNC_CALL_ERROR, @@ -1033,12 +1036,14 @@ AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remot } uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID(); int result = SetFirstCallerTokenID(fullTokenId); // for debug - ACCESSTOKEN_LOG_INFO(LABEL, "Set first caller %{public}" PRIu64 "., ret is %{public}d", fullTokenId, result); + LOGI(ATM_DOMAIN, ATM_TAG, + "Set first caller %{public}" PRIu64 "., ret is %{public}d", fullTokenId, result); std::string remoteUdid; DistributedHardware::DeviceManager::GetInstance().GetUdidByNetworkId(ACCESS_TOKEN_PACKAGE_NAME, remoteDeviceID, remoteUdid); - ACCESSTOKEN_LOG_INFO(LABEL, "Device %{public}s remoteUdid.", ConstantCommon::EncryptDevId(remoteUdid).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Device %{public}s remoteUdid.", + ConstantCommon::EncryptDevId(remoteUdid).c_str()); AccessTokenID mapID = AccessTokenRemoteTokenManager::GetInstance().GetDeviceMappingTokenID(remoteUdid, remoteTokenID); if (mapID != 0) { @@ -1046,7 +1051,7 @@ AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remot } int ret = TokenModifyNotifier::GetInstance().GetRemoteHapTokenInfo(remoteUdid, remoteTokenID); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s token %{public}u sync failed", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s token %{public}u sync failed", ConstantCommon::EncryptDevId(remoteUdid).c_str(), remoteTokenID); std::string errorReason = "token sync call error, error number is " + std::to_string(ret); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_SYNC", @@ -1061,7 +1066,7 @@ AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remot AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remoteDeviceID, AccessTokenID remoteTokenID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Tokensync is disable, check dependent components"); + LOGE(ATM_DOMAIN, ATM_TAG, "Tokensync is disable, check dependent components"); return 0; } #endif @@ -1087,7 +1092,7 @@ int AccessTokenInfoManager::AddHapTokenInfoToDb( std::vector permDefValues; std::vector permStateValues; if (hapInfo == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u info is null!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u info is null!", tokenID); return AccessTokenError::ERR_TOKENID_NOT_EXIST; } StoreHapInfo(hapInfo, appId, apl, hapInfoValues); @@ -1130,7 +1135,7 @@ void AccessTokenInfoManager::PermissionStateNotify(const std::shared_ptr infoGuard(this->userPolicyLock_); if (!permPolicyList_.empty() && (std::find(inactiveUserList_.begin(), inactiveUserList_.end(), userId) != inactiveUserList_.end())) { - ACCESSTOKEN_LOG_INFO(LABEL, "Execute user policy."); + LOGI(ATM_DOMAIN, ATM_TAG, "Execute user policy."); HapTokenInfoInner::GetGrantedPermByTokenId(id, permPolicyList_, permissionList); } else { std::vector emptyList; @@ -1153,18 +1158,18 @@ int32_t AccessTokenInfoManager::GetHapAppIdByTokenId(AccessTokenID tokenID, std: std::vector hapTokenResults; int32_t ret = AccessTokenDb::GetInstance().Find(AtmDataType::ACCESSTOKEN_HAP_INFO, conditionValue, hapTokenResults); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to find Id(%{public}u) from hap_token_table, err: %{public}d.", tokenID, ret); return ret; } if (hapTokenResults.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Id(%{public}u) is not in hap_token_table.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id(%{public}u) is not in hap_token_table.", tokenID); return AccessTokenError::ERR_TOKENID_NOT_EXIST; } std::string result = hapTokenResults[0].GetString(TokenFiledConst::FIELD_APP_ID); if (!DataValidator::IsAppIDDescValid(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID: 0x%{public}x appID is error.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID: 0x%{public}x appID is error.", tokenID); return AccessTokenError::ERR_PARAM_INVALID; } appId = result; @@ -1219,7 +1224,7 @@ void AccessTokenInfoManager::DumpHapTokenInfoByBundleName(const std::string& bun void AccessTokenInfoManager::DumpAllHapTokenname(std::string& dumpInfo) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Get all hap token name."); + LOGD(ATM_DOMAIN, ATM_TAG, "Get all hap token name."); Utils::UniqueReadGuard hapInfoGuard(this->hapTokenInfoLock_); for (auto iter = hapTokenInfoMap_.begin(); iter != hapTokenInfoMap_.end(); iter++) { @@ -1241,7 +1246,7 @@ void AccessTokenInfoManager::DumpNativeTokenInfoByProcessName(const std::string& void AccessTokenInfoManager::DumpAllNativeTokenName(std::string& dumpInfo) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Get all native token name."); + LOGD(ATM_DOMAIN, ATM_TAG, "Get all native token name."); Utils::UniqueReadGuard infoGuard(this->nativeTokenInfoLock_); for (auto iter = nativeTokenInfoMap_.begin(); iter != nativeTokenInfoMap_.end(); iter++) { @@ -1267,10 +1272,10 @@ void AccessTokenInfoManager::ReduceDumpTaskNum() void AccessTokenInfoManager::DumpToken() { - ACCESSTOKEN_LOG_INFO(LABEL, "AccessToken Dump"); - int32_t fd = open(DUMP_JSON_PATH.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP); + LOGI(ATM_DOMAIN, ATM_TAG, "AccessToken Dump"); + int32_t fd = open(DUMP_JSON_PATH, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP); if (fd < 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Open failed errno %{public}d.", errno); + LOGE(ATM_DOMAIN, ATM_TAG, "Open failed errno %{public}d.", errno); return; } std::string dumpStr; @@ -1322,11 +1327,11 @@ int32_t AccessTokenInfoManager::ClearUserGrantedPermission(AccessTokenID id) { std::shared_ptr infoPtr = AccessTokenInfoManager::GetInstance().GetHapTokenInfoInner(id); if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u is invalid.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u is invalid.", id); return ERR_PARAM_INVALID; } if (infoPtr->IsRemote()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "It is a remote hap token %{public}u!", id); + LOGE(ATM_DOMAIN, ATM_TAG, "It is a remote hap token %{public}u!", id); return ERR_IDENTITY_CHECK_FAILED; } std::vector grantedPermListBefore; @@ -1350,7 +1355,7 @@ int32_t AccessTokenInfoManager::ClearUserGrantedPermission(AccessTokenID id) } } PermissionManager::GetInstance().AddPermToKernel(id); - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "grantedPermListBefore size %{public}zu, grantedPermListAfter size %{public}zu!", grantedPermListBefore.size(), grantedPermListAfter.size()); PermissionManager::GetInstance().NotifyUpdatedPermList(grantedPermListBefore, grantedPermListAfter, id); @@ -1361,14 +1366,14 @@ bool AccessTokenInfoManager::IsPermissionRestrictedByUserPolicy(AccessTokenID id { std::shared_ptr infoPtr = AccessTokenInfoManager::GetInstance().GetHapTokenInfoInner(id); if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token %{public}u is invalid.", id); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}u is invalid.", id); return ERR_PARAM_INVALID; } int32_t userId = infoPtr->GetUserID(); Utils::UniqueReadGuard infoGuard(this->userPolicyLock_); if ((std::find(permPolicyList_.begin(), permPolicyList_.end(), permissionName) != permPolicyList_.end()) && (std::find(inactiveUserList_.begin(), inactiveUserList_.end(), userId) != inactiveUserList_.end())) { - ACCESSTOKEN_LOG_INFO(LABEL, "id %{public}u perm %{public}s.", id, permissionName.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "id %{public}u perm %{public}s.", id, permissionName.c_str()); return true; } return false; @@ -1383,7 +1388,7 @@ void AccessTokenInfoManager::GetRelatedSandBoxHapList(AccessTokenID tokenId, std return; } if (infoIter->second == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "HapTokenInfoInner is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "HapTokenInfoInner is nullptr."); return; } std::string bundleName = infoIter->second->GetBundleName(); @@ -1414,7 +1419,7 @@ int32_t AccessTokenInfoManager::SetPermDialogCap(AccessTokenID tokenID, bool ena Utils::UniqueWriteGuard infoGuard(this->hapTokenInfoLock_); auto infoIter = hapTokenInfoMap_.find(tokenID); if ((infoIter == hapTokenInfoMap_.end()) || (infoIter->second == nullptr)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "HapTokenInfoInner is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "HapTokenInfoInner is nullptr."); return ERR_TOKENID_NOT_EXIST; } infoIter->second->SetPermDialogForbidden(enable); @@ -1430,7 +1435,7 @@ int32_t AccessTokenInfoManager::ParseUserPolicyInfo(const std::vector const std::vector& permList, std::map& changedUserList) { if (!permPolicyList_.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UserPolicy has been initialized."); + LOGE(ATM_DOMAIN, ATM_TAG, "UserPolicy has been initialized."); return ERR_USER_POLICY_INITIALIZED; } for (const auto &permission : permList) { @@ -1440,16 +1445,16 @@ int32_t AccessTokenInfoManager::ParseUserPolicyInfo(const std::vector } if (permPolicyList_.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "permList is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "permList is invalid."); return ERR_PARAM_INVALID; } for (const auto &userInfo : userList) { if (userInfo.userId < 0) { - ACCESSTOKEN_LOG_WARN(LABEL, "userId %{public}d is invalid.", userInfo.userId); + LOGW(ATM_DOMAIN, ATM_TAG, "userId %{public}d is invalid.", userInfo.userId); continue; } if (userInfo.isActive) { - ACCESSTOKEN_LOG_INFO(LABEL, "userid %{public}d is active.", userInfo.userId); + LOGI(ATM_DOMAIN, ATM_TAG, "userid %{public}d is active.", userInfo.userId); continue; } inactiveUserList_.emplace_back(userInfo.userId); @@ -1463,12 +1468,12 @@ int32_t AccessTokenInfoManager::ParseUserPolicyInfo(const std::vector std::map& changedUserList) { if (permPolicyList_.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UserPolicy has been initialized."); + LOGE(ATM_DOMAIN, ATM_TAG, "UserPolicy has been initialized."); return ERR_USER_POLICY_NOT_INITIALIZED; } for (const auto &userInfo : userList) { if (userInfo.userId < 0) { - ACCESSTOKEN_LOG_WARN(LABEL, "UserId %{public}d is invalid.", userInfo.userId); + LOGW(ATM_DOMAIN, ATM_TAG, "UserId %{public}d is invalid.", userInfo.userId); continue; } auto iter = std::find(inactiveUserList_.begin(), inactiveUserList_.end(), userInfo.userId); @@ -1494,7 +1499,7 @@ void AccessTokenInfoManager::GetGoalHapList(std::map& token AccessTokenID tokenId = iter->first; std::shared_ptr infoPtr = iter->second; if (infoPtr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId infoPtr is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenId infoPtr is null."); continue; } auto userInfo = changedUserList.find(infoPtr->GetUserID()); @@ -1543,7 +1548,7 @@ int32_t AccessTokenInfoManager::UpdatePermissionStateToKernel(const std::vector< PermissionManager::GetInstance().ParamUpdate(std::string(), 0, true); } for (auto perm = refreshedPermList.begin(); perm != refreshedPermList.end(); ++perm) { - ACCESSTOKEN_LOG_INFO(LABEL, "Perm %{public}s refreshed by user policy, isActive %{public}d.", + LOGI(ATM_DOMAIN, ATM_TAG, "Perm %{public}s refreshed by user policy, isActive %{public}d.", perm->first.c_str(), perm->second); PermStateChangeType change = perm->second ? PermStateChangeType::STATE_CHANGE_GRANTED : PermStateChangeType::STATE_CHANGE_REVOKED; @@ -1565,7 +1570,7 @@ int32_t AccessTokenInfoManager::InitUserPolicy( return ret; } if (changedUserList.empty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "changedUserList is empty."); + LOGI(ATM_DOMAIN, ATM_TAG, "changedUserList is empty."); return ret; } GetGoalHapList(tokenIdList, changedUserList); @@ -1584,7 +1589,7 @@ int32_t AccessTokenInfoManager::UpdateUserPolicy(const std::vector& u return ret; } if (changedUserList.empty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "changedUserList is empty."); + LOGI(ATM_DOMAIN, ATM_TAG, "changedUserList is empty."); return ret; } GetGoalHapList(tokenIdList, changedUserList); @@ -1598,7 +1603,7 @@ int32_t AccessTokenInfoManager::ClearUserPolicy() std::vector permList; Utils::UniqueWriteGuard infoGuard(this->userPolicyLock_); if (permPolicyList_.empty()) { - ACCESSTOKEN_LOG_WARN(LABEL, "UserPolicy has been cleared."); + LOGW(ATM_DOMAIN, ATM_TAG, "UserPolicy has been cleared."); return RET_SUCCESS; } permList.assign(permPolicyList_.begin(), permPolicyList_.end()); @@ -1620,13 +1625,13 @@ int32_t AccessTokenInfoManager::ClearUserPolicy() bool AccessTokenInfoManager::GetPermDialogCap(AccessTokenID tokenID) { if (tokenID == INVALID_TOKENID) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid tokenId."); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid tokenId."); return true; } Utils::UniqueReadGuard infoGuard(this->hapTokenInfoLock_); auto infoIter = hapTokenInfoMap_.find(tokenID); if ((infoIter == hapTokenInfoMap_.end()) || (infoIter->second == nullptr)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenId is not exist in map."); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenId is not exist in map."); return true; } return infoIter->second->IsPermDialogForbidden(); @@ -1642,7 +1647,7 @@ bool AccessTokenInfoManager::UpdateCapStateToDatabase(AccessTokenID tokenID, boo int32_t res = AccessTokenDb::GetInstance().Modify(AtmDataType::ACCESSTOKEN_HAP_INFO, modifyValue, conditionValue); if (res != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "Update tokenID %{public}u permissionDialogForbidden %{public}d to database failed", tokenID, enable); return false; } @@ -1654,26 +1659,26 @@ int AccessTokenInfoManager::VerifyNativeAccessToken(AccessTokenID tokenID, const { if (!PermissionDefinitionCache::GetInstance().HasDefinition(permissionName)) { if (PermissionDefinitionCache::GetInstance().IsHapPermissionDefEmpty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "Permission definition set has not been installed!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Permission definition set has not been installed!"); if (AccessTokenIDManager::GetInstance().GetTokenIdTypeEnum(tokenID) == TOKEN_NATIVE) { return PERMISSION_GRANTED; } - ACCESSTOKEN_LOG_ERROR(LABEL, "Token: %{public}d type error!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Token: %{public}d type error!", tokenID); return PERMISSION_DENIED; } - ACCESSTOKEN_LOG_ERROR(LABEL, "No definition for permission: %{public}s!", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "No definition for permission: %{public}s!", permissionName.c_str()); return PERMISSION_DENIED; } uint32_t code; if (!TransferPermissionToOpcode(permissionName, code)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid perm(%{public}s)", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid perm(%{public}s)", permissionName.c_str()); return PERMISSION_DENIED; } Utils::UniqueReadGuard infoGuard(this->nativeTokenInfoLock_); auto iter = nativeTokenInfoMap_.find(tokenID); if (iter == nativeTokenInfoMap_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Id %{public}u is not exist.", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id %{public}u is not exist.", tokenID); return PERMISSION_DENIED; } @@ -1693,12 +1698,12 @@ int32_t AccessTokenInfoManager::VerifyAccessToken(AccessTokenID tokenID, const s HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", HiviewDFX::HiSysEvent::EventType::FAULT, "CODE", VERIFY_TOKEN_ID_ERROR, "CALLER_TOKENID", static_cast(IPCSkeleton::GetCallingTokenID()), "PERMISSION_NAME", permissionName); - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid"); return PERMISSION_DENIED; } if (!PermissionValidator::IsPermissionNameValid(permissionName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "PermissionName: %{public}s, invalid params!", permissionName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission: %{public}s, invalid params!", permissionName.c_str()); return PERMISSION_DENIED; } @@ -1709,13 +1714,13 @@ int32_t AccessTokenInfoManager::VerifyAccessToken(AccessTokenID tokenID, const s if (tokenType == TOKEN_HAP) { return PermissionManager::GetInstance().VerifyHapAccessToken(tokenID, permissionName); } - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID: %{public}d, invalid tokenType!", tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID: %{public}d, invalid tokenType!", tokenID); return PERMISSION_DENIED; } void AccessTokenInfoManager::ClearHapPolicy() { - ACCESSTOKEN_LOG_INFO(LABEL, "Enter."); + LOGI(ATM_DOMAIN, ATM_TAG, "Enter."); Utils::UniqueReadGuard infoGuard(this->hapTokenInfoLock_); for (auto iter = hapTokenInfoMap_.begin(); iter != hapTokenInfoMap_.end(); iter++) { iter->second->ClearHapInfoPermissionPolicySet(); diff --git a/services/accesstokenmanager/main/cpp/src/token/accesstoken_remote_token_manager.cpp b/services/accesstokenmanager/main/cpp/src/token/accesstoken_remote_token_manager.cpp index 4400f338b19d372c254158891c9d97043dff485a..d393fa00826f898ac5ff43060aea6946bddf3075 100644 --- a/services/accesstokenmanager/main/cpp/src/token/accesstoken_remote_token_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/accesstoken_remote_token_manager.cpp @@ -25,8 +25,6 @@ namespace Security { namespace AccessToken { namespace { std::recursive_mutex g_instanceMutex; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenRemoteTokenManager"}; } AccessTokenRemoteTokenManager::AccessTokenRemoteTokenManager() {} @@ -52,14 +50,13 @@ AccessTokenID AccessTokenRemoteTokenManager::MapRemoteDeviceTokenToLocal(const s AccessTokenID remoteID) { if (!DataValidator::IsDeviceIdValid(deviceID) || !DataValidator::IsTokenIDValid(remoteID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s or token %{public}x is invalid.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s or token %{public}x is invalid.", ConstantCommon::EncryptDevId(deviceID).c_str(), remoteID); return 0; } ATokenTypeEnum tokeType = AccessTokenIDManager::GetInstance().GetTokenIdTypeEnum(remoteID); if ((tokeType <= TOKEN_INVALID) || (tokeType >= TOKEN_TYPE_BUTT)) { - ACCESSTOKEN_LOG_ERROR( - LABEL, "Token %{public}x type is invalid.", remoteID); + LOGE(ATM_DOMAIN, ATM_TAG, "Token %{public}x type is invalid.", remoteID); return 0; } int32_t dlpFlag = AccessTokenIDManager::GetInstance().GetTokenIdDlpFlag(remoteID); @@ -72,8 +69,8 @@ AccessTokenID AccessTokenRemoteTokenManager::MapRemoteDeviceTokenToLocal(const s AccessTokenRemoteDevice& device = remoteDeviceMap_[deviceID]; if (device.MappingTokenIDPairMap_.count(remoteID) > 0) { mapID = device.MappingTokenIDPairMap_[remoteID]; - ACCESSTOKEN_LOG_ERROR( - LABEL, "Device %{public}s token %{public}x has already mapped, map tokenID is %{public}x.", + LOGE(ATM_DOMAIN, ATM_TAG, + "Device %{public}s token %{public}x has already mapped, map tokenID is %{public}x.", ConstantCommon::EncryptDevId(deviceID).c_str(), remoteID, mapID); return mapID; } @@ -87,8 +84,7 @@ AccessTokenID AccessTokenRemoteTokenManager::MapRemoteDeviceTokenToLocal(const s mapID = AccessTokenIDManager::GetInstance().CreateAndRegisterTokenId(tokeType, dlpFlag, cloneFlag); if (mapID == 0) { - ACCESSTOKEN_LOG_ERROR( - LABEL, "Device %{public}s token %{public}x map local Token failed.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s token %{public}x map local Token failed.", ConstantCommon::EncryptDevId(deviceID).c_str(), remoteID); return 0; } @@ -100,12 +96,13 @@ int AccessTokenRemoteTokenManager::GetDeviceAllRemoteTokenID(const std::string& std::vector& remoteIDs) { if (!DataValidator::IsDeviceIdValid(deviceID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s is valid.", ConstantCommon::EncryptDevId(deviceID).c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, + "Device %{public}s is valid.", ConstantCommon::EncryptDevId(deviceID).c_str()); return AccessTokenError::ERR_PARAM_INVALID; } Utils::UniqueReadGuard infoGuard(this->remoteDeviceLock_); if (remoteDeviceMap_.count(deviceID) < 1) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s has not mapping.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s has not mapping.", ConstantCommon::EncryptDevId(deviceID).c_str()); return AccessTokenError::ERR_DEVICE_NOT_EXIST; } @@ -122,7 +119,7 @@ AccessTokenID AccessTokenRemoteTokenManager::GetDeviceMappingTokenID(const std:: AccessTokenID remoteID) { if (!DataValidator::IsDeviceIdValid(deviceID) || !DataValidator::IsTokenIDValid(remoteID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s or token %{public}x is invalid.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s or token %{public}x is invalid.", ConstantCommon::EncryptDevId(deviceID).c_str(), remoteID); return 0; } @@ -130,7 +127,7 @@ AccessTokenID AccessTokenRemoteTokenManager::GetDeviceMappingTokenID(const std:: Utils::UniqueReadGuard infoGuard(this->remoteDeviceLock_); if (remoteDeviceMap_.count(deviceID) < 1 || remoteDeviceMap_[deviceID].MappingTokenIDPairMap_.count(remoteID) < 1) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s has not mapping.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s has not mapping.", ConstantCommon::EncryptDevId(deviceID).c_str()); return 0; } @@ -142,7 +139,7 @@ int AccessTokenRemoteTokenManager::RemoveDeviceMappingTokenID(const std::string& AccessTokenID remoteID) { if (!DataValidator::IsDeviceIdValid(deviceID) || !DataValidator::IsTokenIDValid(remoteID)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s or token %{public}x is invalid.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s or token %{public}x is invalid.", ConstantCommon::EncryptDevId(deviceID).c_str(), remoteID); return ERR_PARAM_INVALID; } @@ -150,7 +147,7 @@ int AccessTokenRemoteTokenManager::RemoveDeviceMappingTokenID(const std::string& Utils::UniqueWriteGuard infoGuard(this->remoteDeviceLock_); if (remoteDeviceMap_.count(deviceID) < 1 || remoteDeviceMap_[deviceID].MappingTokenIDPairMap_.count(remoteID) < 1) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Device %{public}s has not mapping.", + LOGE(ATM_DOMAIN, ATM_TAG, "Device %{public}s has not mapping.", ConstantCommon::EncryptDevId(deviceID).c_str()); return ERR_TOKEN_MAP_FAILED; } diff --git a/services/accesstokenmanager/main/cpp/src/token/hap_token_info_inner.cpp b/services/accesstokenmanager/main/cpp/src/token/hap_token_info_inner.cpp index 069d610ae79e7bd28e07dd746f351399acc1d03a..954c1861c87fe6179cf21b5aa3f39f923fd165c9 100644 --- a/services/accesstokenmanager/main/cpp/src/token/hap_token_info_inner.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/hap_token_info_inner.cpp @@ -34,8 +34,7 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "HapTokenInfoInner"}; -static const std::string DEFAULT_DEVICEID = "0"; +constexpr const char* DEFAULT_DEVICEID = "0"; static const unsigned int SYSTEM_APP_FLAG = 0x0001; } @@ -85,7 +84,7 @@ HapTokenInfoInner::HapTokenInfoInner(AccessTokenID id, HapTokenInfoInner::~HapTokenInfoInner() { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenID: %{public}d destruction", tokenInfoBasic_.tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenID: %{public}d destruction", tokenInfoBasic_.tokenID); PermissionDataBrief::GetInstance().DeleteBriefPermDataByTokenId(tokenInfoBasic_.tokenID); } @@ -133,7 +132,7 @@ int HapTokenInfoInner::RestoreHapTokenBasicInfo(const GenericValues& inGenericVa tokenInfoBasic_.userID = inGenericValues.GetInt(TokenFiledConst::FIELD_USER_ID); tokenInfoBasic_.bundleName = inGenericValues.GetString(TokenFiledConst::FIELD_BUNDLE_NAME); if (!DataValidator::IsBundleNameValid(tokenInfoBasic_.bundleName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID: 0x%{public}x bundle name is error", tokenInfoBasic_.tokenID); + LOGE(ATM_DOMAIN, ATM_TAG, "Id: 0x%{public}x bundle name is error", tokenInfoBasic_.tokenID); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", HiviewDFX::HiSysEvent::EventType::FAULT, "CODE", LOAD_DATABASE_ERROR, "ERROR_REASON", "bundleName error"); return AccessTokenError::ERR_PARAM_INVALID; @@ -142,10 +141,9 @@ int HapTokenInfoInner::RestoreHapTokenBasicInfo(const GenericValues& inGenericVa tokenInfoBasic_.apiVersion = GetApiVersion(inGenericValues.GetInt(TokenFiledConst::FIELD_API_VERSION)); tokenInfoBasic_.instIndex = inGenericValues.GetInt(TokenFiledConst::FIELD_INST_INDEX); tokenInfoBasic_.dlpType = inGenericValues.GetInt(TokenFiledConst::FIELD_DLP_TYPE); - tokenInfoBasic_.ver = (char)inGenericValues.GetInt(TokenFiledConst::FIELD_TOKEN_VERSION); if (tokenInfoBasic_.ver != DEFAULT_TOKEN_VERSION) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TokenID: 0x%{public}x version is error, version %{public}d", + LOGE(ATM_DOMAIN, ATM_TAG, "TokenID: 0x%{public}x version is error, version %{public}d", tokenInfoBasic_.tokenID, tokenInfoBasic_.ver); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", HiviewDFX::HiSysEvent::EventType::FAULT, "CODE", LOAD_DATABASE_ERROR, "ERROR_REASON", "version error"); @@ -173,7 +171,8 @@ int HapTokenInfoInner::RestoreHapTokenInfo(AccessTokenID tokenId, void HapTokenInfoInner::StoreHapInfo(std::vector& valueList) const { if (isRemote_) { - ACCESSTOKEN_LOG_INFO(LABEL, "Token %{public}u is remote hap token, will not store", tokenInfoBasic_.tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, + "Token %{public}u is remote hap token, will not store", tokenInfoBasic_.tokenID); return; } GenericValues genericValues; @@ -184,7 +183,8 @@ void HapTokenInfoInner::StoreHapInfo(std::vector& valueList) cons void HapTokenInfoInner::StorePermissionPolicy(std::vector& permStateValues) { if (isRemote_) { - ACCESSTOKEN_LOG_INFO(LABEL, "Token %{public}u is remote hap token, will not store.", tokenInfoBasic_.tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, + "Token %{public}u is remote hap token, will not store.", tokenInfoBasic_.tokenID); return; } Utils::UniqueReadGuard infoGuard(this->policySetLock_); @@ -196,7 +196,7 @@ void HapTokenInfoInner::StorePermissionPolicy(std::vector& permSt void HapTokenInfoInner::ClearHapInfoPermissionPolicySet() { if (isRemote_) { - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "token %{public}x is a remote hap token, permPolicySet_ should be remained", tokenInfoBasic_.tokenID); return; } @@ -268,7 +268,7 @@ void HapTokenInfoInner::SetRemote(bool isRemote) bool HapTokenInfoInner::IsPermDialogForbidden() const { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}d", isPermDialogForbidden_); + LOGI(ATM_DOMAIN, ATM_TAG, "%{public}d", isPermDialogForbidden_); return isPermDialogForbidden_; } @@ -315,12 +315,13 @@ int32_t HapTokenInfoInner::UpdatePermissionStatus( return ret; } if (ShortGrantManager::GetInstance().IsShortGrantPermission(permissionName)) { - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "Short grant permission %{public}s should not be notified to db.", permissionName.c_str()); return RET_SUCCESS; } if (isRemote_) { - ACCESSTOKEN_LOG_INFO(LABEL, "Token %{public}u is remote hap token, will not store.", tokenInfoBasic_.tokenID); + LOGI(ATM_DOMAIN, ATM_TAG, + "Token %{public}u is remote hap token, will not store.", tokenInfoBasic_.tokenID); return RET_SUCCESS; } std::vector permStateValues; @@ -386,7 +387,7 @@ bool HapTokenInfoInner::UpdateStatesToDB(AccessTokenID tokenID, std::vector& dcap) const @@ -80,7 +76,7 @@ int NativeTokenInfoInner::RestoreNativeTokenInfo(AccessTokenID tokenId, const Ge tokenInfoBasic_.tokenID = tokenId; tokenInfoBasic_.processName = inGenericValues.GetString(TokenFiledConst::FIELD_PROCESS_NAME); if (!DataValidator::IsProcessNameValid(tokenInfoBasic_.processName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "tokenID: %{public}u process name is null", tokenInfoBasic_.tokenID); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", HiviewDFX::HiSysEvent::EventType::FAULT, "CODE", LOAD_DATABASE_ERROR, @@ -89,7 +85,7 @@ int NativeTokenInfoInner::RestoreNativeTokenInfo(AccessTokenID tokenId, const Ge } int aplNum = inGenericValues.GetInt(TokenFiledConst::FIELD_APL); if (!DataValidator::IsAplNumValid(aplNum)) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "tokenID: %{public}u apl is error, value %{public}d", tokenInfoBasic_.tokenID, aplNum); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", @@ -100,7 +96,7 @@ int NativeTokenInfoInner::RestoreNativeTokenInfo(AccessTokenID tokenId, const Ge tokenInfoBasic_.apl = static_cast(aplNum); tokenInfoBasic_.ver = (char)inGenericValues.GetInt(TokenFiledConst::FIELD_TOKEN_VERSION); if (tokenInfoBasic_.ver != DEFAULT_TOKEN_VERSION) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "tokenID: %{public}u version is error, version %{public}d", tokenInfoBasic_.tokenID, tokenInfoBasic_.ver); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "PERMISSION_CHECK", diff --git a/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp b/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp index 14de978ae2a9e52dad10971209969e56beab17fe..ca43c2148358cff8a71f7a7892480688fe222363 100644 --- a/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp @@ -32,16 +32,16 @@ namespace Security { namespace AccessToken { namespace { std::recursive_mutex g_instanceMutex; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "NativeTokenReceptor"}; -static const std::string DEFAULT_DEVICEID = "0"; -static const std::string JSON_PROCESS_NAME = "processName"; -static const std::string JSON_APL = "APL"; -static const std::string JSON_VERSION = "version"; -static const std::string JSON_TOKEN_ID = "tokenId"; -static const std::string JSON_TOKEN_ATTR = "tokenAttr"; -static const std::string JSON_DCAPS = "dcaps"; -static const std::string JSON_PERMS = "permissions"; -static const std::string JSON_ACLS = "nativeAcls"; +constexpr const char* NATIVE_TOKEN_CONFIG_FILE = "/data/service/el0/access_token/nativetoken.json"; +constexpr const char* JSON_PROCESS_NAME = "processName"; +constexpr const char* DEFAULT_DEVICEID = "0"; +constexpr const char* JSON_APL = "APL"; +constexpr const char* JSON_VERSION = "version"; +constexpr const char* JSON_TOKEN_ID = "tokenId"; +constexpr const char* JSON_TOKEN_ATTR = "tokenAttr"; +constexpr const char* JSON_DCAPS = "dcaps"; +constexpr const char* JSON_PERMS = "permissions"; +constexpr const char* JSON_ACLS = "nativeAcls"; } int32_t NativeReqPermsGet( @@ -49,12 +49,12 @@ int32_t NativeReqPermsGet( { std::vector permReqList; if (j.find(JSON_PERMS) == j.end() || (!j.at(JSON_PERMS).is_array())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "JSON_PERMS is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "JSON_PERMS is invalid."); return ERR_PARAM_INVALID; } permReqList = j.at(JSON_PERMS).get>(); if (permReqList.size() > MAX_REQ_PERM_NUM) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission num oversize."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission num oversize."); return ERR_OVERSIZE; } std::set permRes; @@ -117,7 +117,7 @@ void from_json(const nlohmann::json& j, std::shared_ptr& p } native.dcap = j.at(JSON_DCAPS).get>(); if (native.dcap.size() > MAX_DCAPS_NUM) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Native dcap oversize."); + LOGE(ATM_DOMAIN, ATM_TAG, "Native dcap oversize."); return; } @@ -126,7 +126,7 @@ void from_json(const nlohmann::json& j, std::shared_ptr& p } native.nativeAcls = j.at(JSON_ACLS).get>(); if (native.nativeAcls.size() > MAX_REQ_PERM_NUM) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission num oversize."); + LOGE(ATM_DOMAIN, ATM_TAG, "Permission num oversize."); return; } @@ -143,7 +143,7 @@ int32_t NativeTokenReceptor::ParserNativeRawData(const std::string& nativeRawDat { nlohmann::json jsonRes = nlohmann::json::parse(nativeRawData, nullptr, false); if (jsonRes.is_discarded()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "JsonRes is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "JsonRes is invalid."); return ERR_PARAM_INVALID; } for (auto it = jsonRes.begin(); it != jsonRes.end(); it++) { @@ -151,7 +151,7 @@ int32_t NativeTokenReceptor::ParserNativeRawData(const std::string& nativeRawDat if (token != nullptr) { tokenInfos.emplace_back(token); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Token is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Token is invalid."); } } return RET_SUCCESS; @@ -162,18 +162,18 @@ int NativeTokenReceptor::Init() std::string nativeRawData; int ret = JsonParser::ReadCfgFile(NATIVE_TOKEN_CONFIG_FILE, nativeRawData); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadCfgFile failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadCfgFile failed."); return ret; } std::vector> tokenInfos; ret = ParserNativeRawData(nativeRawData, tokenInfos); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ParserNativeRawData failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ParserNativeRawData failed."); return ret; } AccessTokenInfoManager::GetInstance().ProcessNativeTokenInfos(tokenInfos); - ACCESSTOKEN_LOG_INFO(LABEL, "Init ok, native token size: %{public}zu.", tokenInfos.size()); + LOGI(ATM_DOMAIN, ATM_TAG, "Init ok, native token size: %{public}zu.", tokenInfos.size()); return RET_SUCCESS; } diff --git a/services/accesstokenmanager/main/cpp/src/token/token_modify_notifier.cpp b/services/accesstokenmanager/main/cpp/src/token/token_modify_notifier.cpp index 612db78c1475f8045e9b2827210e769b9f4a80a6..c20399ed764ad7c952766965784465dc0039f41b 100644 --- a/services/accesstokenmanager/main/cpp/src/token/token_modify_notifier.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/token_modify_notifier.cpp @@ -30,7 +30,6 @@ namespace Security { namespace AccessToken { namespace { std::recursive_mutex g_instanceMutex; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TokenModifyNotifier"}; } #ifdef RESOURCESCHEDULE_FFRT_ENABLE @@ -53,7 +52,7 @@ TokenModifyNotifier::~TokenModifyNotifier() void TokenModifyNotifier::AddHapTokenObservation(AccessTokenID tokenID) { if (AccessTokenIDManager::GetInstance().GetTokenIdType(tokenID) != TOKEN_HAP) { - ACCESSTOKEN_LOG_INFO(LABEL, "Observation token is not hap token"); + LOGI(ATM_DOMAIN, ATM_TAG, "Observation token is not hap token"); return; } Utils::UniqueWriteGuard infoGuard(this->Notifylock_); @@ -66,7 +65,7 @@ void TokenModifyNotifier::NotifyTokenDelete(AccessTokenID tokenID) { Utils::UniqueWriteGuard infoGuard(this->Notifylock_); if (observationSet_.count(tokenID) <= 0) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Hap token is not observed"); + LOGD(ATM_DOMAIN, ATM_TAG, "Hap token is not observed"); return; } observationSet_.erase(tokenID); @@ -78,7 +77,7 @@ void TokenModifyNotifier::NotifyTokenModify(AccessTokenID tokenID) { Utils::UniqueWriteGuard infoGuard(this->Notifylock_); if (observationSet_.count(tokenID) <= 0) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Hap token is not observed"); + LOGD(ATM_DOMAIN, ATM_TAG, "Hap token is not observed"); return; } modifiedTokenList_.emplace_back(tokenID); @@ -111,13 +110,13 @@ TokenModifyNotifier& TokenModifyNotifier::GetInstance() void TokenModifyNotifier::NotifyTokenSyncTask() { - ACCESSTOKEN_LOG_INFO(LABEL, "Called!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Called!"); Utils::UniqueWriteGuard infoGuard(this->Notifylock_); LibraryLoader loader(TOKEN_SYNC_LIBPATH); TokenSyncKitInterface* tokenSyncKit = loader.GetObject(); if (tokenSyncKit == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Dlopen libtokensync_sdk failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Dlopen libtokensync_sdk failed."); return; } for (AccessTokenID deleteToken : deleteTokenList_) { @@ -127,7 +126,7 @@ void TokenModifyNotifier::NotifyTokenSyncTask() } ret = tokenSyncKit->DeleteRemoteHapTokenInfo(deleteToken); if (ret != TOKEN_SYNC_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to delete remote haptoken info, ret is %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to delete remote haptoken info, ret is %{public}d", ret); } } @@ -135,7 +134,7 @@ void TokenModifyNotifier::NotifyTokenSyncTask() HapTokenInfoForSync hapSync; int ret = AccessTokenInfoManager::GetInstance().GetHapTokenSync(modifyToken, hapSync); if (ret != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "The hap token 0x%{public}x need to sync is not found!", modifyToken); + LOGE(ATM_DOMAIN, ATM_TAG, "hap 0x%{public}x need to sync is not found!", modifyToken); continue; } if (tokenSyncCallbackObject_ != nullptr) { @@ -143,13 +142,13 @@ void TokenModifyNotifier::NotifyTokenSyncTask() } ret = tokenSyncKit->UpdateRemoteHapTokenInfo(hapSync); if (ret != TOKEN_SYNC_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to update remote haptoken info, ret is %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to update remote haptoken info, ret is %{public}d", ret); } } deleteTokenList_.clear(); modifiedTokenList_.clear(); - ACCESSTOKEN_LOG_INFO(LABEL, "Over!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Over!"); } int32_t TokenModifyNotifier::GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) @@ -165,7 +164,7 @@ int32_t TokenModifyNotifier::GetRemoteHapTokenInfo(const std::string& deviceID, LibraryLoader loader(TOKEN_SYNC_LIBPATH); TokenSyncKitInterface* tokenSyncKit = loader.GetObject(); if (tokenSyncKit == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Dlopen libtokensync_sdk failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Dlopen libtokensync_sdk failed."); return ERR_LOAD_SO_FAILED; } return tokenSyncKit->GetRemoteHapTokenInfo(deviceID, tokenID); @@ -177,7 +176,7 @@ int32_t TokenModifyNotifier::RegisterTokenSyncCallback(const sptr tokenSyncCallbackObject_ = new TokenSyncCallbackProxy(callback); tokenSyncCallbackDeathRecipient_ = sptr::MakeSptr(); callback->AddDeathRecipient(tokenSyncCallbackDeathRecipient_); - ACCESSTOKEN_LOG_INFO(LABEL, "Register token sync callback successful."); + LOGI(ATM_DOMAIN, ATM_TAG, "Register token sync callback successful."); return ERR_OK; } @@ -189,7 +188,7 @@ int32_t TokenModifyNotifier::UnRegisterTokenSyncCallback() } tokenSyncCallbackObject_ = nullptr; tokenSyncCallbackDeathRecipient_ = nullptr; - ACCESSTOKEN_LOG_INFO(LABEL, "Unregister token sync callback successful."); + LOGI(ATM_DOMAIN, ATM_TAG, "Unregister token sync callback successful."); return ERR_OK; } @@ -201,13 +200,13 @@ int32_t TokenModifyNotifier::GetCurTaskNum() void TokenModifyNotifier::AddCurTaskNum() { - ACCESSTOKEN_LOG_INFO(LABEL, "Add task!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Add task!"); curTaskNum_++; } void TokenModifyNotifier::ReduceCurTaskNum() { - ACCESSTOKEN_LOG_INFO(LABEL, "Reduce task!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Reduce task!"); curTaskNum_--; } #endif @@ -216,7 +215,7 @@ void TokenModifyNotifier::NotifyTokenChangedIfNeed() { #ifdef RESOURCESCHEDULE_FFRT_ENABLE if (GetCurTaskNum() > 1) { - ACCESSTOKEN_LOG_INFO(LABEL, "Has notify task! taskNum is %{public}d.", GetCurTaskNum()); + LOGI(ATM_DOMAIN, ATM_TAG, "Has notify task! taskNum is %{public}d.", GetCurTaskNum()); return; } @@ -229,7 +228,8 @@ void TokenModifyNotifier::NotifyTokenChangedIfNeed() AddCurTaskNum(); #else if (notifyTokenWorker_.GetCurTaskNum() > 1) { - ACCESSTOKEN_LOG_INFO(LABEL, " has notify task! taskNum is %{public}zu.", notifyTokenWorker_.GetCurTaskNum()); + LOGI(ATM_DOMAIN, ATM_TAG, + " has notify task! taskNum is %{public}zu.", notifyTokenWorker_.GetCurTaskNum()); return; } diff --git a/services/accesstokenmanager/test/coverage/BUILD.gn b/services/accesstokenmanager/test/coverage/BUILD.gn index 2062da57856452266fa2454ca4fafa00aa05785d..bcbc566eb4cf53171771a7e03e66bfff53689626 100644 --- a/services/accesstokenmanager/test/coverage/BUILD.gn +++ b/services/accesstokenmanager/test/coverage/BUILD.gn @@ -22,7 +22,6 @@ accesstoken_manager_service_source = [ "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/access_token_db.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/access_token_open_callback.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/data_translator.cpp", - "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/token_field_const.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/form_manager/form_instance.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_client.cpp", diff --git a/services/accesstokenmanager/test/unittest/BUILD.gn b/services/accesstokenmanager/test/unittest/BUILD.gn index fb49955981b2de2dca4466dc2064fb071dccd948..33df6f028333ae2ba12a3acb3123b299fe08c071 100644 --- a/services/accesstokenmanager/test/unittest/BUILD.gn +++ b/services/accesstokenmanager/test/unittest/BUILD.gn @@ -22,7 +22,6 @@ accesstoken_manager_service_source = [ "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/access_token_db.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/access_token_open_callback.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/data_translator.cpp", - "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/token_field_const.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/form_manager/form_instance.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_client.cpp", diff --git a/services/accesstokenmanager/test/unittest/accesstoken_info_manager_test.cpp b/services/accesstokenmanager/test/unittest/accesstoken_info_manager_test.cpp index 40d577ee31dc2610b326b01cbb12faf12a8517b1..d842f5fa652021884a3000c52cebd6275e352b20 100644 --- a/services/accesstokenmanager/test/unittest/accesstoken_info_manager_test.cpp +++ b/services/accesstokenmanager/test/unittest/accesstoken_info_manager_test.cpp @@ -43,9 +43,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenInfoManagerTest" -}; static std::map g_permissionDefinitionMap; static bool g_hasHapPermissionDefinition; static constexpr int32_t DEFAULT_API_VERSION = 8; @@ -240,7 +237,7 @@ HWTEST_F(AccessTokenInfoManagerTest, CreateHapTokenInfo001, TestSize.Level1) */ HWTEST_F(AccessTokenInfoManagerTest, CreateHapTokenInfo002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "AddHapToken001 fill data"); + LOGI(ATM_DOMAIN, ATM_TAG, "AddHapToken001 fill data"); AccessTokenIDEx tokenIdEx = {0}; int ret = AccessTokenInfoManager::GetInstance().CreateHapTokenInfo(g_infoManagerTestInfoParms, diff --git a/services/accesstokenmanager/test/unittest/multi_thread_test.cpp b/services/accesstokenmanager/test/unittest/multi_thread_test.cpp index 04a0eecbc9c520d4b721879d575ee55cc30603a7..05f3af09c2bff3dc99070b4cd30587ecd160e0cd 100644 --- a/services/accesstokenmanager/test/unittest/multi_thread_test.cpp +++ b/services/accesstokenmanager/test/unittest/multi_thread_test.cpp @@ -37,8 +37,6 @@ static std::set g_tokenIdSet; static constexpr int32_t TEST_TOKEN_ID_1 = 537800000; static constexpr int32_t TEST_TOKEN_ID_2 = 537900000; static constexpr int32_t MULTI_CYCLE_TIMES = 1000; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenMultiThreadTest"}; } void AccessTokenMultiThreadTest::SetUpTestCase() @@ -51,7 +49,7 @@ void AccessTokenMultiThreadTest::TearDownTestCase() void AccessTokenMultiThreadTest::SetUp() { - ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); + LOGI(ATM_DOMAIN, ATM_TAG, "SetUp ok."); g_tokenIdSet = AccessTokenIDManager::GetInstance().tokenIdSet_; AccessTokenIDManager::GetInstance().tokenIdSet_.clear(); } diff --git a/services/accesstokenmanager/test/unittest/native_token_receptor_test.cpp b/services/accesstokenmanager/test/unittest/native_token_receptor_test.cpp index c6f5061cade7ce8e3a15b0bd8ed3b6e786661644..c7bcc9160af5a0b5f6142aefc81c5b7a7c1fb962 100644 --- a/services/accesstokenmanager/test/unittest/native_token_receptor_test.cpp +++ b/services/accesstokenmanager/test/unittest/native_token_receptor_test.cpp @@ -42,10 +42,6 @@ using namespace testing::ext; using namespace OHOS::Security::AccessToken; -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "NativeTokenReceptorTest"}; -} - void NativeTokenReceptorTest::SetUpTestCase() { // delete all test 0x28100000 - 0x28100007 @@ -81,7 +77,7 @@ void NativeTokenReceptorTest::SetUp() void NativeTokenReceptorTest::TearDown() { - ACCESSTOKEN_LOG_INFO(LABEL, "test down!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test down!"); } /** @@ -92,7 +88,7 @@ void NativeTokenReceptorTest::TearDown() */ HWTEST_F(NativeTokenReceptorTest, ParserNativeRawData001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test ParserNativeRawData001!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test ParserNativeRawData001!"); std::string testStr = R"([)"\ R"({"processName":"process6","APL":3,"version":1,"tokenId":685266937,"tokenAttr":0,)"\ R"("dcaps":["AT_CAP","ST_CAP"], "permissions":[], "nativeAcls":[]},)"\ @@ -121,7 +117,7 @@ HWTEST_F(NativeTokenReceptorTest, ParserNativeRawData001, TestSize.Level1) */ HWTEST_F(NativeTokenReceptorTest, ParserNativeRawData002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test ParserNativeRawData002!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test ParserNativeRawData002!"); std::string testStr = R"([{"processName":""}])"; std::vector> tokenInfos; @@ -184,7 +180,7 @@ namespace AccessToken { */ HWTEST_F(NativeTokenReceptorTest, from_json001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test from_json001!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test from_json001!"); nlohmann::json j = nlohmann::json{ {"processName", "process6"}, {"APL", APL_SYSTEM_CORE}, @@ -207,7 +203,7 @@ HWTEST_F(NativeTokenReceptorTest, from_json001, TestSize.Level1) */ HWTEST_F(NativeTokenReceptorTest, from_json002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test from_json002!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test from_json002!"); // version wrong nlohmann::json j = nlohmann::json{ {"processName", "process6"}, {"APL", APL_SYSTEM_CORE}, @@ -272,7 +268,7 @@ HWTEST_F(NativeTokenReceptorTest, from_json002, TestSize.Level1) */ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test ProcessNativeTokenInfos001!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test ProcessNativeTokenInfos001!"); std::vector> tokenInfos; // test process one @@ -369,7 +365,7 @@ static void CompareGoalTokenInfo(const NativeTokenInfoBase &info) */ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test ProcessNativeTokenInfos002!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test ProcessNativeTokenInfos002!"); std::vector> tokenInfos; NativeTokenInfoBase info1; info1.apl = APL_NORMAL; @@ -439,7 +435,7 @@ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos002, TestSize.Level1) */ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos003, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test ProcessNativeTokenInfos003!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test ProcessNativeTokenInfos003!"); std::vector> tokenInfos; std::shared_ptr nativeToken1 = std::make_shared(); @@ -456,7 +452,7 @@ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos003, TestSize.Level1) */ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos004, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test ProcessNativeTokenInfos004!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test ProcessNativeTokenInfos004!"); std::vector> tokenInfos; NativeTokenInfoBase info3 = { @@ -503,7 +499,7 @@ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos004, TestSize.Level1) */ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos005, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test ProcessNativeTokenInfos005!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test ProcessNativeTokenInfos005!"); std::vector> tokenInfos; NativeTokenInfoBase info5 = { @@ -553,7 +549,7 @@ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos005, TestSize.Level1) */ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos006, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test ProcessNativeTokenInfos006!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test ProcessNativeTokenInfos006!"); std::vector> tokenInfos; NativeTokenInfoBase info7 = { @@ -600,7 +596,7 @@ HWTEST_F(NativeTokenReceptorTest, ProcessNativeTokenInfos006, TestSize.Level1) */ HWTEST_F(NativeTokenReceptorTest, init001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "test init001!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test init001!"); const char *dcaps[1]; dcaps[0] = "AT_CAP_01"; diff --git a/services/accesstokenmanager/test/unittest/permission_definition_parser_test.cpp b/services/accesstokenmanager/test/unittest/permission_definition_parser_test.cpp index 775766c2b81049412f7efb22202a295e10ee90e7..d5ff94f2ca93c348e5bbf3d69833b0d3ffc78696 100644 --- a/services/accesstokenmanager/test/unittest/permission_definition_parser_test.cpp +++ b/services/accesstokenmanager/test/unittest/permission_definition_parser_test.cpp @@ -48,8 +48,6 @@ namespace { static bool g_hasHapPermissionDefinition; static std::map g_permissionDefinitionMap; static const int32_t EXTENSION_PERMISSION_ID = 0; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "PermissionDefinitionParserTest"}; static const std::string SYSTEM_PERMISSION_A = "ohos.permission.PermDefParserTestA"; static const std::string USER_PERMISSION_B = "ohos.permission.PermDefParserTestB"; } @@ -74,7 +72,7 @@ void PermissionDefinitionParserTest::TearDown() { PermissionDefinitionCache::GetInstance().permissionDefinitionMap_ = g_permissionDefinitionMap; // recovery PermissionDefinitionCache::GetInstance().hasHapPermissionDefinition_ = g_hasHapPermissionDefinition; - ACCESSTOKEN_LOG_INFO(LABEL, "test down!"); + LOGI(ATM_DOMAIN, ATM_TAG, "test down!"); } /** diff --git a/services/accesstokenmanager/test/unittest/permission_grant_event_test.cpp b/services/accesstokenmanager/test/unittest/permission_grant_event_test.cpp index 8452b346a3795db921232c94e422c6f238890528..57eb3e48ecd32108b7d2efd3268a8c3ccd802c07 100644 --- a/services/accesstokenmanager/test/unittest/permission_grant_event_test.cpp +++ b/services/accesstokenmanager/test/unittest/permission_grant_event_test.cpp @@ -22,11 +22,6 @@ using namespace testing::ext; using namespace OHOS::Security::AccessToken; -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PermissionGrantEventTest"}; -} - void PermissionGrantEventTest::SetUpTestCase() {} @@ -49,7 +44,7 @@ void PermissionGrantEventTest::TearDown() */ HWTEST_F(PermissionGrantEventTest, NotifyPermGrantStoreResult001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "NotifyPermGrantStoreResult001!"); + LOGI(ATM_DOMAIN, ATM_TAG, "NotifyPermGrantStoreResult001!"); AccessTokenID tokenID = 0x100000; std::string permissionName = "testpremission"; uint64_t time; @@ -71,7 +66,7 @@ HWTEST_F(PermissionGrantEventTest, NotifyPermGrantStoreResult001, TestSize.Level */ HWTEST_F(PermissionGrantEventTest, NotifyPermGrantStoreResult002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "NotifyPermGrantStoreResult002!"); + LOGI(ATM_DOMAIN, ATM_TAG, "NotifyPermGrantStoreResult002!"); AccessTokenID tokenID = 0x100000; std::string permissionName = "testpremission"; uint64_t time; @@ -93,7 +88,7 @@ HWTEST_F(PermissionGrantEventTest, NotifyPermGrantStoreResult002, TestSize.Level */ HWTEST_F(PermissionGrantEventTest, NotifyPermGrantStoreResult003, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "NotifyPermGrantStoreResult003!"); + LOGI(ATM_DOMAIN, ATM_TAG, "NotifyPermGrantStoreResult003!"); AccessTokenID tokenID = 0x100000; std::string permissionName = "testpremission"; uint64_t time; diff --git a/services/common/ability_manager/src/ability_manager_adapter.cpp b/services/common/ability_manager/src/ability_manager_adapter.cpp index 44dd7187840be22f0c93412bab5af21e7e476154..52d4826934ae3e2a3e66434adb70dcbef2f6b2ff 100644 --- a/services/common/ability_manager/src/ability_manager_adapter.cpp +++ b/services/common/ability_manager/src/ability_manager_adapter.cpp @@ -25,9 +25,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AbilityManagerAdapter" -}; const int32_t DEFAULT_INVAL_VALUE = -1; const std::u16string ABILITY_MGR_DESCRIPTOR = u"ohos.aafwk.AbilityManager"; } @@ -48,7 +45,7 @@ int32_t AbilityManagerAdapter::StartAbility(const AAFwk::Want &want, const sptr< { auto abms = GetProxy(); if (abms == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to GetProxy."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to GetProxy."); return AccessTokenError::ERR_WRITE_PARCEL_FAILED; } @@ -57,26 +54,26 @@ int32_t AbilityManagerAdapter::StartAbility(const AAFwk::Want &want, const sptr< MessageOption option; if (!data.WriteInterfaceToken(ABILITY_MGR_DESCRIPTOR)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write WriteInterfaceToken."); return AccessTokenError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteParcelable(&want)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Want write failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Want write failed."); return AccessTokenError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteInt32(DEFAULT_INVAL_VALUE)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UserId write failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "UserId write failed."); return AccessTokenError::ERR_WRITE_PARCEL_FAILED; } if (!data.WriteInt32(DEFAULT_INVAL_VALUE)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RequestCode write failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "RequestCode write failed."); return AccessTokenError::ERR_WRITE_PARCEL_FAILED; } int32_t error = abms->SendRequest(static_cast(AbilityManagerInterfaceCode::START_ABILITY), data, reply, option); if (error != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest error: %{public}d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "SendRequest error: %{public}d", error); return error; } return reply.ReadInt32(); @@ -89,22 +86,22 @@ void AbilityManagerAdapter::InitProxy() } sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemManager == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get system ability registry."); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get system ability registry."); return; } sptr remoteObj = systemManager->CheckSystemAbility(ABILITY_MGR_SERVICE_ID); if (remoteObj == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to connect ability manager service."); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to connect ability manager service."); return; } deathRecipient_ = sptr(new (std::nothrow) AbilityMgrDeathRecipient()); if (deathRecipient_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create AbilityMgrDeathRecipient!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create AbilityMgrDeathRecipient!"); return; } if ((remoteObj->IsProxyObject()) && (!remoteObj->AddDeathRecipient(deathRecipient_))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Add death recipient to AbilityManagerService failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Add death recipient to AbilityManagerService failed."); return; } proxy_ = remoteObj; @@ -131,7 +128,7 @@ void AbilityManagerAdapter::ReleaseProxy(const wptr& remote) void AbilityManagerAdapter::AbilityMgrDeathRecipient::OnRemoteDied(const wptr& remote) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AbilityMgrDeathRecipient handle remote died."); + LOGE(ATM_DOMAIN, ATM_TAG, "AbilityMgrDeathRecipient handle remote died."); AbilityManagerAdapter::GetInstance().ReleaseProxy(remote); } } // namespace AccessToken diff --git a/services/common/app_manager/src/ams_manager_access_proxy.cpp b/services/common/app_manager/src/ams_manager_access_proxy.cpp index 4f1d6a064bd1ea4ce221ea0d9309df708443a4aa..5176a7627f20a9419d2ec0f62ae866f8d6dcdef0 100644 --- a/services/common/app_manager/src/ams_manager_access_proxy.cpp +++ b/services/common/app_manager/src/ams_manager_access_proxy.cpp @@ -20,7 +20,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AmsManagerAccessProxy"}; static constexpr int32_t ERROR = -1; } int32_t AmsManagerAccessProxy::KillProcessesByAccessTokenId(const uint32_t accessTokenId) @@ -29,23 +28,23 @@ int32_t AmsManagerAccessProxy::KillProcessesByAccessTokenId(const uint32_t acces MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed."); return ERROR; } if (!data.WriteInt32(accessTokenId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return ERROR; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return ERROR; } int32_t error = remote->SendRequest( static_cast(IAmsMgr::Message::FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "KillProcessesByAccessTokenId failed, error: %{public}d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "KillProcessesByAccessTokenId failed, error: %{public}d", error); return ERROR; } return reply.ReadInt32(); diff --git a/services/common/app_manager/src/app_manager_access_client.cpp b/services/common/app_manager/src/app_manager_access_client.cpp index ed3118ad51c5967c7faadea6393dc71b5e70e9d1..e45ce6d3b4d30e9b77c1ae498d3b53ab6ded7cb7 100644 --- a/services/common/app_manager/src/app_manager_access_client.cpp +++ b/services/common/app_manager/src/app_manager_access_client.cpp @@ -23,9 +23,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AppManagerAccessClient" -}; static constexpr int32_t ERROR = -1; std::recursive_mutex g_instanceMutex; } // namespace @@ -56,12 +53,12 @@ int32_t AppManagerAccessClient::KillProcessesByAccessTokenId(const uint32_t acce { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return ERROR; } sptr amsService = proxy->GetAmsMgr(); if (amsService == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AmsService is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "AmsService is null."); return ERROR; } return amsService->KillProcessesByAccessTokenId(accessTokenId); @@ -69,14 +66,14 @@ int32_t AppManagerAccessClient::KillProcessesByAccessTokenId(const uint32_t acce int32_t AppManagerAccessClient::RegisterApplicationStateObserver(const sptr& observer) { - ACCESSTOKEN_LOG_INFO(LABEL, "Entry"); + LOGI(ATM_DOMAIN, ATM_TAG, "Entry"); if (observer == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "Callback is nullptr."); return ERROR; } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null."); return ERROR; } std::vector bundleNameList; @@ -86,12 +83,12 @@ int32_t AppManagerAccessClient::RegisterApplicationStateObserver(const sptr &observer) { if (observer == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "Callback is nullptr."); return ERROR; } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return ERROR; } return proxy->UnregisterApplicationStateObserver(observer); @@ -101,7 +98,7 @@ int32_t AppManagerAccessClient::GetForegroundApplications(std::vectorGetForegroundApplications(list); @@ -111,12 +108,12 @@ void AppManagerAccessClient::InitProxy() { auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (sam == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbilityManager is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "GetSystemAbilityManager is null"); return; } auto appManagerSa = sam->GetSystemAbility(APP_MGR_SERVICE_ID); if (appManagerSa == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbility %{public}d is null", + LOGE(ATM_DOMAIN, ATM_TAG, "GetSystemAbility %{public}d is null", APP_MGR_SERVICE_ID); return; } @@ -128,7 +125,7 @@ void AppManagerAccessClient::InitProxy() proxy_ = new AppManagerAccessProxy(appManagerSa); if (proxy_ == nullptr || proxy_->AsObject() == nullptr || proxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Iface_cast get null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Iface_cast get null"); } } @@ -136,7 +133,7 @@ void AppManagerAccessClient::RegisterDeathCallback(const std::shared_ptr lock(deathCallbackMutex_); if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AppManagerAccessClient: Callback is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "AppManagerAccessClient: Callback is nullptr."); return; } appManagerDeathCallbackList_.emplace_back(callback); diff --git a/services/common/app_manager/src/app_manager_access_proxy.cpp b/services/common/app_manager/src/app_manager_access_proxy.cpp index 6ccb979d93e533c6eaa1942feb51387154089761..8e59e7704746242a5a0c7e29ff4b93fe3e905398 100644 --- a/services/common/app_manager/src/app_manager_access_proxy.cpp +++ b/services/common/app_manager/src/app_manager_access_proxy.cpp @@ -20,7 +20,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AppManagerAccessProxy"}; static constexpr int32_t ERROR = -1; constexpr int32_t CYCLE_LIMIT = 1000; } @@ -35,19 +34,19 @@ sptr AppManagerAccessProxy::GetAmsMgr() } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return nullptr; } int32_t error = remote->SendRequest( static_cast(IAppMgr::Message::APP_GET_MGR_INSTANCE), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetAmsMgr failed, error: %{public}d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "GetAmsMgr failed, error: %{public}d", error); return nullptr; } sptr object = reply.ReadRemoteObject(); sptr amsMgr = new AmsManagerAccessProxy(object); if (!amsMgr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Ability manager service instance is nullptr. "); + LOGE(ATM_DOMAIN, ATM_TAG, "Ability manager service instance is nullptr. "); return nullptr; } return amsMgr; @@ -60,26 +59,26 @@ int32_t AppManagerAccessProxy::RegisterApplicationStateObserver(const sptrAsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Observer write failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Observer write failed."); return ERROR; } if (!data.WriteStringVector(bundleNameList)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "BundleNameList write failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "BundleNameList write failed."); return ERROR; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return ERROR; } int32_t error = remote->SendRequest( static_cast(IAppMgr::Message::REGISTER_APPLICATION_STATE_OBSERVER), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RegisterAppStatus failed, error: %{public}d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "RegisterAppStatus failed, error: %{public}d", error); return ERROR; } return reply.ReadInt32(); @@ -92,22 +91,22 @@ int32_t AppManagerAccessProxy::UnregisterApplicationStateObserver( MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed"); return ERROR; } if (!data.WriteRemoteObject(observer->AsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Observer write failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Observer write failed."); return ERROR; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return ERROR; } int32_t error = remote->SendRequest( static_cast(IAppMgr::Message::UNREGISTER_APPLICATION_STATE_OBSERVER), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Set microphoneMute failed, error: %d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "Set microphoneMute failed, error: %d", error); return error; } return reply.ReadInt32(); @@ -119,23 +118,23 @@ int32_t AppManagerAccessProxy::GetForegroundApplications(std::vector remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return ERROR; } int32_t error = remote->SendRequest( static_cast(IAppMgr::Message::GET_FOREGROUND_APPLICATIONS), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetForegroundApplications failed, error: %{public}d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "GetForegroundApplications failed, error: %{public}d", error); return error; } uint32_t infoSize = reply.ReadUint32(); if (infoSize > CYCLE_LIMIT) { - ACCESSTOKEN_LOG_ERROR(LABEL, "InfoSize is too large"); + LOGE(ATM_DOMAIN, ATM_TAG, "InfoSize is too large"); return ERROR; } for (uint32_t i = 0; i < infoSize; i++) { diff --git a/services/common/app_manager/src/app_manager_death_recipient.cpp b/services/common/app_manager/src/app_manager_death_recipient.cpp index 86870441df3b398bb11ce7800f5aa0a63a7e7e8c..02203a1a942455c7cea34916ff97a38659f67658 100644 --- a/services/common/app_manager/src/app_manager_death_recipient.cpp +++ b/services/common/app_manager/src/app_manager_death_recipient.cpp @@ -20,15 +20,9 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AppMgrDeathRecipient" -}; -} // namespace - void AppMgrDeathRecipient::OnRemoteDied(const wptr& object) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called", __func__); + LOGI(ATM_DOMAIN, ATM_TAG, "%{public}s called", __func__); AppManagerAccessClient::GetInstance().OnRemoteDiedHandle(); } } // namespace AccessToken diff --git a/services/common/app_manager/src/app_status_change_callback.cpp b/services/common/app_manager/src/app_status_change_callback.cpp index b25caf1b61518b365225faab250c7ca5b0b6d137..047f701aa1ee2da4f74d0e3dbdc251c6fc5f9cf9 100644 --- a/services/common/app_manager/src/app_status_change_callback.cpp +++ b/services/common/app_manager/src/app_status_change_callback.cpp @@ -20,27 +20,21 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "ApplicationStateObserverStub" -}; -} - ApplicationStateObserverStub::ApplicationStateObserverStub() { - ACCESSTOKEN_LOG_INFO(LABEL, "ApplicationStateObserverStub Instance create"); + LOGI(ATM_DOMAIN, ATM_TAG, "ApplicationStateObserverStub Instance create"); } ApplicationStateObserverStub::~ApplicationStateObserverStub() { - ACCESSTOKEN_LOG_INFO(LABEL, "ApplicationStateObserverStub Instance destroy"); + LOGI(ATM_DOMAIN, ATM_TAG, "ApplicationStateObserverStub Instance destroy"); } int32_t ApplicationStateObserverStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { if (data.ReadInterfaceToken() != GetDescriptor()) { - ACCESSTOKEN_LOG_INFO(LABEL, "ApplicationStateObserverStub: ReadInterfaceToken failed"); + LOGI(ATM_DOMAIN, ATM_TAG, "ApplicationStateObserverStub: ReadInterfaceToken failed"); return ERROR_IPC_REQUEST_FAIL; } switch (static_cast(code)) { @@ -65,7 +59,7 @@ int32_t ApplicationStateObserverStub::OnRemoteRequest( return NO_ERROR; } default: { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Default case, need check AudioListenerStub"); + LOGD(ATM_DOMAIN, ATM_TAG, "Default case, need check AudioListenerStub"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } @@ -76,7 +70,7 @@ int32_t ApplicationStateObserverStub::HandleOnProcessStateChanged(MessageParcel { std::unique_ptr processData(data.ReadParcelable()); if (processData == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed"); return -1; } @@ -88,7 +82,7 @@ int32_t ApplicationStateObserverStub::HandleOnProcessDied(MessageParcel &data, M { std::unique_ptr processData(data.ReadParcelable()); if (processData == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed"); return -1; } @@ -100,7 +94,7 @@ int32_t ApplicationStateObserverStub::HandleOnAppStateChanged(MessageParcel &dat { std::unique_ptr processData(data.ReadParcelable()); if (processData == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed"); return -1; } @@ -112,7 +106,7 @@ int32_t ApplicationStateObserverStub::HandleOnAppStopped(MessageParcel &data, Me { std::unique_ptr appStateData(data.ReadParcelable()); if (appStateData == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed"); return -1; } diff --git a/services/common/background_task_manager/src/background_task_manager_access_client.cpp b/services/common/background_task_manager/src/background_task_manager_access_client.cpp index 4307b3c4dd97fd4f0a091c563a55b2e714855b5f..ff85fc1549a17c7bd2346996f3f26da517c03079 100644 --- a/services/common/background_task_manager/src/background_task_manager_access_client.cpp +++ b/services/common/background_task_manager/src/background_task_manager_access_client.cpp @@ -22,9 +22,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "BackgourndTaskManagerAccessClient" -}; static constexpr int32_t ERROR = -1; std::recursive_mutex g_instanceMutex; } // namespace @@ -54,12 +51,12 @@ BackgourndTaskManagerAccessClient::~BackgourndTaskManagerAccessClient() int32_t BackgourndTaskManagerAccessClient::SubscribeBackgroundTask(const sptr& subscriber) { if (subscriber == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "Callback is nullptr."); return ERROR; } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return ERROR; } return proxy->SubscribeBackgroundTask(subscriber); @@ -68,12 +65,12 @@ int32_t BackgourndTaskManagerAccessClient::SubscribeBackgroundTask(const sptr& subscriber) { if (subscriber == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is nullptr."); + LOGE(ATM_DOMAIN, ATM_TAG, "Callback is nullptr."); return ERROR; } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return ERROR; } return proxy->UnsubscribeBackgroundTask(subscriber); @@ -84,7 +81,7 @@ int32_t BackgourndTaskManagerAccessClient::GetContinuousTaskApps( { auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Proxy is null"); return ERROR; } return proxy->GetContinuousTaskApps(list); @@ -94,12 +91,12 @@ void BackgourndTaskManagerAccessClient::InitProxy() { auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (sam == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbilityManager is null"); + LOGE(ATM_DOMAIN, ATM_TAG, "GetSystemAbilityManager is null"); return; } auto backgroundTaskManagerSa = sam->GetSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID); if (backgroundTaskManagerSa == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbility %{public}d is null", + LOGE(ATM_DOMAIN, ATM_TAG, "GetSystemAbility %{public}d is null", BACKGROUND_TASK_MANAGER_SERVICE_ID); return; } @@ -111,7 +108,7 @@ void BackgourndTaskManagerAccessClient::InitProxy() proxy_ = new BackgroundTaskManagerAccessProxy(backgroundTaskManagerSa); if (proxy_ == nullptr || proxy_->AsObject() == nullptr || proxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Iface_cast get null"); + LOGE(ATM_DOMAIN, ATM_TAG, "Iface_cast get null"); } } diff --git a/services/common/background_task_manager/src/background_task_manager_access_proxy.cpp b/services/common/background_task_manager/src/background_task_manager_access_proxy.cpp index a6a465ca000fa7759dd413281aa0ab6d4b602699..7aefbfda455f5e4a2eb06d70130de40ee38617e9 100644 --- a/services/common/background_task_manager/src/background_task_manager_access_proxy.cpp +++ b/services/common/background_task_manager/src/background_task_manager_access_proxy.cpp @@ -21,7 +21,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "BackgroundTaskManagerAccessProxy"}; static constexpr int32_t ERROR = -1; static constexpr int32_t MAX_CALLBACK_NUM = 10 * 1024; } @@ -32,27 +31,27 @@ int32_t BackgroundTaskManagerAccessProxy::SubscribeBackgroundTask(const sptrAsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write callerToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write callerToken failed."); return ERROR; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return ERROR; } int32_t error = remote->SendRequest( static_cast(IBackgroundTaskMgr::Message::SUBSCRIBE_BACKGROUND_TASK), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Regist background task observer failed, error: %{public}d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "Regist background task observer failed, error: %{public}d", error); return ERROR; } int32_t result; if (!reply.ReadInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return ERROR; } return result; @@ -64,27 +63,27 @@ int32_t BackgroundTaskManagerAccessProxy::UnsubscribeBackgroundTask(const sptrAsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write callerToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Write callerToken failed."); return ERROR; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return ERROR; } int32_t error = remote->SendRequest( static_cast(IBackgroundTaskMgr::Message::UNSUBSCRIBE_BACKGROUND_TASK), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Unregist background task observer failed, error: %d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "Unregist background task observer failed, error: %d", error); return error; } int32_t result; if (!reply.ReadInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return ERROR; } return result; @@ -97,38 +96,38 @@ int32_t BackgroundTaskManagerAccessProxy::GetContinuousTaskApps( MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed"); return ERROR; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null."); return ERROR; } int32_t error = remote->SendRequest( static_cast(IBackgroundTaskMgr::Message::GET_CONTINUOUS_TASK_APPS), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get continuous task apps failed, error: %{public}d", error); + LOGE(ATM_DOMAIN, ATM_TAG, "Get continuous task apps failed, error: %{public}d", error); return ERROR; } int32_t result; if (!reply.ReadInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return ERROR; } if (result != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetContinuousTaskApps failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "GetContinuousTaskApps failed."); return result; } int32_t infoSize = reply.ReadInt32(); if ((infoSize < 0) || (infoSize > MAX_CALLBACK_NUM)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "InfoSize:%{public}d invalid.", infoSize); + LOGE(ATM_DOMAIN, ATM_TAG, "InfoSize:%{public}d invalid.", infoSize); return ERROR; } for (int32_t i = 0; i < infoSize; i++) { auto info = ContinuousTaskCallbackInfo::Unmarshalling(reply); if (info == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to Read Parcelable infos."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Read Parcelable infos."); return ERROR; } list.emplace_back(info); diff --git a/services/common/background_task_manager/src/background_task_manager_death_recipient.cpp b/services/common/background_task_manager/src/background_task_manager_death_recipient.cpp index 461a6e517e8be26271684d5dd433879c210cd721..5d3d7685a31962a629b81567115b839df8f0ad59 100644 --- a/services/common/background_task_manager/src/background_task_manager_death_recipient.cpp +++ b/services/common/background_task_manager/src/background_task_manager_death_recipient.cpp @@ -20,15 +20,9 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "BackgroundTaskMgrDeathRecipient" -}; -} // namespace - void BackgroundTaskMgrDeathRecipient::OnRemoteDied(const wptr& object) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called", __func__); + LOGI(ATM_DOMAIN, ATM_TAG, "%{public}s called", __func__); BackgourndTaskManagerAccessClient::GetInstance().OnRemoteDiedHandle(); } } // namespace AccessToken diff --git a/services/common/background_task_manager/src/continuous_task_callback_info.cpp b/services/common/background_task_manager/src/continuous_task_callback_info.cpp index 171f500515f5bce4aa6023dce8903ef578c8181f..35de72facbf0be24ffcf5bd560d57c19c2c6c9ee 100644 --- a/services/common/background_task_manager/src/continuous_task_callback_info.cpp +++ b/services/common/background_task_manager/src/continuous_task_callback_info.cpp @@ -20,56 +20,51 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "ContinuousTaskCallbackInfo" -}; -} // namespace bool ContinuousTaskCallbackInfo::Marshalling(Parcel &parcel) const { if (!parcel.WriteUint32(typeId_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint32 failed."); return false; } if (!parcel.WriteInt32(creatorUid_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return false; } if (!parcel.WriteInt32(creatorPid_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return false; } if (!parcel.WriteBool(isFromWebview_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteBool failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteBool failed."); return false; } std::u16string u16AbilityName = Str8ToStr16(abilityName_); if (!parcel.WriteString16(u16AbilityName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString16 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteString16 failed."); return false; } if (!parcel.WriteBool(isBatchApi_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteBool failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteBool failed."); return false; } if (!parcel.WriteUInt32Vector(typeIds_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUInt32Vector failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUInt32Vector failed."); return false; } if (!parcel.WriteInt32(abilityId_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteInt32 failed."); return false; } if (!parcel.WriteUint64(tokenId_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint64 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "WriteUint64 failed."); return false; } return true; @@ -89,51 +84,51 @@ ContinuousTaskCallbackInfo *ContinuousTaskCallbackInfo::Unmarshalling(Parcel &pa bool ContinuousTaskCallbackInfo::ReadFromParcel(Parcel &parcel) { if (!parcel.ReadUint32(typeId_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadUint32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadUint32 failed."); return false; } if (!parcel.ReadInt32(creatorUid_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return false; } int32_t pid; if (!parcel.ReadInt32(pid)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return false; } creatorPid_ = static_cast(pid); if (!parcel.ReadBool(isFromWebview_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadBool failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadBool failed."); return false; } std::u16string u16AbilityName; if (!parcel.ReadString16(u16AbilityName)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadString16 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadString16 failed."); return false; } abilityName_ = Str16ToStr8(u16AbilityName); if (!parcel.ReadBool(isBatchApi_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadBool failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadBool failed."); return false; } if (!parcel.ReadUInt32Vector(&typeIds_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadUInt32Vector failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadUInt32Vector failed."); return false; } if (!parcel.ReadInt32(abilityId_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadInt32 failed."); return false; } if (!parcel.ReadUint64(tokenId_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadUint64 failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadUint64 failed."); return false; } return true; diff --git a/services/common/background_task_manager/src/continuous_task_change_callback.cpp b/services/common/background_task_manager/src/continuous_task_change_callback.cpp index e7c8efe3f33ec49eeffa64f382a56711cf3e755a..72fb30fd9fc9ec1c899ecbcbd651c944b6fa660d 100644 --- a/services/common/background_task_manager/src/continuous_task_change_callback.cpp +++ b/services/common/background_task_manager/src/continuous_task_change_callback.cpp @@ -22,27 +22,21 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "BackgroundTaskSubscriberStub" -}; -} - BackgroundTaskSubscriberStub::BackgroundTaskSubscriberStub() { - ACCESSTOKEN_LOG_INFO(LABEL, "BackgroundTaskSubscriberStub Instance create."); + LOGI(ATM_DOMAIN, ATM_TAG, "BackgroundTaskSubscriberStub Instance create."); } BackgroundTaskSubscriberStub::~BackgroundTaskSubscriberStub() { - ACCESSTOKEN_LOG_INFO(LABEL, "BackgroundTaskSubscriberStub Instance destroy."); + LOGI(ATM_DOMAIN, ATM_TAG, "BackgroundTaskSubscriberStub Instance destroy."); } int32_t BackgroundTaskSubscriberStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { if (data.ReadInterfaceToken() != GetDescriptor()) { - ACCESSTOKEN_LOG_INFO(LABEL, "BackgroundTaskSubscriberStub: ReadInterfaceToken failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "BackgroundTaskSubscriberStub: ReadInterfaceToken failed."); return ERROR_IPC_REQUEST_FAIL; } switch (static_cast(code)) { @@ -55,7 +49,7 @@ int32_t BackgroundTaskSubscriberStub::OnRemoteRequest( return NO_ERROR; } default: { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Default case code: %{public}d.", code); + LOGD(ATM_DOMAIN, ATM_TAG, "Default case code: %{public}d.", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } @@ -67,7 +61,7 @@ void BackgroundTaskSubscriberStub::HandleOnContinuousTaskStart(MessageParcel &da std::shared_ptr continuousTaskCallbackInfo( data.ReadParcelable()); if (continuousTaskCallbackInfo == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed."); return; } OnContinuousTaskStart(continuousTaskCallbackInfo); @@ -78,7 +72,7 @@ void BackgroundTaskSubscriberStub::HandleOnContinuousTaskStop(MessageParcel &dat std::shared_ptr continuousTaskCallbackInfo( data.ReadParcelable()); if (continuousTaskCallbackInfo == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed."); return; } OnContinuousTaskStop(continuousTaskCallbackInfo); diff --git a/services/common/config_policy/src/config_policy_loader.cpp b/services/common/config_policy/src/config_policy_loader.cpp index 12b797fa46b146f4777ba235ec5535aba55da107..55231a9002e2f80f2f573b0a325e375547b1a676 100644 --- a/services/common/config_policy/src/config_policy_loader.cpp +++ b/services/common/config_policy/src/config_policy_loader.cpp @@ -25,7 +25,6 @@ namespace Security { namespace AccessToken { namespace { #ifdef CUSTOMIZATION_CONFIG_POLICY_ENABLE -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "ConfigPolicLoader"}; static constexpr const char* ACCESSTOKEN_CONFIG_FILE = "/etc/access_token/accesstoken_config.json"; static constexpr const char* PERMISSION_MANAGER_BUNDLE_NAME_KEY = "permission_manager_bundle_name"; @@ -49,7 +48,7 @@ void ConfigPolicLoader::GetConfigFilePathList(std::vector& pathList { CfgDir *dirs = GetCfgDirList(); // malloc a CfgDir point, need to free later if (dirs == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Can't get cfg file path."); + LOGE(ATM_DOMAIN, ATM_TAG, "Can't get cfg file path."); return; } @@ -58,7 +57,7 @@ void ConfigPolicLoader::GetConfigFilePathList(std::vector& pathList continue; } - ACCESSTOKEN_LOG_INFO(LABEL, "Accesstoken cfg dir: %{public}s.", path); + LOGI(ATM_DOMAIN, ATM_TAG, "Accesstoken cfg dir: %{public}s.", path); pathList.emplace_back(path); } @@ -123,7 +122,7 @@ bool ConfigPolicLoader::GetConfigValueFromFile(const ServiceType& type, const st { nlohmann::json jsonRes = nlohmann::json::parse(fileContent, nullptr, false); if (jsonRes.is_discarded()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "JsonRes is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "JsonRes is invalid."); return false; } @@ -164,13 +163,13 @@ bool ConfigPolicLoader::GetConfigValue(const ServiceType& type, AccessTokenConfi std::string fileContent; int32_t res = JsonParser::ReadCfgFile(filePath, fileContent); if (res != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read Cfg file [%{public}s] failed, error(%{public}d).", + LOGE(ATM_DOMAIN, ATM_TAG, "Read Cfg file [%{public}s] failed, error(%{public}d).", filePath.c_str(), res); continue; } if (GetConfigValueFromFile(type, fileContent, config)) { - ACCESSTOKEN_LOG_INFO(LABEL, "Get valid config value!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Get valid config value!"); successFlag = true; break; // once get the config value, break the loop } diff --git a/services/common/database/include/sqlite_helper.h b/services/common/database/include/sqlite_helper.h index 68d7020b480df0e15d07296badb86eb1ca3ee10f..57cd4516c8c89771f60510641a6f7bb545f6230b 100644 --- a/services/common/database/include/sqlite_helper.h +++ b/services/common/database/include/sqlite_helper.h @@ -52,7 +52,7 @@ public: virtual void OnUpdate(int32_t version) = 0; private: - inline static const std::string PRAGMA_VERSION_COMMAND = "PRAGMA user_version"; + inline static constexpr const char* PRAGMA_VERSION_COMMAND = "PRAGMA user_version"; static const int32_t GENERAL_ERROR = -1; const std::string dbName_; diff --git a/services/common/database/src/memory_guard.cpp b/services/common/database/src/memory_guard.cpp index 98bcb4d9960e13f388df8b98c0279bb6d40b422c..31d9e2c747da241c30d3ece69902cce6af83e256 100644 --- a/services/common/database/src/memory_guard.cpp +++ b/services/common/database/src/memory_guard.cpp @@ -20,20 +20,12 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -#ifdef CONFIG_USE_JEMALLOC_DFX_INTF -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "MemoryGuard" -}; -#endif -} - MemoryGuard::MemoryGuard() { #ifdef CONFIG_USE_JEMALLOC_DFX_INTF int32_t ret1 = mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_DISABLE); int32_t ret2 = mallopt(M_DELAYED_FREE, M_DELAYED_FREE_DISABLE); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Disable tcache and delay free, result[%{public}d, %{public}d]", ret1, ret2); + LOGD(ATM_DOMAIN, ATM_TAG, "Disable tcache and delay free, ret[%{public}d, %{public}d]", ret1, ret2); #endif } @@ -41,7 +33,7 @@ MemoryGuard::~MemoryGuard() { #ifdef CONFIG_USE_JEMALLOC_DFX_INTF int32_t err = mallopt(M_FLUSH_THREAD_CACHE, 0); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Flush cache, result: %{public}d", err); + LOGD(ATM_DOMAIN, ATM_TAG, "Flush cache, result: %{public}d", err); #endif } } // namespace AccessToken diff --git a/services/common/database/src/sqlite_helper.cpp b/services/common/database/src/sqlite_helper.cpp index 443f4e57ba3b23a6ba72c2355c95346f89b71c93..8f4812c8ff5efa02bf326d3d242b9d10021b3277 100644 --- a/services/common/database/src/sqlite_helper.cpp +++ b/services/common/database/src/sqlite_helper.cpp @@ -22,10 +22,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "SqliteHelper"}; -} - SqliteHelper::SqliteHelper(const std::string& dbName, const std::string& dbPath, int32_t version) : dbName_(dbName), dbPath_(dbPath), currentVersion_(version), db_(nullptr) {} @@ -36,13 +32,12 @@ SqliteHelper::~SqliteHelper() void SqliteHelper::Open() __attribute__((no_sanitize("cfi"))) { if (db_ != nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Db s already open"); + LOGW(ATM_DOMAIN, ATM_TAG, "Db s already open"); return; } if (dbName_.empty() || dbPath_.empty() || currentVersion_ < 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Param invalid, dbName: %{public}s, " - "dbPath: %{public}s, currentVersion: %{public}d", - dbName_.c_str(), dbPath_.c_str(), currentVersion_); + LOGE(ATM_DOMAIN, ATM_TAG, "Param invalid, dbName: %{public}s, " + "dbPath: %{public}s, currentVersion: %{public}d", dbName_.c_str(), dbPath_.c_str(), currentVersion_); return; } // set soft heap limit as 10KB @@ -51,7 +46,7 @@ void SqliteHelper::Open() __attribute__((no_sanitize("cfi"))) std::string fileName = dbPath_ + dbName_; int32_t res = sqlite3_open(fileName.c_str(), &db_); if (res != SQLITE_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to open db: %{public}s", sqlite3_errmsg(db_)); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to open db: %{public}s", sqlite3_errmsg(db_)); return; } @@ -75,12 +70,12 @@ void SqliteHelper::Open() __attribute__((no_sanitize("cfi"))) void SqliteHelper::Close() { if (db_ == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Do open data base first!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Do open data base first!"); return; } int32_t ret = sqlite3_close(db_); if (ret != SQLITE_OK) { - ACCESSTOKEN_LOG_WARN(LABEL, "Sqlite3_close error, ret=%{public}d", ret); + LOGW(ATM_DOMAIN, ATM_TAG, "Sqlite3_close error, ret=%{public}d", ret); return; } db_ = nullptr; @@ -89,14 +84,14 @@ void SqliteHelper::Close() int32_t SqliteHelper::BeginTransaction() const { if (db_ == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Do open data base first!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Do open data base first!"); return GENERAL_ERROR; } char* errorMessage = nullptr; int32_t result = 0; int32_t ret = sqlite3_exec(db_, "BEGIN;", nullptr, nullptr, &errorMessage); if (ret != SQLITE_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed, errorMsg: %{public}s", errorMessage); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed, errorMsg: %{public}s", errorMessage); result = GENERAL_ERROR; } sqlite3_free(errorMessage); @@ -106,14 +101,14 @@ int32_t SqliteHelper::BeginTransaction() const int32_t SqliteHelper::CommitTransaction() const { if (db_ == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Do open data base first!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Do open data base first!"); return GENERAL_ERROR; } char* errorMessage = nullptr; int32_t result = 0; int32_t ret = sqlite3_exec(db_, "COMMIT;", nullptr, nullptr, &errorMessage); if (ret != SQLITE_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed, errorMsg: %{public}s", errorMessage); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed, errorMsg: %{public}s", errorMessage); result = GENERAL_ERROR; } sqlite3_free(errorMessage); @@ -124,14 +119,14 @@ int32_t SqliteHelper::CommitTransaction() const int32_t SqliteHelper::RollbackTransaction() const { if (db_ == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Do open data base first!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Do open data base first!"); return GENERAL_ERROR; } int32_t result = 0; char* errorMessage = nullptr; int32_t ret = sqlite3_exec(db_, "ROLLBACK;", nullptr, nullptr, &errorMessage); if (ret != SQLITE_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed, errorMsg: %{public}s", errorMessage); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed, errorMsg: %{public}s", errorMessage); result = GENERAL_ERROR; } sqlite3_free(errorMessage); @@ -146,14 +141,14 @@ Statement SqliteHelper::Prepare(const std::string& sql) const int32_t SqliteHelper::ExecuteSql(const std::string& sql) const { if (db_ == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Do open data base first!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Do open data base first!"); return GENERAL_ERROR; } char* errorMessage = nullptr; int32_t result = 0; int32_t res = sqlite3_exec(db_, sql.c_str(), nullptr, nullptr, &errorMessage); if (res != SQLITE_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed, errorMsg: %{public}s", errorMessage); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed, errorMsg: %{public}s", errorMessage); result = GENERAL_ERROR; } sqlite3_free(errorMessage); @@ -163,7 +158,7 @@ int32_t SqliteHelper::ExecuteSql(const std::string& sql) const int32_t SqliteHelper::GetVersion() const __attribute__((no_sanitize("cfi"))) { if (db_ == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Do open data base first!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Do open data base first!"); return GENERAL_ERROR; } auto statement = Prepare(PRAGMA_VERSION_COMMAND); @@ -171,24 +166,25 @@ int32_t SqliteHelper::GetVersion() const __attribute__((no_sanitize("cfi"))) while (statement.Step() == Statement::State::ROW) { version = statement.GetColumnInt(0); } - ACCESSTOKEN_LOG_INFO(LABEL, "Version: %{public}d", version); + LOGI(ATM_DOMAIN, ATM_TAG, "Version: %{public}d", version); return version; } void SqliteHelper::SetVersion() const { if (db_ == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Do open data base first!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Do open data base first!"); return; } - auto statement = Prepare(PRAGMA_VERSION_COMMAND + " = " + std::to_string(currentVersion_)); + std::string equalStr = " = "; + auto statement = Prepare(PRAGMA_VERSION_COMMAND + equalStr + std::to_string(currentVersion_)); statement.Step(); } std::string SqliteHelper::SpitError() const { if (db_ == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Do open data base first!"); + LOGW(ATM_DOMAIN, ATM_TAG, "Do open data base first!"); return ""; } return sqlite3_errmsg(db_); diff --git a/services/common/database/src/statement.cpp b/services/common/database/src/statement.cpp index 9a8123c5eec67dd543e8e89056e25b8ec411ee4a..897d73ffa0767a2d0e5c077de9f9776fcd0c08ee 100644 --- a/services/common/database/src/statement.cpp +++ b/services/common/database/src/statement.cpp @@ -20,14 +20,10 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "Statement"}; -} - Statement::Statement(sqlite3* db, const std::string& sql) : db_(db), sql_(sql) { if (sqlite3_prepare_v2(db, sql.c_str(), sql.size(), &statement_, nullptr) != SQLITE_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot prepare, errorMsg: %{public}s", sqlite3_errmsg(db_)); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot prepare, errorMsg: %{public}s", sqlite3_errmsg(db_)); } } @@ -40,21 +36,21 @@ Statement::~Statement() void Statement::Bind(const int32_t index, const std::string& text) { if (sqlite3_bind_text(statement_, index, text.c_str(), text.size(), SQLITE_TRANSIENT) != SQLITE_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot bind string, errorMsg: %{public}s", sqlite3_errmsg(db_)); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot bind string, errorMsg: %{public}s", sqlite3_errmsg(db_)); } } void Statement::Bind(const int32_t index, int32_t value) { if (sqlite3_bind_int(statement_, index, value) != SQLITE_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot bind int32_t, errorMsg: %{public}s", sqlite3_errmsg(db_)); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot bind int32_t, errorMsg: %{public}s", sqlite3_errmsg(db_)); } } void Statement::Bind(const int32_t index, int64_t value) { if (sqlite3_bind_int64(statement_, index, value) != SQLITE_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot bind int64_t, errorMsg: %{public}s", sqlite3_errmsg(db_)); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot bind int64_t, errorMsg: %{public}s", sqlite3_errmsg(db_)); } } diff --git a/services/common/database/test/BUILD.gn b/services/common/database/test/BUILD.gn index 0984317f17cc1b4c71133f9030d6e9d196b501a1..a92c03e2d50176e804a05fef054888bf45980c17 100644 --- a/services/common/database/test/BUILD.gn +++ b/services/common/database/test/BUILD.gn @@ -43,7 +43,6 @@ ohos_unittest("libdatabase_test") { "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/access_token_db_util.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/access_token_open_callback.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/data_translator.cpp", - "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/token_field_const.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/permission/permission_validator.cpp", "unittest/database_test.cpp", ] diff --git a/services/common/database/test/unittest/database_test.cpp b/services/common/database/test/unittest/database_test.cpp index a37e376f56d3a3b9ec5d0c2a63d14ac6b06192eb..f67f0f6bfc0262c119954560d310ba13b2af8420 100644 --- a/services/common/database/test/unittest/database_test.cpp +++ b/services/common/database/test/unittest/database_test.cpp @@ -35,7 +35,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "DatabaseTest"}; static constexpr int32_t GET_INT64_TRUE_VALUE = -1; static const int32_t DEFAULT_VALUE = -1; static const int32_t TEST_TOKEN_ID = 100; @@ -157,7 +156,7 @@ static void RemoveTestTokenHapInfo() */ HWTEST_F(DatabaseTest, SqliteStorageAddTest001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SqliteStorageAddTest001 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "SqliteStorageAddTest001 begin"); RemoveTestTokenHapInfo(); @@ -178,7 +177,7 @@ HWTEST_F(DatabaseTest, SqliteStorageAddTest001, TestSize.Level1) std::vector values; values.emplace_back(genericValues); EXPECT_EQ(0, AccessTokenDb::GetInstance().Add(AtmDataType::ACCESSTOKEN_HAP_INFO, values)); - ACCESSTOKEN_LOG_INFO(LABEL, "SqliteStorageAddTest001 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "SqliteStorageAddTest001 end"); } /* @@ -189,7 +188,7 @@ HWTEST_F(DatabaseTest, SqliteStorageAddTest001, TestSize.Level1) */ HWTEST_F(DatabaseTest, SqliteStorageAddTest002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SqliteStorageAddTest002 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "SqliteStorageAddTest002 begin"); RemoveTestTokenHapInfo(); @@ -200,7 +199,7 @@ HWTEST_F(DatabaseTest, SqliteStorageAddTest002, TestSize.Level1) values.emplace_back(genericValues); EXPECT_EQ(AccessTokenError::ERR_DATABASE_OPERATE_FAILED, AccessTokenDb::GetInstance().Add(AtmDataType::ACCESSTOKEN_HAP_INFO, values)); - ACCESSTOKEN_LOG_INFO(LABEL, "SqliteStorageAddTest002 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "SqliteStorageAddTest002 end"); } /* @@ -211,7 +210,7 @@ HWTEST_F(DatabaseTest, SqliteStorageAddTest002, TestSize.Level1) */ HWTEST_F(DatabaseTest, SqliteStorageModifyTest001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "SqliteStorageModifyTest001 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "SqliteStorageModifyTest001 begin"); RemoveTestTokenHapInfo(); @@ -255,7 +254,7 @@ HWTEST_F(DatabaseTest, SqliteStorageModifyTest001, TestSize.Level1) } } EXPECT_TRUE(modifySuccess); - ACCESSTOKEN_LOG_INFO(LABEL, "SqliteStorageModifyTest001 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "SqliteStorageModifyTest001 end"); } /* @@ -266,7 +265,7 @@ HWTEST_F(DatabaseTest, SqliteStorageModifyTest001, TestSize.Level1) */ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionDef001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionDefTest001 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionDefTest001 begin"); RemoveTestTokenHapInfo(); @@ -276,7 +275,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionDef001, TestSize.L PermissionDef outPermissionDef; ASSERT_NE(RET_SUCCESS, DataTranslator::TranslationIntoPermissionDef(genericValues, outPermissionDef)); - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionDefTest001 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionDefTest001 end"); } /* @@ -287,7 +286,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionDef001, TestSize.L */ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoGenericValues001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoGenericValues001 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoGenericValues001 begin"); PermissionStateFull grantPermissionReq = { .permissionName = "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", .isGeneral = true, @@ -299,7 +298,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoGenericValues001, TestSize.L GenericValues genericValues; ASSERT_NE(RET_SUCCESS, DataTranslator::TranslationIntoGenericValues(grantPermissionReq, grantIndex, genericValues)); - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoGenericValues001 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoGenericValues001 end"); } /* @@ -310,7 +309,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoGenericValues001, TestSize.L */ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoGenericValues002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoGenericValues002 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoGenericValues002 begin"); PermissionStateFull grantPermissionReq = { .permissionName = "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", .isGeneral = true, @@ -322,7 +321,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoGenericValues002, TestSize.L GenericValues genericValues; ASSERT_NE(RET_SUCCESS, DataTranslator::TranslationIntoGenericValues(grantPermissionReq, grantIndex, genericValues)); - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoGenericValues002 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoGenericValues002 end"); } /* @@ -333,7 +332,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoGenericValues002, TestSize.L */ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoGenericValues003, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoGenericValues003 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoGenericValues003 begin"); PermissionStateFull grantPermissionReq = { .permissionName = "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", .isGeneral = true, @@ -345,7 +344,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoGenericValues003, TestSize.L GenericValues genericValues; ASSERT_NE(RET_SUCCESS, DataTranslator::TranslationIntoGenericValues(grantPermissionReq, grantIndex, genericValues)); - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoGenericValues003 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoGenericValues003 end"); } /* @@ -356,7 +355,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoGenericValues003, TestSize.L */ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull001, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionStateFullTest001 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionStateFullTest001 begin"); PermissionStateFull outPermissionState; @@ -366,7 +365,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull001, Test PermissionDef outPermissionDef; ASSERT_NE(RET_SUCCESS, DataTranslator::TranslationIntoPermissionStateFull(inGenericValues, outPermissionState)); - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionStateFullTest001 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionStateFullTest001 end"); } /* @@ -377,7 +376,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull001, Test */ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionStateFullTest002 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionStateFullTest002 begin"); PermissionStateFull outPermissionState; @@ -388,7 +387,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull002, Test PermissionDef outPermissionDef; ASSERT_NE(RET_SUCCESS, DataTranslator::TranslationIntoPermissionStateFull(inGenericValues, outPermissionState)); - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionStateFullTest002 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionStateFullTest002 end"); } /* @@ -399,7 +398,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull002, Test */ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull003, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionStateFullTest003 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionStateFullTest003 begin"); PermissionStateFull outPermissionState; @@ -411,7 +410,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull003, Test PermissionDef outPermissionDef; ASSERT_NE(RET_SUCCESS, DataTranslator::TranslationIntoPermissionStateFull(inGenericValues, outPermissionState)); - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionStateFullTest003 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionStateFullTest003 end"); } /* @@ -422,7 +421,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull003, Test */ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull004, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionStateFullTest004 begin"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionStateFullTest004 begin"); PermissionStateFull outPermissionState; @@ -435,7 +434,7 @@ HWTEST_F(DatabaseTest, DataTranslatorTranslationIntoPermissionStateFull004, Test PermissionDef outPermissionDef; ASSERT_NE(RET_SUCCESS, DataTranslator::TranslationIntoPermissionStateFull(inGenericValues, outPermissionState)); - ACCESSTOKEN_LOG_INFO(LABEL, "DataTranslatorTranslationIntoPermissionStateFullTest004 end"); + LOGI(ATM_DOMAIN, ATM_TAG, "DataTranslatorTranslationIntoPermissionStateFullTest004 end"); } } // namespace AccessToken } // namespace Security diff --git a/services/common/handler/src/access_event_handler.cpp b/services/common/handler/src/access_event_handler.cpp index 389cfc5342a0e7e63e02f0b1f674b4df6bf612f4..e25ae4ad05cae623081b3e24e3b3171650f20e1b 100644 --- a/services/common/handler/src/access_event_handler.cpp +++ b/services/common/handler/src/access_event_handler.cpp @@ -20,28 +20,24 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessEventHandler"}; -} AccessEventHandler::AccessEventHandler( const std::shared_ptr& runner) : AppExecFwk::EventHandler(runner) { - ACCESSTOKEN_LOG_INFO(LABEL, "Enter"); + LOGI(ATM_DOMAIN, ATM_TAG, "Enter"); } AccessEventHandler::~AccessEventHandler() = default; bool AccessEventHandler::ProxyPostTask(const Callback &callback, int64_t delayTime) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "PostTask without name"); + LOGD(ATM_DOMAIN, ATM_TAG, "PostTask without name"); return AppExecFwk::EventHandler::PostTask(callback, delayTime); } bool AccessEventHandler::ProxyPostTask( const Callback &callback, const std::string &name, int64_t delayTime) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "PostTask with name"); + LOGD(ATM_DOMAIN, ATM_TAG, "PostTask with name"); return AppExecFwk::EventHandler::PostTask(callback, name, delayTime); } diff --git a/services/common/libraryloader/src/libraryloader.cpp b/services/common/libraryloader/src/libraryloader.cpp index b370cd4f70cf9f67e099211ac5de77e8043be2df..7117438ee130ea60829e3633395f99b677e0f381 100644 --- a/services/common/libraryloader/src/libraryloader.cpp +++ b/services/common/libraryloader/src/libraryloader.cpp @@ -24,8 +24,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, - SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenLibLoader"}; typedef void* (*FUNC_CREATE) (void); typedef void (*FUNC_DESTROY) (void*); } @@ -57,7 +55,7 @@ bool LibraryLoader::PrintErrorLog(const std::string& targetName) { char* error; if ((error = dlerror()) != nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get %{public}s failed, errMsg=%{public}s.", + LOGE(ATM_DOMAIN, ATM_TAG, "Get %{public}s failed, errMsg=%{public}s.", targetName.c_str(), error); return false; } diff --git a/services/common/power_manager/src/power_manager_client.cpp b/services/common/power_manager/src/power_manager_client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57447cc45c284ff34a7514ccbfb45503d715b33d --- /dev/null +++ b/services/common/power_manager/src/power_manager_client.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024 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 "power_manager_client.h" +#include + +#include "accesstoken_log.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +std::mutex g_instanceMutex; +} // namespace + +PowerMgrClient& PowerMgrClient::GetInstance() +{ + static PowerMgrClient* instance = nullptr; + if (instance == nullptr) { + std::lock_guard lock(g_instanceMutex); + if (instance == nullptr) { + instance = new PowerMgrClient(); + } + } + return *instance; +} + +PowerMgrClient::PowerMgrClient() +{} + +PowerMgrClient::~PowerMgrClient() +{ + std::lock_guard lock(proxyMutex_); + ReleaseProxy(); +} + +bool PowerMgrClient::IsScreenOn() +{ + LOGI(ATM_DOMAIN, ATM_TAG, "Entry"); + auto proxy = GetProxy(); + if (proxy == nullptr) { + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null"); + return false; + } + return proxy->IsScreenOn(); +} + +void PowerMgrClient::InitProxy() +{ + auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (sam == nullptr) { + LOGE(PRI_DOMAIN, PRI_TAG, "GetSystemAbilityManager is null"); + return; + } + auto powerManagerSa = sam->GetSystemAbility(POWER_MANAGER_SERVICE_ID); + if (powerManagerSa == nullptr) { + LOGE(PRI_DOMAIN, PRI_TAG, "GetSystemAbility %{public}d is null", + POWER_MANAGER_SERVICE_ID); + return; + } + + serviceDeathObserver_ = sptr::MakeSptr(); + if (serviceDeathObserver_ != nullptr) { + powerManagerSa->AddDeathRecipient(serviceDeathObserver_); + } + + proxy_ = new PowerMgrProxy(powerManagerSa); + if (proxy_ == nullptr || proxy_->AsObject() == nullptr || proxy_->AsObject()->IsObjectDead()) { + LOGE(PRI_DOMAIN, PRI_TAG, "Iface_cast get null"); + } +} + +void PowerMgrClient::OnRemoteDiedHandle() +{ + std::lock_guard lock(proxyMutex_); + ReleaseProxy(); +} + +sptr PowerMgrClient::GetProxy() +{ + std::lock_guard lock(proxyMutex_); + if (proxy_ == nullptr || proxy_->AsObject() == nullptr || proxy_->AsObject()->IsObjectDead()) { + InitProxy(); + } + return proxy_; +} + +void PowerMgrClient::ReleaseProxy() +{ + if (proxy_ != nullptr && serviceDeathObserver_ != nullptr) { + proxy_->AsObject()->RemoveDeathRecipient(serviceDeathObserver_); + } + proxy_ = nullptr; + serviceDeathObserver_ = nullptr; +} + +void PowerMgrDeathRecipient::OnRemoteDied(const wptr& object) +{ + LOGI(PRI_DOMAIN, PRI_TAG, "OnRemoteDied"); + PowerMgrClient::GetInstance().OnRemoteDiedHandle(); +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + diff --git a/frameworks/privacy/include/privacy_audio_service_ipc_interface_code.h b/services/common/power_manager/src/power_manager_proxy.cpp similarity index 41% rename from frameworks/privacy/include/privacy_audio_service_ipc_interface_code.h rename to services/common/power_manager/src/power_manager_proxy.cpp index 2cbd6fff289d1f5192dea29cdb93284849eaba9a..6c634c406a8e334a983cf611d2b7c7413f089e08 100644 --- a/frameworks/privacy/include/privacy_audio_service_ipc_interface_code.h +++ b/services/common/power_manager/src/power_manager_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -13,23 +13,38 @@ * limitations under the License. */ -#ifndef PRIVACY_AUDIO_SERVICE_IPC_INTERFACE_CODE_H -#define PRIVACY_AUDIO_SERVICE_IPC_INTERFACE_CODE_H +#include "power_manager_proxy.h" +#include "accesstoken_log.h" namespace OHOS { namespace Security { namespace AccessToken { -enum PrivacyAudioPolicyInterfaceCode { -#ifdef FEATURE_DTMF_TONE - SET_MICROPHONE_MUTE_PERSISTENT = 120, - GET_MICROPHONE_MUTE_PERSISTENT = 121, -#else - SET_MICROPHONE_MUTE_PERSISTENT = 118, - GET_MICROPHONE_MUTE_PERSISTENT = 119, -#endif -}; +bool PowerMgrProxy::IsScreenOn() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed"); + return false; + } + bool needPrintLog = true; + if (!data.WriteBool(needPrintLog)) { + LOGE(PRI_DOMAIN, PRI_TAG, "WriteBool failed"); + return false; + } + sptr remote = Remote(); + if (remote == nullptr) { + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null."); + return false; + } + int32_t error = remote->SendRequest(static_cast(IPowerMgr::Message::IS_SCREEN_ON), data, reply, option); + if (error != ERR_NONE) { + LOGE(PRI_DOMAIN, PRI_TAG, "IsScreenOn failed, error: %{public}d", error); + return false; + } + return reply.ReadBool(); +} } // namespace AccessToken } // namespace Security } // namespace OHOS - -#endif // PRIVACY_AUDIO_SERVICE_IPC_INTERFACE_CODE_H diff --git a/services/common/window_manager/src/privacy_mock_session_manager_proxy.cpp b/services/common/window_manager/src/privacy_mock_session_manager_proxy.cpp index 6dbb1305177cc855da27831eb264350baf3aae22..29526552694489c855946d80a7ddf9fa55d1155e 100644 --- a/services/common/window_manager/src/privacy_mock_session_manager_proxy.cpp +++ b/services/common/window_manager/src/privacy_mock_session_manager_proxy.cpp @@ -20,23 +20,19 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyMockSessionManagerProxy"}; -} - sptr PrivacyMockSessionManagerProxy::GetSessionManagerService() { MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed"); return nullptr; } if (Remote()->SendRequest(static_cast( MockSessionManagerServiceMessage::TRANS_ID_GET_SESSION_MANAGER_SERVICE), data, reply, option) != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed"); return nullptr; } sptr remoteObject = reply.ReadRemoteObject(); diff --git a/services/common/window_manager/src/privacy_scene_session_manager_lite_proxy.cpp b/services/common/window_manager/src/privacy_scene_session_manager_lite_proxy.cpp index 38c257b8041e454ee082497c2dd7ed62845115b8..b12f4045496c5b965b348d174d3c966c431fc29a 100644 --- a/services/common/window_manager/src/privacy_scene_session_manager_lite_proxy.cpp +++ b/services/common/window_manager/src/privacy_scene_session_manager_lite_proxy.cpp @@ -21,10 +21,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacySceneSessionManagerLiteProxy"}; -} - int32_t PrivacySceneSessionManagerLiteProxy::RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) { @@ -32,30 +28,30 @@ int32_t PrivacySceneSessionManagerLiteProxy::RegisterWindowManagerAgent(WindowMa MessageParcel reply; MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write InterfaceToken failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(static_cast(type))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed"); return ERR_WRITE_PARCEL_FAILED; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null."); return ERR_REMOTE_CONNECTION; } int32_t error = remote->SendRequest(static_cast( SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, err=%{public}d.", error); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error); return error; } @@ -69,30 +65,30 @@ int32_t PrivacySceneSessionManagerLiteProxy::UnregisterWindowManagerAgent(Window MessageOption option; MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write InterfaceToken failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(static_cast(type))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed"); return ERR_WRITE_PARCEL_FAILED; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null."); return ERR_REMOTE_CONNECTION; } int32_t error = remote->SendRequest(static_cast( SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, err=%{public}d.", error); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error); return error; } diff --git a/services/common/window_manager/src/privacy_scene_session_manager_proxy.cpp b/services/common/window_manager/src/privacy_scene_session_manager_proxy.cpp index 5f5ac1b9c9ea8811fbdc688ae89a88c9752bdc62..775f6581aa65441d7667af0a3d141c52eb695360 100644 --- a/services/common/window_manager/src/privacy_scene_session_manager_proxy.cpp +++ b/services/common/window_manager/src/privacy_scene_session_manager_proxy.cpp @@ -21,10 +21,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacySceneSessionManagerProxy"}; -} - int32_t PrivacySceneSessionManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) { @@ -32,17 +28,17 @@ int32_t PrivacySceneSessionManagerProxy::RegisterWindowManagerAgent(WindowManage MessageParcel reply; MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write InterfaceToken failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(static_cast(type))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed"); return ERR_WRITE_PARCEL_FAILED; } @@ -50,7 +46,7 @@ int32_t PrivacySceneSessionManagerProxy::RegisterWindowManagerAgent(WindowManage SceneSessionManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, err=%{public}d.", error); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error); return error; } @@ -64,17 +60,17 @@ int32_t PrivacySceneSessionManagerProxy::UnregisterWindowManagerAgent(WindowMana MessageOption option; MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write InterfaceToken failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(static_cast(type))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed"); return ERR_WRITE_PARCEL_FAILED; } @@ -82,7 +78,7 @@ int32_t PrivacySceneSessionManagerProxy::UnregisterWindowManagerAgent(WindowMana SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, err=%{public}d.", error); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error); return error; } diff --git a/services/common/window_manager/src/privacy_session_manager_proxy.cpp b/services/common/window_manager/src/privacy_session_manager_proxy.cpp index 113f87fa1c48af8be8fae166621ee91889067892..89158fda1e7c2cf4769cf64da167b537ecbf45dc 100644 --- a/services/common/window_manager/src/privacy_session_manager_proxy.cpp +++ b/services/common/window_manager/src/privacy_session_manager_proxy.cpp @@ -20,10 +20,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacySessionManagerProxy" }; -} - sptr PrivacySessionManagerProxy::GetSceneSessionManager() { MessageParcel data; @@ -31,20 +27,20 @@ sptr PrivacySessionManagerProxy::GetSceneSessionManager() MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed"); return nullptr; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null."); return nullptr; } auto ret = remote->SendRequest( static_cast(SessionManagerServiceMessage::TRANS_ID_GET_SCENE_SESSION_MANAGER), data, reply, option); if (ret != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, errorCode %{public}d", ret); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, errorCode %{public}d", ret); return nullptr; } @@ -58,20 +54,20 @@ sptr PrivacySessionManagerProxy::GetSceneSessionManagerLite() MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed"); return nullptr; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null."); return nullptr; } auto ret = remote->SendRequest( static_cast(SessionManagerServiceMessage::TRANS_ID_GET_SCENE_SESSION_MANAGER_LITE), data, reply, option); if (ret != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, errorCode %{public}d", ret); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, errorCode %{public}d", ret); return nullptr; } diff --git a/services/common/window_manager/src/privacy_window_manager_agent.cpp b/services/common/window_manager/src/privacy_window_manager_agent.cpp index 15fe476c7cb4f6c5600395f18f9ede80518efa54..504648f90b1414e574889374179ed3a5000e0c41 100644 --- a/services/common/window_manager/src/privacy_window_manager_agent.cpp +++ b/services/common/window_manager/src/privacy_window_manager_agent.cpp @@ -19,12 +19,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyWindowManagerAgent" -}; -} - PrivacyWindowManagerAgent::PrivacyWindowManagerAgent(WindowChangeCallback callback) { callback_ = callback; @@ -33,9 +27,9 @@ PrivacyWindowManagerAgent::PrivacyWindowManagerAgent(WindowChangeCallback callba int PrivacyWindowManagerAgent::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called, code: %{public}u", __func__, code); + LOGI(PRI_DOMAIN, PRI_TAG, "%{public}s called, code: %{public}u", __func__, code); if (data.ReadInterfaceToken() != IWindowManagerAgent::GetDescriptor()) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called, read desciptor error", __func__); + LOGI(PRI_DOMAIN, PRI_TAG, "%{public}s called, read desciptor error", __func__); return ERROR_IPC_REQUEST_FAIL; } PrivacyWindowServiceInterfaceCode msgId = static_cast(code); @@ -60,13 +54,13 @@ int PrivacyWindowManagerAgent::OnRemoteRequest(uint32_t code, MessageParcel& dat void PrivacyWindowManagerAgent::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) { - ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(tokenId=%{public}d, isShow=%{public}d)", accessTokenId, isShowing); + LOGI(PRI_DOMAIN, PRI_TAG, "OnChange(tokenId=%{public}d, isShow=%{public}d)", accessTokenId, isShowing); callback_(accessTokenId, isShowing); } void PrivacyWindowManagerAgent::UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing) { - ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(tokenId=%{public}d, isShow=%{public}d)", accessTokenId, isShowing); + LOGI(PRI_DOMAIN, PRI_TAG, "OnChange(tokenId=%{public}d, isShow=%{public}d)", accessTokenId, isShowing); callback_(accessTokenId, isShowing); } } // namespace AccessToken diff --git a/services/common/window_manager/src/privacy_window_manager_client.cpp b/services/common/window_manager/src/privacy_window_manager_client.cpp index f7e2a59e7bcc7d749e13a9fed5b95ebaf21a9f92..89eeb27bf733bda5a728bf07edaf94a6abd17e25 100644 --- a/services/common/window_manager/src/privacy_window_manager_client.cpp +++ b/services/common/window_manager/src/privacy_window_manager_client.cpp @@ -31,9 +31,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyWindowManagerClient" -}; std::recursive_mutex g_instanceMutex; static const int MAX_PTHREAD_NAME_LEN = 15; // pthread name max length } // namespace @@ -59,7 +56,7 @@ PrivacyWindowManagerClient::PrivacyWindowManagerClient() : deathCallback_(nullpt PrivacyWindowManagerClient::~PrivacyWindowManagerClient() { - ACCESSTOKEN_LOG_INFO(LABEL, "~PrivacyWindowManagerClient()."); + LOGI(PRI_DOMAIN, PRI_TAG, "~PrivacyWindowManagerClient()."); std::lock_guard lock(proxyMutex_); RemoveDeathRecipient(); } @@ -72,7 +69,7 @@ int32_t PrivacyWindowManagerClient::RegisterWindowManagerAgent(WindowManagerAgen } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null"); return ERR_SERVICE_ABNORMAL; } return proxy->RegisterWindowManagerAgent(type, windowManagerAgent); @@ -86,7 +83,7 @@ int32_t PrivacyWindowManagerClient::UnregisterWindowManagerAgent(WindowManagerAg } auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null"); return ERR_SERVICE_ABNORMAL; } return proxy->UnregisterWindowManagerAgent(type, windowManagerAgent); @@ -97,7 +94,7 @@ int32_t PrivacyWindowManagerClient::RegisterWindowManagerAgentLite(WindowManager { auto proxy = GetLiteProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null"); return ERR_SERVICE_ABNORMAL; } return proxy->RegisterWindowManagerAgent(type, windowManagerAgent); @@ -108,7 +105,7 @@ int32_t PrivacyWindowManagerClient::UnregisterWindowManagerAgentLite(WindowManag { auto proxy = GetLiteProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null"); + LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null"); return ERR_SERVICE_ABNORMAL; } return proxy->UnregisterWindowManagerAgent(type, windowManagerAgent); @@ -129,29 +126,29 @@ void PrivacyWindowManagerClient::InitSessionManagerServiceProxy() sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!systemAbilityManager) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to get system ability mgr."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to get system ability mgr."); return; } sptr remoteObject = systemAbilityManager->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID); if (!remoteObject) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote object is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote object is nullptr"); return; } mockSessionManagerServiceProxy_ = new PrivacyMockSessionManagerProxy(remoteObject); if (!mockSessionManagerServiceProxy_ || mockSessionManagerServiceProxy_->AsObject() == nullptr || mockSessionManagerServiceProxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_WARN(LABEL, "Get mock session manager service proxy failed, nullptr"); + LOGW(PRI_DOMAIN, PRI_TAG, "Get mock session manager service proxy failed, nullptr"); return; } sptr remoteObject2 = mockSessionManagerServiceProxy_->GetSessionManagerService(); if (!remoteObject2) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote object2 is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote object2 is nullptr"); return; } sessionManagerServiceProxy_ = new PrivacySessionManagerProxy(remoteObject2); if (!sessionManagerServiceProxy_ || sessionManagerServiceProxy_->AsObject() == nullptr || sessionManagerServiceProxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SessionManagerServiceProxy_ is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "SessionManagerServiceProxy_ is nullptr"); } } @@ -163,30 +160,30 @@ void PrivacyWindowManagerClient::InitSceneSessionManagerProxy() } if (!sessionManagerServiceProxy_ || sessionManagerServiceProxy_->AsObject() == nullptr || sessionManagerServiceProxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SessionManagerServiceProxy_ is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "SessionManagerServiceProxy_ is nullptr"); return; } sptr remoteObject = sessionManagerServiceProxy_->GetSceneSessionManager(); if (!remoteObject) { - ACCESSTOKEN_LOG_WARN(LABEL, "Get scene session manager proxy failed, scene session manager service is null"); + LOGW(PRI_DOMAIN, PRI_TAG, "Get scene session manager proxy failed, service is null"); return; } sceneSessionManagerProxy_ = new PrivacySceneSessionManagerProxy(remoteObject); if (sceneSessionManagerProxy_ == nullptr || sceneSessionManagerProxy_->AsObject() == nullptr || sceneSessionManagerProxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_WARN(LABEL, "SceneSessionManagerProxy_ is null."); + LOGW(PRI_DOMAIN, PRI_TAG, "SceneSessionManagerProxy_ is null."); return; } if (!serviceDeathObserver_) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create death Recipient ptr WMSDeathRecipient"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to create death Recipient ptr WMSDeathRecipient"); return; } if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(serviceDeathObserver_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to add death recipient"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to add death recipient"); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "InitSceneSessionManagerProxy end."); + LOGI(PRI_DOMAIN, PRI_TAG, "InitSceneSessionManagerProxy end."); } void PrivacyWindowManagerClient::InitSceneSessionManagerLiteProxy() @@ -196,30 +193,30 @@ void PrivacyWindowManagerClient::InitSceneSessionManagerLiteProxy() return; } if (!sessionManagerServiceProxy_) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SessionManagerServiceProxy_ is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "SessionManagerServiceProxy_ is nullptr"); return; } sptr remoteObject = sessionManagerServiceProxy_->GetSceneSessionManagerLite(); if (!remoteObject) { - ACCESSTOKEN_LOG_WARN(LABEL, "Get scene session manager proxy failed, scene session manager service is null"); + LOGW(PRI_DOMAIN, PRI_TAG, "Get scene session manager proxy failed, service is null"); return; } sceneSessionManagerLiteProxy_ = new PrivacySceneSessionManagerLiteProxy(remoteObject); if (sceneSessionManagerLiteProxy_ == nullptr || sceneSessionManagerLiteProxy_->AsObject() == nullptr || sceneSessionManagerLiteProxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_WARN(LABEL, "SceneSessionManagerLiteProxy_ is null."); + LOGW(PRI_DOMAIN, PRI_TAG, "SceneSessionManagerLiteProxy_ is null."); return; } if (!serviceDeathObserver_) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create death Recipient ptr WMSDeathRecipient"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to create death Recipient ptr WMSDeathRecipient"); return; } if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(serviceDeathObserver_)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to add death recipient"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to add death recipient"); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "InitSceneSessionManagerLiteProxy end."); + LOGI(PRI_DOMAIN, PRI_TAG, "InitSceneSessionManagerLiteProxy end."); } sptr PrivacyWindowManagerClient::GetSSMProxy() @@ -245,12 +242,12 @@ void PrivacyWindowManagerClient::InitWMSProxy() } auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (sam == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbilityManager is null"); + LOGE(PRI_DOMAIN, PRI_TAG, "GetSystemAbilityManager is null"); return; } auto windowManagerSa = sam->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID); if (windowManagerSa == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetSystemAbility %{public}d is null", + LOGE(PRI_DOMAIN, PRI_TAG, "GetSystemAbility %{public}d is null", WINDOW_MANAGER_SERVICE_ID); return; } @@ -261,10 +258,10 @@ void PrivacyWindowManagerClient::InitWMSProxy() wmsProxy_ = new PrivacyWindowManagerProxy(windowManagerSa); if (wmsProxy_ == nullptr || wmsProxy_->AsObject() == nullptr || wmsProxy_->AsObject()->IsObjectDead()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WmsProxy_ is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "WmsProxy_ is null."); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "InitWMSProxy end."); + LOGI(PRI_DOMAIN, PRI_TAG, "InitWMSProxy end."); } sptr PrivacyWindowManagerClient::GetWMSProxy() @@ -277,7 +274,7 @@ sptr PrivacyWindowManagerClient::GetWMSProxy() void PrivacyWindowManagerClient::OnRemoteDiedHandle() { std::lock_guard lock(proxyMutex_); - ACCESSTOKEN_LOG_INFO(LABEL, "Window manager remote died."); + LOGW(PRI_DOMAIN, PRI_TAG, "Window manager remote died."); RemoveDeathRecipient(); std::function runner = [this]() { diff --git a/services/common/window_manager/src/privacy_window_manager_death_recipient.cpp b/services/common/window_manager/src/privacy_window_manager_death_recipient.cpp index 5da7ce251d457c208c52b06f62c29a5edc96d2ca..393b0690486bc5d285fe25eef532fd59cd124714 100644 --- a/services/common/window_manager/src/privacy_window_manager_death_recipient.cpp +++ b/services/common/window_manager/src/privacy_window_manager_death_recipient.cpp @@ -19,14 +19,9 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyWindowManagerDeathRecipient"}; -} // namespace - void PrivacyWindowManagerDeathRecipient::OnRemoteDied(const wptr& object) { - ACCESSTOKEN_LOG_INFO(LABEL, "WindowManger died."); + LOGI(PRI_DOMAIN, PRI_TAG, "WindowManger died."); PrivacyWindowManagerClient::GetInstance().OnRemoteDiedHandle(); } } // namespace AccessToken diff --git a/services/common/window_manager/src/privacy_window_manager_proxy.cpp b/services/common/window_manager/src/privacy_window_manager_proxy.cpp index 097ab3af695534f3e3d094e223a8a31889b048db..8c65dda58a91ab06fa48c6dda455426f03f1fa34 100644 --- a/services/common/window_manager/src/privacy_window_manager_proxy.cpp +++ b/services/common/window_manager/src/privacy_window_manager_proxy.cpp @@ -20,10 +20,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyWindowManagerProxy"}; -} - int32_t PrivacyWindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) { @@ -31,29 +27,29 @@ int32_t PrivacyWindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgent MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(static_cast(type))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed"); return ERR_WRITE_PARCEL_FAILED; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null."); return ERR_REMOTE_CONNECTION; } int32_t error = remote->SendRequest( static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed"); return error; } return reply.ReadInt32(); @@ -66,30 +62,30 @@ int32_t PrivacyWindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAge MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteUint32(static_cast(type))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed"); return ERR_WRITE_PARCEL_FAILED; } if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed"); return ERR_WRITE_PARCEL_FAILED; } sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null."); return ERR_REMOTE_CONNECTION; } int32_t error = remote->SendRequest( static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT), data, reply, option); if (error != ERR_NONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed"); return error; } diff --git a/services/privacymanager/BUILD.gn b/services/privacymanager/BUILD.gn index f26c76e5a751db8f7be6e9a4654350445282f558..4829f6bf3bf4b60768336f7826ddc39bc96a934c 100644 --- a/services/privacymanager/BUILD.gn +++ b/services/privacymanager/BUILD.gn @@ -77,7 +77,6 @@ if (is_standard_system && ability_base_enable == true) { "src/common/constant.cpp", "src/database/data_translator.cpp", "src/database/permission_used_record_db.cpp", - "src/database/privacy_field_const.cpp", "src/record/on_permission_used_record_callback_proxy.cpp", "src/record/permission_record.cpp", "src/record/permission_record_manager.cpp", diff --git a/services/privacymanager/include/database/privacy_field_const.h b/services/privacymanager/include/database/privacy_field_const.h index 8c8946a3516dfd025c4043b4dfc1db24b2473586..913fa844e6a35f317171df8d7996cff886201f55 100644 --- a/services/privacymanager/include/database/privacy_field_const.h +++ b/services/privacymanager/include/database/privacy_field_const.h @@ -23,22 +23,22 @@ namespace Security { namespace AccessToken { class PrivacyFiledConst { public: - const static std::string FIELD_TOKEN_ID; - const static std::string FIELD_DEVICE_ID; - const static std::string FIELD_OP_CODE; - const static std::string FIELD_STATUS; - const static std::string FIELD_TIMESTAMP; - const static std::string FIELD_ACCESS_DURATION; - const static std::string FIELD_ACCESS_COUNT; - const static std::string FIELD_REJECT_COUNT; + inline static constexpr const char* FIELD_TOKEN_ID = "token_id"; + inline static constexpr const char* FIELD_DEVICE_ID = "device_id"; + inline static constexpr const char* FIELD_OP_CODE = "op_code"; + inline static constexpr const char* FIELD_STATUS = "status"; + inline static constexpr const char* FIELD_TIMESTAMP = "timestamp"; + inline static constexpr const char* FIELD_ACCESS_DURATION = "access_duration"; + inline static constexpr const char* FIELD_ACCESS_COUNT = "access_count"; + inline static constexpr const char* FIELD_REJECT_COUNT = "reject_count"; - const static std::string FIELD_TIMESTAMP_BEGIN; - const static std::string FIELD_TIMESTAMP_END; - const static std::string FIELD_FLAG; - const static std::string FIELD_LOCKSCREEN_STATUS; + inline static constexpr const char* FIELD_TIMESTAMP_BEGIN = "timestamp_begin"; + inline static constexpr const char* FIELD_TIMESTAMP_END = "timestamp_end"; + inline static constexpr const char* FIELD_FLAG = "flag"; + inline static constexpr const char* FIELD_LOCKSCREEN_STATUS = "lockScreenStatus"; - const static std::string FIELD_PERMISSION_CODE; - const static std::string FIELD_USED_TYPE; + inline static constexpr const char* FIELD_PERMISSION_CODE = "permission_code"; + inline static constexpr const char* FIELD_USED_TYPE = "used_type"; }; } // namespace AccessToken } // namespace Security diff --git a/services/privacymanager/src/active/active_status_callback_manager.cpp b/services/privacymanager/src/active/active_status_callback_manager.cpp index ff5f794dbd2d9566cd83311a34d72c39ebcf59c2..40f745fe340eb4a80485a171471077352fa66b2e 100644 --- a/services/privacymanager/src/active/active_status_callback_manager.cpp +++ b/services/privacymanager/src/active/active_status_callback_manager.cpp @@ -29,9 +29,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "ActiveStatusCallbackManager" -}; static const uint32_t MAX_CALLBACK_SIZE = 1024; std::recursive_mutex g_instanceMutex; } @@ -70,13 +67,13 @@ int32_t ActiveStatusCallbackManager::AddCallback( AccessTokenID regiterTokenId, const std::vector& permList, const sptr& callback) { if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Input is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "Input is nullptr"); return PrivacyError::ERR_PARAM_INVALID; } std::lock_guard lock(mutex_); if (callbackDataList_.size() >= MAX_CALLBACK_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "List size has reached max value"); + LOGE(PRI_DOMAIN, PRI_TAG, "List size has reached max value"); return PrivacyError::ERR_CALLBACKS_EXCEED_LIMITATION; } callback->AddDeathRecipient(callbackDeathRecipient_); @@ -88,15 +85,15 @@ int32_t ActiveStatusCallbackManager::AddCallback( callbackDataList_.emplace_back(recordInstance); - ACCESSTOKEN_LOG_INFO(LABEL, "RecordInstance is added"); + LOGI(PRI_DOMAIN, PRI_TAG, "RecordInstance is added"); return RET_SUCCESS; } int32_t ActiveStatusCallbackManager::RemoveCallback(const sptr& callback) { - ACCESSTOKEN_LOG_INFO(LABEL, "Called"); + LOGI(PRI_DOMAIN, PRI_TAG, "Called"); if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is nullptr."); + LOGE(PRI_DOMAIN, PRI_TAG, "Callback is nullptr."); return PrivacyError::ERR_PARAM_INVALID; } @@ -104,7 +101,7 @@ int32_t ActiveStatusCallbackManager::RemoveCallback(const sptr& c for (auto it = callbackDataList_.begin(); it != callbackDataList_.end(); ++it) { if (callback == (*it).callbackObject_) { - ACCESSTOKEN_LOG_INFO(LABEL, "Find callback"); + LOGI(PRI_DOMAIN, PRI_TAG, "Find callback"); if (callbackDeathRecipient_ != nullptr) { callback->RemoveDeathRecipient(callbackDeathRecipient_); } @@ -134,7 +131,7 @@ void ActiveStatusCallbackManager::ActiveStatusChange(ActiveChangeResponse& info) for (auto it = callbackDataList_.begin(); it != callbackDataList_.end(); ++it) { std::vector permList = (*it).permList_; if (!NeedCalled(permList, info.permissionName)) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenId %{public}u, perm %{public}s", info.tokenID, + LOGI(PRI_DOMAIN, PRI_TAG, "TokenId %{public}u, perm %{public}s", info.tokenID, info.permissionName.c_str()); continue; } @@ -144,7 +141,7 @@ void ActiveStatusCallbackManager::ActiveStatusChange(ActiveChangeResponse& info) for (auto it = list.begin(); it != list.end(); ++it) { sptr callback = new PermActiveStatusChangeCallbackProxy(*it); if (callback != nullptr) { - ACCESSTOKEN_LOG_INFO(LABEL, "callback execute callingTokenId %{public}u, tokenId %{public}u, " + LOGI(PRI_DOMAIN, PRI_TAG, "callback execute callingTokenId %{public}u, tokenId %{public}u, " "permision %{public}s, changeType %{public}d, usedType %{public}d", info.callingTokenID, info.tokenID, info.permissionName.c_str(), info.type, info.usedType); callback->ActiveStatusChangeCallback(info); @@ -162,22 +159,22 @@ void ActiveStatusCallbackManager::ExecuteCallbackAsync(ActiveChangeResponse& inf #ifdef EVENTHANDLER_ENABLE if (eventHandler_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(PRI_DOMAIN, PRI_TAG, "Fail to get EventHandler"); return; } std::string taskName = info.permissionName + std::to_string(info.tokenID); - ACCESSTOKEN_LOG_INFO(LABEL, "Add permission task name:%{public}s", taskName.c_str()); + LOGI(PRI_DOMAIN, PRI_TAG, "Add permission task name:%{public}s", taskName.c_str()); std::function task = ([info]() mutable { ActiveStatusCallbackManager::GetInstance().ActiveStatusChange(info); - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(PRI_DOMAIN, PRI_TAG, "Token: %{public}u, permName: %{public}s, changeType: %{public}d, ActiveStatusChange end", info.tokenID, info.permissionName.c_str(), info.type); }); eventHandler_->ProxyPostTask(task, taskName); - ACCESSTOKEN_LOG_INFO(LABEL, "The callback execution is complete"); + LOGI(PRI_DOMAIN, PRI_TAG, "The callback execution is complete"); return; #else - ACCESSTOKEN_LOG_INFO(LABEL, "Event handler is unenabled"); + LOGI(PRI_DOMAIN, PRI_TAG, "Event handler is unenabled"); return; #endif } diff --git a/services/privacymanager/src/active/perm_active_status_callback_death_recipient.cpp b/services/privacymanager/src/active/perm_active_status_callback_death_recipient.cpp index 98101dadbffed80d66dc585ac082c8a3b5c83dd2..c5e8fde432e83ecac17f4dd0335053e1ee5561a2 100644 --- a/services/privacymanager/src/active/perm_active_status_callback_death_recipient.cpp +++ b/services/privacymanager/src/active/perm_active_status_callback_death_recipient.cpp @@ -21,26 +21,21 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PermActiveStatusCallbackDeathRecipient" -}; -} void PermActiveStatusCallbackDeathRecipient::OnRemoteDied(const wptr &remote) { - ACCESSTOKEN_LOG_INFO(LABEL, "Enter"); + LOGI(PRI_DOMAIN, PRI_TAG, "Enter"); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote object is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote object is nullptr"); return; } sptr object = remote.promote(); if (object == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Object is nullptr"); + LOGE(PRI_DOMAIN, PRI_TAG, "Object is nullptr"); return; } ActiveStatusCallbackManager::GetInstance().RemoveCallback(object); - ACCESSTOKEN_LOG_INFO(LABEL, "End"); + LOGI(PRI_DOMAIN, PRI_TAG, "End"); } } // namespace AccessToken } // namespace Security diff --git a/services/privacymanager/src/active/perm_active_status_change_callback_proxy.cpp b/services/privacymanager/src/active/perm_active_status_change_callback_proxy.cpp index e4b994c94f1f42271f5bc0cd2ed9077a056024cf..c6a31bfffd590e94cc5ea21e078655fda6948455 100644 --- a/services/privacymanager/src/active/perm_active_status_change_callback_proxy.cpp +++ b/services/privacymanager/src/active/perm_active_status_change_callback_proxy.cpp @@ -21,12 +21,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PermActiveStatusChangeCallbackProxy" -}; -} - PermActiveStatusChangeCallbackProxy::PermActiveStatusChangeCallbackProxy(const sptr& impl) : IRemoteProxy(impl) { } @@ -42,7 +36,7 @@ void PermActiveStatusChangeCallbackProxy::ActiveStatusChangeCallback(ActiveChang ActiveChangeResponseParcel resultParcel; resultParcel.changeResponse = result; if (!data.WriteParcelable(&resultParcel)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to WriteParcelable"); return; } @@ -50,13 +44,13 @@ void PermActiveStatusChangeCallbackProxy::ActiveStatusChangeCallback(ActiveChang MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service null."); return; } int32_t requestResult = remote->SendRequest( static_cast(PrivacyActiveChangeInterfaceCode::PERM_ACTIVE_STATUS_CHANGE), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result: %{public}d", requestResult); + LOGE(PRI_DOMAIN, PRI_TAG, "Send request fail, result: %{public}d", requestResult); return; } } diff --git a/services/privacymanager/src/active/state_change_callback_proxy.cpp b/services/privacymanager/src/active/state_change_callback_proxy.cpp index f4e05379b5bdead018fbd165d71da0bee2699a10..0d72ccdbef76ed8d5a614d817a5438ccded04809 100644 --- a/services/privacymanager/src/active/state_change_callback_proxy.cpp +++ b/services/privacymanager/src/active/state_change_callback_proxy.cpp @@ -21,12 +21,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "StateChangeCallbackProxy" -}; -} - StateChangeCallbackProxy::StateChangeCallbackProxy(const sptr& impl) : IRemoteProxy(impl) { } @@ -40,11 +34,11 @@ void StateChangeCallbackProxy::StateChangeNotify(AccessTokenID tokenId, bool isS data.WriteInterfaceToken(IStateChangeCallback::GetDescriptor()); if (!data.WriteUint32(tokenId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to Write tokenId"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to Write tokenId"); return; } if (!data.WriteBool(isShowing)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to Write isShowing"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to Write isShowing"); return; } @@ -52,17 +46,17 @@ void StateChangeCallbackProxy::StateChangeNotify(AccessTokenID tokenId, bool isS MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service null."); return; } int32_t requestResult = remote->SendRequest( static_cast(IStateChangeCallback::STATE_CHANGE_CALLBACK), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result: %{public}d", requestResult); + LOGE(PRI_DOMAIN, PRI_TAG, "Send request fail, result: %{public}d", requestResult); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "SendRequest success"); + LOGI(PRI_DOMAIN, PRI_TAG, "SendRequest success"); } } // namespace AccessToken } // namespace Security diff --git a/services/privacymanager/src/common/privacy_common_event_subscriber.cpp b/services/privacymanager/src/common/privacy_common_event_subscriber.cpp index ea330799f076582ac39a9204fae324b409f6070d..7d6b2cebaa1dae6753fe5c2f86c24b29b4e811f9 100644 --- a/services/privacymanager/src/common/privacy_common_event_subscriber.cpp +++ b/services/privacymanager/src/common/privacy_common_event_subscriber.cpp @@ -27,10 +27,6 @@ namespace Security { namespace AccessToken { #ifdef COMMON_EVENT_SERVICE_ENABLE namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyCommonEventSubscriber" -}; - static bool g_isRegistered = false; static std::shared_ptr g_subscriber = nullptr; @@ -38,9 +34,9 @@ static std::shared_ptr g_subscriber = nullptr; void PrivacyCommonEventSubscriber::RegisterEvent() { - ACCESSTOKEN_LOG_INFO(LABEL, "RegisterEvent start"); + LOGI(PRI_DOMAIN, PRI_TAG, "RegisterEvent start"); if (g_isRegistered) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Status observer already registered"); + LOGD(PRI_DOMAIN, PRI_TAG, "Status observer already registered"); return; } @@ -55,7 +51,7 @@ void PrivacyCommonEventSubscriber::RegisterEvent() g_subscriber = std::make_shared(*info); const auto result = EventFwk::CommonEventManager::SubscribeCommonEvent(g_subscriber); if (!result) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RegisterEvent result is err"); + LOGE(PRI_DOMAIN, PRI_TAG, "RegisterEvent result is err"); return; } g_isRegistered = true; @@ -63,10 +59,10 @@ void PrivacyCommonEventSubscriber::RegisterEvent() void PrivacyCommonEventSubscriber::UnRegisterEvent() { - ACCESSTOKEN_LOG_INFO(LABEL, "UnregisterEvent start"); + LOGI(PRI_DOMAIN, PRI_TAG, "UnregisterEvent start"); const auto result = EventFwk::CommonEventManager::UnSubscribeCommonEvent(g_subscriber); if (!result) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UnregisterEvent result is err"); + LOGE(PRI_DOMAIN, PRI_TAG, "UnregisterEvent result is err"); return; } g_isRegistered = false; @@ -76,7 +72,7 @@ void PrivacyCommonEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventDat { const auto want = event.GetWant(); const auto action = want.GetAction(); - ACCESSTOKEN_LOG_INFO(LABEL, "Receive event(%{public}s)", action.c_str()); + LOGI(PRI_DOMAIN, PRI_TAG, "Receive event(%{public}s)", action.c_str()); if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) { PermissionRecordManager::GetInstance().SetLockScreenStatus(LockScreenStatusChangeType::PERM_ACTIVE_IN_UNLOCKED); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED) { @@ -85,13 +81,13 @@ void PrivacyCommonEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventDat } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED || action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED) { uint32_t tokenId = static_cast(want.GetParams().GetIntParam("accessTokenId", 0)); - ACCESSTOKEN_LOG_INFO(LABEL, "Receive package uninstall: tokenId=%{public}d.", tokenId); + LOGI(PRI_DOMAIN, PRI_TAG, "Receive package uninstall: tokenId=%{public}d.", tokenId); PermissionRecordManager::GetInstance().RemovePermissionUsedRecords(tokenId); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SHUTDOWN) { // when receive shut down power event, store the cache data to database immediately PermissionRecordManager::GetInstance().UpdatePermRecImmediately(); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Action is invalid."); + LOGE(PRI_DOMAIN, PRI_TAG, "Action is invalid."); } } #endif diff --git a/services/privacymanager/src/database/permission_used_record_db.cpp b/services/privacymanager/src/database/permission_used_record_db.cpp index 5e32ce5f365e0719c9755fa38f5803f385828da9..dadbc53104031b7647072ab0f038cf949f8d5ebe 100644 --- a/services/privacymanager/src/database/permission_used_record_db.cpp +++ b/services/privacymanager/src/database/permission_used_record_db.cpp @@ -26,9 +26,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PermissionUsedRecordDb" -}; constexpr const char* FIELD_COUNT_NUMBER = "count"; constexpr const char* INTEGER_STR = " integer not null,"; constexpr const char* CREATE_TABLE_STR = "create table if not exists "; @@ -57,14 +54,14 @@ PermissionUsedRecordDb::~PermissionUsedRecordDb() void PermissionUsedRecordDb::OnCreate() { - ACCESSTOKEN_LOG_INFO(LABEL, "Entry"); + LOGI(PRI_DOMAIN, PRI_TAG, "Entry"); CreatePermissionRecordTable(); CreatePermissionUsedTypeTable(); } void PermissionUsedRecordDb::OnUpdate(int32_t version) { - ACCESSTOKEN_LOG_INFO(LABEL, "Entry"); + LOGI(PRI_DOMAIN, PRI_TAG, "Entry"); if (version == DataBaseVersion::VERISION_1) { InsertLockScreenStatusColumn(); InsertPermissionUsedTypeColumn(); @@ -125,7 +122,7 @@ int32_t PermissionUsedRecordDb::Add(DataType type, const std::vector lock(this->rwLock_); std::string prepareSql = CreateInsertPrepareSqlCmd(type); if (prepareSql.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Type %{public}u invalid", type); + LOGE(PRI_DOMAIN, PRI_TAG, "Type %{public}u invalid", type); return FAILURE; } @@ -139,17 +136,17 @@ int32_t PermissionUsedRecordDb::Add(DataType type, const std::vector columnNames = conditions.GetAllKeys(); std::string prepareSql = CreateDeletePrepareSqlCmd(type, columnNames); if (prepareSql.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Type %{public}u invalid", type); + LOGE(PRI_DOMAIN, PRI_TAG, "Type %{public}u invalid", type); return FAILURE; } @@ -181,7 +178,7 @@ int32_t PermissionUsedRecordDb::FindByConditions(DataType type, const std::set lock(this->rwLock_); std::string prepareSql = CreateUpdatePrepareSqlCmd(type, modifyNames, conditionNames); if (prepareSql.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Type %{public}u invalid", type); + LOGE(PRI_DOMAIN, PRI_TAG, "Type %{public}u invalid", type); return FAILURE; } @@ -274,7 +271,7 @@ int32_t PermissionUsedRecordDb::Update(DataType type, const GenericValues& modif int32_t ret = statement.Step(); if (ret != Statement::State::DONE) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(PRI_DOMAIN, PRI_TAG, "Update table Type %{public}u failed, errCode is %{public}d, errMsg is %{public}s.", type, ret, SpitError().c_str()); return FAILURE; @@ -291,7 +288,7 @@ int32_t PermissionUsedRecordDb::Query(DataType type, const GenericValues& condit OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); std::string prepareSql = CreateQueryPrepareSqlCmd(type, conditionColumns); if (prepareSql.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Type %{public}u invalid.", type); + LOGE(PRI_DOMAIN, PRI_TAG, "Type %{public}u invalid.", type); return FAILURE; } @@ -573,7 +570,7 @@ int32_t PermissionUsedRecordDb::InsertLockScreenStatusColumn() const PrivacyFiledConst::FIELD_LOCKSCREEN_STATUS + "=" + std::to_string(LockScreenStatusChangeType::PERM_ACTIVE_IN_UNLOCKED); int32_t checkResult = ExecuteSql(checkSql); - ACCESSTOKEN_LOG_INFO(LABEL, "Check result:%{public}d", checkResult); + LOGI(PRI_DOMAIN, PRI_TAG, "Check result:%{public}d", checkResult); if (checkResult != -1) { return SUCCESS; } @@ -584,7 +581,7 @@ int32_t PermissionUsedRecordDb::InsertLockScreenStatusColumn() const .append(" integer default ") .append(std::to_string(LockScreenStatusChangeType::PERM_ACTIVE_IN_UNLOCKED)); int32_t insertResult = ExecuteSql(sql); - ACCESSTOKEN_LOG_INFO(LABEL, "Insert column result:%{public}d", insertResult); + LOGI(PRI_DOMAIN, PRI_TAG, "Insert column result:%{public}d", insertResult); return insertResult; } @@ -598,7 +595,7 @@ int32_t PermissionUsedRecordDb::InsertPermissionUsedTypeColumn() const PrivacyFiledConst::FIELD_USED_TYPE + "=" + std::to_string(PermissionUsedType::NORMAL_TYPE); int32_t checkResult = ExecuteSql(checkSql); - ACCESSTOKEN_LOG_INFO(LABEL, "Check result:%{public}d", checkResult); + LOGI(PRI_DOMAIN, PRI_TAG, "Check result:%{public}d", checkResult); if (checkResult != -1) { return SUCCESS; } @@ -609,7 +606,7 @@ int32_t PermissionUsedRecordDb::InsertPermissionUsedTypeColumn() const .append(" integer default ") .append(std::to_string(PermissionUsedType::NORMAL_TYPE)); int32_t insertResult = ExecuteSql(sql); - ACCESSTOKEN_LOG_INFO(LABEL, "Insert column result:%{public}d", insertResult); + LOGI(PRI_DOMAIN, PRI_TAG, "Insert column result:%{public}d", insertResult); return insertResult; } @@ -664,7 +661,7 @@ int32_t PermissionUsedRecordDb::UpdatePermissionRecordTablePrimaryKey() const int32_t createNewRes = ExecuteSql(createNewSql); // 1、create new table with new primary key if (createNewRes != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Create new table failed, errCode is %{public}d, errMsg is %{public}s.", + LOGE(PRI_DOMAIN, PRI_TAG, "Create new table failed, errCode is %{public}d, errMsg is %{public}s.", createNewRes, SpitError().c_str()); return FAILURE; } @@ -672,7 +669,7 @@ int32_t PermissionUsedRecordDb::UpdatePermissionRecordTablePrimaryKey() const std::string copyDataSql = "insert into " + newTableName + " select * from " + tableName; int32_t copyDataRes = ExecuteSql(copyDataSql); // 2、copy data from old table to new table if (copyDataRes != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Copy data from old table failed, errCode is %{public}d, errMsg is %{public}s.", + LOGE(PRI_DOMAIN, PRI_TAG, "Copy data from old table failed, err is %{public}d, errMsg is %{public}s.", copyDataRes, SpitError().c_str()); RollbackTransaction(); return FAILURE; @@ -681,7 +678,7 @@ int32_t PermissionUsedRecordDb::UpdatePermissionRecordTablePrimaryKey() const std::string dropOldSql = "drop table " + tableName; int32_t dropOldRes = ExecuteSql(dropOldSql); // 3、drop old table if (dropOldRes != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Drop old table failed, errCode is %{public}d, errMsg is %{public}s.", + LOGE(PRI_DOMAIN, PRI_TAG, "Drop old table failed, errCode is %{public}d, errMsg is %{public}s.", dropOldRes, SpitError().c_str()); RollbackTransaction(); return FAILURE; @@ -690,7 +687,7 @@ int32_t PermissionUsedRecordDb::UpdatePermissionRecordTablePrimaryKey() const std::string renameSql = "alter table " + newTableName + " rename to " + tableName; int32_t renameRes = ExecuteSql(renameSql); // 4、rename new table to old if (renameRes != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Rename table failed, errCode is %{public}d, errMsg is %{public}s.", + LOGE(PRI_DOMAIN, PRI_TAG, "Rename table failed, errCode is %{public}d, errMsg is %{public}s.", renameRes, SpitError().c_str()); RollbackTransaction(); return FAILURE; diff --git a/services/privacymanager/src/database/privacy_field_const.cpp b/services/privacymanager/src/database/privacy_field_const.cpp deleted file mode 100644 index 845efa00da23db6e122398868943fdf00033e817..0000000000000000000000000000000000000000 --- a/services/privacymanager/src/database/privacy_field_const.cpp +++ /dev/null @@ -1,39 +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 "privacy_field_const.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -const std::string PrivacyFiledConst::FIELD_TOKEN_ID = "token_id"; -const std::string PrivacyFiledConst::FIELD_DEVICE_ID = "device_id"; -const std::string PrivacyFiledConst::FIELD_OP_CODE = "op_code"; -const std::string PrivacyFiledConst::FIELD_STATUS = "status"; -const std::string PrivacyFiledConst::FIELD_TIMESTAMP = "timestamp"; -const std::string PrivacyFiledConst::FIELD_ACCESS_DURATION = "access_duration"; -const std::string PrivacyFiledConst::FIELD_ACCESS_COUNT = "access_count"; -const std::string PrivacyFiledConst::FIELD_REJECT_COUNT = "reject_count"; - -const std::string PrivacyFiledConst::FIELD_TIMESTAMP_BEGIN = "timestamp_begin"; -const std::string PrivacyFiledConst::FIELD_TIMESTAMP_END = "timestamp_end"; -const std::string PrivacyFiledConst::FIELD_FLAG = "flag"; - -const std::string PrivacyFiledConst::FIELD_LOCKSCREEN_STATUS = "lockScreenStatus"; - -const std::string PrivacyFiledConst::FIELD_PERMISSION_CODE = "permission_code"; -const std::string PrivacyFiledConst::FIELD_USED_TYPE = "used_type"; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS diff --git a/services/privacymanager/src/record/on_permission_used_record_callback_proxy.cpp b/services/privacymanager/src/record/on_permission_used_record_callback_proxy.cpp index ce1c59c41efbce64246131b94e79854f62c5ed71..4991e6dceeafcfb5e8446dca7076dbb6194c2766 100644 --- a/services/privacymanager/src/record/on_permission_used_record_callback_proxy.cpp +++ b/services/privacymanager/src/record/on_permission_used_record_callback_proxy.cpp @@ -21,12 +21,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "OnPermissionUsedRecordCallbackProxy" -}; -} - OnPermissionUsedRecordCallbackProxy::OnPermissionUsedRecordCallbackProxy(const sptr& impl) : IRemoteProxy(impl) { } @@ -39,14 +33,14 @@ void OnPermissionUsedRecordCallbackProxy::OnQueried(ErrCode code, PermissionUsed MessageParcel data; data.WriteInterfaceToken(OnPermissionUsedRecordCallback::GetDescriptor()); if (!data.WriteInt32(code)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(code)"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to WriteParcelable(code)"); return; } PermissionUsedResultParcel usedResultParcel; usedResultParcel.result = result; if (!data.WriteParcelable(&usedResultParcel)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(result)"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to WriteParcelable(result)"); return; } @@ -54,17 +48,17 @@ void OnPermissionUsedRecordCallbackProxy::OnQueried(ErrCode code, PermissionUsed MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null."); + LOGE(PRI_DOMAIN, PRI_TAG, "Remote service null."); return; } int32_t requestResult = remote->SendRequest( static_cast(PrivacyPermissionRecordInterfaceCode::ON_QUERIED), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result: %{public}d", requestResult); + LOGE(PRI_DOMAIN, PRI_TAG, "Send request fail, result: %{public}d", requestResult); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "SendRequest success"); + LOGI(PRI_DOMAIN, PRI_TAG, "SendRequest success"); } } // namespace AccessToken } // namespace Security diff --git a/services/privacymanager/src/record/permission_record_manager.cpp b/services/privacymanager/src/record/permission_record_manager.cpp index 0268ac750e7dbe462569b0320f0205da498b27c1..f17024303e352020cb0ce364e3b448b9eae51627 100644 --- a/services/privacymanager/src/record/permission_record_manager.cpp +++ b/services/privacymanager/src/record/permission_record_manager.cpp @@ -57,9 +57,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PermissionRecordManager" -}; static const int32_t VALUE_MAX_LEN = 32; constexpr const char* CAMERA_PERMISSION_NAME = "ohos.permission.CAMERA"; constexpr const char* MICROPHONE_PERMISSION_NAME = "ohos.permission.MICROPHONE"; @@ -110,7 +107,7 @@ PermissionRecordManager::~PermissionRecordManager() void PrivacyAppStateObserver::OnAppStateChanged(const AppStateData &appStateData) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "OnChange(id=%{public}d, pid=%{public}d, state=%{public}d).", + LOGD(PRI_DOMAIN, PRI_TAG, "OnChange(id=%{public}d, pid=%{public}d, state=%{public}d).", appStateData.accessTokenId, appStateData.pid, appStateData.state); ActiveChangeType status = PERM_INACTIVE; @@ -124,7 +121,7 @@ void PrivacyAppStateObserver::OnAppStateChanged(const AppStateData &appStateData void PrivacyAppStateObserver::OnAppStopped(const AppStateData &appStateData) { - ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(id=%{public}d, state=%{public}d).", + LOGI(PRI_DOMAIN, PRI_TAG, "OnChange(id=%{public}d, state=%{public}d).", appStateData.accessTokenId, appStateData.state); if (appStateData.state == static_cast(ApplicationState::APP_STATE_TERMINATED)) { @@ -134,7 +131,7 @@ void PrivacyAppStateObserver::OnAppStopped(const AppStateData &appStateData) void PrivacyAppStateObserver::OnProcessDied(const ProcessData &processData) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "OnChange(id=%{public}u, pid=%{public}d, state=%{public}d).", + LOGD(PRI_DOMAIN, PRI_TAG, "OnChange(id=%{public}u, pid=%{public}d, state=%{public}d).", processData.accessTokenId, processData.pid, processData.state); PermissionRecordManager::GetInstance().RemoveRecordFromStartListByPid(processData.accessTokenId, processData.pid); @@ -194,14 +191,14 @@ int32_t PermissionRecordManager::MergeOrInsertRecord(const PermissionRecord& rec { std::lock_guard lock(permUsedRecMutex_); if (permUsedRecList_.empty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "First record in cache!"); + LOGI(PRI_DOMAIN, PRI_TAG, "First record in cache!"); AddRecToCacheAndValueVec(record, insertRecords); } else { bool mergeFlag = false; for (auto it = permUsedRecList_.begin(); it != permUsedRecList_.end(); ++it) { if (RecordMergeCheck(it->record, record)) { - ACCESSTOKEN_LOG_INFO(LABEL, "Merge record, ori timestamp is %{public}" PRId64 ".", + LOGI(PRI_DOMAIN, PRI_TAG, "Merge record, ori timestamp is %{public}" PRId64 ".", it->record.timestamp); // merge new record to older one if match the merge condition @@ -230,11 +227,11 @@ int32_t PermissionRecordManager::MergeOrInsertRecord(const PermissionRecord& rec int32_t res = PermissionUsedRecordDb::GetInstance().Add(PermissionUsedRecordDb::DataType::PERMISSION_RECORD, insertRecords); if (res != PermissionUsedRecordDb::ExecuteResult::SUCCESS) { - ACCESSTOKEN_LOG_INFO(LABEL, "Add permission_record_table failed!"); + LOGI(PRI_DOMAIN, PRI_TAG, "Add permission_record_table failed!"); return res; } - ACCESSTOKEN_LOG_INFO(LABEL, "Add record, id %{public}d, op %{public}d, status: %{public}d, sucCnt: %{public}d, " + LOGI(PRI_DOMAIN, PRI_TAG, "Add, id %{public}d, op %{public}d, status: %{public}d, sucCnt: %{public}d, " "failCnt: %{public}d, lockScreenStatus %{public}d, timestamp %{public}" PRId64 ", type %{public}d.", record.tokenId, record.opCode, record.status, record.accessCount, record.rejectCount, record.lockScreenStatus, record.timestamp, record.type); @@ -287,7 +284,7 @@ int32_t PermissionRecordManager::AddRecord(const PermissionRecord& record) whether update database succeed or not, recod remove from cache */ if ((it->needUpdateToDb) && (!UpdatePermissionUsedRecordToDb(it->record))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Record with timestamp %{public}" PRId64 "update database failed!", + LOGE(PRI_DOMAIN, PRI_TAG, "Record with timestamp %{public}" PRId64 "update database failed!", it->record.timestamp); } @@ -310,12 +307,12 @@ void PermissionRecordManager::UpdatePermRecImmediately() int32_t PermissionRecordManager::GetPermissionRecord(const AddPermParamInfo& info, PermissionRecord& record) { if (AccessTokenKit::GetTokenTypeFlag(info.tokenId) != TOKEN_HAP) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Not hap(%{public}d).", info.tokenId); + LOGE(PRI_DOMAIN, PRI_TAG, "Not hap(%{public}d).", info.tokenId); return PrivacyError::ERR_PARAM_INVALID; } int32_t opCode; if (!Constant::TransferPermissionToOpcode(info.permissionName, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid perm(%{public}s)", info.permissionName.c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Invalid perm(%{public}s)", info.permissionName.c_str()); return PrivacyError::ERR_PERMISSION_NOT_EXIST; } if (GetMuteStatus(info.permissionName, EDM)) { @@ -331,7 +328,7 @@ int32_t PermissionRecordManager::GetPermissionRecord(const AddPermParamInfo& inf record.timestamp = AccessToken::TimeUtil::GetCurrentTimestamp(); record.accessDuration = 0; record.type = info.type; - ACCESSTOKEN_LOG_DEBUG(LABEL, "Record status: %{public}d", record.status); + LOGD(PRI_DOMAIN, PRI_TAG, "Record status: %{public}d", record.status); return Constant::SUCCESS; } @@ -365,7 +362,7 @@ bool PermissionRecordManager::AddOrUpdateUsedTypeIfNeeded(const AccessTokenID to if (results.empty()) { // empty means there is no permission used type record, add it - ACCESSTOKEN_LOG_DEBUG(LABEL, "No exsit record, add it."); + LOGD(PRI_DOMAIN, PRI_TAG, "No exsit record, add it."); GenericValues recordValue; recordValue.Put(PrivacyFiledConst::FIELD_TOKEN_ID, static_cast(tokenId)); @@ -382,18 +379,18 @@ bool PermissionRecordManager::AddOrUpdateUsedTypeIfNeeded(const AccessTokenID to } else { // not empty means there is permission used type record exsit, update it if needed uint32_t dbType = static_cast(results[0].GetInt(PrivacyFiledConst::FIELD_USED_TYPE)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Record exsit, type is %{public}u.", dbType); + LOGD(PRI_DOMAIN, PRI_TAG, "Record exsit, type is %{public}u.", dbType); if ((dbType & inputType) == inputType) { // true means visitTypeEnum has exsits, no need to add - ACCESSTOKEN_LOG_DEBUG(LABEL, "Used type has add."); + LOGD(PRI_DOMAIN, PRI_TAG, "Used type has add."); return true; } else { results[0].Remove(PrivacyFiledConst::FIELD_USED_TYPE); dbType |= inputType; // false means visitTypeEnum not exsits, update record - ACCESSTOKEN_LOG_DEBUG(LABEL, "Used type not add, generate new %{public}u.", dbType); + LOGD(PRI_DOMAIN, PRI_TAG, "Used type not add, generate new %{public}u.", dbType); GenericValues newValue; newValue.Put(PrivacyFiledConst::FIELD_USED_TYPE, static_cast(dbType)); @@ -463,7 +460,7 @@ int32_t PermissionRecordManager::GetPermissionUsedRecords( ExecuteDeletePermissionRecordTask(); if (!request.isRemote && !GetRecordsFromLocalDB(request, result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to GetRecordsFromLocalDB"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to GetRecordsFromLocalDB"); return PrivacyError::ERR_PARAM_INVALID; } return Constant::SUCCESS; @@ -473,7 +470,7 @@ int32_t PermissionRecordManager::GetPermissionUsedRecordsAsync( const PermissionUsedRequest& request, const sptr& callback) { auto task = [request, callback]() { - ACCESSTOKEN_LOG_INFO(LABEL, "GetPermissionUsedRecordsAsync task called"); + LOGI(PRI_DOMAIN, PRI_TAG, "GetPermissionUsedRecordsAsync task called"); PermissionUsedResult result; int32_t retCode = PermissionRecordManager::GetInstance().GetPermissionUsedRecords(request, result); callback->OnQueried(retCode, result); @@ -580,7 +577,7 @@ bool PermissionRecordManager::FillBundleUsedRecord(const GenericValues& value, c // translate database value into PermissionUsedRecord value PermissionUsedRecord record; if (DataTranslator::TranslationGenericValuesIntoPermissionUsedRecord(flag, value, record) != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to transform op(%{public}d)", + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to transform op(%{public}d)", value.GetInt(PrivacyFiledConst::FIELD_OP_CODE)); return false; } @@ -607,7 +604,7 @@ static void AddDebugLog(const AccessTokenID tokenId, const BundleUsedRecord& bun tokenTotalSuccCount += permissionRecord.accessCount; tokenTotalFailCount += permissionRecord.rejectCount; } - ACCESSTOKEN_LOG_INFO(LABEL, "TokenId %{public}d[%{public}s] get %{public}d records, success %{public}d," + LOGI(PRI_DOMAIN, PRI_TAG, "TokenId %{public}d[%{public}s] get %{public}d records, success %{public}d," " failure %{public}d", tokenId, bundleRecord.bundleName.c_str(), queryCount, tokenTotalSuccCount, tokenTotalFailCount); totalSuccCount += tokenTotalSuccCount; @@ -618,7 +615,7 @@ bool PermissionRecordManager::GetRecordsFromLocalDB(const PermissionUsedRequest& { GenericValues andConditionValues; if (DataTranslator::TranslationIntoGenericValues(request, andConditionValues) != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Query time or flag is invalid"); + LOGE(PRI_DOMAIN, PRI_TAG, "Query time or flag is invalid"); return false; } @@ -634,7 +631,7 @@ bool PermissionRecordManager::GetRecordsFromLocalDB(const PermissionUsedRequest& uint32_t currentCount = findRecordsValues.size(); // handle query result if (currentCount == 0) { - ACCESSTOKEN_LOG_INFO(LABEL, "No record match the condition."); + LOGI(PRI_DOMAIN, PRI_TAG, "No record match the condition."); return true; } @@ -673,7 +670,7 @@ bool PermissionRecordManager::GetRecordsFromLocalDB(const PermissionUsedRequest& } if (request.flag == FLAG_PERMISSION_USAGE_SUMMARY) { - ACCESSTOKEN_LOG_INFO(LABEL, "Total success count is %{public}d, total failure count is %{public}d", + LOGI(PRI_DOMAIN, PRI_TAG, "Total success count is %{public}d, total failure count is %{public}d", totalSuccCount, totalFailCount); } @@ -684,7 +681,7 @@ bool PermissionRecordManager::CreateBundleUsedRecord(const AccessTokenID tokenId { HapTokenInfo tokenInfo; if (AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo) != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetHapTokenInfo failed, tokenId is %{public}u.", tokenId); + LOGE(PRI_DOMAIN, PRI_TAG, "GetHapTokenInfo failed, tokenId is %{public}u.", tokenId); return false; } bundleRecord.tokenId = tokenId; @@ -697,14 +694,14 @@ bool PermissionRecordManager::CreateBundleUsedRecord(const AccessTokenID tokenId void PermissionRecordManager::ExecuteDeletePermissionRecordTask() { if (GetCurDeleteTaskNum() > 1) { - ACCESSTOKEN_LOG_INFO(LABEL, "Has delete task!"); + LOGI(PRI_DOMAIN, PRI_TAG, "Has delete task!"); return; } AddDeleteTaskNum(); std::function delayed = ([this]() { DeletePermissionRecord(recordAgingTime_); - ACCESSTOKEN_LOG_INFO(LABEL, "Delete record end."); + LOGI(PRI_DOMAIN, PRI_TAG, "Delete record end."); // Sleep for one minute to avoid frequent refresh of the file. std::this_thread::sleep_for(std::chrono::minutes(1)); ReduceDeleteTaskNum(); @@ -757,7 +754,7 @@ int32_t PermissionRecordManager::AddRecordToStartList( { int32_t opCode; if (!Constant::TransferPermissionToOpcode(permissionName, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid perm(%{public}s)", permissionName.c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Invalid perm(%{public}s)", permissionName.c_str()); return PrivacyError::ERR_PERMISSION_NOT_EXIST; } @@ -775,7 +772,7 @@ int32_t PermissionRecordManager::AddRecordToStartList( break; } } - ACCESSTOKEN_LOG_INFO(LABEL, "Id(%{public}u), pid(%{public}d), opCode(%{public}d),\ + LOGI(PRI_DOMAIN, PRI_TAG, "Id(%{public}u), pid(%{public}d), opCode(%{public}d),\ hasTokenStarted(%{public}d), hasPidStarted(%{public}d).", tokenId, pid, opCode, hasTokenStarted, hasPidStarted); if (!hasTokenStarted) { @@ -817,14 +814,14 @@ void PermissionRecordManager::ExecuteAndUpdateRecord(uint32_t tokenId, int32_t p } if ((perm == CAMERA_PERMISSION_NAME) && (status == PERM_ACTIVE_IN_BACKGROUND) && (!isShow) && (!isAllowedBackGround)) { - ACCESSTOKEN_LOG_INFO(LABEL, "Camera float window is close!"); + LOGI(PRI_DOMAIN, PRI_TAG, "Camera float window is close!"); camPermList.emplace_back(perm); continue; } // update status to input and timestamp to now in cache it->status = status; - ACCESSTOKEN_LOG_DEBUG(LABEL, "TokenId %{public}d get permission %{public}s.", tokenId, perm.c_str()); + LOGD(PRI_DOMAIN, PRI_TAG, "TokenId %{public}d get permission %{public}s.", tokenId, perm.c_str()); } } @@ -839,14 +836,14 @@ void PermissionRecordManager::ExecuteAndUpdateRecord(uint32_t tokenId, int32_t p */ void PermissionRecordManager::NotifyAppStateChange(AccessTokenID tokenId, int32_t pid, ActiveChangeType status) { - ACCESSTOKEN_LOG_INFO(LABEL, "Id %{public}u, pid %{public}d, status %{public}d", tokenId, pid, status); + LOGI(PRI_DOMAIN, PRI_TAG, "Id %{public}u, pid %{public}d, status %{public}d", tokenId, pid, status); // find permissions from startRecordList_ by tokenId which status diff from currStatus ExecuteAndUpdateRecord(tokenId, pid, status); } void PermissionRecordManager::SetLockScreenStatus(int32_t lockScreenStatus) { - ACCESSTOKEN_LOG_INFO(LABEL, "LockScreenStatus %{public}d", lockScreenStatus); + LOGI(PRI_DOMAIN, PRI_TAG, "LockScreenStatus %{public}d", lockScreenStatus); std::lock_guard lock(lockScreenStateMutex_); lockScreenStatus_ = lockScreenStatus; } @@ -877,11 +874,11 @@ int32_t PermissionRecordManager::RemoveRecordFromStartList( { int32_t opCode; if (!Constant::TransferPermissionToOpcode(permissionName, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid permission(%{public}s)", permissionName.c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Invalid permission(%{public}s)", permissionName.c_str()); return PrivacyError::ERR_PERMISSION_NOT_EXIST; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Id %{public}u, pid %{public}d, perm %{public}s", + LOGD(PRI_DOMAIN, PRI_TAG, "Id %{public}u, pid %{public}d, perm %{public}s", tokenId, pid, permissionName.c_str()); int32_t status = PERM_INACTIVE; bool isFind = false; @@ -909,7 +906,7 @@ int32_t PermissionRecordManager::RemoveRecordFromStartList( } if (!isFind) { ret = PrivacyError::ERR_PERMISSION_NOT_START_USING; - ACCESSTOKEN_LOG_ERROR(LABEL, "No records started, tokenId=%{public}u, pid=%{public}d, opCode=%{public}d", + LOGE(PRI_DOMAIN, PRI_TAG, "No records started, tokenId=%{public}u, pid=%{public}d, opCode=%{public}d", tokenId, pid, opCode); } return ret; @@ -921,7 +918,7 @@ int32_t PermissionRecordManager::RemoveRecordFromStartList( */ void PermissionRecordManager::RemoveRecordFromStartListByPid(const AccessTokenID tokenId, int32_t pid) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenId %{public}u, pid %{public}d", tokenId, pid); + LOGI(PRI_DOMAIN, PRI_TAG, "TokenId %{public}u, pid %{public}d", tokenId, pid); { std::vector permList; std::lock_guard lock(startRecordListMutex_); @@ -950,7 +947,7 @@ void PermissionRecordManager::RemoveRecordFromStartListByPid(const AccessTokenID */ void PermissionRecordManager::RemoveRecordFromStartListByToken(const AccessTokenID tokenId) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenId %{public}u", tokenId); + LOGI(PRI_DOMAIN, PRI_TAG, "TokenId %{public}u", tokenId); { std::vector permList; std::lock_guard lock(startRecordListMutex_); @@ -973,7 +970,7 @@ void PermissionRecordManager::RemoveRecordFromStartListByToken(const AccessToken void PermissionRecordManager::RemoveRecordFromStartListByOp(int32_t opCode) { - ACCESSTOKEN_LOG_INFO(LABEL, "OpCode %{public}d", opCode); + LOGI(PRI_DOMAIN, PRI_TAG, "OpCode %{public}d", opCode); std::string perm; Constant::TransferOpcodeToPermission(opCode, perm); { @@ -996,7 +993,7 @@ void PermissionRecordManager::RemoveRecordFromStartListByOp(int32_t opCode) void PermissionRecordManager::CallbackExecute( AccessTokenID tokenId, const std::string& permissionName, int32_t status, PermissionUsedType type) { - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(PRI_DOMAIN, PRI_TAG, "ExecuteCallbackAsync, tokenId %{public}d using permission %{public}s, status %{public}d, type %{public}d", tokenId, permissionName.c_str(), status, type); @@ -1017,10 +1014,10 @@ bool PermissionRecordManager::GetGlobalSwitchStatus(const std::string& permissio // only manage camera and microphone global switch now, other default true if (permissionName == MICROPHONE_PERMISSION_NAME) { isOpen = !isMicMixMute_; - ACCESSTOKEN_LOG_INFO(LABEL, "Permission is %{public}s, status is %{public}d", permissionName.c_str(), isOpen); + LOGI(PRI_DOMAIN, PRI_TAG, "%{public}s, status is %{public}d", permissionName.c_str(), isOpen); } else if (permissionName == CAMERA_PERMISSION_NAME) { isOpen = !isCamMixMute_; - ACCESSTOKEN_LOG_INFO(LABEL, "Permission is %{public}s, status is %{public}d", permissionName.c_str(), isOpen); + LOGI(PRI_DOMAIN, PRI_TAG, "%{public}s, status is %{public}d", permissionName.c_str(), isOpen); } return isOpen; } @@ -1041,11 +1038,11 @@ void PermissionRecordManager::ExecuteAndUpdateRecordByPerm(const std::string& pe continue; } if (switchStatus) { - ACCESSTOKEN_LOG_INFO(LABEL, "Global switch is open, update record from inactive"); + LOGI(PRI_DOMAIN, PRI_TAG, "Global switch is open, update record from inactive"); // no need to store in database when status from inactive to foreground or background record.status = GetAppStatus(record.tokenId); } else { - ACCESSTOKEN_LOG_INFO(LABEL, "Global switch is close, update record to inactive"); + LOGI(PRI_DOMAIN, PRI_TAG, "Global switch is close, update record to inactive"); record.status = PERM_INACTIVE; } recordList.emplace_back(*it); @@ -1064,7 +1061,7 @@ bool PermissionRecordManager::ShowGlobalDialog(const std::string& permissionName } else if (permissionName == MICROPHONE_PERMISSION_NAME) { resource = "microphone"; } else { - ACCESSTOKEN_LOG_INFO(LABEL, "Invalid permissionName(%{public}s).", permissionName.c_str()); + LOGI(PRI_DOMAIN, PRI_TAG, "Invalid permissionName(%{public}s).", permissionName.c_str()); return true; } @@ -1085,7 +1082,7 @@ bool PermissionRecordManager::ShowGlobalDialog(const std::string& permissionName } ErrCode err = abilityManager->StartAbility(want, nullptr); if (err != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to StartAbility, err:%{public}d", err); + LOGE(PRI_DOMAIN, PRI_TAG, "Fail to StartAbility, err:%{public}d", err); return false; } return true; @@ -1094,13 +1091,13 @@ bool PermissionRecordManager::ShowGlobalDialog(const std::string& permissionName void PermissionRecordManager::ExecuteAllCameraExecuteCallback() { - ACCESSTOKEN_LOG_INFO(LABEL, "ExecuteAllCameraExecuteCallback called"); + LOGI(PRI_DOMAIN, PRI_TAG, "ExecuteAllCameraExecuteCallback called"); auto it = [&](uint64_t id, sptr cameraCallback) { auto callback = iface_cast(cameraCallback); AccessTokenID tokenId = static_cast(id); if (callback != nullptr) { - ACCESSTOKEN_LOG_INFO( - LABEL, "CameraCallback tokenId %{public}d changeType %{public}d.", tokenId, PERM_INACTIVE); + LOGI(PRI_DOMAIN, PRI_TAG, + "CameraCallback tokenId %{public}d changeType %{public}d.", tokenId, PERM_INACTIVE); callback->StateChangeNotify(tokenId, false); } }; @@ -1109,14 +1106,15 @@ void PermissionRecordManager::ExecuteAllCameraExecuteCallback() void PermissionRecordManager::ExecuteCameraCallbackAsync(AccessTokenID tokenId, int32_t pid) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry."); + LOGD(PRI_DOMAIN, PRI_TAG, "Entry."); auto task = [tokenId, pid, this]() { uint64_t uniqueId = GetUniqueId(tokenId, pid); - ACCESSTOKEN_LOG_INFO(LABEL, "ExecuteCameraCallbackAsync task called."); + LOGI(PRI_DOMAIN, PRI_TAG, "ExecuteCameraCallbackAsync task called."); auto it = [&](uint64_t id, sptr cameraCallback) { auto callback = iface_cast(cameraCallback); if ((uniqueId == id) && (callback != nullptr)) { - ACCESSTOKEN_LOG_INFO(LABEL, "CameraCallback tokenId(%{public}u) pid( %{public}d) changeType %{public}d", + LOGI(PRI_DOMAIN, PRI_TAG, + "CameraCallback tokenId(%{public}u) pid( %{public}d) changeType %{public}d", tokenId, pid, PERM_INACTIVE); callback->StateChangeNotify(tokenId, false); } @@ -1125,20 +1123,20 @@ void PermissionRecordManager::ExecuteCameraCallbackAsync(AccessTokenID tokenId, }; std::thread executeThread(task); executeThread.detach(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "The cameraCallback execution is complete."); + LOGD(PRI_DOMAIN, PRI_TAG, "The cameraCallback execution is complete."); } int32_t PermissionRecordManager::StartUsingPermission( AccessTokenID tokenId, int32_t pid, const std::string& permissionName, PermissionUsedType type) { if (AccessTokenKit::GetTokenTypeFlag(tokenId) != TOKEN_HAP) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Not hap(%{public}d).", tokenId); + LOGD(PRI_DOMAIN, PRI_TAG, "Not hap(%{public}d).", tokenId); return PrivacyError::ERR_PARAM_INVALID; } InitializeMuteState(permissionName); if (GetMuteStatus(permissionName, EDM)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "EDM not allow."); + LOGE(PRI_DOMAIN, PRI_TAG, "EDM not allow."); return PrivacyError::ERR_EDM_POLICY_CHECK_FAILED; } if (!Register()) { @@ -1161,13 +1159,13 @@ int32_t PermissionRecordManager::StartUsingPermission(AccessTokenID tokenId, int const std::string& permissionName, const sptr& callback, PermissionUsedType type) { if ((permissionName != CAMERA_PERMISSION_NAME) || (AccessTokenKit::GetTokenTypeFlag(tokenId) != TOKEN_HAP)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Token(%{public}u), perm(%{public}s).", tokenId, permissionName.c_str()); + LOGD(PRI_DOMAIN, PRI_TAG, "Token(%{public}u), perm(%{public}s).", tokenId, permissionName.c_str()); return PrivacyError::ERR_PARAM_INVALID; } InitializeMuteState(permissionName); if (GetMuteStatus(permissionName, EDM)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "EDM not allow."); + LOGE(PRI_DOMAIN, PRI_TAG, "EDM not allow."); return PrivacyError::ERR_EDM_POLICY_CHECK_FAILED; } @@ -1202,7 +1200,7 @@ int32_t PermissionRecordManager::StopUsingPermission( ExecuteDeletePermissionRecordTask(); if (AccessTokenKit::GetTokenTypeFlag(tokenId) != TOKEN_HAP) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Not hap(%{public}d).", tokenId); + LOGD(PRI_DOMAIN, PRI_TAG, "Not hap(%{public}d).", tokenId); return PrivacyError::ERR_PARAM_INVALID; } @@ -1214,7 +1212,7 @@ void PermissionRecordManager::PermListToString(const std::vector& p std::string permStr; permStr = accumulate(permList.begin(), permList.end(), std::string(" ")); - ACCESSTOKEN_LOG_INFO(LABEL, "PermStr =%{public}s.", permStr.c_str()); + LOGI(PRI_DOMAIN, PRI_TAG, "PermStr =%{public}s.", permStr.c_str()); } int32_t PermissionRecordManager::PermissionListFilter( @@ -1230,10 +1228,10 @@ int32_t PermissionRecordManager::PermissionListFilter( permSet.insert(perm); continue; } - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission %{public}s invalid!", perm.c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Permission %{public}s invalid!", perm.c_str()); } if ((listRes.empty()) && (!listSrc.empty())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Valid permission size is 0!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Valid permission size is 0!"); return PrivacyError::ERR_PARAM_INVALID; } PermListToString(listRes); @@ -1248,7 +1246,7 @@ bool PermissionRecordManager::IsAllowedUsingCamera(AccessTokenID tokenId, int32_ return true; } - ACCESSTOKEN_LOG_INFO(LABEL, "Id %{public}d, appStatus %{public}d.", tokenId, status); + LOGI(PRI_DOMAIN, PRI_TAG, "Id %{public}d, appStatus %{public}d.", tokenId, status); return (AccessTokenKit::VerifyAccessToken(tokenId, "ohos.permission.CAMERA_BACKGROUND") == PERMISSION_GRANTED); } @@ -1256,7 +1254,7 @@ bool PermissionRecordManager::IsAllowedUsingCamera(AccessTokenID tokenId, int32_ bool PermissionRecordManager::IsAllowedUsingMicrophone(AccessTokenID tokenId, int32_t pid) { int32_t status = GetAppStatus(tokenId, pid); - ACCESSTOKEN_LOG_INFO(LABEL, "Id %{public}d, status is %{public}d.", tokenId, status); + LOGI(PRI_DOMAIN, PRI_TAG, "Id %{public}d, status is %{public}d.", tokenId, status); if (status == ActiveChangeType::PERM_ACTIVE_IN_FOREGROUND) { return true; } @@ -1273,7 +1271,7 @@ bool PermissionRecordManager::IsAllowedUsingPermission(AccessTokenID tokenId, co int32_t pid) { if (AccessTokenKit::GetTokenTypeFlag(tokenId) != TOKEN_HAP) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Id(%{public}d) is not hap.", tokenId); + LOGD(PRI_DOMAIN, PRI_TAG, "Id(%{public}d) is not hap.", tokenId); return false; } @@ -1282,7 +1280,7 @@ bool PermissionRecordManager::IsAllowedUsingPermission(AccessTokenID tokenId, co } else if (permissionName == MICROPHONE_PERMISSION_NAME) { return IsAllowedUsingMicrophone(tokenId, pid); } - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid permission(%{public}s).", permissionName.c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Invalid permission(%{public}s).", permissionName.c_str()); return false; } @@ -1314,22 +1312,22 @@ int32_t PermissionRecordManager::SetMutePolicy(const PolicyType& policyType, con int32_t PermissionRecordManager::SetHapWithFGReminder(uint32_t tokenId, bool isAllowed) { if (AccessTokenKit::GetTokenTypeFlag(tokenId) != TOKEN_HAP) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Not hap(%{public}d).", tokenId); + LOGE(PRI_DOMAIN, PRI_TAG, "Not hap(%{public}d).", tokenId); return PrivacyError::ERR_PARAM_INVALID; } std::lock_guard lock(foreReminderMutex_); auto iter = std::find(foreTokenIdList_.begin(), foreTokenIdList_.end(), tokenId); if (iter == foreTokenIdList_.end() && isAllowed) { foreTokenIdList_.emplace_back(tokenId); - ACCESSTOKEN_LOG_INFO(LABEL, "Set hap(%{public}d) foreground.", tokenId); + LOGI(PRI_DOMAIN, PRI_TAG, "Set hap(%{public}d) foreground.", tokenId); return RET_SUCCESS; } if (iter != foreTokenIdList_.end() && !isAllowed) { foreTokenIdList_.erase(iter); - ACCESSTOKEN_LOG_INFO(LABEL, "cancel hap(%{public}d) foreground.", tokenId); + LOGI(PRI_DOMAIN, PRI_TAG, "cancel hap(%{public}d) foreground.", tokenId); return RET_SUCCESS; } - ACCESSTOKEN_LOG_ERROR(LABEL, "(%{public}d) is invalid to be operated.", tokenId); + LOGE(PRI_DOMAIN, PRI_TAG, "(%{public}d) is invalid to be operated.", tokenId); return PrivacyError::ERR_PARAM_INVALID; } @@ -1398,7 +1396,7 @@ void PermissionRecordManager::ModifyMuteStatus(const std::string& permissionName isCamMixMute_ = isMute; } } - ACCESSTOKEN_LOG_INFO(LABEL, "permissionName: %{public}s, isMute: %{public}d, index: %{public}d.", + LOGI(PRI_DOMAIN, PRI_TAG, "permissionName: %{public}s, isMute: %{public}d, index: %{public}d.", permissionName.c_str(), isMute, index); } @@ -1414,7 +1412,7 @@ bool PermissionRecordManager::GetMuteStatus(const std::string& permissionName, i } else { return false; } - ACCESSTOKEN_LOG_INFO(LABEL, "perm: %{public}s, isMute: %{public}d, index: %{public}d.", + LOGI(PRI_DOMAIN, PRI_TAG, "perm: %{public}s, isMute: %{public}d, index: %{public}d.", permissionName.c_str(), isMute, index); return isMute; } @@ -1464,7 +1462,7 @@ int32_t PermissionRecordManager::GetPermissionUsedTypeInfos(AccessTokenID tokenI if (tokenId != INVALID_TOKENID) { HapTokenInfo tokenInfo; if (AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo) != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid tokenId(%{public}d).", tokenId); + LOGE(PRI_DOMAIN, PRI_TAG, "Invalid tokenId(%{public}d).", tokenId); return PrivacyError::ERR_TOKENID_NOT_EXIST; } value.Put(PrivacyFiledConst::FIELD_TOKEN_ID, static_cast(tokenId)); @@ -1473,7 +1471,7 @@ int32_t PermissionRecordManager::GetPermissionUsedTypeInfos(AccessTokenID tokenI if (!permissionName.empty()) { int32_t opCode; if (!Constant::TransferPermissionToOpcode(permissionName, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid (%{public}s).", permissionName.c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Invalid (%{public}s).", permissionName.c_str()); return PrivacyError::ERR_PERMISSION_NOT_EXIST; } value.Put(PrivacyFiledConst::FIELD_PERMISSION_CODE, opCode); @@ -1489,7 +1487,7 @@ int32_t PermissionRecordManager::GetPermissionUsedTypeInfos(AccessTokenID tokenI AddDataValueToResults(valueResult, results); } - ACCESSTOKEN_LOG_INFO(LABEL, "Get %{public}zu permission used type records.", results.size()); + LOGI(PRI_DOMAIN, PRI_TAG, "Get %{public}zu permission used type records.", results.size()); return Constant::SUCCESS; } @@ -1520,7 +1518,7 @@ bool PermissionRecordManager::Register() if (appManagerDeathCallback_ == nullptr) { appManagerDeathCallback_ = std::make_shared(); if (appManagerDeathCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register appManagerDeathCallback failed."); + LOGE(PRI_DOMAIN, PRI_TAG, "Register appManagerDeathCallback failed."); return false; } AppManagerAccessClient::GetInstance().RegisterDeathCallback(appManagerDeathCallback_); @@ -1532,12 +1530,12 @@ bool PermissionRecordManager::Register() if (appStateCallback_ == nullptr) { appStateCallback_ = new (std::nothrow) PrivacyAppStateObserver(); if (appStateCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register appStateCallback failed."); + LOGE(PRI_DOMAIN, PRI_TAG, "Register appStateCallback failed."); return false; } int32_t result = AppManagerAccessClient::GetInstance().RegisterApplicationStateObserver(appStateCallback_); if (result != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register application state observer failed(%{public}d).", result); + LOGE(PRI_DOMAIN, PRI_TAG, "Register application state observer failed(%{public}d).", result); return false; } } @@ -1574,21 +1572,21 @@ void HandleWindowDied() bool PermissionRecordManager::RegisterWindowCallback() { #ifdef CAMERA_FLOAT_WINDOW_ENABLE - ACCESSTOKEN_LOG_INFO(LABEL, "Begin to RegisterWindowCallback."); + LOGI(PRI_DOMAIN, PRI_TAG, "Begin to RegisterWindowCallback."); std::lock_guard lock(windowMutex_); WindowChangeCallback floatCallback = UpdateCameraFloatWindowStatus; if (floatWindowCallback_ == nullptr) { floatWindowCallback_ = new (std::nothrow) PrivacyWindowManagerAgent(floatCallback); if (floatWindowCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to new PrivacyWindowManagerAgent."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to new PrivacyWindowManagerAgent."); return false; } } ErrCode err = PrivacyWindowManagerClient::GetInstance().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, floatWindowCallback_); if (err != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to register float window listener, err:%{public}d", err); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to register float window listener, err:%{public}d", err); return false; } @@ -1598,7 +1596,7 @@ bool PermissionRecordManager::RegisterWindowCallback() if (pipWindowCallback_ == nullptr) { pipWindowCallback_ = new (std::nothrow) PrivacyWindowManagerAgent(pipCallback); if (floatWindowCallback_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to new PrivacyWindowManagerAgent."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to new PrivacyWindowManagerAgent."); return false; } } @@ -1606,7 +1604,7 @@ bool PermissionRecordManager::RegisterWindowCallback() err = PrivacyWindowManagerClient::GetInstance().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW, pipWindowCallback_); if (err != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to register pip window listener, err:%{public}d", err); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to register pip window listener, err:%{public}d", err); PrivacyWindowManagerClient::GetInstance().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, floatWindowCallback_); return false; @@ -1622,15 +1620,15 @@ void PermissionRecordManager::InitializeMuteState(const std::string& permissionN { if (permissionName == MICROPHONE_PERMISSION_NAME) { bool isMicMute = AudioManagerAdapter::GetInstance().GetPersistentMicMuteState(); - ACCESSTOKEN_LOG_INFO(LABEL, "Mic mute state: %{public}d.", isMicMute); + LOGI(PRI_DOMAIN, PRI_TAG, "Mic mute state: %{public}d.", isMicMute); ModifyMuteStatus(MICROPHONE_PERMISSION_NAME, MIXED, isMicMute); { std::lock_guard lock(micLoadMutex_); if (!isMicLoad_) { - ACCESSTOKEN_LOG_INFO(LABEL, "Mic mute state: %{public}d.", isMicLoad_); + LOGI(PRI_DOMAIN, PRI_TAG, "Mic mute state: %{public}d.", isMicLoad_); bool isEdmMute = false; if (!GetMuteParameter(EDM_MIC_MUTE_KEY, isEdmMute)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get param failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Get param failed"); return; } ModifyMuteStatus(MICROPHONE_PERMISSION_NAME, EDM, isEdmMute); @@ -1638,14 +1636,14 @@ void PermissionRecordManager::InitializeMuteState(const std::string& permissionN } } else if (permissionName == CAMERA_PERMISSION_NAME) { bool isCameraMute = CameraManagerAdapter::GetInstance().IsCameraMuted(); - ACCESSTOKEN_LOG_INFO(LABEL, "Camera mute state: %{public}d.", isCameraMute); + LOGI(PRI_DOMAIN, PRI_TAG, "Camera mute state: %{public}d.", isCameraMute); ModifyMuteStatus(CAMERA_PERMISSION_NAME, MIXED, isCameraMute); { std::lock_guard lock(camLoadMutex_); if (!isCamLoad_) { bool isEdmMute = false; if (!GetMuteParameter(EDM_CAMERA_MUTE_KEY, isEdmMute)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get camera param failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "Get camera param failed"); return; } ModifyMuteStatus(CAMERA_PERMISSION_NAME, EDM, isEdmMute); @@ -1669,12 +1667,12 @@ bool PermissionRecordManager::GetMuteParameter(const char* key, bool& isMute) char value[VALUE_MAX_LEN] = {0}; int32_t ret = GetParameter(key, "", value, VALUE_MAX_LEN - 1); if (ret < 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Return default value, ret=%{public}d", ret); + LOGE(PRI_DOMAIN, PRI_TAG, "Return default value, ret=%{public}d", ret); return false; } isMute = false; if (strncmp(value, "true", VALUE_MAX_LEN) == 0) { - ACCESSTOKEN_LOG_INFO(LABEL, "EDM not allow."); + LOGI(PRI_DOMAIN, PRI_TAG, "EDM not allow."); isMute = true; } return true; @@ -1682,14 +1680,14 @@ bool PermissionRecordManager::GetMuteParameter(const char* key, bool& isMute) void PermissionRecordManager::OnAppMgrRemoteDiedHandle() { - ACCESSTOKEN_LOG_INFO(LABEL, "Handle app fwk died."); + LOGI(PRI_DOMAIN, PRI_TAG, "Handle app fwk died."); std::lock_guard lock(appStateMutex_); appStateCallback_ = nullptr; } void PermissionRecordManager::OnAudioMgrRemoteDiedHandle() { - ACCESSTOKEN_LOG_INFO(LABEL, "Handle audio fwk died."); + LOGI(PRI_DOMAIN, PRI_TAG, "Handle audio fwk died."); { std::lock_guard lock(micLoadMutex_); isMicLoad_ = false; @@ -1699,7 +1697,7 @@ void PermissionRecordManager::OnAudioMgrRemoteDiedHandle() void PermissionRecordManager::OnCameraMgrRemoteDiedHandle() { - ACCESSTOKEN_LOG_INFO(LABEL, "Handle camera fwk died."); + LOGI(PRI_DOMAIN, PRI_TAG, "Handle camera fwk died."); { std::lock_guard lock(camLoadMutex_); isCamLoad_ = false; @@ -1727,7 +1725,7 @@ bool PermissionRecordManager::IsCameraWindowShow(AccessTokenID tokenId) */ void PermissionRecordManager::NotifyCameraWindowChange(bool isPip, AccessTokenID tokenId, bool isShowing) { - ACCESSTOKEN_LOG_INFO(LABEL, "Update window, isPip(%{public}d), id(%{public}u), status(%{public}d)", + LOGI(PRI_DOMAIN, PRI_TAG, "Update window, isPip(%{public}d), id(%{public}u), status(%{public}d)", isPip, tokenId, isShowing); { std::lock_guard lock(windowStatusMutex_); @@ -1740,11 +1738,12 @@ void PermissionRecordManager::NotifyCameraWindowChange(bool isPip, AccessTokenID } } if (isShowing) { - ACCESSTOKEN_LOG_INFO(LABEL, "Camera float window is showing!"); + LOGI(PRI_DOMAIN, PRI_TAG, "Camera float window is showing!"); } else { if ((GetAppStatus(tokenId) == ActiveChangeType::PERM_ACTIVE_IN_BACKGROUND) && !IsCameraWindowShow(tokenId)) { - ACCESSTOKEN_LOG_INFO(LABEL, "Token(%{public}d) is background, pip and float window is not show.", tokenId); + LOGI(PRI_DOMAIN, PRI_TAG, + "Token(%{public}d) is background, pip and float window is not show.", tokenId); ExecuteCameraCallbackAsync(tokenId, -1); } } @@ -1752,7 +1751,7 @@ void PermissionRecordManager::NotifyCameraWindowChange(bool isPip, AccessTokenID void PermissionRecordManager::ClearWindowShowing() { - ACCESSTOKEN_LOG_INFO(LABEL, "Clear window show status."); + LOGI(PRI_DOMAIN, PRI_TAG, "Clear window show status."); { std::lock_guard lock(windowStatusMutex_); camFloatWindowShowing_ = false; @@ -1766,7 +1765,7 @@ void PermissionRecordManager::ClearWindowShowing() /* Handle window manager die */ void PermissionRecordManager::OnWindowMgrRemoteDied() { - ACCESSTOKEN_LOG_INFO(LABEL, "Handle window manager died."); + LOGI(PRI_DOMAIN, PRI_TAG, "Handle window manager died."); ClearWindowShowing(); } #endif @@ -1786,7 +1785,7 @@ void PermissionRecordManager::GetConfigValue() LibraryLoader loader(CONFIG_POLICY_LIBPATH); ConfigPolicyLoaderInterface* policy = loader.GetObject(); if (policy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Dlopen libaccesstoken_config_policy failed."); + LOGE(PRI_DOMAIN, PRI_TAG, "Dlopen libaccesstoken_config_policy failed."); return; } AccessTokenConfigValue value; @@ -1806,7 +1805,7 @@ void PermissionRecordManager::GetConfigValue() SetDefaultConfigValue(); } - ACCESSTOKEN_LOG_INFO(LABEL, "RecordSizeMaximum_ is %{public}d, recordAgingTime_ is %{public}d", + LOGI(PRI_DOMAIN, PRI_TAG, "RecordSizeMaximum_ is %{public}d, recordAgingTime_ is %{public}d", recordSizeMaximum_, recordAgingTime_); } @@ -1826,7 +1825,7 @@ void PermissionRecordManager::Init() if (hasInited_) { return; } - ACCESSTOKEN_LOG_INFO(LABEL, "Init"); + LOGI(PRI_DOMAIN, PRI_TAG, "Init"); hasInited_ = true; GetConfigValue(); diff --git a/services/privacymanager/src/seccomp/privacy_sec_comp_enhance_agent.cpp b/services/privacymanager/src/seccomp/privacy_sec_comp_enhance_agent.cpp index 9faaa1a8c860ecc370b67b1ddf2a7e819b447307..e7b7ffd83653f78616b043f5a1643f7f7d1ae92b 100644 --- a/services/privacymanager/src/seccomp/privacy_sec_comp_enhance_agent.cpp +++ b/services/privacymanager/src/seccomp/privacy_sec_comp_enhance_agent.cpp @@ -26,20 +26,17 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacySecCompEnhanceAgent" -}; std::recursive_mutex g_instanceMutex; } void PrivacyAppUsingSecCompStateObserver::OnProcessDied(const ProcessData &processData) { - ACCESSTOKEN_LOG_INFO(LABEL, "OnProcessDied pid %{public}d", processData.pid); + LOGI(PRI_DOMAIN, PRI_TAG, "OnProcessDied pid %{public}d", processData.pid); PrivacySecCompEnhanceAgent::GetInstance().RemoveSecCompEnhance(processData.pid); } void PrivacySecCompAppManagerDeathCallback::NotifyAppManagerDeath() { - ACCESSTOKEN_LOG_INFO(LABEL, "AppManagerDeath called"); + LOGI(PRI_DOMAIN, PRI_TAG, "AppManagerDeath called"); PrivacySecCompEnhanceAgent::GetInstance().OnAppMgrRemoteDiedHandle(); } @@ -64,11 +61,11 @@ void PrivacySecCompEnhanceAgent::InitAppObserver() } observer_ = new (std::nothrow) PrivacyAppUsingSecCompStateObserver(); if (observer_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "New observer failed."); + LOGE(PRI_DOMAIN, PRI_TAG, "New observer failed."); return; } if (AppManagerAccessClient::GetInstance().RegisterApplicationStateObserver(observer_) != 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register observer failed."); + LOGE(PRI_DOMAIN, PRI_TAG, "Register observer failed."); observer_ = nullptr; return; } @@ -93,7 +90,7 @@ PrivacySecCompEnhanceAgent::~PrivacySecCompEnhanceAgent() void PrivacySecCompEnhanceAgent::OnAppMgrRemoteDiedHandle() { - ACCESSTOKEN_LOG_INFO(LABEL, "OnAppMgrRemoteDiedHandle."); + LOGI(PRI_DOMAIN, PRI_TAG, "OnAppMgrRemoteDiedHandle."); std::lock_guard lock(secCompEnhanceMutex_); secCompEnhanceData_.clear(); observer_ = nullptr; @@ -105,11 +102,11 @@ void PrivacySecCompEnhanceAgent::RemoveSecCompEnhance(int pid) for (auto iter = secCompEnhanceData_.begin(); iter != secCompEnhanceData_.end(); ++iter) { if (iter->pid == pid) { secCompEnhanceData_.erase(iter); - ACCESSTOKEN_LOG_INFO(LABEL, "Remove pid %{public}d data.", pid); + LOGI(PRI_DOMAIN, PRI_TAG, "Remove pid %{public}d data.", pid); return; } } - ACCESSTOKEN_LOG_ERROR(LABEL, "Not found pid %{public}d data.", pid); + LOGE(PRI_DOMAIN, PRI_TAG, "Not found pid %{public}d data.", pid); return; } @@ -120,7 +117,7 @@ int32_t PrivacySecCompEnhanceAgent::RegisterSecCompEnhance(const SecCompEnhanceD int pid = IPCSkeleton::GetCallingPid(); if (std::any_of(secCompEnhanceData_.begin(), secCompEnhanceData_.end(), [pid](const auto& e) { return e.pid == pid; })) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register sec comp enhance exist, pid %{public}d.", pid); + LOGE(PRI_DOMAIN, PRI_TAG, "Register sec comp enhance exist, pid %{public}d.", pid); return PrivacyError::ERR_CALLBACK_ALREADY_EXIST; } SecCompEnhanceData enhance; @@ -134,7 +131,7 @@ int32_t PrivacySecCompEnhanceAgent::RegisterSecCompEnhance(const SecCompEnhanceD return PrivacyError::ERR_CALLBACK_ALREADY_EXIST; } secCompEnhanceData_.emplace_back(enhance); - ACCESSTOKEN_LOG_INFO(LABEL, "Register sec comp enhance success, pid %{public}d, total %{public}u.", + LOGI(PRI_DOMAIN, PRI_TAG, "Register sec comp enhance success, pid %{public}d, total %{public}u.", pid, static_cast(secCompEnhanceData_.size())); return RET_SUCCESS; } @@ -146,7 +143,7 @@ int32_t PrivacySecCompEnhanceAgent::UpdateSecCompEnhance(int32_t pid, uint32_t s for (auto iter = secCompEnhanceData_.begin(); iter != secCompEnhanceData_.end(); ++iter) { if (iter->pid == pid) { iter->seqNum = seqNum; - ACCESSTOKEN_LOG_INFO(LABEL, "Update pid=%{public}d data successful.", pid); + LOGI(PRI_DOMAIN, PRI_TAG, "Update pid=%{public}d data successful.", pid); return RET_SUCCESS; } } @@ -160,7 +157,7 @@ int32_t PrivacySecCompEnhanceAgent::GetSecCompEnhance(int32_t pid, SecCompEnhanc for (auto iter = secCompEnhanceData_.begin(); iter != secCompEnhanceData_.end(); ++iter) { if (iter->pid == pid) { enhanceData = *iter; - ACCESSTOKEN_LOG_INFO(LABEL, "Get pid %{public}d data.", pid); + LOGI(PRI_DOMAIN, PRI_TAG, "Get pid %{public}d data.", pid); return RET_SUCCESS; } } diff --git a/services/privacymanager/src/sensitive/audio_manager/audio_manager_adapter.cpp b/services/privacymanager/src/sensitive/audio_manager/audio_manager_adapter.cpp index 60f9e56a589a98a21d302c76f2bc937c5c395f3e..d9ffbb0fd8df87cddd76089b100ee6c88f6a178e 100644 --- a/services/privacymanager/src/sensitive/audio_manager/audio_manager_adapter.cpp +++ b/services/privacymanager/src/sensitive/audio_manager/audio_manager_adapter.cpp @@ -25,12 +25,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "AudioManagerAdapter" -}; -} - AudioManagerAdapter& AudioManagerAdapter::GetInstance() { static AudioManagerAdapter *instance = new (std::nothrow) AudioManagerAdapter(); @@ -46,12 +40,12 @@ AudioManagerAdapter::~AudioManagerAdapter() bool AudioManagerAdapter::GetPersistentMicMuteState() { #ifndef AUDIO_FRAMEWORK_ENABLE - ACCESSTOKEN_LOG_INFO(LABEL, "audio framework is not support."); + LOGI(PRI_DOMAIN, PRI_TAG, "audio framework is not support."); return false; #else auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to GetProxy."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to GetProxy."); return false; } @@ -61,14 +55,14 @@ bool AudioManagerAdapter::GetPersistentMicMuteState() std::u16string AUDIO_MGR_DESCRIPTOR = u"IAudioPolicy"; if (!data.WriteInterfaceToken(AUDIO_MGR_DESCRIPTOR)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to write WriteInterfaceToken."); return false; } int32_t error = proxy->SendRequest( static_cast(AudioStandard::AudioPolicyInterfaceCode::GET_MICROPHONE_MUTE_PERSISTENT), data, reply, option); if (error != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest error: %{public}d", error); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest error: %{public}d", error); return false; } return reply.ReadBool(); @@ -83,22 +77,22 @@ void AudioManagerAdapter::InitProxy() } sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemManager == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get system ability registry."); + LOGE(PRI_DOMAIN, PRI_TAG, "Fail to get system ability registry."); return; } sptr remoteObj = systemManager->CheckSystemAbility(AUDIO_POLICY_SERVICE_ID); if (remoteObj == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to connect ability manager service."); + LOGE(PRI_DOMAIN, PRI_TAG, "Fail to connect ability manager service."); return; } deathRecipient_ = sptr(new (std::nothrow) AudioManagerDeathRecipient()); if (deathRecipient_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create AudioManagerDeathRecipient!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to create AudioManagerDeathRecipient!"); return; } if ((remoteObj->IsProxyObject()) && (!remoteObj->AddDeathRecipient(deathRecipient_))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Add death recipient to AbilityManagerService failed."); + LOGE(PRI_DOMAIN, PRI_TAG, "Add death recipient to AbilityManagerService failed."); return; } proxy_ = remoteObj; @@ -125,7 +119,7 @@ void AudioManagerAdapter::ReleaseProxy(const wptr& remote) void AudioManagerAdapter::AudioManagerDeathRecipient::OnRemoteDied(const wptr& remote) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AudioManagerDeathRecipient handle remote died."); + LOGE(PRI_DOMAIN, PRI_TAG, "AudioManagerDeathRecipient handle remote died."); AudioManagerAdapter::GetInstance().ReleaseProxy(remote); } #endif diff --git a/services/privacymanager/src/sensitive/camera_manager/camera_manager_adapter.cpp b/services/privacymanager/src/sensitive/camera_manager/camera_manager_adapter.cpp index 683d33ea7f866b486a20c4c4edd6e7bd77e28bb9..89b6d95b366e2e7e7ee3b082a87ba78ec457ae39 100644 --- a/services/privacymanager/src/sensitive/camera_manager/camera_manager_adapter.cpp +++ b/services/privacymanager/src/sensitive/camera_manager/camera_manager_adapter.cpp @@ -25,12 +25,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "CameraManagerAdapter" -}; -} - CameraManagerAdapter& CameraManagerAdapter::GetInstance() { static CameraManagerAdapter *instance = new (std::nothrow) CameraManagerAdapter(); @@ -46,12 +40,12 @@ CameraManagerAdapter::~CameraManagerAdapter() bool CameraManagerAdapter::IsCameraMuted() { #ifndef CAMERA_FRAMEWORK_ENABLE - ACCESSTOKEN_LOG_INFO(LABEL, "camera framework is not support."); + LOGI(PRI_DOMAIN, PRI_TAG, "camera framework is not support."); return false; #else auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to GetProxy."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to GetProxy."); return false; } @@ -61,14 +55,14 @@ bool CameraManagerAdapter::IsCameraMuted() std::u16string CAMERA_MGR_DESCRIPTOR = u"ICameraService"; if (!data.WriteInterfaceToken(CAMERA_MGR_DESCRIPTOR)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to write WriteInterfaceToken."); return false; } int32_t error = proxy->SendRequest( static_cast(CameraStandard::CameraServiceInterfaceCode::CAMERA_SERVICE_IS_CAMERA_MUTED), data, reply, option); if (error != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest error: %{public}d", error); + LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest error: %{public}d", error); return false; } return reply.ReadBool(); @@ -83,22 +77,22 @@ void CameraManagerAdapter::InitProxy() } sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemManager == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get system ability registry."); + LOGE(PRI_DOMAIN, PRI_TAG, "Fail to get system ability registry."); return; } sptr remoteObj = systemManager->CheckSystemAbility(CAMERA_SERVICE_ID); if (remoteObj == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to connect ability manager service."); + LOGE(PRI_DOMAIN, PRI_TAG, "Fail to connect ability manager service."); return; } deathRecipient_ = sptr(new (std::nothrow) CameraManagerDeathRecipient()); if (deathRecipient_ == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create CameraManagerDeathRecipient!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to create CameraManagerDeathRecipient!"); return; } if ((remoteObj->IsProxyObject()) && (!remoteObj->AddDeathRecipient(deathRecipient_))) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Add death recipient to AbilityManagerService failed."); + LOGE(PRI_DOMAIN, PRI_TAG, "Add death recipient to AbilityManagerService failed."); return; } proxy_ = remoteObj; @@ -125,7 +119,7 @@ void CameraManagerAdapter::ReleaseProxy(const wptr& remote) void CameraManagerAdapter::CameraManagerDeathRecipient::OnRemoteDied(const wptr& remote) { - ACCESSTOKEN_LOG_ERROR(LABEL, "CameraManagerDeathRecipient handle remote died."); + LOGE(PRI_DOMAIN, PRI_TAG, "CameraManagerDeathRecipient handle remote died."); CameraManagerAdapter::GetInstance().ReleaseProxy(remote); } #endif diff --git a/services/privacymanager/src/service/privacy_manager_service.cpp b/services/privacymanager/src/service/privacy_manager_service.cpp index 7c4d240830bdee9e68ce87174430800f96123efe..4b8a095a0f7d0b102bbd61e484f1bf591bfade76 100644 --- a/services/privacymanager/src/service/privacy_manager_service.cpp +++ b/services/privacymanager/src/service/privacy_manager_service.cpp @@ -39,23 +39,19 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyManagerService" -}; -} - const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); +} PrivacyManagerService::PrivacyManagerService() : SystemAbility(SA_ID_PRIVACY_MANAGER_SERVICE, true), state_(ServiceRunningState::STATE_NOT_START) { - ACCESSTOKEN_LOG_INFO(LABEL, "PrivacyManagerService()"); + LOGI(PRI_DOMAIN, PRI_TAG, "PrivacyManagerService()"); } PrivacyManagerService::~PrivacyManagerService() { - ACCESSTOKEN_LOG_INFO(LABEL, "~PrivacyManagerService()"); + LOGI(PRI_DOMAIN, PRI_TAG, "~PrivacyManagerService()"); #ifdef COMMON_EVENT_SERVICE_ENABLE PrivacyCommonEventSubscriber::UnRegisterEvent(); #endif //COMMON_EVENT_SERVICE_ENABLE @@ -64,12 +60,12 @@ PrivacyManagerService::~PrivacyManagerService() void PrivacyManagerService::OnStart() { if (state_ == ServiceRunningState::STATE_RUNNING) { - ACCESSTOKEN_LOG_INFO(LABEL, "PrivacyManagerService has already started!"); + LOGI(PRI_DOMAIN, PRI_TAG, "PrivacyManagerService has already started!"); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "PrivacyManagerService is starting"); + LOGI(PRI_DOMAIN, PRI_TAG, "PrivacyManagerService is starting"); if (!Initialize()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to initialize"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to initialize"); return; } @@ -79,22 +75,22 @@ void PrivacyManagerService::OnStart() state_ = ServiceRunningState::STATE_RUNNING; bool ret = Publish(DelayedSingleton::GetInstance().get()); if (!ret) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to publish service!"); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to publish service!"); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "Congratulations, PrivacyManagerService start successfully!"); + LOGI(PRI_DOMAIN, PRI_TAG, "Congratulations, PrivacyManagerService start successfully!"); } void PrivacyManagerService::OnStop() { - ACCESSTOKEN_LOG_INFO(LABEL, "Stop service"); + LOGI(PRI_DOMAIN, PRI_TAG, "Stop service"); state_ = ServiceRunningState::STATE_NOT_START; } int32_t PrivacyManagerService::AddPermissionUsedRecord(const AddPermParamInfoParcel& infoParcel, bool asyncMode) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "id: %{public}d, perm: %{public}s, succCnt: %{public}d," + LOGD(PRI_DOMAIN, PRI_TAG, "id: %{public}d, perm: %{public}s, succCnt: %{public}d," " failCnt: %{public}d, type: %{public}d", infoParcel.info.tokenId, infoParcel.info.permissionName.c_str(), infoParcel.info.successCount, infoParcel.info.failCount, infoParcel.info.type); AddPermParamInfo info = infoParcel.info; @@ -104,7 +100,7 @@ int32_t PrivacyManagerService::AddPermissionUsedRecord(const AddPermParamInfoPar int32_t PrivacyManagerService::StartUsingPermission( AccessTokenID tokenId, int32_t pid, const std::string& permissionName, PermissionUsedType type) { - ACCESSTOKEN_LOG_INFO(LABEL, "Id: %{public}u, pid: %{public}d, perm: %{public}s, type: %{public}d.", + LOGI(PRI_DOMAIN, PRI_TAG, "Id: %{public}u, pid: %{public}d, perm: %{public}s, type: %{public}d.", tokenId, pid, permissionName.c_str(), type); return PermissionRecordManager::GetInstance().StartUsingPermission(tokenId, pid, permissionName, type); } @@ -112,7 +108,7 @@ int32_t PrivacyManagerService::StartUsingPermission( int32_t PrivacyManagerService::StartUsingPermission(AccessTokenID tokenId, int32_t pid, const std::string& permissionName, const sptr& callback, PermissionUsedType type) { - ACCESSTOKEN_LOG_INFO(LABEL, "Id: %{public}u, pid: %{public}d, perm: %{public}s, type: %{public}d.", + LOGI(PRI_DOMAIN, PRI_TAG, "Id: %{public}u, pid: %{public}d, perm: %{public}s, type: %{public}d.", tokenId, pid, permissionName.c_str(), type); return PermissionRecordManager::GetInstance().StartUsingPermission(tokenId, pid, permissionName, callback, type); } @@ -120,14 +116,14 @@ int32_t PrivacyManagerService::StartUsingPermission(AccessTokenID tokenId, int32 int32_t PrivacyManagerService::StopUsingPermission( AccessTokenID tokenId, int32_t pid, const std::string& permissionName) { - ACCESSTOKEN_LOG_INFO(LABEL, "id: %{public}u, pid: %{public}d, perm: %{public}s", + LOGI(PRI_DOMAIN, PRI_TAG, "id: %{public}u, pid: %{public}d, perm: %{public}s", tokenId, pid, permissionName.c_str()); return PermissionRecordManager::GetInstance().StopUsingPermission(tokenId, pid, permissionName); } int32_t PrivacyManagerService::RemovePermissionUsedRecords(AccessTokenID tokenId) { - ACCESSTOKEN_LOG_INFO(LABEL, "id: %{public}u", tokenId); + LOGI(PRI_DOMAIN, PRI_TAG, "id: %{public}u", tokenId); PermissionRecordManager::GetInstance().RemovePermissionUsedRecords(tokenId); return Constant::SUCCESS; } @@ -140,7 +136,7 @@ int32_t PrivacyManagerService::GetPermissionUsedRecords( permissionList.append(perm); permissionList.append(" "); } - ACCESSTOKEN_LOG_INFO(LABEL, "id: %{public}d, timestamp: [%{public}" PRId64 "-%{public}" PRId64 + LOGI(PRI_DOMAIN, PRI_TAG, "id: %{public}d, timestamp: [%{public}" PRId64 "-%{public}" PRId64 "], flag: %{public}d, perm: %{public}s", request.request.tokenId, request.request.beginTimeMillis, request.request.endTimeMillis, request.request.flag, permissionList.c_str()); @@ -153,7 +149,7 @@ int32_t PrivacyManagerService::GetPermissionUsedRecords( int32_t PrivacyManagerService::GetPermissionUsedRecords( const PermissionUsedRequestParcel& request, const sptr& callback) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "id: %{public}d", request.request.tokenId); + LOGD(PRI_DOMAIN, PRI_TAG, "id: %{public}d", request.request.tokenId); return PermissionRecordManager::GetInstance().GetPermissionUsedRecordsAsync(request.request, callback); } @@ -167,7 +163,7 @@ int32_t PrivacyManagerService::RegisterPermActiveStatusCallback( #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE int32_t PrivacyManagerService::RegisterSecCompEnhance(const SecCompEnhanceDataParcel& enhanceParcel) { - ACCESSTOKEN_LOG_INFO(LABEL, "Pid: %{public}d", enhanceParcel.enhanceData.pid); + LOGI(PRI_DOMAIN, PRI_TAG, "Pid: %{public}d", enhanceParcel.enhanceData.pid); return PrivacySecCompEnhanceAgent::GetInstance().RegisterSecCompEnhance(enhanceParcel.enhanceData); } @@ -181,7 +177,7 @@ int32_t PrivacyManagerService::GetSecCompEnhance(int32_t pid, SecCompEnhanceData SecCompEnhanceData enhanceData; int32_t res = PrivacySecCompEnhanceAgent::GetInstance().GetSecCompEnhance(pid, enhanceData); if (res != RET_SUCCESS) { - ACCESSTOKEN_LOG_WARN(LABEL, "Pid: %{public}d get enhance failed ", pid); + LOGW(PRI_DOMAIN, PRI_TAG, "Pid: %{public}d get enhance failed ", pid); return res; } @@ -247,7 +243,7 @@ int32_t PrivacyManagerService::ResponseDumpCommand(int32_t fd, const std::vector int32_t PrivacyManagerService::Dump(int32_t fd, const std::vector& args) { if (fd < 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Dump fd invalid value"); + LOGE(PRI_DOMAIN, PRI_TAG, "Dump fd invalid value"); return ERR_INVALID_VALUE; } int32_t ret = ERR_OK; @@ -278,14 +274,14 @@ int32_t PrivacyManagerService::UnRegisterPermActiveStatusCallback(const sptr(policyType), static_cast(callerType), isMute); @@ -293,14 +289,14 @@ int32_t PrivacyManagerService::SetMutePolicy(uint32_t policyType, uint32_t calle int32_t PrivacyManagerService::SetHapWithFGReminder(uint32_t tokenId, bool isAllowed) { - ACCESSTOKEN_LOG_INFO(LABEL, "id: %{public}d, isAllowed: %{public}d", tokenId, isAllowed); + LOGI(PRI_DOMAIN, PRI_TAG, "id: %{public}d, isAllowed: %{public}d", tokenId, isAllowed); return PermissionRecordManager::GetInstance().SetHapWithFGReminder(tokenId, isAllowed); } int32_t PrivacyManagerService::GetPermissionUsedTypeInfos(const AccessTokenID tokenId, const std::string& permissionName, std::vector& resultsParcel) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "id: %{public}d, perm: %{public}s", tokenId, permissionName.c_str()); + LOGD(PRI_DOMAIN, PRI_TAG, "id: %{public}d, perm: %{public}s", tokenId, permissionName.c_str()); std::vector results; int32_t res = PermissionRecordManager::GetInstance().GetPermissionUsedTypeInfos(tokenId, permissionName, results); @@ -319,7 +315,7 @@ int32_t PrivacyManagerService::GetPermissionUsedTypeInfos(const AccessTokenID to void PrivacyManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { - ACCESSTOKEN_LOG_INFO(LABEL, "saId is %{public}d", systemAbilityId); + LOGI(PRI_DOMAIN, PRI_TAG, "saId is %{public}d", systemAbilityId); #ifdef COMMON_EVENT_SERVICE_ENABLE if (systemAbilityId == COMMON_EVENT_SERVICE_ID) { PrivacyCommonEventSubscriber::RegisterEvent(); @@ -340,7 +336,7 @@ bool PrivacyManagerService::Initialize() #ifdef EVENTHANDLER_ENABLE eventRunner_ = AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT); if (!eventRunner_) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create eventRunner."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to create eventRunner."); return false; } eventHandler_ = std::make_shared(eventRunner_); diff --git a/services/privacymanager/src/service/privacy_manager_stub.cpp b/services/privacymanager/src/service/privacy_manager_stub.cpp index b0907e61fba8c1391cff00a5a2c5d39260f6b815..88de6b36868b6feb181d2825afd1b7c39460d3a3 100644 --- a/services/privacymanager/src/service/privacy_manager_stub.cpp +++ b/services/privacymanager/src/service/privacy_manager_stub.cpp @@ -31,9 +31,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyManagerStub" -}; static const uint32_t PERM_LIST_SIZE_MAX = 1024; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE #ifdef HICOLLIE_ENABLE @@ -94,7 +91,7 @@ int32_t PrivacyManagerStub::OnRemoteRequest( MemoryGuard cacheGuard; std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != IPrivacyManager::GetDescriptor()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); return ERROR_IPC_REQUEST_FAIL; } @@ -123,7 +120,7 @@ void PrivacyManagerStub::AddPermissionUsedRecordInner(MessageParcel& data, Messa } sptr infoParcel = data.ReadParcelable(); if (infoParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable faild"); + LOGE(PRI_DOMAIN, PRI_TAG, "ReadParcelable faild"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } @@ -160,7 +157,7 @@ void PrivacyManagerStub::StartUsingPermissionCallbackInner(MessageParcel& data, std::string permissionName = data.ReadString(); sptr callback = data.ReadRemoteObject(); if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read ReadRemoteObject fail"); + LOGE(PRI_DOMAIN, PRI_TAG, "Read ReadRemoteObject fail"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } @@ -211,14 +208,14 @@ void PrivacyManagerStub::GetPermissionUsedRecordsInner(MessageParcel& data, Mess } sptr requestParcel = data.ReadParcelable(); if (requestParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable faild"); + LOGE(PRI_DOMAIN, PRI_TAG, "ReadParcelable faild"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } int32_t result = this->GetPermissionUsedRecords(*requestParcel, responseParcel); reply.WriteInt32(result); if (result != RET_SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 faild"); + LOGE(PRI_DOMAIN, PRI_TAG, "WriteInt32 faild"); return; } reply.WriteParcelable(&responseParcel); @@ -232,13 +229,13 @@ void PrivacyManagerStub::GetPermissionUsedRecordsAsyncInner(MessageParcel& data, } sptr requestParcel = data.ReadParcelable(); if (requestParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed"); + LOGE(PRI_DOMAIN, PRI_TAG, "ReadParcelable failed"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } sptr callback = new OnPermissionUsedRecordCallbackProxy(data.ReadRemoteObject()); if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is null"); + LOGE(PRI_DOMAIN, PRI_TAG, "Callback is null"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } @@ -258,7 +255,7 @@ void PrivacyManagerStub::RegisterPermActiveStatusCallbackInner(MessageParcel& da } uint32_t permListSize = data.ReadUint32(); if (permListSize > PERM_LIST_SIZE_MAX) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read permListSize fail"); + LOGE(PRI_DOMAIN, PRI_TAG, "Read permListSize fail"); reply.WriteInt32(PrivacyError::ERR_OVERSIZE); return; } @@ -269,7 +266,7 @@ void PrivacyManagerStub::RegisterPermActiveStatusCallbackInner(MessageParcel& da } sptr callback = data.ReadRemoteObject(); if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read ReadRemoteObject fail"); + LOGE(PRI_DOMAIN, PRI_TAG, "Read ReadRemoteObject fail"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } @@ -289,7 +286,7 @@ void PrivacyManagerStub::UnRegisterPermActiveStatusCallbackInner(MessageParcel& } sptr callback = data.ReadRemoteObject(); if (callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Read scopeParcel fail"); + LOGE(PRI_DOMAIN, PRI_TAG, "Read scopeParcel fail"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } @@ -309,7 +306,7 @@ void PrivacyManagerStub::IsAllowedUsingPermissionInner(MessageParcel& data, Mess bool result = this->IsAllowedUsingPermission(tokenId, permissionName, pid); if (!reply.WriteBool(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteBool(%{public}s)", permissionName.c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to WriteBool(%{public}s)", permissionName.c_str()); reply.WriteBool(false); return; } @@ -326,7 +323,7 @@ void PrivacyManagerStub::RegisterSecCompEnhanceInner(MessageParcel& data, Messag sptr requestParcel = data.ReadParcelable(); if (requestParcel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable faild"); + LOGE(PRI_DOMAIN, PRI_TAG, "ReadParcelable faild"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); #ifdef HICOLLIE_ENABLE @@ -418,7 +415,7 @@ void PrivacyManagerStub::GetPermissionUsedTypeInfosInner(MessageParcel& data, Me std::vector resultsParcel; int32_t result = this->GetPermissionUsedTypeInfos(tokenId, permissionName, resultsParcel); if (!reply.WriteInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteInt32(%{public}d-%{public}s)", tokenId, permissionName.c_str()); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to Write(%{public}d-%{public}s)", tokenId, permissionName.c_str()); return; } reply.WriteUint32(resultsParcel.size()); @@ -435,26 +432,26 @@ void PrivacyManagerStub::SetMutePolicyInner(MessageParcel& data, MessageParcel& } uint32_t policyType; if (!data.ReadUint32(policyType)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read policyType."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to read policyType."); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } uint32_t callerType; if (!data.ReadUint32(callerType)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read callerType."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to read callerType."); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } bool isMute; if (!data.ReadBool(isMute)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read isMute."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to read isMute."); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } int32_t result = this->SetMutePolicy(policyType, callerType, isMute); if (!reply.WriteInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteInt32."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to WriteInt32."); return; } } @@ -467,20 +464,20 @@ void PrivacyManagerStub::SetHapWithFGReminderInner(MessageParcel& data, MessageP } uint32_t tokenId; if (!data.ReadUint32(tokenId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read tokenId."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to read tokenId."); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } bool isAllowed; if (!data.ReadBool(isAllowed)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to read isAllowed."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to read isAllowed."); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } int32_t result = this->SetHapWithFGReminder(tokenId, isAllowed); if (!reply.WriteInt32(result)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteInt32."); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to WriteInt32."); return; } } @@ -501,7 +498,7 @@ bool PrivacyManagerStub::VerifyPermission(const std::string& permission) const { uint32_t callingTokenID = IPCSkeleton::GetCallingTokenID(); if (AccessTokenKit::VerifyAccessToken(callingTokenID, permission) == PERMISSION_DENIED) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Permission denied(callingTokenID=%{public}d)", callingTokenID); + LOGE(PRI_DOMAIN, PRI_TAG, "Permission denied(callingTokenID=%{public}d)", callingTokenID); return false; } return true; diff --git a/services/privacymanager/test/coverage/BUILD.gn b/services/privacymanager/test/coverage/BUILD.gn index 5d232251c35b2a8a1bec4e16d1bed9426d78cbac..320b318f4176563097daa9af8a2db96804e7cb68 100644 --- a/services/privacymanager/test/coverage/BUILD.gn +++ b/services/privacymanager/test/coverage/BUILD.gn @@ -56,7 +56,6 @@ if (is_standard_system && ability_base_enable == true) { "../../src/common/constant.cpp", "../../src/database/data_translator.cpp", "../../src/database/permission_used_record_db.cpp", - "../../src/database/privacy_field_const.cpp", "../../src/record/on_permission_used_record_callback_proxy.cpp", "../../src/record/permission_record.cpp", "../../src/record/permission_record_manager.cpp", diff --git a/services/privacymanager/test/unittest/BUILD.gn b/services/privacymanager/test/unittest/BUILD.gn index fdd402a287afce82fc3d3a38aa74871813900ea7..6b1d34e291f6e4dee94cfffc1f674475724d1d31 100644 --- a/services/privacymanager/test/unittest/BUILD.gn +++ b/services/privacymanager/test/unittest/BUILD.gn @@ -57,7 +57,6 @@ if (is_standard_system && ability_base_enable == true) { "../../src/common/constant.cpp", "../../src/database/data_translator.cpp", "../../src/database/permission_used_record_db.cpp", - "../../src/database/privacy_field_const.cpp", "../../src/record/on_permission_used_record_callback_proxy.cpp", "../../src/record/permission_record.cpp", "../../src/record/permission_record_manager.cpp", diff --git a/services/tokensyncmanager/BUILD.gn b/services/tokensyncmanager/BUILD.gn index 1630d590b0af2f12bad48a1512d8e2cc1d159c7d..60d0bca946e5e14dba75c2fd9040123df2d6f88b 100644 --- a/services/tokensyncmanager/BUILD.gn +++ b/services/tokensyncmanager/BUILD.gn @@ -68,7 +68,6 @@ if (token_sync_enable == true) { "src/command/delete_remote_token_command.cpp", "src/command/sync_remote_hap_token_command.cpp", "src/command/update_remote_hap_token_command.cpp", - "src/common/constant.cpp", "src/device/device_info_manager.cpp", "src/device/device_info_repository.cpp", "src/remote/remote_command_executor.cpp", diff --git a/services/tokensyncmanager/include/command/delete_remote_token_command.h b/services/tokensyncmanager/include/command/delete_remote_token_command.h index 36b93b342c0b96478e92437572d784f70da6da53..4edf182f1fa186153f91c29f2e9ccc5b5fb983bb 100644 --- a/services/tokensyncmanager/include/command/delete_remote_token_command.h +++ b/services/tokensyncmanager/include/command/delete_remote_token_command.h @@ -43,7 +43,7 @@ private: /** * The command name. Should be equal to class name. */ - const std::string COMMAND_NAME = "DeleteRemoteTokenCommand"; + const char* COMMAND_NAME = "DeleteRemoteTokenCommand"; AccessTokenID deleteTokenId_; }; } // namespace AccessToken diff --git a/services/tokensyncmanager/include/command/sync_remote_hap_token_command.h b/services/tokensyncmanager/include/command/sync_remote_hap_token_command.h index 7fbb9b7adb121d984c9f99e77c2e790ac1fd176c..33a2d111e6fcc996e82291ed806d19a353271e9e 100644 --- a/services/tokensyncmanager/include/command/sync_remote_hap_token_command.h +++ b/services/tokensyncmanager/include/command/sync_remote_hap_token_command.h @@ -48,7 +48,7 @@ private: /** * The command name. Should be equal to class name. */ - const std::string COMMAND_NAME = "SyncRemoteHapTokenCommand"; + const char* COMMAND_NAME = "SyncRemoteHapTokenCommand"; HapTokenInfoForSync hapTokenInfo_; AccessTokenID requestTokenId_; }; diff --git a/services/tokensyncmanager/include/command/update_remote_hap_token_command.h b/services/tokensyncmanager/include/command/update_remote_hap_token_command.h index f31280c210c2fcbfb72e43dc6b975814227bb435..8a3428b8512c1e2a34a533848ddb5978c1098c8c 100644 --- a/services/tokensyncmanager/include/command/update_remote_hap_token_command.h +++ b/services/tokensyncmanager/include/command/update_remote_hap_token_command.h @@ -47,7 +47,7 @@ private: /** * The command name. Should be equal to class name. */ - const std::string COMMAND_NAME = "UpdateRemoteHapTokenCommand"; + const char* COMMAND_NAME = "UpdateRemoteHapTokenCommand"; HapTokenInfoForSync updateTokenInfo_; }; } // namespace AccessToken diff --git a/services/tokensyncmanager/include/common/constant.h b/services/tokensyncmanager/include/common/constant.h index 9b6e875aff6bed3dd0336341009d85039c61ed4c..7e9938ea44b2e1acb596faa79bf944e1918b6ad0 100644 --- a/services/tokensyncmanager/include/common/constant.h +++ b/services/tokensyncmanager/include/common/constant.h @@ -67,12 +67,12 @@ public: /** * Command result string, indicates success. */ - static const std::string COMMAND_RESULT_SUCCESS; + inline static constexpr const char* COMMAND_RESULT_SUCCESS = "success"; /** * Command result string, indicates failed. */ - static const std::string COMMAND_RESULT_FAILED; + inline static constexpr const char* COMMAND_RESULT_FAILED = "execute command failed"; const static int32_t DELAY_SYNC_TOKEN_MS = 3000; }; } // namespace AccessToken diff --git a/services/tokensyncmanager/src/command/base_remote_command.cpp b/services/tokensyncmanager/src/command/base_remote_command.cpp index 8448d13886228fae654d3bf897d470140bff239b..5c1659b74b5e5646a67440fb4dc0e15cb437bc6f 100644 --- a/services/tokensyncmanager/src/command/base_remote_command.cpp +++ b/services/tokensyncmanager/src/command/base_remote_command.cpp @@ -21,25 +21,24 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "BaseRemoteCommand"}; -static const std::string JSON_COMMAND_NAME = "commandName"; -static const std::string JSON_UNIQUEID = "uniqueId"; -static const std::string JSON_REQUEST_VERSION = "requestVersion"; -static const std::string JSON_SRC_DEVICEID = "srcDeviceId"; -static const std::string JSON_SRC_DEVICE_LEVEL = "srcDeviceLevel"; -static const std::string JSON_DST_DEVICEID = "dstDeviceId"; -static const std::string JSON_DST_DEVICE_LEVEL = "dstDeviceLevel"; -static const std::string JSON_STATUS_CODE = "statusCode"; -static const std::string JSON_MESSAGE = "message"; -static const std::string JSON_RESPONSE_VERSION = "responseVersion"; -static const std::string JSON_RESPONSE_DEVICEID = "responseDeviceId"; -static const std::string JSON_VERSION = "version"; -static const std::string JSON_TOKENID = "tokenID"; -static const std::string JSON_TOKEN_ATTR = "tokenAttr"; -static const std::string JSON_USERID = "userID"; -static const std::string JSON_BUNDLE_NAME = "bundleName"; -static const std::string JSON_INST_INDEX = "instIndex"; -static const std::string JSON_DLP_TYPE = "dlpType"; +constexpr const char* JSON_COMMAND_NAME = "commandName"; +constexpr const char* JSON_UNIQUEID = "uniqueId"; +constexpr const char* JSON_REQUEST_VERSION = "requestVersion"; +constexpr const char* JSON_SRC_DEVICEID = "srcDeviceId"; +constexpr const char* JSON_SRC_DEVICE_LEVEL = "srcDeviceLevel"; +constexpr const char* JSON_DST_DEVICEID = "dstDeviceId"; +constexpr const char* JSON_DST_DEVICE_LEVEL = "dstDeviceLevel"; +constexpr const char* JSON_STATUS_CODE = "statusCode"; +constexpr const char* JSON_MESSAGE = "message"; +constexpr const char* JSON_RESPONSE_VERSION = "responseVersion"; +constexpr const char* JSON_RESPONSE_DEVICEID = "responseDeviceId"; +constexpr const char* JSON_VERSION = "version"; +constexpr const char* JSON_TOKENID = "tokenID"; +constexpr const char* JSON_TOKEN_ATTR = "tokenAttr"; +constexpr const char* JSON_USERID = "userID"; +constexpr const char* JSON_BUNDLE_NAME = "bundleName"; +constexpr const char* JSON_INST_INDEX = "instIndex"; +constexpr const char* JSON_DLP_TYPE = "dlpType"; } static void GetStringFromJson(const nlohmann::json& jsonObject, const std::string& tag, std::string& out) @@ -123,7 +122,7 @@ nlohmann::json BaseRemoteCommand::ToNativeTokenInfoJson(const NativeTokenInfoFor void BaseRemoteCommand::ToPermStateJson(nlohmann::json& permStateJson, const PermissionStateFull& state) { if (state.resDeviceID.size() != state.grantStatus.size() || state.resDeviceID.size() != state.grantFlags.size()) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "State grant config size is invalid"); + LOGD(ATM_DOMAIN, ATM_TAG, "State grant config size is invalid"); return; } nlohmann::json permConfigsJson; @@ -229,7 +228,7 @@ void BaseRemoteCommand::FromHapTokenInfoJson(const nlohmann::json& hapTokenJson, { FromHapTokenBasicInfoJson(hapTokenJson, hapTokenInfo.baseInfo); if (hapTokenInfo.baseInfo.tokenID == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Hap token basic info is error."); + LOGE(ATM_DOMAIN, ATM_TAG, "Hap token basic info is error."); return; } FromPermStateListJson(hapTokenJson, hapTokenInfo.permStateList); diff --git a/services/tokensyncmanager/src/command/delete_remote_token_command.cpp b/services/tokensyncmanager/src/command/delete_remote_token_command.cpp index 887de19902710712b20105708c27e5a1336c8a7d..c4eb7b8a2ac9e17fb604bac878643ca05428be00 100644 --- a/services/tokensyncmanager/src/command/delete_remote_token_command.cpp +++ b/services/tokensyncmanager/src/command/delete_remote_token_command.cpp @@ -26,11 +26,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "DeleteRemoteTokenCommand"}; -} - DeleteRemoteTokenCommand::DeleteRemoteTokenCommand( const std::string &srcDeviceId, const std::string &dstDeviceId, AccessTokenID deleteID) : deleteTokenId_(deleteID) @@ -48,7 +43,7 @@ DeleteRemoteTokenCommand::DeleteRemoteTokenCommand(const std::string& json) deleteTokenId_ = 0; nlohmann::json jsonObject = nlohmann::json::parse(json, nullptr, false); if (jsonObject.is_discarded()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "JsonObject is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "JsonObject is invalid."); return; } BaseRemoteCommand::FromRemoteProtocolJson(jsonObject); @@ -62,7 +57,7 @@ std::string DeleteRemoteTokenCommand::ToJsonPayload() { nlohmann::json j = BaseRemoteCommand::ToRemoteProtocolJson(); if (j.is_discarded()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "J is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "J is invalid."); return ""; } j["tokenId"] = deleteTokenId_; @@ -73,12 +68,12 @@ void DeleteRemoteTokenCommand::Prepare() { remoteProtocol_.statusCode = Constant::SUCCESS; remoteProtocol_.message = Constant::COMMAND_RESULT_SUCCESS; - ACCESSTOKEN_LOG_INFO(LABEL, "End as: DeleteRemoteTokenCommand"); + LOGI(ATM_DOMAIN, ATM_TAG, "End as: DeleteRemoteTokenCommand"); } void DeleteRemoteTokenCommand::Execute() { - ACCESSTOKEN_LOG_INFO(LABEL, "Execute: start as: DeleteRemoteTokenCommand"); + LOGI(ATM_DOMAIN, ATM_TAG, "Execute: start as: DeleteRemoteTokenCommand"); remoteProtocol_.responseDeviceId = ConstantCommon::GetLocalDeviceId(); remoteProtocol_.responseVersion = Constant::DISTRIBUTED_ACCESS_TOKEN_SERVICE_VERSION; @@ -86,7 +81,7 @@ void DeleteRemoteTokenCommand::Execute() bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(remoteProtocol_.srcDeviceId, DeviceIdType::UNKNOWN, devInfo); if (!result) { - ACCESSTOKEN_LOG_INFO(LABEL, "Error: get remote uniqueDeviceId failed"); + LOGI(ATM_DOMAIN, ATM_TAG, "Error: get remote uniqueDeviceId failed"); remoteProtocol_.statusCode = Constant::FAILURE_BUT_CAN_RETRY; return; } @@ -101,13 +96,13 @@ void DeleteRemoteTokenCommand::Execute() remoteProtocol_.message = Constant::COMMAND_RESULT_SUCCESS; } - ACCESSTOKEN_LOG_INFO(LABEL, "Execute: end as: DeleteRemoteTokenCommand"); + LOGI(ATM_DOMAIN, ATM_TAG, "Execute: end as: DeleteRemoteTokenCommand"); } void DeleteRemoteTokenCommand::Finish() { remoteProtocol_.statusCode = Constant::SUCCESS; - ACCESSTOKEN_LOG_INFO(LABEL, "Finish: end as: DeleteUidPermissionCommand"); + LOGI(ATM_DOMAIN, ATM_TAG, "Finish: end as: DeleteUidPermissionCommand"); } } // namespace AccessToken } // namespace Security diff --git a/services/tokensyncmanager/src/command/sync_remote_hap_token_command.cpp b/services/tokensyncmanager/src/command/sync_remote_hap_token_command.cpp index c86dea43c4bae6044914492359c2cbee33b982ef..e7b2b0527f7456022776aa273ee6f31a8ab2edcd 100644 --- a/services/tokensyncmanager/src/command/sync_remote_hap_token_command.cpp +++ b/services/tokensyncmanager/src/command/sync_remote_hap_token_command.cpp @@ -24,11 +24,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "SyncRemoteHapTokenCommand"}; -} - SyncRemoteHapTokenCommand::SyncRemoteHapTokenCommand( const std::string &srcDeviceId, const std::string &dstDeviceId, AccessTokenID id) : requestTokenId_(id) { @@ -60,7 +55,7 @@ SyncRemoteHapTokenCommand::SyncRemoteHapTokenCommand(const std::string &json) nlohmann::json jsonObject = nlohmann::json::parse(json, nullptr, false); if (jsonObject.is_discarded()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "JsonObject is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "JsonObject is invalid."); return; } BaseRemoteCommand::FromRemoteProtocolJson(jsonObject); @@ -86,12 +81,12 @@ void SyncRemoteHapTokenCommand::Prepare() { remoteProtocol_.statusCode = Constant::SUCCESS; remoteProtocol_.message = Constant::COMMAND_RESULT_SUCCESS; - ACCESSTOKEN_LOG_DEBUG(LABEL, " end as: SyncRemoteHapTokenCommand"); + LOGD(ATM_DOMAIN, ATM_TAG, " end as: SyncRemoteHapTokenCommand"); } void SyncRemoteHapTokenCommand::Execute() { - ACCESSTOKEN_LOG_INFO(LABEL, "Execute: start as: SyncRemoteHapTokenCommand"); + LOGI(ATM_DOMAIN, ATM_TAG, "Execute: start as: SyncRemoteHapTokenCommand"); remoteProtocol_.responseDeviceId = ConstantCommon::GetLocalDeviceId(); remoteProtocol_.responseVersion = Constant::DISTRIBUTED_ACCESS_TOKEN_SERVICE_VERSION; @@ -104,18 +99,18 @@ void SyncRemoteHapTokenCommand::Execute() remoteProtocol_.message = Constant::COMMAND_RESULT_SUCCESS; } - ACCESSTOKEN_LOG_INFO(LABEL, "Execute: end as: SyncRemoteHapTokenCommand"); + LOGI(ATM_DOMAIN, ATM_TAG, "Execute: end as: SyncRemoteHapTokenCommand"); } void SyncRemoteHapTokenCommand::Finish() { if (remoteProtocol_.statusCode != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Finish: end as: SyncRemoteHapTokenCommand get remote result error."); + LOGE(ATM_DOMAIN, ATM_TAG, "Finish: end as: SyncRemoteHapTokenCommand get remote result error."); return; } AccessTokenKit::SetRemoteHapTokenInfo(remoteProtocol_.dstDeviceId, hapTokenInfo_); remoteProtocol_.statusCode = Constant::SUCCESS; - ACCESSTOKEN_LOG_INFO(LABEL, "Finish: end as: SyncRemoteHapTokenCommand"); + LOGI(ATM_DOMAIN, ATM_TAG, "Finish: end as: SyncRemoteHapTokenCommand"); } } // namespace AccessToken } // namespace Security diff --git a/services/tokensyncmanager/src/command/update_remote_hap_token_command.cpp b/services/tokensyncmanager/src/command/update_remote_hap_token_command.cpp index 7fec309d6b1a8a3452eb978c0bb86a621c2104c0..2d511b5a0d9f32e6ade3d5a75ded56cf31fb4495 100644 --- a/services/tokensyncmanager/src/command/update_remote_hap_token_command.cpp +++ b/services/tokensyncmanager/src/command/update_remote_hap_token_command.cpp @@ -25,11 +25,6 @@ namespace OHOS { namespace Security { namespace AccessToken { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "UpdateRemoteHapTokenCommand"}; -} - UpdateRemoteHapTokenCommand::UpdateRemoteHapTokenCommand( const std::string &srcDeviceId, const std::string &dstDeviceId, const HapTokenInfoForSync& tokenInfo) : updateTokenInfo_(tokenInfo) @@ -46,7 +41,7 @@ UpdateRemoteHapTokenCommand::UpdateRemoteHapTokenCommand(const std::string &json { nlohmann::json jsonObject = nlohmann::json::parse(json, nullptr, false); if (jsonObject.is_discarded()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "JsonObject is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "JsonObject is invalid."); return; } BaseRemoteCommand::FromRemoteProtocolJson(jsonObject); @@ -68,12 +63,12 @@ void UpdateRemoteHapTokenCommand::Prepare() { remoteProtocol_.statusCode = Constant::SUCCESS; remoteProtocol_.message = Constant::COMMAND_RESULT_SUCCESS; - ACCESSTOKEN_LOG_DEBUG(LABEL, "End as: UpdateRemoteHapTokenCommand"); + LOGD(ATM_DOMAIN, ATM_TAG, "End as: UpdateRemoteHapTokenCommand"); } void UpdateRemoteHapTokenCommand::Execute() { - ACCESSTOKEN_LOG_INFO(LABEL, "Execute: start as: UpdateRemoteHapTokenCommand"); + LOGI(ATM_DOMAIN, ATM_TAG, "Execute: start as: UpdateRemoteHapTokenCommand"); remoteProtocol_.responseDeviceId = ConstantCommon::GetLocalDeviceId(); remoteProtocol_.responseVersion = Constant::DISTRIBUTED_ACCESS_TOKEN_SERVICE_VERSION; @@ -82,7 +77,7 @@ void UpdateRemoteHapTokenCommand::Execute() bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(remoteProtocol_.srcDeviceId, DeviceIdType::UNKNOWN, devInfo); if (!result) { - ACCESSTOKEN_LOG_INFO(LABEL, "UpdateRemoteHapTokenCommand: get remote uniqueDeviceId failed"); + LOGI(ATM_DOMAIN, ATM_TAG, "UpdateRemoteHapTokenCommand: get remote uniqueDeviceId failed"); remoteProtocol_.statusCode = Constant::FAILURE_BUT_CAN_RETRY; return; } @@ -96,14 +91,13 @@ void UpdateRemoteHapTokenCommand::Execute() remoteProtocol_.statusCode = Constant::SUCCESS; remoteProtocol_.message = Constant::COMMAND_RESULT_SUCCESS; } - - ACCESSTOKEN_LOG_INFO(LABEL, "Execute: end as: UpdateRemoteHapTokenCommand"); +LOGI(ATM_DOMAIN, ATM_TAG, "Execute: end as: UpdateRemoteHapTokenCommand"); } void UpdateRemoteHapTokenCommand::Finish() { remoteProtocol_.statusCode = Constant::SUCCESS; - ACCESSTOKEN_LOG_INFO(LABEL, "Finish: end as: DeleteUidPermissionCommand"); + LOGI(ATM_DOMAIN, ATM_TAG, "Finish: end as: DeleteUidPermissionCommand"); } } // namespace AccessToken } // namespace Security diff --git a/services/tokensyncmanager/src/common/constant.cpp b/services/tokensyncmanager/src/common/constant.cpp deleted file mode 100644 index b5866e34c0efd2cc170a8ee5cdc032fcbe20fcb8..0000000000000000000000000000000000000000 --- a/services/tokensyncmanager/src/common/constant.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2021-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 "constant.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -namespace { -static const std::string REPLACE_TARGET = "****"; -} // namespace -const std::string Constant::COMMAND_RESULT_SUCCESS = "success"; -const std::string Constant::COMMAND_RESULT_FAILED = "execute command failed"; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS diff --git a/services/tokensyncmanager/src/device/device_info_manager.cpp b/services/tokensyncmanager/src/device/device_info_manager.cpp index f8783d04008894c187ff5c66b47db7de42288aae..71a4072f00ecdfeb11ac1b0d8a045ebb0b63e121 100644 --- a/services/tokensyncmanager/src/device/device_info_manager.cpp +++ b/services/tokensyncmanager/src/device/device_info_manager.cpp @@ -20,7 +20,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "DeviceInfoManager"}; std::recursive_mutex g_instanceMutex; } DeviceInfoManager &DeviceInfoManager::GetInstance() @@ -54,7 +53,7 @@ void DeviceInfoManager::AddDeviceInfo(const std::string &networkId, const std::s if (!DataValidator::IsDeviceIdValid(networkId) || !DataValidator::IsDeviceIdValid(universallyUniqueId) || !DataValidator::IsDeviceIdValid(uniqueDeviceId) || deviceName.empty() || deviceType.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AddDeviceInfo: input param is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "AddDeviceInfo: input param is invalid"); return; } DeviceInfoRepository::GetInstance().SaveDeviceInfo( @@ -75,7 +74,7 @@ void DeviceInfoManager::RemoveAllRemoteDeviceInfo() void DeviceInfoManager::RemoveRemoteDeviceInfo(const std::string &nodeId, DeviceIdType deviceIdType) { if (!DataValidator::IsDeviceIdValid(nodeId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RemoveDeviceInfoByNetworkId: nodeId is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "RemoveDeviceInfoByNetworkId: nodeId is invalid"); } else { DeviceInfo deviceInfo; std::string localDevice = ConstantCommon::GetLocalDeviceId(); @@ -91,7 +90,7 @@ std::string DeviceInfoManager::ConvertToUniversallyUniqueIdOrFetch(const std::st { std::string result; if (!DataValidator::IsDeviceIdValid(nodeId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ConvertToUniversallyUniqueIdOrFetch: nodeId is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "ConvertToUniversallyUniqueIdOrFetch: nodeId is invalid."); return result; } DeviceInfo deviceInfo; @@ -114,7 +113,7 @@ std::string DeviceInfoManager::ConvertToUniqueDeviceIdOrFetch(const std::string { std::string result; if (!DataValidator::IsDeviceIdValid(nodeId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ConvertToUniqueDeviceIdOrFetch: nodeId is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "ConvertToUniqueDeviceIdOrFetch: nodeId is invalid."); return result; } DeviceInfo deviceInfo; @@ -125,29 +124,29 @@ std::string DeviceInfoManager::ConvertToUniqueDeviceIdOrFetch(const std::string if (!udid.empty()) { result = udid; } else { - ACCESSTOKEN_LOG_DEBUG(LABEL, + LOGD(ATM_DOMAIN, ATM_TAG, "FindDeviceInfo succeed, udid and local udid is empty, nodeId(%{public}s)", ConstantCommon::EncryptDevId(nodeId).c_str()); } } else { - ACCESSTOKEN_LOG_DEBUG(LABEL, + LOGD(ATM_DOMAIN, ATM_TAG, "FindDeviceInfo succeed, udid is empty, nodeId(%{public}s) ", ConstantCommon::EncryptDevId(nodeId).c_str()); result = uniqueDeviceId; } } else { - ACCESSTOKEN_LOG_DEBUG( - LABEL, "FindDeviceInfo failed, nodeId(%{public}s)", + LOGD( + ATM_DOMAIN, ATM_TAG, "FindDeviceInfo failed, nodeId(%{public}s)", ConstantCommon::EncryptDevId(nodeId).c_str()); auto list = DeviceInfoRepository::GetInstance().ListDeviceInfo(); auto iter = list.begin(); for (; iter != list.end(); iter++) { DeviceInfo info = (*iter); - ACCESSTOKEN_LOG_DEBUG( - LABEL, ">>> DeviceInfoRepository device name: %{public}s", info.deviceName.c_str()); - ACCESSTOKEN_LOG_DEBUG( - LABEL, ">>> DeviceInfoRepository device type: %{public}s", info.deviceType.c_str()); - ACCESSTOKEN_LOG_DEBUG(LABEL, + LOGD(ATM_DOMAIN, ATM_TAG, + ">>> DeviceInfoRepository device name: %{public}s", info.deviceName.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, + ">>> DeviceInfoRepository device type: %{public}s", info.deviceType.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, ">>> DeviceInfoRepository device network id: %{public}s", ConstantCommon::EncryptDevId(info.deviceId.networkId).c_str()); } @@ -158,7 +157,7 @@ std::string DeviceInfoManager::ConvertToUniqueDeviceIdOrFetch(const std::string bool DeviceInfoManager::IsDeviceUniversallyUniqueId(const std::string &nodeId) const { if (!DataValidator::IsDeviceIdValid(nodeId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "IsDeviceUniversallyUniqueId: nodeId is invalid"); + LOGE(ATM_DOMAIN, ATM_TAG, "IsDeviceUniversallyUniqueId: nodeId is invalid"); return false; } DeviceInfo deviceInfo; diff --git a/services/tokensyncmanager/src/remote/remote_command_executor.cpp b/services/tokensyncmanager/src/remote/remote_command_executor.cpp index de63487802a5febaa5d9f2ed56d196d51fdd443a..2692b72a4876226361a497bd65ca41a6a38a361a 100644 --- a/services/tokensyncmanager/src/remote/remote_command_executor.cpp +++ b/services/tokensyncmanager/src/remote/remote_command_executor.cpp @@ -28,24 +28,23 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "RemoteCommandExecutor"}; static const std::string TASK_NAME = "RemoteCommandExecutor::ProcessBufferedCommandsWithThread"; } // namespace RemoteCommandExecutor::RemoteCommandExecutor(const std::string &targetNodeId) : targetNodeId_(targetNodeId), ptrChannel_(nullptr), mutex_(), commands_(), running_(false) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "RemoteCommandExecutor()"); + LOGD(ATM_DOMAIN, ATM_TAG, "RemoteCommandExecutor()"); } RemoteCommandExecutor::~RemoteCommandExecutor() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "~RemoteCommandExecutor() begin"); + LOGD(ATM_DOMAIN, ATM_TAG, "~RemoteCommandExecutor() begin"); running_ = false; } const std::shared_ptr RemoteCommandExecutor::CreateChannel(const std::string &targetNodeId) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "CreateChannel: targetNodeId=%{public}s", + LOGD(ATM_DOMAIN, ATM_TAG, "CreateChannel: targetNodeId=%{public}s", ConstantCommon::EncryptDevId(targetNodeId).c_str()); // only consider SoftBusChannel std::shared_ptr ptrChannel = std::make_shared(targetNodeId); @@ -58,18 +57,18 @@ const std::shared_ptr RemoteCommandExecutor::CreateChannel(const std int RemoteCommandExecutor::ProcessOneCommand(const std::shared_ptr& ptrCommand) { if (ptrCommand == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "TargetNodeId %{public}s, attempt to process on null command.", + LOGW(ATM_DOMAIN, ATM_TAG, "TargetNodeId %{public}s, attempt to process on null command.", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); return Constant::SUCCESS; } const std::string uniqueId = ptrCommand->remoteProtocol_.uniqueId; - ACCESSTOKEN_LOG_INFO(LABEL, "TargetNodeId %{public}s, process one command start, uniqueId: %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "TargetId %{public}s, process one command start, uniqueId: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), uniqueId.c_str()); ptrCommand->Prepare(); int status = ptrCommand->remoteProtocol_.statusCode; if (status != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "targetNodeId %{public}s, process one command error, uniqueId: %{public}s, message: " "prepare failure code %{public}d", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), uniqueId.c_str(), status); @@ -84,12 +83,12 @@ int RemoteCommandExecutor::ProcessOneCommand(const std::shared_ptrBuildConnection() != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TargetNodeId %{public}s, channel is not ready.", + LOGE(ATM_DOMAIN, ATM_TAG, "TargetNodeId %{public}s, channel is not ready.", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); return Constant::FAILURE; } @@ -103,13 +102,13 @@ int RemoteCommandExecutor::ProcessOneCommand(const std::shared_ptr& ptrCommand) { if (ptrCommand == nullptr) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "TargetNodeId %{public}s, attempt to add an empty command.", + LOGD(ATM_DOMAIN, ATM_TAG, "TargetNodeId %{public}s, attempt to add an empty command.", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); return Constant::INVALID_COMMAND; } const std::string uniqueId = ptrCommand->remoteProtocol_.uniqueId; - ACCESSTOKEN_LOG_DEBUG(LABEL, "TargetNodeId %{public}s, add uniqueId %{public}s", + LOGD(ATM_DOMAIN, ATM_TAG, "TargetNodeId %{public}s, add uniqueId %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), uniqueId.c_str()); std::unique_lock lock(mutex_); @@ -117,7 +116,7 @@ int RemoteCommandExecutor::AddCommand(const std::shared_ptr& // make sure do not have the same command in the command buffer if (std::any_of(commands_.begin(), commands_.end(), [uniqueId](const auto& buffCommand) {return buffCommand->remoteProtocol_.uniqueId == uniqueId; })) { - ACCESSTOKEN_LOG_WARN(LABEL, + LOGW(ATM_DOMAIN, ATM_TAG, "targetNodeId %{public}s, add uniqueId %{public}s, already exist in the buffer, skip", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), uniqueId.c_str()); @@ -133,13 +132,13 @@ int RemoteCommandExecutor::AddCommand(const std::shared_ptr& */ int RemoteCommandExecutor::ProcessBufferedCommands(bool standalone) { - ACCESSTOKEN_LOG_INFO(LABEL, "Begin, targetNodeId: %{public}s, standalone: %{public}d", + LOGI(ATM_DOMAIN, ATM_TAG, "Begin, targetNodeId: %{public}s, standalone: %{public}d", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), standalone); std::unique_lock lock(mutex_); if (commands_.empty()) { - ACCESSTOKEN_LOG_WARN(LABEL, "No command, targetNodeId %{public}s", + LOGW(ATM_DOMAIN, ATM_TAG, "No command, targetNodeId %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); running_ = false; return Constant::SUCCESS; @@ -149,14 +148,14 @@ int RemoteCommandExecutor::ProcessBufferedCommands(bool standalone) while (true) { // interrupt if (!running_) { - ACCESSTOKEN_LOG_INFO(LABEL, "End with running flag == false, targetNodeId: %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "End with running flag == false, targetNodeId: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); return Constant::FAILURE; } // end if (commands_.empty()) { running_ = false; - ACCESSTOKEN_LOG_INFO(LABEL, "End, no command left, targetNodeId: %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "End, no command left, targetNodeId: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); return Constant::SUCCESS; } @@ -168,7 +167,7 @@ int RemoteCommandExecutor::ProcessBufferedCommands(bool standalone) commands_.pop_front(); continue; } else if (status == Constant::FAILURE_BUT_CAN_RETRY) { - ACCESSTOKEN_LOG_WARN(LABEL, + LOGW(ATM_DOMAIN, ATM_TAG, "execute failed and wait to retry, targetNodeId: %{public}s, message: %{public}s, and will retry ", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), bufferedCommand->remoteProtocol_.message.c_str()); @@ -181,7 +180,7 @@ int RemoteCommandExecutor::ProcessBufferedCommands(bool standalone) } else { // this command failed, move on to execute next command commands_.pop_front(); - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "execute failed, targetNodeId: %{public}s, commandName: %{public}s, message: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), bufferedCommand->remoteProtocol_.commandName.c_str(), @@ -195,18 +194,19 @@ int RemoteCommandExecutor::ProcessBufferedCommands(bool standalone) */ void RemoteCommandExecutor::ProcessBufferedCommandsWithThread() { - ACCESSTOKEN_LOG_INFO(LABEL, "Begin, targetNodeId: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, + "Begin, targetNodeId: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); std::unique_lock lock(mutex_); if (commands_.empty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "No buffered commands. targetNodeId: %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "No buffered commands. targetNodeId: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); return; } if (running_) { // task is running, do not need to start one more - ACCESSTOKEN_LOG_WARN(LABEL, "Task busy. targetNodeId: %{public}s", + LOGW(ATM_DOMAIN, ATM_TAG, "Task busy. targetNodeId: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); return; } @@ -215,7 +215,7 @@ void RemoteCommandExecutor::ProcessBufferedCommandsWithThread() const std::function runner = [weak = weak_from_this()]() { auto self = weak.lock(); if (self == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "RemoteCommandExecutor is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "RemoteCommandExecutor is nullptr"); return; } self->ProcessBufferedCommands(true); @@ -225,16 +225,16 @@ void RemoteCommandExecutor::ProcessBufferedCommandsWithThread() std::shared_ptr handler = DelayedSingleton::GetInstance()->GetSendEventHandler(); if (handler == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get EventHandler"); return; } bool result = handler->ProxyPostTask(runner, TASK_NAME); if (!result) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Post task failed, targetNodeId: %{public}s", + LOGE(ATM_DOMAIN, ATM_TAG, "Post task failed, targetNodeId: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); } #endif - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "post task succeed, targetNodeId: %{public}s, taskName: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), TASK_NAME.c_str()); @@ -244,7 +244,8 @@ int RemoteCommandExecutor::ExecuteRemoteCommand( const std::shared_ptr& ptrCommand, const bool isRemote) { std::string uniqueId = ptrCommand->remoteProtocol_.uniqueId; - ACCESSTOKEN_LOG_INFO(LABEL, "TargetNodeId %{public}s, uniqueId %{public}s, remote %{public}d: start to execute.", + LOGI(ATM_DOMAIN, ATM_TAG, + "TargetNodeId %{public}s, uniqueId %{public}s, remote %{public}d: start to execute.", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), uniqueId.c_str(), isRemote); ptrCommand->remoteProtocol_.statusCode = Constant::STATUS_CODE_BEFORE_RPC; @@ -253,12 +254,12 @@ int RemoteCommandExecutor::ExecuteRemoteCommand( // Local device, play myself. ptrCommand->Execute(); int code = ClientProcessResult(ptrCommand); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Command finished with status: %{public}d, message: %{public}s.", + LOGD(ATM_DOMAIN, ATM_TAG, "Command finished with status: %{public}d, message: %{public}s.", ptrCommand->remoteProtocol_.statusCode, ptrCommand->remoteProtocol_.message.c_str()); return code; } - ACCESSTOKEN_LOG_INFO(LABEL, "Command executed uniqueId %{public}s.", uniqueId.c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Command executed uniqueId %{public}s.", uniqueId.c_str()); std::string responseString; int32_t repeatTimes = SoftBusManager::GetInstance().GetRepeatTimes(); // repeat 5 times if responseString empty @@ -269,7 +270,7 @@ int RemoteCommandExecutor::ExecuteRemoteCommand( break; // when responseString is not empty, break the loop } - ACCESSTOKEN_LOG_WARN(LABEL, + LOGW(ATM_DOMAIN, ATM_TAG, "TargetNodeId %{public}s, uniqueId %{public}s, execute remote command error, response is empty.", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), uniqueId.c_str()); } @@ -285,7 +286,7 @@ int RemoteCommandExecutor::ExecuteRemoteCommand( RemoteCommandFactory::GetInstance().NewRemoteCommandFromJson( ptrCommand->remoteProtocol_.commandName, responseString); if (ptrResponseCommand == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "TargetNodeId %{public}s, get null response command!", + LOGE(ATM_DOMAIN, ATM_TAG, "TargetNodeId %{public}s, get null response command!", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); return Constant::FAILURE; } @@ -293,7 +294,7 @@ int RemoteCommandExecutor::ExecuteRemoteCommand( if (commands_.empty()) { ptrChannel_->CloseConnection(); } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Command finished with status: %{public}d, message: %{public}s.", + LOGD(ATM_DOMAIN, ATM_TAG, "Command finished with status: %{public}d, message: %{public}s.", ptrResponseCommand->remoteProtocol_.statusCode, ptrResponseCommand->remoteProtocol_.message.c_str()); return result; } @@ -302,7 +303,7 @@ void RemoteCommandExecutor::CreateChannelIfNeeded() { std::unique_lock lock(mutex_); if (ptrChannel_ != nullptr) { - ACCESSTOKEN_LOG_INFO(LABEL, "TargetNodeId %{public}s, channel is exist.", + LOGI(ATM_DOMAIN, ATM_TAG, "TargetNodeId %{public}s, channel is exist.", ConstantCommon::EncryptDevId(targetNodeId_).c_str()); return; } @@ -314,7 +315,7 @@ int RemoteCommandExecutor::ClientProcessResult(const std::shared_ptrremoteProtocol_.uniqueId; if (ptrCommand->remoteProtocol_.statusCode == Constant::STATUS_CODE_BEFORE_RPC) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "targetNodeId %{public}s, uniqueId %{public}s, status code after RPC is same as before, the remote side " "may not " "support this command", @@ -326,13 +327,13 @@ int RemoteCommandExecutor::ClientProcessResult(const std::shared_ptrFinish(); int status = ptrCommand->remoteProtocol_.statusCode; if (status != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "targetNodeId %{public}s, uniqueId %{public}s, execute failed, message: %{public}s", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), uniqueId.c_str(), ptrCommand->remoteProtocol_.message.c_str()); } else { - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "targetNodeId %{public}s, uniqueId %{public}s, execute succeed.", ConstantCommon::EncryptDevId(targetNodeId_).c_str(), uniqueId.c_str()); diff --git a/services/tokensyncmanager/src/remote/remote_command_factory.cpp b/services/tokensyncmanager/src/remote/remote_command_factory.cpp index 88ecff12441539a3d8cef5d9cc987bfbdd35ce6b..27e3807f97875c203762f5b08d83e9cf825f5537 100644 --- a/services/tokensyncmanager/src/remote/remote_command_factory.cpp +++ b/services/tokensyncmanager/src/remote/remote_command_factory.cpp @@ -58,17 +58,13 @@ std::shared_ptr RemoteCommandFactory::NewUpdateRemo std::shared_ptr RemoteCommandFactory::NewRemoteCommandFromJson( const std::string &commandName, const std::string &commandJsonString) { - const std::string SYNC_HAP_COMMAND_NAME = "SyncRemoteHapTokenCommand"; - const std::string DELETE_TOKEN_COMMAND_NAME = "DeleteRemoteTokenCommand"; - const std::string UPDATE_HAP_COMMAND_NAME = "UpdateRemoteHapTokenCommand"; - - if (commandName == SYNC_HAP_COMMAND_NAME) { + if (commandName == "SyncRemoteHapTokenCommand") { return std::make_shared(commandJsonString); } - if (commandName == DELETE_TOKEN_COMMAND_NAME) { + if (commandName == "DeleteRemoteTokenCommand") { return std::make_shared(commandJsonString); } - if (commandName == UPDATE_HAP_COMMAND_NAME) { + if (commandName == "UpdateRemoteHapTokenCommand") { return std::make_shared(commandJsonString); } return nullptr; diff --git a/services/tokensyncmanager/src/remote/remote_command_manager.cpp b/services/tokensyncmanager/src/remote/remote_command_manager.cpp index 98c77f07e862227bc15de2f657d7f5de7657e1e6..43f5fdf4942db5842e7645a9d414dfc34bcc1b36 100644 --- a/services/tokensyncmanager/src/remote/remote_command_manager.cpp +++ b/services/tokensyncmanager/src/remote/remote_command_manager.cpp @@ -28,17 +28,16 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "RemoteCommandManager"}; std::recursive_mutex g_instanceMutex; } RemoteCommandManager::RemoteCommandManager() : executors_(), mutex_() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "RemoteCommandManager()"); + LOGD(ATM_DOMAIN, ATM_TAG, "RemoteCommandManager()"); } RemoteCommandManager::~RemoteCommandManager() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "~RemoteCommandManager()"); + LOGD(ATM_DOMAIN, ATM_TAG, "~RemoteCommandManager()"); } RemoteCommandManager &RemoteCommandManager::GetInstance() @@ -56,89 +55,92 @@ RemoteCommandManager &RemoteCommandManager::GetInstance() void RemoteCommandManager::Init() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Init()"); + LOGD(ATM_DOMAIN, ATM_TAG, "Init()"); } int RemoteCommandManager::AddCommand(const std::string &udid, const std::shared_ptr& command) { if (udid.empty() || command == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Invalid udid, or null command"); + LOGW(ATM_DOMAIN, ATM_TAG, "Invalid udid, or null command"); return Constant::FAILURE; } - ACCESSTOKEN_LOG_INFO(LABEL, "Add uniqueId"); + LOGI(ATM_DOMAIN, ATM_TAG, "Add uniqueId"); std::shared_ptr executor = GetOrCreateRemoteCommandExecutor(udid); if (executor == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get or create remote command executor"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get or create remote command executor"); return Constant::FAILURE; } int result = executor->AddCommand(command); - ACCESSTOKEN_LOG_INFO(LABEL, "Add command result: %{public}d ", result); + LOGI(ATM_DOMAIN, ATM_TAG, "Add command result: %{public}d ", result); return result; } void RemoteCommandManager::RemoveCommand(const std::string &udid) { - ACCESSTOKEN_LOG_INFO(LABEL, "Remove command"); + LOGI(ATM_DOMAIN, ATM_TAG, "Remove command"); executors_.erase(udid); } int RemoteCommandManager::ExecuteCommand(const std::string &udid, const std::shared_ptr& command) { if (udid.empty() || command == nullptr) { - ACCESSTOKEN_LOG_WARN(LABEL, "Invalid udid: %{public}s, or null command", + LOGW(ATM_DOMAIN, ATM_TAG, "Invalid udid: %{public}s, or null command", ConstantCommon::EncryptDevId(udid).c_str()); return Constant::FAILURE; } std::string uniqueId = command->remoteProtocol_.uniqueId; - ACCESSTOKEN_LOG_INFO(LABEL, "Start with udid: %{public}s , uniqueId: %{public}s ", + LOGI(ATM_DOMAIN, ATM_TAG, "Start with udid: %{public}s , uniqueId: %{public}s ", ConstantCommon::EncryptDevId(udid).c_str(), ConstantCommon::EncryptDevId(uniqueId).c_str()); std::shared_ptr executor = GetOrCreateRemoteCommandExecutor(udid); if (executor == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get or create remote command executor"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get or create remote command executor"); return Constant::FAILURE; } int result = executor->ProcessOneCommand(command); - ACCESSTOKEN_LOG_INFO(LABEL, "RemoteCommandExecutor processOneCommand result:%{public}d ", result); + LOGI(ATM_DOMAIN, ATM_TAG, "RemoteCommandExecutor processOneCommand result:%{public}d ", result); return result; } int RemoteCommandManager::ProcessDeviceCommandImmediately(const std::string &udid) { if (udid.empty()) { - ACCESSTOKEN_LOG_WARN(LABEL, "Invalid udid: %{public}s", ConstantCommon::EncryptDevId(udid).c_str()); + LOGW(ATM_DOMAIN, ATM_TAG, + "Invalid udid: %{public}s", ConstantCommon::EncryptDevId(udid).c_str()); return Constant::FAILURE; } - ACCESSTOKEN_LOG_INFO(LABEL, "Start with udid:%{public}s ", ConstantCommon::EncryptDevId(udid).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, + "Start with udid:%{public}s ", ConstantCommon::EncryptDevId(udid).c_str()); std::unique_lock lock(mutex_); auto executorIt = executors_.find(udid); if (executorIt == executors_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "No executor found, udid:%{public}s", ConstantCommon::EncryptDevId(udid).c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, + "No executor found, udid:%{public}s", ConstantCommon::EncryptDevId(udid).c_str()); return Constant::FAILURE; } auto executor = executorIt->second; if (executor == nullptr) { - ACCESSTOKEN_LOG_INFO(LABEL, "RemoteCommandExecutor is null for udid %{public}s ", + LOGI(ATM_DOMAIN, ATM_TAG, "RemoteCommandExecutor is null for udid %{public}s ", ConstantCommon::EncryptDevId(udid).c_str()); return Constant::FAILURE; } int result = executor->ProcessBufferedCommands(); - ACCESSTOKEN_LOG_INFO(LABEL, "ProcessBufferedCommands result: %{public}d", result); + LOGI(ATM_DOMAIN, ATM_TAG, "ProcessBufferedCommands result: %{public}d", result); return result; } int RemoteCommandManager::Loop() { - ACCESSTOKEN_LOG_INFO(LABEL, "Start"); + LOGI(ATM_DOMAIN, ATM_TAG, "Start"); std::unique_lock lock(mutex_); for (auto it = executors_.begin(); it != executors_.end(); it++) { - ACCESSTOKEN_LOG_INFO(LABEL, "Udid:%{public}s", ConstantCommon::EncryptDevId(it->first).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "Udid:%{public}s", ConstantCommon::EncryptDevId(it->first).c_str()); (*it).second->ProcessBufferedCommandsWithThread(); } return Constant::SUCCESS; @@ -149,7 +151,7 @@ int RemoteCommandManager::Loop() */ void RemoteCommandManager::Clear() { - ACCESSTOKEN_LOG_INFO(LABEL, "Remove all remote command executors."); + LOGI(ATM_DOMAIN, ATM_TAG, "Remove all remote command executors."); std::map> dummy; std::unique_lock lock(mutex_); @@ -163,23 +165,24 @@ void RemoteCommandManager::Clear() int RemoteCommandManager::NotifyDeviceOnline(const std::string &nodeId) { if (!DataValidator::IsDeviceIdValid(nodeId)) { - ACCESSTOKEN_LOG_INFO(LABEL, "Invalid nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, + "Invalid nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); return Constant::FAILURE; } - ACCESSTOKEN_LOG_INFO(LABEL, "Operation start with nodeId: %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "Operation start with nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); auto executor = GetOrCreateRemoteCommandExecutor(nodeId); std::unique_lock lock(mutex_); if (executor == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Cannot get or create remote command executor"); + LOGE(ATM_DOMAIN, ATM_TAG, "Cannot get or create remote command executor"); return Constant::FAILURE; } if (executor->GetChannel() == nullptr) { auto channel = RemoteCommandExecutor::CreateChannel(nodeId); if (channel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Create channel failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Create channel failed."); return Constant::FAILURE; } executor->SetChannel(channel); @@ -196,10 +199,11 @@ int RemoteCommandManager::NotifyDeviceOnline(const std::string &nodeId) int RemoteCommandManager::NotifyDeviceOffline(const std::string &nodeId) { if (!DataValidator::IsDeviceIdValid(nodeId)) { - ACCESSTOKEN_LOG_INFO(LABEL, "Invalid nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, + "Invalid nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); return Constant::FAILURE; } - ACCESSTOKEN_LOG_INFO(LABEL, "Operation start with nodeId: %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "Operation start with nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); auto channel = GetExecutorChannel(nodeId); @@ -214,7 +218,7 @@ int RemoteCommandManager::NotifyDeviceOffline(const std::string &nodeId) DeviceInfo devInfo; bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(nodeId, DeviceIdType::UNKNOWN, devInfo); if (!result) { - ACCESSTOKEN_LOG_INFO(LABEL, "Get remote networkId failed"); + LOGI(ATM_DOMAIN, ATM_TAG, "Get remote networkId failed"); return Constant::FAILURE; } std::string uniqueDeviceId = devInfo.deviceId.uniqueDeviceId; @@ -226,19 +230,19 @@ int RemoteCommandManager::NotifyDeviceOffline(const std::string &nodeId) std::shared_ptr handler = DelayedSingleton::GetInstance()->GetSendEventHandler(); if (handler == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get EventHandler"); return Constant::FAILURE; } handler->ProxyPostTask(delayed, "HandleDeviceOffline"); #endif - ACCESSTOKEN_LOG_INFO(LABEL, "Complete"); + LOGI(ATM_DOMAIN, ATM_TAG, "Complete"); return Constant::SUCCESS; } std::shared_ptr RemoteCommandManager::GetOrCreateRemoteCommandExecutor(const std::string &nodeId) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Begin, nodeId %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "Begin, nodeId %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); std::unique_lock lock(mutex_); auto executorIter = executors_.find(nodeId); @@ -248,7 +252,8 @@ std::shared_ptr RemoteCommandManager::GetOrCreateRemoteCo auto executor = std::make_shared(nodeId); executors_.insert(std::pair>(nodeId, executor)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Executor added, nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, + "Executor added, nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); return executor; } @@ -257,23 +262,24 @@ std::shared_ptr RemoteCommandManager::GetOrCreateRemoteCo */ std::shared_ptr RemoteCommandManager::GetExecutorChannel(const std::string &nodeId) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Convert udid start, nodeId:%{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, + "Convert udid start, nodeId:%{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); std::string udid = DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(nodeId); if (!DataValidator::IsDeviceIdValid(udid)) { - ACCESSTOKEN_LOG_WARN( - LABEL, "Converted udid is invalid, nodeId:%{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); + LOGW(ATM_DOMAIN, ATM_TAG, + "Converted udid is invalid, nodeId:%{public}s", ConstantCommon::EncryptDevId(nodeId).c_str()); return nullptr; } std::unique_lock lock(mutex_); std::map>::iterator iter = executors_.find(udid); if (iter == executors_.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "Executor not found"); + LOGI(ATM_DOMAIN, ATM_TAG, "Executor not found"); return nullptr; } std::shared_ptr executor = iter->second; if (executor == nullptr) { - ACCESSTOKEN_LOG_INFO(LABEL, "Executor is null"); + LOGI(ATM_DOMAIN, ATM_TAG, "Executor is null"); return nullptr; } return executor->GetChannel(); diff --git a/services/tokensyncmanager/src/remote/soft_bus_channel.cpp b/services/tokensyncmanager/src/remote/soft_bus_channel.cpp index c8ac29a672ada649ee6d766d40643d5b14bfd01a..0363fe6faae90d242a25f966cb47c45181bdb36a 100644 --- a/services/tokensyncmanager/src/remote/soft_bus_channel.cpp +++ b/services/tokensyncmanager/src/remote/soft_bus_channel.cpp @@ -29,12 +29,9 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "SoftBusChannel"}; -} -namespace { -static const std::string REQUEST_TYPE = "request"; -static const std::string RESPONSE_TYPE = "response"; -static const std::string TASK_NAME_CLOSE_SESSION = "atm_soft_bus_channel_close_session"; +constexpr const char* REQUEST_TYPE = "request"; +constexpr const char* RESPONSE_TYPE = "response"; +constexpr const char* TASK_NAME_CLOSE_SESSION = "atm_soft_bus_channel_close_session"; static const int32_t EXECUTE_COMMAND_TIME_OUT = 3000; static const int32_t WAIT_SESSION_CLOSE_MILLISECONDS = 5 * 1000; // send buf size for header @@ -45,7 +42,7 @@ static const int RPC_TRANSFER_BYTES_MAX_LENGTH = 1024 * 1024; SoftBusChannel::SoftBusChannel(const std::string &deviceId) : deviceId_(deviceId), mutex_(), callbacks_(), responseResult_(""), loadedCond_() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "SoftBusChannel(deviceId)"); + LOGD(ATM_DOMAIN, ATM_TAG, "SoftBusChannel(deviceId)"); isDelayClosing_ = false; socketFd_ = Constant::INVALID_SOCKET_FD; isSocketUsing_ = false; @@ -53,7 +50,7 @@ SoftBusChannel::SoftBusChannel(const std::string &deviceId) SoftBusChannel::~SoftBusChannel() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "~SoftBusChannel()"); + LOGD(ATM_DOMAIN, ATM_TAG, "~SoftBusChannel()"); } int SoftBusChannel::BuildConnection() @@ -62,16 +59,16 @@ int SoftBusChannel::BuildConnection() std::unique_lock lock(socketMutex_); if (socketFd_ != Constant::INVALID_SOCKET_FD) { - ACCESSTOKEN_LOG_INFO(LABEL, "Socket is exist, no need open again."); + LOGI(ATM_DOMAIN, ATM_TAG, "Socket is exist, no need open again."); return Constant::SUCCESS; } if (socketFd_ == Constant::INVALID_SOCKET_FD) { - ACCESSTOKEN_LOG_INFO(LABEL, "Bind service with device: %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "Bind service with device: %{public}s", ConstantCommon::EncryptDevId(deviceId_).c_str()); int socket = SoftBusManager::GetInstance().BindService(deviceId_); if (socket == Constant::INVALID_SOCKET_FD) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Bind service failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Bind service failed."); return Constant::FAILURE; } socketFd_ = socket; @@ -81,7 +78,7 @@ int SoftBusChannel::BuildConnection() void SoftBusChannel::CloseConnection() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Close connection"); + LOGD(ATM_DOMAIN, ATM_TAG, "Close connection"); std::unique_lock lock(mutex_); if (isDelayClosing_) { return; @@ -91,7 +88,7 @@ void SoftBusChannel::CloseConnection() std::shared_ptr handler = DelayedSingleton::GetInstance()->GetSendEventHandler(); if (handler == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get EventHandler"); return; } #endif @@ -99,22 +96,22 @@ void SoftBusChannel::CloseConnection() std::function delayed = ([weakPtr]() { auto self = weakPtr.lock(); if (self == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SoftBusChannel is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "SoftBusChannel is nullptr"); return; } std::unique_lock lock(self->socketMutex_); if (self->isSocketUsing_) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Socket is in using, cancel close socket"); + LOGD(ATM_DOMAIN, ATM_TAG, "Socket is in using, cancel close socket"); } else { SoftBusManager::GetInstance().CloseSocket(self->socketFd_); self->socketFd_ = Constant::INVALID_SESSION; - ACCESSTOKEN_LOG_INFO(LABEL, "Close socket for device: %{public}s", + LOGI(ATM_DOMAIN, ATM_TAG, "Close socket for device: %{public}s", ConstantCommon::EncryptDevId(self->deviceId_).c_str()); } self->isDelayClosing_ = false; }); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Close socket after %{public}d ms", WAIT_SESSION_CLOSE_MILLISECONDS); + LOGD(ATM_DOMAIN, ATM_TAG, "Close socket after %{public}d ms", WAIT_SESSION_CLOSE_MILLISECONDS); #ifdef EVENTHANDLER_ENABLE handler->ProxyPostTask(delayed, TASK_NAME_CLOSE_SESSION, WAIT_SESSION_CLOSE_MILLISECONDS); #endif @@ -128,7 +125,7 @@ void SoftBusChannel::Release() std::shared_ptr handler = DelayedSingleton::GetInstance()->GetSendEventHandler(); if (handler == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get EventHandler"); return; } handler->ProxyRemoveTask(TASK_NAME_CLOSE_SESSION); @@ -142,7 +139,8 @@ std::string SoftBusChannel::GetUuid() char uuidbuf[uuidStrLen]; RandomUuid(uuidbuf, uuidStrLen); std::string uuid(uuidbuf); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Generated message uuid: %{public}s", ConstantCommon::EncryptDevId(uuid).c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, + "Generated message uuid: %{public}s", ConstantCommon::EncryptDevId(uuid).c_str()); return uuid; } @@ -153,7 +151,7 @@ void SoftBusChannel::InsertCallback(int result, std::string &uuid) std::function callback = [this](const std::string &result) { responseResult_ = std::string(result); loadedCond_.notify_all(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "OnResponse called end"); + LOGD(ATM_DOMAIN, ATM_TAG, "OnResponse called end"); }; callbacks_.insert(std::pair>(uuid, callback)); @@ -164,7 +162,7 @@ void SoftBusChannel::InsertCallback(int result, std::string &uuid) std::string SoftBusChannel::ExecuteCommand(const std::string &commandName, const std::string &jsonPayload) { if (commandName.empty() || jsonPayload.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid params, commandName: %{public}s", commandName.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid params, commandName: %{public}s", commandName.c_str()); return ""; } @@ -173,7 +171,7 @@ std::string SoftBusChannel::ExecuteCommand(const std::string &commandName, const int len = static_cast(RPC_TRANSFER_HEAD_BYTES_LENGTH + jsonPayload.length()); unsigned char *buf = new (std::nothrow) unsigned char[len + 1]; if (buf == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "No enough memory: %{public}d", len); + LOGE(ATM_DOMAIN, ATM_TAG, "No enough memory: %{public}d", len); return ""; } (void)memset_s(buf, len + 1, 0, len + 1); @@ -191,15 +189,15 @@ std::string SoftBusChannel::ExecuteCommand(const std::string &commandName, const std::unique_lock lock2(socketMutex_); if (retCode != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Send request data failed: %{public}d ", retCode); + LOGE(ATM_DOMAIN, ATM_TAG, "Send request data failed: %{public}d ", retCode); callbacks_.erase(uuid); isSocketUsing_ = false; return ""; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Wait command response"); + LOGD(ATM_DOMAIN, ATM_TAG, "Wait command response"); if (loadedCond_.wait_for(lock2, std::chrono::milliseconds(EXECUTE_COMMAND_TIME_OUT)) == std::cv_status::timeout) { - ACCESSTOKEN_LOG_WARN(LABEL, "Time out to wait response."); + LOGW(ATM_DOMAIN, ATM_TAG, "Time out to wait response."); callbacks_.erase(uuid); isSocketUsing_ = false; return ""; @@ -211,26 +209,27 @@ std::string SoftBusChannel::ExecuteCommand(const std::string &commandName, const void SoftBusChannel::HandleDataReceived(int socket, const unsigned char *bytes, int length) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "HandleDataReceived"); + LOGD(ATM_DOMAIN, ATM_TAG, "HandleDataReceived"); #ifdef DEBUG_API_PERFORMANCE - ACCESSTOKEN_LOG_INFO(LABEL, "Api_performance:recieve message from softbus"); + LOGI(ATM_DOMAIN, ATM_TAG, "Api_performance:recieve message from softbus"); #endif if (socket <= 0 || length <= 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid params: socket: %{public}d, data length: %{public}d", socket, length); + LOGE(ATM_DOMAIN, ATM_TAG, + "Invalid params: socket: %{public}d, data length: %{public}d", socket, length); return; } std::string receiveData = Decompress(bytes, length); if (receiveData.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid parameter bytes"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid parameter bytes"); return; } std::shared_ptr message = SoftBusMessage::FromJson(receiveData); if (message == nullptr) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Invalid json string"); + LOGD(ATM_DOMAIN, ATM_TAG, "Invalid json string"); return; } if (!message->IsValid()) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Invalid data, has empty field"); + LOGD(ATM_DOMAIN, ATM_TAG, "Invalid data, has empty field"); return; } @@ -239,7 +238,7 @@ void SoftBusChannel::HandleDataReceived(int socket, const unsigned char *bytes, std::function delayed = ([weak = weak_from_this(), socket, message]() { auto self = weak.lock(); if (self == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SoftBusChannel is nullptr"); + LOGE(ATM_DOMAIN, ATM_TAG, "SoftBusChannel is nullptr"); return; } self->HandleRequest(socket, message->GetId(), message->GetCommandName(), message->GetJsonPayload()); @@ -249,7 +248,7 @@ void SoftBusChannel::HandleDataReceived(int socket, const unsigned char *bytes, std::shared_ptr handler = DelayedSingleton::GetInstance()->GetRecvEventHandler(); if (handler == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to get EventHandler"); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to get EventHandler"); return; } handler->ProxyPostTask(delayed, "HandleDataReceived_HandleRequest"); @@ -257,7 +256,7 @@ void SoftBusChannel::HandleDataReceived(int socket, const unsigned char *bytes, } else if (RESPONSE_TYPE == (type)) { HandleResponse(message->GetId(), message->GetJsonPayload()); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid type: %{public}s ", type.c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid type: %{public}s ", type.c_str()); } } @@ -274,7 +273,7 @@ int SoftBusChannel::Compress(const std::string &json, const unsigned char *compr uLong len = compressBound(json.size()); // length will not so that long if (compressedLength > 0 && static_cast(len) > compressedLength) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "compress error. data length overflow, bound length: %{public}d, buffer length: %{public}d", static_cast(len), compressedLength); return Constant::FAILURE; @@ -283,10 +282,11 @@ int SoftBusChannel::Compress(const std::string &json, const unsigned char *compr int result = compress(const_cast(compressedBytes), &len, reinterpret_cast(const_cast(json.c_str())), json.size() + 1); if (result != Z_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Compress failed! error code: %{public}d", result); + LOGE(ATM_DOMAIN, ATM_TAG, "Compress failed! error code: %{public}d", result); return result; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Compress complete. compress %{public}d bytes to %{public}d", compressedLength, + LOGD(ATM_DOMAIN, ATM_TAG, + "Compress complete. compress %{public}d bytes to %{public}d", compressedLength, static_cast(len)); compressedLength = static_cast(len); return Constant::SUCCESS; @@ -294,17 +294,17 @@ int SoftBusChannel::Compress(const std::string &json, const unsigned char *compr std::string SoftBusChannel::Decompress(const unsigned char *bytes, const int length) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Input length: %{public}d", length); + LOGD(ATM_DOMAIN, ATM_TAG, "Input length: %{public}d", length); uLong len = RPC_TRANSFER_BYTES_MAX_LENGTH; unsigned char *buf = new (std::nothrow) unsigned char[len + 1]; if (buf == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "No enough memory!"); + LOGE(ATM_DOMAIN, ATM_TAG, "No enough memory!"); return ""; } (void)memset_s(buf, len + 1, 0, len + 1); int result = uncompress(buf, &len, const_cast(bytes), length); if (result != Z_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "uncompress failed, error code: %{public}d, bound length: %{public}d, buffer length: %{public}d", result, static_cast(len), length); delete[] buf; @@ -319,26 +319,26 @@ std::string SoftBusChannel::Decompress(const unsigned char *bytes, const int len int SoftBusChannel::SendRequestBytes(const unsigned char *bytes, const int bytesLength) { if (bytesLength == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Bytes data is invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Bytes data is invalid."); return Constant::FAILURE; } std::unique_lock lock(socketMutex_); if (CheckSessionMayReopenLocked() != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Socket invalid and reopen failed!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Socket invalid and reopen failed!"); return Constant::FAILURE; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Send len (after compress len)= %{public}d", bytesLength); + LOGD(ATM_DOMAIN, ATM_TAG, "Send len (after compress len)= %{public}d", bytesLength); #ifdef DEBUG_API_PERFORMANCE - ACCESSTOKEN_LOG_INFO(LABEL, "Api_performance:send command to softbus"); + LOGI(ATM_DOMAIN, ATM_TAG, "Api_performance:send command to softbus"); #endif int result = ::SendBytes(socketFd_, bytes, bytesLength); if (result != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to send! result= %{public}d", result); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to send! result= %{public}d", result); return Constant::FAILURE; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Send successfully."); + LOGD(ATM_DOMAIN, ATM_TAG, "Send successfully."); return Constant::SUCCESS; } @@ -367,7 +367,7 @@ void SoftBusChannel::CancelCloseConnectionIfNeeded() if (!isDelayClosing_) { return; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Cancel close connection"); + LOGD(ATM_DOMAIN, ATM_TAG, "Cancel close connection"); Release(); isDelayClosing_ = false; @@ -380,12 +380,12 @@ void SoftBusChannel::HandleRequest(int socket, const std::string &id, const std: RemoteCommandFactory::GetInstance().NewRemoteCommandFromJson(commandName, jsonPayload); if (command == nullptr) { // send result back directly - ACCESSTOKEN_LOG_WARN(LABEL, "Command %{public}s cannot get from json", commandName.c_str()); + LOGW(ATM_DOMAIN, ATM_TAG, "Command %{public}s cannot get from json", commandName.c_str()); int sendlen = static_cast(RPC_TRANSFER_HEAD_BYTES_LENGTH + jsonPayload.length()); unsigned char *sendbuf = new (std::nothrow) unsigned char[sendlen + 1]; if (sendbuf == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "No enough memory: %{public}d", sendlen); + LOGE(ATM_DOMAIN, ATM_TAG, "No enough memory: %{public}d", sendlen); return; } (void)memset_s(sendbuf, sendlen + 1, 0, sendlen + 1); @@ -399,13 +399,14 @@ void SoftBusChannel::HandleRequest(int socket, const std::string &id, const std: } int sendResultCode = SendResponseBytes(socket, sendbuf, info.bytesLength); delete[] sendbuf; - ACCESSTOKEN_LOG_DEBUG(LABEL, "Send response result= %{public}d ", sendResultCode); + LOGD(ATM_DOMAIN, ATM_TAG, "Send response result= %{public}d ", sendResultCode); return; } // execute command command->Execute(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Command uniqueId: %{public}s, finish with status: %{public}d, message: %{public}s", + LOGD(ATM_DOMAIN, ATM_TAG, + "Command uniqueId: %{public}s, finish with status: %{public}d, message: %{public}s", ConstantCommon::EncryptDevId(command->remoteProtocol_.uniqueId).c_str(), command->remoteProtocol_.statusCode, command->remoteProtocol_.message.c_str()); @@ -414,7 +415,7 @@ void SoftBusChannel::HandleRequest(int socket, const std::string &id, const std: int len = static_cast(RPC_TRANSFER_HEAD_BYTES_LENGTH + resultJsonPayload.length()); unsigned char *buf = new (std::nothrow) unsigned char[len + 1]; if (buf == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "No enough memory: %{public}d", len); + LOGE(ATM_DOMAIN, ATM_TAG, "No enough memory: %{public}d", len); return; } (void)memset_s(buf, len + 1, 0, len + 1); @@ -428,7 +429,7 @@ void SoftBusChannel::HandleRequest(int socket, const std::string &id, const std: } int retCode = SendResponseBytes(socket, buf, info.bytesLength); delete[] buf; - ACCESSTOKEN_LOG_DEBUG(LABEL, "Send response result= %{public}d", retCode); + LOGD(ATM_DOMAIN, ATM_TAG, "Send response result= %{public}d", retCode); } void SoftBusChannel::HandleResponse(const std::string &id, const std::string &jsonPayload) @@ -443,13 +444,13 @@ void SoftBusChannel::HandleResponse(const std::string &id, const std::string &js int SoftBusChannel::SendResponseBytes(int socket, const unsigned char *bytes, const int bytesLength) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Send len (after compress len)= %{public}d", bytesLength); + LOGD(ATM_DOMAIN, ATM_TAG, "Send len (after compress len)= %{public}d", bytesLength); int result = ::SendBytes(socket, bytes, bytesLength); if (result != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to send! result= %{public}d", result); + LOGE(ATM_DOMAIN, ATM_TAG, "Fail to send! result= %{public}d", result); return Constant::FAILURE; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Send successfully."); + LOGD(ATM_DOMAIN, ATM_TAG, "Send successfully."); return Constant::SUCCESS; } @@ -461,7 +462,7 @@ std::shared_ptr SoftBusMessage::FromJson(const std::string &json } json = json.parse(jsonString, nullptr, false); if (json.is_discarded() || (!json.is_object())) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to parse jsonString"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to parse jsonString"); return nullptr; } @@ -482,7 +483,7 @@ std::shared_ptr SoftBusMessage::FromJson(const std::string &json json.at("jsonPayload").get_to(jsonPayload); } if (type.empty() || id.empty() || commandName.empty() || jsonPayload.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to get json string(json format error)"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to get json string(json format error)"); return nullptr; } std::shared_ptr message = std::make_shared(type, id, commandName, jsonPayload); diff --git a/services/tokensyncmanager/src/remote/soft_bus_device_connection_listener.cpp b/services/tokensyncmanager/src/remote/soft_bus_device_connection_listener.cpp index a85249845f93c7f2ee49912e0f347e6c248efe1d..67b5ac949b7f0ef263711665f12ac299834e0c09 100644 --- a/services/tokensyncmanager/src/remote/soft_bus_device_connection_listener.cpp +++ b/services/tokensyncmanager/src/remote/soft_bus_device_connection_listener.cpp @@ -29,19 +29,15 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "SoftBusDeviceConnectionListener"}; +constexpr const char* ACCESSTOKEN_PACKAGE_NAME = "ohos.security.distributed_access_token"; } - -const std::string ACCESSTOKEN_PACKAGE_NAME = "ohos.security.distributed_access_token"; - SoftBusDeviceConnectionListener::SoftBusDeviceConnectionListener() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "SoftBusDeviceConnectionListener()"); + LOGD(ATM_DOMAIN, ATM_TAG, "SoftBusDeviceConnectionListener()"); } SoftBusDeviceConnectionListener::~SoftBusDeviceConnectionListener() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "~SoftBusDeviceConnectionListener()"); + LOGD(ATM_DOMAIN, ATM_TAG, "~SoftBusDeviceConnectionListener()"); } void SoftBusDeviceConnectionListener::OnDeviceOnline(const DistributedHardware::DmDeviceInfo &info) @@ -50,7 +46,7 @@ void SoftBusDeviceConnectionListener::OnDeviceOnline(const DistributedHardware:: std::string uuid = SoftBusManager::GetInstance().GetUniversallyUniqueIdByNodeId(networkId); std::string udid = SoftBusManager::GetInstance().GetUniqueDeviceIdByNodeId(networkId); - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "networkId: %{public}s, uuid: %{public}s, udid: %{public}s", ConstantCommon::EncryptDevId(networkId).c_str(), ConstantCommon::EncryptDevId(uuid).c_str(), @@ -61,7 +57,7 @@ void SoftBusDeviceConnectionListener::OnDeviceOnline(const DistributedHardware:: networkId, uuid, udid, info.deviceName, std::to_string(info.deviceTypeId)); RemoteCommandManager::GetInstance().NotifyDeviceOnline(udid); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Uuid or udid is empty, online failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Uuid or udid is empty, online failed."); } // no need to load local permissions by now. } @@ -70,12 +66,12 @@ void SoftBusDeviceConnectionListener::UnloadTokensyncService() { auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get samgr failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Get samgr failed."); return ; } int32_t ret = samgr->UnloadSystemAbility(TOKEN_SYNC_MANAGER_SERVICE_ID); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Remove system ability failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Remove system ability failed."); } } @@ -85,11 +81,11 @@ void SoftBusDeviceConnectionListener::OnDeviceOffline(const DistributedHardware: std::string uuid = DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(networkId); std::string udid = DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(networkId); if ((uuid == "") || (udid == "")) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Uuid or udid is empty, offline failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Uuid or udid is empty, offline failed."); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "NetworkId: %{public}s, uuid: %{public}s, udid: %{public}s.", + LOGI(ATM_DOMAIN, ATM_TAG, "NetworkId: %{public}s, uuid: %{public}s, udid: %{public}s.", ConstantCommon::EncryptDevId(networkId).c_str(), ConstantCommon::EncryptDevId(uuid).c_str(), ConstantCommon::EncryptDevId(udid).c_str()); @@ -105,12 +101,12 @@ void SoftBusDeviceConnectionListener::OnDeviceOffline(const DistributedHardware: int32_t ret = DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(packageName, extra, deviceList); if (ret != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetTrustedDeviceList error, result: %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "GetTrustedDeviceList error, result: %{public}d", ret); return; } if (deviceList.empty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "There is no remote decice online, exit tokensync process"); + LOGI(ATM_DOMAIN, ATM_TAG, "There is no remote decice online, exit tokensync process"); UnloadTokensyncService(); } @@ -119,13 +115,13 @@ void SoftBusDeviceConnectionListener::OnDeviceOffline(const DistributedHardware: void SoftBusDeviceConnectionListener::OnDeviceReady(const DistributedHardware::DmDeviceInfo &info) { std::string networkId = std::string(info.networkId); - ACCESSTOKEN_LOG_INFO(LABEL, "NetworkId: %{public}s", ConstantCommon::EncryptDevId(networkId).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "NetworkId: %{public}s", ConstantCommon::EncryptDevId(networkId).c_str()); } void SoftBusDeviceConnectionListener::OnDeviceChanged(const DistributedHardware::DmDeviceInfo &info) { std::string networkId = std::string(info.networkId); - ACCESSTOKEN_LOG_INFO(LABEL, "NetworkId: %{public}s", ConstantCommon::EncryptDevId(networkId).c_str()); + LOGI(ATM_DOMAIN, ATM_TAG, "NetworkId: %{public}s", ConstantCommon::EncryptDevId(networkId).c_str()); } } // namespace AccessToken } // namespace Security diff --git a/services/tokensyncmanager/src/remote/soft_bus_manager.cpp b/services/tokensyncmanager/src/remote/soft_bus_manager.cpp index 512e1a56d2009c642a1b5e2fe092e10e67daedb5..5e54ffaeb9f8eca04e52c9af7669e6284f58c59f 100644 --- a/services/tokensyncmanager/src/remote/soft_bus_manager.cpp +++ b/services/tokensyncmanager/src/remote/soft_bus_manager.cpp @@ -35,14 +35,12 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "SoftBusManager"}; static constexpr int32_t DEFAULT_SEND_REQUEST_REPEAT_TIMES = 5; -} -namespace { static const int MAX_PTHREAD_NAME_LEN = 15; // pthread name max length -static const std::string TOKEN_SYNC_PACKAGE_NAME = "ohos.security.distributed_access_token"; -static const std::string TOKEN_SYNC_SOCKET_NAME = "ohos.security.atm_channel."; +constexpr const char* TOKEN_SYNC_PACKAGE_NAME = "ohos.security.distributed_access_token"; +constexpr const char* TOKEN_SYNC_SOCKET_NAME = "ohos.security.atm_channel."; +constexpr const char* TOKEN_SYNC_SERVICE_NAME = "ohos.security.atm_channel.service"; static const uint32_t SOCKET_NAME_MAX_LEN = 256; static const uint32_t QOS_LEN = 3; @@ -62,12 +60,12 @@ std::recursive_mutex g_instanceMutex; SoftBusManager::SoftBusManager() : isSoftBusServiceBindSuccess_(false), inited_(false), mutex_(), fulfillMutex_() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "SoftBusManager()"); + LOGD(ATM_DOMAIN, ATM_TAG, "SoftBusManager()"); } SoftBusManager::~SoftBusManager() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "~SoftBusManager()"); + LOGD(ATM_DOMAIN, ATM_TAG, "~SoftBusManager()"); } SoftBusManager &SoftBusManager::GetInstance() @@ -92,7 +90,7 @@ int SoftBusManager::AddTrustedDeviceInfo() int32_t ret = DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(packageName, extra, deviceList); if (ret != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "AddTrustedDeviceInfo: GetTrustedDeviceList error, result: %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, " GetTrustedDeviceList error, result: %{public}d", ret); return Constant::FAILURE; } @@ -104,7 +102,8 @@ int SoftBusManager::AddTrustedDeviceInfo() DistributedHardware::DeviceManager::GetInstance().GetUdidByNetworkId(TOKEN_SYNC_PACKAGE_NAME, device.networkId, udid); if (uuid.empty() || udid.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Uuid = %{public}s, udid = %{public}s, uuid or udid is empty, abort.", + LOGE(ATM_DOMAIN, ATM_TAG, + "Uuid = %{public}s, udid = %{public}s, uuid or udid is empty, abort.", ConstantCommon::EncryptDevId(uuid).c_str(), ConstantCommon::EncryptDevId(udid).c_str()); continue; } @@ -124,13 +123,13 @@ int SoftBusManager::DeviceInit() int ret = DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(packageName, ptrDmInitCallback); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Initialize: InitDeviceManager error, result: %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Initialize: InitDeviceManager error, result: %{public}d", ret); return ret; } ret = AddTrustedDeviceInfo(); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Initialize: AddTrustedDeviceInfo error, result: %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Initialize: AddTrustedDeviceInfo error, result: %{public}d", ret); return ret; } @@ -140,7 +139,7 @@ int SoftBusManager::DeviceInit() ret = DistributedHardware::DeviceManager::GetInstance().RegisterDevStateCallback(packageName, extra, ptrDeviceStateCallback); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Initialize: RegisterDevStateCallback error, result: %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "RegisterDevStateCallback error, result: %{public}d", ret); return ret; } @@ -150,11 +149,11 @@ int SoftBusManager::DeviceInit() bool SoftBusManager::CheckAndCopyStr(char* dest, uint32_t destLen, const std::string& src) { if (destLen < src.length() + 1) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid src length"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid src length"); return false; } if (strcpy_s(dest, destLen, src.c_str()) != EOK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid src"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid src"); return false; } return true; @@ -162,9 +161,8 @@ bool SoftBusManager::CheckAndCopyStr(char* dest, uint32_t destLen, const std::st int32_t SoftBusManager::ServiceSocketInit() { - std::string serviceName = TOKEN_SYNC_SOCKET_NAME + "service"; char name[SOCKET_NAME_MAX_LEN + 1]; - if (!CheckAndCopyStr(name, SOCKET_NAME_MAX_LEN, serviceName)) { + if (!CheckAndCopyStr(name, SOCKET_NAME_MAX_LEN, TOKEN_SYNC_SERVICE_NAME)) { return ERROR_TRANSFORM_STRING_TO_CHAR; } @@ -180,11 +178,11 @@ int32_t SoftBusManager::ServiceSocketInit() }; int32_t ret = ::Socket(info); // create service socket id if (ret <= Constant::INVALID_SOCKET_FD) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Create service socket faild, ret is %{public}d.", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Create service socket faild, ret is %{public}d.", ret); return ERROR_CREATE_SOCKET_FAIL; } else { socketFd_ = ret; - ACCESSTOKEN_LOG_DEBUG(LABEL, "Create service socket[%{public}d] success.", socketFd_); + LOGD(ATM_DOMAIN, ATM_TAG, "Create service socket[%{public}d] success.", socketFd_); } // set service qos, no need to regist OnQos now, regist it @@ -201,10 +199,10 @@ int32_t SoftBusManager::ServiceSocketInit() ret = ::Listen(socketFd_, serverQos, QOS_LEN, &listener); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Create listener failed, ret is %{public}d.", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "Create listener failed, ret is %{public}d.", ret); return ERROR_CREATE_LISTENER_FAIL; } else { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Create listener success."); + LOGD(ATM_DOMAIN, ATM_TAG, "Create listener success."); } return ERR_OK; @@ -218,7 +216,7 @@ int32_t SoftBusManager::GetRepeatTimes() void SoftBusManager::SetDefaultConfigValue() { - ACCESSTOKEN_LOG_INFO(LABEL, "No config file or config file is not valid, use default values"); + LOGI(ATM_DOMAIN, ATM_TAG, "No config file or config file is not valid, use default values"); sendRequestRepeatTimes_ = DEFAULT_SEND_REQUEST_REPEAT_TIMES; } @@ -228,7 +226,7 @@ void SoftBusManager::GetConfigValue() LibraryLoader loader(CONFIG_POLICY_LIBPATH); ConfigPolicyLoaderInterface* policy = loader.GetObject(); if (policy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Dlopen libaccesstoken_config_policy failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "Dlopen libaccesstoken_config_policy failed."); return; } AccessTokenConfigValue value; @@ -239,7 +237,7 @@ void SoftBusManager::GetConfigValue() SetDefaultConfigValue(); } - ACCESSTOKEN_LOG_INFO(LABEL, "SendRequestRepeatTimes_ is %{public}d.", sendRequestRepeatTimes_); + LOGI(ATM_DOMAIN, ATM_TAG, "SendRequestRepeatTimes_ is %{public}d.", sendRequestRepeatTimes_); } void SoftBusManager::Initialize() @@ -247,7 +245,7 @@ void SoftBusManager::Initialize() bool inited = false; // cas failed means already inited. if (!inited_.compare_exchange_strong(inited, true)) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Already initialized, skip"); + LOGD(ATM_DOMAIN, ATM_TAG, "Already initialized, skip"); return; } @@ -275,22 +273,22 @@ void SoftBusManager::Initialize() std::thread initThread(runner); initThread.detach(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Initialize thread started"); + LOGD(ATM_DOMAIN, ATM_TAG, "Initialize thread started"); } void SoftBusManager::Destroy() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Destroy, init: %{public}d, isSoftBusServiceBindSuccess: %{public}d", inited_.load(), - isSoftBusServiceBindSuccess_); + LOGD(ATM_DOMAIN, ATM_TAG, + "Destroy: %{public}d, isSoftBusServiceBindSuccess: %{public}d", inited_.load(), isSoftBusServiceBindSuccess_); if (!inited_.load()) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Not inited, skip"); + LOGD(ATM_DOMAIN, ATM_TAG, "Not inited, skip"); return; } std::unique_lock lock(mutex_); if (!inited_.load()) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Not inited, skip"); + LOGD(ATM_DOMAIN, ATM_TAG, "Not inited, skip"); return; } @@ -299,11 +297,11 @@ void SoftBusManager::Destroy() ::Shutdown(socketFd_); } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Destroy service socket."); + LOGD(ATM_DOMAIN, ATM_TAG, "Destroy service socket."); SoftBusSocketListener::CleanUpAllBindSocket(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Destroy client socket."); + LOGD(ATM_DOMAIN, ATM_TAG, "Destroy client socket."); isSoftBusServiceBindSuccess_ = false; } @@ -311,16 +309,16 @@ void SoftBusManager::Destroy() std::string packageName = TOKEN_SYNC_PACKAGE_NAME; int ret = DistributedHardware::DeviceManager::GetInstance().UnRegisterDevStateCallback(packageName); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UnRegisterDevStateCallback failed, code: %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "UnRegisterDevStateCallback failed, code: %{public}d", ret); } ret = DistributedHardware::DeviceManager::GetInstance().UnInitDeviceManager(packageName); if (ret != ERR_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "UnInitDeviceManager failed, code: %{public}d", ret); + LOGE(ATM_DOMAIN, ATM_TAG, "UnInitDeviceManager failed, code: %{public}d", ret); } inited_.store(false); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Destroy, done"); + LOGD(ATM_DOMAIN, ATM_TAG, "Destroy, done"); } int32_t SoftBusManager::InitSocketAndListener(const std::string& networkId, ISocketListener& listener) @@ -331,9 +329,8 @@ int32_t SoftBusManager::InitSocketAndListener(const std::string& networkId, ISoc return ERROR_TRANSFORM_STRING_TO_CHAR; } - std::string serviceName = TOKEN_SYNC_SOCKET_NAME + "service"; char peerName[SOCKET_NAME_MAX_LEN + 1]; - if (!CheckAndCopyStr(peerName, SOCKET_NAME_MAX_LEN, serviceName)) { + if (!CheckAndCopyStr(peerName, SOCKET_NAME_MAX_LEN, TOKEN_SYNC_SERVICE_NAME)) { return ERROR_TRANSFORM_STRING_TO_CHAR; } @@ -365,13 +362,13 @@ int32_t SoftBusManager::InitSocketAndListener(const std::string& networkId, ISoc int32_t SoftBusManager::BindService(const std::string &deviceId) { #ifdef DEBUG_API_PERFORMANCE - ACCESSTOKEN_LOG_INFO(LABEL, "Api_performance:start bind service"); + LOGI(ATM_DOMAIN, ATM_TAG, "Api_performance:start bind service"); #endif DeviceInfo info; bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(deviceId, DeviceIdType::UNKNOWN, info); if (!result) { - ACCESSTOKEN_LOG_WARN(LABEL, "Device info not found for deviceId %{public}s", + LOGW(ATM_DOMAIN, ATM_TAG, "Device info not found for deviceId %{public}s", ConstantCommon::EncryptDevId(deviceId).c_str()); return Constant::FAILURE; } @@ -380,7 +377,7 @@ int32_t SoftBusManager::BindService(const std::string &deviceId) ISocketListener listener; int32_t socketFd = InitSocketAndListener(networkId, listener); if (socketFd_ <= Constant::INVALID_SOCKET_FD) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Create client socket faild."); + LOGE(ATM_DOMAIN, ATM_TAG, "Create client socket faild."); return ERROR_CREATE_SOCKET_FAIL; } @@ -390,7 +387,7 @@ int32_t SoftBusManager::BindService(const std::string &deviceId) if (iter == clientSocketMap_.end()) { clientSocketMap_.insert(std::pair(socketFd, networkId)); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Client socket has bind already"); + LOGE(ATM_DOMAIN, ATM_TAG, "Client socket has bind already"); return ERROR_CLIENT_HAS_BIND_ALREADY; } } @@ -403,7 +400,7 @@ int32_t SoftBusManager::BindService(const std::string &deviceId) AccessTokenID firstCaller = IPCSkeleton::GetFirstTokenID(); SetFirstCallerTokenID(firstCaller); - ACCESSTOKEN_LOG_INFO(LABEL, "Bind service and setFirstCaller %{public}u.", firstCaller); + LOGI(ATM_DOMAIN, ATM_TAG, "Bind service and setFirstCaller %{public}u.", firstCaller); // retry 10 times or bind success int32_t retryTimes = 0; @@ -418,14 +415,14 @@ int32_t SoftBusManager::BindService(const std::string &deviceId) break; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "Bind service succeed, socketFd is %{public}d.", socketFd); + LOGD(ATM_DOMAIN, ATM_TAG, "Bind service succeed, socketFd is %{public}d.", socketFd); return socketFd; } int SoftBusManager::CloseSocket(int socketFd) { if (socketFd <= Constant::INVALID_SOCKET_FD) { - ACCESSTOKEN_LOG_INFO(LABEL, "Socket is invalid"); + LOGI(ATM_DOMAIN, ATM_TAG, "Socket is invalid"); return Constant::FAILURE; } @@ -437,7 +434,7 @@ int SoftBusManager::CloseSocket(int socketFd) clientSocketMap_.erase(iter); } - ACCESSTOKEN_LOG_INFO(LABEL, "Close socket"); + LOGI(ATM_DOMAIN, ATM_TAG, "Close socket"); return Constant::SUCCESS; } @@ -456,21 +453,21 @@ bool SoftBusManager::GetNetworkIdBySocket(const int32_t socket, std::string& net std::string SoftBusManager::GetUniversallyUniqueIdByNodeId(const std::string &networkId) { if (!DataValidator::IsDeviceIdValid(networkId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid networkId, empty or size extends 256"); + LOGE(ATM_DOMAIN, ATM_TAG, "Invalid networkId, empty or size extends 256"); return ""; } std::string uuid; DistributedHardware::DeviceManager::GetInstance().GetUuidByNetworkId(TOKEN_SYNC_PACKAGE_NAME, networkId, uuid); if (uuid.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Softbus return null or empty string"); + LOGE(ATM_DOMAIN, ATM_TAG, "Softbus return null or empty string"); return ""; } DeviceInfo info; bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(uuid, DeviceIdType::UNIVERSALLY_UNIQUE_ID, info); if (!result) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "Local device info not found for uuid %{public}s", + LOGD(ATM_DOMAIN, ATM_TAG, "Local device info not found for uuid %{public}s", ConstantCommon::EncryptDevId(uuid).c_str()); } else { std::string dimUuid = info.deviceId.universallyUniqueId; @@ -488,13 +485,14 @@ std::string SoftBusManager::GetUniversallyUniqueIdByNodeId(const std::string &ne std::string SoftBusManager::GetUniqueDeviceIdByNodeId(const std::string &networkId) { if (!DataValidator::IsDeviceIdValid(networkId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid networkId: %{public}s", ConstantCommon::EncryptDevId(networkId).c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, + "Invalid networkId: %{public}s", ConstantCommon::EncryptDevId(networkId).c_str()); return ""; } std::string udid; DistributedHardware::DeviceManager::GetInstance().GetUdidByNetworkId(TOKEN_SYNC_PACKAGE_NAME, networkId, udid); if (udid.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Softbus return null or empty string: %{public}s", + LOGE(ATM_DOMAIN, ATM_TAG, "Softbus return null or empty string: %{public}s", ConstantCommon::EncryptDevId(udid).c_str()); return ""; } @@ -512,7 +510,7 @@ int SoftBusManager::FulfillLocalDeviceInfo() { // repeated task will just skip if (!fulfillMutex_.try_lock()) { - ACCESSTOKEN_LOG_INFO(LABEL, "FulfillLocalDeviceInfo already running, skip."); + LOGI(ATM_DOMAIN, ATM_TAG, "FulfillLocalDeviceInfo already running, skip."); return Constant::SUCCESS; } @@ -520,13 +518,13 @@ int SoftBusManager::FulfillLocalDeviceInfo() int32_t res = DistributedHardware::DeviceManager::GetInstance().GetLocalDeviceInfo(TOKEN_SYNC_PACKAGE_NAME, deviceInfo); if (res != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetLocalDeviceInfo error"); + LOGE(ATM_DOMAIN, ATM_TAG, "GetLocalDeviceInfo error"); fulfillMutex_.unlock(); return Constant::FAILURE; } std::string networkId = std::string(deviceInfo.networkId); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Call softbus finished, type:%{public}d", deviceInfo.deviceTypeId); + LOGD(ATM_DOMAIN, ATM_TAG, "Call softbus finished, type:%{public}d", deviceInfo.deviceTypeId); std::string uuid; std::string udid; @@ -534,14 +532,14 @@ int SoftBusManager::FulfillLocalDeviceInfo() DistributedHardware::DeviceManager::GetInstance().GetUuidByNetworkId(TOKEN_SYNC_PACKAGE_NAME, networkId, uuid); DistributedHardware::DeviceManager::GetInstance().GetUdidByNetworkId(TOKEN_SYNC_PACKAGE_NAME, networkId, udid); if (uuid.empty() || udid.empty()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "FulfillLocalDeviceInfo: uuid or udid is empty, abort."); + LOGE(ATM_DOMAIN, ATM_TAG, "FulfillLocalDeviceInfo: uuid or udid is empty, abort."); fulfillMutex_.unlock(); return Constant::FAILURE; } DeviceInfoManager::GetInstance().AddDeviceInfo(networkId, uuid, udid, std::string(deviceInfo.deviceName), std::to_string(deviceInfo.deviceTypeId)); - ACCESSTOKEN_LOG_DEBUG(LABEL, "AddDeviceInfo finished"); + LOGD(ATM_DOMAIN, ATM_TAG, "AddDeviceInfo finished"); fulfillMutex_.unlock(); return Constant::SUCCESS; diff --git a/services/tokensyncmanager/src/remote/soft_bus_socket_listener.cpp b/services/tokensyncmanager/src/remote/soft_bus_socket_listener.cpp index 86af56e93bf20a1a8fa8db271aece1d6dd5b6f55..0f83f0bf4092b7e1707ecef62b729cf4c86c4b40 100644 --- a/services/tokensyncmanager/src/remote/soft_bus_socket_listener.cpp +++ b/services/tokensyncmanager/src/remote/soft_bus_socket_listener.cpp @@ -25,21 +25,17 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "SoftBusSocketListener"}; -} -namespace { static const int32_t MAX_ONBYTES_RECEIVED_DATA_LEN = 1024 * 1024 * 10; } // namespace - std::mutex SoftBusSocketListener::socketMutex_; std::map SoftBusSocketListener::socketBindMap_; void SoftBusSocketListener::OnBind(int32_t socket, PeerSocketInfo info) { - ACCESSTOKEN_LOG_INFO(LABEL, "Socket fd is %{public}d.", socket); + LOGI(ATM_DOMAIN, ATM_TAG, "Socket fd is %{public}d.", socket); if (socket <= Constant::INVALID_SOCKET_FD) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Socket fd invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Socket fd invalid."); return; } @@ -55,10 +51,10 @@ void SoftBusSocketListener::OnBind(int32_t socket, PeerSocketInfo info) void SoftBusSocketListener::OnShutdown(int32_t socket, ShutdownReason reason) { - ACCESSTOKEN_LOG_INFO(LABEL, "Socket fd %{public}d shutdown because %{public}u.", socket, reason); + LOGI(ATM_DOMAIN, ATM_TAG, "Socket fd %{public}d shutdown because %{public}u.", socket, reason); if (socket <= Constant::INVALID_SOCKET_FD) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Socket fd invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Socket fd invalid."); return; } @@ -73,7 +69,7 @@ void SoftBusSocketListener::OnShutdown(int32_t socket, ShutdownReason reason) bool SoftBusSocketListener::GetNetworkIdBySocket(const int32_t socket, std::string& networkId) { if (socket <= Constant::INVALID_SOCKET_FD) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Socket fd invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Socket fd invalid."); return false; } @@ -88,24 +84,24 @@ bool SoftBusSocketListener::GetNetworkIdBySocket(const int32_t socket, std::stri void SoftBusSocketListener::OnClientBytes(int32_t socket, const void *data, uint32_t dataLen) { - ACCESSTOKEN_LOG_INFO(LABEL, "Socket fd %{public}d, recv len %{public}d.", socket, dataLen); + LOGI(ATM_DOMAIN, ATM_TAG, "Socket fd %{public}d, recv len %{public}d.", socket, dataLen); if ((socket <= Constant::INVALID_SOCKET_FD) || (data == nullptr) || (dataLen == 0) || (dataLen > MAX_ONBYTES_RECEIVED_DATA_LEN)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Params invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Params invalid."); return; } std::string networkId; if (!GetNetworkIdBySocket(socket, networkId)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Socket invalid, bind service first."); + LOGE(ATM_DOMAIN, ATM_TAG, "Socket invalid, bind service first."); return; } // channel create in SoftBusDeviceConnectionListener::OnDeviceOnline->RemoteCommandManager::NotifyDeviceOnline auto channel = RemoteCommandManager::GetInstance().GetExecutorChannel(networkId); if (channel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetExecutorChannel failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "GetExecutorChannel failed"); return; } channel->HandleDataReceived(socket, static_cast(const_cast(data)), dataLen); @@ -113,11 +109,11 @@ void SoftBusSocketListener::OnClientBytes(int32_t socket, const void *data, uint void SoftBusSocketListener::OnServiceBytes(int32_t socket, const void *data, uint32_t dataLen) { - ACCESSTOKEN_LOG_INFO(LABEL, "Socket fd %{public}d, recv len %{public}d.", socket, dataLen); + LOGI(ATM_DOMAIN, ATM_TAG, "Socket fd %{public}d, recv len %{public}d.", socket, dataLen); if ((socket <= Constant::INVALID_SOCKET_FD) || (data == nullptr) || (dataLen == 0) || (dataLen > MAX_ONBYTES_RECEIVED_DATA_LEN)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Params invalid."); + LOGE(ATM_DOMAIN, ATM_TAG, "Params invalid."); return; } @@ -126,12 +122,12 @@ void SoftBusSocketListener::OnServiceBytes(int32_t socket, const void *data, uin // channel create in SoftBusDeviceConnectionListener::OnDeviceOnline->RemoteCommandManager::NotifyDeviceOnline auto channel = RemoteCommandManager::GetInstance().GetExecutorChannel(networkId); if (channel == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetExecutorChannel failed"); + LOGE(ATM_DOMAIN, ATM_TAG, "GetExecutorChannel failed"); return; } channel->HandleDataReceived(socket, static_cast(const_cast(data)), dataLen); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "Unkonow socket."); + LOGE(ATM_DOMAIN, ATM_TAG, "Unkonow socket."); } } diff --git a/services/tokensyncmanager/src/service/token_sync_manager_service.cpp b/services/tokensyncmanager/src/service/token_sync_manager_service.cpp index 769238dc0db80cb896be9d0ebff5970391bfd117..0acd1d4f983fecfee85a95b2a5d565438431af3a 100644 --- a/services/tokensyncmanager/src/service/token_sync_manager_service.cpp +++ b/services/tokensyncmanager/src/service/token_sync_manager_service.cpp @@ -29,47 +29,45 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TokenSyncManagerService"}; -} - const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); +} TokenSyncManagerService::TokenSyncManagerService() : SystemAbility(SA_ID_TOKENSYNC_MANAGER_SERVICE, false), state_(ServiceRunningState::STATE_NOT_START) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenSyncManagerService()"); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenSyncManagerService()"); } TokenSyncManagerService::~TokenSyncManagerService() { - ACCESSTOKEN_LOG_INFO(LABEL, "~TokenSyncManagerService()"); + LOGI(ATM_DOMAIN, ATM_TAG, "~TokenSyncManagerService()"); } void TokenSyncManagerService::OnStart() { if (state_ == ServiceRunningState::STATE_RUNNING) { - ACCESSTOKEN_LOG_INFO(LABEL, "TokenSyncManagerService has already started!"); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenSyncManagerService has already started!"); return; } - ACCESSTOKEN_LOG_INFO(LABEL, "TokenSyncManagerService is starting"); + LOGI(ATM_DOMAIN, ATM_TAG, "TokenSyncManagerService is starting"); if (!Initialize()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to initialize"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to initialize"); return; } state_ = ServiceRunningState::STATE_RUNNING; bool ret = Publish(DelayedSingleton::GetInstance().get()); if (!ret) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to publish service!"); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to publish service!"); return; } (void)AddSystemAbilityListener(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); - ACCESSTOKEN_LOG_INFO(LABEL, "Congratulations, TokenSyncManagerService start successfully!"); + LOGI(ATM_DOMAIN, ATM_TAG, "Congratulations, TokenSyncManagerService start successfully!"); } void TokenSyncManagerService::OnStop() { - ACCESSTOKEN_LOG_INFO(LABEL, "Stop service"); + LOGI(ATM_DOMAIN, ATM_TAG, "Stop service"); state_ = ServiceRunningState::STATE_NOT_START; SoftBusManager::GetInstance().Destroy(); } @@ -96,13 +94,13 @@ std::shared_ptr TokenSyncManagerService::GetRecvEventHandler int TokenSyncManagerService::GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) { if (!DataValidator::IsDeviceIdValid(deviceID) || tokenID == 0) { - ACCESSTOKEN_LOG_INFO(LABEL, "Params is wrong."); + LOGI(ATM_DOMAIN, ATM_TAG, "Params is wrong."); return TOKEN_SYNC_PARAMS_INVALID; } DeviceInfo devInfo; bool result = DeviceInfoRepository::GetInstance().FindDeviceInfo(deviceID, DeviceIdType::UNKNOWN, devInfo); if (!result) { - ACCESSTOKEN_LOG_INFO(LABEL, "FindDeviceInfo failed"); + LOGI(ATM_DOMAIN, ATM_TAG, "FindDeviceInfo failed"); return TOKEN_SYNC_REMOTE_DEVICE_INVALID; } std::string udid = devInfo.deviceId.uniqueDeviceId; @@ -112,18 +110,18 @@ int TokenSyncManagerService::GetRemoteHapTokenInfo(const std::string& deviceID, const int32_t resultCode = RemoteCommandManager::GetInstance().ExecuteCommand(udid, syncRemoteHapTokenCommand); if (resultCode != Constant::SUCCESS) { - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "RemoteExecutorManager executeCommand SyncRemoteHapTokenCommand failed, return %{public}d", resultCode); return TOKEN_SYNC_COMMAND_EXECUTE_FAILED; } - ACCESSTOKEN_LOG_INFO(LABEL, "Get resultCode: %{public}d", resultCode); + LOGI(ATM_DOMAIN, ATM_TAG, "Get resultCode: %{public}d", resultCode); return TOKEN_SYNC_SUCCESS; } int TokenSyncManagerService::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) { if (tokenID == 0) { - ACCESSTOKEN_LOG_INFO(LABEL, "Params is wrong, token id is invalid."); + LOGI(ATM_DOMAIN, ATM_TAG, "Params is wrong, token id is invalid."); return TOKEN_SYNC_PARAMS_INVALID; } @@ -131,7 +129,7 @@ int TokenSyncManagerService::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) std::string localUdid = ConstantCommon::GetLocalDeviceId(); for (const DeviceInfo& device : devices) { if (device.deviceId.uniqueDeviceId == localUdid) { - ACCESSTOKEN_LOG_INFO(LABEL, "No need notify local device"); + LOGI(ATM_DOMAIN, ATM_TAG, "No need notify local device"); continue; } const std::shared_ptr deleteRemoteTokenCommand = @@ -141,11 +139,11 @@ int TokenSyncManagerService::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) const int32_t resultCode = RemoteCommandManager::GetInstance().ExecuteCommand( device.deviceId.uniqueDeviceId, deleteRemoteTokenCommand); if (resultCode != Constant::SUCCESS) { - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "RemoteExecutorManager executeCommand DeleteRemoteTokenCommand failed, return %{public}d", resultCode); continue; } - ACCESSTOKEN_LOG_INFO(LABEL, "Get resultCode: %{public}d", resultCode); + LOGI(ATM_DOMAIN, ATM_TAG, "Get resultCode: %{public}d", resultCode); } return TOKEN_SYNC_SUCCESS; } @@ -156,7 +154,7 @@ int TokenSyncManagerService::UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& std::string localUdid = ConstantCommon::GetLocalDeviceId(); for (const DeviceInfo& device : devices) { if (device.deviceId.uniqueDeviceId == localUdid) { - ACCESSTOKEN_LOG_INFO(LABEL, "No need notify local device"); + LOGI(ATM_DOMAIN, ATM_TAG, "No need notify local device"); continue; } @@ -167,12 +165,12 @@ int TokenSyncManagerService::UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& const int32_t resultCode = RemoteCommandManager::GetInstance().ExecuteCommand( device.deviceId.uniqueDeviceId, updateRemoteHapTokenCommand); if (resultCode != Constant::SUCCESS) { - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "RemoteExecutorManager executeCommand updateRemoteHapTokenCommand failed, return %{public}d", resultCode); continue; } - ACCESSTOKEN_LOG_INFO(LABEL, "Get resultCode: %{public}d", resultCode); + LOGI(ATM_DOMAIN, ATM_TAG, "Get resultCode: %{public}d", resultCode); } return TOKEN_SYNC_SUCCESS; @@ -183,14 +181,14 @@ bool TokenSyncManagerService::Initialize() #ifdef EVENTHANDLER_ENABLE sendRunner_ = AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT); if (!sendRunner_) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create a sendRunner."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create a sendRunner."); return false; } sendHandler_ = std::make_shared(sendRunner_); recvRunner_ = AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT); if (!recvRunner_) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to create a recvRunner."); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to create a recvRunner."); return false; } diff --git a/services/tokensyncmanager/src/service/token_sync_manager_stub.cpp b/services/tokensyncmanager/src/service/token_sync_manager_stub.cpp index 3b37f4dcfadc8301c9c56700384f9390d261964e..0503c0cdc76b72895eac0186317195f0466f353d 100644 --- a/services/tokensyncmanager/src/service/token_sync_manager_stub.cpp +++ b/services/tokensyncmanager/src/service/token_sync_manager_stub.cpp @@ -25,7 +25,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TokenSyncManagerStub"}; #ifndef ATM_BUILD_VARIANT_USER_ENABLE static const int32_t ROOT_UID = 0; #endif @@ -34,10 +33,10 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ int32_t TokenSyncManagerStub::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called, code: %{public}d", __func__, code); + LOGI(ATM_DOMAIN, ATM_TAG, "%{public}s called, code: %{public}d", __func__, code); std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != ITokenSyncManager::GetDescriptor()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); + LOGE(ATM_DOMAIN, ATM_TAG, "Unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); return ERROR_IPC_REQUEST_FAIL; } switch (code) { @@ -60,7 +59,7 @@ bool TokenSyncManagerStub::IsNativeProcessCalling() const { AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); uint32_t type = (reinterpret_cast(&tokenCaller))->type; - ACCESSTOKEN_LOG_DEBUG(LABEL, "Calling type: %{public}d", type); + LOGD(ATM_DOMAIN, ATM_TAG, "Calling type: %{public}d", type); return type == TOKEN_NATIVE; } @@ -68,7 +67,7 @@ bool TokenSyncManagerStub::IsRootCalling() const { #ifndef ATM_BUILD_VARIANT_USER_ENABLE int callingUid = IPCSkeleton::GetCallingUid(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "Calling uid: %{public}d", callingUid); + LOGD(ATM_DOMAIN, ATM_TAG, "Calling uid: %{public}d", callingUid); return callingUid == ROOT_UID; #else return false; @@ -78,7 +77,7 @@ bool TokenSyncManagerStub::IsRootCalling() const void TokenSyncManagerStub::GetRemoteHapTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsRootCalling() && !IsNativeProcessCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s called, permission denied", __func__); + LOGE(ATM_DOMAIN, ATM_TAG, "%{public}s called, permission denied", __func__); reply.WriteInt32(ERR_IDENTITY_CHECK_FAILED); return; } @@ -94,7 +93,7 @@ void TokenSyncManagerStub::GetRemoteHapTokenInfoInner(MessageParcel& data, Messa void TokenSyncManagerStub::DeleteRemoteHapTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsRootCalling() && !IsNativeProcessCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s called, permission denied", __func__); + LOGE(ATM_DOMAIN, ATM_TAG, "%{public}s called, permission denied", __func__); reply.WriteInt32(ERR_IDENTITY_CHECK_FAILED); return; } @@ -106,7 +105,7 @@ void TokenSyncManagerStub::DeleteRemoteHapTokenInfoInner(MessageParcel& data, Me void TokenSyncManagerStub::UpdateRemoteHapTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsRootCalling() && !IsNativeProcessCalling()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s called, permission denied", __func__); + LOGE(ATM_DOMAIN, ATM_TAG, "%{public}s called, permission denied", __func__); reply.WriteInt32(ERR_IDENTITY_CHECK_FAILED); return; } diff --git a/services/tokensyncmanager/test/coverage/token_sync_service_coverage_test.cpp b/services/tokensyncmanager/test/coverage/token_sync_service_coverage_test.cpp index 33bdc35d887dac3f138192a2af8e49d17a6fb596..0055d555a298cea3017ab80df9bd647fb6d3ba4d 100644 --- a/services/tokensyncmanager/test/coverage/token_sync_service_coverage_test.cpp +++ b/services/tokensyncmanager/test/coverage/token_sync_service_coverage_test.cpp @@ -55,8 +55,6 @@ namespace OHOS { namespace Security { namespace AccessToken { namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TokenSyncServiceTest"}; - static DistributedHardware::DmDeviceInfo g_devInfo = { // udid = deviceid-1:udid-001 uuid = deviceid-1:uuid-001 .deviceId = "deviceid-1", @@ -115,7 +113,7 @@ void TokenSyncServiceTest::SetUp() } void TokenSyncServiceTest::TearDown() { - ACCESSTOKEN_LOG_INFO(LABEL, "TearDown start."); + LOGI(ATM_DOMAIN, ATM_TAG, "TearDown start."); tokenSyncManagerService_ = nullptr; for (auto it = threads_.begin(); it != threads_.end(); it++) { it->join(); @@ -134,7 +132,7 @@ void TokenSyncServiceTest::OnDeviceOffline(const DistributedHardware::DmDeviceIn std::string uuid = DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(networkId); std::string udid = DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(networkId); - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "networkId: %{public}s, uuid: %{public}s, udid: %{public}s", networkId.c_str(), uuid.c_str(), @@ -145,7 +143,7 @@ void TokenSyncServiceTest::OnDeviceOffline(const DistributedHardware::DmDeviceIn RemoteCommandManager::GetInstance().NotifyDeviceOffline(udid); DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(networkId, DeviceIdType::NETWORK_ID); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "uuid or udid is empty, offline failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "uuid or udid is empty, offline failed."); } } diff --git a/services/tokensyncmanager/test/mock/src/constant_mock.cpp b/services/tokensyncmanager/test/mock/src/constant_mock.cpp index 9c61d5f6764d82bd27d186801bac49800429a8cd..ae67df32a004ee0999414b69cf60f680f4246cd1 100644 --- a/services/tokensyncmanager/test/mock/src/constant_mock.cpp +++ b/services/tokensyncmanager/test/mock/src/constant_mock.cpp @@ -21,8 +21,6 @@ namespace AccessToken { namespace { static const std::string REPLACE_TARGET = "****"; } // namespace -const std::string Constant::COMMAND_RESULT_SUCCESS = "success"; -const std::string Constant::COMMAND_RESULT_FAILED = "execute command failed"; const int32_t Constant::SUCCESS; const int32_t Constant::FAILURE; diff --git a/services/tokensyncmanager/test/mock/src/soft_bus_socket_mock.cpp b/services/tokensyncmanager/test/mock/src/soft_bus_socket_mock.cpp index 955800a8707a334c037e97c9ad7ab77836e6ae40..a24b600661050550110e7f5ddd0e0589eac20c81 100644 --- a/services/tokensyncmanager/test/mock/src/soft_bus_socket_mock.cpp +++ b/services/tokensyncmanager/test/mock/src/soft_bus_socket_mock.cpp @@ -22,7 +22,6 @@ using namespace OHOS::Security::AccessToken; namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "SoftBusSocketMock"}; static const int SERVER_COUNT_LIMIT = 10; static int g_serverCount = -1; static bool g_sendMessFlag = false; @@ -38,7 +37,7 @@ bool IsServerCountOK() int SendBytes(int sessionId, const void *data, unsigned int len) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "len: %{public}d", len); + LOGD(ATM_DOMAIN, ATM_TAG, "len: %{public}d", len); if (sessionId == Constant::INVALID_SESSION) { return Constant::FAILURE; } @@ -49,17 +48,17 @@ int SendBytes(int sessionId, const void *data, unsigned int len) void DecompressMock(const unsigned char *bytes, const int length) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "input length: %{public}d", length); + LOGD(ATM_DOMAIN, ATM_TAG, "input length: %{public}d", length); uLong len = 1048576; unsigned char *buf = static_cast(malloc(len + 1)); if (buf == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "no enough memory!"); + LOGE(ATM_DOMAIN, ATM_TAG, "no enough memory!"); return; } (void)memset_s(buf, len + 1, 0, len + 1); int result = uncompress(buf, &len, const_cast(bytes), length); if (result != Z_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "uncompress failed, error code: %{public}d, bound length: %{public}d, buffer length: %{public}d", result, static_cast(len), length); free(buf); @@ -68,13 +67,13 @@ void DecompressMock(const unsigned char *bytes, const int length) buf[len] = '\0'; std::string str(reinterpret_cast(buf)); free(buf); - ACCESSTOKEN_LOG_DEBUG(LABEL, "done, output: %{public}s", str.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "done, output: %{public}s", str.c_str()); std::size_t id_post = str.find("\"id\":"); std::string id_string = str.substr(id_post + 6, 9); g_uuid = id_string; - ACCESSTOKEN_LOG_DEBUG(LABEL, "id_string: %{public}s", id_string.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "id_string: %{public}s", id_string.c_str()); return; } @@ -83,7 +82,7 @@ void CompressMock(const std::string &json, const unsigned char *compressedBytes, uLong len = compressBound(json.size()); // length will not so that long if (compressedLength > 0 && (int) len > compressedLength) { - ACCESSTOKEN_LOG_ERROR(LABEL, + LOGE(ATM_DOMAIN, ATM_TAG, "compress error. data length overflow, bound length: %{public}d, buffer length: %{public}d", (int) len, compressedLength); return ; @@ -92,18 +91,18 @@ void CompressMock(const std::string &json, const unsigned char *compressedBytes, int result = compress(const_cast(compressedBytes), &len, reinterpret_cast(const_cast(json.c_str())), json.size() + 1); if (result != Z_OK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "compress failed! error code: %{public}d", result); + LOGE(ATM_DOMAIN, ATM_TAG, "compress failed! error code: %{public}d", result); return; } - ACCESSTOKEN_LOG_DEBUG(LABEL, "compress complete. compress %{public}d bytes to %{public}d", compressedLength, - (int) len); + LOGD(ATM_DOMAIN, ATM_TAG, + "compress complete. compress %{public}d bytes to %{public}d", compressedLength, (int) len); compressedLength = len; return ; } std::string GetUuidMock() { - ACCESSTOKEN_LOG_DEBUG(LABEL, "GetUuidMock called uuid: %{public}s", g_uuid.c_str()); + LOGD(ATM_DOMAIN, ATM_TAG, "GetUuidMock called uuid: %{public}s", g_uuid.c_str()); return g_uuid; } diff --git a/services/tokensyncmanager/test/unittest/token_sync_service_test.cpp b/services/tokensyncmanager/test/unittest/token_sync_service_test.cpp index 627cb992d9748c96e31e10e9b5f99055c8a41298..21e596f8f618023c2be8377c6ddbdf0045b78362 100644 --- a/services/tokensyncmanager/test/unittest/token_sync_service_test.cpp +++ b/services/tokensyncmanager/test/unittest/token_sync_service_test.cpp @@ -84,7 +84,6 @@ static DistributedHardware::DmDeviceInfo g_devInfo = { }; namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "TokenSyncServiceTest"}; static constexpr int MAX_RETRY_TIMES = 10; static constexpr int32_t DEVICEID_MAX_LEN = 256; } @@ -119,7 +118,7 @@ void TokenSyncServiceTest::SetUp() } void TokenSyncServiceTest::TearDown() { - ACCESSTOKEN_LOG_INFO(LABEL, "TearDown start."); + LOGI(ATM_DOMAIN, ATM_TAG, "TearDown start."); tokenSyncManagerService_ = nullptr; for (auto it = threads_.begin(); it != threads_.end(); it++) { it->join(); @@ -138,7 +137,7 @@ void TokenSyncServiceTest::OnDeviceOffline(const DistributedHardware::DmDeviceIn std::string uuid = DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(networkId); std::string udid = DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(networkId); - ACCESSTOKEN_LOG_INFO(LABEL, + LOGI(ATM_DOMAIN, ATM_TAG, "networkId: %{public}s, uuid: %{public}s, udid: %{public}s", networkId.c_str(), uuid.c_str(), @@ -149,7 +148,7 @@ void TokenSyncServiceTest::OnDeviceOffline(const DistributedHardware::DmDeviceIn RemoteCommandManager::GetInstance().NotifyDeviceOffline(udid); DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(networkId, DeviceIdType::NETWORK_ID); } else { - ACCESSTOKEN_LOG_ERROR(LABEL, "uuid or udid is empty, offline failed."); + LOGE(ATM_DOMAIN, ATM_TAG, "uuid or udid is empty, offline failed."); } } @@ -590,7 +589,7 @@ HWTEST_F(TokenSyncServiceTest, FromPermStateListJson002, TestSize.Level1) */ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo002, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo002 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo002 start."); ResetUuidMock(); @@ -645,7 +644,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo002, TestSize.Level1) */ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo003, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo003 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo003 start."); g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\""; // apl is error g_jsonAfter = @@ -677,7 +676,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo003, TestSize.Level1) */ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo004, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo004 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo004 start."); g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\""; // lost tokenID g_jsonAfter = @@ -709,7 +708,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo004, TestSize.Level1) */ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo005, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo005 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo005 start."); g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\""; // instIndex is not number g_jsonAfter = @@ -742,7 +741,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo005, TestSize.Level1) */ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo006, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo006 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo006 start."); g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\""; // mock_token_sync lost \\\" g_jsonAfter = @@ -776,7 +775,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo006, TestSize.Level1) */ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo007, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo007 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo007 start."); g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\""; // statusCode error g_jsonAfter = @@ -809,7 +808,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo007, TestSize.Level1) */ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo008, TestSize.Level1) { - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo008 start."); + LOGI(ATM_DOMAIN, ATM_TAG, "GetRemoteHapTokenInfo008 start."); // create local token AccessTokenID tokenID = AccessTokenKit::GetHapTokenID(g_infoManagerTestInfoParms.userID, g_infoManagerTestInfoParms.bundleName, diff --git a/test/fuzztest/services/accesstoken/access_token_service_fuzz.gni b/test/fuzztest/services/accesstoken/access_token_service_fuzz.gni index 911d538344da0aeb3af541509d90edac30941e5a..1adea2e87444d8e794dccf5e888cd9116fb371e0 100644 --- a/test/fuzztest/services/accesstoken/access_token_service_fuzz.gni +++ b/test/fuzztest/services/accesstoken/access_token_service_fuzz.gni @@ -83,7 +83,6 @@ access_token_sources = [ "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/access_token_db_util.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/access_token_open_callback.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/data_translator.cpp", - "${access_token_path}/services/accesstokenmanager/main/cpp/src/database/token_field_const.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/form_manager/form_instance.cpp", "${access_token_path}/services/accesstokenmanager/main/cpp/src/form_manager/form_manager_access_client.cpp", @@ -114,7 +113,6 @@ token_sync_sources = [ "${access_token_path}/services/tokensyncmanager/src/command/delete_remote_token_command.cpp", "${access_token_path}/services/tokensyncmanager/src/command/sync_remote_hap_token_command.cpp", "${access_token_path}/services/tokensyncmanager/src/command/update_remote_hap_token_command.cpp", - "${access_token_path}/services/tokensyncmanager/src/common/constant.cpp", "${access_token_path}/services/tokensyncmanager/src/device/device_info_manager.cpp", "${access_token_path}/services/tokensyncmanager/src/device/device_info_repository.cpp", "${access_token_path}/services/tokensyncmanager/src/remote/remote_command_executor.cpp", diff --git a/test/fuzztest/services/privacy/privacy_service_fuzz.gni b/test/fuzztest/services/privacy/privacy_service_fuzz.gni index f1c1eead44a6c1f6939a932efd1fb45a00d1d97c..d10d8daabe7654a832561c3a0f89877911d4e6fe 100644 --- a/test/fuzztest/services/privacy/privacy_service_fuzz.gni +++ b/test/fuzztest/services/privacy/privacy_service_fuzz.gni @@ -75,7 +75,6 @@ privacy_sources = [ "${access_token_path}/services/privacymanager/src/common/constant.cpp", "${access_token_path}/services/privacymanager/src/database/data_translator.cpp", "${access_token_path}/services/privacymanager/src/database/permission_used_record_db.cpp", - "${access_token_path}/services/privacymanager/src/database/privacy_field_const.cpp", "${access_token_path}/services/privacymanager/src/record/on_permission_used_record_callback_proxy.cpp", "${access_token_path}/services/privacymanager/src/record/permission_record.cpp", "${access_token_path}/services/privacymanager/src/record/permission_record_manager.cpp",