diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index eeafa782275b57dce3033fb01b7de70f9641c17e..7fb64bd2008e4bce1716edee152b4ae1004ed36b 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -79,8 +79,8 @@ private: void SetNotifictaionContent(const NotifticationRequestBox& box, sptr& request, int32_t contentType); void MakeNotifictaionReminderFlag(const NotifticationRequestBox& box, sptr& request); - void RemoveNotifictaion(const std::shared_ptr& boxMessage); - void RemoveNotifictaions(const std::shared_ptr& boxMessage); + void RemoveNotification(const std::shared_ptr& boxMessage); + void RemoveNotifications(const std::shared_ptr& boxMessage); void SetNotificationContent(const std::shared_ptr &content, NotificationContent::Type type, NotifticationRequestBox &requestBox); void GetNeedUpdateDevice(bool updatedExit, 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 c5bd3965bb842ce1f77d2beb74f4c5a214c00273..9a163cca670c9f82a47e4f37dbc1c6c390b37a3e 100644 --- a/services/distributed/include/soft_bus/distributed_subscriber.h +++ b/services/distributed/include/soft_bus/distributed_subscriber.h @@ -45,6 +45,10 @@ public: void SetPeerDevice(DistributedDeviceInfo localDevice); bool CheckNeedCollaboration(const std::shared_ptr ¬ification); bool CheckCollaborativeRemoveType(const NotificationConstant::SlotType& slotType); + bool HasOnBatchCancelCallback() override + { + return true; + } private: DistributedDeviceInfo localDevice_; diff --git a/services/distributed/include/tlv_box/batch_remove_box.h b/services/distributed/include/tlv_box/batch_remove_box.h index 31363ddd862effcc7f09cfc2e2c710080507c0bb..e0f35ef86fa149dc6295a77c0868bd30b94019b6 100644 --- a/services/distributed/include/tlv_box/batch_remove_box.h +++ b/services/distributed/include/tlv_box/batch_remove_box.h @@ -23,13 +23,12 @@ namespace OHOS { namespace Notification { -class BatchRemoveNotifticationBox : public BoxBase { +class BatchRemoveNotificationBox : public BoxBase { public: - BatchRemoveNotifticationBox(); - ~BatchRemoveNotifticationBox(); - BatchRemoveNotifticationBox(std::shared_ptr box); - bool SetNotificationHashCode(const std::string& hasdCode); - bool SetNotificationKeys(const std::vector& keys); + BatchRemoveNotificationBox(); + ~BatchRemoveNotificationBox(); + BatchRemoveNotificationBox(std::shared_ptr box); + bool SetNotificationHashCode(const std::string& hashCode); }; } // namespace Notification } // namespace OHOS diff --git a/services/distributed/include/tlv_box/remove_box.h b/services/distributed/include/tlv_box/remove_box.h index 27628513c4a99b120bbfdcb663cace62f6be4e56..f8db324a78abff06328fd5d264d30de5201db37d 100644 --- a/services/distributed/include/tlv_box/remove_box.h +++ b/services/distributed/include/tlv_box/remove_box.h @@ -27,8 +27,7 @@ public: NotificationRemoveBox(); ~NotificationRemoveBox(); NotificationRemoveBox(std::shared_ptr box); - bool SetNotificationHashCode(const std::string& hasdCode); - bool SetDistributedCollaborate(bool distributedCollaborate); + bool SetNotificationHashCode(const std::string& hashCode); }; } // namespace Notification } // namespace OHOS diff --git a/services/distributed/include/tlv_box/tlv_box.h b/services/distributed/include/tlv_box/tlv_box.h index 8281e2df80ef48a4ad61985db446bc18f3784d70..c361ad9cb9e485fc793a41bb0cafb9bcb612252e 100644 --- a/services/distributed/include/tlv_box/tlv_box.h +++ b/services/distributed/include/tlv_box/tlv_box.h @@ -48,8 +48,6 @@ enum TlvType : int32_t { NOTIFICATION_OVERLAY_ICON = 9, NOTIFICATION_CONTENT_TYPE = 10, NOTIFICATION_COMMON_LIVEVIEW = 11, - BATCH_REMOVE_NOTIFICATIONS = 12, - COLLABORATIVE_NOTIFICATION = 13, BUNDLE_ICON_SYNC_TYPE = 992, MATCH_TYPE = 993, PEER_DEVICE_ID = 994, @@ -68,7 +66,6 @@ public: TlvItem(int32_t type, std::string value); TlvItem(int32_t type, const unsigned char* value, int32_t length); TlvItem(int32_t type, const TlvItem& value); - TlvItem(int32_t type, std::vector value); ~TlvItem(); int32_t GetType() const; @@ -99,7 +96,6 @@ public: bool GetStringValue(int32_t type, std::string& value); bool GetInt32Value(int32_t type, int32_t& value); bool GetObjectValue(int32_t type, TlvBox& value); - bool GetVectorValue(int32_t type, std::vector& value); int32_t bytesLength_ = 0; unsigned char* byteBuffer_ = nullptr; diff --git a/services/distributed/src/soft_bus/distributed_publish_service.cpp b/services/distributed/src/soft_bus/distributed_publish_service.cpp index 0d881787b4014f42529d86fcad422bc40a9cf952..be3277d170ddda1ddcce2049a684e796ec0717cd 100644 --- a/services/distributed/src/soft_bus/distributed_publish_service.cpp +++ b/services/distributed/src/soft_bus/distributed_publish_service.cpp @@ -12,6 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + #include + #include "distributed_service.h" #include "notification_helper.h" @@ -175,29 +178,41 @@ void DistributedService::PublishNotifictaion(const std::shared_ptr& boxM ANS_LOGI("Dans publish message %{public}s %{public}d.", request->Dump().c_str(), result); } -void DistributedService::RemoveNotifictaion(const std::shared_ptr& boxMessage) +void DistributedService::RemoveNotification(const std::shared_ptr& boxMessage) { - std::string hasdCode; + std::string hashCode; if (boxMessage == nullptr) { ANS_LOGE("boxMessage is nullptr"); return; } - boxMessage->GetStringValue(NOTIFICATION_HASHCODE, hasdCode); + boxMessage->GetStringValue(NOTIFICATION_HASHCODE, hashCode); int result = IN_PROCESS_CALL(NotificationHelper::RemoveNotification( - hasdCode, NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE)); + hashCode, NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE)); ANS_LOGI("dans remove message %{public}d.", result); } -void DistributedService::RemoveNotifictaions(const std::shared_ptr& boxMessage) +void DistributedService::RemoveNotifications(const std::shared_ptr& boxMessage) { - std::vector hasdCodes; + std::vector hashCodes; + std::string hashCodesString; if (boxMessage == nullptr) { ANS_LOGE("boxMessage is nullptr"); return; } - boxMessage->GetVectorValue(BATCH_REMOVE_NOTIFICATIONS, hasdCodes); + if (!boxMessage->GetStringValue(NOTIFICATION_HASHCODE, hashCodesString)) { + ANS_LOGE("failed GetStringValue from boxMessage"); + return; + } + std::istringstream hashCodesStream(hashCodesString); + std::string hashCode; + while (hashCodesStream >> hashCode) { + if (!hashCode.empty()) { + hashCodes.push_back(hashCode); + } + } + int result = IN_PROCESS_CALL( - NotificationHelper::RemoveNotifications(hasdCodes, NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE)); + NotificationHelper::RemoveNotifications(hashCodes, NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE)); ANS_LOGI("dans batch remove message %{public}d.", result); } } diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index a09413b3aa3604d5bc9db0e5fa145c4aa43d2649..821f409af8f7d22d2fd601dc3e9de17e2031ecd9 100644 --- a/services/distributed/src/soft_bus/distributed_service.cpp +++ b/services/distributed/src/soft_bus/distributed_service.cpp @@ -197,10 +197,10 @@ void DistributedService::OnReceiveMsg(const void *data, uint32_t dataLen) HandleMatchSync(box); break; case NotificationEventType::REMOVE_NOTIFICATION: - RemoveNotifictaion(box); + RemoveNotification(box); break; case NotificationEventType::REMOVE_ALL_NOTIFICATIONS: - RemoveNotifictaions(box); + RemoveNotifications(box); break; case NotificationEventType::BUNDLE_ICON_SYNC: HandleBundleIconSync(box); diff --git a/services/distributed/src/soft_bus/distributed_subscribe_service.cpp b/services/distributed/src/soft_bus/distributed_subscribe_service.cpp index 23aaba637f30c5d16f678851d028ce02305aedf5..c3ef5e3178abf4649f66918fe2ca0ace5e5e145a 100644 --- a/services/distributed/src/soft_bus/distributed_subscribe_service.cpp +++ b/services/distributed/src/soft_bus/distributed_subscribe_service.cpp @@ -12,6 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include + #include "distributed_service.h" #include "notification_helper.h" @@ -26,6 +29,7 @@ #include "distributed_preference.h" #include "batch_remove_box.h" #include "remove_box.h" + namespace OHOS { namespace Notification { @@ -196,21 +200,22 @@ void DistributedService::OnBatchCanceled(const std::vector task = std::bind([peerDevice, notifications, this]() { - BatchRemoveNotifticationBox batchRemoveBox; - std::vector notificationKeys; - for (auto notification : notifications) { - if (notification == nullptr || notification->GetNotificationRequestPoint() == nullptr) { - ANS_LOGE("notification or GetNotificationRequestPoint is nullptr"); - continue; - } - ANS_LOGI("dans OnBatchCanceled %{public}s", notification->Dump().c_str()); - notificationKeys.push_back(GetNotificationKey(notification)); + std::ostringstream keysStream; + for (auto notification : notifications) { + if (notification == nullptr || notification->GetNotificationRequestPoint() == nullptr) { + ANS_LOGE("notification or GetNotificationRequestPoint is nullptr"); + continue; } + ANS_LOGI("dans OnBatchCanceled %{public}s", notification->Dump().c_str()); + keysStream << GetNotificationKey(notification) << ' '; + } + std::string notificationKeys = keysStream.str(); + + std::function task = std::bind([peerDevice, notifications, notificationKeys]() { + BatchRemoveNotificationBox batchRemoveBox; if (!notificationKeys.empty()) { - batchRemoveBox.SetNotificationHashCode(notificationKeys[0]); + batchRemoveBox.SetNotificationHashCode(notificationKeys); } - batchRemoveBox.SetNotificationKeys(notificationKeys); if (!batchRemoveBox.Serialize()) { ANS_LOGW("dans OnCanceled serialize failed"); @@ -229,14 +234,15 @@ void DistributedService::OnCanceled(const std::shared_ptr& notific ANS_LOGE("check handler is null"); return; } - std::function task = std::bind([peerDevice, notification, this]() { + if (notification == nullptr || notification->GetNotificationRequestPoint() == nullptr) { + ANS_LOGE("notification or GetNotificationRequestPoint is nullptr"); + return; + } + std::string notificationKey = GetNotificationKey(notification); + std::function task = std::bind([peerDevice, notification, notificationKey]() { NotificationRemoveBox removeBox; - if (notification == nullptr || notification->GetNotificationRequestPoint() == nullptr) { - ANS_LOGE("notification or GetNotificationRequestPoint is nullptr"); - return; - } ANS_LOGI("dans OnCanceled %{public}s", notification->Dump().c_str()); - removeBox.SetNotificationHashCode(GetNotificationKey(notification)); + removeBox.SetNotificationHashCode(notificationKey); if (!removeBox.Serialize()) { ANS_LOGW("dans OnCanceled serialize failed"); return; diff --git a/services/distributed/src/tlv_box/batch_remove_box.cpp b/services/distributed/src/tlv_box/batch_remove_box.cpp index ee130c8f0f2b12af9931036ed6d32717ecdc6349..7743658e5452a84d4682d1f0ae15d44377ad006c 100644 --- a/services/distributed/src/tlv_box/batch_remove_box.cpp +++ b/services/distributed/src/tlv_box/batch_remove_box.cpp @@ -18,7 +18,7 @@ namespace OHOS { namespace Notification { -BatchRemoveNotifticationBox::BatchRemoveNotifticationBox() +BatchRemoveNotificationBox::BatchRemoveNotificationBox() { if (box_ == nullptr) { return; @@ -26,26 +26,18 @@ BatchRemoveNotifticationBox::BatchRemoveNotifticationBox() box_->SetMessageType(REMOVE_ALL_NOTIFICATIONS); } -BatchRemoveNotifticationBox::~BatchRemoveNotifticationBox() +BatchRemoveNotificationBox::~BatchRemoveNotificationBox() {} -BatchRemoveNotifticationBox::BatchRemoveNotifticationBox(std::shared_ptr box) : BoxBase(box) +BatchRemoveNotificationBox::BatchRemoveNotificationBox(std::shared_ptr box) : BoxBase(box) {} -bool BatchRemoveNotifticationBox::SetNotificationKeys(const std::vector& keys) +bool BatchRemoveNotificationBox::SetNotificationHashCode(const std::string& hashCode) { if (box_ == nullptr) { return false; } - return box_->PutValue(std::make_shared(BATCH_REMOVE_NOTIFICATIONS, keys)); -} - -bool BatchRemoveNotifticationBox::SetNotificationHashCode(const std::string& hasdCode) -{ - if (box_ == nullptr) { - return false; - } - return box_->PutValue(std::make_shared(NOTIFICATION_HASHCODE, hasdCode)); + return box_->PutValue(std::make_shared(NOTIFICATION_HASHCODE, hashCode)); } } } diff --git a/services/distributed/src/tlv_box/remove_box.cpp b/services/distributed/src/tlv_box/remove_box.cpp index 5603b555b9c7399015ea78a41996dbe367c082ac..76a9c0a6d35e946bcb6533db85f1faae2cdf7e71 100644 --- a/services/distributed/src/tlv_box/remove_box.cpp +++ b/services/distributed/src/tlv_box/remove_box.cpp @@ -33,20 +33,12 @@ NotificationRemoveBox::NotificationRemoveBox(std::shared_ptr box) : BoxB { } -bool NotificationRemoveBox::SetNotificationHashCode(const std::string& hasdCode) +bool NotificationRemoveBox::SetNotificationHashCode(const std::string& hashCode) { if (box_ == nullptr) { return false; } - return box_->PutValue(std::make_shared(NOTIFICATION_HASHCODE, hasdCode)); -} - -bool NotificationRemoveBox::SetDistributedCollaborate(bool distributedCollaborate) -{ - if (box_ == nullptr) { - return false; - } - return box_->PutValue(std::make_shared(COLLABORATIVE_NOTIFICATION, distributedCollaborate)); + return box_->PutValue(std::make_shared(NOTIFICATION_HASHCODE, hashCode)); } } } diff --git a/services/distributed/src/tlv_box/tlv_box.cpp b/services/distributed/src/tlv_box/tlv_box.cpp index dcb02772af7fbfd217648c12c73f3e41907ce227..816ca09ee2a50cdc752f64d5cd2ea2ca7ebdf9df 100644 --- a/services/distributed/src/tlv_box/tlv_box.cpp +++ b/services/distributed/src/tlv_box/tlv_box.cpp @@ -79,11 +79,6 @@ TlvItem::TlvItem(int32_t type, std::string value) : type_(type) Initialize(value.c_str(), value.size() + 1); } -TlvItem::TlvItem(int32_t type, std::vector value) : type_(type) -{ - Initialize(&value, value.size()); -} - TlvItem::TlvItem(int32_t type, const TlvItem& value) : type_(type) { Initialize(value.GetValue(), value.GetLength()); @@ -153,16 +148,6 @@ bool TlvBox::GetStringValue(int32_t type, std::string& value) return false; } -bool TlvBox::GetVectorValue(int32_t type, std::vector& value) -{ - auto iter = TlvMap_.find(type); - if (iter != TlvMap_.end()) { - value = *reinterpret_cast *>(iter->second->GetValue()); - return true; - } - return false; -} - bool TlvBox::GetInt32Value(int32_t type, int32_t& value) { auto iter = TlvMap_.find(type);