diff --git a/services/ans/include/notification_analytics_util.h b/services/ans/include/notification_analytics_util.h index 9f4edca4ba55a4bce0516899580656bc11eb9455..a7cce3a7b2af08b41ef78d5105b337b513d1d68c 100644 --- a/services/ans/include/notification_analytics_util.h +++ b/services/ans/include/notification_analytics_util.h @@ -174,6 +174,8 @@ struct ReportLiveViewMessage { class NotificationAnalyticsUtil { public: + static void ReportTipsEvent(const sptr& request, const HaMetaMessage& message); + static void ReportPublishFailedEvent(const sptr& request, const HaMetaMessage& message); static void ReportDeleteFailedEvent(const sptr& request, HaMetaMessage& message); @@ -288,6 +290,8 @@ private: static void AddLocalLiveViewSuccessNum(std::string bundle); static void AddLocalLiveViewFailedNum(std::string bundle); + + static void MakeRequestBundle(const sptr& request); }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 06a181d1446e00a3cad629380b1b3a8c93b87308..3be89158f42d8df5c4221895f041d222ffdf09fe 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1809,11 +1809,14 @@ ErrCode AdvancedNotificationService::PushCheck(const sptr & if (result != ERR_OK) { HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_2, EventBranchId::BRANCH_5) .ErrorCode(result).Message("Push OnCheckNotification failed."); - NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); if (AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) && AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER)) { ANS_LOGI("The application with the permission fails to pushcheck."); + NotificationAnalyticsUtil::ReportTipsEvent(request, message); result = ERR_OK; + } else { + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); + return result; } } if (pushCallBackParam != nullptr && !pushCallBackParam->eventControl.empty() && extroInfo != nullptr) { diff --git a/services/ans/src/common/notification_analytics_util.cpp b/services/ans/src/common/notification_analytics_util.cpp index a98c52aa8228e9704e1e8fd9427fffa022d66fe5..d0f9dc245d4d6cb512168f5188306b205ac5b312 100644 --- a/services/ans/src/common/notification_analytics_util.cpp +++ b/services/ans/src/common/notification_analytics_util.cpp @@ -31,6 +31,7 @@ #include "notification_preferences.h" #include "os_account_manager_helper.h" #include "notification_constant.h" +#include "advanced_notification_inline.h" namespace OHOS { namespace Notification { @@ -291,12 +292,31 @@ std::string HaMetaMessage::Build() const MESSAGE_DELIMITER + message_ + MESSAGE_DELIMITER; } +void NotificationAnalyticsUtil::MakeRequestBundle(const sptr& request) +{ + if (request->GetOwnerBundleName().empty() && request->GetCreatorBundleName().empty()) { + request->SetCreatorUid(IPCSkeleton::GetCallingUid()); + request->SetCreatorBundleName(GetClientBundleName()); + } +} + +void NotificationAnalyticsUtil::ReportTipsEvent(const sptr& request, + const HaMetaMessage& message) +{ + if (request == nullptr) { + return; + } + MakeRequestBundle(request); + CommonNotificationEvent(request, PUBLISH_ERROR_EVENT_CODE, message); +} + void NotificationAnalyticsUtil::ReportPublishFailedEvent(const sptr& request, const HaMetaMessage& message) { if (request == nullptr) { return; } + MakeRequestBundle(request); CommonNotificationEvent(request, PUBLISH_ERROR_EVENT_CODE, message); ReportLiveViewNumber(request, PUBLISH_ERROR_EVENT_CODE); } @@ -347,13 +367,15 @@ void NotificationAnalyticsUtil::ReportPublishSuccessEvent(const sptr& request, const int32_t reportType) { NotificationNapi::ContentType contentType; + std::string bundleName = request->GetOwnerBundleName().empty() ? request->GetCreatorBundleName() : + request->GetOwnerBundleName(); NotificationNapi::AnsEnumUtil::ContentTypeCToJS( static_cast(request->GetNotificationType()), contentType); if (contentType == NotificationNapi::ContentType::NOTIFICATION_CONTENT_LIVE_VIEW) { auto content = request->GetContent()->GetNotificationContent(); auto liveViewContent = std::static_pointer_cast(content); if (liveViewContent->GetExtraInfo() != nullptr) { - std::string bundle = request->GetOwnerBundleName() + MESSAGE_DELIMITER + + std::string bundle = bundleName + MESSAGE_DELIMITER + liveViewContent->GetExtraInfo()->GetStringParam("event"); std::lock_guard lock(ReportLiveViewMessageMutex_); if (reportType == ANS_CUSTOMIZE_CODE) { @@ -366,7 +388,7 @@ void NotificationAnalyticsUtil::ReportLiveViewNumber(const sptr lock(ReportLiveViewMessageMutex_); - std::string bundle = request->GetOwnerBundleName() + "#-99"; + std::string bundle = bundleName + "#-99"; if (reportType == ANS_CUSTOMIZE_CODE) { AddLocalLiveViewSuccessNum(bundle); } else if (reportType == PUBLISH_ERROR_EVENT_CODE) {