diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index bed7e60ec3..78af526f5c 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -31,6 +31,7 @@ #include "singleton.h" #include "app_mgr_client.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" namespace OHOS { @@ -94,7 +95,7 @@ bool AppfreezeManager::IsHandleAppfreeze(const std::string& bundleName) int AppfreezeManager::AppfreezeHandle(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo) { - HILOG_DEBUG("called %{public}s, bundleName %{public}s, name_ %{public}s", + TAG_LOGD(AAFwkTag::APPDFR, "called %{public}s, bundleName %{public}s, name_ %{public}s", faultData.errorObject.name.c_str(), appInfo.bundleName.c_str(), name_.c_str()); if (!IsHandleAppfreeze(appInfo.bundleName)) { return -1; @@ -111,7 +112,7 @@ int AppfreezeManager::AppfreezeHandle(const FaultData& faultData, const Appfreez int AppfreezeManager::AppfreezeHandleWithStack(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo) { - HILOG_DEBUG("called %{public}s, bundleName %{public}s, name_ %{public}s", + TAG_LOGD(AAFwkTag::APPDFR, "called %{public}s, bundleName %{public}s, name_ %{public}s", faultData.errorObject.name.c_str(), appInfo.bundleName.c_str(), name_.c_str()); if (!IsHandleAppfreeze(appInfo.bundleName)) { return -1; @@ -152,8 +153,8 @@ int AppfreezeManager::LifecycleTimeoutHandle(const ParamInfo& info, std::unique_ info.eventName != AppFreezeType::LIFECYCLE_HALF_TIMEOUT) { return -1; } - HILOG_DEBUG("LifecycleTimeoutHandle called %{public}s, name_ %{public}s", - info.bundleName.c_str(), name_.c_str()); + TAG_LOGD(AAFwkTag::APPDFR, "LifecycleTimeoutHandle called %{public}s, name_ %{public}s", info.bundleName.c_str(), + name_.c_str()); HITRACE_METER_FMT(HITRACE_TAG_APP, "LifecycleTimeoutHandle:%{public}s bundleName:%{public}s", info.eventName.c_str(), info.bundleName.c_str()); AppFaultDataBySA faultDataSA; @@ -187,7 +188,7 @@ int AppfreezeManager::AcquireStack(const FaultData& faultData, const AppfreezeMa binderInfo += "PeerBinder pids is empty\n"; } for (auto& pidTemp : pids) { - HILOG_INFO("pidTemp pids:%{public}d", pidTemp); + TAG_LOGI(AAFwkTag::APPDFR, "pidTemp pids:%{public}d", pidTemp); if (pidTemp != pid) { std::string content = "PeerBinder catcher stacktrace for pid : " + std::to_string(pidTemp) + "\n"; content += CatcherStacktrace(pidTemp); @@ -208,7 +209,8 @@ int AppfreezeManager::NotifyANR(const FaultData& faultData, const AppfreezeManag EVENT_PROCESS_NAME, appInfo.processName, EVENT_MESSAGE, faultData.errorObject.message, EVENT_STACK, faultData.errorObject.stack, BINDER_INFO, binderInfo); - HILOG_INFO("reportEvent:%{public}s, pid:%{public}d, bundleName:%{public}s, " + TAG_LOGI(AAFwkTag::APPDFR, + "reportEvent:%{public}s, pid:%{public}d, bundleName:%{public}s, " "hisysevent write ret = %{public}d.", faultData.errorObject.name.c_str(), appInfo.pid, appInfo.bundleName.c_str(), ret); return 0; @@ -220,7 +222,7 @@ std::map> AppfreezeManager::BinderParser(std::ifstream& fin, const int decimal = 10; std::string line; bool isBinderMatchup = false; - HILOG_INFO("start"); + TAG_LOGI(AAFwkTag::APPDFR, "start"); stack += "BinderCatcher --\n\n"; while (getline(fin, line)) { stack += line + "\n"; @@ -261,14 +263,15 @@ std::map> AppfreezeManager::BinderParser(std::ifstream& fin, int serverNum = std::strtol(server.c_str(), nullptr, decimal); int clientNum = std::strtol(client.c_str(), nullptr, decimal); int waitNum = std::strtol(wait.c_str(), nullptr, decimal); - HILOG_INFO("server:%{public}d, client:%{public}d, wait:%{public}d", serverNum, clientNum, waitNum); + TAG_LOGI(AAFwkTag::APPDFR, "server:%{public}d, client:%{public}d, wait:%{public}d", serverNum, clientNum, + waitNum); binderInfo[clientNum].insert(serverNum); } if (line.find("context") != line.npos) { isBinderMatchup = true; } } - HILOG_INFO("binderInfo size: %{public}zu", binderInfo.size()); + TAG_LOGI(AAFwkTag::APPDFR, "binderInfo size: %{public}zu", binderInfo.size()); return binderInfo; } @@ -279,12 +282,12 @@ std::set AppfreezeManager::GetBinderPeerPids(std::string& stack, int pid) c std::string path = LOGGER_DEBUG_PROC_PATH; char resolvePath[PATH_MAX] = {0}; if (realpath(path.c_str(), resolvePath) == nullptr) { - HILOG_ERROR("GetBinderPeerPids realpath error"); + TAG_LOGE(AAFwkTag::APPDFR, "GetBinderPeerPids realpath error"); return pids; } fin.open(resolvePath); if (!fin.is_open()) { - HILOG_ERROR("open file failed, %{public}s.", resolvePath); + TAG_LOGE(AAFwkTag::APPDFR, "open file failed, %{public}s.", resolvePath); stack += "open file failed :" + path + "\r\n"; return pids; } @@ -299,7 +302,7 @@ std::set AppfreezeManager::GetBinderPeerPids(std::string& stack, int pid) c ParseBinderPids(binderInfo, pids, pid, 0); for (auto& each : pids) { - HILOG_DEBUG("each pids:%{public}d", each); + TAG_LOGD(AAFwkTag::APPDFR, "each pids:%{public}d", each); } return pids; } diff --git a/services/appdfr/src/application_anr_listener.cpp b/services/appdfr/src/application_anr_listener.cpp index 37d222f19e..0f8d8c2303 100644 --- a/services/appdfr/src/application_anr_listener.cpp +++ b/services/appdfr/src/application_anr_listener.cpp @@ -20,6 +20,7 @@ #include "app_mgr_client.h" #include "fault_data.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" namespace OHOS { diff --git a/services/dataobsmgr/src/data_ability_observer_proxy.cpp b/services/dataobsmgr/src/data_ability_observer_proxy.cpp index 21b101dd84..403dc21b10 100644 --- a/services/dataobsmgr/src/data_ability_observer_proxy.cpp +++ b/services/dataobsmgr/src/data_ability_observer_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -14,6 +14,7 @@ */ #include "data_ability_observer_proxy.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "message_parcel.h" @@ -36,13 +37,13 @@ void DataAbilityObserverProxy::OnChange() MessageOption option(MessageOption::TF_ASYNC); if (!data.WriteInterfaceToken(DataAbilityObserverProxy::GetDescriptor())) { - HILOG_ERROR("data.WriteInterfaceToken(GetDescriptor()) return false"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "data.WriteInterfaceToken(GetDescriptor()) return false"); return; } int result = SendTransactCmd(IDataAbilityObserver::DATA_ABILITY_OBSERVER_CHANGE, data, reply, option); if (result != ERR_NONE) { - HILOG_ERROR("SendRequest error, result=%{public}d", result); + TAG_LOGE(AAFwkTag::DBOBSMGR, "SendRequest error, result=%{public}d", result); } } @@ -58,18 +59,18 @@ void DataAbilityObserverProxy::OnChangeExt(const ChangeInfo &changeInfo) MessageOption option(MessageOption::TF_ASYNC); if (!data.WriteInterfaceToken(DataAbilityObserverProxy::GetDescriptor())) { - HILOG_ERROR("data.WriteInterfaceToken(GetDescriptor()) return false"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "data.WriteInterfaceToken(GetDescriptor()) return false"); return; } if (!ChangeInfo::Marshalling(changeInfo, data)) { - HILOG_ERROR("changeInfo marshalling failed"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "changeInfo marshalling failed"); return; } int result = SendTransactCmd(IDataAbilityObserver::DATA_ABILITY_OBSERVER_CHANGE_EXT, data, reply, option); if (result != ERR_NONE) { - HILOG_ERROR("SendRequest error, result=%{public}d", result); + TAG_LOGE(AAFwkTag::DBOBSMGR, "SendRequest error, result=%{public}d", result); } } @@ -85,19 +86,19 @@ void DataAbilityObserverProxy::OnChangePreferences(const std::string &key) MessageOption option(MessageOption::TF_ASYNC); if (!data.WriteInterfaceToken(DataAbilityObserverProxy::GetDescriptor())) { - HILOG_ERROR("data.WriteInterfaceToken(GetDescriptor()) return false"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "data.WriteInterfaceToken(GetDescriptor()) return false"); return; } if (!data.WriteString(key)) { - HILOG_ERROR("data.WriteString(key) return false"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "data.WriteString(key) return false"); return; } int result = SendTransactCmd(IDataAbilityObserver::DATA_ABILITY_OBSERVER_CHANGE_PREFERENCES, data, reply, option); if (result != ERR_NONE) { - HILOG_ERROR("SendRequest error, result=%{public}d", result); + TAG_LOGE(AAFwkTag::DBOBSMGR, "SendRequest error, result=%{public}d", result); } } @@ -106,7 +107,7 @@ int32_t DataAbilityObserverProxy::SendTransactCmd(uint32_t code, MessageParcel & { sptr remote = Remote(); if (remote == nullptr) { - HILOG_ERROR("Remote is nullptr."); + TAG_LOGE(AAFwkTag::DBOBSMGR, "Remote is nullptr."); return ERR_NULL_OBJECT; } diff --git a/services/dataobsmgr/src/data_ability_observer_stub.cpp b/services/dataobsmgr/src/data_ability_observer_stub.cpp index 8f520d6dba..89cd01da1b 100644 --- a/services/dataobsmgr/src/data_ability_observer_stub.cpp +++ b/services/dataobsmgr/src/data_ability_observer_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -15,6 +15,7 @@ #include "data_ability_observer_stub.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "ipc_skeleton.h" #include "common_utils.h" @@ -36,19 +37,20 @@ DataAbilityObserverStub::~DataAbilityObserverStub() {} int DataAbilityObserverStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_DEBUG("code: %{public}d, flags: %{public}d, callingPid:%{public}d", code, option.GetFlags(), + TAG_LOGD(AAFwkTag::DBOBSMGR, "code: %{public}d, flags: %{public}d, callingPid:%{public}d", code, option.GetFlags(), IPCSkeleton::GetCallingPid()); std::u16string descriptor = DataAbilityObserverStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { - HILOG_ERROR("local descriptor is not equal to remote, descriptor: %{public}s, remoteDescriptor: %{public}s", + TAG_LOGE(AAFwkTag::DBOBSMGR, + "local descriptor is not equal to remote, descriptor: %{public}s, remoteDescriptor: %{public}s", CommonUtils::Anonymous(Str16ToStr8(descriptor)).c_str(), CommonUtils::Anonymous(Str16ToStr8(remoteDescriptor)).c_str()); return ERR_INVALID_STATE; } if (code < TRANS_HEAD || code >= TRANS_BUTT || HANDLES[code] == nullptr) { - HILOG_ERROR("not support code:%u, BUTT:%d", code, TRANS_BUTT); + TAG_LOGE(AAFwkTag::DBOBSMGR, "not support code:%u, BUTT:%d", code, TRANS_BUTT); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } return (this->*HANDLES[code])(data, reply); diff --git a/services/dataobsmgr/src/dataobs_mgr_client.cpp b/services/dataobsmgr/src/dataobs_mgr_client.cpp index 586eeef5d7..2efa89436d 100644 --- a/services/dataobsmgr/src/dataobs_mgr_client.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -16,6 +16,7 @@ #include #include "dataobs_mgr_client.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" @@ -123,19 +124,19 @@ Status DataObsMgrClient::Connect() sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemManager == nullptr) { - HILOG_ERROR("fail to get Registry"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "fail to get Registry"); return GET_DATAOBS_SERVICE_FAILED; } auto remoteObject = systemManager->GetSystemAbility(DATAOBS_MGR_SERVICE_SA_ID); if (remoteObject == nullptr) { - HILOG_ERROR("fail to get systemAbility"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "fail to get systemAbility"); return GET_DATAOBS_SERVICE_FAILED; } dataObsManger_ = iface_cast(remoteObject); if (dataObsManger_ == nullptr) { - HILOG_ERROR("fail to get IDataObsMgr"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "fail to get IDataObsMgr"); return GET_DATAOBS_SERVICE_FAILED; } sptr serviceDeathRecipient(new (std::nothrow) ServiceDeathRecipient(GetInstance())); diff --git a/services/dataobsmgr/src/dataobs_mgr_inner.cpp b/services/dataobsmgr/src/dataobs_mgr_inner.cpp index 7ed27e9b20..ac8e005c76 100644 --- a/services/dataobsmgr/src/dataobs_mgr_inner.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_inner.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -16,6 +16,7 @@ #include "data_ability_observer_stub.h" #include "dataobs_mgr_errors.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "common_utils.h" @@ -32,14 +33,15 @@ int DataObsMgrInner::HandleRegisterObserver(const Uri &uri, sptr>()); if (!flag && obsPair->second.size() > OBS_NUM_MAX) { - HILOG_ERROR("The number of subscribers for this uri : %{public}s has reached the upper limit.", + TAG_LOGE(AAFwkTag::DBOBSMGR, + "The number of subscribers for this uri : %{public}s has reached the upper limit.", CommonUtils::Anonymous(uri.ToString()).c_str()); return DATAOBS_SERVICE_OBS_LIMMIT; } for (auto obs = obsPair->second.begin(); obs != obsPair->second.end(); obs++) { if ((*obs)->AsObject() == dataObserver->AsObject()) { - HILOG_ERROR("the obs has registered on this uri : %{public}s", + TAG_LOGE(AAFwkTag::DBOBSMGR, "the obs has registered on this uri : %{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); return OBS_EXIST; } @@ -58,11 +60,12 @@ int DataObsMgrInner::HandleUnregisterObserver(const Uri &uri, sptrsecond.size(), + TAG_LOGD(AAFwkTag::DBOBSMGR, "obs num is %{public}zu on this uri : %{public}s", obsPair->second.size(), CommonUtils::Anonymous(uri.ToString()).c_str()); auto obs = obsPair->second.begin(); for (; obs != obsPair->second.end(); obs++) { @@ -71,7 +74,8 @@ int DataObsMgrInner::HandleUnregisterObserver(const Uri &uri, sptrsecond.end()) { - HILOG_WARN("no obs on this uri : %{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGW( + AAFwkTag::DBOBSMGR, "no obs on this uri : %{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); return NO_OBS_FOR_URI; } obsPair->second.remove(*obs); @@ -93,7 +97,8 @@ int DataObsMgrInner::HandleNotifyChange(const Uri &uri) { auto obsPair = observers_.find(uri.ToString()); if (obsPair == observers_.end()) { - HILOG_DEBUG("there is no obs on the uri : %{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGD(AAFwkTag::DBOBSMGR, "there is no obs on the uri : %{public}s", + CommonUtils::Anonymous(uri.ToString()).c_str()); return NO_OBS_FOR_URI; } obsList = obsPair->second; @@ -105,7 +110,7 @@ int DataObsMgrInner::HandleNotifyChange(const Uri &uri) } } - HILOG_DEBUG("called end on the uri : %{public}s,obs num: %{public}zu", + TAG_LOGD(AAFwkTag::DBOBSMGR, "called end on the uri : %{public}s,obs num: %{public}zu", CommonUtils::Anonymous(uri.ToString()).c_str(), obsList.size()); return NO_ERROR; } @@ -118,7 +123,7 @@ void DataObsMgrInner::AddObsDeathRecipient(sptr dataObserv auto it = obsRecipient_.find(dataObserver->AsObject()); if (it != obsRecipient_.end()) { - HILOG_WARN("this death recipient has been added."); + TAG_LOGW(AAFwkTag::DBOBSMGR, "this death recipient has been added."); return; } else { std::weak_ptr thisWeakPtr(shared_from_this()); @@ -130,7 +135,7 @@ void DataObsMgrInner::AddObsDeathRecipient(sptr dataObserv } }); if (!dataObserver->AsObject()->AddDeathRecipient(deathRecipient)) { - HILOG_ERROR("AddDeathRecipient failed."); + TAG_LOGE(AAFwkTag::DBOBSMGR, "AddDeathRecipient failed."); } obsRecipient_.emplace(dataObserver->AsObject(), deathRecipient); } @@ -159,7 +164,7 @@ void DataObsMgrInner::OnCallBackDied(const wptr &remote) std::lock_guard lock(innerMutex_); if (dataObserver == nullptr) { - HILOG_ERROR("dataObserver is nullptr."); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObserver is nullptr."); return; } @@ -172,7 +177,7 @@ void DataObsMgrInner::RemoveObs(sptr dataObserver) auto &obsList = iter->second; for (auto it = obsList.begin(); it != obsList.end(); it++) { if ((*it)->AsObject() == dataObserver) { - HILOG_DEBUG("Erase an observer form list."); + TAG_LOGD(AAFwkTag::DBOBSMGR, "Erase an observer form list."); obsList.erase(it); break; } diff --git a/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp b/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp index b115bbe5a6..00fdd00183 100644 --- a/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -16,6 +16,7 @@ #include "data_ability_observer_stub.h" #include "dataobs_mgr_errors.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "common_utils.h" @@ -40,7 +41,8 @@ Status DataObsMgrInnerExt::HandleRegisterObserver(Uri &uri, sptr path = { uri.GetScheme(), uri.GetAuthority() }; uri.GetPathSegments(path); if (root_ != nullptr && !root_->AddObserver(path, 0, Entry(dataObserver, deathRecipientRef, isDescendants))) { - HILOG_ERROR("The number of subscribers for this uri : %{public}s has reached the upper limit.", + TAG_LOGE(AAFwkTag::DBOBSMGR, + "The number of subscribers for this uri : %{public}s has reached the upper limits.", CommonUtils::Anonymous(uri.ToString()).c_str()); RemoveObsDeathRecipient(dataObserver->AsObject()); return DATAOBS_SERVICE_OBS_LIMMIT; @@ -51,7 +53,7 @@ Status DataObsMgrInnerExt::HandleRegisterObserver(Uri &uri, sptr dataObserver) { if (dataObserver->AsObject() == nullptr) { - HILOG_ERROR("dataObserver is null, uri : %{public}s has reached the upper limit.", + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObserver is null, uri : %{public}s has reached the upper limit.", CommonUtils::Anonymous(uri.ToString()).c_str()); return DATA_OBSERVER_IS_NULL; } @@ -68,7 +70,7 @@ Status DataObsMgrInnerExt::HandleUnregisterObserver(Uri &uri, sptr dataObserver) { if (dataObserver->AsObject() == nullptr) { - HILOG_ERROR("dataObserver is null"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObserver is null"); return DATA_OBSERVER_IS_NULL; } std::lock_guard lock(nodeMutex_); @@ -94,8 +96,9 @@ Status DataObsMgrInnerExt::HandleNotifyChange(const ChangeInfo &changeInfo) } } if (changeRes.empty()) { - HILOG_DEBUG("no obs for this uris, changeType:%{public}ud, num of uris:%{public}zu, data is " - "nullptr:%{public}d, size:%{public}ud", + TAG_LOGD(AAFwkTag::DBOBSMGR, + "no obs for this uris, changeType:%{public}ud, num of uris:%{public}zu, data is " + "nullptr:%{public}d, size:%{public}ud", changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_); return NO_OBS_FOR_URI; } @@ -114,7 +117,7 @@ std::shared_ptr DataObsMgrInnerExt::AddOb auto it = obsRecipientRefs.find(dataObserver); if (it != obsRecipientRefs.end()) { if (std::numeric_limits::max() - 1 < it->second->ref) { - HILOG_ERROR("the num of observer reach max limit"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "the num of observer reach max limit"); return nullptr; } } else { @@ -129,7 +132,8 @@ std::shared_ptr DataObsMgrInnerExt::AddOb dataObserver->AddDeathRecipient(deathRecipient); it = obsRecipientRefs.emplace(dataObserver, std::make_shared(deathRecipient)).first; } - HILOG_DEBUG("this observer will be added, sum:%{public}ud", it->second->ref.load(std::memory_order_relaxed)); + TAG_LOGD(AAFwkTag::DBOBSMGR, "this observer will be added, sum:%{public}ud", + it->second->ref.load(std::memory_order_relaxed)); return it->second; } @@ -141,7 +145,7 @@ void DataObsMgrInnerExt::RemoveObsDeathRecipient(const sptr &data } if (isForce || it->second->ref <= 1) { - HILOG_DEBUG("this observer deathRecipient will be remove, sum:%{public}ud", + TAG_LOGD(AAFwkTag::DBOBSMGR, "this observer deathRecipient will be remove, sum:%{public}ud", it->second->ref.load(std::memory_order_relaxed)); dataObserver->RemoveDeathRecipient(it->second->deathRecipient); obsRecipientRefs.erase(it); @@ -151,7 +155,7 @@ void DataObsMgrInnerExt::RemoveObsDeathRecipient(const sptr &data void DataObsMgrInnerExt::OnCallBackDied(const wptr &remote) { - HILOG_DEBUG("this observer died"); + TAG_LOGD(AAFwkTag::DBOBSMGR, "this observer died"); auto dataObserver = remote.promote(); if (dataObserver == nullptr) { return; diff --git a/services/dataobsmgr/src/dataobs_mgr_inner_pref.cpp b/services/dataobsmgr/src/dataobs_mgr_inner_pref.cpp index 4275edcf3f..13a68b0643 100644 --- a/services/dataobsmgr/src/dataobs_mgr_inner_pref.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_inner_pref.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -16,6 +16,7 @@ #include "data_ability_observer_stub.h" #include "dataobs_mgr_errors.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "common_utils.h" @@ -32,14 +33,15 @@ int DataObsMgrInnerPref::HandleRegisterObserver(const Uri &uri, sptr>()); if (!flag && obsPair->second.size() > OBS_NUM_MAX) { - HILOG_ERROR("The number of subscribers for this uri : %{public}s has reached the upper limit.", + TAG_LOGE(AAFwkTag::DBOBSMGR, + "The number of subscribers for this uri : %{public}s has reached the upper limit.", CommonUtils::Anonymous(uri.ToString()).c_str()); return DATAOBS_SERVICE_OBS_LIMMIT; } for (auto obs = obsPair->second.begin(); obs != obsPair->second.end(); obs++) { if ((*obs)->AsObject() == dataObserver->AsObject()) { - HILOG_ERROR("the obs has registered on this uri : %{public}s", + TAG_LOGE(AAFwkTag::DBOBSMGR, "the obs has registered on this uri : %{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); return OBS_EXIST; } @@ -57,11 +59,12 @@ int DataObsMgrInnerPref::HandleUnregisterObserver(const Uri &uri, sptrsecond.size(), + TAG_LOGD(AAFwkTag::DBOBSMGR, "obs num is %{public}zu on this uri : %{public}s", obsPair->second.size(), CommonUtils::Anonymous(uri.ToString()).c_str()); auto obs = obsPair->second.begin(); for (; obs != obsPair->second.end(); obs++) { @@ -70,7 +73,8 @@ int DataObsMgrInnerPref::HandleUnregisterObserver(const Uri &uri, sptrsecond.end()) { - HILOG_WARN("no obs on this uri : %{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGW( + AAFwkTag::DBOBSMGR, "no obs on this uri : %{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); return NO_OBS_FOR_URI; } obsPair->second.remove(*obs); @@ -92,14 +96,15 @@ int DataObsMgrInnerPref::HandleNotifyChange(const Uri &uri) std::string uriStr = uri.ToString(); size_t pos = uriStr.find('?'); if (pos == std::string::npos) { - HILOG_WARN("the current uri is missing the query section : %{public}s", + TAG_LOGW(AAFwkTag::DBOBSMGR, "the current uri is missing the query section : %{public}s", CommonUtils::Anonymous(uriStr).c_str()); return INVALID_PARAM; } std::string observerKey = uriStr.substr(0, pos); auto obsPair = observers_.find(observerKey); if (obsPair == observers_.end()) { - HILOG_DEBUG("there is no obs on the uri : %{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGD(AAFwkTag::DBOBSMGR, "there is no obs on the uri : %{public}s", + CommonUtils::Anonymous(uri.ToString()).c_str()); return NO_OBS_FOR_URI; } obsList = obsPair->second; @@ -111,7 +116,7 @@ int DataObsMgrInnerPref::HandleNotifyChange(const Uri &uri) } } - HILOG_DEBUG("called end on the uri : %{public}s,obs num: %{public}zu", + TAG_LOGD(AAFwkTag::DBOBSMGR, "called end on the uri : %{public}s,obs num: %{public}zu", CommonUtils::Anonymous(uri.ToString()).c_str(), obsList.size()); return NO_ERROR; } @@ -124,7 +129,7 @@ void DataObsMgrInnerPref::AddObsDeathRecipient(sptr dataOb auto it = obsRecipient_.find(dataObserver->AsObject()); if (it != obsRecipient_.end()) { - HILOG_WARN("this death recipient has been added."); + TAG_LOGW(AAFwkTag::DBOBSMGR, "this death recipient has been added."); return; } else { std::weak_ptr thisWeakPtr(shared_from_this()); @@ -136,7 +141,7 @@ void DataObsMgrInnerPref::AddObsDeathRecipient(sptr dataOb } }); if (!dataObserver->AsObject()->AddDeathRecipient(deathRecipient)) { - HILOG_ERROR("AddDeathRecipient failed."); + TAG_LOGE(AAFwkTag::DBOBSMGR, "AddDeathRecipient failed."); } obsRecipient_.emplace(dataObserver->AsObject(), deathRecipient); } @@ -165,7 +170,7 @@ void DataObsMgrInnerPref::OnCallBackDied(const wptr &remote) std::lock_guard lock(preferenceMutex_); if (dataObserver == nullptr) { - HILOG_ERROR("dataObserver is nullptr."); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObserver is nullptr."); return; } @@ -178,7 +183,7 @@ void DataObsMgrInnerPref::RemoveObs(sptr dataObserver) auto &obsList = iter->second; for (auto it = obsList.begin(); it != obsList.end(); it++) { if ((*it)->AsObject() == dataObserver) { - HILOG_DEBUG("Erase an observer form list."); + TAG_LOGD(AAFwkTag::DBOBSMGR, "Erase an observer form list."); obsList.erase(it); break; } diff --git a/services/dataobsmgr/src/dataobs_mgr_proxy.cpp b/services/dataobsmgr/src/dataobs_mgr_proxy.cpp index 06d01c095c..e1c29d1b60 100644 --- a/services/dataobsmgr/src/dataobs_mgr_proxy.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -16,6 +16,7 @@ #include "dataobs_mgr_proxy.h" #include "errors.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "dataobs_mgr_errors.h" #include "common_utils.h" @@ -25,7 +26,7 @@ namespace AAFwk { bool DataObsManagerProxy::WriteInterfaceToken(MessageParcel &data) { if (!data.WriteInterfaceToken(DataObsManagerProxy::GetDescriptor())) { - HILOG_ERROR("failed, write interface token error"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "failed, write interface token error"); return false; } return true; @@ -34,17 +35,17 @@ bool DataObsManagerProxy::WriteInterfaceToken(MessageParcel &data) bool DataObsManagerProxy::WriteParam(MessageParcel &data, const Uri &uri, sptr dataObserver) { if (!data.WriteString(uri.ToString())) { - HILOG_ERROR("failed, write uri error"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "failed, write uri error"); return false; } if (dataObserver == nullptr) { - HILOG_ERROR("failed, dataObserver is nullptr"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "failed, dataObserver is nullptr"); return false; } if (!data.WriteRemoteObject(dataObserver->AsObject())) { - HILOG_ERROR("failed, write dataObserver error"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "failed, write dataObserver error"); return false; } return true; @@ -66,7 +67,7 @@ int32_t DataObsManagerProxy::RegisterObserver(const Uri &uri, sptr dat } if (dataObserver == nullptr) { - HILOG_ERROR("failed, dataObserver is nullptr"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "failed, dataObserver is nullptr"); return INVALID_PARAM; } if (!data.WriteRemoteObject(dataObserver->AsObject())) { - HILOG_ERROR("failed, write dataObserver error"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "failed, write dataObserver error"); return INVALID_PARAM; } auto error = SendTransactCmd(IDataObsMgr::UNREGISTER_OBSERVER_ALL_EXT, data, reply, option); if (error != NO_ERROR) { - HILOG_ERROR("failed, SendRequest error: %{public}d", error); + TAG_LOGE(AAFwkTag::DBOBSMGR, "failed, SendRequest error: %{public}d", error); return IPC_ERROR; } int32_t res = IPC_ERROR; @@ -218,16 +221,18 @@ Status DataObsManagerProxy::NotifyChangeExt(const ChangeInfo &changeInfo) } if (!ChangeInfo::Marshalling(changeInfo, data)) { - HILOG_ERROR("failed, changeInfo marshalling error, changeType:%{public}ud, num of uris:%{public}zu, data is " - "nullptr:%{public}d, size:%{public}ud", + TAG_LOGE(AAFwkTag::DBOBSMGR, + "failed, changeInfo marshalling error, changeType:%{public}ud, num of uris:%{public}zu, data is " + "nullptr:%{public}d, size:%{public}ud", changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_); return INVALID_PARAM; } auto error = SendTransactCmd(IDataObsMgr::NOTIFY_CHANGE_EXT, data, reply, option); if (error != NO_ERROR) { - HILOG_ERROR("failed, SendRequest error: %{public}d, changeType:%{public}ud, num of uris:%{public}zu, data is " - "nullptr:%{public}d, size:%{public}ud", + TAG_LOGE(AAFwkTag::DBOBSMGR, + "failed, SendRequest error: %{public}d, changeType:%{public}ud, num of uris:%{public}zu, data is " + "nullptr:%{public}d, size:%{public}ud", error, changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_); return IPC_ERROR; } @@ -240,13 +245,13 @@ int32_t DataObsManagerProxy::SendTransactCmd(uint32_t code, MessageParcel &data, { sptr remote = Remote(); if (remote == nullptr) { - HILOG_ERROR("remote object is nullptr."); + TAG_LOGE(AAFwkTag::DBOBSMGR, "remote object is nullptr."); return ERR_NULL_OBJECT; } int32_t ret = remote->SendRequest(code, data, reply, option); if (ret != NO_ERROR) { - HILOG_ERROR("SendRequest failed. code is %{public}d, ret is %{public}d.", code, ret); + TAG_LOGE(AAFwkTag::DBOBSMGR, "SendRequest failed. code is %{public}d, ret is %{public}d.", code, ret); return ret; } return NO_ERROR; diff --git a/services/dataobsmgr/src/dataobs_mgr_service.cpp b/services/dataobsmgr/src/dataobs_mgr_service.cpp index 46c6ed4e03..e060d62bf9 100644 --- a/services/dataobsmgr/src/dataobs_mgr_service.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -22,6 +22,7 @@ #include "string_ex.h" #include "dataobs_mgr_errors.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "if_system_ability_manager.h" #include "ipc_skeleton.h" @@ -49,22 +50,22 @@ DataObsMgrService::~DataObsMgrService() void DataObsMgrService::OnStart() { if (state_ == DataObsServiceRunningState::STATE_RUNNING) { - HILOG_INFO("Dataobs Manager Service has already started."); + TAG_LOGI(AAFwkTag::DBOBSMGR, "Dataobs Manager Service has already started."); return; } if (!Init()) { - HILOG_ERROR("failed to init service."); + TAG_LOGE(AAFwkTag::DBOBSMGR, "failed to init service."); return; } state_ = DataObsServiceRunningState::STATE_RUNNING; /* Publish service maybe failed, so we need call this function at the last, * so it can't affect the TDD test program */ if (!Publish(DelayedSingleton::GetInstance().get())) { - HILOG_ERROR("Init Publish failed!"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "Init Publish failed!"); return; } - HILOG_INFO("Dataobs Manager Service start success."); + TAG_LOGI(AAFwkTag::DBOBSMGR, "Dataobs Manager Service start success."); } bool DataObsMgrService::Init() @@ -75,7 +76,7 @@ bool DataObsMgrService::Init() void DataObsMgrService::OnStop() { - HILOG_INFO("stop service"); + TAG_LOGI(AAFwkTag::DBOBSMGR, "stop service"); handler_.reset(); state_ = DataObsServiceRunningState::STATE_NOT_START; } @@ -88,12 +89,14 @@ DataObsServiceRunningState DataObsMgrService::QueryServiceState() const int DataObsMgrService::RegisterObserver(const Uri &uri, sptr dataObserver) { if (dataObserver == nullptr) { - HILOG_ERROR("dataObserver is nullptr, uri:%{public}s.", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObserver is nullptr, uri:%{public}s.", + CommonUtils::Anonymous(uri.ToString()).c_str()); return DATA_OBSERVER_IS_NULL; } if (dataObsMgrInner_ == nullptr) { - HILOG_ERROR("dataObsMgrInner_ is nullptr, uri:%{public}s.", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObsMgrInner_ is nullptr, uri:%{public}s.", + CommonUtils::Anonymous(uri.ToString()).c_str()); return DATAOBS_SERVICE_INNER_IS_NULL; } @@ -105,7 +108,7 @@ int DataObsMgrService::RegisterObserver(const Uri &uri, sptr dataObserver) { if (dataObserver == nullptr) { - HILOG_ERROR("dataObserver is nullptr, uri:%{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObserver is nullptr, uri:%{public}s", + CommonUtils::Anonymous(uri.ToString()).c_str()); return DATA_OBSERVER_IS_NULL; } if (dataObsMgrInner_ == nullptr) { - HILOG_ERROR("dataObsMgrInner_ is nullptr, uri:%{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObsMgrInner_ is nullptr, uri:%{public}s", + CommonUtils::Anonymous(uri.ToString()).c_str()); return DATAOBS_SERVICE_INNER_IS_NULL; } @@ -132,7 +137,7 @@ int DataObsMgrService::UnregisterObserver(const Uri &uri, sptr lck(taskCountMutex_); if (taskCount_ >= TASK_COUNT_MAX) { - HILOG_ERROR("The number of task has reached the upper limit, uri:%{public}s", + TAG_LOGE(AAFwkTag::DBOBSMGR, "The number of task has reached the upper limit, uri:%{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); return DATAOBS_SERVICE_TASK_LIMMIT; } @@ -180,13 +187,13 @@ Status DataObsMgrService::RegisterObserverExt(const Uri &uri, sptr dataObserver) { if (dataObserver == nullptr) { - HILOG_ERROR("dataObserver is nullptr, uri:%{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObserver is nullptr, uri:%{public}s", + CommonUtils::Anonymous(uri.ToString()).c_str()); return DATA_OBSERVER_IS_NULL; } if (dataObsMgrInnerExt_ == nullptr) { - HILOG_ERROR("dataObsMgrInner_ is nullptr, uri:%{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObsMgrInner_ is nullptr, uri:%{public}s", + CommonUtils::Anonymous(uri.ToString()).c_str()); return DATAOBS_SERVICE_INNER_IS_NULL; } @@ -214,12 +223,12 @@ Status DataObsMgrService::UnregisterObserverExt(const Uri &uri, sptr dataObserver) { if (dataObserver == nullptr) { - HILOG_ERROR("dataObserver is nullptr"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObserver is nullptr"); return DATA_OBSERVER_IS_NULL; } if (dataObsMgrInnerExt_ == nullptr) { - HILOG_ERROR("dataObsMgrInner_ is nullptr"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObsMgrInner_ is nullptr"); return DATAOBS_SERVICE_INNER_IS_NULL; } @@ -249,28 +258,31 @@ Status DataObsMgrService::DeepCopyChangeInfo(const ChangeInfo &src, ChangeInfo & Status DataObsMgrService::NotifyChangeExt(const ChangeInfo &changeInfo) { if (handler_ == nullptr) { - HILOG_ERROR("handler is nullptr"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "handler is nullptr"); return DATAOBS_SERVICE_HANDLER_IS_NULL; } if (dataObsMgrInner_ == nullptr || dataObsMgrInnerExt_ == nullptr) { - HILOG_ERROR("dataObsMgrInner_:%{public}d or dataObsMgrInnerExt_ is nullptr", dataObsMgrInner_ == nullptr); + TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObsMgrInner_:%{public}d or dataObsMgrInnerExt_ is nullptr", + dataObsMgrInner_ == nullptr); return DATAOBS_SERVICE_INNER_IS_NULL; } ChangeInfo changes; Status result = DeepCopyChangeInfo(changeInfo, changes); if (result != SUCCESS) { - HILOG_ERROR("copy data failed, changeType:%{public}ud, num of uris:%{public}zu, data is " - "nullptr:%{public}d, size:%{public}ud", - changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_); + TAG_LOGE(AAFwkTag::DBOBSMGR, + "copy data failed, changeType:%{public}ud, num of uris:%{public}zu, data is " + "nullptr:%{public}d, size:%{public}ud", + changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_); return result; } { std::lock_guard lck(taskCountMutex_); if (taskCount_ >= TASK_COUNT_MAX) { - HILOG_ERROR("The number of task has reached the upper limit, changeType:%{public}ud, num of " - "uris:%{public}zu, data is nullptr:%{public}d, size:%{public}ud", + TAG_LOGE(AAFwkTag::DBOBSMGR, + "The number of task has reached the upper limit, changeType:%{public}ud, num of " + "uris:%{public}zu, data is nullptr:%{public}d, size:%{public}ud", changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_); return DATAOBS_SERVICE_TASK_LIMMIT; } @@ -295,7 +307,7 @@ int DataObsMgrService::Dump(int fd, const std::vector& args) Dump(args, result); int ret = dprintf(fd, "%s\n", result.c_str()); if (ret < 0) { - HILOG_ERROR("%{public}s, dprintf error.", __func__); + TAG_LOGE(AAFwkTag::DBOBSMGR, "%{public}s, dprintf error.", __func__); return DATAOBS_HIDUMP_ERROR; } return SUCCESS; diff --git a/services/dataobsmgr/src/dataobs_mgr_stub.cpp b/services/dataobsmgr/src/dataobs_mgr_stub.cpp index 46defe350c..9cbe957124 100644 --- a/services/dataobsmgr/src/dataobs_mgr_stub.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -21,6 +21,7 @@ #include "dataobs_mgr_errors.h" #include "ipc_skeleton.h" #include "common_utils.h" +#include "hilog_tag_wrapper.h" namespace OHOS { namespace AAFwk { @@ -42,19 +43,20 @@ DataObsManagerStub::~DataObsManagerStub() {} int DataObsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_DEBUG("code: %{public}d, flags: %{public}d, callingPid:%{public}d", code, option.GetFlags(), + TAG_LOGD(AAFwkTag::DBOBSMGR, "code: %{public}d, flags: %{public}d, callingPid:%{public}d", code, option.GetFlags(), IPCSkeleton::GetCallingPid()); std::u16string descriptor = DataObsManagerStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { - HILOG_ERROR("local descriptor is not equal to remote, descriptor: %{public}s, remoteDescriptor: %{public}s", + TAG_LOGE(AAFwkTag::DBOBSMGR, + "local descriptor is not equal to remote, descriptor: %{public}s, remoteDescriptor: %{public}s", CommonUtils::Anonymous(Str16ToStr8(descriptor)).c_str(), CommonUtils::Anonymous(Str16ToStr8(remoteDescriptor)).c_str()); return ERR_INVALID_STATE; } if (code < TRANS_HEAD || code >= TRANS_BUTT || HANDLES[code] == nullptr) { - HILOG_ERROR("not support code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); + TAG_LOGE(AAFwkTag::DBOBSMGR, "not support code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } return (this->*HANDLES[code])(data, reply); @@ -64,7 +66,7 @@ int DataObsManagerStub::RegisterObserverInner(MessageParcel &data, MessageParcel { Uri uri(data.ReadString()); if (uri.ToString().empty()) { - HILOG_ERROR("uri is invalid"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "uri is invalid"); return IPC_STUB_INVALID_DATA_ERR; } @@ -79,7 +81,7 @@ int DataObsManagerStub::UnregisterObserverInner(MessageParcel &data, MessageParc { Uri uri(data.ReadString()); if (uri.ToString().empty()) { - HILOG_ERROR("uri is invalid"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "uri is invalid"); return IPC_STUB_INVALID_DATA_ERR; } @@ -94,7 +96,7 @@ int DataObsManagerStub::NotifyChangeInner(MessageParcel &data, MessageParcel &re { Uri uri(data.ReadString()); if (uri.ToString().empty()) { - HILOG_ERROR("uri is invalid"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "uri is invalid"); return IPC_STUB_INVALID_DATA_ERR; } @@ -107,7 +109,7 @@ int32_t DataObsManagerStub::RegisterObserverExtInner(MessageParcel &data, Messag { Uri uri(data.ReadString()); if (uri.ToString().empty()) { - HILOG_ERROR("uri is invalid"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "uri is invalid"); return IPC_STUB_INVALID_DATA_ERR; } auto remote = data.ReadRemoteObject(); @@ -121,7 +123,7 @@ int32_t DataObsManagerStub::UnregisterObserverExtInner(MessageParcel &data, Mess { Uri uri(data.ReadString()); if (uri.ToString().empty()) { - HILOG_ERROR("uri is invalid"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "uri is invalid"); return IPC_STUB_INVALID_DATA_ERR; } auto remote = data.ReadRemoteObject(); diff --git a/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp b/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp index a99ec13ffc..1de1f3bf77 100644 --- a/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -19,6 +19,7 @@ #include "common_event_data.h" #include "common_event_manager.h" #include "common_event_support.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" #include "quick_fix_callback_stub.h" @@ -60,27 +61,28 @@ public: virtual ~QuickFixManagerStatusCallback() { - HILOG_DEBUG("destroyed."); + TAG_LOGD(AAFwkTag::QUICKFIX, "destroyed."); } void OnPatchDeployed(const std::shared_ptr &result) override { - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); if (applyTask_ == nullptr) { - HILOG_ERROR("Apply task is nullptr, result is %{public}s.", result->ToString().c_str()); + TAG_LOGE(AAFwkTag::QUICKFIX, "Apply task is nullptr, result is %{public}s.", result->ToString().c_str()); return; } int32_t ret = QUICK_FIX_OK; do { if (result->GetResCode() != 0) { - HILOG_ERROR("Deploy quick fix failed, result is %{public}s.", result->ToString().c_str()); + TAG_LOGE(AAFwkTag::QUICKFIX, "Deploy quick fix failed, result is %{public}s.", + result->ToString().c_str()); ret = QUICK_FIX_DEPLOY_FAILED; break; } if (!applyTask_->SetQuickFixInfo(result)) { - HILOG_ERROR("Set quick fix info failed"); + TAG_LOGE(AAFwkTag::QUICKFIX, "Set quick fix info failed"); ret = QUICK_FIX_SET_INFO_FAILED; break; } @@ -97,16 +99,17 @@ public: void OnPatchSwitched(const std::shared_ptr &result) override { - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); if (applyTask_ == nullptr) { - HILOG_ERROR("Apply task is nullptr, result is %{public}s.", result->ToString().c_str()); + TAG_LOGE(AAFwkTag::QUICKFIX, "Apply task is nullptr, result is %{public}s.", result->ToString().c_str()); return; } int32_t ret = QUICK_FIX_OK; do { if (result->GetResCode() != 0) { - HILOG_ERROR("Switch quick fix failed, result is %{public}s.", result->ToString().c_str()); + TAG_LOGE(AAFwkTag::QUICKFIX, "Switch quick fix failed, result is %{public}s.", + result->ToString().c_str()); ret = QUICK_FIX_SWICH_FAILED; break; } @@ -120,7 +123,7 @@ public: } ret = QUICK_FIX_SWICH_FAILED; - HILOG_ERROR("Switch quick fix invalid task type"); + TAG_LOGE(AAFwkTag::QUICKFIX, "Switch quick fix invalid task type"); } while (0); if (ret != QUICK_FIX_OK) { @@ -132,16 +135,17 @@ public: void OnPatchDeleted(const std::shared_ptr &result) override { - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); if (applyTask_ == nullptr) { - HILOG_ERROR("Apply task is nullptr, result is %{public}s.", result->ToString().c_str()); + TAG_LOGE(AAFwkTag::QUICKFIX, "Apply task is nullptr, result is %{public}s.", result->ToString().c_str()); return; } int32_t ret = QUICK_FIX_OK; do { if (result->GetResCode() != 0) { - HILOG_ERROR("Delete quick fix failed, result is %{public}s.", result->ToString().c_str()); + TAG_LOGE(AAFwkTag::QUICKFIX, "Delete quick fix failed, result is %{public}s.", + result->ToString().c_str()); ret = QUICK_FIX_DELETE_FAILED; break; } @@ -155,7 +159,7 @@ public: } ret = QUICK_FIX_DELETE_FAILED; - HILOG_ERROR("Delete quick fix invalid task type"); + TAG_LOGE(AAFwkTag::QUICKFIX, "Delete quick fix invalid task type"); } while (0); if (ret != QUICK_FIX_OK) { @@ -178,7 +182,7 @@ public: void OnPatchDeployed(const std::shared_ptr &result) override { - HILOG_DEBUG("Function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function called."); } }; @@ -190,15 +194,16 @@ public: virtual ~QuickFixMgrAppStateObserver() { - HILOG_DEBUG("destroyed."); + TAG_LOGD(AAFwkTag::QUICKFIX, "destroyed."); } void OnProcessDied(const AppExecFwk::ProcessData &processData) override { - HILOG_INFO("process died, bundle name is %{public}s.", processData.bundleName.c_str()); + TAG_LOGI(AAFwkTag::QUICKFIX, "process died, bundle name is %{public}s.", processData.bundleName.c_str()); if (applyTask_ == nullptr) { - HILOG_ERROR("Apply task is nullptr, bundle name is %{public}s.", processData.bundleName.c_str()); + TAG_LOGE(AAFwkTag::QUICKFIX, "Apply task is nullptr, bundle name is %{public}s.", + processData.bundleName.c_str()); return; } @@ -209,7 +214,7 @@ public: } else if (applyTask_->GetTaskType() == QuickFixManagerApplyTask::TaskType::QUICK_FIX_REVOKE) { applyTask_->PostRevokeQuickFixProcessDiedTask(); } else { - HILOG_WARN("Invalid task type"); + TAG_LOGW(AAFwkTag::QUICKFIX, "Invalid task type"); } } @@ -228,14 +233,14 @@ public: virtual ~QuickFixNotifyCallback() { - HILOG_DEBUG("destroyed."); + TAG_LOGD(AAFwkTag::QUICKFIX, "destroyed."); } void OnLoadPatchDone(int32_t resultCode, [[maybe_unused]] int32_t recordId) override { - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); if (resultCode != 0) { - HILOG_ERROR("Notify app load patch failed with %{public}d.", resultCode); + TAG_LOGE(AAFwkTag::QUICKFIX, "Notify app load patch failed with %{public}d.", resultCode); applyTask_->NotifyApplyStatus(QUICK_FIX_NOTIFY_LOAD_PATCH_FAILED); applyTask_->RemoveSelf(); return; @@ -246,9 +251,9 @@ public: void OnUnloadPatchDone(int32_t resultCode, [[maybe_unused]] int32_t recordId) override { - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); if (resultCode != 0) { - HILOG_ERROR("Notify app load patch failed with %{public}d.", resultCode); + TAG_LOGE(AAFwkTag::QUICKFIX, "Notify app load patch failed with %{public}d.", resultCode); applyTask_->NotifyApplyStatus(QUICK_FIX_NOTIFY_UNLOAD_PATCH_FAILED); applyTask_->RemoveSelf(); return; @@ -262,14 +267,14 @@ public: return; } - HILOG_WARN("Invalid task type"); + TAG_LOGW(AAFwkTag::QUICKFIX, "Invalid task type"); } void OnReloadPageDone(int32_t resultCode, [[maybe_unused]] int32_t recordId) override { - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); if (resultCode != 0) { - HILOG_ERROR("Notify app load patch failed with %{public}d.", resultCode); + TAG_LOGE(AAFwkTag::QUICKFIX, "Notify app load patch failed with %{public}d.", resultCode); applyTask_->NotifyApplyStatus(QUICK_FIX_NOTIFY_RELOAD_PAGE_FAILED); applyTask_->RemoveSelf(); return; @@ -293,24 +298,24 @@ public: void OnLoadPatchDone(int32_t resultCode, [[maybe_unused]] int32_t recordId) override { - HILOG_DEBUG("Function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function called."); } void OnReloadPageDone(int32_t resultCode, [[maybe_unused]] int32_t recordId) override { - HILOG_DEBUG("Function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function called."); } }; QuickFixManagerApplyTask::~QuickFixManagerApplyTask() { - HILOG_DEBUG("destroyed."); + TAG_LOGD(AAFwkTag::QUICKFIX, "destroyed."); } void QuickFixManagerApplyTask::Run(const std::vector &quickFixFiles, bool isDebug) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_INFO("Run apply task."); + TAG_LOGI(AAFwkTag::QUICKFIX, "Run apply task."); taskType_ = TaskType::QUICK_FIX_APPLY; PostDeployQuickFixTask(quickFixFiles, isDebug); } @@ -318,7 +323,7 @@ void QuickFixManagerApplyTask::Run(const std::vector &quickFixFiles void QuickFixManagerApplyTask::RunRevoke() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_INFO("Run apply revoke task."); + TAG_LOGI(AAFwkTag::QUICKFIX, "Run apply revoke task."); taskType_ = TaskType::QUICK_FIX_REVOKE; PostRevokeQuickFixTask(); } @@ -327,14 +332,14 @@ void QuickFixManagerApplyTask::InitRevokeTask(const std::string &bundleName, boo { isSoContained_ = isSoContained; bundleName_ = bundleName; - HILOG_INFO("Function called. name:%{public}s and isSoContained:%{public}s", bundleName_.c_str(), + TAG_LOGI(AAFwkTag::QUICKFIX, "Function called. name:%{public}s and isSoContained:%{public}s", bundleName_.c_str(), isSoContained_ ? "true" : "false"); } void QuickFixManagerApplyTask::HandlePatchDeployed() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); isRunning_ = GetRunningState(); if (isRunning_ && isSoContained_) { @@ -343,7 +348,7 @@ void QuickFixManagerApplyTask::HandlePatchDeployed() ApplicationQuickFixInfo quickFixInfo; auto service = quickFixMgrService_.promote(); if (service == nullptr) { - HILOG_ERROR("Quick fix service is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Quick fix service is nullptr."); NotifyApplyStatus(QUICK_FIX_INVALID_PARAM); RemoveSelf(); return; @@ -352,7 +357,7 @@ void QuickFixManagerApplyTask::HandlePatchDeployed() auto ret = service->GetApplyedQuickFixInfo(bundleName_, quickFixInfo); if (ret == QUICK_FIX_OK && !quickFixInfo.appqfInfo.hqfInfos.empty()) { // if there exist old version hqfInfo, need to unload. - HILOG_DEBUG("Need unload patch firstly."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Need unload patch firstly."); return PostNotifyUnloadRepairPatchTask(); } } @@ -363,7 +368,7 @@ void QuickFixManagerApplyTask::HandlePatchDeployed() void QuickFixManagerApplyTask::HandlePatchSwitched() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); if (isRunning_ && !isSoContained_) { return PostNotifyLoadRepairPatchTask(); @@ -375,7 +380,7 @@ void QuickFixManagerApplyTask::HandlePatchSwitched() void QuickFixManagerApplyTask::HandlePatchDeleted() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); if (isRunning_ && !isSoContained_ && type_ == AppExecFwk::QuickFixType::HOT_RELOAD) { return PostNotifyHotReloadPageTask(); @@ -393,28 +398,28 @@ void QuickFixManagerApplyTask::PostDeployQuickFixTask(const std::vectorbundleQfMgr_ == nullptr) { - HILOG_ERROR("PostDeployQuickFixTask, Bundle quick fix manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "PostDeployQuickFixTask, Bundle quick fix manager is nullptr."); applyTask->NotifyApplyStatus(QUICK_FIX_BUNDLEMGR_INVALID); applyTask->RemoveSelf(); return; } - HILOG_DEBUG("isDebug is %d", isDebug); + TAG_LOGD(AAFwkTag::QUICKFIX, "isDebug is %d", isDebug); auto ret = applyTask->bundleQfMgr_->DeployQuickFix(quickFixFiles, callback, isDebug); if (ret != 0) { - HILOG_ERROR("PostDeployQuickFixTask, Deploy quick fix failed with %{public}d.", ret); + TAG_LOGE(AAFwkTag::QUICKFIX, "PostDeployQuickFixTask, Deploy quick fix failed with %{public}d.", ret); applyTask->NotifyApplyStatus(QUICK_FIX_DEPLOY_FAILED); applyTask->RemoveSelf(); return; } }; if (eventHandler_ == nullptr || !eventHandler_->PostTask(deployTask, "QuickFixManager:deployTask")) { - HILOG_ERROR("Post deploy task failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Post deploy task failed."); } PostTimeOutTask(); } @@ -427,12 +432,12 @@ void QuickFixManagerApplyTask::PostSwitchQuickFixTask() auto switchTask = [thisWeakPtr, callback]() { auto applyTask = thisWeakPtr.lock(); if (applyTask == nullptr) { - HILOG_ERROR("PostSwitchQuickFixTask, Apply task is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "PostSwitchQuickFixTask, Apply task is nullptr."); return; } if (applyTask->bundleQfMgr_ == nullptr) { - HILOG_ERROR("PostSwitchQuickFixTask, Bundle quick fix manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "PostSwitchQuickFixTask, Bundle quick fix manager is nullptr."); applyTask->NotifyApplyStatus(QUICK_FIX_BUNDLEMGR_INVALID); applyTask->RemoveSelf(); return; @@ -440,14 +445,14 @@ void QuickFixManagerApplyTask::PostSwitchQuickFixTask() auto ret = applyTask->bundleQfMgr_->SwitchQuickFix(applyTask->bundleName_, true, callback); if (ret != 0) { - HILOG_ERROR("PostSwitchQuickFixTask, Switch quick fix failed with %{public}d.", ret); + TAG_LOGE(AAFwkTag::QUICKFIX, "PostSwitchQuickFixTask, Switch quick fix failed with %{public}d.", ret); applyTask->NotifyApplyStatus(QUICK_FIX_SWICH_FAILED); applyTask->RemoveSelf(); return; } }; if (eventHandler_ == nullptr || !eventHandler_->PostTask(switchTask, "QuickFixManager:switchTask")) { - HILOG_ERROR("Post switch task failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Post switch task failed."); } PostTimeOutTask(); } @@ -456,19 +461,19 @@ void QuickFixManagerApplyTask::PostDeleteQuickFixTask() { auto callback = new (std::nothrow) QuickFixManagerStatusCallback(shared_from_this()); if (callback == nullptr) { - HILOG_ERROR("callback is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "callback is nullptr."); return; } std::weak_ptr thisWeakPtr(weak_from_this()); auto deleteTask = [thisWeakPtr, callback]() { auto applyTask = thisWeakPtr.lock(); if (applyTask == nullptr) { - HILOG_ERROR("PostDeleteQuickFixTask, Apply task is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "PostDeleteQuickFixTask, Apply task is nullptr."); return; } if (applyTask->bundleQfMgr_ == nullptr) { - HILOG_ERROR("PostDeleteQuickFixTask, Bundle quick fix manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "PostDeleteQuickFixTask, Bundle quick fix manager is nullptr."); applyTask->NotifyApplyStatus(QUICK_FIX_BUNDLEMGR_INVALID); applyTask->RemoveSelf(); return; @@ -476,14 +481,14 @@ void QuickFixManagerApplyTask::PostDeleteQuickFixTask() auto ret = applyTask->bundleQfMgr_->DeleteQuickFix(applyTask->bundleName_, callback); if (ret != 0) { - HILOG_ERROR("PostDeleteQuickFixTask, Delete quick fix failed with %{public}d.", ret); + TAG_LOGE(AAFwkTag::QUICKFIX, "PostDeleteQuickFixTask, Delete quick fix failed with %{public}d.", ret); applyTask->NotifyApplyStatus(QUICK_FIX_DELETE_FAILED); applyTask->RemoveSelf(); return; } }; if (eventHandler_ == nullptr || !eventHandler_->PostTask(deleteTask, "QuickFixManager:deleteTask")) { - HILOG_ERROR("Post delete task failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Post delete task failed."); } PostTimeOutTask(); } @@ -494,7 +499,7 @@ void QuickFixManagerApplyTask::PostTimeOutTask() auto timeoutTask = [thisWeakPtr]() { auto applyTask = thisWeakPtr.lock(); if (applyTask == nullptr) { - HILOG_ERROR("Apply task is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Apply task is nullptr."); return; } @@ -502,14 +507,14 @@ void QuickFixManagerApplyTask::PostTimeOutTask() applyTask->RemoveSelf(); }; if (eventHandler_ == nullptr || !eventHandler_->PostTask(timeoutTask, TIMEOUT_TASK_NAME, TIMEOUT_TASK_DELAY_TIME)) { - HILOG_ERROR("Post delete task failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Post delete task failed."); } } void QuickFixManagerApplyTask::RemoveTimeoutTask() { if (eventHandler_ == nullptr) { - HILOG_ERROR("event handler is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "event handler is nullptr."); return; } eventHandler_->RemoveTask(TIMEOUT_TASK_NAME); @@ -519,47 +524,47 @@ bool QuickFixManagerApplyTask::SetQuickFixInfo(const std::shared_ptrToString(), nullptr, false); if (resultJson.is_discarded()) { - HILOG_ERROR("failed to parse json sting."); + TAG_LOGE(AAFwkTag::QUICKFIX, "failed to parse json sting."); return false; } if (!resultJson.contains(QUICK_FIX_BUNDLE_NAME) || !resultJson.at(QUICK_FIX_BUNDLE_NAME).is_string()) { - HILOG_ERROR("Invalid bundleName."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid bundleName."); return false; } bundleName_ = resultJson.at(QUICK_FIX_BUNDLE_NAME).get(); if (!resultJson.contains(QUICK_FIX_BUNDLE_VERSION_CODE) || !resultJson.at(QUICK_FIX_BUNDLE_VERSION_CODE).is_number()) { - HILOG_ERROR("Invalid bundle version code."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid bundle version code."); return false; } bundleVersionCode_ = resultJson.at(QUICK_FIX_BUNDLE_VERSION_CODE).get(); if (!resultJson.contains(QUICK_FIX_PATCH_VERSION_CODE) || !resultJson.at(QUICK_FIX_PATCH_VERSION_CODE).is_number()) { - HILOG_ERROR("Invalid patch version code."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid patch version code."); return false; } patchVersionCode_ = resultJson.at(QUICK_FIX_PATCH_VERSION_CODE).get(); if (!resultJson.contains(QUICK_FIX_IS_SO_CONTAINED) || !resultJson.at(QUICK_FIX_IS_SO_CONTAINED).is_boolean()) { - HILOG_ERROR("Invalid so status."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid so status."); return false; } isSoContained_ = resultJson.at(QUICK_FIX_IS_SO_CONTAINED).get(); if (!resultJson.contains(QUICK_FIX_TYPE) || !resultJson.at(QUICK_FIX_TYPE).is_number()) { - HILOG_ERROR("Invalid quickfix type."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid quickfix type."); return false; } type_ = static_cast(resultJson.at(QUICK_FIX_TYPE).get()); if (type_ != AppExecFwk::QuickFixType::PATCH && type_ != AppExecFwk::QuickFixType::HOT_RELOAD) { - HILOG_ERROR("Quick fix type is invalid."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Quick fix type is invalid."); return false; } if (!resultJson.contains(QUICK_FIX_MODULE_NAME) || !resultJson.at(QUICK_FIX_MODULE_NAME).is_array()) { - HILOG_ERROR("Invalid moduleName."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid moduleName."); return false; } moduleNames_.clear(); @@ -570,28 +575,28 @@ bool QuickFixManagerApplyTask::SetQuickFixInfo(const std::shared_ptr(type_)); + TAG_LOGI(AAFwkTag::QUICKFIX, "bundleName: %{public}s, bundleVersion: %{public}d, patchVersion: %{public}d," + "soContained: %{public}d, ""type: %{public}d.", bundleName_.c_str(), bundleVersionCode_, + patchVersionCode_, isSoContained_, static_cast(type_)); return true; } bool QuickFixManagerApplyTask::GetRunningState() { if (appMgr_ == nullptr) { - HILOG_ERROR("App manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "App manager is nullptr."); return false; } auto ret = appMgr_->GetAppRunningStateByBundleName(bundleName_); - HILOG_INFO("Process running state of [%{public}s] is %{public}d.", bundleName_.c_str(), ret); + TAG_LOGI(AAFwkTag::QUICKFIX, "Process running state of [%{public}s] is %{public}d.", bundleName_.c_str(), ret); return ret; } void QuickFixManagerApplyTask::NotifyApplyStatus(int32_t resultCode) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); Want want; if (GetTaskType() == TaskType::QUICK_FIX_APPLY) { @@ -611,7 +616,7 @@ void QuickFixManagerApplyTask::NotifyApplyStatus(int32_t resultCode) want.SetParam(REVOKE_RESULT, QuickFixErrorUtil::GetErrorCode(resultCode)); want.SetParam(REVOKE_RESULT_INFO, QuickFixErrorUtil::GetErrorMessage(resultCode)); } else { - HILOG_WARN("Invalid task type, Can not publish common event"); + TAG_LOGW(AAFwkTag::QUICKFIX, "Invalid task type, Can not publish common event"); return; } @@ -628,12 +633,12 @@ void QuickFixManagerApplyTask::PostNotifyLoadRepairPatchTask() auto loadPatchTask = [thisWeakPtr, callback]() { auto applyTask = thisWeakPtr.lock(); if (applyTask == nullptr) { - HILOG_ERROR("Apply task is nullptr"); + TAG_LOGE(AAFwkTag::QUICKFIX, "Apply task is nullptr"); return; } if (applyTask->appMgr_ == nullptr) { - HILOG_ERROR("Appmgr is nullptr"); + TAG_LOGE(AAFwkTag::QUICKFIX, "Appmgr is nullptr"); applyTask->NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); applyTask->RemoveSelf(); return; @@ -641,13 +646,13 @@ void QuickFixManagerApplyTask::PostNotifyLoadRepairPatchTask() auto ret = applyTask->appMgr_->NotifyLoadRepairPatch(applyTask->bundleName_, callback); if (ret != 0) { - HILOG_ERROR("Notify app load patch failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Notify app load patch failed."); applyTask->NotifyApplyStatus(QUICK_FIX_NOTIFY_LOAD_PATCH_FAILED); applyTask->RemoveSelf(); } }; if (eventHandler_ == nullptr || !eventHandler_->PostTask(loadPatchTask, "QuickFixManager:loadPatchTask")) { - HILOG_ERROR("Post delete task failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Post delete task failed."); } PostTimeOutTask(); } @@ -659,12 +664,12 @@ void QuickFixManagerApplyTask::PostNotifyUnloadRepairPatchTask() auto unloadPatchTask = [thisWeakPtr, callback]() { auto applyTask = thisWeakPtr.lock(); if (applyTask == nullptr) { - HILOG_ERROR("Apply task is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Apply task is nullptr."); return; } if (applyTask->appMgr_ == nullptr) { - HILOG_ERROR("Appmgr is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Appmgr is nullptr."); applyTask->NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); applyTask->RemoveSelf(); return; @@ -672,13 +677,13 @@ void QuickFixManagerApplyTask::PostNotifyUnloadRepairPatchTask() auto ret = applyTask->appMgr_->NotifyUnLoadRepairPatch(applyTask->bundleName_, callback); if (ret != 0) { - HILOG_ERROR("Notify app unload patch failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Notify app unload patch failed."); applyTask->NotifyApplyStatus(QUICK_FIX_NOTIFY_UNLOAD_PATCH_FAILED); applyTask->RemoveSelf(); } }; if (eventHandler_ == nullptr || !eventHandler_->PostTask(unloadPatchTask, "QuickFixManager:unloadPatchTask")) { - HILOG_ERROR("Post delete task failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Post delete task failed."); } PostTimeOutTask(); } @@ -690,12 +695,12 @@ void QuickFixManagerApplyTask::PostNotifyHotReloadPageTask() auto reloadPageTask = [thisWeakPtr, callback]() { auto applyTask = thisWeakPtr.lock(); if (applyTask == nullptr) { - HILOG_ERROR("Apply task is nullptr!"); + TAG_LOGE(AAFwkTag::QUICKFIX, "Apply task is nullptr!"); return; } if (applyTask->appMgr_ == nullptr) { - HILOG_ERROR("Appmgr is nullptr!"); + TAG_LOGE(AAFwkTag::QUICKFIX, "Appmgr is nullptr!"); applyTask->NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); applyTask->RemoveSelf(); return; @@ -703,22 +708,22 @@ void QuickFixManagerApplyTask::PostNotifyHotReloadPageTask() auto ret = applyTask->appMgr_->NotifyHotReloadPage(applyTask->bundleName_, callback); if (ret != 0) { - HILOG_ERROR("Notify app reload page failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Notify app reload page failed."); applyTask->NotifyApplyStatus(QUICK_FIX_NOTIFY_RELOAD_PAGE_FAILED); applyTask->RemoveSelf(); } }; if (eventHandler_ == nullptr || !eventHandler_->PostTask(reloadPageTask, "QuickFixManager:reloadPageTask")) { - HILOG_ERROR("Post delete task failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Post delete task failed."); } PostTimeOutTask(); } void QuickFixManagerApplyTask::RegAppStateObserver() { - HILOG_DEBUG("Register application state observer."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Register application state observer."); if (appMgr_ == nullptr) { - HILOG_ERROR("Appmgr is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Appmgr is nullptr."); NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); RemoveSelf(); return; @@ -730,31 +735,31 @@ void QuickFixManagerApplyTask::RegAppStateObserver() shared_from_this()); auto ret = appMgr_->RegisterApplicationStateObserver(callback, bundleNameList); if (ret != 0) { - HILOG_ERROR("Register application state observer failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Register application state observer failed."); NotifyApplyStatus(QUICK_FIX_REGISTER_OBSERVER_FAILED); RemoveSelf(); return; } appStateCallback_ = callback; - HILOG_DEBUG("Register application state observer succeed."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Register application state observer succeed."); } void QuickFixManagerApplyTask::UnregAppStateObserver() { - HILOG_DEBUG("Unregister application state observer."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Unregister application state observer."); if (appMgr_ == nullptr || appStateCallback_ == nullptr) { - HILOG_ERROR("Appmgr or callback is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Appmgr or callback is nullptr."); return; } auto ret = appMgr_->UnregisterApplicationStateObserver(appStateCallback_); if (ret != 0) { - HILOG_ERROR("Unregister application state observer failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Unregister application state observer failed."); return; } - HILOG_DEBUG("Unregister application state observer succeed."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Unregister application state observer succeed."); } void QuickFixManagerApplyTask::RemoveSelf() @@ -781,7 +786,7 @@ void QuickFixManagerApplyTask::PostRevokeQuickFixTask() auto revokeTask = [thisWeakPtr] () { auto applyTask = thisWeakPtr.lock(); if (applyTask == nullptr) { - HILOG_ERROR("Revoke task is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Revoke task is nullptr."); return; } if (applyTask->GetRunningState()) { @@ -792,7 +797,7 @@ void QuickFixManagerApplyTask::PostRevokeQuickFixTask() }; if (eventHandler_ == nullptr || !eventHandler_->PostTask(revokeTask, "QuickFixManager:revokeTask")) { - HILOG_ERROR("Post revoke task failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Post revoke task failed."); } PostTimeOutTask(); } @@ -813,7 +818,7 @@ void QuickFixManagerApplyTask::HandleRevokeQuickFixAppRunning() void QuickFixManagerApplyTask::HandleRevokePatchSwitched() { - HILOG_DEBUG("Function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function called."); // process is run, notify app unload patch if (GetRunningState()) { PostRevokeQuickFixNotifyUnloadPatchTask(); @@ -828,7 +833,7 @@ void QuickFixManagerApplyTask::PostRevokeQuickFixNotifyUnloadPatchTask() { // notify app process unload patch if (appMgr_ == nullptr) { - HILOG_ERROR("App manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "App manager is nullptr."); NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); RemoveSelf(); return; @@ -839,12 +844,12 @@ void QuickFixManagerApplyTask::PostRevokeQuickFixNotifyUnloadPatchTask() new (std::nothrow) RevokeQuickFixNotifyCallback(shared_from_this()); auto ret = appMgr_->NotifyUnLoadRepairPatch(bundleName_, callback); if (ret != 0) { - HILOG_ERROR("Notify app unload patch failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Notify app unload patch failed."); NotifyApplyStatus(QUICK_FIX_NOTIFY_UNLOAD_PATCH_FAILED); RemoveSelf(); } - HILOG_DEBUG("Function end."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function end."); } void QuickFixManagerApplyTask::PostRevokeQuickFixDeleteTask() @@ -852,7 +857,7 @@ void QuickFixManagerApplyTask::PostRevokeQuickFixDeleteTask() sptr callback = new (std::nothrow) RevokeQuickFixTaskCallback( shared_from_this()); if (bundleQfMgr_ == nullptr) { - HILOG_ERROR("Bundle quick fix manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Bundle quick fix manager is nullptr."); NotifyApplyStatus(QUICK_FIX_BUNDLEMGR_INVALID); RemoveSelf(); return; @@ -861,18 +866,18 @@ void QuickFixManagerApplyTask::PostRevokeQuickFixDeleteTask() // call delete patch to bms auto ret = bundleQfMgr_->DeleteQuickFix(bundleName_, callback); if (ret != ERR_OK) { - HILOG_ERROR("Delete quick fix failed with %{public}d.", ret); + TAG_LOGE(AAFwkTag::QUICKFIX, "Delete quick fix failed with %{public}d.", ret); NotifyApplyStatus(QUICK_FIX_DELETE_FAILED); RemoveSelf(); return; } - HILOG_DEBUG("Function end."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function end."); } void QuickFixManagerApplyTask::PostRevokeQuickFixProcessDiedTask() { - HILOG_DEBUG("Function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function called."); // app process died HandleRevokeQuickFixAppStop(); PostTimeOutTask(); @@ -883,7 +888,7 @@ void QuickFixManagerApplyTask::HandleRevokeQuickFixAppStop() sptr callback = new (std::nothrow) RevokeQuickFixTaskCallback( shared_from_this()); if (bundleQfMgr_ == nullptr) { - HILOG_ERROR("Bundle quick fix manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Bundle quick fix manager is nullptr."); NotifyApplyStatus(QUICK_FIX_BUNDLEMGR_INVALID); RemoveSelf(); return; @@ -891,20 +896,20 @@ void QuickFixManagerApplyTask::HandleRevokeQuickFixAppStop() auto ret = bundleQfMgr_->SwitchQuickFix(bundleName_, false, callback); if (ret != ERR_OK) { - HILOG_ERROR("Switch quick fix failed with %{public}d.", ret); + TAG_LOGE(AAFwkTag::QUICKFIX, "Switch quick fix failed with %{public}d.", ret); NotifyApplyStatus(QUICK_FIX_SWICH_FAILED); RemoveSelf(); return; } - HILOG_DEBUG("Function end."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function end."); } void QuickFixManagerApplyTask::HandleRevokePatchDeleted() { NotifyApplyStatus(QUICK_FIX_OK); RemoveSelf(); - HILOG_DEBUG("Function end."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function end."); } } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/quickfixmgr/src/quick_fix_manager_service.cpp b/services/quickfixmgr/src/quick_fix_manager_service.cpp index 7a7f0bb947..0b9b5a0bc4 100644 --- a/services/quickfixmgr/src/quick_fix_manager_service.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -16,6 +16,7 @@ #include "quick_fix_manager_service.h" #include "bundle_mgr_helper.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" #include "permission_verification.h" @@ -42,13 +43,13 @@ bool QuickFixManagerService::Init() std::lock_guard lock(mutex_); eventRunner_ = AppExecFwk::EventRunner::Create("QuickFixMgrSvrMain"); if (eventRunner_ == nullptr) { - HILOG_ERROR("Create event runner failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Create event runner failed."); return false; } eventHandler_ = std::make_shared(eventRunner_); if (eventHandler_ == nullptr) { - HILOG_ERROR("Create event handler failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Create event handler failed."); return false; } @@ -58,9 +59,9 @@ bool QuickFixManagerService::Init() int32_t QuickFixManagerService::ApplyQuickFix(const std::vector &quickFixFiles, bool isDebug) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_DEBUG("Function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function called."); if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { - HILOG_ERROR("The caller is not system-app, can not use system-api."); + TAG_LOGE(AAFwkTag::QUICKFIX, "The caller is not system-app, can not use system-api."); return QUICK_FIX_NOT_SYSTEM_APP; } if (!AAFwk::PermissionVerification::GetInstance()->VerifyInstallBundlePermission()) { @@ -69,20 +70,20 @@ int32_t QuickFixManagerService::ApplyQuickFix(const std::vector &qu auto bundleQfMgr = QuickFixUtil::GetBundleQuickFixMgrProxy(); if (bundleQfMgr == nullptr) { - HILOG_ERROR("Bundle quick fix manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Bundle quick fix manager is nullptr."); return QUICK_FIX_CONNECT_FAILED; } auto appMgr = QuickFixUtil::GetAppManagerProxy(); if (appMgr == nullptr) { - HILOG_ERROR("App manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "App manager is nullptr."); return QUICK_FIX_CONNECT_FAILED; } auto applyTask = std::make_shared(bundleQfMgr, appMgr, eventHandler_, this); AddApplyTask(applyTask); applyTask->Run(quickFixFiles, isDebug); - HILOG_DEBUG("Function finished."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function finished."); return QUICK_FIX_OK; } @@ -90,9 +91,9 @@ int32_t QuickFixManagerService::GetApplyedQuickFixInfo(const std::string &bundle ApplicationQuickFixInfo &quickFixInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { - HILOG_ERROR("The caller is not system-app, can not use system-api"); + TAG_LOGE(AAFwkTag::QUICKFIX, "The caller is not system-app, can not use system-api"); return QUICK_FIX_NOT_SYSTEM_APP; } if (!AAFwk::PermissionVerification::GetInstance()->VerifyGetBundleInfoPrivilegedPermission()) { @@ -101,14 +102,14 @@ int32_t QuickFixManagerService::GetApplyedQuickFixInfo(const std::string &bundle auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { - HILOG_ERROR("Failed to get bundle manager helper!"); + TAG_LOGE(AAFwkTag::QUICKFIX, "Failed to get bundle manager helper!"); return QUICK_FIX_CONNECT_FAILED; } AppExecFwk::BundleInfo bundleInfo; if (!bundleMgrHelper->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, AppExecFwk::Constants::ANY_USERID)) { - HILOG_ERROR("Get bundle info failed!"); + TAG_LOGE(AAFwkTag::QUICKFIX, "Get bundle info failed!"); return QUICK_FIX_GET_BUNDLE_INFO_FAILED; } @@ -117,26 +118,26 @@ int32_t QuickFixManagerService::GetApplyedQuickFixInfo(const std::string &bundle quickFixInfo.bundleVersionName = bundleInfo.versionName; quickFixInfo.appqfInfo = bundleInfo.applicationInfo.appQuickFix.deployedAppqfInfo; - HILOG_DEBUG("function finished."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function finished."); return QUICK_FIX_OK; } int32_t QuickFixManagerService::RevokeQuickFix(const std::string &bundleName) { - HILOG_DEBUG("Called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Called."); if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { - HILOG_ERROR("The caller is not system-app, can not use system-api"); + TAG_LOGE(AAFwkTag::QUICKFIX, "The caller is not system-app, can not use system-api"); return QUICK_FIX_NOT_SYSTEM_APP; } if (!AAFwk::PermissionVerification::GetInstance()->VerifyGetBundleInfoPrivilegedPermission() || !AAFwk::PermissionVerification::GetInstance()->VerifyInstallBundlePermission()) { - HILOG_ERROR("Permission verification failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Permission verification failed."); return QUICK_FIX_VERIFY_PERMISSION_FAILED; } if (CheckTaskRunningState(bundleName)) { - HILOG_ERROR("Has a apply quick fix task."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Has a apply quick fix task."); return QUICK_FIX_DEPLOYING_TASK; } @@ -144,32 +145,32 @@ int32_t QuickFixManagerService::RevokeQuickFix(const std::string &bundleName) auto isSoContained = false; auto ret = GetQuickFixInfo(bundleName, patchExists, isSoContained); if (ret != QUICK_FIX_OK || !patchExists) { - HILOG_ERROR("Get bundle info failed or patch does not exist."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Get bundle info failed or patch does not exist."); return QUICK_FIX_GET_BUNDLE_INFO_FAILED; } auto appMgr = QuickFixUtil::GetAppManagerProxy(); if (appMgr == nullptr) { - HILOG_ERROR("App manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "App manager is nullptr."); return QUICK_FIX_CONNECT_FAILED; } auto bundleQfMgr = QuickFixUtil::GetBundleQuickFixMgrProxy(); if (bundleQfMgr == nullptr) { - HILOG_ERROR("Bundle quick fix manager is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Bundle quick fix manager is nullptr."); return QUICK_FIX_CONNECT_FAILED; } auto applyTask = std::make_shared(bundleQfMgr, appMgr, eventHandler_, this); if (applyTask == nullptr) { - HILOG_ERROR("Task connect failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Task connect failed."); return QUICK_FIX_CONNECT_FAILED; } applyTask->InitRevokeTask(bundleName, isSoContained); AddApplyTask(applyTask); applyTask->RunRevoke(); - HILOG_DEBUG("Function finished."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Function finished."); return QUICK_FIX_OK; } @@ -200,7 +201,7 @@ bool QuickFixManagerService::CheckTaskRunningState(const std::string &bundleName } } - HILOG_DEBUG("bundleName %{public}s not found in tasks.", bundleName.c_str()); + TAG_LOGD(AAFwkTag::QUICKFIX, "bundleName %{public}s not found in tasks.", bundleName.c_str()); return false; } @@ -208,14 +209,14 @@ int32_t QuickFixManagerService::GetQuickFixInfo(const std::string &bundleName, b { auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { - HILOG_ERROR("Failed to get bundle manager helper."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Failed to get bundle manager helper."); return QUICK_FIX_CONNECT_FAILED; } AppExecFwk::BundleInfo bundleInfo; if (!bundleMgrHelper->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, AppExecFwk::Constants::ANY_USERID)) { - HILOG_ERROR("Get bundle info failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Get bundle info failed."); return QUICK_FIX_GET_BUNDLE_INFO_FAILED; } diff --git a/services/quickfixmgr/src/quick_fix_manager_service_ability.cpp b/services/quickfixmgr/src/quick_fix_manager_service_ability.cpp index 89e2b8c73e..5a8dca5bb9 100644 --- a/services/quickfixmgr/src/quick_fix_manager_service_ability.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_service_ability.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -15,6 +15,7 @@ #include "quick_fix_manager_service_ability.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "system_ability_definition.h" @@ -25,44 +26,44 @@ REGISTER_SYSTEM_ABILITY_BY_ID(QuickFixManagerServiceAbility, QUICK_FIX_MGR_SERVI QuickFixManagerServiceAbility::QuickFixManagerServiceAbility(const int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate), service_(nullptr) { - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); } QuickFixManagerServiceAbility::~QuickFixManagerServiceAbility() { - HILOG_DEBUG("function called."); + TAG_LOGD(AAFwkTag::QUICKFIX, "function called."); } void QuickFixManagerServiceAbility::OnStart() { - HILOG_INFO("function called."); + TAG_LOGI(AAFwkTag::QUICKFIX, "function called."); if (service_ != nullptr) { - HILOG_DEBUG("Quick fix manager service has started."); + TAG_LOGD(AAFwkTag::QUICKFIX, "Quick fix manager service has started."); return; } service_ = QuickFixManagerService::GetInstance(); if (service_ == nullptr) { - HILOG_ERROR("instance is nullptr."); + TAG_LOGE(AAFwkTag::QUICKFIX, "instance is nullptr."); return; } if (!service_->Init()) { - HILOG_ERROR("init failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "init failed."); return; } if (!Publish(service_)) { - HILOG_ERROR("Publish failed."); + TAG_LOGE(AAFwkTag::QUICKFIX, "Publish failed."); return; } - HILOG_INFO("Quick fix manager service start succeed."); + TAG_LOGI(AAFwkTag::QUICKFIX, "Quick fix manager service start succeed."); } void QuickFixManagerServiceAbility::OnStop() { - HILOG_INFO("function called."); + TAG_LOGI(AAFwkTag::QUICKFIX, "function called."); service_ = nullptr; } } // namespace AAFwk diff --git a/services/uripermmgr/src/proxy_authorization_uri_config.cpp b/services/uripermmgr/src/proxy_authorization_uri_config.cpp index 4d813a57df..a7ecb0af65 100644 --- a/services/uripermmgr/src/proxy_authorization_uri_config.cpp +++ b/services/uripermmgr/src/proxy_authorization_uri_config.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -20,6 +20,7 @@ #include "accesstoken_kit.h" #include "parameters.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" namespace OHOS { @@ -36,7 +37,7 @@ const std::string PROCESS_NAME = "processName"; void ProxyAuthorizationUriConfig::LoadConfiguration() { - HILOG_DEBUG("call"); + TAG_LOGD(AAFwkTag::URIPERMMGR, "call"); nlohmann::json jsonBuf; std::string deviceType = OHOS::system::GetDeviceType(); if (deviceType == "2in1") { @@ -74,7 +75,7 @@ bool ProxyAuthorizationUriConfig::IsAuthorizationUriAllowed(uint32_t fromTokenId void ProxyAuthorizationUriConfig::LoadAllowedList(const nlohmann::json &object) { if (!object.contains(PROXY_AUTHORIZATION_URI_NAME)) { - HILOG_ERROR("Proxy authorization uri config not existed."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Proxy authorization uri config not existed."); return; } @@ -94,7 +95,7 @@ void ProxyAuthorizationUriConfig::LoadAllowedList(const nlohmann::json &object) bool ProxyAuthorizationUriConfig::ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf) { if (access(filePath.c_str(), F_OK) != 0) { - HILOG_DEBUG("%{public}s, not existed", filePath.c_str()); + TAG_LOGD(AAFwkTag::URIPERMMGR, "%{public}s, not existed", filePath.c_str()); return false; } @@ -104,14 +105,14 @@ bool ProxyAuthorizationUriConfig::ReadFileInfoJson(const std::string &filePath, in.open(filePath, std::ios_base::in); if (!in.is_open()) { strerror_r(errno, errBuf, sizeof(errBuf)); - HILOG_ERROR("the file cannot be open due to %{public}s", errBuf); + TAG_LOGE(AAFwkTag::URIPERMMGR, "the file cannot be open due to %{public}s", errBuf); return false; } in.seekg(0, std::ios::end); int64_t size = in.tellg(); if (size <= 0) { - HILOG_ERROR("the file is an empty file"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "the file is an empty file"); in.close(); return false; } @@ -120,7 +121,7 @@ bool ProxyAuthorizationUriConfig::ReadFileInfoJson(const std::string &filePath, jsonBuf = nlohmann::json::parse(in, nullptr, false); in.close(); if (jsonBuf.is_discarded()) { - HILOG_ERROR("bad profile file"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "bad profile file"); return false; } diff --git a/services/uripermmgr/src/uri_permission_manager_service.cpp b/services/uripermmgr/src/uri_permission_manager_service.cpp index 612615a9e6..d0596a6744 100644 --- a/services/uripermmgr/src/uri_permission_manager_service.cpp +++ b/services/uripermmgr/src/uri_permission_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -15,6 +15,7 @@ #include "uri_permission_manager_service.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "if_system_ability_manager.h" #include "ipc_skeleton.h" @@ -37,7 +38,7 @@ UriPermissionManagerService::~UriPermissionManagerService() void UriPermissionManagerService::OnStart() { - HILOG_INFO("UriPermissionManagerService start is triggered."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "UriPermissionManagerService start is triggered."); if (!Init()) { HILOG_ERROR("init failed."); return; @@ -49,14 +50,14 @@ void UriPermissionManagerService::OnStart() HILOG_ERROR("fail to register to system ability manager"); return; } - HILOG_INFO("register to system ability manager success"); + TAG_LOGI(AAFwkTag::URIPERMMGR, "register to system ability manager success"); registerToService_ = true; } } void UriPermissionManagerService::OnStop() { - HILOG_INFO("OnStop is called."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "OnStop is called."); SelfClean(); } @@ -68,7 +69,7 @@ bool UriPermissionManagerService::IsServiceReady() const bool UriPermissionManagerService::Init() { if (ready_) { - HILOG_WARN("init more than one time."); + TAG_LOGW(AAFwkTag::URIPERMMGR, "init more than one time."); return true; } diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index 6f4dd524c6..2c3245d3c2 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -20,6 +20,7 @@ #include "ability_manager_errors.h" #include "accesstoken_kit.h" #include "app_utils.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "if_system_ability_manager.h" #include "in_process_call_wrapper.h" @@ -55,19 +56,20 @@ bool UriPermissionManagerStubImpl::VerifyUriPermission(const Uri &uri, uint32_t { // verify if tokenId have uri permission record auto uriStr = uri.ToString(); - HILOG_INFO("uri is %{private}s, flag is %{public}u, tokenId is %{public}u", uriStr.c_str(), flag, tokenId); + TAG_LOGI(AAFwkTag::URIPERMMGR, "uri is %{private}s, flag is %{public}u, tokenId is %{public}u", uriStr.c_str(), + flag, tokenId); std::lock_guard guard(mutex_); auto search = uriMap_.find(uriStr); if (search != uriMap_.end()) { auto& list = search->second; for (auto it = list.begin(); it != list.end(); it++) { if ((it->targetTokenId == tokenId) && ((it->flag | Want::FLAG_AUTH_READ_URI_PERMISSION) & flag) != 0) { - HILOG_INFO("have uri permission."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "have uri permission."); return true; } } } - HILOG_INFO("have no uri permission"); + TAG_LOGI(AAFwkTag::URIPERMMGR, "have no uri permission"); return false; } @@ -79,7 +81,7 @@ bool UriPermissionManagerStubImpl::IsAuthorizationUriAllowed(uint32_t fromTokenI int UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned int flag, const std::string targetBundleName, int32_t appIndex, uint32_t initiatorTokenId) { - HILOG_DEBUG("CALL: appIndex is %{public}d.", appIndex); + TAG_LOGD(AAFwkTag::URIPERMMGR, "CALL: appIndex is %{public}d.", appIndex); std::vector uriVec = { uri }; return GrantUriPermission(uriVec, flag, targetBundleName, appIndex, initiatorTokenId); } @@ -87,12 +89,12 @@ int UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned in int UriPermissionManagerStubImpl::GrantUriPermission(const std::vector &uriVec, unsigned int flag, const std::string targetBundleName, int32_t appIndex, uint32_t initiatorTokenId) { - HILOG_DEBUG("CALL: appIndex is %{public}d, uriVec size is %{public}zu", appIndex, uriVec.size()); + TAG_LOGD(AAFwkTag::URIPERMMGR, "CALL: appIndex is %{public}d, uriVec size is %{public}zu", appIndex, uriVec.size()); if (AppUtils::GetInstance().IsGrantPersistUriPermission()) { bool isSystemAppCall = PermissionVerification::GetInstance()->IsSystemAppCall(); // IsSACall function used for visibility checks. if (!isSystemAppCall && !PermissionVerification::GetInstance()->IsSACall()) { - HILOG_ERROR("Not system application or SA call."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Not system application or SA call."); return INNER_ERR; } return GrantUriPermissionFor2In1Inner( @@ -104,7 +106,7 @@ int UriPermissionManagerStubImpl::GrantUriPermission(const std::vector &uri int UriPermissionManagerStubImpl::GrantUriPermissionInner(const std::vector &uriVec, unsigned int flag, const std::string targetBundleName, int32_t appIndex, uint32_t initiatorTokenId) { - HILOG_DEBUG("Called."); + TAG_LOGD(AAFwkTag::URIPERMMGR, "Called."); auto checkResult = CheckRule(flag); if (checkResult != ERR_OK) { return checkResult; @@ -129,13 +131,13 @@ int checkPersistPermission(uint64_t tokenId, const std::vector &poli for (size_t i = 0; i < policy.size(); i++) { result.emplace_back(true); } - HILOG_INFO("Called, result size is %{public}zu", result.size()); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Called, result size is %{public}zu", result.size()); return 0; } int32_t setPolicy(uint64_t tokenId, const std::vector &policy, uint64_t policyFlag) { - HILOG_INFO("Called, policy size is %{public}zu", policy.size()); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Called, policy size is %{public}zu", policy.size()); return 0; } @@ -144,7 +146,7 @@ int persistPermission(const std::vector &policy, std::vectorJudgeSandboxByPid(callerPid, isSandbox) != ERR_OK) { - HILOG_ERROR("JudgeSandboxByPid failed."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "JudgeSandboxByPid failed."); return INNER_ERR; } if (isSandbox) { - HILOG_ERROR("Sandbox application can not grant URI permission."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Sandbox application can not grant URI permission."); return ERR_CODE_GRANT_URI_PERMISSION; } if ((flag & (Want::FLAG_AUTH_READ_URI_PERMISSION | Want::FLAG_AUTH_WRITE_URI_PERMISSION)) == 0) { - HILOG_WARN("UriPermissionManagerStubImpl::GrantUriPermission: The param flag is invalid."); + TAG_LOGW(AAFwkTag::URIPERMMGR, "UriPermissionManagerStubImpl::GrantUriPermission: The param flag is invalid."); return ERR_CODE_INVALID_URI_FLAG; } return ERR_OK; @@ -177,9 +179,9 @@ int UriPermissionManagerStubImpl::CheckRule(unsigned int flag) int UriPermissionManagerStubImpl::GrantUriPermissionFor2In1(const std::vector &uriVec, unsigned int flag, const std::string &targetBundleName, int32_t appIndex, bool isSystemAppCall) { - HILOG_DEBUG("Called."); + TAG_LOGD(AAFwkTag::URIPERMMGR, "Called."); if (!IsFoundationCall()) { - HILOG_ERROR("Not foundation call."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Not foundation call."); return INNER_ERR; } return GrantUriPermissionFor2In1Inner(uriVec, flag, targetBundleName, appIndex, isSystemAppCall); @@ -192,7 +194,7 @@ int UriPermissionManagerStubImpl::AddTempUriPermission(const std::string &uri, u auto search = uriMap_.find(uri); GrantInfo info = { flag, fromTokenId, targetTokenId, autoRemove }; if (search == uriMap_.end()) { - HILOG_INFO("Insert an uri r/w permission."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Insert an uri r/w permission."); std::list infoList = { info }; uriMap_.emplace(uri, infoList); return ERR_OK; @@ -200,18 +202,19 @@ int UriPermissionManagerStubImpl::AddTempUriPermission(const std::string &uri, u auto& infoList = search->second; for (auto& item : infoList) { if (item.fromTokenId == fromTokenId && item.targetTokenId == targetTokenId) { - HILOG_DEBUG("Item: flag = %{public}i, fromTokenId = %{public}i, targetTokenId = %{public}i," - "autoRemove = %{public}i", item.flag, item.fromTokenId, item.targetTokenId, item.autoRemove); + TAG_LOGD(AAFwkTag::URIPERMMGR, "Item: flag = %{public}i, fromTokenId = %{public}i," + "targetTokenId = %{public}i, autoRemove = %{public}i", item.flag, item.fromTokenId, + item.targetTokenId, item.autoRemove); if ((flag & (item.flag | Want::FLAG_AUTH_READ_URI_PERMISSION)) == 0) { - HILOG_INFO("Update uri r/w permission."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Update uri r/w permission."); item.flag = flag; } else { - HILOG_INFO("uri permission has granted, not to grant again."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "uri permission has granted, not to grant again."); } return ERR_OK; } } - HILOG_INFO("Insert an new uri permission record."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Insert an new uri permission record."); infoList.emplace_back(info); return ERR_OK; } @@ -219,22 +222,23 @@ int UriPermissionManagerStubImpl::AddTempUriPermission(const std::string &uri, u int UriPermissionManagerStubImpl::GrantUriPermissionImpl(const Uri &uri, unsigned int flag, TokenId callerTokenId, TokenId targetTokenId, uint32_t autoRemove) { - HILOG_INFO("uri = %{private}s, flag = %{public}i, callerTokenId = %{public}i, targetTokenId = %{public}i," - "autoRemove = %{public}i", uri.ToString().c_str(), flag, callerTokenId, targetTokenId, autoRemove); + TAG_LOGI(AAFwkTag::URIPERMMGR, "uri = %{private}s, flag = %{public}i, callerTokenId = %{public}i," + "targetTokenId = %{public}i, autoRemove = %{public}i", uri.ToString().c_str(), flag, callerTokenId, + targetTokenId, autoRemove); ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID); if (storageManager_ == nullptr) { - HILOG_ERROR("ConnectManager failed"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "ConnectManager failed"); return INNER_ERR; } auto uriStr = uri.ToString(); std::vector uriVec = { uriStr }; auto resVec = storageManager_->CreateShareFile(uriVec, targetTokenId, flag); if (resVec.size() == 0) { - HILOG_ERROR("storageManager resVec is empty."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "storageManager resVec is empty."); return INNER_ERR; } if (resVec[0] != 0 && resVec[0] != -EEXIST) { - HILOG_ERROR("failed to CreateShareFile."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "failed to CreateShareFile."); return INNER_ERR; } AddTempUriPermission(uriStr, flag, callerTokenId, targetTokenId, autoRemove); @@ -246,12 +250,12 @@ int UriPermissionManagerStubImpl::GrantSingleUriPermission(const Uri &uri, unsig uint32_t targetTokenId, uint32_t autoRemove) { if (!CheckUriTypeIsValid(uri)) { - HILOG_ERROR("Check uri type failed, uri is %{private}s", uri.ToString().c_str()); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Check uri type failed, uri is %{private}s", uri.ToString().c_str()); return ERR_CODE_INVALID_URI_TYPE; } auto permission = IsAuthorizationUriAllowed(callerTokenId); if (!permission && !CheckUriPermission(uri, flag, callerTokenId)) { - HILOG_WARN("No permission, uri is %{private}s, callerTokenId is %{public}u", + TAG_LOGW(AAFwkTag::URIPERMMGR, "No permission, uri is %{private}s, callerTokenId is %{public}u", uri.ToString().c_str(), callerTokenId); return CHECK_PERMISSION_FAILED; } @@ -261,20 +265,20 @@ int UriPermissionManagerStubImpl::GrantSingleUriPermission(const Uri &uri, unsig int UriPermissionManagerStubImpl::GrantBatchUriPermissionImpl(const std::vector &uriVec, unsigned int flag, TokenId callerTokenId, TokenId targetTokenId, uint32_t autoRemove) { - HILOG_INFO("callerTokenId is %{public}u, targetTokenId is %{public}u, flag is %{public}i, list size is %{public}zu", - callerTokenId, targetTokenId, flag, uriVec.size()); + TAG_LOGI(AAFwkTag::URIPERMMGR, "callerTokenId is %{public}u, targetTokenId is %{public}u, flag is %{public}i," + "list size is %{public}zu", callerTokenId, targetTokenId, flag, uriVec.size()); ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID); if (storageManager_ == nullptr) { - HILOG_ERROR("ConnectManager failed."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "ConnectManager failed."); return INNER_ERR; } auto resVec = storageManager_->CreateShareFile(uriVec, targetTokenId, flag); if (resVec.size() == 0) { - HILOG_ERROR("Failed to createShareFile, storageManager resVec is empty."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Failed to createShareFile, storageManager resVec is empty."); return INNER_ERR; } if (resVec.size() != uriVec.size()) { - HILOG_ERROR("Failed to createShareFile, ret is %{public}u", resVec[0]); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Failed to createShareFile, ret is %{public}u", resVec[0]); return resVec[0]; } EventInfo eventInfo; @@ -283,7 +287,7 @@ int UriPermissionManagerStubImpl::GrantBatchUriPermissionImpl(const std::vector< for (size_t i = 0; i < uriVec.size(); i++) { auto ret = resVec[i]; if (ret != 0 && ret != -EEXIST) { - HILOG_ERROR("failed to CreateShareFile."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "failed to CreateShareFile."); continue; } AddTempUriPermission(uriVec[i], flag, callerTokenId, targetTokenId, autoRemove); @@ -293,7 +297,7 @@ int UriPermissionManagerStubImpl::GrantBatchUriPermissionImpl(const std::vector< } successCount++; } - HILOG_INFO("total %{public}d uri permissions added.", successCount); + TAG_LOGI(AAFwkTag::URIPERMMGR, "total %{public}d uri permissions added.", successCount); if (successCount == 0) { return INNER_ERR; } @@ -307,11 +311,11 @@ int UriPermissionManagerStubImpl::GrantBatchUriPermission(const std::vector auto permission = IsAuthorizationUriAllowed(callerTokenId); for (const auto &uri : uriVec) { if (!CheckUriTypeIsValid(uri)) { - HILOG_WARN("Check uri type failed, "); + TAG_LOGW(AAFwkTag::URIPERMMGR, "Check uri type failed, "); continue; } if (!permission && !CheckUriPermission(uri, flag, callerTokenId)) { - HILOG_WARN("No permission, uri is %{private}s, callerTokenId is %{public}u", + TAG_LOGW(AAFwkTag::URIPERMMGR, "No permission, uri is %{private}s, callerTokenId is %{public}u", uri.ToString().c_str(), callerTokenId); continue; } @@ -322,9 +326,9 @@ int UriPermissionManagerStubImpl::GrantBatchUriPermission(const std::vector void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId) { - HILOG_INFO("Start to remove uri permission."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Start to remove uri permission."); if (!IsFoundationCall()) { - HILOG_ERROR("RevokeUriPermission can only be called by foundation"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "RevokeUriPermission can only be called by foundation"); return; } std::vector uriList; @@ -334,7 +338,7 @@ void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId) auto& list = iter->second; for (auto it = list.begin(); it != list.end(); it++) { if (it->targetTokenId == tokenId && it->autoRemove) { - HILOG_INFO("Erase an info form list."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Erase an info form list."); list.erase(it); uriList.emplace_back(iter->first); break; @@ -350,7 +354,7 @@ void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId) ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID); if (storageManager_ == nullptr) { - HILOG_ERROR("ConnectManager failed"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "ConnectManager failed"); return; } @@ -361,9 +365,9 @@ void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId) int UriPermissionManagerStubImpl::RevokeAllUriPermissions(uint32_t tokenId) { - HILOG_INFO("Start to remove all uri permission for uninstalled app or clear app data."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Start to remove all uri permission for uninstalled app or clear app data."); if (!IsFoundationCall()) { - HILOG_ERROR("RevokeAllUriPermissions can only be called by foundation"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "RevokeAllUriPermissions can only be called by foundation"); return CHECK_PERMISSION_FAILED; } std::map> uriLists; @@ -375,7 +379,7 @@ int UriPermissionManagerStubImpl::RevokeAllUriPermissions(uint32_t tokenId) for (auto it = list.begin(); it != list.end();) { if (it->targetTokenId == static_cast(tokenId) || it->fromTokenId == static_cast(tokenId)) { - HILOG_INFO("Erase an info form list."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Erase an info form list."); uriLists[it->targetTokenId].emplace_back(iter->first); list.erase(it++); } else { @@ -392,7 +396,7 @@ int UriPermissionManagerStubImpl::RevokeAllUriPermissions(uint32_t tokenId) ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID); if (storageManager_ == nullptr) { - HILOG_ERROR("ConnectStorageManager failed."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "ConnectStorageManager failed."); return INNER_ERR; } if (!uriLists.empty()) { @@ -405,18 +409,18 @@ int UriPermissionManagerStubImpl::RevokeAllUriPermissions(uint32_t tokenId) int UriPermissionManagerStubImpl::RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) { - HILOG_INFO("Start to remove uri permission manually."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Start to remove uri permission manually."); Uri uri_inner = uri; auto uriStr = uri.ToString(); auto&& authority = uri_inner.GetAuthority(); auto&& scheme = uri_inner.GetScheme(); if (scheme != "file" && scheme != "content") { - HILOG_WARN("only support file uri."); + TAG_LOGW(AAFwkTag::URIPERMMGR, "only support file uri."); return ERR_CODE_INVALID_URI_TYPE; } auto tokenId = GetTokenIdByBundleName(bundleName, 0); auto callerTokenId = IPCSkeleton::GetCallingTokenID(); - HILOG_DEBUG("callerTokenId is %{public}u, targetTokenId is %{public}u", callerTokenId, tokenId); + TAG_LOGD(AAFwkTag::URIPERMMGR, "callerTokenId is %{public}u, targetTokenId is %{public}u", callerTokenId, tokenId); if (tokenId == callerTokenId) { return DeleteTempUriPermission(uriStr, 0, tokenId); } @@ -428,25 +432,25 @@ int UriPermissionManagerStubImpl::DeleteTempUriPermission(const std::string &uri { ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID); if (storageManager_ == nullptr) { - HILOG_ERROR("ConnectStorageManager failed"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "ConnectStorageManager failed"); return INNER_ERR; } std::lock_guard guard(mutex_); auto search = uriMap_.find(uri); if (search == uriMap_.end()) { - HILOG_INFO("URI does not exist on uri map."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "URI does not exist on uri map."); return ERR_OK; } auto& list = search->second; for (auto it = list.begin(); it != list.end(); it++) { if ((it->fromTokenId == fromTokenId || fromTokenId == 0) && it->targetTokenId == targetTokenId) { - HILOG_INFO("Notify storageMGR to delete shareFile."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Notify storageMGR to delete shareFile."); std::vector uriList; uriList.emplace_back(search->first); auto procedureRet = storageManager_->DeleteShareFile(targetTokenId, uriList); if (procedureRet != ERR_OK) { - HILOG_ERROR("DeleteShareFile failed"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "DeleteShareFile failed"); return procedureRet; } list.erase(it); @@ -462,25 +466,25 @@ int UriPermissionManagerStubImpl::DeleteTempUriPermission(const std::string &uri template void UriPermissionManagerStubImpl::ConnectManager(sptr &mgr, int32_t serviceId) { - HILOG_DEBUG("Call."); + TAG_LOGD(AAFwkTag::URIPERMMGR, "Call."); std::lock_guard lock(mgrMutex_); if (mgr == nullptr) { - HILOG_ERROR("mgr is nullptr."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "mgr is nullptr."); auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemAbilityMgr == nullptr) { - HILOG_ERROR("Failed to get SystemAbilityManager."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Failed to get SystemAbilityManager."); return; } auto remoteObj = systemAbilityMgr->GetSystemAbility(serviceId); if (remoteObj == nullptr) { - HILOG_ERROR("Failed to get mgr."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Failed to get mgr."); return; } - HILOG_ERROR("to cast."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "to cast."); mgr = iface_cast(remoteObj); if (mgr == nullptr) { - HILOG_ERROR("Failed to cast."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Failed to cast."); return; } wptr manager = mgr; @@ -495,7 +499,7 @@ void UriPermissionManagerStubImpl::ConnectManager(sptr &mgr, int32_t serviceI }; sptr recipient(new ProxyDeathRecipient(std::move(onClearProxyCallback))); if (!mgr->AsObject()->AddDeathRecipient(recipient)) { - HILOG_ERROR("AddDeathRecipient failed."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "AddDeathRecipient failed."); } } } @@ -512,7 +516,7 @@ uint32_t UriPermissionManagerStubImpl::GetTokenIdByBundleName(const std::string { auto bundleMgrHelper = ConnectManagerHelper(); if (bundleMgrHelper == nullptr) { - HILOG_WARN("The bundleMgrHelper is nullptr."); + TAG_LOGW(AAFwkTag::URIPERMMGR, "The bundleMgrHelper is nullptr."); return GET_BUNDLE_MANAGER_SERVICE_FAILED; } auto bundleFlag = AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO; @@ -520,13 +524,13 @@ uint32_t UriPermissionManagerStubImpl::GetTokenIdByBundleName(const std::string auto userId = GetCurrentAccountId(); if (appIndex == 0) { if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfo(bundleName, bundleFlag, bundleInfo, userId))) { - HILOG_WARN("Failed to get bundle info according to uri."); + TAG_LOGW(AAFwkTag::URIPERMMGR, "Failed to get bundle info according to uri."); return GET_BUNDLE_INFO_FAILED; } } else { if (IN_PROCESS_CALL(bundleMgrHelper->GetSandboxBundleInfo( bundleName, appIndex, userId, bundleInfo) != ERR_OK)) { - HILOG_WARN("Failed to get bundle info according to appIndex."); + TAG_LOGW(AAFwkTag::URIPERMMGR, "Failed to get bundle info according to appIndex."); return GET_BUNDLE_INFO_FAILED; } } @@ -537,7 +541,7 @@ void UriPermissionManagerStubImpl::ProxyDeathRecipient::OnRemoteDied([[maybe_unu const wptr& remote) { if (proxy_) { - HILOG_DEBUG("mgr stub died."); + TAG_LOGD(AAFwkTag::URIPERMMGR, "mgr stub died."); proxy_(remote); } } @@ -548,11 +552,11 @@ int32_t UriPermissionManagerStubImpl::GetCurrentAccountId() const auto ret = DelayedSingleton::GetInstance()-> QueryActiveOsAccountIds(osActiveAccountIds); if (ret != ERR_OK) { - HILOG_ERROR("QueryActiveOsAccountIds error."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "QueryActiveOsAccountIds error."); return DEFAULT_USER_ID; } if (osActiveAccountIds.empty()) { - HILOG_ERROR("%{public}s, the QueryActiveOsAccountIds is empty, no accounts.", __func__); + TAG_LOGE(AAFwkTag::URIPERMMGR, "%{public}s, the QueryActiveOsAccountIds is empty, no accounts.", __func__); return DEFAULT_USER_ID; } @@ -562,7 +566,8 @@ int32_t UriPermissionManagerStubImpl::GetCurrentAccountId() const int UriPermissionManagerStubImpl::GrantUriPermissionFor2In1Inner(const std::vector &uriVec, unsigned int flag, const std::string &targetBundleName, int32_t appIndex, bool isSystemAppCall, uint32_t initiatorTokenId) { - HILOG_INFO("UriVec size is %{public}zu, targetBundleName is %{public}s", uriVec.size(), targetBundleName.c_str()); + TAG_LOGI(AAFwkTag::URIPERMMGR, + "UriVec size is %{public}zu, targetBundleName is %{public}s", uriVec.size(), targetBundleName.c_str()); auto checkResult = CheckRule(flag); if (checkResult != ERR_OK) { return checkResult; @@ -573,11 +578,11 @@ int UriPermissionManagerStubImpl::GrantUriPermissionFor2In1Inner(const std::vect Uri uri_inner = uri; auto &&scheme = uri_inner.GetScheme(); if (scheme != "file") { - HILOG_WARN("Only support file uri."); + TAG_LOGW(AAFwkTag::URIPERMMGR, "Only support file uri."); continue; } auto &&authority = uri_inner.GetAuthority(); - HILOG_DEBUG("The authority is %{public}s", authority.c_str()); + TAG_LOGD(AAFwkTag::URIPERMMGR, "The authority is %{public}s", authority.c_str()); PolicyInfo policyInfo; policyInfo.path = uri_inner.ToString(); if ((flag & Want::FLAG_AUTH_WRITE_URI_PERMISSION) != 0) { @@ -592,7 +597,7 @@ int UriPermissionManagerStubImpl::GrantUriPermissionFor2In1Inner(const std::vect } } uint32_t tokenId = GetTokenIdByBundleName(targetBundleName, appIndex); - HILOG_DEBUG("The tokenId is %{public}u", tokenId); + TAG_LOGD(AAFwkTag::URIPERMMGR, "The tokenId is %{public}u", tokenId); HandleUriPermission(tokenId, flag, docsVec, isSystemAppCall); if (!otherVec.empty()) { return GrantUriPermissionInner(otherVec, flag, targetBundleName, appIndex, initiatorTokenId); @@ -612,7 +617,7 @@ void UriPermissionManagerStubImpl::HandleUriPermission( std::vector result; checkPersistPermission(tokenId, docsVec, result); if (docsVec.size() != result.size()) { - HILOG_ERROR("Check persist permission failed."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Check persist permission failed."); return; } std::vector policyVec; @@ -640,7 +645,7 @@ bool UriPermissionManagerStubImpl::IsFoundationCall() auto callerTokenId = IPCSkeleton::GetCallingTokenID(); Security::AccessToken::NativeTokenInfo nativeInfo; Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(callerTokenId, nativeInfo); - HILOG_DEBUG("Caller process name : %{public}s", nativeInfo.processName.c_str()); + TAG_LOGD(AAFwkTag::URIPERMMGR, "Caller process name : %{public}s", nativeInfo.processName.c_str()); if (nativeInfo.processName == "foundation") { return true; } @@ -664,16 +669,16 @@ bool UriPermissionManagerStubImpl::CheckAndCreateEventInfo(uint32_t callerTokenI std::string callerBundleName = GetBundleNameByTokenId(callerTokenId); std::string targetBundleName = GetBundleNameByTokenId(targetTokenId); if (callerBundleName.empty() || targetBundleName.empty()) { - HILOG_ERROR("Caller bundle name is empty or target bundle name is empty."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Caller bundle name is empty or target bundle name is empty."); return false; } auto isSystemAppCall = CheckIsSystemAppByBundleName(callerBundleName); auto targetIsSystemApp = CheckIsSystemAppByBundleName(targetBundleName); if (!isSystemAppCall || targetIsSystemApp) { - HILOG_DEBUG("Caller is not system app or callee is system app."); + TAG_LOGD(AAFwkTag::URIPERMMGR, "Caller is not system app or callee is system app."); return false; } - HILOG_INFO("Send Grant_Uri_Permission event."); + TAG_LOGI(AAFwkTag::URIPERMMGR, "Send Grant_Uri_Permission event."); eventInfo.callerBundleName = callerBundleName; eventInfo.bundleName = targetBundleName; return true; @@ -684,7 +689,7 @@ std::string UriPermissionManagerStubImpl::GetBundleNameByTokenId(uint32_t tokenI Security::AccessToken::HapTokenInfo hapInfo; auto ret = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo); if (ret != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { - HILOG_ERROR("GetHapTokenInfo failed, ret is %{public}i", ret); + TAG_LOGE(AAFwkTag::URIPERMMGR, "GetHapTokenInfo failed, ret is %{public}i", ret); return ""; } return hapInfo.bundleName; @@ -694,17 +699,17 @@ bool UriPermissionManagerStubImpl::CheckIsSystemAppByBundleName(std::string &bun { auto bundleMgrHelper = ConnectManagerHelper(); if (bundleMgrHelper == nullptr) { - HILOG_WARN("The bundleMgrHelper is nullptr."); + TAG_LOGW(AAFwkTag::URIPERMMGR, "The bundleMgrHelper is nullptr."); return false; } AppExecFwk::ApplicationInfo appInfo; if (!IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, GetCurrentAccountId(), appInfo))) { - HILOG_WARN("Get application info failed."); + TAG_LOGW(AAFwkTag::URIPERMMGR, "Get application info failed."); return false; } auto isSystemApp = Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(appInfo.accessTokenIdEx); - HILOG_DEBUG("BundleName is %{public}s, isSystemApp = %{public}i", bundleName.c_str(), + TAG_LOGD(AAFwkTag::URIPERMMGR, "BundleName is %{public}s, isSystemApp = %{public}i", bundleName.c_str(), static_cast(isSystemApp)); return isSystemApp; } @@ -716,11 +721,11 @@ bool UriPermissionManagerStubImpl::CheckUriPermission(const Uri &uri, unsigned i auto &&authority = uriInner.GetAuthority(); auto authorityTokenId = GetTokenIdByBundleName(authority, 0); if (authority == "docs" || authority == "media") { - HILOG_ERROR("Authotity is media or docs, do not have permission."); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Authotity is media or docs, do not have permission."); return false; } if (authorityTokenId != callerTokenId) { - HILOG_ERROR("The uri does not belong to caller, have not permission"); + TAG_LOGE(AAFwkTag::URIPERMMGR, "The uri does not belong to caller, have not permission"); return false; } return true; @@ -731,7 +736,7 @@ bool UriPermissionManagerStubImpl::CheckUriTypeIsValid(const Uri &uri) auto innerUri = uri; auto &&scheme = innerUri.GetScheme(); if (scheme != "file" && scheme != "content") { - HILOG_ERROR("Only support file or content uri, scheme is %{public}s", scheme.c_str()); + TAG_LOGE(AAFwkTag::URIPERMMGR, "Only support file or content uri, scheme is %{public}s", scheme.c_str()); return false; } return true; diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 9c51db5a1c..4402fd364c 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -20,6 +20,7 @@ #include #include "ability_manager_client.h" #include "app_mgr_client.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "iservice_registry.h" #include "mission_snapshot.h" @@ -127,7 +128,7 @@ constexpr struct option LONG_OPTIONS_ATTACH[] = { AbilityManagerShellCommand::AbilityManagerShellCommand(int argc, char* argv[]) : ShellCommand(argc, argv, TOOL_NAME) { for (int i = 0; i < argc_; i++) { - HILOG_INFO("argv_[%{public}d]: %{public}s", i, argv_[i]); + TAG_LOGI(AAFwkTag::AA_TOOL, "argv_[%{public}d]: %{public}s", i, argv_[i]); } } @@ -298,7 +299,7 @@ ErrCode AbilityManagerShellCommand::RunAsHelpCommand() ErrCode AbilityManagerShellCommand::RunAsScreenCommand() { - HILOG_INFO("enter"); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter"); int result = OHOS::ERR_OK; @@ -310,7 +311,8 @@ ErrCode AbilityManagerShellCommand::RunAsScreenCommand() option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + TAG_LOGI( + AAFwkTag::AA_TOOL, "option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE; @@ -321,7 +323,7 @@ ErrCode AbilityManagerShellCommand::RunAsScreenCommand() if (counter == 1 && strcmp(argv_[optind], cmd_.c_str()) == 0) { // 'aa screen' with no option: aa screen // 'aa screen' with a wrong argument: aa screen xxx - HILOG_INFO("'aa %{public}s' %{public}s.", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' %{public}s.", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); resultReceiver_.append(HELP_MSG_NO_OPTION + "\n"); result = OHOS::ERR_INVALID_VALUE; } @@ -332,7 +334,7 @@ ErrCode AbilityManagerShellCommand::RunAsScreenCommand() switch (optopt) { case 'p': { // 'aa screen -p' with no argument - HILOG_INFO("'aa %{public}s -p' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -p' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -346,7 +348,7 @@ ErrCode AbilityManagerShellCommand::RunAsScreenCommand() std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa screen' with an unknown option."); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa screen' with an unknown option."); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; @@ -358,7 +360,7 @@ ErrCode AbilityManagerShellCommand::RunAsScreenCommand() std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa screen' with an unknown option."); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa screen' with an unknown option."); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; @@ -409,10 +411,10 @@ ErrCode AbilityManagerShellCommand::RunAsStartAbility() result = AbilityManagerClient::GetInstance()->StartAbility(want); } if (result == OHOS::ERR_OK) { - HILOG_INFO("%{public}s", STRING_START_ABILITY_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_START_ABILITY_OK.c_str()); resultReceiver_ = STRING_START_ABILITY_OK + "\n"; } else { - HILOG_INFO("%{public}s result = %{public}d", STRING_START_ABILITY_NG.c_str(), result); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_START_ABILITY_NG.c_str(), result); if (result != START_ABILITY_WAITING) { resultReceiver_ = STRING_START_ABILITY_NG + "\n"; } @@ -436,10 +438,11 @@ ErrCode AbilityManagerShellCommand::RunAsStopService() if (result == OHOS::ERR_OK) { result = AbilityManagerClient::GetInstance()->StopServiceAbility(want); if (result == OHOS::ERR_OK) { - HILOG_INFO("%{public}s", STRING_STOP_SERVICE_ABILITY_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_STOP_SERVICE_ABILITY_OK.c_str()); resultReceiver_ = STRING_STOP_SERVICE_ABILITY_OK + "\n"; } else { - HILOG_INFO("%{public}s result = %{public}d", STRING_STOP_SERVICE_ABILITY_NG.c_str(), result); + TAG_LOGI( + AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_STOP_SERVICE_ABILITY_NG.c_str(), result); resultReceiver_ = STRING_STOP_SERVICE_ABILITY_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); @@ -499,7 +502,8 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() while (true) { int option = getopt_long(argc_, argv_, SHORT_OPTIONS_DUMPSYS.c_str(), LONG_OPTIONS_DUMPSYS, nullptr); - HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + TAG_LOGI( + AAFwkTag::AA_TOOL, "option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); if (optind < 0 || optind > argc_) { resultReceiver_.append(HELP_MSG_DUMPSYS); @@ -638,7 +642,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() } case '?': { if (!isfirstCommand) { - HILOG_INFO("'aa %{public}s' with an unknown option.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' with an unknown option.", cmd_.c_str()); std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); resultReceiver_.append(unknownOptionMsg); @@ -649,7 +653,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() break; } default: { - HILOG_INFO("'aa %{public}s' with an unknown option.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' with an unknown option.", cmd_.c_str()); std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); resultReceiver_.append(unknownOptionMsg); @@ -676,7 +680,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() resultReceiver_ += it + "\n"; } } else { - HILOG_INFO("failed to dump state."); + TAG_LOGI(AAFwkTag::AA_TOOL, "failed to dump state."); } } return result; @@ -684,19 +688,19 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() ErrCode AbilityManagerShellCommand::RunAsForceStop() { - HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + TAG_LOGI(AAFwkTag::AA_TOOL, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); if (argList_.empty()) { resultReceiver_.append(HELP_MSG_FORCE_STOP + "\n"); return OHOS::ERR_INVALID_VALUE; } - HILOG_INFO("Bundle name : %{public}s", argList_[0].c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "Bundle name : %{public}s", argList_[0].c_str()); ErrCode result = OHOS::ERR_OK; result = AbilityManagerClient::GetInstance()->KillProcess(argList_[0]); if (result == OHOS::ERR_OK) { - HILOG_INFO("%{public}s", STRING_FORCE_STOP_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_FORCE_STOP_OK.c_str()); resultReceiver_ = STRING_FORCE_STOP_OK + "\n"; } else { - HILOG_INFO("%{public}s result = %{public}d", STRING_FORCE_STOP_NG.c_str(), result); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_FORCE_STOP_NG.c_str(), result); resultReceiver_ = STRING_FORCE_STOP_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); } @@ -705,7 +709,7 @@ ErrCode AbilityManagerShellCommand::RunAsForceStop() ErrCode AbilityManagerShellCommand::RunAsAttachDebugCommand() { - HILOG_DEBUG("Called."); + TAG_LOGD(AAFwkTag::AA_TOOL, "Called."); std::string bundleName = ""; ParseBundleName(bundleName); if (bundleName.empty()) { @@ -719,14 +723,14 @@ ErrCode AbilityManagerShellCommand::RunAsAttachDebugCommand() return result; } - HILOG_DEBUG("%{public}s result = %{public}d", STRING_ATTACH_APP_DEBUG_NG.c_str(), result); + TAG_LOGD(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_ATTACH_APP_DEBUG_NG.c_str(), result); resultReceiver_.append(STRING_ATTACH_APP_DEBUG_NG + "\n"); return result; } ErrCode AbilityManagerShellCommand::RunAsDetachDebugCommand() { - HILOG_DEBUG("Called."); + TAG_LOGD(AAFwkTag::AA_TOOL, "Called."); std::string bundleName = ""; ParseBundleName(bundleName); if (bundleName.empty()) { @@ -740,7 +744,7 @@ ErrCode AbilityManagerShellCommand::RunAsDetachDebugCommand() return result; } - HILOG_DEBUG("%{public}s result = %{public}d", STRING_DETACH_APP_DEBUG_NG.c_str(), result); + TAG_LOGD(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_DETACH_APP_DEBUG_NG.c_str(), result); resultReceiver_.append(STRING_DETACH_APP_DEBUG_NG + "\n"); return result; } @@ -753,10 +757,11 @@ ErrCode AbilityManagerShellCommand::RunAsProcessCommand() auto appMgrClient = std::make_shared(); result = appMgrClient->StartNativeProcessForDebugger(want); if (result == OHOS::ERR_OK) { - HILOG_INFO("%{public}s", STRING_START_NATIVE_PROCESS_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_START_NATIVE_PROCESS_OK.c_str()); resultReceiver_ = STRING_START_NATIVE_PROCESS_OK; } else { - HILOG_INFO("%{public}s result = %{public}d", STRING_START_NATIVE_PROCESS_NG.c_str(), result); + TAG_LOGI( + AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_START_NATIVE_PROCESS_NG.c_str(), result); resultReceiver_ = STRING_START_NATIVE_PROCESS_NG; } } else { @@ -769,15 +774,15 @@ ErrCode AbilityManagerShellCommand::RunAsProcessCommand() bool AbilityManagerShellCommand::MatchOrderString(const std::regex ®exScript, const std::string &orderCmd) { - HILOG_DEBUG("order string is %{public}s", orderCmd.c_str()); + TAG_LOGD(AAFwkTag::AA_TOOL, "order string is %{public}s", orderCmd.c_str()); if (orderCmd.empty()) { - HILOG_ERROR("input param order string is empty"); + TAG_LOGE(AAFwkTag::AA_TOOL, "input param order string is empty"); return false; } std::match_results matchResults; if (!std::regex_match(orderCmd, matchResults, regexScript)) { - HILOG_ERROR("the order not match"); + TAG_LOGE(AAFwkTag::AA_TOOL, "the order not match"); return false; } @@ -788,12 +793,12 @@ bool AbilityManagerShellCommand::CheckPerfCmdString( const char* optarg, const size_t paramLength, std::string &perfCmd) { if (optarg == nullptr) { - HILOG_ERROR("input param optarg is nullptr"); + TAG_LOGE(AAFwkTag::AA_TOOL, "input param optarg is nullptr"); return false; } if (strlen(optarg) >= paramLength) { - HILOG_ERROR("debuggablePipe aa start -p param length must be less than 1024."); + TAG_LOGE(AAFwkTag::AA_TOOL, "debuggablePipe aa start -p param length must be less than 1024."); return false; } @@ -804,10 +809,10 @@ bool AbilityManagerShellCommand::CheckPerfCmdString( return true; } - HILOG_DEBUG("the command not match"); + TAG_LOGD(AAFwkTag::AA_TOOL, "the command not match"); const std::regex regexProfileType(R"(^\s*(profile)\s+(nativeperf|jsperf)(\s+.*|$))"); if (!MatchOrderString(regexProfileType, perfCmd)) { - HILOG_ERROR("the command is invalid"); + TAG_LOGE(AAFwkTag::AA_TOOL, "the command is invalid"); return false; } @@ -815,7 +820,7 @@ bool AbilityManagerShellCommand::CheckPerfCmdString( if (findPos != std::string::npos) { const std::regex regexCmd(R"(^jsperf($|\s+($|((5000|([1-9]|[1-4]\d)\d\d)|)\s*($|nativeperf.*))))"); if (!MatchOrderString(regexCmd, perfCmd.substr(findPos, perfCmd.length() - findPos))) { - HILOG_ERROR("the order is invalid"); + TAG_LOGE(AAFwkTag::AA_TOOL, "the order is invalid"); return false; } } @@ -941,7 +946,8 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) option = getopt_long(argc_, argv_, SHORT_OPTIONS_PROCESS.c_str(), LONG_OPTIONS_PROCESS, nullptr); - HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + TAG_LOGI( + AAFwkTag::AA_TOOL, "option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE; @@ -952,7 +958,7 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) if (counter == 1 && strcmp(argv_[optind], cmd_.c_str()) == 0) { // 'aa process' with no option: aa process // 'aa process' with a wrong argument: aa process xxx - HILOG_INFO("'aa %{public}s' %{public}s!", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' %{public}s!", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); resultReceiver_.append(HELP_MSG_NO_OPTION + "\n"); result = OHOS::ERR_INVALID_VALUE; @@ -964,7 +970,7 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) switch (optopt) { case 'a': { // 'aa process -a' with no argument - HILOG_INFO("'aa %{public}s -a' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -a' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -974,7 +980,7 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) } case 'b': { // 'aa process -b' with no argument - HILOG_INFO("'aa %{public}s -b' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -b' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -984,7 +990,7 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) } case 'm': { // 'aa process -m' with no argument - HILOG_INFO("'aa %{public}s -m' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -m' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -994,7 +1000,7 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) } case 'p': { // 'aa process -p' with no argument - HILOG_INFO("'aa %{public}s -p' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -p' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1004,7 +1010,7 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) } case 'D': { // 'aa process -D' with no argument - HILOG_INFO("'aa %{public}s -D' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -D' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1018,7 +1024,7 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa %{public}s' with an unknown option.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' with an unknown option.", cmd_.c_str()); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; @@ -1030,7 +1036,7 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa %{public}s' with an unknown option.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' with an unknown option.", cmd_.c_str()); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; @@ -1078,7 +1084,7 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) // 'aa process -D xxx' // save debug cmd if (!isPerf && strlen(optarg) < PARAM_LENGTH) { - HILOG_INFO("debug cmd."); + TAG_LOGI(AAFwkTag::AA_TOOL, "debug cmd."); debugCmd = optarg; } break; @@ -1100,13 +1106,14 @@ ErrCode AbilityManagerShellCommand::MakeWantForProcess(Want& want) if (result == OHOS::ERR_OK) { if (perfCmd.empty() && debugCmd.empty()) { - HILOG_INFO("debuggablePipe aa process must contains -p or -D and param length must be less than 1024."); + TAG_LOGI(AAFwkTag::AA_TOOL, + "debuggablePipe aa process must contains -p or -D and param length must be less than 1024."); return OHOS::ERR_INVALID_VALUE; } if (abilityName.size() == 0 || bundleName.size() == 0) { // 'aa process -a -b [-D]' - HILOG_INFO("'aa %{public}s' without enough options.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' without enough options.", cmd_.c_str()); if (abilityName.size() == 0) { resultReceiver_.append(HELP_MSG_NO_ABILITY_NAME_OPTION + "\n"); @@ -1144,7 +1151,8 @@ void AbilityManagerShellCommand::ParseBundleName(std::string &bundleName) while (true) { counter++; option = getopt_long(argc_, argv_, SHORT_OPTIONS_ATTACH.c_str(), LONG_OPTIONS_ATTACH, nullptr); - HILOG_DEBUG("getopt_long option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + TAG_LOGD(AAFwkTag::AA_TOOL, "getopt_long option: %{public}d, optopt: %{public}d, optind: %{public}d", option, + optopt, optind); if (optind < 0 || optind > argc_) { break; @@ -1188,7 +1196,7 @@ void AbilityManagerShellCommand::ParseBundleName(std::string &bundleName) #ifdef ABILITY_COMMAND_FOR_TEST ErrCode AbilityManagerShellCommand::RunForceTimeoutForTest() { - HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + TAG_LOGI(AAFwkTag::AA_TOOL, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); if (argList_.empty()) { resultReceiver_.append(HELP_MSG_FORCE_TIMEOUT + "\n"); return OHOS::ERR_INVALID_VALUE; @@ -1196,20 +1204,21 @@ ErrCode AbilityManagerShellCommand::RunForceTimeoutForTest() ErrCode result = OHOS::ERR_OK; if (argList_.size() == NUMBER_ONE && argList_[0] == HELP_MSG_FORCE_TIMEOUT_CLEAN) { - HILOG_INFO("clear ability timeout flags."); + TAG_LOGI(AAFwkTag::AA_TOOL, "clear ability timeout flags."); result = AbilityManagerClient::GetInstance()->ForceTimeoutForTest(argList_[0], ""); } else if (argList_.size() == NUMBER_TWO) { - HILOG_INFO("Ability name : %{public}s, state: %{public}s", argList_[0].c_str(), argList_[1].c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "Ability name : %{public}s, state: %{public}s", argList_[0].c_str(), + argList_[1].c_str()); result = AbilityManagerClient::GetInstance()->ForceTimeoutForTest(argList_[0], argList_[1]); } else { resultReceiver_.append(HELP_MSG_FORCE_TIMEOUT + "\n"); return OHOS::ERR_INVALID_VALUE; } if (result == OHOS::ERR_OK) { - HILOG_INFO("%{public}s", STRING_FORCE_TIMEOUT_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_FORCE_TIMEOUT_OK.c_str()); resultReceiver_ = STRING_FORCE_TIMEOUT_OK + "\n"; } else { - HILOG_INFO("%{public}s result = %{public}d", STRING_FORCE_TIMEOUT_NG.c_str(), result); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_FORCE_TIMEOUT_NG.c_str(), result); resultReceiver_ = STRING_FORCE_TIMEOUT_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); } @@ -1247,7 +1256,8 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + TAG_LOGI( + AAFwkTag::AA_TOOL, "option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE; @@ -1260,7 +1270,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win // 'aa start' with a wrong argument: aa start xxx // 'aa stop-service' with no option: aa stop-service // 'aa stop-service' with a wrong argument: aa stop-service xxx - HILOG_INFO("'aa %{public}s' %{public}s", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' %{public}s", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); resultReceiver_.append(HELP_MSG_NO_OPTION + "\n"); result = OHOS::ERR_INVALID_VALUE; @@ -1279,7 +1289,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win case 'd': { // 'aa start -d' with no argument // 'aa stop-service -d' with no argument - HILOG_INFO("'aa %{public}s -d' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -d' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1290,7 +1300,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win case 'a': { // 'aa start -a' with no argument // 'aa stop-service -a' with no argument - HILOG_INFO("'aa %{public}s -a' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -a' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1301,7 +1311,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win case 'b': { // 'aa start -b' with no argument // 'aa stop-service -b' with no argument - HILOG_INFO("'aa %{public}s -b' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -b' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1311,7 +1321,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win } case 'e': { // 'aa start -e' with no argument - HILOG_INFO("'aa %{public}s -e with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -e with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1321,7 +1331,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win } case 't': { // 'aa start -t' with no argument - HILOG_INFO("'aa %{public}s -t with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -t with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1332,7 +1342,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win case 's': { // 'aa start -s' with no argument // 'aa stop-service -s' with no argument - HILOG_INFO("'aa %{public}s -s' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -s' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append(argv_[optind - 1]); @@ -1344,7 +1354,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win case 'm': { // 'aa start -m' with no argument // 'aa stop-service -m' with no argument - HILOG_INFO("'aa %{public}s -m' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -m' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1355,7 +1365,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win case 'p': { // 'aa start -p' with no argument // 'aa stop-service -p' with no argument - HILOG_INFO("'aa %{public}s -p' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -p' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1365,7 +1375,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win } case OPTION_PARAMETER_INTEGER: { // 'aa start --pi' with no argumnet - HILOG_INFO("'aa %{public}s --pi' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s --pi' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1376,7 +1386,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win } case OPTION_PARAMETER_STRING: { // 'aa start --ps' with no argumnet - HILOG_INFO("'aa %{public}s --ps' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s --ps' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1387,7 +1397,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win } case OPTION_PARAMETER_BOOL: { // 'aa start --pb' with no argumnet - HILOG_INFO("'aa %{public}s -pb' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -pb' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1398,7 +1408,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win } case OPTION_PARAMETER_NULL_STRING: { // 'aa start --psn' with no argumnet - HILOG_INFO("'aa %{public}s --psn' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s --psn' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1410,7 +1420,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win case 'A': { // 'aa start -A' with no argumnet - HILOG_INFO("'aa %{public}s -A' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -A' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1421,7 +1431,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win } case 'U': { // 'aa start -U' with no argumnet - HILOG_INFO("'aa %{public}s -U' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -U' with no argument.", cmd_.c_str()); resultReceiver_.append("error: option "); resultReceiver_.append("requires a value.\n"); @@ -1438,7 +1448,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa %{public}s' with an unknown option.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' with an unknown option.", cmd_.c_str()); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; @@ -1452,7 +1462,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa %{public}s' with an unknown option.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' with an unknown option.", cmd_.c_str()); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; @@ -1531,7 +1541,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win // save module name if (!CheckPerfCmdString(optarg, PARAM_LENGTH, perfCmd)) { - HILOG_ERROR("input perfCmd is invalid %{public}s", perfCmd.c_str()); + TAG_LOGE(AAFwkTag::AA_TOOL, "input perfCmd is invalid %{public}s", perfCmd.c_str()); result = OHOS::ERR_INVALID_VALUE; } break; @@ -1653,7 +1663,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win // 'aa start [-d ] -a -b [-D]' // 'aa stop-service [-d ] -a -b ' - HILOG_INFO("'aa %{public}s' without enough options.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' without enough options.", cmd_.c_str()); resultReceiver_.append(HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n"); result = OHOS::ERR_INVALID_VALUE; @@ -1708,11 +1718,11 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win ErrCode AbilityManagerShellCommand::RunAsTestCommand() { - HILOG_INFO("enter"); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter"); std::map params; for (int i = USER_TEST_COMMAND_START_INDEX; i < argc_; i++) { - HILOG_INFO("argv_[%{public}d]: %{public}s", i, argv_[i]); + TAG_LOGI(AAFwkTag::AA_TOOL, "argv_[%{public}d]: %{public}s", i, argv_[i]); std::string opt = argv_[i]; if ((opt == "-h") || (opt == "--help")) { resultReceiver_.append(HELP_MSG_TEST); @@ -1759,7 +1769,7 @@ ErrCode AbilityManagerShellCommand::RunAsTestCommand() bool AbilityManagerShellCommand::IsTestCommandIntegrity(const std::map& params) { - HILOG_INFO("enter"); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter"); std::vector opts = { "-b", "-s unittest" }; for (auto opt : opts) { @@ -1781,7 +1791,7 @@ ErrCode AbilityManagerShellCommand::TestCommandError(const std::string& info) ErrCode AbilityManagerShellCommand::StartUserTest(const std::map& params) { - HILOG_INFO("enter"); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter"); Want want; for (auto param : params) { @@ -1790,24 +1800,24 @@ ErrCode AbilityManagerShellCommand::StartUserTest(const std::mapsecond.compare(DEBUG_VALUE) == 0) { - HILOG_INFO("Set Debug to want"); + TAG_LOGI(AAFwkTag::AA_TOOL, "Set Debug to want"); want.SetParam("debugApp", true); } sptr observer = new (std::nothrow) TestObserver(); if (!observer) { - HILOG_ERROR("Failed: the TestObserver is null"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed: the TestObserver is null"); return OHOS::ERR_INVALID_VALUE; } int result = AbilityManagerClient::GetInstance()->StartUserTest(want, observer->AsObject()); if (result != OHOS::ERR_OK) { - HILOG_INFO("%{public}s result = %{public}d", STRING_START_USER_TEST_NG.c_str(), result); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_START_USER_TEST_NG.c_str(), result); resultReceiver_ = STRING_START_USER_TEST_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); return result; } - HILOG_INFO("%{public}s", STRING_USER_TEST_STARTED.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_USER_TEST_STARTED.c_str()); std::signal(SIGCHLD, SIG_DFL); @@ -1821,7 +1831,7 @@ ErrCode AbilityManagerShellCommand::StartUserTest(const std::map AbilityManagerShellCommand::GetAbilityManagerService() { sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemManager == nullptr) { - HILOG_ERROR("Fail to get registry."); + TAG_LOGE(AAFwkTag::AA_TOOL, "Fail to get registry."); return nullptr; } sptr remoteObject = systemManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID); @@ -1846,7 +1856,7 @@ ErrCode AbilityManagerShellCommand::RunAsSendAppNotRespondingWithUnknownOption() break; } case 'p': { - HILOG_INFO("'aa ApplicationNotResponding -p' with no argument."); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa ApplicationNotResponding -p' with no argument."); resultReceiver_.append("error: option -p "); resultReceiver_.append("' requires a value.\n"); break; @@ -1854,7 +1864,7 @@ ErrCode AbilityManagerShellCommand::RunAsSendAppNotRespondingWithUnknownOption() default: { std::string unknownOption; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa ApplicationNotResponding' with an unknown option."); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa ApplicationNotResponding' with an unknown option."); resultReceiver_.append(unknownOptionMsg); break; } @@ -1871,14 +1881,14 @@ ErrCode AbilityManagerShellCommand::RunAsSendAppNotRespondingWithOption(int32_t break; } case 'p': { - HILOG_INFO("aa ApplicationNotResponding 'aa %{public}s' -p process.", cmd_.c_str()); - HILOG_INFO("aa ApplicationNotResponding 'aa optarg = %{public}s'.", optarg); + TAG_LOGI(AAFwkTag::AA_TOOL, "aa ApplicationNotResponding 'aa %{public}s' -p process.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "aa ApplicationNotResponding 'aa optarg = %{public}s'.", optarg); pid = optarg; - HILOG_INFO("aa ApplicationNotResponding 'aa pid = %{public}s'.", pid.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "aa ApplicationNotResponding 'aa pid = %{public}s'.", pid.c_str()); break; } default: { - HILOG_INFO("'aa %{public}s' with an unknown option.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' with an unknown option.", cmd_.c_str()); result = OHOS::ERR_INVALID_VALUE; break; } @@ -1888,7 +1898,7 @@ ErrCode AbilityManagerShellCommand::RunAsSendAppNotRespondingWithOption(int32_t ErrCode AbilityManagerShellCommand::RunAsBlockAbilityCommand() { - HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + TAG_LOGI(AAFwkTag::AA_TOOL, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); ErrCode result = OHOS::ERR_OK; if (argList_.size() > 0) { result = AbilityManagerClient::GetInstance()->BlockAbility(atoi(argList_[0].c_str())); @@ -1897,10 +1907,10 @@ ErrCode AbilityManagerShellCommand::RunAsBlockAbilityCommand() } if (result == OHOS::ERR_OK) { - HILOG_INFO("%{public}s", STRING_BLOCK_ABILITY_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_BLOCK_ABILITY_OK.c_str()); resultReceiver_ = STRING_BLOCK_ABILITY_OK + "\n"; } else { - HILOG_INFO("%{public}s result = %{public}d", STRING_BLOCK_ABILITY_NG.c_str(), result); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_BLOCK_ABILITY_NG.c_str(), result); resultReceiver_ = STRING_BLOCK_ABILITY_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); } @@ -1909,14 +1919,14 @@ ErrCode AbilityManagerShellCommand::RunAsBlockAbilityCommand() ErrCode AbilityManagerShellCommand::RunAsBlockAmsServiceCommand() { - HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + TAG_LOGI(AAFwkTag::AA_TOOL, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); ErrCode result = OHOS::ERR_OK; result = AbilityManagerClient::GetInstance()->BlockAmsService(); if (result == OHOS::ERR_OK) { - HILOG_INFO("%{public}s", STRING_BLOCK_AMS_SERVICE_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_BLOCK_AMS_SERVICE_OK.c_str()); resultReceiver_ = STRING_BLOCK_AMS_SERVICE_OK + "\n"; } else { - HILOG_INFO("%{public}s result = %{public}d", STRING_BLOCK_AMS_SERVICE_NG.c_str(), result); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_BLOCK_AMS_SERVICE_NG.c_str(), result); resultReceiver_ = STRING_BLOCK_AMS_SERVICE_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); } @@ -1925,14 +1935,14 @@ ErrCode AbilityManagerShellCommand::RunAsBlockAmsServiceCommand() ErrCode AbilityManagerShellCommand::RunAsBlockAppServiceCommand() { - HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + TAG_LOGI(AAFwkTag::AA_TOOL, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); ErrCode result = OHOS::ERR_OK; result = AbilityManagerClient::GetInstance()->BlockAppService(); if (result == OHOS::ERR_OK) { - HILOG_INFO("%{public}s", STRING_BLOCK_APP_SERVICE_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_BLOCK_APP_SERVICE_OK.c_str()); resultReceiver_ = STRING_BLOCK_APP_SERVICE_OK + "\n"; } else { - HILOG_INFO("%{public}s result = %{public}d", STRING_BLOCK_APP_SERVICE_NG.c_str(), result); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_BLOCK_APP_SERVICE_NG.c_str(), result); resultReceiver_ = STRING_BLOCK_APP_SERVICE_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); } @@ -1971,7 +1981,7 @@ Reason CovertExitReason(std::string &cmd) ErrCode AbilityManagerShellCommand::RunAsForceExitAppCommand() { - HILOG_DEBUG("enter"); + TAG_LOGD(AAFwkTag::AA_TOOL, "enter"); int result = OHOS::ERR_OK; int option = -1; @@ -1983,7 +1993,8 @@ ErrCode AbilityManagerShellCommand::RunAsForceExitAppCommand() while (true) { counter++; option = getopt_long(argc_, argv_, SHORT_OPTIONS_FORCE_EXIT_APP.c_str(), LONG_OPTIONS_FORCE_EXIT_APP, nullptr); - HILOG_DEBUG("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + TAG_LOGD( + AAFwkTag::AA_TOOL, "option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE; @@ -1991,7 +2002,7 @@ ErrCode AbilityManagerShellCommand::RunAsForceExitAppCommand() if (option == -1) { if (counter == 1 && strcmp(argv_[optind], cmd_.c_str()) == 0) { - HILOG_ERROR("'aa %{public}s' %{public}s", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); + TAG_LOGE(AAFwkTag::AA_TOOL, "'aa %{public}s' %{public}s", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); resultReceiver_.append(HELP_MSG_NO_OPTION + "\n"); result = OHOS::ERR_INVALID_VALUE; } @@ -2000,20 +2011,20 @@ ErrCode AbilityManagerShellCommand::RunAsForceExitAppCommand() switch (option) { case 'h': { - HILOG_INFO("'aa %{public}s -h' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -h' with no argument.", cmd_.c_str()); // 'aa forceexitapp -h' // 'aa forceexitapp --help' result = OHOS::ERR_INVALID_VALUE; break; } case 'p': { - HILOG_INFO("'aa %{public}s -p' pid.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -p' pid.", cmd_.c_str()); // 'aa forceexitapp -p pid' pid = optarg; break; } case 'r': { - HILOG_INFO("'aa %{public}s -r' reason.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -r' reason.", cmd_.c_str()); // 'aa forceexitapp -r reason' reason = optarg; break; @@ -2021,7 +2032,7 @@ ErrCode AbilityManagerShellCommand::RunAsForceExitAppCommand() case '?': { std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa notifyappfault' with an unknown option."); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa notifyappfault' with an unknown option."); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; break; @@ -2042,12 +2053,12 @@ ErrCode AbilityManagerShellCommand::RunAsForceExitAppCommand() if (result == OHOS::ERR_OK) { resultReceiver_ = STRING_BLOCK_AMS_SERVICE_OK + "\n"; } else { - HILOG_INFO("%{public}s result = %{public}d", STRING_BLOCK_AMS_SERVICE_NG.c_str(), result); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_BLOCK_AMS_SERVICE_NG.c_str(), result); resultReceiver_ = STRING_BLOCK_AMS_SERVICE_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); } - HILOG_DEBUG("pid: %{public}s, reason: %{public}s", pid.c_str(), reason.c_str()); + TAG_LOGD(AAFwkTag::AA_TOOL, "pid: %{public}s, reason: %{public}s", pid.c_str(), reason.c_str()); return result; } @@ -2076,7 +2087,7 @@ FaultDataType CovertFaultType(std::string &cmd) ErrCode AbilityManagerShellCommand::RunAsNotifyAppFaultCommand() { - HILOG_DEBUG("called"); + TAG_LOGD(AAFwkTag::AA_TOOL, "called"); int result = OHOS::ERR_OK; int option = -1; int counter = 0; @@ -2089,14 +2100,15 @@ ErrCode AbilityManagerShellCommand::RunAsNotifyAppFaultCommand() counter++; option = getopt_long( argc_, argv_, SHORT_OPTIONS_NOTIFY_APP_FAULT.c_str(), LONG_OPTIONS_NOTIFY_APP_FAULT, nullptr); - HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + TAG_LOGI( + AAFwkTag::AA_TOOL, "option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE; } if (option == -1) { if (counter == 1 && strcmp(argv_[optind], cmd_.c_str()) == 0) { - HILOG_INFO("'aa %{public}s' %{public}s", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s' %{public}s", HELP_MSG_NO_OPTION.c_str(), cmd_.c_str()); resultReceiver_.append(HELP_MSG_NO_OPTION + "\n"); result = OHOS::ERR_INVALID_VALUE; } @@ -2105,38 +2117,38 @@ ErrCode AbilityManagerShellCommand::RunAsNotifyAppFaultCommand() switch (option) { case 'h': { - HILOG_INFO("'aa %{public}s -h' with no argument.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -h' with no argument.", cmd_.c_str()); // 'aa notifyappfault -h' // 'aa notifyappfault --help' result = OHOS::ERR_INVALID_VALUE; break; } case 'n': { - HILOG_INFO("'aa %{public}s -n' errorName.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -n' errorName.", cmd_.c_str()); // 'aa notifyappfault -n errorName' errorName = optarg; break; } case 'm': { - HILOG_INFO("'aa %{public}s -m' errorMessage.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -m' errorMessage.", cmd_.c_str()); // 'aa notifyappfault -m errorMessage' errorMessage = optarg; break; } case 's': { - HILOG_INFO("'aa %{public}s -s' errorStack.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -s' errorStack.", cmd_.c_str()); // 'aa notifyappfault -s errorStack' errorStack = optarg; break; } case 't': { - HILOG_INFO("'aa %{public}s -t' faultType.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -t' faultType.", cmd_.c_str()); // 'aa notifyappfault -t faultType' faultType = optarg; break; } case 'p': { - HILOG_INFO("'aa %{public}s -p' pid.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa %{public}s -p' pid.", cmd_.c_str()); // 'aa notifyappfault -p pid' pid = optarg; break; @@ -2144,7 +2156,7 @@ ErrCode AbilityManagerShellCommand::RunAsNotifyAppFaultCommand() case '?': { std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa notifyappfault' with an unknown option."); + TAG_LOGI(AAFwkTag::AA_TOOL, "'aa notifyappfault' with an unknown option."); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; break; @@ -2160,7 +2172,8 @@ ErrCode AbilityManagerShellCommand::RunAsNotifyAppFaultCommand() result = OHOS::ERR_INVALID_VALUE; } - HILOG_INFO("name: %{public}s, message: %{public}s, stack: %{public}s, type: %{public}s, pid: %{public}s", + TAG_LOGI(AAFwkTag::AA_TOOL, + "name: %{public}s, message: %{public}s, stack: %{public}s, type: %{public}s, pid: %{public}s", errorName.c_str(), errorMessage.c_str(), errorStack.c_str(), faultType.c_str(), pid.c_str()); AppFaultDataBySA faultData; diff --git a/tools/aa/src/ability_tool_command.cpp b/tools/aa/src/ability_tool_command.cpp index 8163b68ffd..58bb4cb1a3 100644 --- a/tools/aa/src/ability_tool_command.cpp +++ b/tools/aa/src/ability_tool_command.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -22,6 +22,7 @@ #include "ability_manager_client.h" #include "element_name.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "bool_wrapper.h" @@ -103,12 +104,12 @@ const int32_t ARG_LIST_INDEX_OFFSET = 2; AbilityToolCommand::AbilityToolCommand(int argc, char* argv[]) : ShellCommand(argc, argv, ABILITY_TOOL_NAME) { for (int i = 0; i < argc_; i++) { - HILOG_INFO("argv_[%{public}d]: %{public}s", i, argv_[i]); + TAG_LOGI(AAFwkTag::AA_TOOL, "argv_[%{public}d]: %{public}s", i, argv_[i]); } aaShellCmd_ = std::make_shared(argc, argv); if (aaShellCmd_.get() == nullptr) { - HILOG_ERROR("Get aa command failed."); + TAG_LOGE(AAFwkTag::AA_TOOL, "Get aa command failed."); } } @@ -128,7 +129,7 @@ ErrCode AbilityToolCommand::CreateCommandMap() ErrCode AbilityToolCommand::CreateMessageMap() { if (aaShellCmd_.get() == nullptr) { - HILOG_ERROR("aa shell command is nullptr."); + TAG_LOGE(AAFwkTag::AA_TOOL, "aa shell command is nullptr."); return OHOS::ERR_INVALID_VALUE; } return aaShellCmd_.get()->CreateMessageMap(); @@ -158,7 +159,7 @@ ErrCode AbilityToolCommand::RunAsStartAbility() result = AbilityManagerClient::GetInstance()->StartAbility(want, startoptions, nullptr); if (result != OHOS::ERR_OK) { - HILOG_ERROR("%{public}s result = %{public}d", STRING_START_ABILITY_NG.c_str(), result); + TAG_LOGE(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_START_ABILITY_NG.c_str(), result); if (result != START_ABILITY_WAITING) { resultReceiver_ = STRING_START_ABILITY_NG + "\n"; } @@ -166,7 +167,7 @@ ErrCode AbilityToolCommand::RunAsStartAbility() return result; } - HILOG_INFO("%{public}s", STRING_START_ABILITY_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_START_ABILITY_OK.c_str()); resultReceiver_ = STRING_START_ABILITY_OK + "\n"; return OHOS::ERR_OK; } @@ -183,13 +184,13 @@ ErrCode AbilityToolCommand::RunAsStopService() result = AbilityManagerClient::GetInstance()->StopServiceAbility(want); if (result != OHOS::ERR_OK) { - HILOG_ERROR("%{public}s result = %{public}d", STRING_STOP_SERVICE_ABILITY_NG.c_str(), result); + TAG_LOGE(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_STOP_SERVICE_ABILITY_NG.c_str(), result); resultReceiver_ = STRING_STOP_SERVICE_ABILITY_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); return result; } - HILOG_INFO("%{public}s", STRING_STOP_SERVICE_ABILITY_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_STOP_SERVICE_ABILITY_OK.c_str()); resultReceiver_ = STRING_STOP_SERVICE_ABILITY_OK + "\n"; return OHOS::ERR_OK; } @@ -204,13 +205,13 @@ ErrCode AbilityToolCommand::RunAsForceStop() std::string bundleName = argList_[0]; ErrCode result = AbilityManagerClient::GetInstance()->KillProcess(bundleName); if (result != OHOS::ERR_OK) { - HILOG_ERROR("%{public}s result = %{public}d", STRING_FORCE_STOP_NG.c_str(), result); + TAG_LOGE(AAFwkTag::AA_TOOL, "%{public}s result = %{public}d", STRING_FORCE_STOP_NG.c_str(), result); resultReceiver_ = STRING_FORCE_STOP_NG + "\n"; resultReceiver_.append(GetMessageFromCode(result)); return result; } - HILOG_INFO("%{public}s", STRING_FORCE_STOP_OK.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_FORCE_STOP_OK.c_str()); resultReceiver_ = STRING_FORCE_STOP_OK + "\n"; return OHOS::ERR_OK; } @@ -226,12 +227,12 @@ ErrCode AbilityToolCommand::RunAsTestCommand() } if (aaShellCmd_.get() == nullptr) { - HILOG_ERROR("aa shell command is nullptr."); + TAG_LOGE(AAFwkTag::AA_TOOL, "aa shell command is nullptr."); return OHOS::ERR_INVALID_VALUE; } if (!aaShellCmd_.get()->IsTestCommandIntegrity(params)) { - HILOG_ERROR("test command lack of essential args."); + TAG_LOGE(AAFwkTag::AA_TOOL, "test command lack of essential args."); resultReceiver_ = ABILITY_TOOL_HELP_LACK_OPTIONS + "\n"; resultReceiver_.append(ABILITY_TOOL_HELP_MSG_TEST); return OHOS::ERR_INVALID_VALUE; @@ -267,7 +268,8 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption }; while ((option = getopt_long(argc_, argv_, shortOptions.c_str(), longOptions, &index)) != EOF) { - HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + TAG_LOGI( + AAFwkTag::AA_TOOL, "option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); switch (option) { case 'h': break; @@ -284,7 +286,8 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption if (!GetKeyAndValueByOpt(optind, paramName, paramValue)) { return OHOS::ERR_INVALID_VALUE; } - HILOG_DEBUG("paramName: %{public}s, paramValue: %{public}s", paramName.c_str(), paramValue.c_str()); + TAG_LOGD(AAFwkTag::AA_TOOL, "paramName: %{public}s, paramValue: %{public}s", paramName.c_str(), + paramValue.c_str()); if (paramName == "windowMode" && std::regex_match(paramValue, sm, std::regex(STRING_TEST_REGEX_INTEGER_NUMBERS))) { windowMode = std::stoi(paramValue); @@ -309,7 +312,7 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption // Parameter check if (abilityName.size() == 0 || bundleName.size() == 0) { - HILOG_DEBUG("'ability_tool %{public}s' without enough options.", cmd_.c_str()); + TAG_LOGD(AAFwkTag::AA_TOOL, "'ability_tool %{public}s' without enough options.", cmd_.c_str()); if (abilityName.size() == 0) { resultReceiver_.append(ABILITY_TOOL_HELP_MSG_NO_ABILITY_NAME_OPTION + "\n"); } @@ -344,7 +347,7 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption windowMode != AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY && windowMode != AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY && windowMode != AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING) { - HILOG_DEBUG("'ability_tool %{public}s' %{public}s", cmd_.c_str(), + TAG_LOGD(AAFwkTag::AA_TOOL, "'ability_tool %{public}s' %{public}s", cmd_.c_str(), ABILITY_TOOL_HELP_MSG_WINDOW_MODE_INVALID.c_str()); resultReceiver_.append(ABILITY_TOOL_HELP_MSG_WINDOW_MODE_INVALID + "\n"); return OHOS::ERR_INVALID_VALUE; @@ -372,7 +375,8 @@ ErrCode AbilityToolCommand::ParseStopServiceArgsFromCmd(Want& want) }; while ((option = getopt_long(argc_, argv_, shortOptions.c_str(), longOptions, &index)) != EOF) { - HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + TAG_LOGI( + AAFwkTag::AA_TOOL, "option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); switch (option) { case 'h': break; @@ -391,7 +395,7 @@ ErrCode AbilityToolCommand::ParseStopServiceArgsFromCmd(Want& want) } if (abilityName.size() == 0 || bundleName.size() == 0) { - HILOG_INFO("'ability_tool %{public}s' without enough options.", cmd_.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "'ability_tool %{public}s' without enough options.", cmd_.c_str()); if (abilityName.size() == 0) { resultReceiver_.append(ABILITY_TOOL_HELP_MSG_NO_ABILITY_NAME_OPTION + "\n"); } @@ -419,7 +423,8 @@ ErrCode AbilityToolCommand::ParseTestArgsFromCmd(std::map= static_cast(argList_.size()) || keyIndex < 0 || valueIndex >= static_cast(argList_.size()) || valueIndex < 0) { - HILOG_DEBUG("'ability_tool %{public}s' %{public}s", cmd_.c_str(), + TAG_LOGD(AAFwkTag::AA_TOOL, "'ability_tool %{public}s' %{public}s", cmd_.c_str(), ABILITY_TOOL_HELP_MSG_LACK_VALUE.c_str()); resultReceiver_.append(ABILITY_TOOL_HELP_MSG_LACK_VALUE + "\n"); return false; diff --git a/tools/aa/src/accessibility_ability_command.cpp b/tools/aa/src/accessibility_ability_command.cpp index 03321bdd38..6aec0f0398 100644 --- a/tools/aa/src/accessibility_ability_command.cpp +++ b/tools/aa/src/accessibility_ability_command.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -25,6 +25,7 @@ #include "accessibility_config.h" #include "accessibility_system_ability_client.h" #include "bool_wrapper.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "iservice_registry.h" #include "mission_snapshot.h" @@ -240,17 +241,17 @@ AccessibilityAbilityShellCommand::AccessibilityAbilityShellCommand(int argc, cha : ShellCommand(argc, argv, ACCESSIBILITY_TOOL_NAME) { for (int i = 0; i < argc_; i++) { - HILOG_INFO("argv_[%{public}d]: %{public}s", i, argv_[i]); + TAG_LOGI(AAFwkTag::AA_TOOL, "argv_[%{public}d]: %{public}s", i, argv_[i]); } if (abilityClientPtr_ == nullptr) { abilityClientPtr_ = Accessibility::AccessibilitySystemAbilityClient::GetInstance(); if (abilityClientPtr_ == nullptr) { - HILOG_ERROR("Get accessibility system ability client failed."); + TAG_LOGE(AAFwkTag::AA_TOOL, "Get access ability system ability client failed."); } } int32_t addPermissionResult = AccessibilityUtils::AddPermission(); if (addPermissionResult != 0) { - HILOG_ERROR("Add permission for accessibility tool failed."); + TAG_LOGE(AAFwkTag::AA_TOOL, "Add permission for access ability tool failed."); } } @@ -335,7 +336,8 @@ ErrCode AccessibilityAbilityShellCommand::MakeEnableCommandArgumentFromCmd(Acces option = getopt_long(argc_, argv_, ENABLE_SHORT_OPTIONS.c_str(), ENABLE_LONG_OPTIONS, nullptr); - HILOG_INFO("option: %{public}d, optind: %{public}d, optopt: %{public}d", option, optind, optopt); + TAG_LOGI( + AAFwkTag::AA_TOOL, "option: %{public}d, optind: %{public}d, optopt: %{public}d", option, optind, optopt); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE; @@ -488,7 +490,7 @@ const std::vector AccessibilityAbilityShellCommand::GetEnabledAbili std::vector enabledAbilities; if (abilityClientPtr_ != nullptr && (abilityClientPtr_->GetEnabledAbilities(enabledAbilities) != Accessibility::RET_OK)) { - HILOG_ERROR("Failed to GetEnabledAbilities"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to GetEnabledAbilities"); } return enabledAbilities; } @@ -500,7 +502,7 @@ const std::vector AccessibilityAbilityS const Accessibility::AbilityStateType stateType = Accessibility::AbilityStateType::ABILITY_STATE_INSTALLED; if (abilityClientPtr_ != nullptr && (abilityClientPtr_->GetAbilityList(allTypes, stateType, installedAbilities) != Accessibility::RET_OK)) { - HILOG_ERROR("Failed to GetInstalledAbilities"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to GetInstalledAbilities"); } return installedAbilities; } @@ -618,19 +620,19 @@ ErrCode AccessibilityAbilityShellCommand::CheckEnableCommandArgument(const Acces } std::vector installedAbilities = GetInstalledAbilities(); if (!CheckAbilityArgument(argument, resultMessage)) { - HILOG_ERROR("abilityName = %{public}s is invalid.", argument.abilityName.c_str()); + TAG_LOGE(AAFwkTag::AA_TOOL, "abilityName = %{public}s is invalid.", argument.abilityName.c_str()); return OHOS::ERR_INVALID_VALUE; } if (!CheckBundleArgument(argument, resultMessage)) { - HILOG_ERROR("bundleName = %{public}s is invalid.", argument.bundleName.c_str()); + TAG_LOGE(AAFwkTag::AA_TOOL, "bundleName = %{public}s is invalid.", argument.bundleName.c_str()); return OHOS::ERR_INVALID_VALUE; } if (!CheckCapabilitiesArgument(argument, installedAbilities, resultMessage)) { - HILOG_ERROR("capabilityNames = %{public}s is invalid", argument.capabilityNames.c_str()); + TAG_LOGE(AAFwkTag::AA_TOOL, "capabilityNames = %{public}s is invalid", argument.capabilityNames.c_str()); return OHOS::ERR_INVALID_VALUE; } if (!CheckParamValidity(argument, installedAbilities, resultMessage)) { - HILOG_ERROR("%{public}s/%{public}s is not installed", + TAG_LOGE(AAFwkTag::AA_TOOL, "%{public}s/%{public}s is not installed", argument.bundleName.c_str(), argument.abilityName.c_str()); return OHOS::ERR_INVALID_VALUE; } @@ -691,15 +693,15 @@ ErrCode AccessibilityAbilityShellCommand::CheckCommandArgument(const Accessibili } std::vector installedAbilities = GetInstalledAbilities(); if (!CheckAbilityArgument(argument, resultMessage)) { - HILOG_ERROR("abilityName = %{public}s is invalid", argument.abilityName.c_str()); + TAG_LOGE(AAFwkTag::AA_TOOL, "abilityName = %{public}s is invalid", argument.abilityName.c_str()); return OHOS::ERR_INVALID_VALUE; } if (!CheckBundleArgument(argument, resultMessage)) { - HILOG_ERROR("bundleName = %{public}s is invalid", argument.bundleName.c_str()); + TAG_LOGE(AAFwkTag::AA_TOOL, "bundleName = %{public}s is invalid", argument.bundleName.c_str()); return OHOS::ERR_INVALID_VALUE; } if (!CheckParamValidity(argument, installedAbilities, resultMessage)) { - HILOG_ERROR("%{public}s/%{public}s is not installed", + TAG_LOGE(AAFwkTag::AA_TOOL, "%{public}s/%{public}s is not installed", argument.bundleName.c_str(), argument.abilityName.c_str()); return OHOS::ERR_INVALID_VALUE; } @@ -1180,7 +1182,8 @@ ErrCode AccessibilityAbilityShellCommand::MakeCommandArgumentFromCmd(Accessibili counter++; option = getopt_long(argc_, argv_, DISABLE_SHORT_OPTIONS.c_str(), DISABLE_LONG_OPTIONS, nullptr); - HILOG_INFO("optopt: %{public}d, option: %{public}d, optind: %{public}d", optopt, option, optind); + TAG_LOGI( + AAFwkTag::AA_TOOL, "optopt: %{public}d, option: %{public}d, optind: %{public}d", optopt, option, optind); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE; @@ -1242,7 +1245,8 @@ ErrCode AccessibilityAbilityShellCommand::MakeSetCommandArgumentFromCmd(Accessib option = getopt_long(argc_, argv_, SET_SHORT_OPTIONS.c_str(), SET_LONG_OPTIONS, nullptr); - HILOG_INFO("optind: %{public}d, optopt: %{public}d, option: %{public}d", optind, optopt, option); + TAG_LOGI( + AAFwkTag::AA_TOOL, "optind: %{public}d, optopt: %{public}d, option: %{public}d", optind, optopt, option); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE; diff --git a/tools/aa/src/accessibility_ability_utils.cpp b/tools/aa/src/accessibility_ability_utils.cpp index 2f32d48f90..d4f8a1369a 100644 --- a/tools/aa/src/accessibility_ability_utils.cpp +++ b/tools/aa/src/accessibility_ability_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -17,6 +17,7 @@ #include #include "accesstoken_kit.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "nativetoken_kit.h" #include "token_setproc.h" @@ -186,12 +187,12 @@ int32_t AccessibilityUtils::AddPermission() }; uint64_t tokenId = GetAccessTokenId(&infoInstance); if (!tokenId) { - HILOG_ERROR("Set token failed."); + TAG_LOGE(AAFwkTag::AA_TOOL, "Set token failed."); return -1; } int32_t setTokenResult = SetSelfTokenID(tokenId); if (setTokenResult != 0) { - HILOG_ERROR("Set token failed."); + TAG_LOGE(AAFwkTag::AA_TOOL, "Set token failed."); return -1; } return AccessTokenKit::ReloadNativeTokenInfo(); diff --git a/tools/aa/src/shell_command.cpp b/tools/aa/src/shell_command.cpp index 9500914584..62cc2d4e04 100644 --- a/tools/aa/src/shell_command.cpp +++ b/tools/aa/src/shell_command.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -16,13 +16,14 @@ #include "shell_command.h" #include +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" namespace OHOS { namespace AAFwk { ShellCommand::ShellCommand(int argc, char* argv[], std::string name) { - HILOG_DEBUG("start"); + TAG_LOGD(AAFwkTag::AA_TOOL, "start"); opterr = 0; argc_ = argc; argv_ = argv; @@ -36,7 +37,7 @@ ShellCommand::ShellCommand(int argc, char* argv[], std::string name) for (int i = 2; i < argc; i++) { argList_.push_back(argv[i]); } - HILOG_DEBUG("exit"); + TAG_LOGD(AAFwkTag::AA_TOOL, "exit"); } ShellCommand::~ShellCommand() @@ -44,7 +45,7 @@ ShellCommand::~ShellCommand() ErrCode ShellCommand::OnCommand() { - HILOG_DEBUG("start"); + TAG_LOGD(AAFwkTag::AA_TOOL, "start"); int result = OHOS::ERR_OK; auto respond = commandMap_[cmd_]; @@ -59,37 +60,37 @@ ErrCode ShellCommand::OnCommand() result = OHOS::ERR_INVALID_VALUE; } - HILOG_DEBUG("end"); + TAG_LOGD(AAFwkTag::AA_TOOL, "end"); return result; } std::string ShellCommand::ExecCommand() { - HILOG_DEBUG("start"); + TAG_LOGD(AAFwkTag::AA_TOOL, "start"); int result = CreateCommandMap(); if (result != OHOS::ERR_OK) { - HILOG_ERROR("failed to create command map.\n"); + TAG_LOGE(AAFwkTag::AA_TOOL, "failed to create command map.\n"); } result = CreateMessageMap(); if (result != OHOS::ERR_OK) { - HILOG_ERROR("failed to create message map.\n"); + TAG_LOGE(AAFwkTag::AA_TOOL, "failed to create message map.\n"); } result = OnCommand(); if (result != OHOS::ERR_OK) { - HILOG_ERROR("failed to execute your command.\n"); + TAG_LOGE(AAFwkTag::AA_TOOL, "failed to execute your command.\n"); resultReceiver_ = "error: failed to execute your command.\n"; } return resultReceiver_; - HILOG_DEBUG("end"); + TAG_LOGD(AAFwkTag::AA_TOOL, "end"); } std::string ShellCommand::GetCommandErrorMsg() const { - HILOG_DEBUG("start"); + TAG_LOGD(AAFwkTag::AA_TOOL, "start"); std::string commandErrorMsg = name_ + ": '" + cmd_ + "' is not a valid " + name_ + " command. See '" + name_ + " help'.\n"; @@ -98,7 +99,7 @@ std::string ShellCommand::GetCommandErrorMsg() const std::string ShellCommand::GetUnknownOptionMsg(std::string& unknownOption) const { - HILOG_DEBUG("start"); + TAG_LOGD(AAFwkTag::AA_TOOL, "start"); std::string result = ""; if (optind < 0 || optind > argc_) { @@ -113,8 +114,8 @@ std::string ShellCommand::GetUnknownOptionMsg(std::string& unknownOption) const std::string ShellCommand::GetMessageFromCode(const int32_t code) const { - HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); - HILOG_INFO("code = %{public}d", code); + TAG_LOGI(AAFwkTag::AA_TOOL, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + TAG_LOGI(AAFwkTag::AA_TOOL, "code = %{public}d", code); std::string result = ""; if (messageMap_.find(code) != messageMap_.end()) { @@ -124,7 +125,7 @@ std::string ShellCommand::GetMessageFromCode(const int32_t code) const } } - HILOG_INFO("result = %{public}s", result.c_str()); + TAG_LOGI(AAFwkTag::AA_TOOL, "result = %{public}s", result.c_str()); return result; } diff --git a/tools/aa/src/shell_command_config_loader.cpp b/tools/aa/src/shell_command_config_loader.cpp index 1ea23d821a..759b3cc45d 100644 --- a/tools/aa/src/shell_command_config_loader.cpp +++ b/tools/aa/src/shell_command_config_loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -17,6 +17,7 @@ #include #include #include +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" using json = nlohmann::json; @@ -32,16 +33,16 @@ std::set ShellCommandConfigLoder::commands_ = {}; bool ShellCommandConfigLoder::ReadConfig(const std::string &filePath) { - HILOG_INFO("%{public}s", __func__); + TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", __func__); if (configState_) { - HILOG_INFO("config has been read"); + TAG_LOGI(AAFwkTag::AA_TOOL, "config has been read"); return true; } std::ifstream inFile; inFile.open(filePath, std::ios::in); if (!inFile.is_open()) { - HILOG_INFO("read aa config error"); + TAG_LOGI(AAFwkTag::AA_TOOL, "read aa config error"); return false; } @@ -49,28 +50,28 @@ bool ShellCommandConfigLoder::ReadConfig(const std::string &filePath) inFile >> aaJson; inFile.close(); if (aaJson.is_discarded()) { - HILOG_INFO("json discarded error"); + TAG_LOGI(AAFwkTag::AA_TOOL, "json discarded error"); return false; } if (aaJson.is_null() || aaJson.empty()) { - HILOG_INFO("invalid jsonObj"); + TAG_LOGI(AAFwkTag::AA_TOOL, "invalid jsonObj"); return false; } if (!aaJson.contains(AA_TOOL_COMMAND_LIST)) { - HILOG_INFO("json config not contains the key"); + TAG_LOGI(AAFwkTag::AA_TOOL, "json config not contains the key"); return false; } if (aaJson[AA_TOOL_COMMAND_LIST].is_null() || !aaJson[AA_TOOL_COMMAND_LIST].is_array() || aaJson[AA_TOOL_COMMAND_LIST].empty()) { - HILOG_INFO("invalid command obj size"); + TAG_LOGI(AAFwkTag::AA_TOOL, "invalid command obj size"); return false; } if (aaJson[AA_TOOL_COMMAND_LIST].size() > COMMANDS_MAX_SIZE) { - HILOG_INFO("command obj size overflow"); + TAG_LOGI(AAFwkTag::AA_TOOL, "command obj size overflow"); return false; } @@ -80,12 +81,12 @@ bool ShellCommandConfigLoder::ReadConfig(const std::string &filePath) continue; } std::string cmd = aaJson[AA_TOOL_COMMAND_LIST][i].get(); - HILOG_DEBUG("add cmd: %{public}s", cmd.c_str()); + TAG_LOGD(AAFwkTag::AA_TOOL, "add cmd: %{public}s", cmd.c_str()); commands_.emplace(cmd); } aaJson.clear(); - HILOG_INFO("read config success"); + TAG_LOGI(AAFwkTag::AA_TOOL, "read config success"); configState_ = true; return true; } diff --git a/tools/aa/src/shell_command_executor.cpp b/tools/aa/src/shell_command_executor.cpp index 4f70e8ce2b..2c5603deb4 100644 --- a/tools/aa/src/shell_command_executor.cpp +++ b/tools/aa/src/shell_command_executor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -20,6 +20,7 @@ #include #include +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "shell_command_config_loader.h" @@ -34,10 +35,10 @@ ShellCommandExecutor::ShellCommandExecutor(const std::string& cmd, const int64_t ShellCommandResult ShellCommandExecutor::WaitWorkDone() { - HILOG_INFO("enter"); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter"); if (!DoWork()) { - HILOG_INFO("Failed to execute command : \"%{public}s\"", cmd_.data()); + TAG_LOGI(AAFwkTag::AA_TOOL, "Failed to execute command : \"%{public}s\"", cmd_.data()); return cmdResult_; } @@ -47,7 +48,7 @@ ShellCommandResult ShellCommandExecutor::WaitWorkDone() if (timeoutSec_ <= 0) { cvWork_.wait(workLock, condition); } else if (!cvWork_.wait_for(workLock, timeoutSec_ * 1s, condition)) { - HILOG_WARN("Command execution timed out! cmd : \"%{public}s\", timeoutSec : %{public}" PRId64, + TAG_LOGW(AAFwkTag::AA_TOOL, "Command execution timed out! cmd : \"%{public}s\", timeoutSec : %{public}" PRId64, cmd_.data(), timeoutSec_); std::cout << "Warning! Command execution timed out! cmd : " << cmd_ << ", timeoutSec : " << timeoutSec_ << std::endl; @@ -61,44 +62,44 @@ ShellCommandResult ShellCommandExecutor::WaitWorkDone() return realResult; } - HILOG_INFO("Command execution complete, cmd : \"%{public}s\", exitCode : %{public}d", + TAG_LOGI(AAFwkTag::AA_TOOL, "Command execution complete, cmd : \"%{public}s\", exitCode : %{public}d", cmd_.data(), cmdResult_.exitCode); return cmdResult_; } bool ShellCommandExecutor::DoWork() { - HILOG_INFO("enter"); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter"); if (cmd_.empty()) { - HILOG_ERROR("Invalid command"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Invalid command"); return false; } if (!handler_) { - HILOG_ERROR("Invalid event handler"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Invalid event handler"); return false; } if (!CheckCommand()) { - HILOG_ERROR("Invalid command"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Invalid command"); return false; } auto self(shared_from_this()); handler_->PostTask([this, self]() { - HILOG_INFO("DoWork async task begin, cmd : \"%{public}s\"", cmd_.data()); + TAG_LOGI(AAFwkTag::AA_TOOL, "DoWork async task begin, cmd : \"%{public}s\"", cmd_.data()); FILE* file = popen(cmd_.c_str(), "r"); if (!file) { - HILOG_ERROR("Failed to call popen, cmd : \"%{public}s\"", cmd_.data()); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to call popen, cmd : \"%{public}s\"", cmd_.data()); { std::unique_lock workLock(mtxWork_); isDone_ = true; } cvWork_.notify_one(); - HILOG_INFO("DoWork async task end, cmd : \"%{public}s\"", cmd_.data()); + TAG_LOGI(AAFwkTag::AA_TOOL, "DoWork async task end, cmd : \"%{public}s\"", cmd_.data()); return; } @@ -119,7 +120,7 @@ bool ShellCommandExecutor::DoWork() isDone_ = true; } cvWork_.notify_one(); - HILOG_INFO("DoWork async task end, cmd : \"%{public}s\"", cmd_.data()); + TAG_LOGI(AAFwkTag::AA_TOOL, "DoWork async task end, cmd : \"%{public}s\"", cmd_.data()); }); return true; diff --git a/tools/aa/src/shell_command_result.cpp b/tools/aa/src/shell_command_result.cpp index 7bca86c975..47f30688cc 100644 --- a/tools/aa/src/shell_command_result.cpp +++ b/tools/aa/src/shell_command_result.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -15,6 +15,7 @@ #include "shell_command_result.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" namespace OHOS { @@ -22,12 +23,12 @@ namespace AAFwk { bool ShellCommandResult::Marshalling(Parcel& parcel) const { if (!parcel.WriteInt32(exitCode)) { - HILOG_ERROR("Failed to write exitCode"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to write exitCode"); return false; } if (!parcel.WriteString(stdResult)) { - HILOG_ERROR("Failed to write stdResult"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to write stdResult"); return false; } diff --git a/tools/aa/src/system_time.cpp b/tools/aa/src/system_time.cpp index 7a1e18dfda..972696d017 100644 --- a/tools/aa/src/system_time.cpp +++ b/tools/aa/src/system_time.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -15,6 +15,7 @@ #include "system_time.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "inner_event.h" @@ -24,7 +25,7 @@ using namespace OHOS::AppExecFwk; int64_t SystemTime::GetNowSysTime() { - HILOG_INFO("enter"); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter"); InnerEvent::TimePoint nowSys = InnerEvent::Clock::now(); auto epoch = nowSys.time_since_epoch(); diff --git a/tools/aa/src/test_observer.cpp b/tools/aa/src/test_observer.cpp index 465204b261..db6e597054 100644 --- a/tools/aa/src/test_observer.cpp +++ b/tools/aa/src/test_observer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -19,6 +19,7 @@ #include #include +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "shell_command_config_loader.h" #include "shell_command_executor.h" @@ -40,14 +41,14 @@ TestObserver::~TestObserver() void TestObserver::TestStatus(const std::string& msg, const int64_t& resultCode) { - HILOG_INFO("enter, msg : %{public}s, code : %{public}" PRId64, msg.data(), resultCode); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter, msg : %{public}s, code : %{public}" PRId64, msg.data(), resultCode); printf("%s\n", msg.data()); fflush(stdout); } void TestObserver::TestFinished(const std::string& msg, const int64_t& resultCode) { - HILOG_INFO("enter, msg : %{public}s, code : %{public}" PRId64, msg.data(), resultCode); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter, msg : %{public}s, code : %{public}" PRId64, msg.data(), resultCode); std::cout << "TestFinished-ResultCode: " + std::to_string(resultCode) << std::endl; std::cout << "TestFinished-ResultMsg: " + msg << std::endl; isFinished_ = true; @@ -55,16 +56,16 @@ void TestObserver::TestFinished(const std::string& msg, const int64_t& resultCod ShellCommandResult TestObserver::ExecuteShellCommand(const std::string& cmd, const int64_t timeoutSec) { - HILOG_INFO("enter, cmd : \"%{public}s\", timeoutSec : %{public}" PRId64, cmd.data(), timeoutSec); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter, cmd : \"%{public}s\", timeoutSec : %{public}" PRId64, cmd.data(), timeoutSec); auto cmdExecutor = std::make_shared(cmd, timeoutSec); if (!cmdExecutor) { - HILOG_ERROR("Failed to create ShellCommandExecutor intance"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to create ShellCommandExecutor intance"); return {}; } if (!std::make_shared()->ReadConfig(AA_TOOL_COMMAND_CONFIG)) { - HILOG_ERROR("Failed to read config"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to read config"); return {}; } @@ -73,7 +74,7 @@ ShellCommandResult TestObserver::ExecuteShellCommand(const std::string& cmd, con bool TestObserver::WaitForFinish(const int64_t& timeoutMs) { - HILOG_INFO("enter"); + TAG_LOGI(AAFwkTag::AA_TOOL, "enter"); auto realTime = timeoutMs > 0 ? timeoutMs : 0; int64_t startTime = SystemTime::GetNowSysTime(); @@ -85,7 +86,7 @@ bool TestObserver::WaitForFinish(const int64_t& timeoutMs) sleep(1); } - HILOG_INFO("User test finished"); + TAG_LOGI(AAFwkTag::AA_TOOL, "User test finished"); return true; } } // namespace AAFwk diff --git a/tools/aa/src/test_observer_proxy.cpp b/tools/aa/src/test_observer_proxy.cpp index da4cf4e9c7..783f3e8956 100644 --- a/tools/aa/src/test_observer_proxy.cpp +++ b/tools/aa/src/test_observer_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -14,23 +14,24 @@ */ #include "test_observer_proxy.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" namespace OHOS { namespace AAFwk { TestObserverProxy::TestObserverProxy(const sptr& object) : IRemoteProxy(object) { - HILOG_INFO("test observer proxy instance is created"); + TAG_LOGI(AAFwkTag::AA_TOOL, "test observer proxy instance is created"); } TestObserverProxy::~TestObserverProxy() { - HILOG_INFO("test observer proxy is destroyed"); + TAG_LOGI(AAFwkTag::AA_TOOL, "test observer proxy is destroyed"); } void TestObserverProxy::TestStatus(const std::string& msg, const int64_t& resultCode) { - HILOG_INFO("TestStatus start"); + TAG_LOGI(AAFwkTag::AA_TOOL, "TestStatus start"); MessageParcel data; MessageParcel reply; @@ -41,26 +42,26 @@ void TestObserverProxy::TestStatus(const std::string& msg, const int64_t& result } if (!data.WriteString(msg)) { - HILOG_ERROR("Write string msg failed"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Write string msg failed"); return; } if (!data.WriteInt64(resultCode)) { - HILOG_ERROR("Write resultCode failed"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Write resultCode failed"); return; } int32_t result = SendTransactCmd( static_cast(ITestObserver::Message::AA_TEST_STATUS), data, reply, option); if (result != OHOS::NO_ERROR) { - HILOG_ERROR("SendRequest failed, error code: %{public}d", result); + TAG_LOGE(AAFwkTag::AA_TOOL, "SendRequest failed, error code: %{public}d", result); return; } } void TestObserverProxy::TestFinished(const std::string& msg, const int64_t& resultCode) { - HILOG_INFO("TestFinished start"); + TAG_LOGI(AAFwkTag::AA_TOOL, "TestFinished start"); MessageParcel data; MessageParcel reply; @@ -71,19 +72,19 @@ void TestObserverProxy::TestFinished(const std::string& msg, const int64_t& resu } if (!data.WriteString(msg)) { - HILOG_ERROR("Failed to write string msg"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to write string msg"); return; } if (!data.WriteInt64(resultCode)) { - HILOG_ERROR("Failed to write resultCode"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to write resultCode"); return; } int32_t result = SendTransactCmd( static_cast(ITestObserver::Message::AA_TEST_FINISHED), data, reply, option); if (result != OHOS::NO_ERROR) { - HILOG_ERROR("Failed to SendRequest, error code: %{public}d", result); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to SendRequest, error code: %{public}d", result); return; } } @@ -91,7 +92,7 @@ void TestObserverProxy::TestFinished(const std::string& msg, const int64_t& resu ShellCommandResult TestObserverProxy::ExecuteShellCommand( const std::string& cmd, const int64_t timeoutSec) { - HILOG_INFO("start"); + TAG_LOGI(AAFwkTag::AA_TOOL, "start"); ShellCommandResult result; MessageParcel data; @@ -103,24 +104,24 @@ ShellCommandResult TestObserverProxy::ExecuteShellCommand( } if (!data.WriteString(cmd)) { - HILOG_ERROR("Failed to write string cmd"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to write string cmd"); return result; } if (!data.WriteInt64(timeoutSec)) { - HILOG_ERROR("Failed to write timeoutSec"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to write timeoutSec"); return result; } int32_t ret = SendTransactCmd( static_cast(ITestObserver::Message::AA_EXECUTE_SHELL_COMMAND), data, reply, option); if (ret != OHOS::NO_ERROR) { - HILOG_ERROR("Failed to SendRequest, error code: %{public}d", ret); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to SendRequest, error code: %{public}d", ret); return result; } ShellCommandResult* resultPtr = reply.ReadParcelable(); if (!resultPtr) { - HILOG_ERROR("Failed to read result"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to read result"); return result; } result = *resultPtr; @@ -135,7 +136,7 @@ int32_t TestObserverProxy::SendTransactCmd(uint32_t code, MessageParcel &data, { sptr remote = Remote(); if (remote == nullptr) { - HILOG_ERROR("Remote is nullptr."); + TAG_LOGE(AAFwkTag::AA_TOOL, "Remote is nullptr."); return ERR_NULL_OBJECT; } diff --git a/tools/aa/src/test_observer_stub.cpp b/tools/aa/src/test_observer_stub.cpp index d64185b9f0..bab144909c 100644 --- a/tools/aa/src/test_observer_stub.cpp +++ b/tools/aa/src/test_observer_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -14,24 +14,25 @@ */ #include "test_observer_stub.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" namespace OHOS { namespace AAFwk { TestObserverStub::TestObserverStub() { - HILOG_INFO("test observer stub instance is created"); + TAG_LOGI(AAFwkTag::AA_TOOL, "test observer stub instance is created"); } TestObserverStub::~TestObserverStub() { - HILOG_INFO("test observer stub instance is destroyed"); + TAG_LOGI(AAFwkTag::AA_TOOL, "test observer stub instance is destroyed"); } int TestObserverStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { if (data.ReadInterfaceToken() != GetDescriptor()) { - HILOG_ERROR("local descriptor is not equal to remote"); + TAG_LOGE(AAFwkTag::AA_TOOL, "local descriptor is not equal to remote"); return ERR_TRANSACTION_FAILED; } switch (code) { @@ -52,13 +53,13 @@ int TestObserverStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messag int64_t timeoutSecs = data.ReadInt64(); ShellCommandResult result = ExecuteShellCommand(cmd, timeoutSecs); if (!reply.WriteParcelable(&result)) { - HILOG_ERROR("Failed to write reply ShellCommandResult!"); + TAG_LOGE(AAFwkTag::AA_TOOL, "Failed to write reply ShellCommandResult!"); return ERR_INVALID_VALUE; } break; } default: - HILOG_WARN("event receive stub receives unknown code, code = %{public}u", code); + TAG_LOGW(AAFwkTag::AA_TOOL, "event receive stub receives unknown code, code = %{public}u", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); }