diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 83c528687738e4069ebee49c4a31e9f726c981fc..af385ec7c10291607c424dd2b00e95d7748b1a76 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -64,6 +64,7 @@ ohos_shared_library("ans_innerkits") { "src/notification_subscriber.cpp", "src/notification_template.cpp", "src/notification_user_input.cpp", + "src/push_callback_stub.cpp", ] configs = [ "${core_path}:public_ans_core_config" ] diff --git a/services/ans/src/push_callback_stub.cpp b/frameworks/ans/src/push_callback_stub.cpp similarity index 88% rename from services/ans/src/push_callback_stub.cpp rename to frameworks/ans/src/push_callback_stub.cpp index 04a14b6de2b83a0062d2bc6887dc4009b9ee3963..beb84e2d185906af5c11506f6649068a12f96a6b 100644 --- a/services/ans/src/push_callback_stub.cpp +++ b/frameworks/ans/src/push_callback_stub.cpp @@ -15,7 +15,6 @@ #include "push_callback_stub.h" -#include "advanced_notification_service.h" #include "ans_log_wrapper.h" #include "ipc_types.h" #include "message_parcel.h" @@ -83,15 +82,5 @@ bool PushCallBackProxy::OnCheckNotification(const std::string ¬ificationData) return reply.ReadBool(); } - -void PushCallbackRecipient::OnRemoteDied(const wptr &remote) -{ - ANS_LOGE("Push Callback died, remove the proxy object"); - AdvancedNotificationService::GetInstance()->ResetPushCallbackProxy(); -} - -PushCallbackRecipient::PushCallbackRecipient() {} - -PushCallbackRecipient::~PushCallbackRecipient() {} } // namespace Notification } // namespace OHOS diff --git a/frameworks/js/napi/src/manager/BUILD.gn b/frameworks/js/napi/src/manager/BUILD.gn index 9ec1cb5e6244421ff707eb68c8f72f669dafa794..5dc1f08fb29455292cdd8605c50f7c776819749e 100644 --- a/frameworks/js/napi/src/manager/BUILD.gn +++ b/frameworks/js/napi/src/manager/BUILD.gn @@ -67,7 +67,6 @@ ohos_shared_library("notificationmanager") { deps = [ "${core_path}:ans_core", "${frameworks_module_ans_path}:ans_innerkits", - "${services_path}/ans:libans", ] external_deps = [ diff --git a/frameworks/test/moduletest/BUILD.gn b/frameworks/test/moduletest/BUILD.gn index 79e1e6ec78074e0fdb85ef82dfd0209ae9ddfdb6..598f61a311cc49da922d025b1df8827c21058978 100644 --- a/frameworks/test/moduletest/BUILD.gn +++ b/frameworks/test/moduletest/BUILD.gn @@ -40,6 +40,7 @@ ohos_moduletest("ans_fw_module_test") { "${core_path}/include", "${inner_api_path}", "${frameworks_path}/test/moduletest/mock/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] sources = [ @@ -87,6 +88,7 @@ ohos_moduletest("ans_fw_module_test") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "ffrt:libffrt", ] subsystem_name = "${subsystem_name}" @@ -108,6 +110,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "${core_path}/include", "${inner_api_path}", "${frameworks_path}/test/moduletest/mock/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] sources = [ @@ -153,6 +156,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "ffrt:libffrt", ] subsystem_name = "${subsystem_name}" @@ -174,6 +178,7 @@ ohos_moduletest("ans_innerkits_module_slot_test") { "${core_path}/include", "${inner_api_path}", "${frameworks_path}/test/moduletest/mock/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] sources = [ @@ -217,6 +222,7 @@ ohos_moduletest("ans_innerkits_module_slot_test") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "ffrt:libffrt", ] subsystem_name = "${subsystem_name}" @@ -238,6 +244,7 @@ ohos_moduletest("ans_innerkits_module_setting_test") { "${core_path}/include", "${inner_api_path}", "${frameworks_path}/test/moduletest/mock/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] sources = [ @@ -281,6 +288,7 @@ ohos_moduletest("ans_innerkits_module_setting_test") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "ffrt:libffrt", ] subsystem_name = "${subsystem_name}" diff --git a/services/ans/include/push_callback_proxy.h b/interfaces/inner_api/push_callback_proxy.h similarity index 80% rename from services/ans/include/push_callback_proxy.h rename to interfaces/inner_api/push_callback_proxy.h index 469f00b0dac5ed94b4e03f1f70b2ae9cf0ef51d2..1d9dce762c3b7f437046cd416d29540e49dedfa7 100644 --- a/services/ans/include/push_callback_proxy.h +++ b/interfaces/inner_api/push_callback_proxy.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_PUSH_CALLBACK_PROXY_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_PUSH_CALLBACK_PROXY_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PUSH_CALLBACK_PROXY_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PUSH_CALLBACK_PROXY_H #include "push_callback_interface.h" #include "iremote_proxy.h" @@ -46,4 +46,4 @@ private: }; } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_PUSH_CALLBACK_PROXY_H +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PUSH_CALLBACK_PROXY_H diff --git a/interfaces/inner_api/push_callback_stub.h b/interfaces/inner_api/push_callback_stub.h index 18bf248692cc1363bd8882f54159fc83efa8c62b..25ea84c269af48708ef1591ed8dd5b4c8e25b2c0 100644 --- a/interfaces/inner_api/push_callback_stub.h +++ b/interfaces/inner_api/push_callback_stub.h @@ -40,17 +40,6 @@ public: private: DISALLOW_COPY_AND_MOVE(PushCallBackStub); }; - -/** - * @class PushCallbackRecipient - * PushCallbackRecipient notices IRemoteBroker died. - */ -class PushCallbackRecipient : public IRemoteObject::DeathRecipient { -public: - explicit PushCallbackRecipient(); - virtual ~PushCallbackRecipient(); - virtual void OnRemoteDied(const wptr &remote); -}; } // namespace Notification } // namespace OHOS #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PUSH_CALLBACK_STUB_H diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 8df7d8bd74a9f57f1a5c0f529e90b8352900b47b..4b89d4d217bd6e00c8d19b60f8efd00a5a84d405 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -28,7 +28,10 @@ config("public_ans_config") { ohos_shared_library("libans") { shlib_type = "sa" version_script = "libans.map" - include_dirs = [ "include" ] + include_dirs = [ + "include", + "//foundation/resourceschedule/ffrt/interfaces/kits", + ] sources = [ "src/access_token_helper.cpp", @@ -44,7 +47,6 @@ ohos_shared_library("libans") { "src/notification_slot_filter.cpp", "src/notification_subscriber_manager.cpp", "src/permission_filter.cpp", - "src/push_callback_stub.cpp", "src/reminder_data_manager.cpp", "src/reminder_event_manager.cpp", "src/reminder_timer_info.cpp", @@ -56,7 +58,11 @@ ohos_shared_library("libans") { defines = [] cflags = [] - deps = [ "${core_path}:ans_core" ] + deps = [ + "${arkui_ace_engine_path}/interfaces/inner_api/ui_service_manager:ui_service_mgr", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] if (is_double_framework) { cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ] @@ -83,6 +89,7 @@ ohos_shared_library("libans") { "relational_store:native_rdb", "time_service:time_client", "window_manager:libdm", + "ffrt:libffrt", ] external_deps += component_external_deps diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index be7b9c47d977a006c9454911e194ae47fa72704a..b5293676c58465ada310736ca0b1babfe8dde2d0 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -23,6 +23,7 @@ #include "event_handler.h" #include "event_runner.h" +#include "ffrt.h" #include "refbase.h" #include "ans_const_define.h" @@ -840,12 +841,24 @@ private: std::shared_ptr distributedKvStoreDeathRecipient_ = nullptr; std::shared_ptr systemEventObserver_ = nullptr; DistributedKv::DistributedKvDataManager dataManager_; - sptr pushRecipient_ = nullptr;; + sptr pushRecipient_ = nullptr; + std::shared_ptr notificationSvrQueue_ = nullptr; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED NotificationConstant::DistributedReminderPolicy distributedReminderPolicy_ = DEFAULT_DISTRIBUTED_REMINDER_POLICY; bool localScreenOn_ = true; #endif }; + +/** + * @class PushCallbackRecipient + * PushCallbackRecipient notices IRemoteBroker died. + */ +class PushCallbackRecipient : public IRemoteObject::DeathRecipient { +public: + explicit PushCallbackRecipient(); + virtual ~PushCallbackRecipient(); + virtual void OnRemoteDied(const wptr &remote); +}; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/notification_subscriber_manager.h b/services/ans/include/notification_subscriber_manager.h index 83a4ea4595a641bad9bbc702338fe3824bcf97e7..53bae6aa4b2dabbbb3c8b9f54b69938c29f63e9b 100644 --- a/services/ans/include/notification_subscriber_manager.h +++ b/services/ans/include/notification_subscriber_manager.h @@ -23,6 +23,7 @@ #include "errors.h" #include "event_handler.h" #include "event_runner.h" +#include "ffrt.h" #include "nocopyable.h" #include "refbase.h" #include "singleton.h" @@ -138,6 +139,7 @@ private: std::shared_ptr handler_ {}; sptr ansSubscriberProxy_ {}; sptr recipient_ {}; + std::shared_ptr notificationSubQueue_ = nullptr; 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 903d668e6bc66cd5382c3ab29c3abf63545688a4..d52a704547a1744ed9ac8e53c93b3747bbef34f8 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -48,7 +48,7 @@ #include "notification_subscriber_manager.h" #include "os_account_manager.h" #include "permission_filter.h" -#include "push_callback_stub.h" +#include "push_callback_proxy.h" #include "reminder_data_manager.h" #include "trigger_info.h" #include "want_agent_helper.h" @@ -278,9 +278,10 @@ sptr AdvancedNotificationService::GetInstance() AdvancedNotificationService::AdvancedNotificationService() { - runner_ = OHOS::AppExecFwk::EventRunner::Create("NotificationSvrMain"); - handler_ = std::make_shared(runner_); - AnsWatchdog::AddHandlerThread(handler_, runner_); + notificationSvrQueue_ = std::make_shared("NotificationSvrMain"); + if (!notificationSvrQueue_) { + ANS_LOGE("ffrt create failed!"); + } recentInfo_ = std::make_shared(); distributedKvStoreDeathRecipient_ = std::make_shared( std::bind(&AdvancedNotificationService::OnDistributedKvStoreDeathRecipient, this)); @@ -392,7 +393,10 @@ ErrCode AdvancedNotificationService::CancelPreparedNotification( return ERR_ANS_INVALID_BUNDLE; } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); sptr notification = nullptr; result = RemoveFromNotificationList(bundleOption, label, notificationId, notification, true); if (result != ERR_OK) { @@ -409,7 +413,9 @@ ErrCode AdvancedNotificationService::CancelPreparedNotification( #endif } })); - + ANS_LOGE("ffrt wait!"); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); SendCancelHiSysEvent(notificationId, label, bundleOption, result); return result; } @@ -460,7 +466,9 @@ ErrCode AdvancedNotificationService::PublishPreparedNotification( SetNotificationRemindType(record->notification, true); ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = AssignValidNotificationSlot(record); if (result != ERR_OK) { ANS_LOGE("Can not assign valid slot!"); @@ -487,7 +495,8 @@ ErrCode AdvancedNotificationService::PublishPreparedNotification( } #endif })); - + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); if (record->request->GetAutoDeletedTime() > GetCurrentTime()) { StartAutoDelete(record); } @@ -674,7 +683,9 @@ ErrCode AdvancedNotificationService::CancelAll() ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); sptr notification = nullptr; std::vector keys = GetNotificationKeys(bundleOption); @@ -703,6 +714,8 @@ ErrCode AdvancedNotificationService::CancelAll() result = ERR_OK; })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -757,7 +770,9 @@ ErrCode AdvancedNotificationService::AddSlots(const std::vectorPostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); std::vector> addSlots; for (auto slot : slots) { sptr originalSlot; @@ -776,6 +791,8 @@ ErrCode AdvancedNotificationService::AddSlots(const std::vectorwait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -789,13 +806,17 @@ ErrCode AdvancedNotificationService::GetSlots(std::vector } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().GetNotificationAllSlots(bundleOption, slots); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_OK; slots.clear(); } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -808,8 +829,9 @@ ErrCode AdvancedNotificationService::GetActiveNotifications(std::vectorPostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); notifications.clear(); for (auto record : notificationList_) { if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && @@ -818,7 +840,9 @@ ErrCode AdvancedNotificationService::GetActiveNotifications(std::vectorwait(handler); + ANS_LOGE("ffrt end!"); + return ERR_OK; } ErrCode AdvancedNotificationService::GetActiveNotificationNums(uint64_t &num) @@ -830,8 +854,9 @@ ErrCode AdvancedNotificationService::GetActiveNotificationNums(uint64_t &num) return ERR_ANS_INVALID_BUNDLE; } - ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); size_t count = 0; for (auto record : notificationList_) { if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && @@ -841,7 +866,9 @@ ErrCode AdvancedNotificationService::GetActiveNotificationNums(uint64_t &num) } num = static_cast(count); })); - return result; + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); + return ERR_OK; } ErrCode AdvancedNotificationService::SetNotificationAgent(const std::string &agent) @@ -875,8 +902,14 @@ ErrCode AdvancedNotificationService::SetNotificationBadgeNum(int32_t num) } ErrCode result = ERR_OK; - handler_->PostSyncTask( - std::bind([&]() { result = NotificationPreferences::GetInstance().SetTotalBadgeNums(bundleOption, num); })); + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h( + std::bind([&]() { + ANS_LOGE("ffrt enter!"); + result = NotificationPreferences::GetInstance().SetTotalBadgeNums(bundleOption, num); + })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -890,8 +923,14 @@ ErrCode AdvancedNotificationService::GetBundleImportance(int32_t &importance) } ErrCode result = ERR_OK; - handler_->PostSyncTask( - std::bind([&]() { result = NotificationPreferences::GetInstance().GetImportance(bundleOption, importance); })); + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h( + std::bind([&]() { + ANS_LOGE("ffrt enter!"); + result = NotificationPreferences::GetInstance().GetImportance(bundleOption, importance); + })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -915,7 +954,9 @@ ErrCode AdvancedNotificationService::Delete(const std::string &key, int32_t remo ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); sptr notification = nullptr; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED std::string deviceId; @@ -936,6 +977,8 @@ ErrCode AdvancedNotificationService::Delete(const std::string &key, int32_t remo #endif } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -959,7 +1002,9 @@ ErrCode AdvancedNotificationService::DeleteByBundle(const sptrPostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); std::vector keys = GetNotificationKeys(bundle); for (auto key : keys) { #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED @@ -987,6 +1032,8 @@ ErrCode AdvancedNotificationService::DeleteByBundle(const sptrwait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1005,7 +1052,9 @@ ErrCode AdvancedNotificationService::DeleteAll() } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); int32_t activeUserId = SUBSCRIBE_USER_INIT; (void)GetActiveUserId(activeUserId); std::vector keys = GetNotificationKeys(nullptr); @@ -1035,6 +1084,8 @@ ErrCode AdvancedNotificationService::DeleteAll() result = ERR_OK; })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1075,13 +1126,18 @@ ErrCode AdvancedNotificationService::GetSlotsByBundle( } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().GetNotificationAllSlots(bundle, slots); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_OK; slots.clear(); } })); + + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1105,12 +1161,16 @@ ErrCode AdvancedNotificationService::UpdateSlots( } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().UpdateNotificationSlots(bundle, slots); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST; } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); if (result == ERR_OK) { PublishSlotChangeCommonEvent(bundle); @@ -1139,8 +1199,14 @@ ErrCode AdvancedNotificationService::SetShowBadgeEnabledForBundle( } ErrCode result = ERR_OK; - handler_->PostSyncTask( - std::bind([&]() { result = NotificationPreferences::GetInstance().SetShowBadge(bundle, enabled); })); + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h( + std::bind([&]() { + result = NotificationPreferences::GetInstance().SetShowBadge(bundle, enabled); + ANS_LOGE("ffrt enter!"); + })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1164,13 +1230,17 @@ ErrCode AdvancedNotificationService::GetShowBadgeEnabledForBundle( } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().IsShowBadge(bundle, enabled); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_OK; enabled = false; } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1184,13 +1254,17 @@ ErrCode AdvancedNotificationService::GetShowBadgeEnabled(bool &enabled) } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().IsShowBadge(bundleOption, enabled); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_OK; enabled = false; } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1338,9 +1412,13 @@ ErrCode AdvancedNotificationService::GetSlotByType( return ERR_ANS_INVALID_BUNDLE; } - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); NotificationPreferences::GetInstance().GetNotificationSlot(bundleOption, slotType, slot); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); // if get slot failed, it still return ok. return ERR_OK; } @@ -1354,9 +1432,13 @@ ErrCode AdvancedNotificationService::RemoveSlotByType(const NotificationConstant return ERR_ANS_INVALID_BUNDLE; } - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); NotificationPreferences::GetInstance().RemoveNotificationSlot(bundleOption, slotType); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); // if remove slot failed, it still return ok. return ERR_OK; } @@ -1374,8 +1456,9 @@ ErrCode AdvancedNotificationService::GetAllActiveNotifications(std::vectorPostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); notifications.clear(); for (auto record : notificationList_) { if (record->notification != nullptr) { @@ -1383,7 +1466,9 @@ ErrCode AdvancedNotificationService::GetAllActiveNotifications(std::vectorwait(handler); + ANS_LOGE("ffrt end!"); + return ERR_OK; } inline bool IsContained(const std::vector &vec, const std::string &target) @@ -1416,15 +1501,18 @@ ErrCode AdvancedNotificationService::GetSpecialActiveNotifications( return ERR_ANS_PERMISSION_DENIED; } - ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); for (auto record : notificationList_) { if (IsContained(key, record->notification->GetKey())) { notifications.push_back(record->notification); } } })); - return result; + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); + return ERR_OK; } ErrCode AdvancedNotificationService::RequestEnableNotification( @@ -1493,7 +1581,9 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForAllBundles(const } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); if (deviceId.empty()) { // Local device result = NotificationPreferences::GetInstance().SetNotificationsEnabled(userId, enabled); @@ -1501,6 +1591,8 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForAllBundles(const // Remote device } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1528,7 +1620,9 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForSpecialBundle( new EnabledNotificationCallbackData(bundle->GetBundleName(), bundle->GetUid(), enabled); ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start! 123"); + // ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); if (deviceId.empty()) { // Local device result = NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(bundle, enabled); @@ -1542,7 +1636,9 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForSpecialBundle( } else { // Remote revice } - })); + // })); + // notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); SendEnableNotificationHiSysEvent(bundleOption, enabled, result); return result; @@ -1567,10 +1663,14 @@ ErrCode AdvancedNotificationService::IsAllowedNotify(bool &allowed) } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); allowed = false; result = NotificationPreferences::GetInstance().GetNotificationsEnabled(userId, allowed); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1599,7 +1699,12 @@ ErrCode AdvancedNotificationService::IsAllowedNotifySelf(const sptrPostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start! 123"); + + + + // ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); allowed = false; result = NotificationPreferences::GetInstance().GetNotificationsEnabled(userId, allowed); if (result == ERR_OK && allowed) { @@ -1610,7 +1715,9 @@ ErrCode AdvancedNotificationService::IsAllowedNotifySelf(const sptrwait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1676,7 +1783,11 @@ ErrCode AdvancedNotificationService::IsSpecialBundleAllowedNotify( } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start! 123"); + + + // ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); allowed = false; result = NotificationPreferences::GetInstance().GetNotificationsEnabled(userId, allowed); if (result == ERR_OK && allowed) { @@ -1687,7 +1798,9 @@ ErrCode AdvancedNotificationService::IsSpecialBundleAllowedNotify( SetNotificationsEnabledForSpecialBundle("", bundleOption, allowed); } } - })); + // })); + //notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1733,7 +1846,9 @@ ErrCode AdvancedNotificationService::PublishContinuousTaskNotification(const spt record->notification->SetSourceType(NotificationConstant::SourceType::TYPE_CONTINUOUS); } - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); if (!IsNotificationExists(record->notification->GetKey())) { AddToNotificationList(record); } else { @@ -1749,6 +1864,8 @@ ErrCode AdvancedNotificationService::PublishContinuousTaskNotification(const spt sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -1764,7 +1881,9 @@ ErrCode AdvancedNotificationService::CancelContinuousTaskNotification(const std: int32_t uid = IPCSkeleton::GetCallingUid(); ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); sptr notification = nullptr; for (auto record : notificationList_) { if ((record->bundleOption->GetBundleName().empty()) && (record->bundleOption->GetUid() == uid) && @@ -1782,6 +1901,8 @@ ErrCode AdvancedNotificationService::CancelContinuousTaskNotification(const std: NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -2146,7 +2267,9 @@ void AdvancedNotificationService::OnBundleRemoved(const sptrPostTask(std::bind([this, bundleOption]() { + ANS_LOGE("ffrt start!"); + notificationSvrQueue_->submit(std::bind([this, bundleOption]() { + ANS_LOGE("ffrt enter!"); ErrCode result = NotificationPreferences::GetInstance().RemoveNotificationForBundle(bundleOption); if (result != ERR_OK) { ANS_LOGW("NotificationPreferences::RemoveNotificationForBundle failed: %{public}d", result); @@ -2178,6 +2301,7 @@ void AdvancedNotificationService::OnBundleRemoved(const sptrPostTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); NotificationPreferences::GetInstance().OnDistributedKvStoreDeathRecipient(); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED DistributedNotificationManager::GetInstance()->OnDistributedKvStoreDeathRecipient(); #endif })); + ANS_LOGE("ffrt end!"); } ErrCode AdvancedNotificationService::RemoveAllSlots() @@ -2217,12 +2344,16 @@ ErrCode AdvancedNotificationService::RemoveAllSlots() } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().RemoveNotificationAllSlots(bundleOption); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_OK; } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -2236,7 +2367,9 @@ ErrCode AdvancedNotificationService::AddSlotByType(NotificationConstant::SlotTyp } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); sptr slot; result = NotificationPreferences::GetInstance().GetNotificationSlot(bundleOption, slotType, slot); if ((result == ERR_OK) && (slot != nullptr)) { @@ -2248,6 +2381,8 @@ ErrCode AdvancedNotificationService::AddSlotByType(NotificationConstant::SlotTyp result = NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption, slots); } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -2273,7 +2408,9 @@ ErrCode AdvancedNotificationService::RemoveNotification(const sptrPostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); sptr notification = nullptr; sptr notificationRequest = nullptr; @@ -2316,6 +2453,8 @@ ErrCode AdvancedNotificationService::RemoveNotification(const sptrwait(handler); + ANS_LOGE("ffrt end!"); SendRemoveHiSysEvent(notificationId, label, bundleOption, result); return result; @@ -2340,7 +2479,9 @@ ErrCode AdvancedNotificationService::RemoveAllNotifications(const sptrPostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); std::vector> removeList; for (auto record : notificationList_) { if (!record->notification->IsRemoveAllowed()) { @@ -2372,6 +2513,8 @@ ErrCode AdvancedNotificationService::RemoveAllNotifications(const sptrrequest); } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return ERR_OK; } @@ -2397,13 +2540,17 @@ ErrCode AdvancedNotificationService::GetSlotNumAsBundle( ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(bundle, num); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_OK; num = 0; } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -2421,7 +2568,9 @@ ErrCode AdvancedNotificationService::CancelGroup(const std::string &groupName) return ERR_ANS_INVALID_BUNDLE; } - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); std::vector> removeList; for (auto record : notificationList_) { if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && @@ -2448,6 +2597,8 @@ ErrCode AdvancedNotificationService::CancelGroup(const std::string &groupName) } } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return ERR_OK; } @@ -2475,7 +2626,9 @@ ErrCode AdvancedNotificationService::RemoveGroupByBundle( return ERR_ANS_INVALID_BUNDLE; } - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); std::vector> removeList; for (auto record : notificationList_) { if (!record->notification->IsRemoveAllowed()) { @@ -2505,6 +2658,8 @@ ErrCode AdvancedNotificationService::RemoveGroupByBundle( } } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return ERR_OK; } @@ -2648,13 +2803,17 @@ ErrCode AdvancedNotificationService::IsDistributedEnabled(bool &enabled) ANS_LOGD("%{public}s", __FUNCTION__); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = DistributedPreferences::GetInstance()->GetDistributedEnable(enabled); if (result != ERR_OK) { result = ERR_OK; enabled = false; } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; #else return ERR_INVALID_OPERATION; @@ -2676,8 +2835,14 @@ ErrCode AdvancedNotificationService::EnableDistributed(bool enabled) } ErrCode result = ERR_OK; - handler_->PostSyncTask( - std::bind([&]() { result = DistributedPreferences::GetInstance()->SetDistributedEnable(enabled); })); + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h( + std::bind([&]() { + result = DistributedPreferences::GetInstance()->SetDistributedEnable(enabled); + ANS_LOGE("ffrt enter!"); + })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; #else return ERR_INVALID_OPERATION; @@ -2712,13 +2877,17 @@ ErrCode AdvancedNotificationService::EnableDistributedByBundle( } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = DistributedPreferences::GetInstance()->SetDistributedBundleEnable(bundle, enabled); if (result != ERR_OK) { result = ERR_OK; enabled = false; } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; #else return ERR_INVALID_OPERATION; @@ -2742,8 +2911,14 @@ ErrCode AdvancedNotificationService::EnableDistributedSelf(const bool enabled) } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind( - [&]() { result = DistributedPreferences::GetInstance()->SetDistributedBundleEnable(bundleOption, enabled); })); + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind( + [&]() { + ANS_LOGE("ffrt enter!"); + result = DistributedPreferences::GetInstance()->SetDistributedBundleEnable(bundleOption, enabled); + })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; #else return ERR_INVALID_OPERATION; @@ -2779,13 +2954,17 @@ ErrCode AdvancedNotificationService::IsDistributedEnableByBundle( } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = DistributedPreferences::GetInstance()->GetDistributedBundleEnable(bundle, enabled); if (result != ERR_OK) { result = ERR_OK; enabled = false; } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; #else return ERR_INVALID_OPERATION; @@ -2806,7 +2985,10 @@ ErrCode AdvancedNotificationService::GetDeviceRemindType(NotificationConstant::R } #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - handler_->PostSyncTask(std::bind([&]() { remindType = GetRemindType(); })); + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { remindType = GetRemindType(); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return ERR_OK; #else return ERR_INVALID_OPERATION; @@ -2962,7 +3144,9 @@ void AdvancedNotificationService::OnDistributedPublish( return; } - handler_->PostTask(std::bind([this, deviceId, bundleName, request, activeUserId]() { + ANS_LOGE("ffrt start!"); + notificationSvrQueue_->submit(std::bind([this, deviceId, bundleName, request, activeUserId]() { + ANS_LOGE("ffrt enter!"); if (!CheckDistributedNotificationType(request)) { ANS_LOGD("device type not support display."); return; @@ -3015,6 +3199,7 @@ void AdvancedNotificationService::OnDistributedPublish( sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap); })); + ANS_LOGE("ffrt end!"); } void AdvancedNotificationService::OnDistributedUpdate( @@ -3027,7 +3212,9 @@ void AdvancedNotificationService::OnDistributedUpdate( return; } - handler_->PostTask(std::bind([this, deviceId, bundleName, request, activeUserId]() { + ANS_LOGE("ffrt start!"); + notificationSvrQueue_->submit(std::bind([this, deviceId, bundleName, request, activeUserId]() { + ANS_LOGE("ffrt enter!"); if (!CheckDistributedNotificationType(request)) { ANS_LOGD("device type not support display."); return; @@ -3084,13 +3271,16 @@ void AdvancedNotificationService::OnDistributedUpdate( sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap); })); + ANS_LOGE("ffrt end!"); } void AdvancedNotificationService::OnDistributedDelete( const std::string &deviceId, const std::string &bundleName, const std::string &label, int32_t id) { ANS_LOGD("%{public}s", __FUNCTION__); - handler_->PostTask(std::bind([this, deviceId, bundleName, label, id]() { + ANS_LOGE("ffrt start!"); + notificationSvrQueue_->submit(std::bind([this, deviceId, bundleName, label, id]() { + ANS_LOGE("ffrt enter!"); int32_t activeUserId = -1; if (!GetActiveUserId(activeUserId)) { ANS_LOGE("Failed to get active user id!"); @@ -3130,6 +3320,7 @@ void AdvancedNotificationService::OnDistributedDelete( NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); } })); + ANS_LOGE("ffrt end!"); } ErrCode AdvancedNotificationService::GetDistributedEnableInApplicationInfo( @@ -3191,10 +3382,14 @@ ErrCode AdvancedNotificationService::IsSupportTemplate(const std::string& templa { ANS_LOGD("%{public}s", __FUNCTION__); ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); support = false; result = NotificationPreferences::GetInstance().GetTemplateSupported(templateName, support); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -3237,10 +3432,14 @@ ErrCode AdvancedNotificationService::IsSpecialUserAllowedNotify(const int32_t &u } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); allowed = false; result = NotificationPreferences::GetInstance().GetNotificationsEnabled(userId, allowed); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -3258,9 +3457,13 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledByUser(const int32_t } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().SetNotificationsEnabled(userId, enabled); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -3279,7 +3482,9 @@ ErrCode AdvancedNotificationService::DeleteAllByUser(const int32_t &userId) } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); std::vector keys = GetNotificationKeys(nullptr); for (auto key : keys) { #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED @@ -3307,6 +3512,8 @@ ErrCode AdvancedNotificationService::DeleteAllByUser(const int32_t &userId) result = ERR_OK; })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -3398,12 +3605,16 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDateByUser(const int32_t &us return ERR_ANS_INVALID_BUNDLE; } - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().SetDoNotDisturbDate(userId, newConfig); if (result == ERR_OK) { NotificationSubscriberManager::GetInstance()->NotifyDoNotDisturbDateChanged(newConfig); } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return ERR_OK; } @@ -3413,7 +3624,9 @@ ErrCode AdvancedNotificationService::GetDoNotDisturbDateByUser(const int32_t &us { ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); sptr currentConfig = nullptr; result = NotificationPreferences::GetInstance().GetDoNotDisturbDate(userId, currentConfig); if (result == ERR_OK) { @@ -3434,6 +3647,8 @@ ErrCode AdvancedNotificationService::GetDoNotDisturbDateByUser(const int32_t &us } } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return ERR_OK; } @@ -3443,9 +3658,13 @@ ErrCode AdvancedNotificationService::SetHasPoppedDialog( { ANS_LOGD("%{public}s", __FUNCTION__); ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().SetHasPoppedDialog(bundleOption, hasPopped); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -3454,9 +3673,13 @@ ErrCode AdvancedNotificationService::GetHasPoppedDialog( { ANS_LOGD("%{public}s", __FUNCTION__); ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = NotificationPreferences::GetInstance().GetHasPoppedDialog(bundleOption, hasPopped); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -3474,14 +3697,20 @@ void AdvancedNotificationService::OnResourceRemove(int32_t userId) { DeleteAllByUser(userId); - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); NotificationPreferences::GetInstance().RemoveSettings(userId); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); } void AdvancedNotificationService::OnBundleDataCleared(const sptr &bundleOption) { - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); std::vector keys = GetNotificationKeys(bundleOption); for (auto key : keys) { #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED @@ -3508,6 +3737,8 @@ void AdvancedNotificationService::OnBundleDataCleared(const sptrwait(handler); + ANS_LOGE("ffrt end!"); } void AdvancedNotificationService::GetDisplayPosition( @@ -3569,7 +3800,8 @@ ErrCode AdvancedNotificationService::SetEnabledForBundleSlot( } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { sptr slot; result = NotificationPreferences::GetInstance().GetNotificationSlot(bundle, slotType, slot); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST || @@ -3601,6 +3833,8 @@ ErrCode AdvancedNotificationService::SetEnabledForBundleSlot( PublishSlotChangeCommonEvent(bundle); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); SendEnableNotificationSlotHiSysEvent(bundleOption, slotType, enabled, result); return result; @@ -3626,7 +3860,9 @@ ErrCode AdvancedNotificationService::GetEnabledForBundleSlot( } ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); sptr slot; result = NotificationPreferences::GetInstance().GetNotificationSlot(bundle, slotType, slot); if (result != ERR_OK) { @@ -3641,6 +3877,8 @@ ErrCode AdvancedNotificationService::GetEnabledForBundleSlot( } enabled = slot->GetEnable(); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -3677,7 +3915,9 @@ ErrCode AdvancedNotificationService::ShellDump(const std::string &cmd, const std } ErrCode result = ERR_ANS_NOT_ALLOWED; - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGE("ffrt enter!"); if (cmd == ACTIVE_NOTIFICATION_OPTION) { result = ActiveNotificationDump(bundle, userId, dumpInfo); } else if (cmd == RECENT_NOTIFICATION_OPTION) { @@ -3692,6 +3932,8 @@ ErrCode AdvancedNotificationService::ShellDump(const std::string &cmd, const std result = ERR_ANS_INVALID_PARAM; } })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -3895,10 +4137,14 @@ ErrCode AdvancedNotificationService::SetSyncNotificationEnabledWithoutApp(const } ErrCode result = ERR_OK; - handler_->PostSyncTask( + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h( std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = DistributedPreferences::GetInstance()->SetSyncEnabledWithoutApp(userId, enabled); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; #else return ERR_INVALID_OPERATION; @@ -3920,10 +4166,14 @@ ErrCode AdvancedNotificationService::GetSyncNotificationEnabledWithoutApp(const } ErrCode result = ERR_OK; - handler_->PostSyncTask( + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h( std::bind([&]() { + ANS_LOGE("ffrt enter!"); result = DistributedPreferences::GetInstance()->GetSyncEnabledWithoutApp(userId, enabled); })); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; #else return ERR_INVALID_OPERATION; @@ -3984,7 +4234,8 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptrPostSyncTask([this, &record]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h([this, &record]() { if (AssignToNotificationList(record) != ERR_OK) { ANS_LOGE("Failed to assign notification list"); return; @@ -3994,6 +4245,8 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap); }); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -4009,13 +4262,13 @@ ErrCode AdvancedNotificationService::SetBadgeNumber(int32_t badgeNumber) return ERR_ANS_NO_MEMORY; } - if (!handler_) { - ANS_LOGE("handler_ is null."); - return ERR_ANS_TASK_ERR; - } - handler_->PostSyncTask(std::bind([&]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSvrQueue_->submit_h([&]() { + ANS_LOGE("ffrt enter!"); NotificationSubscriberManager::GetInstance()->SetBadgeNumber(badgeData); - })); + }); + notificationSvrQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return ERR_OK; } @@ -4063,8 +4316,8 @@ ErrCode AdvancedNotificationService::RegisterPushCallback(const sptrAddDeathRecipient(pushRecipient_); + pushCallBack_ = iface_cast(pushCallback); ANS_LOGD("end"); return ERR_OK; @@ -4114,6 +4367,7 @@ bool AdvancedNotificationService::IsNeedPushCheck(NotificationConstant::SlotType ErrCode AdvancedNotificationService::PushCheck(const sptr &request) { + ANS_LOGD("start."); if (pushCallBack_) { nlohmann::json jsonObject; jsonObject["pkgName"] = request->GetCreatorBundleName(); @@ -4133,7 +4387,10 @@ void AdvancedNotificationService::StartAutoDelete(const std::shared_ptrnotification->GetKey()); int64_t autoDeleteTime = record->request->GetAutoDeletedTime() - GetCurrentTime(); - handler_->PostTask(triggerFunc, autoDeleteTime); + ANS_LOGE("ffrt start!"); + + ffrt::task_handle handler = notificationSvrQueue_->submit_h(triggerFunc, ffrt::task_attr().delay(autoDeleteTime * 1000)); + ANS_LOGE("ffrt end!"); } void AdvancedNotificationService::TriggerAutoDelete(std::string hashCode) @@ -4154,5 +4411,15 @@ void AdvancedNotificationService::TriggerAutoDelete(std::string hashCode) } } } + +void PushCallbackRecipient::OnRemoteDied(const wptr &remote) +{ + ANS_LOGE("Push Callback died, remove the proxy object"); + AdvancedNotificationService::GetInstance()->ResetPushCallbackProxy(); +} + +PushCallbackRecipient::PushCallbackRecipient() {} + +PushCallbackRecipient::~PushCallbackRecipient() {} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 16ee92cc7d7fa59caf94340087382e55626a57c6..76d4bc62f3c184b668474c4bf02d817ecb6ae3ee 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -58,6 +58,7 @@ ErrCode NotificationPreferences::AddNotificationSlots( } } + ANS_LOGE("ffrt: add slot to db!"); if (result == ERR_OK && (!preferncesDB_->PutSlotsToDisturbeDB(bundleOption->GetBundleName(), bundleOption->GetUid(), slots))) { return ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 1b20cb165f09d0d4956d6fd3d44895e131f74bd4..a50c3dd800e589ffbe8079892cf9699c29a62906 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -39,9 +39,7 @@ struct NotificationSubscriberManager::SubscriberRecord { NotificationSubscriberManager::NotificationSubscriberManager() { - runner_ = OHOS::AppExecFwk::EventRunner::Create("NotificationSubscriberMgr"); - handler_ = std::make_shared(runner_); - AnsWatchdog::AddHandlerThread(handler_, runner_); + notificationSubQueue_ = std::make_shared("NotificationSubscriberMgr"); recipient_ = new RemoteDeathRecipient(std::bind(&NotificationSubscriberManager::OnRemoteDied, this, std::placeholders::_1)); } @@ -83,10 +81,17 @@ ErrCode NotificationSubscriberManager::AddSubscriber( } ErrCode result = ERR_ANS_TASK_ERR; - handler_->PostSyncTask(std::bind([this, &subscriber, &subInfo, &result]() { + if (notificationSubQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); + return result; + } + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSubQueue_->submit_h(std::bind([this, &subscriber, &subInfo, &result]() { + ANS_LOGE("ffrt enter!"); result = this->AddSubscriberInner(subscriber, subInfo); - }), - AppExecFwk::EventQueue::Priority::HIGH); + })/*, AppExecFwk::EventQueue::Priority::HIGH*/); + notificationSubQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -100,10 +105,17 @@ ErrCode NotificationSubscriberManager::RemoveSubscriber( } ErrCode result = ERR_ANS_TASK_ERR; - handler_->PostSyncTask(std::bind([this, &subscriber, &subscribeInfo, &result]() { + if (notificationSubQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); + return result; + } + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationSubQueue_->submit_h(std::bind([this, &subscriber, &subscribeInfo, &result]() { + ANS_LOGE("ffrt enter!"); result = this->RemoveSubscriberInner(subscriber, subscribeInfo); - }), - AppExecFwk::EventQueue::Priority::HIGH); + })/*, AppExecFwk::EventQueue::Priority::HIGH*/); + notificationSubQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return result; } @@ -111,83 +123,96 @@ void NotificationSubscriberManager::NotifyConsumed( const sptr ¬ification, const sptr ¬ificationMap) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - if (handler_ == nullptr) { - ANS_LOGE("handler is nullptr"); + if (notificationSubQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); return; } AppExecFwk::EventHandler::Callback NotifyConsumedFunc = std::bind(&NotificationSubscriberManager::NotifyConsumedInner, this, notification, notificationMap); - handler_->PostTask(NotifyConsumedFunc); + ANS_LOGE("ffrt start!"); + notificationSubQueue_->submit(NotifyConsumedFunc); + ANS_LOGE("ffrt end!"); } void NotificationSubscriberManager::NotifyCanceled( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - if (handler_ == nullptr) { - ANS_LOGE("handler is nullptr"); + if (notificationSubQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); return; } - AppExecFwk::EventHandler::Callback NotifyCanceledFunc = std::bind( &NotificationSubscriberManager::NotifyCanceledInner, this, notification, notificationMap, deleteReason); - handler_->PostTask(NotifyCanceledFunc); + ANS_LOGE("ffrt start!"); + notificationSubQueue_->submit(NotifyCanceledFunc); + ANS_LOGE("ffrt end!"); } void NotificationSubscriberManager::NotifyUpdated(const sptr ¬ificationMap) { - if (handler_ == nullptr) { - ANS_LOGE("handler is nullptr"); + if (notificationSubQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); return; } - AppExecFwk::EventHandler::Callback NotifyUpdatedFunc = std::bind(&NotificationSubscriberManager::NotifyUpdatedInner, this, notificationMap); - handler_->PostTask(NotifyUpdatedFunc); + ANS_LOGE("ffrt start!"); + notificationSubQueue_->submit(NotifyUpdatedFunc); + ANS_LOGE("ffrt end!"); } void NotificationSubscriberManager::NotifyDoNotDisturbDateChanged(const sptr &date) { - if (handler_ == nullptr) { - ANS_LOGE("handler is nullptr"); + if (notificationSubQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); return; } - AppExecFwk::EventHandler::Callback func = std::bind(&NotificationSubscriberManager::NotifyDoNotDisturbDateChangedInner, this, date); - handler_->PostTask(func); + ANS_LOGE("ffrt start!"); + notificationSubQueue_->submit(func); + ANS_LOGE("ffrt end!"); } void NotificationSubscriberManager::NotifyEnabledNotificationChanged( const sptr &callbackData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - if (handler_ == nullptr) { - ANS_LOGE("handler is nullptr"); + if (notificationSubQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); return; } - AppExecFwk::EventHandler::Callback func = std::bind(&NotificationSubscriberManager::NotifyEnabledNotificationChangedInner, this, callbackData); - handler_->PostTask(func); + ANS_LOGE("ffrt start!"); + notificationSubQueue_->submit(func); + ANS_LOGE("ffrt end!"); } void NotificationSubscriberManager::OnRemoteDied(const wptr &object) { ANS_LOGI("OnRemoteDied"); - handler_->PostSyncTask(std::bind([this, object]() { + if (notificationSubQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); + return; + } + ffrt::task_handle handler = notificationSubQueue_->submit_h(std::bind([this, object]() { + ANS_LOGE("ffrt enter!"); std::shared_ptr record = FindSubscriberRecord(object); if (record != nullptr) { ANS_LOGW("subscriber removed."); subscriberRecordList_.remove(record); } - }), - AppExecFwk::EventQueue::Priority::HIGH); + })/*, AppExecFwk::EventQueue::Priority::HIGH*/); + ANS_LOGE("ffrt start!"); + notificationSubQueue_->wait(handler); + ANS_LOGE("ffrt end!"); } std::shared_ptr NotificationSubscriberManager::FindSubscriberRecord( @@ -312,6 +337,7 @@ ErrCode NotificationSubscriberManager::RemoveSubscriberInner( void NotificationSubscriberManager::NotifyConsumedInner( const sptr ¬ification, const sptr ¬ificationMap) { + ANS_LOGE("ffrt enter!"); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("%{public}s notification->GetUserId <%{public}d>", __FUNCTION__, notification->GetUserId()); int32_t recvUserId = notification->GetNotificationRequest().GetReceiverUserId(); @@ -335,6 +361,7 @@ void NotificationSubscriberManager::NotifyConsumedInner( void NotificationSubscriberManager::NotifyCanceledInner( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) { + ANS_LOGE("ffrt enter!"); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("%{public}s notification->GetUserId <%{public}d>", __FUNCTION__, notification->GetUserId()); int32_t recvUserId = notification->GetNotificationRequest().GetReceiverUserId(); @@ -356,6 +383,7 @@ void NotificationSubscriberManager::NotifyCanceledInner( void NotificationSubscriberManager::NotifyUpdatedInner(const sptr ¬ificationMap) { + ANS_LOGE("ffrt enter!"); for (auto record : subscriberRecordList_) { record->subscriber->OnUpdated(notificationMap); } @@ -363,6 +391,7 @@ void NotificationSubscriberManager::NotifyUpdatedInner(const sptr &date) { + ANS_LOGE("ffrt enter!"); for (auto record : subscriberRecordList_) { record->subscriber->OnDoNotDisturbDateChange(date); } @@ -376,6 +405,7 @@ bool NotificationSubscriberManager::IsSystemUser(int32_t userId) void NotificationSubscriberManager::NotifyEnabledNotificationChangedInner( const sptr &callbackData) { + ANS_LOGE("ffrt enter!"); for (auto record : subscriberRecordList_) { record->subscriber->OnEnabledNotificationChanged(callbackData); } @@ -383,17 +413,18 @@ void NotificationSubscriberManager::NotifyEnabledNotificationChangedInner( void NotificationSubscriberManager::SetBadgeNumber(const sptr &badgeData) { - if (handler_ == nullptr) { - ANS_LOGE("handler is nullptr"); + if (notificationSubQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); return; } - std::function setBadgeNumberFunc = [badgeData] () { for (auto record : NotificationSubscriberManager::GetInstance()->subscriberRecordList_) { record->subscriber->OnBadgeChanged(badgeData); } }; - handler_->PostTask(setBadgeNumberFunc); + ANS_LOGE("ffrt start!"); + notificationSubQueue_->submit(setBadgeNumberFunc); + ANS_LOGE("ffrt end!"); } } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 929770bf44c9a34cbc639eb03a7c16e5c0f94e04..e21b4964dd2c143a810c288b28986a5d8a674631 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -102,6 +102,7 @@ ohos_unittest("ans_unit_test") { "include", "/${services_path}/ans/include", "${services_path}/ans/test/unittest/mock/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] defines = [] @@ -167,6 +168,7 @@ ohos_unittest("ans_unit_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "time_service:time_client", + "ffrt:libffrt", ] if (device_usage) { @@ -342,6 +344,7 @@ ohos_unittest("notification_subscriber_manager_branch_test") { "include", "/${services_path}/ans/include", "${services_path}/ans/test/unittest/mock/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] defines = [] @@ -394,6 +397,7 @@ ohos_unittest("notification_subscriber_manager_branch_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "time_service:time_client", + "ffrt:libffrt", ] subsystem_name = "${subsystem_name}" @@ -407,6 +411,7 @@ ohos_unittest("advanced_notification_service_branch_test") { "include", "/${services_path}/ans/include", "${services_path}/ans/test/unittest/mock/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] defines = [] @@ -463,6 +468,7 @@ ohos_unittest("advanced_notification_service_branch_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "time_service:time_client", + "ffrt:libffrt", ] subsystem_name = "${subsystem_name}" diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 54edfd6fb370f129151948e1e1dc4506c7ca42b6..c4fb598a84bfba490c1bae88c7ffa76826d33f17 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -15,7 +15,10 @@ import("//base/notification/distributed_notification_service/notification.gni") import("//build/ohos.gni") config("ans_distributed_config") { - include_dirs = [ "${services_path}/distributed/include" ] + include_dirs = [ + "${services_path}/distributed/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", + ] } ohos_shared_library("libans_distributed") { @@ -39,7 +42,8 @@ ohos_shared_library("libans_distributed") { "${frameworks_module_ans_path}:ans_innerkits_public_config", ] - deps = [ "${core_path}:ans_core" ] + deps = [ + "${core_path}:ans_core",] external_deps = [ "ability_base:want", @@ -50,6 +54,7 @@ ohos_shared_library("libans_distributed") { "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "kv_store:distributeddata_inner", + "ffrt:libffrt", ] innerapi_tags = [ "platformsdk_indirect" ] diff --git a/services/distributed/include/distributed_notification_manager.h b/services/distributed/include/distributed_notification_manager.h index 9d453e155ca9d1a90e584f19c1009d3e86a52cf8..422aacc7ab7c051df113aca47df089d7a6488b63 100644 --- a/services/distributed/include/distributed_notification_manager.h +++ b/services/distributed/include/distributed_notification_manager.h @@ -22,6 +22,7 @@ #include "event_handler.h" #include "event_runner.h" +#include "ffrt.h" #include "distributed_database.h" #include "distributed_database_callback.h" @@ -166,6 +167,7 @@ private: std::shared_ptr databaseCb_; std::shared_ptr deviceCb_; IDistributedCallback callback_ = {0}; + std::shared_ptr distributedQueue_ = nullptr; 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 073060a6cf342d62ede37e3321e3269e98d746b9..7e38d94c97fe8629c52dd4049bd87c09bfbd721a 100644 --- a/services/distributed/src/distributed_notification_manager.cpp +++ b/services/distributed/src/distributed_notification_manager.cpp @@ -30,9 +30,7 @@ const std::string DELIMITER = "|"; DistributedNotificationManager::DistributedNotificationManager() { - runner_ = OHOS::AppExecFwk::EventRunner::Create("NotificationDistributedMgr"); - handler_ = std::make_shared(runner_); - AnsWatchdog::AddHandlerThread(handler_, runner_); + distributedQueue_ = std::make_shared("NotificationDistributedMgr"); DistributedDatabaseCallback::IDatabaseChange databaseCallback = { .OnInsert = std::bind(&DistributedNotificationManager::OnDatabaseInsert, @@ -68,7 +66,10 @@ DistributedNotificationManager::DistributedNotificationManager() DistributedNotificationManager::~DistributedNotificationManager() { - handler_->PostSyncTask(std::bind([&]() { callback_ = {}; }), AppExecFwk::EventHandler::Priority::HIGH); + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = distributedQueue_->submit_h(std::bind([&]() { callback_ = {}; })); + distributedQueue_->wait(handler); + ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::GenerateDistributedKey( @@ -131,7 +132,9 @@ void DistributedNotificationManager::OnDatabaseInsert( const std::string &deviceId, const std::string &key, const std::string &value) { ANS_LOGD("%{public}s", __FUNCTION__); - handler_->PostTask(std::bind([=]() { + ANS_LOGE("ffrt start!"); + distributedQueue_->submit(std::bind([=]() { + ANS_LOGE("ffrt enter!"); if (!CheckDeviceId(deviceId, key)) { ANS_LOGD("device id are not the same. deviceId:%{public}s key:%{public}s", deviceId.c_str(), key.c_str()); } @@ -151,13 +154,16 @@ void DistributedNotificationManager::OnDatabaseInsert( PublishCallback(resolveKey.deviceId, resolveKey.bundleName, request); })); + ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::OnDatabaseUpdate( const std::string &deviceId, const std::string &key, const std::string &value) { ANS_LOGD("%{public}s", __FUNCTION__); - handler_->PostTask(std::bind([=]() { + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = distributedQueue_->submit_h(std::bind([=]() { + ANS_LOGE("ffrt enter!"); if (!CheckDeviceId(deviceId, key)) { ANS_LOGD("device id are not the same. deviceId:%{public}s key:%{public}s", deviceId.c_str(), key.c_str()); } @@ -177,13 +183,16 @@ void DistributedNotificationManager::OnDatabaseUpdate( UpdateCallback(resolveKey.deviceId, resolveKey.bundleName, request); })); + ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::OnDatabaseDelete( const std::string &deviceId, const std::string &key, const std::string &value) { ANS_LOGD("%{public}s", __FUNCTION__); - handler_->PostTask(std::bind([=]() { + ANS_LOGE("ffrt start!"); + distributedQueue_->submit(std::bind([=]() { + ANS_LOGE("ffrt enter!"); if (!CheckDeviceId(deviceId, key)) { ANS_LOGD("device id are not the same. deviceId:%{public}s key:%{public}s", deviceId.c_str(), key.c_str()); } @@ -196,12 +205,15 @@ void DistributedNotificationManager::OnDatabaseDelete( DeleteCallback(resolveKey.deviceId, resolveKey.bundleName, resolveKey.label, resolveKey.id); })); + ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::OnDeviceConnected(const std::string &deviceId) { ANS_LOGD("%{public}s", __FUNCTION__); - handler_->PostTask(std::bind([=]() { + ANS_LOGE("ffrt start!"); + distributedQueue_->submit(std::bind([=]() { + ANS_LOGE("ffrt enter!"); if (database_ == nullptr) { ANS_LOGE("OnDeviceConnected failed: database is null"); return; @@ -210,13 +222,16 @@ void DistributedNotificationManager::OnDeviceConnected(const std::string &device ANS_LOGE("OnDeviceConnected failed."); } })); + ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::OnDeviceDisconnected(const std::string &deviceId) { ANS_LOGD("%{public}s", __FUNCTION__); - handler_->PostTask(std::bind([=]() { + ANS_LOGE("ffrt start!"); + distributedQueue_->submit(std::bind([=]() { + ANS_LOGE("ffrt enter!"); std::string prefixKey = deviceId + DELIMITER; std::vector entries; if (!database_->GetEntriesFromDistributedDB(prefixKey, entries)) { @@ -241,6 +256,7 @@ void DistributedNotificationManager::OnDeviceDisconnected(const std::string &dev database_->RecreateDistributedDB(); } })); + ANS_LOGE("ffrt end!"); return; } @@ -364,14 +380,20 @@ ErrCode DistributedNotificationManager::DeleteRemoteNotification( ErrCode DistributedNotificationManager::RegisterCallback(const IDistributedCallback &callback) { ANS_LOGI("%{public}s start", __FUNCTION__); - handler_->PostSyncTask(std::bind([&]() { callback_ = callback; }), AppExecFwk::EventHandler::Priority::HIGH); + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = distributedQueue_->submit_h(std::bind([&]() { callback_ = callback; })); + distributedQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return ERR_OK; } ErrCode DistributedNotificationManager::UngegisterCallback(void) { ANS_LOGI("%{public}s start", __FUNCTION__); - handler_->PostSyncTask(std::bind([&]() { callback_ = {}; }), AppExecFwk::EventHandler::Priority::HIGH); + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = distributedQueue_->submit_h(std::bind([&]() { callback_ = {}; })); + distributedQueue_->wait(handler); + ANS_LOGE("ffrt end!"); return ERR_OK; } diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index dfc759afea8b1299e1f9b9bd593d564d4ad2419d..dd3facc42c402392459f3ca0de2f2bcd3cad46e2 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -35,7 +35,10 @@ group("ans_unit_test") { ohos_unittest("ans_distributed_unit_test") { module_out_path = "${component_name}/unittest" - include_dirs = [ "/${services_path}/distributed/include" ] + include_dirs = [ + "/${services_path}/distributed/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", + ] sources = [ "${services_path}/distributed/src/distributed_database.cpp", @@ -83,6 +86,7 @@ ohos_unittest("ans_distributed_unit_test") { "ipc:ipc_core", "kv_store:distributeddata_inner", "multimedia_image_framework:image_native", + "ffrt:libffrt", ] subsystem_name = "${subsystem_name}" @@ -382,7 +386,10 @@ ohos_unittest("distributed_flow_control_test") { ohos_unittest("distributed_notification_manager_branch_test") { module_out_path = "${component_name}/unittest" - include_dirs = [ "/${services_path}/distributed/include" ] + include_dirs = [ + "/${services_path}/distributed/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", + ] sources = [ "distributed_notification_manager_branch_test/distributed_notification_manager_branch_test.cpp", @@ -415,6 +422,7 @@ ohos_unittest("distributed_notification_manager_branch_test") { "ipc:ipc_core", "kv_store:distributeddata_inner", "multimedia_image_framework:image_native", + "ffrt:libffrt", ] subsystem_name = "${subsystem_name}" diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 12b1fee76527408337568746e2588b68a77630f6..a299c6e9502a55946a6502c8053d9bc42d27454b 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -25,6 +25,7 @@ ohos_moduletest("ans_module_test") { "${services_path}/ans/test/unittest", "${services_path}/ans/test/unittest/mock/include", "${services_path}/test/moduletest/mock/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] sources = [ @@ -88,6 +89,7 @@ ohos_moduletest("ans_module_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "time_service:time_client", + "ffrt:libffrt", ] if (device_usage) { diff --git a/test/bechmarktest/notification_services_test/BUILD.gn b/test/bechmarktest/notification_services_test/BUILD.gn index 2d9f0f5ae01541c341de3d0fa1f9cf4c1b49ef84..96b927e0c48e2c86fd1d87cea8b86229b5386bf0 100644 --- a/test/bechmarktest/notification_services_test/BUILD.gn +++ b/test/bechmarktest/notification_services_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_benchmarktest("Benchmark_Notification_Servece_Test") { "include", "mock/include", "${services_path}/ans/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] sources = [ @@ -47,6 +48,7 @@ ohos_benchmarktest("Benchmark_Notification_Servece_Test") { "kv_store:distributeddata_inner", "multimedia_image_framework:image_native", "relational_store:native_rdb", + "ffrt:libffrt", ] subsystem_name = "${subsystem_name}" part_name = "${component_name}" diff --git a/test/fuzztest/advancednotificationservice_fuzzer/BUILD.gn b/test/fuzztest/advancednotificationservice_fuzzer/BUILD.gn index 9d911ff5a9354a7ae9cf884fe691fb2a11bc237b..5bd454141186219b1caef51af2d9a12b3445ee46 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/BUILD.gn +++ b/test/fuzztest/advancednotificationservice_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("AdvancedNotificationServiceFuzzTest") { "${inner_api_path}", "${core_path}/common/include", "${core_path}/include", + "//foundation/resourceschedule/ffrt/interfaces/kits", ] cflags = [ "-g", @@ -57,6 +58,7 @@ ohos_fuzztest("AdvancedNotificationServiceFuzzTest") { "kv_store:distributeddata_inner", "multimedia_image_framework:image_native", "relational_store:native_rdb", + "ffrt:libffrt", ] }