diff --git a/hisysevent.yaml b/hisysevent.yaml index 7ececce794d97362899f569a77e39e0d2d3faba2..f6abf8c820f2cfe8557018884652aecbc27cdbfb 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -45,6 +45,12 @@ PUBLISH_ERROR: USER_ID: {type: INT32, desc: userId of notification creater} ERROR_CODE: {type: INT32, desc: error code} +EVENT_NOTIFICATION_ERROR: + __BASE: {type: FAULT, level: MINOR, desc: enable notification system error} + MESSAGE_TYPE: {type: STRING, desc: message type} + ERROR_CODE: {type: INT32, desc: error code} + REASON: {type: STRING, desc: err position and data type} + FLOW_CONTROL_OCCUR: __BASE: {type: FAULT, level: MINOR, desc: flow control occured} NOTIFICATION_ID: {type: INT32, desc: notification Id} diff --git a/services/ans/include/event_report.h b/services/ans/include/event_report.h index 01c44d6953f270f6fe0a46205deb4a0380ed1c26..fed32ae03e11c3c9b97485c21ea4cfc7cfa3bb6e 100644 --- a/services/ans/include/event_report.h +++ b/services/ans/include/event_report.h @@ -30,6 +30,7 @@ constexpr char SUBSCRIBE_ERROR[] = "SUBSCRIBE_ERROR"; constexpr char ENABLE_NOTIFICATION_ERROR[] = "ENABLE_NOTIFICATION_ERROR"; constexpr char ENABLE_NOTIFICATION_SLOT_ERROR[] = "ENABLE_NOTIFICATION_SLOT_ERROR"; constexpr char PUBLISH_ERROR[] = "PUBLISH_ERROR"; +constexpr char EVENT_NOTIFICATION_ERROR[] = "EVENT_NOTIFICATION_ERROR"; constexpr char FLOW_CONTROL_OCCUR[] = "FLOW_CONTROL_OCCUR"; constexpr char SUBSCRIBE[] = "SUBSCRIBE"; @@ -55,6 +56,8 @@ struct EventInfo { std::string bundleName; std::string notificationLabel; int32_t operateFlag; + int32_t messageType; + std::string reason; }; class EventReport { @@ -75,6 +78,7 @@ private: static void InnerSendEnableNotificationSlotErrorEvent(const EventInfo &eventInfo); static void InnerSendPublishErrorEvent(const EventInfo &eventInfo); static void InnerSendFlowControlOccurEvent(const EventInfo &eventInfo); + static void InnerSendNotificationSystemErrorEvent(const EventInfo &eventInfo); // behavior event static void InnerSendSubscribeEvent(const EventInfo &eventInfo); diff --git a/services/ans/include/notification_analytics_util.h b/services/ans/include/notification_analytics_util.h index c06609e15893f5e4f77041aa85b398ce966400a3..9dfca4a650ca849be44e5de28c43742471ab96bf 100644 --- a/services/ans/include/notification_analytics_util.h +++ b/services/ans/include/notification_analytics_util.h @@ -23,6 +23,8 @@ namespace OHOS { namespace Notification { +constexpr int MAX_TIME = 43200000;// ms + enum EventSceneId { SCENE_0 = 0, SCENE_1 = 1, @@ -36,6 +38,8 @@ enum EventSceneId { SCENE_9 = 9, SCENE_10 = 10, SCENE_11 = 11, + SCENE_20 = 20, + SCENE_21 = 21, }; enum EventBranchId { @@ -65,6 +69,12 @@ public: HaMetaMessage& TypeCode(int32_t typeCode); HaMetaMessage& NotificationId(int32_t notificationId); HaMetaMessage& SlotType(int32_t slotType); + HaMetaMessage& syncWatch(bool isLiveView); + HaMetaMessage& syncHeadSet(bool isLiveView); + HaMetaMessage& syncWatchHeadSet(bool isLiveView); + HaMetaMessage& keyNode(bool isKeyNode); + HaMetaMessage& delByWatch(bool isLiveView); + HaMetaMessage& deleteReason(int32_t deleteReason); std::string GetMessage() const; HaMetaMessage& Checkfailed(bool checkfailed); bool NeedReport() const; @@ -81,9 +91,20 @@ public: uint32_t errorCode_ = ERR_OK; std::string message_; bool checkfailed_ = true; + int32_t deleteReason_ = -1; + static int32_t syncWatch_; + static int32_t syncHeadSet_; + static int32_t syncWatchHeadSet_; + static int32_t delByWatch_; + static int32_t keyNode_; + static int64_t time_; + static int32_t syncLiveViewWatch_; + static int32_t syncLiveViewHeadSet_; + static int32_t syncLiveViewWatchHeadSet_; + static int64_t liveViewTime_; + static int32_t liveViewDelByWatch_; }; - struct FlowControllerOption { int32_t count; int32_t time; @@ -108,6 +129,11 @@ public: const std::chrono::system_clock::time_point &now, int32_t time = 1); static int64_t GetCurrentTime(); + + static void ReportOperationsDotEvent(const HaMetaMessage& message); + + static void ReportPublishFailedEvent(const HaMetaMessage& message); + private: static void ReportNotificationEvent(const sptr& request, EventFwk::Want want, int32_t eventCode, const std::string& reason); @@ -139,6 +165,8 @@ private: static void ExecuteCacheList(); static void ReportCommonEvent(const ReportCache& reportCache); + + static bool DetermineWhetherToSend(uint32_t slotType); }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/notification_extension/distributed_extension_service.h b/services/ans/include/notification_extension/distributed_extension_service.h index daef404189683396ce50032246d4b43b3535f7f0..c3efbb160b45e5c2ac82b24fc8f9abe8accf96bd 100644 --- a/services/ans/include/notification_extension/distributed_extension_service.h +++ b/services/ans/include/notification_extension/distributed_extension_service.h @@ -71,12 +71,16 @@ public: void OnDeviceOffline(const DmDeviceInfo &deviceInfo); void OnDeviceChanged(const DmDeviceInfo &deviceInfo); static DistributedExtensionService& GetInstance(); + void HADotCallback(int32_t code, int32_t ErrCode, uint32_t branchId, std::string reason); + void SendReportCallback(int32_t messageType, int32_t errCode, std::string reason); private: DistributedExtensionService(); ~DistributedExtensionService() = default; bool CheckAllDeviceOffLine(); bool releaseSameDevice(const DmDeviceInfo &deviceInfo); void SetMaxContentLength(nlohmann::json &configJson); + std::string AnonymousProcessing(std::string data); + std::mutex mapLock_; std::atomic dansRunning_ = false; std::shared_ptr distributedQueue_ = nullptr; diff --git a/services/ans/include/notification_subscriber_manager.h b/services/ans/include/notification_subscriber_manager.h index 0410e633e559d0c0475a9652c13f97bbb81442ad..7124b744ef0feaf1f10875106cd60953dc387484 100644 --- a/services/ans/include/notification_subscriber_manager.h +++ b/services/ans/include/notification_subscriber_manager.h @@ -135,6 +135,12 @@ public: std::list> GetSubscriberRecords(); + void IsDeviceFlag(const std::shared_ptr &record, const sptr ¬ification, + bool &wearableFlag, bool &headsetFlag, bool &keyNodeFlag); + + void TrackCodeLog(const sptr ¬ification, const bool &wearableFlag, const bool &headsetFlag, + const bool &keyNodeFlag); + #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED bool GetIsEnableEffectedRemind(); bool IsDeviceTypeSubscriberd(const std::string deviceType); diff --git a/services/ans/src/common/notification_analytics_util.cpp b/services/ans/src/common/notification_analytics_util.cpp index 333d12cea5fd46c185e971677d574c184d35e0e2..93c2f73472fe220b5e9cf0efbda666d17322ebf9 100644 --- a/services/ans/src/common/notification_analytics_util.cpp +++ b/services/ans/src/common/notification_analytics_util.cpp @@ -33,6 +33,7 @@ constexpr char MESSAGE_DELIMITER = '#'; constexpr const int32_t PUBLISH_ERROR_EVENT_CODE = 0; constexpr const int32_t DELETE_ERROR_EVENT_CODE = 5; constexpr const int32_t MODIFY_ERROR_EVENT_CODE = 6; +constexpr const int32_t ANS_CUSTOMIZE_CODE = 7; constexpr const int32_t DEFAULT_ERROR_EVENT_COUNT = 5; constexpr const int32_t DEFAULT_ERROR_EVENT_TIME = 60; @@ -42,14 +43,27 @@ constexpr const int32_t MODIFY_ERROR_EVENT_TIME = 60; constexpr const int32_t REPORT_CACHE_MAX_SIZE = 50; constexpr const int32_t REPORT_CACHE_INTERVAL_TIME = 30; constexpr const int32_t REASON_MAX_LENGTH = 127; +constexpr const int32_t SUB_CODE = 100; const static std::string NOTIFICATION_EVENT_PUSH_AGENT = "notification.event.PUSH_AGENT"; static std::mutex reportFlowControlMutex_; static std::map> flowControlTimestampMap_ = { {MODIFY_ERROR_EVENT_CODE, {}}, {PUBLISH_ERROR_EVENT_CODE, {}}, {DELETE_ERROR_EVENT_CODE, {}}, + {ANS_CUSTOMIZE_CODE, {}}, }; +int32_t HaMetaMessage::syncWatch_ = 0; +int32_t HaMetaMessage::syncHeadSet_ = 0; +int32_t HaMetaMessage::syncWatchHeadSet_ = 0; +int32_t HaMetaMessage::keyNode_ = 0; +int64_t HaMetaMessage::time_ = NotificationAnalyticsUtil::GetCurrentTime(); +int32_t HaMetaMessage::syncLiveViewWatch_ = 0; +int32_t HaMetaMessage::syncLiveViewHeadSet_ = 0; +int32_t HaMetaMessage::syncLiveViewWatchHeadSet_ = 0; +int64_t HaMetaMessage::liveViewTime_ = NotificationAnalyticsUtil::GetCurrentTime(); +int32_t HaMetaMessage::delByWatch_ = 0; +int32_t HaMetaMessage::liveViewDelByWatch_ = 0; static std::mutex reportCacheMutex_; static uint64_t reportTimerId = 0; static std::list reportCacheList; @@ -142,6 +156,61 @@ HaMetaMessage& HaMetaMessage::SlotType(int32_t slotType) return *this; } +HaMetaMessage& HaMetaMessage::deleteReason(int32_t deleteReason) +{ + deleteReason_ = deleteReason; + return *this; +} + +HaMetaMessage& HaMetaMessage::syncWatch(bool isLiveView) +{ + if (isLiveView) { + HaMetaMessage::syncLiveViewWatch_++; + } else { + HaMetaMessage::syncWatch_++; + } + return *this; + +} + +HaMetaMessage& HaMetaMessage::syncHeadSet(bool isLiveView) +{ + if (isLiveView) { + HaMetaMessage::syncLiveViewHeadSet_++; + } else { + HaMetaMessage::syncHeadSet_++; + } + return *this; +} + +HaMetaMessage& HaMetaMessage::syncWatchHeadSet(bool isLiveView) +{ + if (isLiveView) { + HaMetaMessage::syncLiveViewWatchHeadSet_++; + } else { + HaMetaMessage::syncWatchHeadSet_++; + } + return *this; +} + +HaMetaMessage& HaMetaMessage::keyNode(bool isKeyNode) +{ + if (isKeyNode) { + HaMetaMessage::keyNode_++; + } + return *this; +} + +HaMetaMessage& HaMetaMessage::delByWatch(bool isLiveView) +{ + if (isLiveView) { + HaMetaMessage::liveViewDelByWatch_++; + } else { + HaMetaMessage::delByWatch_++; + } + return *this; +} + std::string HaMetaMessage::Build() const { return std::to_string(sceneId_) + MESSAGE_DELIMITER + @@ -256,6 +325,7 @@ void NotificationAnalyticsUtil::ReportDeleteFailedEvent(const HaMetaMessage& mes want.SetParam("agentBundleName", message.agentBundleName_); want.SetParam("typeCode", message.typeCode_); want.SetParam("id", message.notificationId_); + want.SetParam("deleteReason", message.deleteReason_); IN_PROCESS_CALL_WITHOUT_RET(AddListCache(want, DELETE_ERROR_EVENT_CODE)); } @@ -539,5 +609,84 @@ int64_t NotificationAnalyticsUtil::GetCurrentTime() auto duration = std::chrono::duration_cast(now.time_since_epoch()); return duration.count(); } + +void NotificationAnalyticsUtil::ReportOperationsDotEvent(const HaMetaMessage& message) +{ + if (!ReportFlowControl(ANS_CUSTOMIZE_CODE)) { + ANS_LOGI("Publish event failed, reason:%{public}s", message.Build().c_str()); + return; + } + EventFwk::Want want; + std::string extraInfo = NotificationAnalyticsUtil::BuildExtraInfo(message); + NotificationAnalyticsUtil::SetCommonWant(want, message, extraInfo); + if (!NotificationAnalyticsUtil::DetermineWhetherToSend(message.slotType_)) { + return; + } + want.SetParam("slotType", static_cast(message.slotType_)); + want.SetParam("subCode", SUB_CODE); + if (message.slotType_ == NotificationConstant::SlotType::LIVE_VIEW) { + want.SetParam("syncWatch", HaMetaMessage::syncLiveViewWatch_); + want.SetParam("syncHeadSet", HaMetaMessage::syncLiveViewHeadSet_); + want.SetParam("syncWatchHeadSet", HaMetaMessage::syncLiveViewWatchHeadSet_); + want.SetParam("keyNode", HaMetaMessage::keyNode_); + want.SetParam("delByWatch", HaMetaMessage::liveViewDelByWatch_); + HaMetaMessage::syncLiveViewWatch_ = 0; + HaMetaMessage::syncLiveViewHeadSet_ = 0; + HaMetaMessage::syncLiveViewWatchHeadSet_ = 0; + HaMetaMessage::keyNode_ = 0; + HaMetaMessage::liveViewDelByWatch_ = 0; + HaMetaMessage::liveViewTime_ = NotificationAnalyticsUtil::GetCurrentTime(); + } else { + want.SetParam("syncWatch", HaMetaMessage::syncWatch_); + want.SetParam("syncHeadSet", HaMetaMessage::syncHeadSet_); + want.SetParam("syncWatchHeadSet", HaMetaMessage::syncWatchHeadSet_); + want.SetParam("delByWatch", HaMetaMessage::delByWatch_); + HaMetaMessage::syncWatch_ = 0; + HaMetaMessage::syncHeadSet_ = 0; + HaMetaMessage::syncWatchHeadSet_ = 0; + HaMetaMessage::delByWatch_ = 0; + HaMetaMessage::time_ = NotificationAnalyticsUtil::GetCurrentTime(); + } + IN_PROCESS_CALL_WITHOUT_RET(AddListCache(want, ANS_CUSTOMIZE_CODE)); +} + +void NotificationAnalyticsUtil::ReportPublishFailedEvent(const HaMetaMessage& message) +{ + if (!ReportFlowControl(PUBLISH_ERROR_EVENT_CODE)) { + ANS_LOGI("Publish event failed, reason:%{public}s", message.Build().c_str()); + return; + } + EventFwk::Want want; + std::string extraInfo = NotificationAnalyticsUtil::BuildExtraInfo(message); + NotificationAnalyticsUtil::SetCommonWant(want, message, extraInfo); + + want.SetParam("typeCode", message.typeCode_); + + IN_PROCESS_CALL_WITHOUT_RET(AddListCache(want, PUBLISH_ERROR_EVENT_CODE)); +} + +bool NotificationAnalyticsUtil::DetermineWhetherToSend(uint32_t slotType) +{ + if (HaMetaMessage::keyNode_ != 0){ + return true; + } + if (slotType == NotificationConstant::SlotType::LIVE_VIEW) { + if ((NotificationAnalyticsUtil::GetCurrentTime() - HaMetaMessage::liveViewTime_) >= MAX_TIME) { + return true; + } else if (HaMetaMessage::syncLiveViewWatch_ + HaMetaMessage::syncLiveViewHeadSet_ + + HaMetaMessage::syncLiveViewWatchHeadSet_ + HaMetaMessage::liveViewDelByWatch_ >= 100) { + return true; + } + } else { + if ((NotificationAnalyticsUtil::GetCurrentTime() - HaMetaMessage::time_) >= MAX_TIME) { + return true; + } else if (HaMetaMessage::syncWatch_ + HaMetaMessage::syncHeadSet_ + + HaMetaMessage::syncWatchHeadSet_ + HaMetaMessage::delByWatch_ >= 100) { + return true; + } + } + return false; +} + } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/event_report.cpp b/services/ans/src/event_report.cpp index 8ab68a88f1ab20e84a0417eb44669dc23d970881..fc07710339a52764fd3117d2302cffdc1e61dfe0 100644 --- a/services/ans/src/event_report.cpp +++ b/services/ans/src/event_report.cpp @@ -31,6 +31,8 @@ const std::string EVENT_PARAM_NOTIFICATION_ID = "NOTIFICATION_ID"; const std::string EVENT_PARAM_NOTIFICATION_LABEL = "NOTIFICATION_LABEL"; const std::string EVENT_PARAM_CONTENT_TYPE = "CONTENT_TYPE"; const std::string EVENT_PARAM_OPERATE_FLAG = "OPERATE_FLAG"; +const std::string EVENT_MESSAGE_TYPE = "MESSAGE_TYPE"; +const std::string EVENT_REASON = "REASON"; } // namespace void EventReport::SendHiSysEvent(const std::string &eventName, const EventInfo &eventInfo) @@ -61,6 +63,9 @@ std::unordered_map EventRepor {PUBLISH_ERROR, [](const EventInfo& eventInfo) { InnerSendPublishErrorEvent(eventInfo); }}, + {EVENT_NOTIFICATION_ERROR, [](const EventInfo& eventInfo) { + InnerSendNotificationSystemErrorEvent(eventInfo); + }}, {FLOW_CONTROL_OCCUR, [](const EventInfo& eventInfo) { InnerSendFlowControlOccurEvent(eventInfo); }}, @@ -147,6 +152,16 @@ void EventReport::InnerSendFlowControlOccurEvent(const EventInfo &eventInfo) EVENT_PARAM_UID, eventInfo.uid); } +void EventReport::InnerSendNotificationSystemErrorEvent(const EventInfo &eventInfo) +{ + InnerEventWrite( + EVENT_NOTIFICATION_ERROR, + HiviewDFX::HiSysEvent::EventType::FAULT, + EVENT_MESSAGE_TYPE, eventInfo.messageType, + EVENT_PARAM_ERROR_CODE, eventInfo.errCode, + EVENT_REASON, eventInfo.reason); +} + void EventReport::InnerSendSubscribeEvent(const EventInfo &eventInfo) { InnerEventWrite( diff --git a/services/ans/src/notification_extension/distributed_extension_service.cpp b/services/ans/src/notification_extension/distributed_extension_service.cpp index 3eadb531c8f1e5eaea3bde1ffd71e9564a2d3ca6..c26c43de2aa5756a5d9ad0d9298cce6a97e3afe5 100644 --- a/services/ans/src/notification_extension/distributed_extension_service.cpp +++ b/services/ans/src/notification_extension/distributed_extension_service.cpp @@ -16,6 +16,8 @@ #include "distributed_extension_service.h" #include "ans_log_wrapper.h" +#include "event_report.h" +#include "notification_analytics_util.h" #include @@ -34,6 +36,10 @@ typedef void (*ADD_DEVICE)(const std::string &deviceId, uint16_t deviceType, typedef void (*RELEASE_DEVICE)(const std::string &deviceId, uint16_t deviceType); typedef void (*REFRESH_DEVICE)(const std::string &deviceId, uint16_t deviceType, const std::string &networkId); +typedef void (*INIT_HA_CALLBACK)( + std::function callback); +typedef void (*INIT_SENDREPORT_CALLBACK)( + std::function callback); namespace { constexpr int32_t DEFAULT_TITLE_LENGTH = 200; @@ -45,6 +51,9 @@ constexpr const char* CFG_KEY_LOCAL_TYPE = "localType"; constexpr const char* CFG_KEY_SUPPORT_DEVICES = "supportPeerDevice"; constexpr const char* CFG_KEY_TITLE_LENGTH = "maxTitleLength"; constexpr const char* CFG_KEY_CONTENT_LENGTH = "maxContentLength"; +constexpr const int32_t PUBLISH_ERROR_EVENT_CODE = 0; +constexpr const int32_t DELETE_ERROR_EVENT_CODE = 5; +constexpr const int32_t ANS_CUSTOMIZE_CODE = 7; } std::string TransDeviceTypeToName(uint16_t deviceType_) @@ -169,6 +178,20 @@ int32_t DistributedExtensionService::InitDans() dansRunning_.store(false); return -1; } + + INIT_HA_CALLBACK haHandler = (INIT_HA_CALLBACK)dansHandler_->GetProxyFunc("InitHACallBack"); + if (haHandler != nullptr) { + haHandler(std::bind(&DistributedExtensionService::HADotCallback, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); + } + + INIT_SENDREPORT_CALLBACK sendHandler = + (INIT_SENDREPORT_CALLBACK)dansHandler_->GetProxyFunc("InitSendReportCallBack"); + if (sendHandler != nullptr) { + sendHandler(std::bind(&DistributedExtensionService::SendReportCallback, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3)); + } + dansRunning_.store(true); return 0; } @@ -211,6 +234,10 @@ void DistributedExtensionService::OnDeviceOnline(const DmDeviceInfo &deviceInfo) } std::lock_guard lock(mapLock_); handler(deviceInfo.deviceId, deviceInfo.deviceTypeId, deviceInfo.networkId); + std::string reason = "deviceType: " + std::to_string(deviceInfo.deviceTypeId) + + "deviceId: " + AnonymousProcessing(deviceInfo.deviceId) + "networkId: " + + AnonymousProcessing(deviceInfo.networkId); + HADotCallback(PUBLISH_ERROR_EVENT_CODE, 0, EventSceneId::SCENE_1, reason); DistributedDeviceInfo device = DistributedDeviceInfo(deviceInfo.deviceId, deviceInfo.deviceName, deviceInfo.networkId, deviceInfo.deviceTypeId); deviceMap_.insert(std::make_pair(deviceInfo.deviceId, device)); @@ -258,6 +285,48 @@ bool DistributedExtensionService::DeviceStatusCallback(std::string deviceId, int return release; } +void DistributedExtensionService::HADotCallback(int32_t code, int32_t ErrCode, uint32_t branchId, std::string reason) +{ + ANS_LOGI("Dans ha callback %{public}d, %{public}d, %{public}s.", code, ErrCode, reason.c_str()); + if (code == PUBLISH_ERROR_EVENT_CODE) { + if (reason.find("deviceType") != std::string::npos || + reason.find("ShutdownReason") != std::string::npos) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_21, branchId).Message(reason); + NotificationAnalyticsUtil::ReportPublishFailedEvent(message); + } else { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_20, branchId) + .ErrorCode(ErrCode) + .Message(reason); + NotificationAnalyticsUtil::ReportPublishFailedEvent(message); + } + } else if (code == DELETE_ERROR_EVENT_CODE) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_20, branchId) + .deleteReason(NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE) + .ErrorCode(ErrCode) + .Message(reason); + NotificationAnalyticsUtil::ReportDeleteFailedEvent(message); + } else if (code == ANS_CUSTOMIZE_CODE) { + bool isLiveView = false; + if (ErrCode == NotificationConstant::SlotType::LIVE_VIEW) { + isLiveView = true; + } + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, branchId) + .delByWatch(isLiveView) + .SlotType(ErrCode); + NotificationAnalyticsUtil::ReportOperationsDotEvent(message); + } +} + +void DistributedExtensionService::SendReportCallback( + int32_t messageType, int32_t errCode, std::string reason) +{ + EventInfo eventInfo; + eventInfo.messageType = messageType; + eventInfo.errCode = errCode; + eventInfo.reason = reason; + EventReport::SendHiSysEvent(EVENT_NOTIFICATION_ERROR, eventInfo); +} + void DistributedExtensionService::OnDeviceOffline(const DmDeviceInfo &deviceInfo) { if (distributedQueue_ == nullptr) { @@ -279,6 +348,9 @@ void DistributedExtensionService::OnDeviceOffline(const DmDeviceInfo &deviceInfo return; } handler(deviceInfo.deviceId, deviceInfo.deviceTypeId); + std::string reason = "deviceType: " + std::to_string(deviceInfo.deviceTypeId) + + "deviceId: " + AnonymousProcessing(deviceInfo.deviceId); + HADotCallback(PUBLISH_ERROR_EVENT_CODE, 0, EventSceneId::SCENE_2, reason); deviceMap_.erase(deviceInfo.deviceId); }); distributedQueue_->submit(offlineTask); @@ -320,5 +392,18 @@ void DistributedExtensionService::SetMaxContentLength(nlohmann::json &configJson ANS_LOGI("Dans initConfig content length %{public}d.", deviceConfig_.maxContentLength); } } + +std::string DistributedExtensionService::AnonymousProcessing(std::string data) +{ + if (!data.empty()) { + int length = data.length(); + int count = length / 3; + for (int i = 0; i < count; i++) { + data[i] = '*'; + data[length - i - 1] = '*'; + } + } + return data; +} } } diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 29ac99bc54a13ecc541c658e1d3a546e59a8149f..65703dbb0e91d2036adfa69f24110519b790e41b 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -34,6 +34,7 @@ #include "notification_analytics_util.h" #include "advanced_notification_inline.cpp" +#include "liveview_all_scenarios_extension_wrapper.h" namespace OHOS { namespace Notification { @@ -473,6 +474,9 @@ void NotificationSubscriberManager::NotifyConsumedInner( HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("%{public}s notification->GetUserId <%{public}d>", __FUNCTION__, notification->GetUserId()); + bool wearableFlag = false; + bool headsetFlag = false; + bool keyNodeFlag = false; for (auto record : subscriberRecordList_) { ANS_LOGD("%{public}s record->userId = <%{public}d> BundleName = <%{public}s deviceType = %{public}s", __FUNCTION__, record->userId, notification->GetBundleName().c_str(), record->deviceType.c_str()); @@ -489,11 +493,15 @@ void NotificationSubscriberManager::NotifyConsumedInner( continue; } record->subscriber->OnConsumed(notificationStub, notificationMap); + NotificationSubscriberManager::IsDeviceFlag( + record, notification, wearableFlag, headsetFlag, keyNodeFlag); continue; } record->subscriber->OnConsumed(notification, notificationMap); + NotificationSubscriberManager::IsDeviceFlag(record, notification, wearableFlag, headsetFlag, keyNodeFlag); } } + NotificationSubscriberManager::TrackCodeLog(notification, wearableFlag, headsetFlag, keyNodeFlag); } #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED @@ -536,8 +544,16 @@ void NotificationSubscriberManager::BatchNotifyConsumedInner(const std::vectorsubscriber != nullptr) { + NotificationSubscriberManager::IsDeviceFlag( + record, notification, wearableFlag, headsetFlag, keyNodeFlag); + NotificationSubscriberManager::TrackCodeLog(notification, wearableFlag, headsetFlag, keyNodeFlag); + } } } if (!currNotifications.empty()) { @@ -770,5 +786,84 @@ std::list NotificationSubscriberManager::GetSubscriberRecor return subscriberRecordList_; } +void NotificationSubscriberManager::IsDeviceFlag(const std::shared_ptr &record, + const sptr ¬ification, bool &wearableFlag, bool &headsetFlag, bool &keyNodeFlag) +{ + if (record == nullptr || notification == nullptr) { + ANS_LOGE("record or notification is nullptr."); + return; + } + sptr request = notification->GetNotificationRequestPoint(); + if (request == nullptr) { + ANS_LOGE("request is nullptr."); + return; + } + auto flagsMap = request->GetDeviceFlags(); + if (flagsMap == nullptr || flagsMap->size() <= 0) { + return; + } + + if (record->deviceType == DEVICE_TYPE_LITE_WEARABLE) { + auto flagIter = flagsMap->find(DEVICE_TYPE_LITE_WEARABLE); + if (flagIter != flagsMap->end() && flagIter->second != nullptr) { + wearableFlag = true; + } + } else if (record->deviceType == DEVICE_TYPE_WEARABLE) { + auto flagIter = flagsMap->find(DEVICE_TYPE_WEARABLE); + if (flagIter != flagsMap->end() && flagIter->second != nullptr) { + wearableFlag = true; + } + } else if (record->deviceType == DEVICE_TYPE_HEADSET) { + auto flagIter = flagsMap->find(DEVICE_TYPE_HEADSET); + if (flagIter != flagsMap->end() && flagIter->second != nullptr) { + headsetFlag = true; + } + } + if (request->GetSlotType() == NotificationConstant::SlotType::LIVE_VIEW) { + LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewReminderFlags(request); + auto flags = request->GetFlags(); + if (flags->IsVibrationEnabled() == NotificationConstant::FlagStatus::OPEN && + flags->IsSoundEnabled() == NotificationConstant::FlagStatus::OPEN) { + keyNodeFlag = true; + } + } +} + +void NotificationSubscriberManager::TrackCodeLog( + const sptr ¬ification, const bool &wearableFlag, const bool &headsetFlag, const bool &keyNodeFlag) +{ + if (notification == nullptr) { + ANS_LOGE("notification is empty."); + return; + } + sptr request = notification->GetNotificationRequestPoint(); + if (request == nullptr) { + ANS_LOGE("request is nullptr."); + return; + } + auto slotType = request->GetSlotType(); + bool isLiveViewType = (slotType == NotificationConstant::SlotType::LIVE_VIEW); + if (wearableFlag && headsetFlag) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, EventBranchId::BRANCH_1) + .syncWatchHeadSet(isLiveViewType ? true : false) + .keyNode(keyNodeFlag) + .SlotType(slotType); + NotificationAnalyticsUtil::ReportOperationsDotEvent(message); + } else { + if (headsetFlag) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, EventBranchId::BRANCH_1) + .syncHeadSet(isLiveViewType ? true : false) + .keyNode(keyNodeFlag) + .SlotType(slotType); + NotificationAnalyticsUtil::ReportOperationsDotEvent(message); + } else if (wearableFlag) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, EventBranchId::BRANCH_1) + .syncWatch(isLiveViewType ? true : false) + .keyNode(keyNodeFlag) + .SlotType(slotType); + NotificationAnalyticsUtil::ReportOperationsDotEvent(message); + } + } +} } // namespace Notification } // namespace OHOS diff --git a/services/distributed/include/soft_bus/distributed_client.h b/services/distributed/include/soft_bus/distributed_client.h index 662cce1adb3df9eb08ff882f78a4927a0f1ccb8e..22d6a2674c656072bc60eb254e6d58a925a62ccd 100644 --- a/services/distributed/include/soft_bus/distributed_client.h +++ b/services/distributed/include/soft_bus/distributed_client.h @@ -41,6 +41,7 @@ private: DistributedClient() = default; ~DistributedClient() = default; + std::string ShutdownReasonToString(ShutdownReason reason); std::mutex clientLock_; DistributedDeviceInfo localDevice_; std::map socketsId_; diff --git a/services/distributed/include/soft_bus/distributed_manager.h b/services/distributed/include/soft_bus/distributed_manager.h index 12d6e6489b8ae87339a4d32d18b47761796cfeb3..96d45b89a2499b2fe54af108d7fbdb0eaeb07270 100644 --- a/services/distributed/include/soft_bus/distributed_manager.h +++ b/services/distributed/include/soft_bus/distributed_manager.h @@ -37,6 +37,8 @@ public: void ReleaseDevice(const std::string &deviceId, uint16_t deviceType); void RefreshDevice(const std::string &deviceId, uint16_t deviceType, const std::string &networkId); + void InitHACallBack(std::function callback); + void InitSendReportCallBack(std::function callback); }; } } diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index 7fb64bd2008e4bce1716edee152b4ae1004ed36b..051c0f19817c5d06b67890a460fc8c92da7e5288 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -61,7 +61,12 @@ 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); + void SendEventReport(int32_t messageType, int32_t errCode, std::string& errorReason); + void InitHACallBack(std::function callback); + void InitSendReportCallBack(std::function callback); std::unordered_set GetCollaborativeDeleteTypes(); + int32_t code_ = -1; + std::function haCallback_ = nullptr; private: int64_t GetCurrentTime(); @@ -85,7 +90,11 @@ private: NotificationContent::Type type, NotifticationRequestBox &requestBox); void GetNeedUpdateDevice(bool updatedExit, const std::string& bundleName, std::vector& updateDeviceList); + void AbnormalReporting(int result, uint32_t branchId, const std::string& errorReason); + void OperationalReporting(int branchId, int32_t slotType); + std::string AnonymousProcessing(std::string data); std::function callBack_ = nullptr; + std::function sendReportCallback_ = nullptr; std::map> bundleIconCache_; int32_t userId_ = DEFAULT_USER_ID; 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 e0f35ef86fa149dc6295a77c0868bd30b94019b6..54fc1dc37ba3c80f601c6b1103ddaf18f8611210 100644 --- a/services/distributed/include/tlv_box/batch_remove_box.h +++ b/services/distributed/include/tlv_box/batch_remove_box.h @@ -29,6 +29,7 @@ public: ~BatchRemoveNotificationBox(); BatchRemoveNotificationBox(std::shared_ptr box); bool SetNotificationHashCode(const std::string& hashCode); + bool SetNotificationSlotTypes(const std::string &slotTypes); }; } // 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 f8db324a78abff06328fd5d264d30de5201db37d..d34c0342906a756f6882cd9448cc02d6a659be22 100644 --- a/services/distributed/include/tlv_box/remove_box.h +++ b/services/distributed/include/tlv_box/remove_box.h @@ -28,6 +28,7 @@ public: ~NotificationRemoveBox(); NotificationRemoveBox(std::shared_ptr box); bool SetNotificationHashCode(const std::string& hashCode); + bool setNotificationSlotType(int32_t slotType); }; } // 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 c361ad9cb9e485fc793a41bb0cafb9bcb612252e..0815a7898765c6b2b3b7c60cfa967366819d1641 100644 --- a/services/distributed/include/tlv_box/tlv_box.h +++ b/services/distributed/include/tlv_box/tlv_box.h @@ -48,6 +48,7 @@ enum TlvType : int32_t { NOTIFICATION_OVERLAY_ICON = 9, NOTIFICATION_CONTENT_TYPE = 10, NOTIFICATION_COMMON_LIVEVIEW = 11, + BATCH_REMOVE_SLOT_TYPE = 14, BUNDLE_ICON_SYNC_TYPE = 992, MATCH_TYPE = 993, PEER_DEVICE_ID = 994, diff --git a/services/distributed/src/soft_bus/distributed_client.cpp b/services/distributed/src/soft_bus/distributed_client.cpp index 262f711ed0c81df1bb4af87edcdc1a4ce7436ba2..7e48936ce133e98a3eb0434a48141033578bbed8 100644 --- a/services/distributed/src/soft_bus/distributed_client.cpp +++ b/services/distributed/src/soft_bus/distributed_client.cpp @@ -21,6 +21,13 @@ namespace OHOS { namespace Notification { +namespace { +constexpr const int32_t PUBLISH_ERROR_EVENT_CODE = 0; +constexpr const int32_t BRANCH1_ID = 1; +constexpr const int32_t BRANCH2_ID = 2; +constexpr const int32_t BRANCH4_ID = 4; +} + DistributedClient& DistributedClient::GetInstance() { static DistributedClient distributedClient; @@ -33,6 +40,11 @@ void DistributedClient::OnShutdown(int32_t socket, ShutdownReason reason) for (auto& socketItem : socketsId_) { if (socketItem.second == socket) { socketItem.second = -1; + if (DistributedService::GetInstance().haCallback_ != nullptr) { + std::string message = "socketID: " + std::to_string(socket) + "ShutdownReason: " + + ShutdownReasonToString(reason); + DistributedService::GetInstance().haCallback_(PUBLISH_ERROR_EVENT_CODE, 0, BRANCH4_ID, message); + } } } } @@ -115,10 +127,56 @@ int32_t DistributedClient::SendMessage(const void* data, int32_t length, TransDa int32_t result = GetSocketId(deviceId, deviceType, dataType, socketId); if (result != ERR_OK) { ANS_LOGW("Get SocketId failed %{public}s %{public}d %{public}d", deviceId.c_str(), deviceType, dataType); + int32_t messageType = 0; + std::string errorReason = "Bind server failed,"; + errorReason.append("dataType: " + std::to_string(dataType)); + DistributedService::GetInstance().SendEventReport(messageType, result, errorReason); + if (DistributedService::GetInstance().haCallback_ != nullptr) { + int32_t code = DistributedService::GetInstance().code_; + DistributedService::GetInstance().haCallback_(code, result, BRANCH1_ID, errorReason); + } return result; } - return ClientSendMsg(socketId, data, length, dataType); + result = ClientSendMsg(socketId, data, length, dataType); + if (result != ERR_OK) { + int32_t messageType = 0; + std::string errorReason = "send message failed,"; + errorReason.append("dataType: " + std::to_string(dataType)); + DistributedService::GetInstance().SendEventReport(messageType, result, errorReason); + if (DistributedService::GetInstance().haCallback_ != nullptr) { + int32_t code = DistributedService::GetInstance().code_; + DistributedService::GetInstance().haCallback_(code, result, BRANCH2_ID, errorReason); + } + } + return result; } + +std::string DistributedClient::ShutdownReasonToString(ShutdownReason reason) +{ + switch (reason) { + case ShutdownReason::SHUTDOWN_REASON_UNKNOWN: + return "SHUTDOWN_REASON_UNKNOWN"; + case ShutdownReason::SHUTDOWN_REASON_PEER: + return "SHUTDOWN_REASON_PEER"; + case ShutdownReason::SHUTDOWN_REASON_LNN_CHANGED: + return "SHUTDOWN_REASON_LNN_CHANGED"; + case ShutdownReason::SHUTDOWN_REASON_CONN_CHANGED: + return "SHUTDOWN_REASON_CONN_CHANGED"; + case ShutdownReason::SHUTDOWN_REASON_TIMEOUT: + return "SHUTDOWN_REASON_TIMEOUT"; + case ShutdownReason::SHUTDOWN_REASON_SEND_FILE_ERR: + return "SHUTDOWN_REASON_SEND_FILE_ERR"; + case ShutdownReason::SHUTDOWN_REASON_RECV_FILE_ERR: + return "SHUTDOWN_REASON_RECV_FILE_ERR"; + case ShutdownReason::SHUTDOWN_REASON_RECV_DATA_ERR: + return "SHUTDOWN_REASON_RECV_DATA_ERR"; + case ShutdownReason::SHUTDOWN_REASON_UNEXPECTED: + return "SHUTDOWN_REASON_UNEXPECTED"; + default: + return "unknown"; + } +} + } } diff --git a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp index b32cc81000090f96239f48985f607cc4c50f00a6..22a23d1702fabf2340b477bdab043ba94bf68353 100644 --- a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp +++ b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp @@ -56,6 +56,18 @@ SYMBOL_EXPORT void ReleaseLocalDevice() DistributedManager::GetInstance().ReleaseLocalDevice(); } +SYMBOL_EXPORT void InitHACallBack( + std::function callback) +{ + DistributedManager::GetInstance().InitHACallBack(callback); +} + +SYMBOL_EXPORT void InitSendReportCallBack( + std::function callback) +{ + DistributedManager::GetInstance().InitSendReportCallBack(callback); +} + #ifdef __cplusplus } #endif diff --git a/services/distributed/src/soft_bus/distributed_manager.cpp b/services/distributed/src/soft_bus/distributed_manager.cpp index b75004882badcf249b0a1d00c02d0427a803009a..4fd59e7fe95870a96a9394482f3a9902f6b33881 100644 --- a/services/distributed/src/soft_bus/distributed_manager.cpp +++ b/services/distributed/src/soft_bus/distributed_manager.cpp @@ -76,5 +76,15 @@ void DistributedManager::RefreshDevice(const std::string &deviceId, uint16_t dev DistributedClient::GetInstance().RefreshDevice(deviceId, deviceType, networkId); } +void DistributedManager::InitHACallBack(std::function callback) +{ + DistributedService::GetInstance().InitHACallBack(callback); +} + +void DistributedManager::InitSendReportCallBack(std::function callback) +{ + DistributedService::GetInstance().InitSendReportCallBack(callback); +} + } } diff --git a/services/distributed/src/soft_bus/distributed_publish_service.cpp b/services/distributed/src/soft_bus/distributed_publish_service.cpp index f704b8a3d187428103786cc8bc157e243fba6af9..c3efcc0c81373bc926c30b896a67a450ef4e5476 100644 --- a/services/distributed/src/soft_bus/distributed_publish_service.cpp +++ b/services/distributed/src/soft_bus/distributed_publish_service.cpp @@ -31,6 +31,10 @@ namespace Notification { namespace { constexpr char const DISTRIBUTED_LABEL[] = "ans_distributed"; +constexpr const int32_t ANS_CUSTOMIZE_CODE = 7; +constexpr const int32_t OPERATION_DELETE_BRANCH = 2; +constexpr const int32_t BRANCH3_ID = 3; +constexpr const int32_t BRANCH4_ID = 4; } void DistributedService::SetNotifictaionContent(const NotifticationRequestBox& box, sptr& request, @@ -187,13 +191,24 @@ void DistributedService::PublishNotifictaion(const std::shared_ptr& boxM void DistributedService::RemoveNotification(const std::shared_ptr& boxMessage) { std::string hashCode; + int32_t slotType; if (boxMessage == nullptr) { ANS_LOGE("boxMessage is nullptr"); return; } boxMessage->GetStringValue(NOTIFICATION_HASHCODE, hashCode); + boxMessage->GetInt32Value(NOTIFICATION_SLOT_TYPE, slotType); + int result = IN_PROCESS_CALL(NotificationHelper::RemoveNotification( hashCode, NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE)); + std::string errorReason = "delete message failed"; + if (result == 0) { + errorReason = "delete message success"; + AbnormalReporting(result, BRANCH4_ID, errorReason); + OperationalReporting(OPERATION_DELETE_BRANCH, slotType); + } else { + AbnormalReporting(result, BRANCH3_ID, errorReason); + } ANS_LOGI("dans remove message %{public}d.", result); } @@ -220,6 +235,46 @@ void DistributedService::RemoveNotifications(const std::shared_ptr& boxM int result = IN_PROCESS_CALL( NotificationHelper::RemoveNotifications(hashCodes, NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE)); ANS_LOGI("dans batch remove message %{public}d.", result); + std::string errorReason = "delete message failed"; + if (result == 0) { + errorReason = "delete message success"; + AbnormalReporting(result, BRANCH4_ID, errorReason); + std::string slotTypesString; + if (!boxMessage->GetStringValue(BATCH_REMOVE_SLOT_TYPE, slotTypesString)) { + ANS_LOGE("failed GetStringValue from boxMessage"); + return; + } + std::istringstream slotTypesStream(slotTypesString); + std::string slotTypeString; + while (slotTypesStream >> slotTypeString) { + if (!slotTypeString.empty()) { + OperationalReporting(OPERATION_DELETE_BRANCH, std::stoi(slotTypeString)); + } + } + } else { + AbnormalReporting(result, BRANCH3_ID, errorReason); + } +} + +void DistributedService::AbnormalReporting(int result, uint32_t branchId, const std::string &errorReason) +{ + if (result != 0) { + SendEventReport(0, result, errorReason); + } + if (haCallback_ == nullptr) { + return; + } + haCallback_(code_, result, branchId, errorReason); +} + +void DistributedService::OperationalReporting(int branchId, int32_t slotType) +{ + if (haCallback_ == nullptr || + localDevice_.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE) { + return; + } + std::string reason; + haCallback_(ANS_CUSTOMIZE_CODE, slotType, branchId, reason); } } } diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index 821f409af8f7d22d2fd601dc3e9de17e2031ecd9..ee52ef1c7689ddb3e84349eef3aede208e0b0c7b 100644 --- a/services/distributed/src/soft_bus/distributed_service.cpp +++ b/services/distributed/src/soft_bus/distributed_service.cpp @@ -220,6 +220,39 @@ int64_t DistributedService::GetCurrentTime() return duration.count(); } +void DistributedService::SendEventReport( + int32_t messageType, int32_t errCode, std::string& errorReason) +{ + if (sendReportCallback_ != nullptr) { + sendReportCallback_(messageType, errCode, errorReason); + } +} + +void DistributedService::InitHACallBack( + std::function callback) +{ + haCallback_ = callback; +} + +void DistributedService::InitSendReportCallBack( + std::function callback) +{ + sendReportCallback_ = callback; +} + +std::string DistributedService::AnonymousProcessing(std::string data) +{ + if (!data.empty()) { + int length = data.length(); + int count = length / 3; + for (int i = 0; i < count; i++) { + data[i] = '*'; + data[length - i - 1] = '*'; + } + } + return data; +} + std::unordered_set DistributedService::GetCollaborativeDeleteTypes() { return localDevice_.collaborativeDeleteTypes_; diff --git a/services/distributed/src/soft_bus/distributed_subscribe_service.cpp b/services/distributed/src/soft_bus/distributed_subscribe_service.cpp index dc35e9452ab6d1ba6ecb62259909f56b2da9e4a6..3068132ece0739c34a6080b14254fb0b506153b9 100644 --- a/services/distributed/src/soft_bus/distributed_subscribe_service.cpp +++ b/services/distributed/src/soft_bus/distributed_subscribe_service.cpp @@ -35,6 +35,9 @@ namespace Notification { const std::string DISTRIBUTED_LABEL = "ans_distributed"; const int32_t DEFAULT_FILTER_TYPE = 1; +constexpr const int32_t PUBLISH_ERROR_EVENT_CODE = 0; +constexpr const int32_t DELETE_ERROR_EVENT_CODE = 5; +constexpr const int32_t BRANCH3_ID = 3; std::string SubscribeTransDeviceType(uint16_t deviceType) { @@ -80,6 +83,11 @@ void DistributedService::SubscribeNotifictaion(const DistributedDeviceInfo peerD } else { callBack_(peerDevice.deviceId_, DeviceState::STATE_ONLINE, false); } + if (DistributedService::GetInstance().haCallback_ != nullptr) { + std::string reason = "deviceType: " + std::to_string(localDevice_.deviceType_) + + "deviceId: " + AnonymousProcessing(localDevice_.deviceId_); + DistributedService::GetInstance().haCallback_(PUBLISH_ERROR_EVENT_CODE, 0, BRANCH3_ID, reason); + } } ANS_LOGI("Subscribe notification %{public}s %{public}d %{public}d %{public}d.", peerDevice.deviceId_.c_str(), peerDevice.deviceType_, userId_, result); @@ -185,8 +193,13 @@ void DistributedService::OnConsumed(const std::shared_ptr &request requestPoint->GetNotificationType(), requestBox); if (!requestBox.Serialize()) { ANS_LOGW("Dans OnConsumed serialize failed."); + if(haCallback_ != nullptr) { + std::string reason = "serialization failed"; + haCallback_(PUBLISH_ERROR_EVENT_CODE, -1, BRANCH3_ID, reason); + } return; } + this->code_ = PUBLISH_ERROR_EVENT_CODE; DistributedClient::GetInstance().SendMessage(requestBox.GetByteBuffer(), requestBox.GetByteLength(), TransDataType::DATA_TYPE_BYTES, peerDevice.deviceId_, peerDevice.deviceType_); }); @@ -200,8 +213,9 @@ void DistributedService::OnBatchCanceled(const std::vectorGetNotificationRequestPoint() == nullptr) { ANS_LOGE("notification or GetNotificationRequestPoint is nullptr"); @@ -209,14 +223,17 @@ void DistributedService::OnBatchCanceled(const std::vectorDump().c_str()); keysStream << GetNotificationKey(notification) << ' '; + slotTypesStream << notification->GetNotificationRequestPoint()->GetSlotType() << ' '; } std::string notificationKeys = keysStream.str(); + std::string slotTypes = slotTypesStream.str(); - std::function task = std::bind([peerDevice, notifications, notificationKeys]() { + std::function task = std::bind([peerDevice, notifications, notificationKeys, slotTypes]() { BatchRemoveNotificationBox batchRemoveBox; if (!notificationKeys.empty()) { batchRemoveBox.SetNotificationHashCode(notificationKeys); } + batchRemoveBox.SetNotificationSlotTypes(slotTypes); if (!batchRemoveBox.Serialize()) { ANS_LOGW("dans OnCanceled serialize failed"); @@ -239,11 +256,13 @@ void DistributedService::OnCanceled(const std::shared_ptr& notific ANS_LOGE("notification or GetNotificationRequestPoint is nullptr"); return; } + code_ = DELETE_ERROR_EVENT_CODE; std::string notificationKey = GetNotificationKey(notification); std::function task = std::bind([peerDevice, notification, notificationKey]() { NotificationRemoveBox removeBox; ANS_LOGI("dans OnCanceled %{public}s", notification->Dump().c_str()); removeBox.SetNotificationHashCode(notificationKey); + removeBox.setNotificationSlotType(notification->GetNotificationRequestPoint()->GetSlotType()); 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 7743658e5452a84d4682d1f0ae15d44377ad006c..aba7d7531ea4cfe2a5338ddcca14f4d6ea356f7b 100644 --- a/services/distributed/src/tlv_box/batch_remove_box.cpp +++ b/services/distributed/src/tlv_box/batch_remove_box.cpp @@ -39,5 +39,13 @@ bool BatchRemoveNotificationBox::SetNotificationHashCode(const std::string& hash } return box_->PutValue(std::make_shared(NOTIFICATION_HASHCODE, hashCode)); } + +bool BatchRemoveNotificationBox::SetNotificationSlotTypes(const std::string &slotTypes) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(BATCH_REMOVE_SLOT_TYPE, slotTypes)); +} } } diff --git a/services/distributed/src/tlv_box/remove_box.cpp b/services/distributed/src/tlv_box/remove_box.cpp index 76a9c0a6d35e946bcb6533db85f1faae2cdf7e71..7920e2ca70365b5877de68c8152ec246c33ab7c5 100644 --- a/services/distributed/src/tlv_box/remove_box.cpp +++ b/services/distributed/src/tlv_box/remove_box.cpp @@ -40,5 +40,14 @@ bool NotificationRemoveBox::SetNotificationHashCode(const std::string& hashCode) } return box_->PutValue(std::make_shared(NOTIFICATION_HASHCODE, hashCode)); } + +bool NotificationRemoveBox::setNotificationSlotType(int32_t slotType) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(NOTIFICATION_SLOT_TYPE, slotType)); } + } +} \ No newline at end of file