From 670ecf7c5bd30a83523f92877bb7fb1db9603a8c Mon Sep 17 00:00:00 2001 From: cheerful_ricky Date: Tue, 2 Sep 2025 09:43:53 +0800 Subject: [PATCH] only arm will compile libans_distributed Signed-off-by: cheerful_ricky --- notification.gni | 1 - services/ans/include/advanced_notification_service.h | 4 ++-- services/ans/src/advanced_notification_service.cpp | 10 +++------- .../src/distributed_notification_manager.cpp | 5 ++++- .../distributed_notification_manager_branch_test.cpp | 12 ++++++++++++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/notification.gni b/notification.gni index ee63e4f9e..98566afbc 100644 --- a/notification.gni +++ b/notification.gni @@ -89,7 +89,6 @@ declare_args() { !defined(global_parts_info.resourceschedule_device_standby)) { standby_enable = false } - if (defined(global_parts_info) && !defined(global_parts_info.multimedia_player_framework)) { player_framework = false diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 312bd712c..6410d9551 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1819,13 +1819,13 @@ private: std::shared_ptr handler_ = nullptr; std::list> notificationList_; std::shared_ptr recentInfo_ = nullptr; - std::shared_ptr distributedKvStoreDeathRecipient_ = nullptr; std::shared_ptr systemEventObserver_ = nullptr; - DistributedKv::DistributedKvDataManager dataManager_; sptr pushRecipient_ = nullptr; std::shared_ptr notificationSvrQueue_ = nullptr; std::map> publishProcess_; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED + std::shared_ptr distributedKvStoreDeathRecipient_ = nullptr; + DistributedKv::DistributedKvDataManager dataManager_; NotificationConstant::DistributedReminderPolicy distributedReminderPolicy_ = DEFAULT_DISTRIBUTED_REMINDER_POLICY; bool localScreenOn_ = true; #endif diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 9a7625dd7..8e161647c 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -330,10 +330,6 @@ AdvancedNotificationService::AdvancedNotificationService() } soundPermissionInfo_ = std::make_shared(); recentInfo_ = std::make_shared(); -#ifdef DISABLE_DISTRIBUTED_NOTIFICATION_SUPPORTED - distributedKvStoreDeathRecipient_ = std::make_shared( - std::bind(&AdvancedNotificationService::OnDistributedKvStoreDeathRecipient, this)); -#endif permissonFilter_ = std::make_shared(); notificationSlotFilter_ = std::make_shared(); StartFilters(); @@ -354,11 +350,11 @@ AdvancedNotificationService::AdvancedNotificationService() std::bind(&AdvancedNotificationService::OnBootSystemCompleted, this), }; systemEventObserver_ = std::make_shared(iSystemEvent); -#ifdef DISABLE_DISTRIBUTED_NOTIFICATION_SUPPORTED - dataManager_.RegisterKvStoreServiceDeathRecipient(distributedKvStoreDeathRecipient_); -#endif DelayedSingleton::GetInstance()->GetReportTrustListConfig(); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED + distributedKvStoreDeathRecipient_ = std::make_shared( + std::bind(&AdvancedNotificationService::OnDistributedKvStoreDeathRecipient, this)); + dataManager_.RegisterKvStoreServiceDeathRecipient(distributedKvStoreDeathRecipient_); InitDistributeCallBack(); #endif } diff --git a/services/distributed/src/distributed_notification_manager.cpp b/services/distributed/src/distributed_notification_manager.cpp index ab12fcb26..15c8434c3 100644 --- a/services/distributed/src/distributed_notification_manager.cpp +++ b/services/distributed/src/distributed_notification_manager.cpp @@ -484,7 +484,10 @@ ErrCode DistributedNotificationManager::GetLocalDeviceInfo(DistributedDatabase:: ErrCode DistributedNotificationManager::OnDistributedKvStoreDeathRecipient() { ANS_LOGD("start"); - database_ = std::make_shared(databaseCb_, deviceCb_); + if (database_ == nullptr) { + ANS_LOGE("database_ is invalid."); + return ERR_ANS_DISTRIBUTED_OPERATION_FAILED; + } if (!database_->RecreateDistributedDB()) { ANS_LOGE("RecreateDistributedDB failed."); return ERR_ANS_DISTRIBUTED_OPERATION_FAILED; diff --git a/services/distributed/test/unittest/distributed_notification_manager_branch_test/distributed_notification_manager_branch_test.cpp b/services/distributed/test/unittest/distributed_notification_manager_branch_test/distributed_notification_manager_branch_test.cpp index 5e3b74ebf..8d1a3c8c0 100755 --- a/services/distributed/test/unittest/distributed_notification_manager_branch_test/distributed_notification_manager_branch_test.cpp +++ b/services/distributed/test/unittest/distributed_notification_manager_branch_test/distributed_notification_manager_branch_test.cpp @@ -326,5 +326,17 @@ HWTEST_F(DistributedNotificationManagerBranchTest, DistributedNotificationManage EXPECT_EQ( distributedManager_->OnDistributedKvStoreDeathRecipient(), ERR_ANS_DISTRIBUTED_OPERATION_FAILED); } + +/** + * @tc.name : DistributedNotificationManager_01900 + * @tc.number : DistributedNotificationManager_01900 + * @tc.desc : test OnDistributedKvStoreDeathRecipient and database_ is nullptr. + */ +HWTEST_F(DistributedNotificationManagerBranchTest, DistributedNotificationManager_01900, Function | SmallTest | Level1) +{ + distributedManager_->database_ = nullptr; + EXPECT_EQ( + distributedManager_->OnDistributedKvStoreDeathRecipient(), ERR_ANS_DISTRIBUTED_OPERATION_FAILED); +} } // namespace Notification } // namespace OHOS \ No newline at end of file -- Gitee