From 4399a8e138b56b0d29b3a3a1983c3334136063f1 Mon Sep 17 00:00:00 2001 From: z30053788 Date: Thu, 5 Jun 2025 19:35:37 +0800 Subject: [PATCH] update Signed-off-by: z30053788 Change-Id: I19b4b1a68638645e5ff5627a6ae76c336cef8685 --- .../ans/include/notification_analytics_util.h | 4 ++++ .../ans/src/advanced_notification_service.cpp | 5 +++- .../common/notification_analytics_util.cpp | 23 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/services/ans/include/notification_analytics_util.h b/services/ans/include/notification_analytics_util.h index 9f4edca4b..a7cce3a7b 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 06a181d14..3be89158f 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 e84d44773..592371397 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,9 +292,25 @@ 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) +{ + MakeRequestBundle(request); + CommonNotificationEvent(request, PUBLISH_ERROR_EVENT_CODE, message); +} + void NotificationAnalyticsUtil::ReportPublishFailedEvent(const sptr& request, const HaMetaMessage& message) { + MakeRequestBundle(request); CommonNotificationEvent(request, PUBLISH_ERROR_EVENT_CODE, message); ReportLiveViewNumber(request, PUBLISH_ERROR_EVENT_CODE); } @@ -344,13 +361,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) { @@ -363,7 +382,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) { -- Gitee