From 1f3049a82a4f2f7609f42cff98b2640763509f69 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Tue, 19 Apr 2022 14:31:31 +0800 Subject: [PATCH] add xcollie Signed-off-by: liuyanzhi Change-Id: I5fd029b8145768385230abd893defb0580b354a0 --- frameworks/ans/core/BUILD.gn | 3 ++ .../ans/core/common/include/ans_watchdog.h | 35 +++++++++++++++++++ .../ans/core/common/src/ans_watchdog.cpp | 34 ++++++++++++++++++ .../ans/src/advanced_notification_service.cpp | 2 ++ .../src/notification_subscriber_manager.cpp | 2 ++ .../src/distributed_notification_manager.cpp | 2 ++ 6 files changed, 78 insertions(+) create mode 100644 frameworks/ans/core/common/include/ans_watchdog.h create mode 100644 frameworks/ans/core/common/src/ans_watchdog.cpp diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index 89211e523..94578456f 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -36,6 +36,7 @@ config("public_ans_core_config") { ohos_shared_library("ans_core") { sources = [ "${core_path}/common/src/ans_log_wrapper.cpp", + "${core_path}/common/src/ans_watchdog.cpp", "${core_path}/src/ans_image_util.cpp", "${core_path}/src/ans_manager_death_recipient.cpp", "${core_path}/src/ans_manager_proxy.cpp", @@ -94,6 +95,8 @@ ohos_shared_library("ans_core") { "ability_base:zuri", "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", + "eventhandler:libeventhandler", + "hicollie_native:libhicollie", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", diff --git a/frameworks/ans/core/common/include/ans_watchdog.h b/frameworks/ans/core/common/include/ans_watchdog.h new file mode 100644 index 000000000..466e08607 --- /dev/null +++ b/frameworks/ans/core/common/include/ans_watchdog.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_WATCHDOG_H +#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_WATCHDOG_H + +#include "event_handler.h" +#include "event_runner.h" + +namespace OHOS { +namespace Notification { +class AnsWatchdog { +public: + AnsWatchdog() = delete; + ~AnsWatchdog() = delete; + + static void AddHandlerThread(std::shared_ptr handler, + std::shared_ptr runner); +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_WATCHDOG_H \ No newline at end of file diff --git a/frameworks/ans/core/common/src/ans_watchdog.cpp b/frameworks/ans/core/common/src/ans_watchdog.cpp new file mode 100644 index 000000000..f9546d4bc --- /dev/null +++ b/frameworks/ans/core/common/src/ans_watchdog.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ans_watchdog.h" +#include "ans_log_wrapper.h" +#include "xcollie/watchdog.h" + +namespace OHOS { +namespace Notification { +void AnsWatchdog::AddHandlerThread(std::shared_ptr handler, + std::shared_ptr runner) +{ + if (handler != nullptr && runner != nullptr) { + std::string threadName = handler->GetEventRunner()->GetRunnerThreadName(); + unsigned int timeval = 5000; + if (Singleton::GetInstance().AddThread(threadName, handler, timeval) != 0) { + ANS_LOGE("Failed to Add handler Thread"); + } + } +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 3360c847f..64b450bec 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -26,6 +26,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" +#include "ans_watchdog.h" #include "ans_permission_def.h" #include "bundle_manager_helper.h" #include "display_manager.h" @@ -234,6 +235,7 @@ AdvancedNotificationService::AdvancedNotificationService() { runner_ = OHOS::AppExecFwk::EventRunner::Create(); handler_ = std::make_shared(runner_); + AnsWatchdog::AddHandlerThread(handler_, runner_); recentInfo_ = std::make_shared(); distributedKvStoreDeathRecipient_ = std::make_shared( std::bind(&AdvancedNotificationService::OnDistributedKvStoreDeathRecipient, this)); diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 846996cb8..563b153c3 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -22,6 +22,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" +#include "ans_watchdog.h" #include "ipc_skeleton.h" #include "os_account_manager.h" #include "remote_death_recipient.h" @@ -39,6 +40,7 @@ NotificationSubscriberManager::NotificationSubscriberManager() { runner_ = OHOS::AppExecFwk::EventRunner::Create(); handler_ = std::make_shared(runner_); + AnsWatchdog::AddHandlerThread(handler_, runner_); recipient_ = new RemoteDeathRecipient(std::bind(&NotificationSubscriberManager::OnRemoteDied, this, std::placeholders::_1)); } diff --git a/services/distributed/src/distributed_notification_manager.cpp b/services/distributed/src/distributed_notification_manager.cpp index be2dba32a..7bc78aa8c 100644 --- a/services/distributed/src/distributed_notification_manager.cpp +++ b/services/distributed/src/distributed_notification_manager.cpp @@ -19,6 +19,7 @@ #include "ans_inner_errors.h" #include "ans_log_wrapper.h" +#include "ans_watchdog.h" namespace OHOS { namespace Notification { @@ -30,6 +31,7 @@ DistributedNotificationManager::DistributedNotificationManager() { runner_ = OHOS::AppExecFwk::EventRunner::Create(); handler_ = std::make_shared(runner_); + AnsWatchdog::AddHandlerThread(handler_, runner_); DistributedDatabaseCallback::IDatabaseChange databaseCallback = { .OnInsert = std::bind(&DistributedNotificationManager::OnDatabaseInsert, -- Gitee