diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index b88dedd3a4d7e32279b44105db2d029527f0b231..ae38a542ef8c157babf57436c06bbe0d7c21f72a 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -2886,15 +2886,5 @@ void NotificationRequest::SetDistributedHashCode(const std::string hashCode) { distributedHashCode_ = hashCode; } - -bool NotificationRequest::GetCollaborateDelete() const -{ - return isCollaborateDelete_; -} - -void NotificationRequest::SetCollaborateDelete(bool isCollaborateDelete) -{ - isCollaborateDelete_ = isCollaborateDelete; -} } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index 5f848f50274e57fd89745c57cf0674e678504fb7..02fe3c26831f9096663d16ea07cff0602037a481 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -1449,10 +1449,6 @@ public: const std::string GetDistributedHashCode() const; - bool GetCollaborateDelete() const; - - void SetCollaborateDelete(bool isCollaborateDelete); - void SetDistributedHashCode(const std::string hashCode); private: @@ -1581,7 +1577,6 @@ private: bool forceDistributed_ {false}; bool notDistributed_ {false}; bool isSystemApp_ {false}; - bool isCollaborateDelete_ {false}; std::shared_ptr wantAgent_ {}; std::shared_ptr removalWantAgent_ {}; diff --git a/services/ans/include/notification_extension/distributed_extension_service.h b/services/ans/include/notification_extension/distributed_extension_service.h index db1f75c04d08d5c8709f2d18ff63c7b89811afb0..77f2f34755ec69fe582f597691b9c746f0e5d7f8 100644 --- a/services/ans/include/notification_extension/distributed_extension_service.h +++ b/services/ans/include/notification_extension/distributed_extension_service.h @@ -22,6 +22,7 @@ #include "ffrt.h" #include #include +#include namespace OHOS { namespace Notification { @@ -55,6 +56,7 @@ public: int32_t maxContentLength; std::string localType; std::set supportPeerDevice_; + std::unordered_set collaborativeDeleteTypes_; }; class DistributedExtensionService { diff --git a/services/ans/include/notification_subscriber_manager.h b/services/ans/include/notification_subscriber_manager.h index 950bac00cd5fa1b1108fdb8ce50fa2dd53adfb0e..0410e633e559d0c0475a9652c13f97bbb81442ad 100644 --- a/services/ans/include/notification_subscriber_manager.h +++ b/services/ans/include/notification_subscriber_manager.h @@ -135,8 +135,6 @@ public: std::list> GetSubscriberRecords(); - void CheckCollaborativeRemoveType(sptr ¬ification); - #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED bool GetIsEnableEffectedRemind(); bool IsDeviceTypeSubscriberd(const std::string deviceType); diff --git a/services/ans/src/notification_extension/distributed_extension_service.cpp b/services/ans/src/notification_extension/distributed_extension_service.cpp index 23249d04f406c67075d5790619d3e82fd39d4d50..fe9e5d95e9895006ee8f0232708f95b98340398a 100644 --- a/services/ans/src/notification_extension/distributed_extension_service.cpp +++ b/services/ans/src/notification_extension/distributed_extension_service.cpp @@ -25,7 +25,8 @@ using namespace DistributedHardware; using DeviceCallback = std::function; typedef int32_t (*INIT_LOCAL_DEVICE)(const std::string &deviceId, uint16_t deviceType, - int32_t titleLength, int32_t contentLength, DeviceCallback callback); + int32_t titleLength, int32_t contentLength, std::unordered_set collaborativeDeleteTypes, + DeviceCallback callback); typedef void (*RELEASE_LOCAL_DEVICE)(); typedef void (*ADD_DEVICE)(const std::string &deviceId, uint16_t deviceType, const std::string &networkId); @@ -137,6 +138,7 @@ bool DistributedExtensionService::initConfig() ANS_LOGI("Dans initConfig content length %{public}d.", deviceConfig_.maxContentLength); } + deviceConfig_.collaborativeDeleteTypes_ = NotificationConfigParse::GetInstance()->GetCollaborativeDeleteType(); return true; } @@ -167,7 +169,8 @@ int32_t DistributedExtensionService::InitDans() ANS_LOGI("Dans get local device %{public}s, %{public}d, %{public}d, %{public}d.", deviceInfo.deviceId, deviceInfo.deviceTypeId, deviceConfig_.maxTitleLength, deviceConfig_.maxContentLength); if (handler(deviceInfo.deviceId, deviceInfo.deviceTypeId, deviceConfig_.maxTitleLength, - deviceConfig_.maxContentLength, std::bind(&DistributedExtensionService::DeviceStatusCallback, this, + deviceConfig_.maxContentLength, deviceConfig_.collaborativeDeleteTypes_, + std::bind(&DistributedExtensionService::DeviceStatusCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)) != 0) { dansRunning_.store(false); return -1; diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 5684d5f06ab036fe81180aa1bd1b459f16af8e92..cad2a42c3b76bb6fa45cb9b9c8dc76bbd3837d76 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -231,12 +231,6 @@ void NotificationSubscriberManager::NotifyCanceled( ANS_LOGE("queue is nullptr"); return; } - if (deleteReason != NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE) { - auto nonConstNotification = const_cast &>(notification); - if (nonConstNotification) { - CheckCollaborativeRemoveType(nonConstNotification); - } - } AppExecFwk::EventHandler::Callback NotifyCanceledFunc = std::bind( &NotificationSubscriberManager::NotifyCanceledInner, this, notification, notificationMap, deleteReason); @@ -255,14 +249,6 @@ void NotificationSubscriberManager::BatchNotifyCanceled(const std::vector &>(notification); - if (nonConstNotification) { - CheckCollaborativeRemoveType(nonConstNotification); - } - } - } AppExecFwk::EventHandler::Callback NotifyCanceledFunc = std::bind( &NotificationSubscriberManager::BatchNotifyCanceledInner, this, notifications, notificationMap, deleteReason); @@ -784,48 +770,5 @@ std::list NotificationSubscriberManager::GetSubscriberRecor return subscriberRecordList_; } -void NotificationSubscriberManager::CheckCollaborativeRemoveType(sptr ¬ification) -{ - if (notification == nullptr || notification->GetNotificationRequestPoint() == nullptr) { - ANS_LOGE("notification or NotificationRequest is nullptr"); - return; - } - std::string type; - switch (notification->GetNotificationRequestPoint()->GetSlotType()) { - case NotificationConstant::SlotType::SOCIAL_COMMUNICATION: - type = "SOCIAL_COMMUNICATION"; - break; - case NotificationConstant::SlotType::SERVICE_REMINDER: - type = "SERVICE_REMINDER"; - break; - case NotificationConstant::SlotType::CONTENT_INFORMATION: - type = "CONTENT_INFORMATION"; - break; - case NotificationConstant::SlotType::OTHER: - type = "OTHER"; - break; - case NotificationConstant::SlotType::CUSTOM: - type = "CUSTOM"; - break; - case NotificationConstant::SlotType::LIVE_VIEW: - type = "LIVE_VIEW"; - break; - case NotificationConstant::SlotType::CUSTOMER_SERVICE: - type = "CUSTOMER_SERVICE"; - break; - case NotificationConstant::SlotType::EMERGENCY_INFORMATION: - type = "EMERGENCY_INFORMATION"; - break; - case NotificationConstant::SlotType::ILLEGAL_TYPE: - type = "ILLEGAL_TYPE"; - break; - default: - return; - } - auto collaboratives = DelayedSingleton::GetInstance()->GetCollaborativeDeleteType(); - if (collaboratives.find(type) != collaboratives.end()) { - notification->GetNotificationRequestPoint()->SetCollaborateDelete(true); - } -} } // namespace Notification } // namespace OHOS diff --git a/services/distributed/include/distributed_preferences_info.h b/services/distributed/include/distributed_preferences_info.h index 5e507363d4eba386ed6de81b2053ff04a6b542da..b13d3a53544e4f06b42f8f0411b23744bf75185b 100644 --- a/services/distributed/include/distributed_preferences_info.h +++ b/services/distributed/include/distributed_preferences_info.h @@ -18,7 +18,6 @@ #include #include -#include #include "ans_inner_errors.h" @@ -82,7 +81,6 @@ private: bool distributedEnable_ = false; std::map, bool> bundleEnable_; std::map enabledWithoutApp_; - std::unordered_set collaborativeNotificationList_; }; } // namespace Notification } // namespace OHOS diff --git a/services/distributed/include/soft_bus/distributed_device_data.h b/services/distributed/include/soft_bus/distributed_device_data.h index ac91d950cf77da8a69f218a2052ae0677146e8c1..4f5447dc3b2f33adeb874624aa3ec3e5a0b2a766 100644 --- a/services/distributed/include/soft_bus/distributed_device_data.h +++ b/services/distributed/include/soft_bus/distributed_device_data.h @@ -20,6 +20,7 @@ #include "socket.h" #include "ans_log_wrapper.h" #include "dm_device_info.h" +#include namespace OHOS { namespace Notification { @@ -51,6 +52,7 @@ struct DistributedDeviceInfo { int32_t peerState_ = DeviceState::STATE_INIT; int32_t socketId_ = -1; int32_t connectedTry_ = 0; + std::unordered_set collaborativeDeleteTypes_; }; struct ConnectedSocketInfo { diff --git a/services/distributed/include/soft_bus/distributed_manager.h b/services/distributed/include/soft_bus/distributed_manager.h index 7879c48cc8be1e4e288373ae67d640966797b60c..b179a2081c68df5210633b9b76bb41fdb3622d14 100644 --- a/services/distributed/include/soft_bus/distributed_manager.h +++ b/services/distributed/include/soft_bus/distributed_manager.h @@ -18,6 +18,8 @@ #include "distributed_device_data.h" +#include + namespace OHOS { namespace Notification { class DistributedManager { @@ -27,7 +29,7 @@ public: static DistributedManager& GetInstance(); void ReleaseLocalDevice(); int32_t InitLocalDevice(const std::string &deviceId, uint16_t deviceType, - int32_t titleLength, int32_t contentLength, + int32_t titleLength, int32_t contentLength, std::unordered_set collaborativeDeleteTypes, std::function callback); void AddDevice(const std::string &deviceId, uint16_t deviceType, const std::string &networkId); diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index 8a30b83622798724143fda475730c4906d70c899..d24dd0df199885e077dcf96b37cb20a87453c73e 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -25,6 +25,8 @@ #include "match_box.h" #include #include "bundle_icon_box.h" +#include + namespace OHOS { namespace Notification { @@ -35,6 +37,7 @@ public: void SubscribeNotifictaion(const DistributedDeviceInfo device); void UnSubscribeNotifictaion(const std::string &deviceId, uint16_t deviceType); int32_t InitService(const std::string &deviceId, uint16_t deviceType, + std::unordered_set collaborativeDeleteTypes, std::function callback); void OnReceiveMsg(const void *data, uint32_t dataLen); void OnConsumed(const std::shared_ptr &request, @@ -58,6 +61,8 @@ public: void HandleBundlesEvent(const std::string& bundleName, const std::string& action); void HandleBundleChanged(const std::string& bundleName, bool updatedExit); std::string GetNotificationKey(const std::shared_ptr& notification); + std::unordered_set GetCollaborativeDeleteTypes(); + private: int64_t GetCurrentTime(); void HandleBundleRemoved(const std::string& bundleName); diff --git a/services/distributed/include/soft_bus/distributed_subscriber.h b/services/distributed/include/soft_bus/distributed_subscriber.h index 16d1c76607450cb72b8e46a891b5fe42b0df1199..c5bd3965bb842ce1f77d2beb74f4c5a214c00273 100644 --- a/services/distributed/include/soft_bus/distributed_subscriber.h +++ b/services/distributed/include/soft_bus/distributed_subscriber.h @@ -44,6 +44,8 @@ public: void SetLocalDevice(DistributedDeviceInfo localDevice); void SetPeerDevice(DistributedDeviceInfo localDevice); bool CheckNeedCollaboration(const std::shared_ptr ¬ification); + bool CheckCollaborativeRemoveType(const NotificationConstant::SlotType& slotType); + private: DistributedDeviceInfo localDevice_; DistributedDeviceInfo peerDevice_; diff --git a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp index 7ef2f63c5bef7d82ff63974c32b07faf8b037a27..8d388de7c7dc096798569ecdcb556f429421b8aa 100644 --- a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp +++ b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp @@ -16,6 +16,7 @@ #include #include +#include #define SYMBOL_EXPORT __attribute__ ((visibility("default"))) namespace OHOS { @@ -25,10 +26,11 @@ extern "C" { #endif SYMBOL_EXPORT int32_t InitLocalDevice(const std::string &deviceId, uint16_t deviceType, - int32_t titleLength, int32_t contentLength, std::function callback) + int32_t titleLength, int32_t contentLength, std::unordered_set collaborativeDeleteTypes, + std::function callback) { return DistributedManager::GetInstance().InitLocalDevice(deviceId, deviceType, - titleLength, contentLength, callback); + titleLength, contentLength, collaborativeDeleteTypes, callback); } SYMBOL_EXPORT void AddDevice(const std::string &deviceId, uint16_t deviceType, diff --git a/services/distributed/src/soft_bus/distributed_manager.cpp b/services/distributed/src/soft_bus/distributed_manager.cpp index 431a9c3776009c2ee26c31be2022364ea006be0b..ac2813fb6f48f1b93773b80fd16f5257a06384e0 100644 --- a/services/distributed/src/soft_bus/distributed_manager.cpp +++ b/services/distributed/src/soft_bus/distributed_manager.cpp @@ -42,12 +42,13 @@ void DistributedManager::ReleaseLocalDevice() } int32_t DistributedManager::InitLocalDevice(const std::string &deviceId, uint16_t deviceType, - int32_t titleLength, int32_t contentLength, std::function callback) + int32_t titleLength, int32_t contentLength, std::unordered_set collaborativeDeleteTypes, + std::function callback) { ANS_LOGI("InitLocalDevice %{public}s %{public}u.", deviceId.c_str(), deviceType); DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->InitExtentionWrapper(); DistributedLocalConfig::GetInstance().SetLocalDevice(deviceId, deviceType, titleLength, contentLength); - return DistributedService::GetInstance().InitService(deviceId, deviceType, callback); + return DistributedService::GetInstance().InitService(deviceId, deviceType, collaborativeDeleteTypes, callback); } void DistributedManager::AddDevice(const std::string &deviceId, uint16_t deviceType, diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index e657b8ef5bfb5c2b0b91369c81af64f638be701a..a09413b3aa3604d5bc9db0e5fa145c4aa43d2649 100644 --- a/services/distributed/src/soft_bus/distributed_service.cpp +++ b/services/distributed/src/soft_bus/distributed_service.cpp @@ -49,11 +49,13 @@ DistributedService::DistributedService() } int32_t DistributedService::InitService(const std::string &deviceId, uint16_t deviceType, + std::unordered_set collaborativeDeleteTypes, std::function callback) { int32_t userId; localDevice_.deviceId_ = deviceId; localDevice_.deviceType_ = deviceType; + localDevice_.collaborativeDeleteTypes_ = collaborativeDeleteTypes; if (DistributedServer::GetInstance().InitServer(deviceId, deviceType) != 0) { ANS_LOGI("Distributed service init server failed."); return -1; @@ -218,5 +220,10 @@ int64_t DistributedService::GetCurrentTime() return duration.count(); } +std::unordered_set DistributedService::GetCollaborativeDeleteTypes() +{ + return localDevice_.collaborativeDeleteTypes_; +} + } } diff --git a/services/distributed/src/soft_bus/distributed_subscriber.cpp b/services/distributed/src/soft_bus/distributed_subscriber.cpp index e5361a9218a17722a3b2bb9792ec57b79bf98c2d..cb704e9207fa598efc6e6d0825a5fb3c783b4ff8 100644 --- a/services/distributed/src/soft_bus/distributed_subscriber.cpp +++ b/services/distributed/src/soft_bus/distributed_subscriber.cpp @@ -146,11 +146,50 @@ bool DistribuedSubscriber::CheckNeedCollaboration(const std::shared_ptrGetNotificationRequestPoint()->GetCollaborateDelete()) { - ANS_LOGE("checkCollaborativeDeleteType failed"); + if (!CheckCollaborativeRemoveType(notification->GetNotificationRequestPoint()->GetSlotType())) { + ANS_LOGE("CheckCollaborativeRemoveType failed"); return false; } return true; } + +bool DistribuedSubscriber::CheckCollaborativeRemoveType(const NotificationConstant::SlotType& slotType) +{ + std::string type; + switch (slotType) { + case NotificationConstant::SlotType::SOCIAL_COMMUNICATION: + type = "SOCIAL_COMMUNICATION"; + break; + case NotificationConstant::SlotType::SERVICE_REMINDER: + type = "SERVICE_REMINDER"; + break; + case NotificationConstant::SlotType::CONTENT_INFORMATION: + type = "CONTENT_INFORMATION"; + break; + case NotificationConstant::SlotType::OTHER: + type = "OTHER"; + break; + case NotificationConstant::SlotType::CUSTOM: + type = "CUSTOM"; + break; + case NotificationConstant::SlotType::LIVE_VIEW: + type = "LIVE_VIEW"; + break; + case NotificationConstant::SlotType::CUSTOMER_SERVICE: + type = "CUSTOMER_SERVICE"; + break; + case NotificationConstant::SlotType::EMERGENCY_INFORMATION: + type = "EMERGENCY_INFORMATION"; + break; + case NotificationConstant::SlotType::ILLEGAL_TYPE: + type = "ILLEGAL_TYPE"; + break; + default: + return false; + } + auto collaborativeDeleteTypes = DistributedService::GetInstance().GetCollaborativeDeleteTypes(); + return collaborativeDeleteTypes.find(type) != collaborativeDeleteTypes.end(); +} + } } \ No newline at end of file