From bd0c71e74cc4a90489160236cbf5db40fd0611e6 Mon Sep 17 00:00:00 2001 From: wangsen1994 Date: Mon, 7 Jul 2025 19:27:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=BF=90=E8=90=A5=E6=89=93?= =?UTF-8?q?=E7=82=B9=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangsen1994 --- .../common/include/distributed_data_define.h | 12 + .../ans/include/notification_analytics_util.h | 65 ++-- .../distributed_extension_service.h | 1 + .../include/notification_subscriber_manager.h | 6 +- .../common/notification_analytics_util.cpp | 261 ++++++++------ .../distributed_extension_service.cpp | 72 ++-- .../src/notification_subscriber_manager.cpp | 92 +---- .../notification_analytics_util_test.cpp | 327 +++++------------- .../notification_subscriber_manager_test.cpp | 295 ---------------- .../include/helper/analytics_util.h | 6 +- .../helper/distributed_operation_helper.h | 1 + .../soft_bus/distributed_operation_service.h | 9 +- .../soft_bus/distributed_publish_service.h | 2 +- ...distributed_unlock_listener_oper_service.h | 18 +- services/distributed/libdans.map | 2 - .../distributed/src/helper/analytics_util.cpp | 15 +- .../helper/distributed_operation_helper.cpp | 2 + .../distributed_extern_intferface.cpp | 19 +- .../distributed_operation_service.cpp | 31 +- .../distributed_publish_service_v2.cpp | 26 +- ...stributed_unlock_listener_oper_service.cpp | 27 +- 21 files changed, 449 insertions(+), 840 deletions(-) diff --git a/frameworks/core/common/include/distributed_data_define.h b/frameworks/core/common/include/distributed_data_define.h index 9f3f50d85..3f5236f4c 100644 --- a/frameworks/core/common/include/distributed_data_define.h +++ b/frameworks/core/common/include/distributed_data_define.h @@ -44,6 +44,18 @@ enum DeviceStatueChangeType { DEVICE_USING_CLOSE = 3, }; +enum HaOperationType { + COLLABORATE_DELETE = 0, + COLLABORATE_REPLY = 1, + COLLABORATE_JUMP = 2, +}; + +struct DistributedHaCallbacks { + std::function hiSysEventCallback; + std::function haMaintenanceCallback; + std::function haOperationCallback; +}; + struct DeviceStatueChangeInfo { int32_t changeType; std::string deviceId; diff --git a/services/ans/include/notification_analytics_util.h b/services/ans/include/notification_analytics_util.h index fd05b8f2d..89f83b947 100644 --- a/services/ans/include/notification_analytics_util.h +++ b/services/ans/include/notification_analytics_util.h @@ -83,6 +83,47 @@ enum EventBranchId { BRANCH_19 = 19, BRANCH_20 = 20, }; + +class OperationalMeta { +public: + void ToJson(nlohmann::json& jsonObject); +public: + int32_t syncTime; + int32_t delTime; + int32_t clickTime; + int32_t replyTime; +}; + +class OperationalData { +public: + OperationalData(); + void ToJson(nlohmann::json& jsonObject); +public: + int32_t syncWatchHead = 0; + int32_t keyNode = 0; + int64_t time; + int64_t countTime = 0; + std::map dataMap; +}; + +class HaOperationMessage { +public: + HaOperationMessage() {} + HaOperationMessage(bool isLiveView) : isLiveView_(isLiveView) {} + void ResetData(); + std::string ToJson(); + bool DetermineWhetherToSend(); + HaOperationMessage& KeyNode(bool keyNodeFlag); + HaOperationMessage& SyncPublish(std::vector& deviceTypes); + HaOperationMessage& SyncDelete(std::string deviceType, const std::string& reason); + HaOperationMessage& SyncClick(std::string deviceType); + HaOperationMessage& SyncReply(std::string deviceType); +public: + bool isLiveView_ = false; + static OperationalData notificationData; + static OperationalData liveViewData; +}; + class HaMetaMessage { public: HaMetaMessage() = default; @@ -101,14 +142,7 @@ 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& ClickByWatch(); - HaMetaMessage& ReplyByWatch(); std::string GetMessage() const; HaMetaMessage& Checkfailed(bool checkfailed); bool NeedReport() const; @@ -127,19 +161,6 @@ public: std::string path_; 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 clickByWatch_; - static int32_t replyByWatch_; - 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 { @@ -194,7 +215,7 @@ public: static int64_t GetCurrentTime(); - static void ReportOperationsDotEvent(const HaMetaMessage& message); + static void ReportOperationsDotEvent(HaOperationMessage& message); static void ReportPublishFailedEvent(const HaMetaMessage& message); @@ -254,8 +275,6 @@ private: static bool DetermineWhetherToSend(uint32_t slotType); - static std::string BuildAnsData(const HaMetaMessage& message); - static void AddToBadgeInfos(std::string bundle, BadgeInfo& badgeInfo); static void CheckBadgeReport(); diff --git a/services/ans/include/notification_extension/distributed_extension_service.h b/services/ans/include/notification_extension/distributed_extension_service.h index 31189099b..9427bb6c8 100644 --- a/services/ans/include/notification_extension/distributed_extension_service.h +++ b/services/ans/include/notification_extension/distributed_extension_service.h @@ -61,6 +61,7 @@ public: void SendReportCallback(int32_t messageType, int32_t errCode, std::string reason); int32_t GetOperationReplyTimeout(); int32_t TransDeviceIdToUdid(const std::string& networkId, std::string& udid); + void HaOperationCallback(const std::string& deviceType, int32_t sceneType, int32_t slotType, std::string reason); private: DistributedExtensionService(); diff --git a/services/ans/include/notification_subscriber_manager.h b/services/ans/include/notification_subscriber_manager.h index b6b600fe7..0babfd52e 100644 --- a/services/ans/include/notification_subscriber_manager.h +++ b/services/ans/include/notification_subscriber_manager.h @@ -147,11 +147,7 @@ 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); + void TrackCodeLog(const sptr ¬ification); #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED bool GetIsEnableEffectedRemind(); diff --git a/services/ans/src/common/notification_analytics_util.cpp b/services/ans/src/common/notification_analytics_util.cpp index 38fe9e190..724d70f56 100644 --- a/services/ans/src/common/notification_analytics_util.cpp +++ b/services/ans/src/common/notification_analytics_util.cpp @@ -37,6 +37,7 @@ namespace OHOS { namespace Notification { constexpr char MESSAGE_DELIMITER = '#'; +constexpr const int32_t SYNC_WATCH_HEADSET = 2; 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; @@ -79,19 +80,6 @@ static std::map> flowC static std::map badgeInfos; static std::map liveViewMessages; -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; -int32_t HaMetaMessage::clickByWatch_ = 0; -int32_t HaMetaMessage::replyByWatch_ = 0; static std::mutex reportCacheMutex_; static uint64_t reportTimerId = 0; static std::list reportCacheList; @@ -127,6 +115,8 @@ static std::shared_ptr liveViewTimeInfo = std::make_shared& deviceTypes, OperationalData& data) { - if (isLiveView) { - HaMetaMessage::syncLiveViewWatchHeadSet_++; + int32_t isWatchHeadSet = 0; + for (auto& device : deviceTypes) { + if (data.dataMap.find(device) != data.dataMap.end()) { + data.dataMap[device].syncTime++; + if (device == NotificationConstant::HEADSET_DEVICE_TYPE || + device == NotificationConstant::WEARABLE_DEVICE_TYPE || + device == NotificationConstant::LITEWEARABLE_DEVICE_TYPE) { + isWatchHeadSet++; + } + data.countTime++; + } + } + if (isWatchHeadSet >= SYNC_WATCH_HEADSET) { + data.syncWatchHead++; + } +} + +HaOperationMessage& HaOperationMessage::SyncPublish(std::vector& deviceTypes) +{ + if (isLiveView_) { + SetPublishTime(deviceTypes, liveViewData); } else { - HaMetaMessage::syncWatchHeadSet_++; + SetPublishTime(deviceTypes, notificationData); } return *this; } -HaMetaMessage& HaMetaMessage::KeyNode(bool isKeyNode) +HaOperationMessage& HaOperationMessage::SyncDelete(std::string deviceType, const std::string& reason) { - if (isKeyNode) { - HaMetaMessage::keyNode_++; + if (isLiveView_) { + if (liveViewData.dataMap.find(deviceType) != liveViewData.dataMap.end()) { + liveViewData.dataMap[deviceType].delTime++; + liveViewData.countTime++; + } + } else { + if (notificationData.dataMap.find(deviceType) != notificationData.dataMap.end()) { + notificationData.dataMap[deviceType].delTime++; + notificationData.countTime++; + } } return *this; } -HaMetaMessage& HaMetaMessage::DelByWatch(bool isLiveView) +HaOperationMessage& HaOperationMessage::SyncClick(std::string deviceType) { - if (isLiveView) { - HaMetaMessage::liveViewDelByWatch_++; + if (isLiveView_) { + if (liveViewData.dataMap.find(deviceType) != liveViewData.dataMap.end()) { + liveViewData.dataMap[deviceType].clickTime++; + liveViewData.countTime++; + } } else { - HaMetaMessage::delByWatch_++; + if (notificationData.dataMap.find(deviceType) != notificationData.dataMap.end()) { + notificationData.dataMap[deviceType].clickTime++; + notificationData.countTime++; + } } return *this; } -HaMetaMessage& HaMetaMessage::ClickByWatch() +HaOperationMessage& HaOperationMessage::SyncReply(std::string deviceType) { - HaMetaMessage::clickByWatch_++; + if (isLiveView_) { + if (liveViewData.dataMap.find(deviceType) != liveViewData.dataMap.end()) { + liveViewData.dataMap[deviceType].replyTime++; + liveViewData.countTime++; + } + } else { + if (notificationData.dataMap.find(deviceType) != notificationData.dataMap.end()) { + notificationData.dataMap[deviceType].replyTime++; + notificationData.countTime++; + } + } return *this; } -HaMetaMessage& HaMetaMessage::ReplyByWatch() +bool HaOperationMessage::DetermineWhetherToSend() { - HaMetaMessage::replyByWatch_++; - return *this; + if (isLiveView_ && liveViewData.keyNode != 0) { + return true; + } + if (isLiveView_) { + if (liveViewData.countTime >= NOTIFICATION_MAX_DATA || + (NotificationAnalyticsUtil::GetCurrentTime() - liveViewData.time) >= MAX_TIME) { + return true; + } + } else { + if (notificationData.countTime >= NOTIFICATION_MAX_DATA || + (NotificationAnalyticsUtil::GetCurrentTime() - notificationData.time) >= MAX_TIME) { + return true; + } + } + return false; } -std::string HaMetaMessage::Build() const +void ResetOperationalData(OperationalData& data) { - return std::to_string(sceneId_) + MESSAGE_DELIMITER + - std::to_string(branchId_) + MESSAGE_DELIMITER + std::to_string(errorCode_) + - MESSAGE_DELIMITER + message_ + MESSAGE_DELIMITER; + data.countTime = 0; + data.keyNode = 0; + data.syncWatchHead = 0; + data.time = NotificationAnalyticsUtil::GetCurrentTime(); + for (auto& item : data.dataMap) { + item.second = { 0 }; + } +} + +void HaOperationMessage::ResetData() +{ + if (isLiveView_) { + ResetOperationalData(liveViewData); + } else { + ResetOperationalData(notificationData); + } } void NotificationAnalyticsUtil::MakeRequestBundle(const sptr& request) @@ -1317,20 +1413,24 @@ int64_t NotificationAnalyticsUtil::GetCurrentTime() return duration.count(); } -void NotificationAnalyticsUtil::ReportOperationsDotEvent(const HaMetaMessage& message) +void NotificationAnalyticsUtil::ReportOperationsDotEvent(HaOperationMessage& operationMessage) { + if (!operationMessage.DetermineWhetherToSend()) { + return; + } + if (!ReportFlowControl(ANS_CUSTOMIZE_CODE)) { - ANS_LOGE("Publish event failed, reason:%{public}s", message.Build().c_str()); + ANS_LOGE("Publish event failed, reason:%{public}s", operationMessage.ToJson().c_str()); return; } EventFwk::Want want; + HaMetaMessage message; std::string extraInfo = NotificationAnalyticsUtil::BuildExtraInfo(message); NotificationAnalyticsUtil::SetCommonWant(want, message, extraInfo); - if (!NotificationAnalyticsUtil::DetermineWhetherToSend(message.slotType_)) { - return; - } - std::string ansData = NotificationAnalyticsUtil::BuildAnsData(message); + std::string ansData = operationMessage.ToJson(); want.SetParam("ansData", ansData); + ANS_LOGI("Publish operation event :%{public}s", operationMessage.ToJson().c_str()); + operationMessage.ResetData(); IN_PROCESS_CALL_WITHOUT_RET(AddListCache(want, ANS_CUSTOMIZE_CODE)); } @@ -1349,69 +1449,6 @@ void NotificationAnalyticsUtil::ReportPublishFailedEvent(const HaMetaMessage& me 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_ + - HaMetaMessage::clickByWatch_ >= - NOTIFICATION_MAX_DATA) { - return true; - } - } else { - if ((NotificationAnalyticsUtil::GetCurrentTime() - HaMetaMessage::time_) >= MAX_TIME) { - return true; - } else if (HaMetaMessage::syncWatch_ + HaMetaMessage::syncHeadSet_ + HaMetaMessage::syncWatchHeadSet_ + - HaMetaMessage::delByWatch_ + HaMetaMessage::replyByWatch_ >= - NOTIFICATION_MAX_DATA) { - return true; - } - } - return false; -} - -std::string NotificationAnalyticsUtil::BuildAnsData(const HaMetaMessage& message) -{ - nlohmann::json ansData; - ansData["subCode"] = std::to_string(SUB_CODE); - nlohmann::json data; - data["slotType"] = std::to_string(message.slotType_); - if (message.slotType_ == NotificationConstant::SlotType::LIVE_VIEW) { - data["syncWatch"] = std::to_string(HaMetaMessage::syncLiveViewWatch_); - data["syncHeadSet"] = std::to_string(HaMetaMessage::syncLiveViewHeadSet_); - 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_); - data["syncHeadSet"] = std::to_string(HaMetaMessage::syncHeadSet_); - data["syncWatchHeadSet"] = std::to_string(HaMetaMessage::syncWatchHeadSet_); - data["delByWatch"] = std::to_string(HaMetaMessage::delByWatch_); - data["replyByWatch"] = std::to_string(HaMetaMessage::replyByWatch_); - HaMetaMessage::syncWatch_ = 0; - HaMetaMessage::syncHeadSet_ = 0; - HaMetaMessage::syncWatchHeadSet_ = 0; - HaMetaMessage::delByWatch_ = 0; - HaMetaMessage::replyByWatch_ = 0; - HaMetaMessage::time_ = NotificationAnalyticsUtil::GetCurrentTime(); - } - ansData["data"] = data.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace); - return ansData.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace); -} - void NotificationAnalyticsUtil::ReportSkipFailedEvent(const HaMetaMessage& message) { if (!ReportFlowControl(MODIFY_ERROR_EVENT_CODE)) { diff --git a/services/ans/src/notification_extension/distributed_extension_service.cpp b/services/ans/src/notification_extension/distributed_extension_service.cpp index f3cf0a9f5..37698ad0c 100644 --- a/services/ans/src/notification_extension/distributed_extension_service.cpp +++ b/services/ans/src/notification_extension/distributed_extension_service.cpp @@ -29,7 +29,7 @@ using namespace DistributedHardware; using DeviceCallback = std::function; typedef int32_t (*INIT_LOCAL_DEVICE)(const std::string &deviceId, uint16_t deviceType, - DistributedDeviceConfig config); + DistributedDeviceConfig config, DistributedHaCallbacks callbacks); typedef void (*RELEASE_LOCAL_DEVICE)(); typedef void (*ADD_DEVICE)(const std::string &deviceId, const std::string &udId, uint16_t deviceType, const std::string &networkId); @@ -199,27 +199,23 @@ int32_t DistributedExtensionService::InitDans() return -1; } + DistributedHaCallbacks distributedCallbacks = { + std::bind(&DistributedExtensionService::SendReportCallback, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3), + std::bind(&DistributedExtensionService::HADotCallback, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), + std::bind(&DistributedExtensionService::HaOperationCallback, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), + }; + ANS_LOGI("Dans get local device %{public}s, %{public}d, %{public}d, %{public}d.", StringAnonymous(deviceInfo.deviceId).c_str(), deviceInfo.deviceTypeId, deviceConfig_.maxTitleLength, deviceConfig_.maxContentLength); - if (handler(deviceInfo.deviceId, deviceInfo.deviceTypeId, deviceConfig_) != 0) { + if (handler(deviceInfo.deviceId, deviceInfo.deviceTypeId, deviceConfig_, distributedCallbacks) != 0) { 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; } @@ -291,6 +287,31 @@ void DistributedExtensionService::OnDeviceOnline(const DmDeviceInfo &deviceInfo) distributedQueue_->submit(onlineTask); } +void DistributedExtensionService::HaOperationCallback(const std::string& deviceType, int32_t sceneType, + int32_t slotType, std::string reason) +{ + bool isLiveView = (slotType == NotificationConstant::SlotType::LIVE_VIEW); + ANS_LOGI("HaOperationCallback %{public}s %{public}d %{public}d.", deviceType.c_str(), sceneType, slotType); + HaOperationMessage operation = HaOperationMessage(isLiveView); + switch (sceneType) { + case HaOperationType::COLLABORATE_DELETE: { + operation.SyncDelete(deviceType, reason); + break; + } + case HaOperationType::COLLABORATE_REPLY: { + operation.SyncReply(deviceType); + break; + } + case HaOperationType::COLLABORATE_JUMP: { + operation.SyncClick(deviceType); + break; + } + default: + return; + } + NotificationAnalyticsUtil::ReportOperationsDotEvent(operation); +} + 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()); @@ -311,27 +332,6 @@ void DistributedExtensionService::HADotCallback(int32_t code, int32_t ErrCode, u .ErrorCode(ErrCode) .Message(reason); NotificationAnalyticsUtil::ReportDeleteFailedEvent(message); - } else if (code == ANS_CUSTOMIZE_CODE) { - if (branchId == BRANCH_3) { - HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, branchId) - .ClickByWatch() - .SlotType(ErrCode); - NotificationAnalyticsUtil::ReportOperationsDotEvent(message); - } else if (branchId == BRANCH_4) { - HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, branchId) - .ReplyByWatch() - .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); - } } else if (code == MODIFY_ERROR_EVENT_CODE) { HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_20, branchId) .ErrorCode(ErrCode) diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 072a9f593..2cc6d96ca 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -33,6 +33,7 @@ #include "advanced_notification_service.h" #include "notification_analytics_util.h" +#include "bool_wrapper.h" #include "advanced_notification_inline.h" #include "liveview_all_scenarios_extension_wrapper.h" @@ -495,9 +496,6 @@ void NotificationSubscriberManager::NotifyConsumedInner( NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); 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()); @@ -514,8 +512,6 @@ void NotificationSubscriberManager::NotifyConsumedInner( continue; } record->subscriber->OnConsumed(notificationStub, notificationMap); - NotificationSubscriberManager::IsDeviceFlag( - record, notification, wearableFlag, headsetFlag, keyNodeFlag); continue; } @@ -528,10 +524,9 @@ void NotificationSubscriberManager::NotifyConsumedInner( } else { record->subscriber->OnConsumed(notification); } - NotificationSubscriberManager::IsDeviceFlag(record, notification, wearableFlag, headsetFlag, keyNodeFlag); } } - NotificationSubscriberManager::TrackCodeLog(notification, wearableFlag, headsetFlag, keyNodeFlag); + NotificationSubscriberManager::TrackCodeLog(notification); } #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED @@ -603,9 +598,7 @@ void NotificationSubscriberManager::BatchNotifyConsumedInner(const std::vectorsubscriber != nullptr) { - NotificationSubscriberManager::IsDeviceFlag( - record, notification, wearableFlag, headsetFlag, keyNodeFlag); - NotificationSubscriberManager::TrackCodeLog(notification, wearableFlag, headsetFlag, keyNodeFlag); + NotificationSubscriberManager::TrackCodeLog(notification); } } } @@ -876,10 +869,9 @@ std::list NotificationSubscriberManager::GetSubscriberRecor return subscriberRecordList_; } -void NotificationSubscriberManager::IsDeviceFlag(const std::shared_ptr &record, - const sptr ¬ification, bool &wearableFlag, bool &headsetFlag, bool &keyNodeFlag) +void NotificationSubscriberManager::TrackCodeLog(const sptr ¬ification) { - if (record == nullptr || notification == nullptr) { + if (notification == nullptr) { ANS_LOGE("null record or notification"); return; } @@ -894,70 +886,24 @@ void NotificationSubscriberManager::IsDeviceFlag(const std::shared_ptrdeviceType == 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->IsCommonLiveView()) { - auto flags = request->GetFlags(); - if (flags == nullptr) { - ANS_LOGE("null flags"); - return; - } - if (flags->IsVibrationEnabled() == NotificationConstant::FlagStatus::OPEN && - flags->IsSoundEnabled() == NotificationConstant::FlagStatus::OPEN) { - keyNodeFlag = true; + bool keyNode = false; + bool commonLiveView = request->IsCommonLiveView(); + std::shared_ptr extendInfo = request->GetExtendInfo(); + if (extendInfo != nullptr) { + auto value = extendInfo->GetParam("collaboration_node"); + AAFwk::IBoolean* ao = AAFwk::IBoolean::Query(value); + if (ao != nullptr) { + keyNode = AAFwk::Boolean::Unbox(ao); } } -} -void NotificationSubscriberManager::TrackCodeLog( - const sptr ¬ification, const bool &wearableFlag, const bool &headsetFlag, const bool &keyNodeFlag) -{ - if (notification == nullptr) { - ANS_LOGE("null notification"); - return; - } - sptr request = notification->GetNotificationRequestPoint(); - if (request == nullptr) { - ANS_LOGE("null request"); - 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) - .KeyNode(keyNodeFlag) - .SlotType(slotType); - NotificationAnalyticsUtil::ReportOperationsDotEvent(message); - } else { - if (headsetFlag) { - HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_1, EventBranchId::BRANCH_1) - .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) - .SlotType(slotType); - NotificationAnalyticsUtil::ReportOperationsDotEvent(message); - } + std::vector deviceTypes; + for (auto& flag : *flagsMap) { + deviceTypes.push_back(flag.first); } + HaOperationMessage operation = HaOperationMessage(commonLiveView).KeyNode(keyNode) + .SyncPublish(deviceTypes); + NotificationAnalyticsUtil::ReportOperationsDotEvent(operation); } ErrCode NotificationSubscriberManager::DistributeOperation( diff --git a/services/ans/test/unittest/common_utils/notification_analytics_util_test.cpp b/services/ans/test/unittest/common_utils/notification_analytics_util_test.cpp index 619742b44..9f890d970 100644 --- a/services/ans/test/unittest/common_utils/notification_analytics_util_test.cpp +++ b/services/ans/test/unittest/common_utils/notification_analytics_util_test.cpp @@ -128,161 +128,143 @@ HWTEST_F(NotificationAnalyticsUtilTest, DeleteReason_100, Function | SmallTest | } /** - * @tc.name: SyncWatch_100 - * @tc.desc: Test SyncWatch. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, SyncWatch_100, Function | SmallTest | Level1) -{ - HaMetaMessage message; - - bool isLiveView = false; - message.SyncWatch(isLiveView); - isLiveView = true; - message.SyncWatch(isLiveView); - - ASSERT_EQ(message.syncLiveViewWatch_, 1); - ASSERT_EQ(message.syncWatch_, 1); -} - -/** - * @tc.name: SyncHeadSet_100 - * @tc.desc: Test SyncHeadSet. + * @tc.name: ReportDeleteFailedEvent_100 + * @tc.desc: Test ReportDeleteFailedEvent. * @tc.type: FUNC */ -HWTEST_F(NotificationAnalyticsUtilTest, SyncHeadSet_100, Function | SmallTest | Level1) +HWTEST_F(NotificationAnalyticsUtilTest, ReportDeleteFailedEvent_100, Function | SmallTest | Level1) { HaMetaMessage message; + message.errorCode_ = ERR_OK; + message.checkfailed_ = false; + std::string bundle = "bundle"; + sptr request = new (std::nothrow) NotificationRequest(); + auto agentBundleOption = std::make_shared(bundle, DEFAULT_UID); + request->SetAgentBundle(agentBundleOption); - bool isLiveView = false; - message.SyncHeadSet(isLiveView); - isLiveView = true; - message.SyncHeadSet(isLiveView); + NotificationAnalyticsUtil::ReportDeleteFailedEvent(request, message); - ASSERT_EQ(message.syncLiveViewHeadSet_, 1); - ASSERT_EQ(message.syncHeadSet_, 1); + ASSERT_EQ(message.agentBundleName_, bundle); } /** - * @tc.name: SyncWatchHeadSet_100 - * @tc.desc: Test SyncWatchHeadSet. + * @tc.name: ReportDeleteFailedEvent_200 + * @tc.desc: Test ReportDeleteFailedEvent when no need to report. * @tc.type: FUNC */ -HWTEST_F(NotificationAnalyticsUtilTest, SyncWatchHeadSet_100, Function | SmallTest | Level1) +HWTEST_F(NotificationAnalyticsUtilTest, ReportDeleteFailedEvent_200, Function | SmallTest | Level1) { HaMetaMessage message; + message.errorCode_ = ERR_OK; + message.checkfailed_ = true; + std::string bundle = "bundle"; + sptr request = new (std::nothrow) NotificationRequest(); + auto agentBundleOption = std::make_shared(bundle, DEFAULT_UID); + request->SetAgentBundle(agentBundleOption); - bool isLiveView = false; - message.SyncWatchHeadSet(isLiveView); - isLiveView = true; - message.SyncWatchHeadSet(isLiveView); + NotificationAnalyticsUtil::ReportDeleteFailedEvent(request, message); - ASSERT_EQ(message.syncLiveViewWatchHeadSet_, 1); - ASSERT_EQ(message.syncWatchHeadSet_, 1); + ASSERT_NE(message.agentBundleName_, bundle); } /** - * @tc.name: KeyNode_100 - * @tc.desc: Test KeyNode. + * @tc.name: Operation_100 + * @tc.desc: Test Operation. * @tc.type: FUNC */ -HWTEST_F(NotificationAnalyticsUtilTest, KeyNode_100, Function | SmallTest | Level1) +HWTEST_F(NotificationAnalyticsUtilTest, Operation_100, Function | SmallTest | Level1) { - HaMetaMessage message; - - bool isKeyNode = false; - message.KeyNode(isKeyNode); - ASSERT_EQ(message.keyNode_, 0); + HaOperationMessage operationMessage = HaOperationMessage(false); + std::vector deviceTypes; + deviceTypes.push_back("abc"); + deviceTypes.push_back("pc"); + deviceTypes.push_back("pad"); + operationMessage.KeyNode(true).SyncPublish(deviceTypes); + operationMessage.ToJson(); + ASSERT_EQ(operationMessage.notificationData.countTime, 2); + operationMessage.ResetData(); - isKeyNode = true; - message.KeyNode(isKeyNode); - ASSERT_EQ(message.keyNode_, 1); + operationMessage = HaOperationMessage(true); + deviceTypes.clear(); + deviceTypes.push_back("abc"); + deviceTypes.push_back("wearable"); + deviceTypes.push_back("headset"); + operationMessage.KeyNode(false).SyncPublish(deviceTypes); + operationMessage.ToJson(); + ASSERT_EQ(operationMessage.liveViewData.countTime, 2); + ASSERT_EQ(operationMessage.liveViewData.syncWatchHead, 1); } /** - * @tc.name: DelByWatch_100 - * @tc.desc: Test DelByWatch. + * @tc.name: Operation_200 + * @tc.desc: Test Operation. * @tc.type: FUNC */ -HWTEST_F(NotificationAnalyticsUtilTest, DelByWatch_100, Function | SmallTest | Level1) +HWTEST_F(NotificationAnalyticsUtilTest, Operation_200, Function | SmallTest | Level1) { - HaMetaMessage message; + HaOperationMessage operationMessage = HaOperationMessage(false); + operationMessage.SyncDelete("pc", std::string()).SyncClick("pc").SyncReply("pc"); + operationMessage.SyncDelete("pcb", std::string()).SyncClick("pcb").SyncReply("pcb"); + operationMessage.ToJson(); - bool isLiveView = false; - message.DelByWatch(isLiveView); - isLiveView = true; - message.DelByWatch(isLiveView); + ASSERT_EQ(operationMessage.notificationData.countTime, 3); + operationMessage.ResetData(); - ASSERT_EQ(message.liveViewDelByWatch_, 1); - ASSERT_EQ(message.delByWatch_, 1); + operationMessage = HaOperationMessage(true); + operationMessage.ResetData(); + operationMessage.SyncDelete("pc", std::string()).SyncClick("pc").SyncReply("pc"); + operationMessage.SyncDelete("pcb", std::string()).SyncClick("pcb").SyncReply("pcb"); + operationMessage.ToJson(); + ASSERT_EQ(operationMessage.liveViewData.countTime, 3); } /** - * @tc.name: ClickByWatch_100 - * @tc.desc: Test ClickByWatch. + * @tc.name: Operation_300 + * @tc.desc: Test Operation. * @tc.type: FUNC */ -HWTEST_F(NotificationAnalyticsUtilTest, ClickByWatch_100, Function | SmallTest | Level1) +HWTEST_F(NotificationAnalyticsUtilTest, Operation_300, Function | SmallTest | Level1) { - HaMetaMessage message; - - message.ClickByWatch(); - - ASSERT_EQ(message.clickByWatch_, 1); -} + HaOperationMessage operationMessage = HaOperationMessage(false); + operationMessage.ResetData(); + ASSERT_EQ(operationMessage.DetermineWhetherToSend(), false); -/** - * @tc.name: ReplyByWatch_100 - * @tc.desc: Test ReplyByWatch. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, ReplyByWatch_100, Function | SmallTest | Level1) -{ - HaMetaMessage message; + operationMessage.isLiveView_ = true; + ASSERT_EQ(operationMessage.DetermineWhetherToSend(), false); - message.ReplyByWatch(); + operationMessage.isLiveView_ = false; + operationMessage.liveViewData.keyNode++; + ASSERT_EQ(operationMessage.DetermineWhetherToSend(), false); - ASSERT_EQ(message.replyByWatch_, 1); -} + operationMessage.isLiveView_ = true; + operationMessage.liveViewData.countTime = 10000; + ASSERT_EQ(operationMessage.DetermineWhetherToSend(), true); -/** - * @tc.name: ReportDeleteFailedEvent_100 - * @tc.desc: Test ReportDeleteFailedEvent. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, ReportDeleteFailedEvent_100, Function | SmallTest | Level1) -{ - HaMetaMessage message; - message.errorCode_ = ERR_OK; - message.checkfailed_ = false; - std::string bundle = "bundle"; - sptr request = new (std::nothrow) NotificationRequest(); - auto agentBundleOption = std::make_shared(bundle, DEFAULT_UID); - request->SetAgentBundle(agentBundleOption); + operationMessage.liveViewData.countTime = 10; + operationMessage.liveViewData.time = 0; + ASSERT_EQ(operationMessage.DetermineWhetherToSend(), true); - NotificationAnalyticsUtil::ReportDeleteFailedEvent(request, message); + operationMessage.isLiveView_ = false; + operationMessage.notificationData.countTime = 10000; + ASSERT_EQ(operationMessage.DetermineWhetherToSend(), true); - ASSERT_EQ(message.agentBundleName_, bundle); + operationMessage.notificationData.countTime = 10; + operationMessage.notificationData.time = 0; + ASSERT_EQ(operationMessage.DetermineWhetherToSend(), true); + operationMessage.ResetData(); } /** - * @tc.name: ReportDeleteFailedEvent_200 - * @tc.desc: Test ReportDeleteFailedEvent when no need to report. + * @tc.name: Operation_400 + * @tc.desc: Test Operation. * @tc.type: FUNC */ -HWTEST_F(NotificationAnalyticsUtilTest, ReportDeleteFailedEvent_200, Function | SmallTest | Level1) +HWTEST_F(NotificationAnalyticsUtilTest, Operation_400, Function | SmallTest | Level1) { - HaMetaMessage message; - message.errorCode_ = ERR_OK; - message.checkfailed_ = true; - std::string bundle = "bundle"; - sptr request = new (std::nothrow) NotificationRequest(); - auto agentBundleOption = std::make_shared(bundle, DEFAULT_UID); - request->SetAgentBundle(agentBundleOption); - - NotificationAnalyticsUtil::ReportDeleteFailedEvent(request, message); - - ASSERT_NE(message.agentBundleName_, bundle); + HaOperationMessage operationMessage = HaOperationMessage(true); + operationMessage.liveViewData.keyNode++; + NotificationAnalyticsUtil::ReportOperationsDotEvent(operationMessage); + ASSERT_EQ(operationMessage.liveViewData.keyNode, 0); } /** @@ -367,135 +349,6 @@ HWTEST_F(NotificationAnalyticsUtilTest, SetControlFlags_200, Function | SmallTes ASSERT_EQ(ret, 0); } -/** - * @tc.name: DetermineWhetherToSend_100 - * @tc.desc: Test DetermineWhetherToSend when key node is not 0. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, DetermineWhetherToSend_100, Function | SmallTest | Level1) -{ - uint32_t slotType = NotificationConstant::SlotType::LIVE_VIEW; - HaMetaMessage::keyNode_ = 1; - - auto ret = NotificationAnalyticsUtil::DetermineWhetherToSend(slotType); - - ASSERT_TRUE(ret); - HaMetaMessage::keyNode_ = 0; -} - -/** - * @tc.name: DetermineWhetherToSend_200 - * @tc.desc: Test DetermineWhetherToSend when slot type is LIVE_VIEW. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, DetermineWhetherToSend_200, Function | SmallTest | Level1) -{ - uint32_t slotType = NotificationConstant::SlotType::LIVE_VIEW; - HaMetaMessage::keyNode_ = 0; - HaMetaMessage::liveViewTime_ = 0; - - auto ret = NotificationAnalyticsUtil::DetermineWhetherToSend(slotType); - - ASSERT_TRUE(ret); - HaMetaMessage::liveViewTime_ = NotificationAnalyticsUtil::GetCurrentTime(); -} - -/** - * @tc.name: DetermineWhetherToSend_300 - * @tc.desc: Test DetermineWhetherToSend when slot type is LIVE_VIEW. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, DetermineWhetherToSend_300, Function | SmallTest | Level1) -{ - uint32_t slotType = NotificationConstant::SlotType::LIVE_VIEW; - HaMetaMessage::keyNode_ = 0; - HaMetaMessage::syncLiveViewWatch_ = 1000; - - auto ret = NotificationAnalyticsUtil::DetermineWhetherToSend(slotType); - - ASSERT_TRUE(ret); - HaMetaMessage::syncLiveViewWatch_ = 0; -} - -/** - * @tc.name: DetermineWhetherToSend_400 - * @tc.desc: Test DetermineWhetherToSend when slot type is LIVE_VIEW. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, DetermineWhetherToSend_400, Function | SmallTest | Level1) -{ - uint32_t slotType = NotificationConstant::SlotType::LIVE_VIEW; - HaMetaMessage::keyNode_ = 0; - - auto ret = NotificationAnalyticsUtil::DetermineWhetherToSend(slotType); - - ASSERT_FALSE(ret); -} - -/** - * @tc.name: DetermineWhetherToSend_500 - * @tc.desc: Test DetermineWhetherToSend when slot type is not LIVE_VIEW. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, DetermineWhetherToSend_500, Function | SmallTest | Level1) -{ - uint32_t slotType = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; - HaMetaMessage::keyNode_ = 0; - HaMetaMessage::time_ = 0; - - auto ret = NotificationAnalyticsUtil::DetermineWhetherToSend(slotType); - - ASSERT_TRUE(ret); - HaMetaMessage::time_ = NotificationAnalyticsUtil::GetCurrentTime(); -} - -/** - * @tc.name: DetermineWhetherToSend_600 - * @tc.desc: Test DetermineWhetherToSend when slot type is not LIVE_VIEW. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, DetermineWhetherToSend_600, Function | SmallTest | Level1) -{ - uint32_t slotType = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; - HaMetaMessage::keyNode_ = 0; - HaMetaMessage::syncWatch_ = 1000; - - auto ret = NotificationAnalyticsUtil::DetermineWhetherToSend(slotType); - - ASSERT_TRUE(ret); - HaMetaMessage::syncWatch_ = 0; -} - -/** - * @tc.name: BuildAnsData_200 - * @tc.desc: Test BuildAnsData when slot type is LIVE_VIEW. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, BuildAnsData_200, Function | SmallTest | Level1) -{ - HaMetaMessage message; - message.slotType_ = NotificationConstant::SlotType::LIVE_VIEW; - - auto ret = NotificationAnalyticsUtil::BuildAnsData(message); - - ASSERT_TRUE(ret.find("keyNode") != std::string::npos); -} - -/** - * @tc.name: BuildAnsData_300 - * @tc.desc: Test BuildAnsData when slot type is not LIVE_VIEW. - * @tc.type: FUNC - */ -HWTEST_F(NotificationAnalyticsUtilTest, BuildAnsData_300, Function | SmallTest | Level1) -{ - HaMetaMessage message; - message.slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; - - auto ret = NotificationAnalyticsUtil::BuildAnsData(message); - - ASSERT_FALSE(ret.find("keyNode") != std::string::npos); -} - /** * @tc.name: AggregateLiveView_001 * @tc.desc: Test AggregateLiveView @@ -582,4 +435,4 @@ HWTEST_F(NotificationAnalyticsUtilTest, GetReportSlotMessage_001, Function | Sma EXPECT_FALSE(res); } } -} \ No newline at end of file +} diff --git a/services/ans/test/unittest/notification_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_test.cpp index 0e3d74a8e..e688e5e4e 100644 --- a/services/ans/test/unittest/notification_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_test.cpp @@ -825,189 +825,6 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyApplicationInfoNeedChanged_001 ASSERT_TRUE(isCallback); } -// /** -// * @tc.number : IsDeviceFlag_001 -// * @tc.name : -// */ -HWTEST_F(NotificationSubscriberManagerTest, IsDeviceFlag_001, Function | SmallTest | Level1) -{ - ///build request - sptr notificationMap(new NotificationSortingMap()); - sptr request(new NotificationRequest()); - request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - std::shared_ptr liveViewContentcontent = - std::make_shared(); - std::shared_ptr content = std::make_shared(liveViewContentcontent); - request->SetContent(content); - std::shared_ptr flags = std::make_shared(); - flags->SetReminderFlags(63); - request->SetFlags(flags); - - std::shared_ptr>> notificationFlagsOfDevices = - std::make_shared>>(); - - std::shared_ptr reminderFlags = std::make_shared(); - (*notificationFlagsOfDevices)[NotificationConstant::CURRENT_DEVICE_TYPE] = flags; - request->SetDeviceFlags(notificationFlagsOfDevices); - - sptr notification(new Notification(request)); - NotificationSubscriberManager notificationSubscriberManager; - std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); - std::shared_ptr subscriberRecord = - notificationSubscriberManager.CreateSubscriberRecord(subscriber); - - bool wearableFlag = false; - bool headsetFlag = false; - bool keyNodeFlag = false; - notificationSubscriberManager.IsDeviceFlag( - subscriberRecord, notification, wearableFlag, headsetFlag, keyNodeFlag); - ASSERT_TRUE(keyNodeFlag); - - request->SetFlags(nullptr); - keyNodeFlag = false; - notificationSubscriberManager.IsDeviceFlag( - subscriberRecord, notification, wearableFlag, headsetFlag, keyNodeFlag); - ASSERT_FALSE(keyNodeFlag); -} - -HWTEST_F(NotificationSubscriberManagerTest, IsDeviceFlag_002, Function | SmallTest | Level1) -{ - ///build request - sptr notificationMap(new NotificationSortingMap()); - sptr request(new NotificationRequest()); - std::shared_ptr liveViewContentcontent = - std::make_shared(); - std::shared_ptr content = - std::make_shared(liveViewContentcontent); - request->SetContent(content); - std::shared_ptr flags = std::make_shared(); - - std::shared_ptr>> notificationFlagsOfDevices = - std::make_shared>>(); - - std::shared_ptr reminderFlags = std::make_shared(); - (*notificationFlagsOfDevices)[NotificationConstant::CURRENT_DEVICE_TYPE] = flags; - request->SetDeviceFlags(notificationFlagsOfDevices); - - sptr notification(new Notification(request)); - - NotificationSubscriberManager notificationSubscriberManager; - std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); - std::shared_ptr subscriberRecord = - notificationSubscriberManager.CreateSubscriberRecord(subscriber); - - bool wearableFlag = false; - bool headsetFlag = false; - bool keyNodeFlag = false; - - (*notificationFlagsOfDevices)[DEVICE_TYPE_LITE_WEARABLE] = flags; - sptr subscribeInfo(new NotificationSubscribeInfo()); - subscribeInfo->AddDeviceType(DEVICE_TYPE_LITE_WEARABLE); - notificationSubscriberManager.AddRecordInfo(subscriberRecord, subscribeInfo); - - notificationSubscriberManager.IsDeviceFlag( - subscriberRecord, notification, wearableFlag, headsetFlag, keyNodeFlag); - ASSERT_TRUE(wearableFlag); -} - -HWTEST_F(NotificationSubscriberManagerTest, IsDeviceFlag_003, Function | SmallTest | Level1) -{ - ///build request - sptr notificationMap(new NotificationSortingMap()); - sptr request(new NotificationRequest()); - std::shared_ptr liveViewContentcontent = - std::make_shared(); - std::shared_ptr content = - std::make_shared(liveViewContentcontent); - request->SetContent(content); - std::shared_ptr flags = std::make_shared(); - - std::shared_ptr>> notificationFlagsOfDevices = - std::make_shared>>(); - - std::shared_ptr reminderFlags = std::make_shared(); - (*notificationFlagsOfDevices)[NotificationConstant::CURRENT_DEVICE_TYPE] = flags; - request->SetDeviceFlags(notificationFlagsOfDevices); - - sptr notification(new Notification(request)); - - NotificationSubscriberManager notificationSubscriberManager; - std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); - std::shared_ptr subscriberRecord = - notificationSubscriberManager.CreateSubscriberRecord(subscriber); - - bool wearableFlag = false; - bool headsetFlag = false; - bool keyNodeFlag = false; - - (*notificationFlagsOfDevices)[DEVICE_TYPE_WEARABLE] = flags; - sptr subscribeInfo(new NotificationSubscribeInfo()); - subscribeInfo->AddDeviceType(DEVICE_TYPE_WEARABLE); - notificationSubscriberManager.AddRecordInfo(subscriberRecord, subscribeInfo); - - notificationSubscriberManager.IsDeviceFlag( - subscriberRecord, notification, wearableFlag, headsetFlag, keyNodeFlag); - ASSERT_TRUE(wearableFlag); -} - -HWTEST_F(NotificationSubscriberManagerTest, IsDeviceFlag_004, Function | SmallTest | Level1) -{ - ///build request - sptr notificationMap(new NotificationSortingMap()); - sptr request(new NotificationRequest()); - request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - request->SetLabel("label"); - request->SetCreatorUid(0); - std::shared_ptr liveViewContentcontent = - std::make_shared(); - liveViewContentcontent->SetText("notification text"); - liveViewContentcontent->SetTitle("notification title"); - std::shared_ptr content = std::make_shared(liveViewContentcontent); - request->SetContent(content); - std::shared_ptr flags = std::make_shared(); - - std::shared_ptr>> notificationFlagsOfDevices = - std::make_shared>>(); - - std::shared_ptr reminderFlags = std::make_shared(); - (*notificationFlagsOfDevices)[NotificationConstant::CURRENT_DEVICE_TYPE] = flags; - request->SetDeviceFlags(notificationFlagsOfDevices); - - sptr notification(new Notification(request)); - - NotificationSubscriberManager notificationSubscriberManager; - std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); - std::shared_ptr subscriberRecord = - notificationSubscriberManager.CreateSubscriberRecord(subscriber); - - bool wearableFlag = false; - bool headsetFlag = false; - bool keyNodeFlag = false; - - (*notificationFlagsOfDevices)[DEVICE_TYPE_HEADSET] = flags; - sptr subscribeInfo(new NotificationSubscribeInfo()); - subscribeInfo->AddDeviceType(DEVICE_TYPE_HEADSET); - notificationSubscriberManager.AddRecordInfo(subscriberRecord, subscribeInfo); - - notificationSubscriberManager.IsDeviceFlag( - subscriberRecord, notification, wearableFlag, headsetFlag, keyNodeFlag); - ASSERT_TRUE(headsetFlag); - headsetFlag = false; - - notificationSubscriberManager.IsDeviceFlag( - subscriberRecord, nullptr, wearableFlag, headsetFlag, keyNodeFlag); - ASSERT_FALSE(headsetFlag); - - sptr nullNotification(nullptr); - notificationSubscriberManager.IsDeviceFlag( - subscriberRecord, nullNotification, wearableFlag, headsetFlag, keyNodeFlag); - ASSERT_FALSE(headsetFlag); -} - /** * @tc.number : DistributeOperation_001 * @tc.name : @@ -1254,117 +1071,5 @@ HWTEST_F(NotificationSubscriberManagerTest, IsDeviceTypeAffordConsume_001, Funct ASSERT_TRUE(result); } #endif - -/** - * @tc.name: TrackCodeLog_002 - * @tc.desc: Test TrackCodeLog - * @tc.type: FUNC - */ -HWTEST_F(NotificationSubscriberManagerTest, TrackCodeLog_002, Function | SmallTest | Level1) -{ - NotificationSubscriberManager notificationSubscriberManager; - sptr notification = nullptr; - bool wearableFlag = false; - bool headsetFlag = false; - bool keyNodeFlag = false; - - notificationSubscriberManager.TrackCodeLog(notification, wearableFlag, headsetFlag, keyNodeFlag); - - ASSERT_EQ(notification, nullptr); -} - -/** - * @tc.name: TrackCodeLog_003 - * @tc.desc: Test TrackCodeLog - * @tc.type: FUNC - */ -HWTEST_F(NotificationSubscriberManagerTest, TrackCodeLog_003, Function | SmallTest | Level1) -{ - NotificationSubscriberManager notificationSubscriberManager; - sptr request = nullptr; - sptr notification = new Notification(request); - bool wearableFlag = false; - bool headsetFlag = false; - bool keyNodeFlag = false; - - notificationSubscriberManager.TrackCodeLog(notification, wearableFlag, headsetFlag, keyNodeFlag); - - ASSERT_EQ(notification->GetNotificationRequestPoint(), nullptr); -} - -/** - * @tc.name: TrackCodeLog_004 - * @tc.desc: Test TrackCodeLog - * @tc.type: FUNC - */ -HWTEST_F(NotificationSubscriberManagerTest, TrackCodeLog_004, Function | SmallTest | Level1) -{ - NotificationSubscriberManager notificationSubscriberManager; - sptr request = new NotificationRequest(); - request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - auto liveViewContent = std::make_shared(); - auto content = std::make_shared(liveViewContent); - request->SetContent(content); - sptr notification = new Notification(request); - bool wearableFlag = true; - bool headsetFlag = true; - bool keyNodeFlag = false; - - notificationSubscriberManager.TrackCodeLog(notification, wearableFlag, headsetFlag, keyNodeFlag); - - ASSERT_NE(notification->GetNotificationRequestPoint(), nullptr); - ASSERT_TRUE(wearableFlag); - ASSERT_TRUE(headsetFlag); -} - -/** - * @tc.name: TrackCodeLog_005 - * @tc.desc: Test TrackCodeLog - * @tc.type: FUNC - */ -HWTEST_F(NotificationSubscriberManagerTest, TrackCodeLog_005, Function | SmallTest | Level1) -{ - NotificationSubscriberManager notificationSubscriberManager; - sptr request = new NotificationRequest(); - request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - auto liveViewContent = std::make_shared(); - auto content = std::make_shared(liveViewContent); - request->SetContent(content); - sptr notification = new Notification(request); - bool wearableFlag = true; - bool headsetFlag = false; - bool keyNodeFlag = false; - - notificationSubscriberManager.TrackCodeLog(notification, wearableFlag, headsetFlag, keyNodeFlag); - - ASSERT_NE(notification->GetNotificationRequestPoint(), nullptr); - ASSERT_TRUE(wearableFlag); - ASSERT_FALSE(headsetFlag); -} - -/** - * @tc.name: TrackCodeLog_006 - * @tc.desc: Test TrackCodeLog - * @tc.type: FUNC - */ -HWTEST_F(NotificationSubscriberManagerTest, TrackCodeLog_006, Function | SmallTest | Level1) -{ - NotificationSubscriberManager notificationSubscriberManager; - sptr request = new NotificationRequest(); - request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - auto liveViewContent = std::make_shared(); - auto content = std::make_shared(liveViewContent); - request->SetContent(content); - sptr notification = new Notification(request); - bool wearableFlag = false; - bool headsetFlag = true; - bool keyNodeFlag = false; - - notificationSubscriberManager.TrackCodeLog(notification, wearableFlag, headsetFlag, keyNodeFlag); - - ASSERT_NE(notification->GetNotificationRequestPoint(), nullptr); - ASSERT_TRUE(headsetFlag); - ASSERT_FALSE(wearableFlag); -} } // namespace Notification } // namespace OHOS diff --git a/services/distributed/include/helper/analytics_util.h b/services/distributed/include/helper/analytics_util.h index d6f8f9926..3d23b4960 100644 --- a/services/distributed/include/helper/analytics_util.h +++ b/services/distributed/include/helper/analytics_util.h @@ -41,18 +41,20 @@ public: static AnalyticsUtil& GetInstance(); void InitHACallBack(std::function callback); void InitSendReportCallBack(std::function callback); + void InitOperationCallback(std::function callback); void SendHaReport(int32_t eventCode, int32_t errorCode, uint32_t branchId, const std::string& errorReason, int32_t code = -1); void SendEventReport(int32_t messageType, int32_t errCode, const std::string& errorReason); void AbnormalReporting(int32_t eventCode, int result, uint32_t branchId, const std::string &errorReason); - void OperationalReporting(int branchId, int32_t slotType); - + void OperationalReporting(int32_t deviceType, int32_t sceneType, int32_t slotType, + const std::string& reason = std::string()); private: AnalyticsUtil() = default; ~AnalyticsUtil() = default; std::function haCallback_ = nullptr; std::function sendReportCallback_ = nullptr; + std::function operationCallback_ = nullptr; }; } // namespace Notification } // namespace OHOS diff --git a/services/distributed/include/helper/distributed_operation_helper.h b/services/distributed/include/helper/distributed_operation_helper.h index 5da086580..70962c219 100644 --- a/services/distributed/include/helper/distributed_operation_helper.h +++ b/services/distributed/include/helper/distributed_operation_helper.h @@ -30,6 +30,7 @@ namespace OHOS { namespace Notification { struct OperationInfo { + int32_t deviceTypeId; OperationType type; std::string eventId; AAFwk::Want want; diff --git a/services/distributed/include/soft_bus/distributed_operation_service.h b/services/distributed/include/soft_bus/distributed_operation_service.h index 107244adb..fcffa04e4 100644 --- a/services/distributed/include/soft_bus/distributed_operation_service.h +++ b/services/distributed/include/soft_bus/distributed_operation_service.h @@ -33,10 +33,11 @@ public: #ifdef DISTRIBUTED_FEATURE_MASTER void ReplyOperationResponse(const std::string& hashCode, const NotificationResponseBox& responseBox, OperationType operationType, uint32_t result); - int32_t TriggerReplyApplication(const std::string& hashCode, const NotificationResponseBox& responseBox); - void TriggerJumpApplication(const std::string& hashCode); - void TriggerByOperationType( - const std::string& hashCode, const int32_t operationType, const NotificationResponseBox& responseBox); + int32_t TriggerReplyApplication(const std::string& hashCode, const int32_t deviceType, + const NotificationResponseBox& responseBox); + void TriggerJumpApplication(const std::string& hashCode, const int32_t deviceType); + void TriggerByOperationType(const std::string& hashCode, const int32_t deviceType, + const int32_t operationType, const NotificationResponseBox& responseBox); #else int32_t OnOperationResponse(const std::shared_ptr& operationInfo, const DistributedDeviceInfo& device); diff --git a/services/distributed/include/soft_bus/distributed_publish_service.h b/services/distributed/include/soft_bus/distributed_publish_service.h index 7e6e0dac7..760eb081b 100644 --- a/services/distributed/include/soft_bus/distributed_publish_service.h +++ b/services/distributed/include/soft_bus/distributed_publish_service.h @@ -35,7 +35,7 @@ public: static DistributedPublishService& GetInstance(); void RemoveNotification(const std::shared_ptr& boxMessage); void RemoveNotifications(const std::shared_ptr& boxMessage); - void BatchRemoveReport(const std::string &slotTypesString, const int result); + void BatchRemoveReport(const std::string &slotTypesString, const std::string &deviceId, const int result); int RemoveDistributedNotifications(const std::vector& hashcodes); void OnRemoveNotification(const DistributedDeviceInfo& peerDevice, std::string hashCode, int32_t slotTypes); diff --git a/services/distributed/include/soft_bus/distributed_unlock_listener_oper_service.h b/services/distributed/include/soft_bus/distributed_unlock_listener_oper_service.h index fa67c3cc3..30975302a 100644 --- a/services/distributed/include/soft_bus/distributed_unlock_listener_oper_service.h +++ b/services/distributed/include/soft_bus/distributed_unlock_listener_oper_service.h @@ -62,14 +62,26 @@ private: std::string timerHashCode_; }; +struct NotifictionJumpInfo { +public: + NotifictionJumpInfo() {} + NotifictionJumpInfo(int32_t jump, int32_t index, int32_t typeId) + : jumpType(jump), btnIndex(index), deviceTypeId(typeId) {} + int32_t jumpType; + int32_t btnIndex; + int32_t deviceTypeId; +}; + class UnlockListenerOperService { public: static UnlockListenerOperService& GetInstance(); - void AddDelayTask(const std::string& hashCode, const int32_t jumpType, const int32_t btnIndex); + void AddDelayTask(const std::string& hashCode, const int32_t jumpType, const int32_t deviceType, + const int32_t btnIndex); void ReplyOperationResponse(); void HandleOperationTimeOut(const std::string& hashCode); void RemoveOperationResponse(const std::string& hashCode); - void TriggerByJumpType(const std::string& hashCode, const int32_t jumpType, const int32_t btnIndex); + void TriggerByJumpType(const std::string& hashCode, const int32_t jumpType, + const int32_t deviceType, const int32_t btnIndex); private: UnlockListenerOperService(); @@ -86,7 +98,7 @@ private: std::shared_ptr operationQueue_ = nullptr; std::vector hashCodeOrder_; std::map timerMap_; - std::map> delayTaskMap_; + std::map delayTaskMap_; }; } // namespace OHOS } // namespace Notification diff --git a/services/distributed/libdans.map b/services/distributed/libdans.map index fbcc65573..14f12d11e 100644 --- a/services/distributed/libdans.map +++ b/services/distributed/libdans.map @@ -18,8 +18,6 @@ ReleaseDevice; RefreshDevice; ReleaseLocalDevice; - InitHACallBack; - InitSendReportCallBack; DeviceStatusChange; local: *; diff --git a/services/distributed/src/helper/analytics_util.cpp b/services/distributed/src/helper/analytics_util.cpp index 8ea5c9da5..60ad1bc86 100644 --- a/services/distributed/src/helper/analytics_util.cpp +++ b/services/distributed/src/helper/analytics_util.cpp @@ -34,6 +34,12 @@ void AnalyticsUtil::InitSendReportCallBack(std::functioncallback) +{ + operationCallback_ = callback; +} + void AnalyticsUtil::SendHaReport(int32_t eventCode, int32_t errorCode, uint32_t branchId, const std::string& errorReason, int32_t code) { @@ -55,13 +61,14 @@ void AnalyticsUtil::SendEventReport(int32_t messageType, int32_t errCode, const sendReportCallback_(messageType, errCode, errorReason); } -void AnalyticsUtil::OperationalReporting(int branchId, int32_t slotType) +void AnalyticsUtil::OperationalReporting(int32_t deviceType, int32_t sceneType, int32_t slotType, + const std::string& reason) { - if (haCallback_ == nullptr || !DistributedDeviceService::GetInstance().IsReportDataByHa()) { + if (operationCallback_ == nullptr || !DistributedDeviceService::GetInstance().IsReportDataByHa()) { return; } - std::string reason; - haCallback_(ANS_CUSTOMIZE_CODE, slotType, branchId, reason); + std::string deviceString = DistributedDeviceService::DeviceTypeToTypeString(deviceType); + operationCallback_(deviceString, sceneType, slotType, reason); } void AnalyticsUtil::AbnormalReporting(int32_t eventCode, int result, uint32_t branchId, diff --git a/services/distributed/src/helper/distributed_operation_helper.cpp b/services/distributed/src/helper/distributed_operation_helper.cpp index e9ce47284..170386b5c 100644 --- a/services/distributed/src/helper/distributed_operation_helper.cpp +++ b/services/distributed/src/helper/distributed_operation_helper.cpp @@ -80,6 +80,8 @@ void OperationService::TriggerOperation(std::string eventId) auto ret = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->StartAbility(iter->second.want)); std::string errorReason = "pull up success"; if (ret == ERR_OK) { + AnalyticsUtil::GetInstance().OperationalReporting(iter->second.deviceTypeId, + HaOperationType::COLLABORATE_JUMP, NotificationConstant::SlotType::LIVE_VIEW); AnalyticsUtil::GetInstance().SendHaReport(MODIFY_ERROR_EVENT_CODE, NotificationConstant::SlotType::LIVE_VIEW, BRANCH3_ID, errorReason, ANS_CUSTOMIZE_CODE); } else { diff --git a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp index 61312325a..a47219f1e 100644 --- a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp +++ b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp @@ -31,9 +31,12 @@ extern "C" { #endif SYMBOL_EXPORT int32_t InitLocalDevice(const std::string &deviceId, uint16_t deviceType, - DistributedDeviceConfig config) + DistributedDeviceConfig config, DistributedHaCallbacks callbacks) { ANS_LOGI("InitLocalDevice %{public}s %{public}d.", StringAnonymous(deviceId).c_str(), (int32_t)(deviceType)); + AnalyticsUtil::GetInstance().InitOperationCallback(callbacks.haOperationCallback); + AnalyticsUtil::GetInstance().InitHACallBack(callbacks.haMaintenanceCallback); + AnalyticsUtil::GetInstance().InitSendReportCallBack(callbacks.hiSysEventCallback); DistributedLocalConfig::GetInstance().SetLocalDevice(config); return DistributedService::GetInstance().InitService(deviceId, deviceType); } @@ -41,7 +44,7 @@ SYMBOL_EXPORT int32_t InitLocalDevice(const std::string &deviceId, uint16_t devi SYMBOL_EXPORT void AddDevice(const std::string &deviceId, const std::string &udid, uint16_t deviceType, const std::string &networkId) { - ANS_LOGI("InitLocalDevice %{public}s %{public}d %{public}s.", StringAnonymous(deviceId).c_str(), + ANS_LOGI("AddDevice %{public}s %{public}d %{public}s.", StringAnonymous(deviceId).c_str(), (int32_t)(deviceType), StringAnonymous(networkId).c_str()); DistributedDeviceInfo peerDevice = DistributedDeviceInfo(deviceType, deviceId, networkId); peerDevice.udid_ = udid; @@ -76,18 +79,6 @@ SYMBOL_EXPORT void ReleaseLocalDevice() DistributedService::GetInstance().DestroyService(); } -SYMBOL_EXPORT void InitHACallBack( - std::function callback) -{ - AnalyticsUtil::GetInstance().InitHACallBack(callback); -} - -SYMBOL_EXPORT void InitSendReportCallBack( - std::function callback) -{ - AnalyticsUtil::GetInstance().InitSendReportCallBack(callback); -} - #ifdef __cplusplus } #endif diff --git a/services/distributed/src/soft_bus/distributed_operation_service.cpp b/services/distributed/src/soft_bus/distributed_operation_service.cpp index d92a0b81b..7475aa14d 100644 --- a/services/distributed/src/soft_bus/distributed_operation_service.cpp +++ b/services/distributed/src/soft_bus/distributed_operation_service.cpp @@ -62,17 +62,24 @@ void DistributedOperationService::HandleNotificationOperation(const std::shared_ if (matchType != MatchType::MATCH_SYN) { return; } + std::string deviceId; + DistributedDeviceInfo device; + if (responseBox.GetLocalDeviceId(deviceId)) { + if (DistributedDeviceService::GetInstance().GetDeviceInfo(deviceId, device)) { + peerDeviceType = device.deviceType_; + } + } if (static_cast(operationType) == DISTRIBUTE_OPERATION_JUMP_BY_TYPE) { int32_t btnIndex; responseBox.GetOperationBtnIndex(btnIndex); if (!ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked()) { - UnlockListenerOperService::GetInstance().TriggerByJumpType(hashCode, jumpType, btnIndex); + UnlockListenerOperService::GetInstance().TriggerByJumpType(hashCode, jumpType, peerDeviceType, btnIndex); return; } - UnlockListenerOperService::GetInstance().AddDelayTask(hashCode, jumpType, btnIndex); + UnlockListenerOperService::GetInstance().AddDelayTask(hashCode, jumpType, peerDeviceType, btnIndex); return; } - TriggerByOperationType(hashCode, operationType, responseBox); + TriggerByOperationType(hashCode, peerDeviceType, operationType, responseBox); #else if (matchType == MatchType::MATCH_ACK) { ResponseOperationResult(hashCode, responseBox); @@ -215,7 +222,7 @@ void DistributedOperationService::ReplyOperationResponse(const std::string& hash } int32_t DistributedOperationService::TriggerReplyApplication(const std::string& hashCode, - const NotificationResponseBox& responseBox) + const int32_t deviceType, const NotificationResponseBox& responseBox) { std::string actionName; std::string userInput; @@ -245,7 +252,7 @@ int32_t DistributedOperationService::TriggerReplyApplication(const std::string& ANS_LOGI("StartAbility result:%{public}d", ret); if (ret == ERR_OK) { TriggerReplyWantAgent(request, actionName, ERR_OK, ""); - AnalyticsUtil::GetInstance().OperationalReporting(BRANCH4_ID, + AnalyticsUtil::GetInstance().OperationalReporting(deviceType, HaOperationType::COLLABORATE_REPLY, NotificationConstant::SlotType::SOCIAL_COMMUNICATION); } else { TriggerReplyWantAgent(request, actionName, ret, "ability reply failed"); @@ -256,7 +263,7 @@ int32_t DistributedOperationService::TriggerReplyApplication(const std::string& return ERR_OK; } -void DistributedOperationService::TriggerJumpApplication(const std::string& hashCode) +void DistributedOperationService::TriggerJumpApplication(const std::string& hashCode, const int32_t deviceType) { auto wantPtr = GetNotificationWantPtr(hashCode); if (wantPtr == nullptr) { @@ -274,6 +281,7 @@ void DistributedOperationService::TriggerJumpApplication(const std::string& hash if (ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked()) { OperationInfo info; + info.deviceTypeId = deviceType; info.type = OperationType::DISTRIBUTE_OPERATION_JUMP; info.eventId = std::to_string(GetCurrentTime()); sptr listener = new (std::nothrow) UnlockScreenCallback(info.eventId); @@ -290,7 +298,8 @@ void DistributedOperationService::TriggerJumpApplication(const std::string& hash auto ret = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(*wantPtr); ANS_LOGI("StartAbility result:%{public}d", ret); if (ret == ERR_OK) { - AnalyticsUtil::GetInstance().OperationalReporting(BRANCH3_ID, NotificationConstant::SlotType::LIVE_VIEW); + AnalyticsUtil::GetInstance().OperationalReporting(deviceType, HaOperationType::COLLABORATE_JUMP, + NotificationConstant::SlotType::LIVE_VIEW); } else { AnalyticsUtil::GetInstance().AbnormalReporting(MODIFY_ERROR_EVENT_CODE, 0, ret, "pull up failed"); } @@ -298,13 +307,13 @@ void DistributedOperationService::TriggerJumpApplication(const std::string& hash } } -void DistributedOperationService::TriggerByOperationType( - const std::string& hashCode, const int32_t operationType, const NotificationResponseBox& responseBox) +void DistributedOperationService::TriggerByOperationType(const std::string& hashCode, const int32_t deviceType, + const int32_t operationType, const NotificationResponseBox& responseBox) { if (static_cast(operationType) == OperationType::DISTRIBUTE_OPERATION_JUMP) { - TriggerJumpApplication(hashCode); + TriggerJumpApplication(hashCode, deviceType); } else if (static_cast(operationType) == OperationType::DISTRIBUTE_OPERATION_REPLY) { - ErrCode result = TriggerReplyApplication(hashCode, responseBox); + ErrCode result = TriggerReplyApplication(hashCode, deviceType, responseBox); ReplyOperationResponse(hashCode, responseBox, OperationType::DISTRIBUTE_OPERATION_REPLY, result); } } diff --git a/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp b/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp index 4b0b9e5b2..0da71ee42 100644 --- a/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp +++ b/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp @@ -75,9 +75,9 @@ void DistributedPublishService::RemoveNotification(const std::shared_ptr ANS_LOGW("dans remove hashCode empty"); return; } -#ifdef DISTRIBUTED_FEATURE_MASTER std::string deviceId; removeBox.GetLocalDeviceId(deviceId); +#ifdef DISTRIBUTED_FEATURE_MASTER std::shared_ptr forwardBox = MakeRemvoeBox(hashCode, slotType); if (forwardBox != nullptr) { ForWardRemove(forwardBox, deviceId); @@ -91,8 +91,13 @@ void DistributedPublishService::RemoveNotification(const std::shared_ptr std::string errorReason = "delete message failed"; if (result == 0) { errorReason = "delete message success"; + int32_t deviceType = DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH; + DistributedDeviceInfo device; + if (DistributedDeviceService::GetInstance().GetDeviceInfo(deviceId, device)) { + deviceType = device.deviceType_; + } AnalyticsUtil::GetInstance().AbnormalReporting(DELETE_ERROR_EVENT_CODE, result, BRANCH4_ID, errorReason); - AnalyticsUtil::GetInstance().OperationalReporting(OPERATION_DELETE_BRANCH, slotType); + AnalyticsUtil::GetInstance().OperationalReporting(deviceType, HaOperationType::COLLABORATE_DELETE, slotType); } else { AnalyticsUtil::GetInstance().AbnormalReporting(DELETE_ERROR_EVENT_CODE, result, BRANCH3_ID, errorReason); } @@ -118,10 +123,9 @@ void DistributedPublishService::RemoveNotifications(const std::shared_ptr forwardBox = MakeBatchRemvoeBox(hashCodes, slotTypesString); if (forwardBox != nullptr) { ForWardRemove(forwardBox, deviceId); @@ -130,7 +134,7 @@ void DistributedPublishService::RemoveNotifications(const std::shared_ptr> slotTypeString) { if (!slotTypeString.empty()) { - AnalyticsUtil::GetInstance().OperationalReporting(OPERATION_DELETE_BRANCH, - atoi(slotTypeString.c_str())); + AnalyticsUtil::GetInstance().OperationalReporting(deviceType, + HaOperationType::COLLABORATE_DELETE, atoi(slotTypeString.c_str())); } } } else { diff --git a/services/distributed/src/soft_bus/distributed_unlock_listener_oper_service.cpp b/services/distributed/src/soft_bus/distributed_unlock_listener_oper_service.cpp index 8f78c52b2..6f89570a4 100644 --- a/services/distributed/src/soft_bus/distributed_unlock_listener_oper_service.cpp +++ b/services/distributed/src/soft_bus/distributed_unlock_listener_oper_service.cpp @@ -22,6 +22,8 @@ #include "notification_constant.h" #include "notification_helper.h" #include "time_service_client.h" +#include "analytics_util.h" +#include "distributed_data_define.h" namespace OHOS { namespace Notification { @@ -49,8 +51,8 @@ UnlockListenerOperService::UnlockListenerOperService() ANS_LOGI("Operation service init successfully."); } -void UnlockListenerOperService::AddDelayTask( - const std::string& hashCode, const int32_t jumpType, const int32_t btnIndex) +void UnlockListenerOperService::AddDelayTask(const std::string& hashCode, const int32_t jumpType, + const int32_t deviceType, const int32_t btnIndex) { int32_t timeout = OPERATION_TIMEOUT; int64_t expiredTime = GetCurrentTime() + timeout; @@ -68,7 +70,8 @@ void UnlockListenerOperService::AddDelayTask( ANS_LOGW("Operation delayTask has same key %{public}s.", hashCode.c_str()); delayTaskMap_.erase(iterDelayTask); } - delayTaskMap_.insert_or_assign(hashCode, std::make_pair(jumpType, btnIndex)); + NotifictionJumpInfo jumpInfo = NotifictionJumpInfo(jumpType, btnIndex, deviceType); + delayTaskMap_.insert_or_assign(hashCode, jumpInfo); auto iterTimer = timerMap_.find(hashCode); if (iterTimer != timerMap_.end()) { @@ -121,7 +124,8 @@ void UnlockListenerOperService::ReplyOperationResponse() for (std::string hashCode : hashCodeOrder_) { auto iterDelayTask = delayTaskMap_.find(hashCode); if (iterDelayTask != delayTaskMap_.end()) { - TriggerByJumpType(hashCode, iterDelayTask->second.first, iterDelayTask->second.second); + TriggerByJumpType(hashCode, iterDelayTask->second.jumpType, iterDelayTask->second.deviceTypeId, + iterDelayTask->second.btnIndex); delayTaskMap_.erase(iterDelayTask); } @@ -151,8 +155,8 @@ void UnlockListenerOperService::HandleOperationTimeOut(const std::string& hashCo }); } -void UnlockListenerOperService::TriggerByJumpType( - const std::string& hashCode, const int32_t jumpType, const int32_t btnIndex) +void UnlockListenerOperService::TriggerByJumpType(const std::string& hashCode, const int32_t jumpType, + const int32_t deviceType, const int32_t btnIndex) { sptr notificationRequest = nullptr; auto result = NotificationHelper::GetNotificationRequestByHashCode(hashCode, notificationRequest); @@ -160,6 +164,7 @@ void UnlockListenerOperService::TriggerByJumpType( ANS_LOGE("Check notificationRequest is null."); return; } + NotificationConstant::SlotType slotType = notificationRequest->GetSlotType(); std::shared_ptr wantAgentPtr = nullptr; if (jumpType >= NotificationConstant::DISTRIBUTE_JUMP_BY_LIVE_VIEW) { if (!notificationRequest->IsCommonLiveView()) { @@ -168,20 +173,21 @@ void UnlockListenerOperService::TriggerByJumpType( } ErrCode res = DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->DistributedLiveViewOperation( notificationRequest, jumpType, btnIndex); + AnalyticsUtil::GetInstance().OperationalReporting(deviceType, HaOperationType::COLLABORATE_JUMP, slotType); ANS_LOGI("DistributedLiveViewOperation res: %{public}d.", static_cast(res)); return; } bool triggerWantInner; - ErrCode res = DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->DistributedAncoNotificationClick( - notificationRequest, triggerWantInner); - if (res != ERR_OK) { + if (DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->DistributedAncoNotificationClick( + notificationRequest, triggerWantInner) != ERR_OK) { return; } - if (triggerWantInner && res == ERR_OK) { + if (triggerWantInner) { std::vector hashcodes; hashcodes.push_back(hashCode); NotificationHelper::RemoveNotifications( hashcodes, NotificationConstant::DISTRIBUTED_COLLABORATIVE_CLICK_DELETE); + AnalyticsUtil::GetInstance().OperationalReporting(deviceType, HaOperationType::COLLABORATE_JUMP, slotType); return; } if (jumpType == NotificationConstant::DISTRIBUTE_JUMP_BY_NTF) { @@ -195,6 +201,7 @@ void UnlockListenerOperService::TriggerByJumpType( return; } if (LaunchWantAgent(wantAgentPtr) == ERR_OK) { + AnalyticsUtil::GetInstance().OperationalReporting(deviceType, HaOperationType::COLLABORATE_JUMP, slotType); std::vector hashcodes; hashcodes.push_back(hashCode); NotificationHelper::RemoveNotifications( -- Gitee