diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 12c62d3079d00a2f0828f1a3df7197bd455b9da4..1f7d6b6f3e6136126d074ec8cb2ecf949fab4838 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -73,6 +73,7 @@ ohos_shared_library("libans") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "distributeddatamgr:distributeddata_inner", + "hicollie_native:libhicollie", "multimedia_image_standard:image_native", "multimedia_media_standard:media_client", "os_account_standard:os_account_innerkits", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 95cc804a56656635c4b01a2bced396738b6da201..b02c4fbe114294c5472e39b941c5830c2026d22d 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; @@ -209,6 +210,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 f6e2ae64531e82389a465593f32ad15f8b599679..3938be1f7e004dd1043ebf64b70df851570b413d 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 494a045a00f3617d0eaf48d1408bab7f3b269cbd..4a79de629bb002a6a0d33bb2d1aef2140d577773 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" @@ -223,10 +224,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 0307d32ce604159f7e44061d609f74c8c6c7afb1..5faf6f48cac20a586f607d1f78f03d5ccec376ca 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 3e976bf56a1f295330d56fc59548900f35c51736..5ca68f800110e8ea8bbffc39d1ae8245059fc3bc 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -83,6 +83,7 @@ ohos_unittest("ans_unit_test") { "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "hicollie_native:libhicollie", "eventhandler:libeventhandler", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", @@ -102,6 +103,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 441a16cfd72bcff86cbcda95678a0bbb4288d751..59511ac1af6fec5667226ad004b6485a8c4c6f83 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 eb8d6f743b304b824deb98ca8738bc223a9594dd..4023619d6101f5a2cafea67a5223058f1418313e 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 22c67f691853cbde82f7a4662f034882ef9b87ad..50ef1d7afa519466705cdc9e4c3ea16618e1c87d 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 edcc0a973a0436d4b231befbd1b239f26c6bfa0d..ff6d411daba2cea3bbdb20e19a7755fc212af033 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 be2dba32af65c19d111c4783ef1904f6560a2528..f69fd07f3e1006cb822926938c216379c25c09cb 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 934c13331449282f544f764a2e1657e705f5dbd2..6ae0ff2eb03916463d14f755b76ed8a0b0f8fc5d 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 c6cac5a4cf871d27f50b2b6dd7ace51a1b93ca8d..fc13355e3ad8d697549c88269a2103a1f8119628 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 4e3cdb37c2911ce62175b359e768353c26a80bc6..28298ad8a5e4443fafc1655c55931bbc052e64ec 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 f4bcd539cf25fd6a9d822913fb6a03708da3c078..67b980f04882bfdc1cd6b894f445498fffd1ae99 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -80,6 +80,7 @@ ohos_moduletest("ans_module_test") { "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "time_native:time_service", + "hicollie_native:libhicollie", ] subsystem_name = "notification"