diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index fdca50b6dcef7a63f0c9e2ecbc7ee8d1b73bbace..7196b12f102e089e3fd44c10f85feced9be6d547 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -38,6 +38,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", @@ -95,6 +96,8 @@ ohos_shared_library("ans_core") { "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", + "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 0000000000000000000000000000000000000000..29f4e36a4991d328ec2342496435477ba2c6be81 --- /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 0000000000000000000000000000000000000000..32e28f80a9b9529bb71f48e961ff2012b65fdfb4 --- /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 0a68398f59dd4fb29f08658b449a6f444ee9d17b..d24265d868d72786a3b4ff042acf1caa19ca13b7 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -24,6 +24,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" +#include "ans_watchdog.h" #include "bundle_manager_helper.h" #include "ipc_skeleton.h" #include "notification_constant.h" @@ -232,6 +233,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 1cccad0594456b9e0a2fa08b7ca4e967541fcf6c..205b3e9c345a709bb026617b0f34b56522db2e76 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 be2dba32af65c19d111c4783ef1904f6560a2528..7bc78aa8c58927c542418a8db663c06676dc050f 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, diff --git a/services/distributed/test/unittest/mock/mock_event_runner.cpp b/services/distributed/test/unittest/mock/mock_event_runner.cpp index 4e3cdb37c2911ce62175b359e768353c26a80bc6..1fa2b024841fc75af4e7fd98d54b271ab3a44a45 100644 --- a/services/distributed/test/unittest/mock/mock_event_runner.cpp +++ b/services/distributed/test/unittest/mock/mock_event_runner.cpp @@ -26,5 +26,11 @@ std::shared_ptr EventRunner::Create(bool inNewThread) { return std::shared_ptr(new EventRunner(false)); } + + +std::string EventRunner::GetRunnerThreadName() const +{ + return "1111111"; +} } // namespace AppExecFwk } // namespace OHOS