diff --git a/frameworks/common/BUILD.gn b/frameworks/common/BUILD.gn index 905bea406..8b0d66ce9 100644 --- a/frameworks/common/BUILD.gn +++ b/frameworks/common/BUILD.gn @@ -45,6 +45,7 @@ ohos_shared_library("libaccount_common") { "file_operator/src/account_file_operator.cpp", "log/src/account_log_wrapper.cpp", "perf_stat/src/perf_stat.cpp", + "utils/src/account_constants.cpp", "utils/src/account_permission_manager.cpp", "utils/src/memory_guard.cpp", ] @@ -85,6 +86,11 @@ ohos_shared_library("libaccount_common") { cflags += [ "-DWITH_SELINUX" ] } + if (hicollie_enable == true) { + external_deps += [ "hicollie:libhicollie" ] + cflags_cc += [ "-DHICOLLIE_ENABLE" ] + } + subsystem_name = "account" innerapi_tags = [ "platformsdk" ] part_name = "os_account" diff --git a/frameworks/common/utils/include/account_constants.h b/frameworks/common/utils/include/account_constants.h index adf567063..84d266ebe 100644 --- a/frameworks/common/utils/include/account_constants.h +++ b/frameworks/common/utils/include/account_constants.h @@ -15,6 +15,7 @@ #ifndef OS_ACCOUNT_FRAMEWORKS_ACCOUNT_CONSTANTS_H #define OS_ACCOUNT_FRAMEWORKS_ACCOUNT_CONSTANTS_H +#include #define TOKEN_ID_LOWMASK 0xffffffff namespace OHOS { @@ -25,6 +26,15 @@ const uint32_t TIMEOUT = 30; // 30s constexpr const char TIMER_NAME[] = "AccountMgrTimer"; #endif // HICOLLIE_ENABLE +class AccountTimer { +public: + AccountTimer(bool needInit = true); + ~AccountTimer(); + void Init(); + +private: + int64_t timerId_ = -1; +}; } // namespace AccountSA } // namespace OHOS #endif // OS_ACCOUNT_FRAMEWORKS_ACCOUNT_CONSTANTS_H \ No newline at end of file diff --git a/frameworks/common/utils/src/account_constants.cpp b/frameworks/common/utils/src/account_constants.cpp new file mode 100644 index 000000000..25a9b84c4 --- /dev/null +++ b/frameworks/common/utils/src/account_constants.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "account_constants.h" + +#ifdef HICOLLIE_ENABLE +#include "xcollie/xcollie.h" +#endif // HICOLLIE_ENABLE + +namespace OHOS { +namespace AccountSA { +AccountTimer::AccountTimer(bool needInit) +{ + if (needInit) { + Init(); + } +} + +AccountTimer::~AccountTimer() +{ +#ifdef HICOLLIE_ENABLE + HiviewDFX::XCollie::GetInstance().CancelTimer(timerId_); +#endif // HICOLLIE_ENABLE +} + +void AccountTimer::Init() +{ +#ifdef HICOLLIE_ENABLE + timerId_ = HiviewDFX::XCollie::GetInstance().SetTimer( + TIMER_NAME, TIMEOUT, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG); +#endif // HICOLLIE_ENABLE +} +} // namespace AccountSA +} // namespace OHOS diff --git a/services/accountmgr/src/osaccount/inner_os_account_manager.cpp b/services/accountmgr/src/osaccount/inner_os_account_manager.cpp index 0eb293dba..4475047a7 100644 --- a/services/accountmgr/src/osaccount/inner_os_account_manager.cpp +++ b/services/accountmgr/src/osaccount/inner_os_account_manager.cpp @@ -419,6 +419,7 @@ ErrCode IInnerOsAccountManager::CreateOsAccount( ACCOUNT_LOGI("Not allow creation account."); return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_PLUGIN_NOT_ALLOWED_CREATION_ERROR; } + AccountTimer timer; unsigned int osAccountNum = 0; GetCreatedOsAccountsCount(osAccountNum); if (!AccountPermissionManager::CheckSaCall() && osAccountNum >= config_.maxOsAccountNum) { @@ -446,6 +447,7 @@ ErrCode IInnerOsAccountManager::CreateOsAccount(const std::string &localName, co ACCOUNT_LOGI("Not allow creation account."); return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_PLUGIN_NOT_ALLOWED_CREATION_ERROR; } + AccountTimer timer; osAccountInfo.SetLocalName(localName); #ifdef ENABLE_ACCOUNT_SHORT_NAME OsAccountInfo accountInfoOld; @@ -513,6 +515,7 @@ ErrCode IInnerOsAccountManager::CreateOsAccountWithFullInfo(OsAccountInfo &osAcc ACCOUNT_LOGI("Not allow creation account."); return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_PLUGIN_NOT_ALLOWED_CREATION_ERROR; } + AccountTimer timer; if (!CheckAndAddLocalIdOperating(osAccountInfo.GetLocalId())) { ACCOUNT_LOGW("Account id = %{public}d already in operating", osAccountInfo.GetLocalId()); return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_OPERATING_ERROR; @@ -652,6 +655,7 @@ ErrCode IInnerOsAccountManager::CreateOsAccountForDomain( ACCOUNT_LOGI("Not allow creation account."); return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_PLUGIN_NOT_ALLOWED_CREATION_ERROR; } + AccountTimer timer; std::vector osAccountInfos; (void)QueryAllCreatedOsAccounts(osAccountInfos); if (CheckDomainAccountBound(osAccountInfos, domainInfo)) { diff --git a/services/accountmgr/src/osaccount/os_account_stub.cpp b/services/accountmgr/src/osaccount/os_account_stub.cpp index f675a0b74..8097e3149 100644 --- a/services/accountmgr/src/osaccount/os_account_stub.cpp +++ b/services/accountmgr/src/osaccount/os_account_stub.cpp @@ -29,6 +29,12 @@ namespace AccountSA { #ifdef HICOLLIE_ENABLE constexpr std::int32_t RECOVERY_TIMEOUT = 6; // timeout 6s #endif // HICOLLIE_ENABLE +const std::set WATCH_DOG_WHITE_LIST = { + static_cast(OsAccountInterfaceCode::CREATE_OS_ACCOUNT), + static_cast(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_WITH_SHORT_NAME), + static_cast(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_WITH_FULL_INFO), + static_cast(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_FOR_DOMAIN), +}; const std::map messageProcMap = { { static_cast(OsAccountInterfaceCode::CREATE_OS_ACCOUNT), @@ -505,10 +511,10 @@ int OsAccountStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR; } -#ifdef HICOLLIE_ENABLE - int timerId = - HiviewDFX::XCollie::GetInstance().SetTimer(TIMER_NAME, TIMEOUT, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG); -#endif // HICOLLIE_ENABLE + AccountTimer timer(false); + if (WATCH_DOG_WHITE_LIST.find(code) == WATCH_DOG_WHITE_LIST.end()) { + timer.Init(); + } auto messageProc = messageProcMap_.find(code); if (messageProc != messageProcMap_.end()) { @@ -517,21 +523,12 @@ int OsAccountStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa ErrCode result = AccountPermissionManager::CheckSystemApp(); if (result != ERR_OK) { ACCOUNT_LOGE("is not system application, result = %{public}u.", result); -#ifdef HICOLLIE_ENABLE - HiviewDFX::XCollie::GetInstance().CancelTimer(timerId); -#endif // HICOLLIE_ENABLE return result; } } int ret = (messageProcFunction.messageProcFunction)(this, data, reply); -#ifdef HICOLLIE_ENABLE - HiviewDFX::XCollie::GetInstance().CancelTimer(timerId); -#endif // HICOLLIE_ENABLE return ret; } -#ifdef HICOLLIE_ENABLE - HiviewDFX::XCollie::GetInstance().CancelTimer(timerId); -#endif // HICOLLIE_ENABLE return IPCObjectStub::OnRemoteRequest(code, data, reply, option); }