diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index 89211e523b23703f57d1eebe3990a03b4fb53f98..94578456f0960fd25fa6397b96ad82d08a0ebdce 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 0000000000000000000000000000000000000000..466e0860785ef9b0b17feefed1048bcd3873f0d8 --- /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..f9546d4bc97c13fe385bf32c7cd8e52c69825a30 --- /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 3360c847f2b166215b2e97d06f7c114cb05a3ac6..64b450bec7160db00d8f3921ee1fd9e887377f67 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 846996cb8a8439a937c192a290fc5eb2310481c0..563b153c3bf98c20b5cd90961ae403abb1250fc5 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,