From 87f63b5a215e569e0c16565b4163994ff22e255f Mon Sep 17 00:00:00 2001 From: zhengzhuolan Date: Thu, 9 Jan 2025 22:00:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=85=A8=E5=9C=BA=E6=99=AF=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E3=80=91=E9=80=9A=E7=9F=A5=E5=8D=8F=E5=90=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=20=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhengzhuolan --- .../include/soft_bus/distributed_service.h | 4 +- .../include/soft_bus/distributed_subscriber.h | 4 ++ .../include/tlv_box/batch_remove_box.h | 11 +++-- .../distributed/include/tlv_box/remove_box.h | 3 +- .../distributed/include/tlv_box/tlv_box.h | 4 -- .../soft_bus/distributed_publish_service.cpp | 31 ++++++++++---- .../src/soft_bus/distributed_service.cpp | 4 +- .../distributed_subscribe_service.cpp | 42 +++++++++++-------- .../src/tlv_box/batch_remove_box.cpp | 18 +++----- .../distributed/src/tlv_box/remove_box.cpp | 12 +----- services/distributed/src/tlv_box/tlv_box.cpp | 15 ------- 11 files changed, 68 insertions(+), 80 deletions(-) diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index eeafa7822..7fb64bd20 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 c5bd3965b..9a163cca6 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 31363ddd8..e0f35ef86 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 27628513c..f8db324a7 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 8281e2df8..c361ad9cb 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 0d881787b..be3277d17 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 a09413b3a..821f409af 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 23aaba637..c3ef5e317 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 ee130c8f0..7743658e5 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 5603b555b..76a9c0a6d 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 dcb02772a..816ca09ee 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); -- Gitee