From e20a8ff6e1ff924865df5d5203af786ac699a413 Mon Sep 17 00:00:00 2001 From: zhengzhuolan Date: Tue, 7 Jan 2025 15:45:38 +0800 Subject: [PATCH] add dot Signed-off-by: zhengzhuolan --- hisysevent.yaml | 6 +++++ services/ans/include/event_report.h | 5 ++++ .../ans/include/notification_analytics_util.h | 5 ++++ .../distributed_extension_service.h | 1 + .../common/notification_analytics_util.cpp | 25 ++++++++++++++++++ services/ans/src/event_report.cpp | 16 ++++++++++++ .../distributed_extension_service.cpp | 26 +++++++++++++++++++ .../include/soft_bus/distributed_manager.h | 2 ++ .../include/soft_bus/distributed_service.h | 7 +++++ .../distributed_extern_intferface.cpp | 6 +++++ .../src/soft_bus/distributed_manager.cpp | 4 +++ .../soft_bus/distributed_publish_service.cpp | 26 +++++++++++++++++++ .../src/soft_bus/distributed_service.cpp | 15 +++++++++++ .../src/soft_bus/distributed_socket.cpp | 17 ++++++++++++ .../distributed_subscribe_service.cpp | 5 ++++ 15 files changed, 166 insertions(+) diff --git a/hisysevent.yaml b/hisysevent.yaml index 7ececce79..24d83396b 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} +NOTIFICATION_SYSTEM_ERROR: + __BASE: {type: FAULT, level: MINOR, desc: enable notification system error} + DEVICE_ID: {type: STRING, desc: device id} + DEVICE_TYPE: {type: STRING, desc: device type} + ERROR_REASON: {type: STRING, desc: error reason} + 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 01c44d695..65ade30f6 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 NOTIFICATION_SYSTEM_ERROR[] = "NOTIFICATION_SYSTEM_ERROR"; constexpr char FLOW_CONTROL_OCCUR[] = "FLOW_CONTROL_OCCUR"; constexpr char SUBSCRIBE[] = "SUBSCRIBE"; @@ -55,6 +56,9 @@ struct EventInfo { std::string bundleName; std::string notificationLabel; int32_t operateFlag; + std::string deviceId; + std::string deviceType; + std::string errorReason; }; class EventReport { @@ -75,6 +79,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 c06609e15..52f027213 100644 --- a/services/ans/include/notification_analytics_util.h +++ b/services/ans/include/notification_analytics_util.h @@ -65,6 +65,7 @@ public: HaMetaMessage& TypeCode(int32_t typeCode); HaMetaMessage& NotificationId(int32_t notificationId); HaMetaMessage& SlotType(int32_t slotType); + HaMetaMessage& deleteReason(int32_t deleteReason); std::string GetMessage() const; HaMetaMessage& Checkfailed(bool checkfailed); bool NeedReport() const; @@ -81,6 +82,7 @@ public: uint32_t errorCode_ = ERR_OK; std::string message_; bool checkfailed_ = true; + int32_t deleteReason_ = 0; }; @@ -108,6 +110,9 @@ public: const std::chrono::system_clock::time_point &now, int32_t time = 1); static int64_t GetCurrentTime(); + + static void ReportPublishFailedEvent(const HaMetaMessage& message); + private: static void ReportNotificationEvent(const sptr& request, EventFwk::Want want, int32_t eventCode, const std::string& reason); diff --git a/services/ans/include/notification_extension/distributed_extension_service.h b/services/ans/include/notification_extension/distributed_extension_service.h index db1f75c04..45b949e9c 100644 --- a/services/ans/include/notification_extension/distributed_extension_service.h +++ b/services/ans/include/notification_extension/distributed_extension_service.h @@ -67,6 +67,7 @@ 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); private: DistributedExtensionService(); ~DistributedExtensionService() = default; diff --git a/services/ans/src/common/notification_analytics_util.cpp b/services/ans/src/common/notification_analytics_util.cpp index 333d12cea..6da67f5bc 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 OPERATION_MANAGEMENT_CODE = 100; constexpr const int32_t DEFAULT_ERROR_EVENT_COUNT = 5; constexpr const int32_t DEFAULT_ERROR_EVENT_TIME = 60; @@ -48,6 +49,7 @@ static std::map> flowC {MODIFY_ERROR_EVENT_CODE, {}}, {PUBLISH_ERROR_EVENT_CODE, {}}, {DELETE_ERROR_EVENT_CODE, {}}, + {OPERATION_MANAGEMENT_CODE, {}}, }; static std::mutex reportCacheMutex_; @@ -142,6 +144,12 @@ HaMetaMessage& HaMetaMessage::SlotType(int32_t slotType) return *this; } +HaMetaMessage& HaMetaMessage::deleteReason(int32_t deleteReason) +{ + deleteReason_ = deleteReason; + return *this; +} + std::string HaMetaMessage::Build() const { return std::to_string(sceneId_) + MESSAGE_DELIMITER + @@ -256,6 +264,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 +548,21 @@ int64_t NotificationAnalyticsUtil::GetCurrentTime() auto duration = std::chrono::duration_cast(now.time_since_epoch()); return duration.count(); } + +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)); +} + } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/event_report.cpp b/services/ans/src/event_report.cpp index 8ab68a88f..e8afa7acb 100644 --- a/services/ans/src/event_report.cpp +++ b/services/ans/src/event_report.cpp @@ -31,6 +31,9 @@ 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_DEVICE_Id = "DEVICE_Id"; +const std::string EVENT_DEVICE_TYPE = "DEVICE_TYPE"; +const std::string EVENT_ERROR_REASON = "ERROR_REASON"; } // namespace void EventReport::SendHiSysEvent(const std::string &eventName, const EventInfo &eventInfo) @@ -61,6 +64,9 @@ std::unordered_map EventRepor {PUBLISH_ERROR, [](const EventInfo& eventInfo) { InnerSendPublishErrorEvent(eventInfo); }}, + {NOTIFICATION_SYSTEM_ERROR, [](const EventInfo& eventInfo) { + InnerSendNotificationSystemErrorEvent(eventInfo); + }}, {FLOW_CONTROL_OCCUR, [](const EventInfo& eventInfo) { InnerSendFlowControlOccurEvent(eventInfo); }}, @@ -147,6 +153,16 @@ void EventReport::InnerSendFlowControlOccurEvent(const EventInfo &eventInfo) EVENT_PARAM_UID, eventInfo.uid); } +static void InnerSendNotificationSystemErrorEvent(const EventInfo &eventInfo) +{ + InnerEventWrite( + NOTIFICATION_SYSTEM_ERROR, + HiviewDFX::HiSysEvent::EventType::FAULT, + DEVICE_Id, eventInfo.deviceId, + DEVICE_TYPE, eventInfo.deviceType, + ERROR_REASON, eventInfo.errorReason); +} + 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 1eb91ed23..fca66f24b 100644 --- a/services/ans/src/notification_extension/distributed_extension_service.cpp +++ b/services/ans/src/notification_extension/distributed_extension_service.cpp @@ -16,6 +16,7 @@ #include "distributed_extension_service.h" #include "ans_log_wrapper.h" +#include "notification_analytics_util.h" #include "notification_config_parse.h" namespace OHOS { @@ -32,6 +33,8 @@ 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); namespace { constexpr int32_t DEFAULT_TITLE_LENGTH = 200; @@ -43,6 +46,7 @@ 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 DELETE_ERROR_EVENT_CODE = 5; } std::string TransDeviceTypeToName(uint16_t deviceType_) @@ -172,6 +176,13 @@ 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)); + } + dansRunning_.store(true); return 0; } @@ -261,6 +272,21 @@ 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 == 0) { + HaMetaMessage message = HaMetaMessage(20, branchId) + .ErrorCode(ErrCode).Message(reason); + NotificationAnalyticsUtil::ReportPublishFailedEvent(message); + } else if (code == DELETE_ERROR_EVENT_CODE) { + HaMetaMessage message = HaMetaMessage(20, branchId) + .deleteReason(NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE) + .ErrorCode(ErrCode).Message(reason); + NotificationAnalyticsUtil::ReportDeleteFailedEvent(message); + } +} + void DistributedExtensionService::OnDeviceOffline(const DmDeviceInfo &deviceInfo) { if (distributedQueue_ == nullptr) { diff --git a/services/distributed/include/soft_bus/distributed_manager.h b/services/distributed/include/soft_bus/distributed_manager.h index 7879c48cc..fcadbe8c6 100644 --- a/services/distributed/include/soft_bus/distributed_manager.h +++ b/services/distributed/include/soft_bus/distributed_manager.h @@ -34,6 +34,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); }; } } diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index 0114d7434..98874c3b1 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -21,6 +21,7 @@ #include "socket.h" #include "distributed_subscriber.h" #include "distributed_device_data.h" +#include "event_report.h" #include "request_box.h" #include "match_box.h" #include @@ -58,6 +59,11 @@ 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); + EventInfo BuildEventInfo(const std::string& errorReason); + void InitHACallBack(std::function callback); + int32_t code_ = -1; + std::function haCallback_ = nullptr; + private: int64_t GetCurrentTime(); void HandleBundleRemoved(const std::string& bundleName); @@ -80,6 +86,7 @@ private: NotificationContent::Type type, NotifticationRequestBox &requestBox); void GetNeedUpdateDevice(bool updatedExit, const std::string& bundleName, std::vector& updateDeviceList); + void AbnormalReporting(int result, uint32_t branchId, std::string& errorReason); std::function callBack_ = nullptr; std::map> bundleIconCache_; int32_t userId_ = DEFAULT_USER_ID; diff --git a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp index 7ef2f63c5..903fbac34 100644 --- a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp +++ b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp @@ -53,6 +53,12 @@ SYMBOL_EXPORT void ReleaseLocalDevice() DistributedManager::GetInstance().ReleaseLocalDevice(); } +SYMBOL_EXPORT void InitHACallBack( + std::function callback) +{ + DistributedManager::GetInstance().InitHACallBack(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 f72a4fb0d..38b97d482 100644 --- a/services/distributed/src/soft_bus/distributed_manager.cpp +++ b/services/distributed/src/soft_bus/distributed_manager.cpp @@ -74,5 +74,9 @@ 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); +} } } diff --git a/services/distributed/src/soft_bus/distributed_publish_service.cpp b/services/distributed/src/soft_bus/distributed_publish_service.cpp index 0d881787b..80d9f8d28 100644 --- a/services/distributed/src/soft_bus/distributed_publish_service.cpp +++ b/services/distributed/src/soft_bus/distributed_publish_service.cpp @@ -185,6 +185,13 @@ void DistributedService::RemoveNotifictaion(const std::shared_ptr& boxMe boxMessage->GetStringValue(NOTIFICATION_HASHCODE, hasdCode); int result = IN_PROCESS_CALL(NotificationHelper::RemoveNotification( hasdCode, NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE)); + std::string errorReason = "delete message failed"; + uint32_t branchId = 3; + if (result == 0) { + errorReason = "delete message success"; + branchId = 4; + } + AbnormalReporting(result, branchId, errorReason); ANS_LOGI("dans remove message %{public}d.", result); } @@ -198,7 +205,26 @@ void DistributedService::RemoveNotifictaions(const std::shared_ptr& boxM boxMessage->GetVectorValue(BATCH_REMOVE_NOTIFICATIONS, hasdCodes); int result = IN_PROCESS_CALL( NotificationHelper::RemoveNotifications(hasdCodes, NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE)); + std::string errorReason = "delete message failed"; + uint32_t branchId = 3; + if (result == 0) { + errorReason = "delete message success"; + branchId = 4; + } + AbnormalReporting(result, branchId, errorReason); ANS_LOGI("dans batch remove message %{public}d.", result); } + +void DistributedService::AbnormalReporting(int result, uint32_t branchId, std::string& errorReason) +{ + if (result != 0) { + EventInfo eventInfo = DistributedService::GetInstance().BuildEventInfo(errorReason); + EventReport::SendHiSysEvent(NOTIFICATION_SYSTEM_ERROR, eventInfo); + } + if(haCallback_ == nullptr) { + return; + } + haCallback_(code_, result, branchId, errorReason); +} } } diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index e657b8ef5..c4be2ba4c 100644 --- a/services/distributed/src/soft_bus/distributed_service.cpp +++ b/services/distributed/src/soft_bus/distributed_service.cpp @@ -218,5 +218,20 @@ int64_t DistributedService::GetCurrentTime() return duration.count(); } +EventInfo DistributedService::BuildEventInfo(const std::string& errorReason) +{ + EventInfo eventInfo; + eventInfo.deviceId = localDevice_.deviceId_; + eventInfo.deviceType = localDevice_.deviceType_; + eventInfo.errorReason = errorReason; + return eventInfo; +} + +void DistributedService::InitHACallBack( + std::function callback) +{ + haCallback_ = callback; +} + } } diff --git a/services/distributed/src/soft_bus/distributed_socket.cpp b/services/distributed/src/soft_bus/distributed_socket.cpp index c2a66e1ba..b17f3f705 100644 --- a/services/distributed/src/soft_bus/distributed_socket.cpp +++ b/services/distributed/src/soft_bus/distributed_socket.cpp @@ -19,6 +19,7 @@ #include "session.h" #include "distributed_server.h" #include "distributed_client.h" +#include "distributed_service.h" namespace OHOS { namespace Notification { @@ -202,6 +203,13 @@ int32_t ClientBind(const std::string& name, const std::string& pkgName, const st if (!bindSuccess) { ::Shutdown(socketId); // close client. + std::string errorReason = "Bind server failed"; + EventInfo eventInfo = DistributedService::GetInstance().BuildEventInfo(errorReason); + EventReport::SendHiSysEvent(NOTIFICATION_SYSTEM_ERROR, eventInfo); + if (DistributedService::GetInstance().haCallback_ != nullptr) { + int32_t code = DistributedService::GetInstance().code_; + DistributedService::GetInstance().haCallback_(code, -1, 1, errorReason); + } return -1; } return socketId; @@ -215,6 +223,15 @@ int32_t ClientSendMsg(int32_t socketId, const void* data, int32_t length, TransD } else if (type == TransDataType::DATA_TYPE_MESSAGE) { result = ::SendMessage(socketId, data, length); } + if (result != 0) { + std::string errorReason = "send message failed"; + EventInfo eventInfo = DistributedService::GetInstance().BuildEventInfo(errorReason); + EventReport::SendHiSysEvent(NOTIFICATION_SYSTEM_ERROR, eventInfo); + if (DistributedService::GetInstance().haCallback_ != nullptr) { + int32_t code = DistributedService::GetInstance().code_; + DistributedService::GetInstance().haCallback_(code, result, 2, errorReason); + } + } ANS_LOGI("socket Send %{public}d %{public}d %{public}d %{public}d", socketId, length, type, result); return result; } diff --git a/services/distributed/src/soft_bus/distributed_subscribe_service.cpp b/services/distributed/src/soft_bus/distributed_subscribe_service.cpp index 23aaba637..ddafc0b20 100644 --- a/services/distributed/src/soft_bus/distributed_subscribe_service.cpp +++ b/services/distributed/src/soft_bus/distributed_subscribe_service.cpp @@ -31,6 +31,8 @@ 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; std::string SubscribeTransDeviceType(uint16_t deviceType_) { @@ -182,6 +184,7 @@ void DistributedService::OnConsumed(const std::shared_ptr &request ANS_LOGW("Dans OnConsumed serialize failed."); return; } + this->code_ = PUBLISH_ERROR_EVENT_CODE; DistributedClient::GetInstance().SendMessage(requestBox.GetByteBuffer(), requestBox.GetByteLength(), TransDataType::DATA_TYPE_BYTES, peerDevice.deviceId_, peerDevice.deviceType_); }); @@ -216,6 +219,7 @@ void DistributedService::OnBatchCanceled(const std::vectorcode_ = DELETE_ERROR_EVENT_CODE; DistributedClient::GetInstance().SendMessage(batchRemoveBox.GetByteBuffer(), batchRemoveBox.GetByteLength(), TransDataType::DATA_TYPE_MESSAGE, peerDevice.deviceId_, peerDevice.deviceType_); }); @@ -241,6 +245,7 @@ void DistributedService::OnCanceled(const std::shared_ptr& notific ANS_LOGW("dans OnCanceled serialize failed"); return; } + this->code_ = DELETE_ERROR_EVENT_CODE; DistributedClient::GetInstance().SendMessage(removeBox.GetByteBuffer(), removeBox.GetByteLength(), TransDataType::DATA_TYPE_MESSAGE, peerDevice.deviceId_, peerDevice.deviceType_); }); -- Gitee