From 800900efaa2088a48d448ac63d5dd6a0787f5d62 Mon Sep 17 00:00:00 2001 From: zhengzhuolan Date: Sat, 8 Feb 2025 17:01:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=9C=BA=E6=99=AF=E6=89=93=E7=82=B9?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=96=B0=E5=A2=9E=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhengzhuolan --- .../ans/include/notification_analytics_util.h | 16 ++++--- .../common/notification_analytics_util.cpp | 36 ++++++++++++--- .../distributed_extension_service.cpp | 46 ++++++++++++------- .../src/notification_subscriber_manager.cpp | 12 ++--- .../include/soft_bus/distributed_service.h | 2 +- .../src/soft_bus/distributed_client.cpp | 4 +- .../distributed_operation_service.cpp | 23 ++++++++++ .../soft_bus/distributed_publish_service.cpp | 20 ++++++++ .../src/soft_bus/distributed_service.cpp | 25 ++++++---- .../distributed_subscribe_service.cpp | 8 ++-- 10 files changed, 140 insertions(+), 52 deletions(-) diff --git a/services/ans/include/notification_analytics_util.h b/services/ans/include/notification_analytics_util.h index c1f265170..bf48d8bee 100644 --- a/services/ans/include/notification_analytics_util.h +++ b/services/ans/include/notification_analytics_util.h @@ -67,12 +67,13 @@ 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); + 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); + HaMetaMessage& ClickByWatch(); std::string GetMessage() const; HaMetaMessage& Checkfailed(bool checkfailed); bool NeedReport() const; @@ -94,6 +95,7 @@ public: static int32_t syncHeadSet_; static int32_t syncWatchHeadSet_; static int32_t delByWatch_; + static int32_t clickByWatch_; static int32_t keyNode_; static int64_t time_; static int32_t syncLiveViewWatch_; @@ -134,6 +136,8 @@ public: static void ReportPublishFailedEvent(const HaMetaMessage& message); + static void ReportSkipFailedEvent(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/src/common/notification_analytics_util.cpp b/services/ans/src/common/notification_analytics_util.cpp index 0468b6b32..ea1027fe2 100644 --- a/services/ans/src/common/notification_analytics_util.cpp +++ b/services/ans/src/common/notification_analytics_util.cpp @@ -77,6 +77,7 @@ int32_t HaMetaMessage::syncLiveViewWatchHeadSet_ = 0; int64_t HaMetaMessage::liveViewTime_ = NotificationAnalyticsUtil::GetCurrentTime(); int32_t HaMetaMessage::delByWatch_ = 0; int32_t HaMetaMessage::liveViewDelByWatch_ = 0; +int32_t HaMetaMessage::clickByWatch_ = 0; static std::mutex reportCacheMutex_; static uint64_t reportTimerId = 0; static std::list reportCacheList; @@ -175,13 +176,13 @@ HaMetaMessage& HaMetaMessage::SlotType(int32_t slotType) return *this; } -HaMetaMessage& HaMetaMessage::deleteReason(int32_t deleteReason) +HaMetaMessage& HaMetaMessage::DeleteReason(int32_t deleteReason) { deleteReason_ = deleteReason; return *this; } -HaMetaMessage& HaMetaMessage::syncWatch(bool isLiveView) +HaMetaMessage& HaMetaMessage::SyncWatch(bool isLiveView) { if (isLiveView) { HaMetaMessage::syncLiveViewWatch_++; @@ -191,7 +192,7 @@ HaMetaMessage& HaMetaMessage::syncWatch(bool isLiveView) return *this; } -HaMetaMessage& HaMetaMessage::syncHeadSet(bool isLiveView) +HaMetaMessage& HaMetaMessage::SyncHeadSet(bool isLiveView) { if (isLiveView) { HaMetaMessage::syncLiveViewHeadSet_++; @@ -201,7 +202,7 @@ HaMetaMessage& HaMetaMessage::syncHeadSet(bool isLiveView) return *this; } -HaMetaMessage& HaMetaMessage::syncWatchHeadSet(bool isLiveView) +HaMetaMessage& HaMetaMessage::SyncWatchHeadSet(bool isLiveView) { if (isLiveView) { HaMetaMessage::syncLiveViewWatchHeadSet_++; @@ -211,7 +212,7 @@ HaMetaMessage& HaMetaMessage::syncWatchHeadSet(bool isLiveView) return *this; } -HaMetaMessage& HaMetaMessage::keyNode(bool isKeyNode) +HaMetaMessage& HaMetaMessage::KeyNode(bool isKeyNode) { if (isKeyNode) { HaMetaMessage::keyNode_++; @@ -219,7 +220,7 @@ HaMetaMessage& HaMetaMessage::keyNode(bool isKeyNode) return *this; } -HaMetaMessage& HaMetaMessage::delByWatch(bool isLiveView) +HaMetaMessage& HaMetaMessage::DelByWatch(bool isLiveView) { if (isLiveView) { HaMetaMessage::liveViewDelByWatch_++; @@ -229,6 +230,12 @@ HaMetaMessage& HaMetaMessage::delByWatch(bool isLiveView) return *this; } +HaMetaMessage& HaMetaMessage::ClickByWatch() +{ + HaMetaMessage::clickByWatch_++; + return *this; +} + std::string HaMetaMessage::Build() const { return std::to_string(sceneId_) + MESSAGE_DELIMITER + @@ -880,7 +887,8 @@ bool NotificationAnalyticsUtil::DetermineWhetherToSend(uint32_t slotType) if ((NotificationAnalyticsUtil::GetCurrentTime() - HaMetaMessage::liveViewTime_) >= MAX_TIME) { return true; } else if (HaMetaMessage::syncLiveViewWatch_ + HaMetaMessage::syncLiveViewHeadSet_ + - HaMetaMessage::syncLiveViewWatchHeadSet_ + HaMetaMessage::liveViewDelByWatch_ >= + HaMetaMessage::syncLiveViewWatchHeadSet_ + HaMetaMessage::liveViewDelByWatch_ + + HaMetaMessage::clickByWatch_ >= NOTIFICATION_MAX_DATA) { return true; } @@ -908,11 +916,13 @@ std::string NotificationAnalyticsUtil::BuildAnsData(const HaMetaMessage& message data["syncWatchHeadSet"] = std::to_string(HaMetaMessage::syncLiveViewWatchHeadSet_); data["keyNode"] = std::to_string(HaMetaMessage::keyNode_); data["delByWatch"] = std::to_string(HaMetaMessage::liveViewDelByWatch_); + data["clickByWatch"] = std::to_string(HaMetaMessage::clickByWatch_); HaMetaMessage::syncLiveViewWatch_ = 0; HaMetaMessage::syncLiveViewHeadSet_ = 0; HaMetaMessage::syncLiveViewWatchHeadSet_ = 0; HaMetaMessage::keyNode_ = 0; HaMetaMessage::liveViewDelByWatch_ = 0; + HaMetaMessage::clickByWatch_ = 0; HaMetaMessage::liveViewTime_ = NotificationAnalyticsUtil::GetCurrentTime(); } else { data["syncWatch"] = std::to_string(HaMetaMessage::syncWatch_); @@ -929,5 +939,17 @@ std::string NotificationAnalyticsUtil::BuildAnsData(const HaMetaMessage& message return ansData.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace); } +void NotificationAnalyticsUtil::ReportSkipFailedEvent(const HaMetaMessage& message) +{ + if (!ReportFlowControl(MODIFY_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); + + IN_PROCESS_CALL_WITHOUT_RET(AddListCache(want, MODIFY_ERROR_EVENT_CODE)); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/notification_extension/distributed_extension_service.cpp b/services/ans/src/notification_extension/distributed_extension_service.cpp index c7d3af7ad..d00b77644 100644 --- a/services/ans/src/notification_extension/distributed_extension_service.cpp +++ b/services/ans/src/notification_extension/distributed_extension_service.cpp @@ -52,7 +52,11 @@ 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 MODIFY_ERROR_EVENT_CODE = 6; constexpr const int32_t ANS_CUSTOMIZE_CODE = 7; + +static const int32_t MAX_DATA_LENGTH = 7; +static const int32_t START_ANONYMOUS_INDEX = 5; } std::string TransDeviceTypeToName(uint16_t deviceType_) @@ -246,7 +250,7 @@ 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: " + + " ; 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, @@ -272,19 +276,31 @@ void DistributedExtensionService::HADotCallback(int32_t code, int32_t ErrCode, u } } else if (code == DELETE_ERROR_EVENT_CODE) { HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_20, branchId) - .deleteReason(NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE) + .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; + if (branchId == BRANCH_3) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, branchId) + .ClickByWatch() + .SlotType(ErrCode); + NotificationAnalyticsUtil::ReportOperationsDotEvent(message); + } else { + 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); } - HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, branchId) - .delByWatch(isLiveView) - .SlotType(ErrCode); - NotificationAnalyticsUtil::ReportOperationsDotEvent(message); + } else if (code == MODIFY_ERROR_EVENT_CODE) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_20, branchId) + .ErrorCode(ErrCode) + .Message(reason); + NotificationAnalyticsUtil::ReportSkipFailedEvent(message); } } @@ -320,7 +336,7 @@ void DistributedExtensionService::OnDeviceOffline(const DmDeviceInfo &deviceInfo } handler(deviceInfo.deviceId, deviceInfo.deviceTypeId); std::string reason = "deviceType: " + std::to_string(deviceInfo.deviceTypeId) + - "deviceId: " + AnonymousProcessing(deviceInfo.deviceId); + " ; deviceId: " + AnonymousProcessing(deviceInfo.deviceId); HADotCallback(PUBLISH_ERROR_EVENT_CODE, 0, EventSceneId::SCENE_2, reason); deviceMap_.erase(deviceInfo.deviceId); }); @@ -366,13 +382,9 @@ void DistributedExtensionService::SetMaxContentLength(nlohmann::json &configJson 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] = '*'; - } + int32_t length = data.length(); + if (length >= MAX_DATA_LENGTH) { + data.replace(START_ANONYMOUS_INDEX, length - 1, "**"); } return data; } diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index d1a171638..2bb0f72cf 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -857,21 +857,21 @@ void NotificationSubscriberManager::TrackCodeLog( bool isLiveViewType = (slotType == NotificationConstant::SlotType::LIVE_VIEW); if (wearableFlag && headsetFlag) { HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, EventBranchId::BRANCH_1) - .syncWatchHeadSet(isLiveViewType) - .keyNode(keyNodeFlag) + .SyncWatchHeadSet(isLiveViewType) + .KeyNode(keyNodeFlag) .SlotType(slotType); NotificationAnalyticsUtil::ReportOperationsDotEvent(message); } else { if (headsetFlag) { HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, EventBranchId::BRANCH_1) - .syncHeadSet(isLiveViewType) - .keyNode(keyNodeFlag) + .SyncHeadSet(isLiveViewType) + .KeyNode(keyNodeFlag) .SlotType(slotType); NotificationAnalyticsUtil::ReportOperationsDotEvent(message); } else if (wearableFlag) { HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, EventBranchId::BRANCH_1) - .syncWatch(isLiveViewType) - .keyNode(keyNodeFlag) + .SyncWatch(isLiveViewType) + .KeyNode(keyNodeFlag) .SlotType(slotType); NotificationAnalyticsUtil::ReportOperationsDotEvent(message); } diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index bf4a5221c..e3eec707a 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -61,7 +61,7 @@ public: void SendEventReport(int32_t messageType, int32_t errCode, const std::string& errorReason); void InitHACallBack(std::function callback); void InitSendReportCallBack(std::function callback); - void SendHaReport(int32_t errorCode, uint32_t branchId, const std::string& errorReason); + void SendHaReport(int32_t errorCode, uint32_t branchId, const std::string& errorReason, int32_t code = -1); ErrCode OnResponse(const std::shared_ptr ¬ification, const DistributedDeviceInfo& device); private: diff --git a/services/distributed/src/soft_bus/distributed_client.cpp b/services/distributed/src/soft_bus/distributed_client.cpp index b9df443d7..23bcd656f 100644 --- a/services/distributed/src/soft_bus/distributed_client.cpp +++ b/services/distributed/src/soft_bus/distributed_client.cpp @@ -50,9 +50,9 @@ void DistributedClient::OnShutdown(int32_t socket, ShutdownReason reason) for (auto& socketItem : socketsId_) { if (socketItem.second == socket) { socketItem.second = -1; - std::string message = "socketID: " + std::to_string(socket) + "ShutdownReason: " + + std::string message = "socketID: " + std::to_string(socket) + " ; ShutdownReason: " + ShutdownReasonToString(reason); - DistributedService::GetInstance().SendHaReport(0, BRANCH4_ID, message); + DistributedService::GetInstance().SendHaReport(0, BRANCH4_ID, message, PUBLISH_ERROR_EVENT_CODE); } } } diff --git a/services/distributed/src/soft_bus/distributed_operation_service.cpp b/services/distributed/src/soft_bus/distributed_operation_service.cpp index d8f1451c0..8498de14b 100644 --- a/services/distributed/src/soft_bus/distributed_operation_service.cpp +++ b/services/distributed/src/soft_bus/distributed_operation_service.cpp @@ -17,10 +17,18 @@ #include "screenlock_common.h" #include "in_process_call_wrapper.h" +#include "distributed_service.h" namespace OHOS { namespace Notification { +namespace { +constexpr char const DISTRIBUTED_LABEL[] = "ans_distributed"; +constexpr const int32_t ANS_CUSTOMIZE_CODE = 7; +constexpr const int32_t BRANCH3_ID = 3; +constexpr const int32_t BRANCH7_ID = 7; +constexpr const int32_t BRANCH8_ID = 8; +} UnlockScreenCallback::UnlockScreenCallback(const std::string& eventId) : eventId_(eventId) {} UnlockScreenCallback::~UnlockScreenCallback() {} @@ -30,6 +38,11 @@ void UnlockScreenCallback::OnCallBack(int32_t screenLockResult) ANS_LOGI("Unlock Screen result: %{public}d", screenLockResult); if (screenLockResult == ScreenLock::ScreenChange::SCREEN_SUCC) { OperationService::GetInstance().TriggerOperation(eventId_); + } else { + std::string errorReason = "unlock screen failed"; + int32_t messageType = 0; + DistributedService::GetInstance().SendEventReport(messageType, -1, errorReason); + DistributedService::GetInstance().SendHaReport(-1, BRANCH7_ID, errorReason); } } @@ -72,6 +85,16 @@ void OperationService::TriggerOperation(std::string eventId) } if (iter->second.type == OperationType::OPERATION_CLICK_JUMP) { auto ret = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->StartAbility(iter->second.want)); + std::string errorReason = "pull up success"; + if (ret == ERR_OK) { + DistributedService::GetInstance().SendHaReport( + NotificationConstant::SlotType::LIVE_VIEW, BRANCH3_ID, errorReason, ANS_CUSTOMIZE_CODE); + } else { + errorReason = "pull up failed"; + int32_t messageType = 0; + DistributedService::GetInstance().SendEventReport(messageType, ret, errorReason); + } + DistributedService::GetInstance().SendHaReport(ret, BRANCH8_ID, errorReason); operationInfoMaps_.erase(iter); ANS_LOGI("StartAbility result:%{public}s %{public}d", eventId.c_str(), ret); return; diff --git a/services/distributed/src/soft_bus/distributed_publish_service.cpp b/services/distributed/src/soft_bus/distributed_publish_service.cpp index 3715e7a18..c2e61b2cb 100644 --- a/services/distributed/src/soft_bus/distributed_publish_service.cpp +++ b/services/distributed/src/soft_bus/distributed_publish_service.cpp @@ -38,10 +38,13 @@ namespace Notification { namespace { constexpr char const DISTRIBUTED_LABEL[] = "ans_distributed"; constexpr const int32_t ANS_CUSTOMIZE_CODE = 7; +constexpr const int32_t MODIFY_ERROR_EVENT_CODE = 6; constexpr const int32_t DELETE_ERROR_EVENT_CODE = 5; constexpr const int32_t OPERATION_DELETE_BRANCH = 2; constexpr const int32_t BRANCH3_ID = 3; constexpr const int32_t BRANCH4_ID = 4; +constexpr const int32_t BRANCH6_ID = 6; +constexpr const int32_t BRANCH9_ID = 9; } int64_t GetCurrentTime() @@ -283,6 +286,9 @@ void DistributedService::RemoveNotifications(const std::shared_ptr& boxM void DistributedService::AbnormalReporting(int result, uint32_t branchId, const std::string &errorReason) { + if (localDevice_.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE) { + return; + } if (result != 0) { SendEventReport(0, result, errorReason); } @@ -340,6 +346,7 @@ void DistributedService::HandleResponseSync(const std::shared_ptr& boxMe PowerMgr::PowerMgrClient::GetInstance().WakeupDevice(); } + code_ = MODIFY_ERROR_EVENT_CODE; bool isScreenLocked = ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked(); ANS_LOGI("Screen locked status, isScreenLocked: %{public}d.", isScreenLocked); if (isScreenLocked) { @@ -350,11 +357,24 @@ void DistributedService::HandleResponseSync(const std::shared_ptr& boxMe int32_t unlockResult = IN_PROCESS_CALL( ScreenLock::ScreenLockManager::GetInstance()->Unlock(ScreenLock::Action::UNLOCKSCREEN, listener)); ANS_LOGI("unlock result:%{public}d", unlockResult); + if (unlockResult != ERR_OK) { + std::string errorReason = "unlock failed"; + AbnormalReporting(unlockResult, BRANCH6_ID, errorReason); + } info.want = *wantPtr; OperationService::GetInstance().AddOperation(info); } else { auto ret = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->StartAbility(*wantPtr)); ANS_LOGI("StartAbility result:%{public}d", ret); + std::string errorReason = "pull up success"; + if (ret == ERR_OK) { + OperationalReporting(BRANCH3_ID, NotificationConstant::SlotType::LIVE_VIEW); + } else { + errorReason = "pull up failed"; + int32_t messageType = 0; + AbnormalReporting(messageType, ret, errorReason); + } + AbnormalReporting(ret, BRANCH9_ID, errorReason); } } } diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index 27e5d329f..b9185df58 100644 --- a/services/distributed/src/soft_bus/distributed_service.cpp +++ b/services/distributed/src/soft_bus/distributed_service.cpp @@ -30,6 +30,8 @@ namespace Notification { namespace { static const int32_t MAX_CONNECTED_TYR = 5; static const uint64_t SYNC_TASK_DELAY = 7 * 1000 * 1000; +static const int32_t MAX_DATA_LENGTH = 7; +static const int32_t START_ANONYMOUS_INDEX = 5; } DistributedService& DistributedService::GetInstance() @@ -187,7 +189,8 @@ int64_t DistributedService::GetCurrentTime() void DistributedService::SendEventReport( int32_t messageType, int32_t errCode, const std::string& errorReason) { - if (sendReportCallback_ != nullptr) { + if (sendReportCallback_ != nullptr || + localDevice_.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE) { sendReportCallback_(messageType, errCode, errorReason); } } @@ -206,21 +209,23 @@ void DistributedService::InitSendReportCallBack( 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] = '*'; - } + int32_t length = data.length(); + if (length >= MAX_DATA_LENGTH) { + data.replace(START_ANONYMOUS_INDEX, length - 1, "**"); } return data; } -void DistributedService::SendHaReport(int32_t errorCode, uint32_t branchId, const std::string& errorReason) +void DistributedService::SendHaReport( + int32_t errorCode, uint32_t branchId, const std::string& errorReason, int32_t code) { - if (haCallback_ != nullptr) { + if (haCallback_ == nullptr || localDevice_.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE) { + return; + } + if (code == -1) { haCallback_(code_, errorCode, branchId, errorReason); + } else { + haCallback_(code, errorCode, branchId, errorReason); } } diff --git a/services/distributed/src/soft_bus/distributed_subscribe_service.cpp b/services/distributed/src/soft_bus/distributed_subscribe_service.cpp index 4d0640892..be8c52ff2 100644 --- a/services/distributed/src/soft_bus/distributed_subscribe_service.cpp +++ b/services/distributed/src/soft_bus/distributed_subscribe_service.cpp @@ -38,6 +38,7 @@ 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 MODIFY_ERROR_EVENT_CODE = 6; constexpr const int32_t BRANCH3_ID = 3; std::string SubscribeTransDeviceType(uint16_t deviceType) @@ -79,10 +80,10 @@ void DistributedService::SubscribeNotifictaion(const DistributedDeviceInfo peerD if (result == 0) { subscriberMap_.insert(std::make_pair(peerDevice.deviceId_, subscriber)); peerDevice_[peerDevice.deviceId_].peerState_ = DeviceState::STATE_ONLINE; - if (DistributedService::GetInstance().haCallback_ != nullptr) { + if (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); + " ; deviceId: " + AnonymousProcessing(localDevice_.deviceId_); + haCallback_(PUBLISH_ERROR_EVENT_CODE, 0, BRANCH3_ID, reason); } } ANS_LOGI("Subscribe notification %{public}s %{public}d %{public}d %{public}d.", @@ -285,6 +286,7 @@ std::string DistributedService::GetNotificationKey(const std::shared_ptr& notification, const DistributedDeviceInfo& device) { + this->code_ = MODIFY_ERROR_EVENT_CODE; NotificationResponseBox responseBox; ANS_LOGI("dans OnResponse %{public}s", notification->Dump().c_str()); if (notification == nullptr) { -- Gitee