From c936fc6031717de584376b51c0715b15fae23d24 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Thu, 27 Jan 2022 15:29:09 +0800 Subject: [PATCH] add handler hicollie Signed-off-by: liuyanzhi Change-Id: I6f846a4735450174ec1744b0a7fbd21c92e18d42 --- services/ans/BUILD.gn | 1 + services/ans/include/advanced_notification_service.h | 2 ++ .../ans/include/notification_subscriber_manager.h | 2 ++ services/ans/src/advanced_notification_service.cpp | 9 +++++++++ services/ans/src/notification_subscriber_manager.cpp | 9 +++++++++ services/ans/test/unittest/BUILD.gn | 2 +- .../unittest/advanced_notification_service_test.cpp | 12 ++++++++++++ .../notification_subscriber_manager_test.cpp | 12 ++++++++++++ services/distributed/BUILD.gn | 1 + .../include/distributed_notification_manager.h | 2 ++ .../src/distributed_notification_manager.cpp | 9 +++++++++ services/distributed/test/unittest/BUILD.gn | 1 + .../distributed_notification_manager_test.cpp | 10 ++++++++++ .../test/unittest/mock/mock_event_runner.cpp | 5 +++++ services/test/moduletest/BUILD.gn | 1 + 15 files changed, 77 insertions(+), 1 deletion(-) diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index c8d570535..8578e1f4d 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -72,6 +72,7 @@ ohos_shared_library("libans") { external_deps = [ "ability_runtime:abilitykit_native", "distributeddatamgr:distributeddata_inner", + "hicollie_native:libhicollie", "multimedia_image_standard:image_native", "os_account_standard:os_account_innerkits", "time_native:time_service", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index f7029a8c4..b75e9556b 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -94,6 +94,7 @@ public: ErrCode SetShowBadgeEnabledForBundle(const sptr &bundleOption, bool enabled) override; ErrCode GetShowBadgeEnabledForBundle(const sptr &bundleOption, bool &enabled) override; ErrCode GetShowBadgeEnabled(bool &enabled) override; + int GetNotificationAddThread() const; ErrCode Subscribe(const sptr &subscriber, const sptr &info) override; ErrCode Unsubscribe(const sptr &subscriber, const sptr &info) override; ErrCode IsAllowedNotify(bool &allowed) override; @@ -206,6 +207,7 @@ private: std::shared_ptr distributedKvStoreDeathRecipient_ = nullptr; std::shared_ptr systemEventObserver_ = nullptr; DistributedKv::DistributedKvDataManager dataManager_; + int addThreadSuccess = 1; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED NotificationConstant::DistributedReminderPolicy distributedReminderPolicy_ = DEFAULT_DISTRIBUTED_REMINDER_POLICY; bool localScreenOn_ = true; diff --git a/services/ans/include/notification_subscriber_manager.h b/services/ans/include/notification_subscriber_manager.h index f6e2ae645..3938be1f7 100644 --- a/services/ans/include/notification_subscriber_manager.h +++ b/services/ans/include/notification_subscriber_manager.h @@ -48,6 +48,7 @@ public: void NotifyUpdated(const sptr ¬ificationMap); void NotifyDoNotDisturbDateChanged(const sptr &date); void OnRemoteDied(const wptr &object); + int GetSubscribeAddThread() const; private: struct SubscriberRecord; @@ -77,6 +78,7 @@ private: std::shared_ptr handler_ {}; sptr ansSubscriberProxy_ {}; sptr recipient_ {}; + int addThreadSuccess = 1; DECLARE_DELAYED_SINGLETON(NotificationSubscriberManager); DISALLOW_COPY_AND_MOVE(NotificationSubscriberManager); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index eb2b4d0c7..4d6650521 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -36,6 +36,7 @@ #include "reminder_data_manager.h" #include "trigger_info.h" #include "want_agent_helper.h" +#include "xcollie/watchdog.h" #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED #include "distributed_notification_manager.h" @@ -192,10 +193,18 @@ sptr AdvancedNotificationService::GetInstance() return instance_; } +int AdvancedNotificationService::GetNotificationAddThread() const +{ + return addThreadSuccess; +} + AdvancedNotificationService::AdvancedNotificationService() { runner_ = OHOS::AppExecFwk::EventRunner::Create(); handler_ = std::make_shared(runner_); + std::string threadName = handler_->GetEventRunner()->GetRunnerThreadName(); + unsigned int timeval = 5000; + addThreadSuccess = Singleton::GetInstance().AddThread(threadName, handler_, timeval); 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 9c2dcda42..7815ad802 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -25,6 +25,7 @@ #include "ipc_skeleton.h" #include "os_account_manager.h" #include "remote_death_recipient.h" +#include "xcollie/watchdog.h" namespace OHOS { namespace Notification { @@ -35,10 +36,18 @@ struct NotificationSubscriberManager::SubscriberRecord { int32_t userId {SUBSCRIBE_USER_INIT}; }; +int NotificationSubscriberManager::GetSubscribeAddThread() const +{ + return addThreadSuccess; +} + NotificationSubscriberManager::NotificationSubscriberManager() { runner_ = OHOS::AppExecFwk::EventRunner::Create(); handler_ = std::make_shared(runner_); + std::string threadName = handler_->GetEventRunner()->GetRunnerThreadName(); + unsigned int timeval = 5000; + addThreadSuccess = Singleton::GetInstance().AddThread(threadName, handler_, timeval); recipient_ = new RemoteDeathRecipient(std::bind(&NotificationSubscriberManager::OnRemoteDied, this, std::placeholders::_1)); } diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index de0decb93..6ac41b975 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -84,6 +84,7 @@ ohos_unittest("ans_unit_test") { "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "hicollie_native:libhicollie", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", @@ -101,6 +102,5 @@ ohos_unittest("ans_unit_test") { group("unittest") { testonly = true deps = [] - deps += [ ":ans_unit_test" ] } diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 441a16cfd..59511ac1a 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1626,5 +1626,17 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11300, EXPECT_EQ( advancedNotificationService_->CancelContinuousTaskNotification(label, 1), (int)ERR_ANS_NOT_SYSTEM_SERVICE); } + +/** + * @tc.number : AdvancedNotificationServiceTest_11400 + * @tc.name : Ans notification add thread + * @tc.desc : Test add thread is success + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11400, Function | SmallTest | Level1) +{ + AdvancedNotificationService advancedNotificationService; + std::shared_ptr notificationService = std::make_shared(); + EXPECT_EQ(0, advancedNotificationService.GetNotificationAddThread()); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/notification_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_test.cpp index eb8d6f743..4023619d6 100644 --- a/services/ans/test/unittest/notification_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_test.cpp @@ -188,5 +188,17 @@ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_00 sptr info = new NotificationSubscribeInfo(); EXPECT_EQ(notificationSubscriberManager_->RemoveSubscriber(nullptr, info), (int)ERR_ANS_INVALID_PARAM); } + +/** + * @tc.number : NotificationSubscriberManagerTest_007 + * @tc.name : Notification subscribe add thread + * @tc.desc : Test add thread is success + */ +HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_009, Function | SmallTest | Level1) +{ + NotificationSubscriberManager notificationSubscriberManager; + std::shared_ptr subscribeManager = std::make_shared(); + EXPECT_EQ(0, notificationSubscriberManager.GetSubscribeAddThread()); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 43dd48487..31f551ad6 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -53,6 +53,7 @@ ohos_shared_library("libans_distributed") { "ipc:ipc_core", "multimedia_image_standard:image_native", "utils_base:utils", + "hicollie_native:libhicollie", ] subsystem_name = "notification" diff --git a/services/distributed/include/distributed_notification_manager.h b/services/distributed/include/distributed_notification_manager.h index edcc0a973..ff6d411da 100644 --- a/services/distributed/include/distributed_notification_manager.h +++ b/services/distributed/include/distributed_notification_manager.h @@ -55,6 +55,7 @@ public: ErrCode UngegisterCallback(void); ErrCode GetCurrentDistributedNotification(std::vector> &requestList); ErrCode GetLocalDeviceInfo(DistributedDatabase::DeviceInfo &deviceInfo); + int GetDistributeAddThread() const; ErrCode OnDistributedKvStoreDeathRecipient(); private: @@ -94,6 +95,7 @@ private: std::shared_ptr databaseCb_; std::shared_ptr deviceCb_; IDistributedCallback callback_ = {0}; + int addThreadSuccess = 1; DECLARE_DELAYED_SINGLETON(DistributedNotificationManager); DISALLOW_COPY_AND_MOVE(DistributedNotificationManager); diff --git a/services/distributed/src/distributed_notification_manager.cpp b/services/distributed/src/distributed_notification_manager.cpp index be2dba32a..f69fd07f3 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 "xcollie/watchdog.h" namespace OHOS { namespace Notification { @@ -30,6 +31,9 @@ DistributedNotificationManager::DistributedNotificationManager() { runner_ = OHOS::AppExecFwk::EventRunner::Create(); handler_ = std::make_shared(runner_); + std::string threadName = handler_->GetEventRunner()->GetRunnerThreadName(); + unsigned int timeval = 5000; + addThreadSuccess = Singleton::GetInstance().AddThread(threadName, handler_, timeval); DistributedDatabaseCallback::IDatabaseChange databaseCallback = { .OnInsert = std::bind(&DistributedNotificationManager::OnDatabaseInsert, @@ -64,6 +68,11 @@ DistributedNotificationManager::DistributedNotificationManager() database_->RecreateDistributedDB(); } +int DistributedNotificationManager::GetDistributeAddThread() const +{ + return addThreadSuccess; +} + DistributedNotificationManager::~DistributedNotificationManager() { handler_->PostSyncTask(std::bind([&]() { callback_ = {}; }), AppExecFwk::EventHandler::Priority::HIGH); diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index 934c13331..6ae0ff2eb 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -75,6 +75,7 @@ ohos_unittest("ans_distributed_unit_test") { "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", + "hicollie_native:libhicollie", ] subsystem_name = "notification" diff --git a/services/distributed/test/unittest/distributed_notification_manager_test.cpp b/services/distributed/test/unittest/distributed_notification_manager_test.cpp index c6cac5a4c..fc13355e3 100644 --- a/services/distributed/test/unittest/distributed_notification_manager_test.cpp +++ b/services/distributed/test/unittest/distributed_notification_manager_test.cpp @@ -180,5 +180,15 @@ HWTEST_F(DistributedNotificationManagerTest, Distributed_Get_Local_DeviceInfo_00 DistributedDatabase::DeviceInfo deviceInfo; EXPECT_EQ(distributedManager_->GetLocalDeviceInfo(deviceInfo), ERR_OK); } + +/** + * @tc.name : Distributed_Get_Local_DeviceInfo_00110 + * @tc.number : Distribute Notification add thread + * @tc.desc : Distribute Notification add thread success + */ +HWTEST_F(DistributedNotificationManagerTest, Distributed_Get_Local_DeviceInfo_00110, Function | SmallTest | Level1) +{ + EXPECT_EQ(0, distributedManager_->GetDistributeAddThread()); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/distributed/test/unittest/mock/mock_event_runner.cpp b/services/distributed/test/unittest/mock/mock_event_runner.cpp index 4e3cdb37c..28298ad8a 100644 --- a/services/distributed/test/unittest/mock/mock_event_runner.cpp +++ b/services/distributed/test/unittest/mock/mock_event_runner.cpp @@ -26,5 +26,10 @@ 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 diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 194d497bf..600f96df1 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -79,6 +79,7 @@ ohos_moduletest("ans_module_test") { "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "time_native:time_service", + "hicollie_native:libhicollie", ] subsystem_name = "notification" -- Gitee