From dc7f979468b139c5589ec598e465c545c202c572 Mon Sep 17 00:00:00 2001 From: wufarong Date: Tue, 6 May 2025 15:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=88=86=E6=94=AF=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wufarong Change-Id: If2f1e21d07a56c32c8eb2728940f68dcbe482283 --- .../include/advanced_notification_service.h | 2 +- .../ans/include/notification_analytics_util.h | 22 +++++++ ...dvanced_notification_live_view_service.cpp | 43 ++++---------- .../advanced_notification_publish_service.cpp | 50 +++++++++------- .../ans/src/advanced_notification_service.cpp | 57 +++++++++++++++++-- .../advanced_notification_slot_service.cpp | 4 +- .../src/notification_preferences_database.cpp | 15 +++++ .../ans/src/system_dialog_connect_stb.cpp | 6 ++ ...ed_notification_live_view_service_test.cpp | 20 +------ 9 files changed, 141 insertions(+), 78 deletions(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 93ce0ab67..38d2378f3 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1456,7 +1456,6 @@ private: ErrCode FillNotificationRecord(const NotificationRequestDb &requestdbObj, std::shared_ptr record); static int32_t SetNotificationRequestToDb(const NotificationRequestDb &requestDb); - static int32_t GetNotificationRequestFromDb(const std::string &key, NotificationRequestDb &requestDb); static int32_t GetBatchNotificationRequestsFromDb(std::vector &requests, int32_t userId = -1); static int32_t DoubleDeleteNotificationFromDb(const std::string &key, @@ -1562,6 +1561,7 @@ private: const sptr bundleOption, const bool innerLake); void ClearSlotTypeData(const sptr &request, int32_t callingUid, int32_t sourceType); + ErrCode RegisterPushCallbackTokenCheck(); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) diff --git a/services/ans/include/notification_analytics_util.h b/services/ans/include/notification_analytics_util.h index 76537a62e..292ec786d 100644 --- a/services/ans/include/notification_analytics_util.h +++ b/services/ans/include/notification_analytics_util.h @@ -36,9 +36,19 @@ enum EventSceneId { SCENE_9 = 9, SCENE_10 = 10, SCENE_11 = 11, + SCENE_12 = 12, + SCENE_13 = 13, + SCENE_14 = 14, + SCENE_15 = 15, + SCENE_16 = 16, + SCENE_17 = 17, + SCENE_18 = 18, + SCENE_19 = 19, SCENE_20 = 20, SCENE_21 = 21, SCENE_22 = 22, + SCENE_23 = 23, + SCENE_24 = 24, }; enum EventBranchId { @@ -51,6 +61,18 @@ enum EventBranchId { BRANCH_6 = 6, BRANCH_7 = 7, BRANCH_8 = 8, + BRANCH_9 = 9, + BRANCH_10 = 10, + BRANCH_11 = 11, + BRANCH_12 = 12, + BRANCH_13 = 13, + BRANCH_14 = 14, + BRANCH_15 = 15, + BRANCH_16 = 16, + BRANCH_17 = 17, + BRANCH_18 = 18, + BRANCH_19 = 19, + BRANCH_20 = 20, }; class HaMetaMessage { public: diff --git a/services/ans/src/advanced_notification_live_view_service.cpp b/services/ans/src/advanced_notification_live_view_service.cpp index ecc8f3151..5366181e6 100644 --- a/services/ans/src/advanced_notification_live_view_service.cpp +++ b/services/ans/src/advanced_notification_live_view_service.cpp @@ -286,38 +286,6 @@ int32_t AdvancedNotificationService::SetNotificationRequestToDb(const Notificati return result; } -int32_t AdvancedNotificationService::GetNotificationRequestFromDb( - const std::string &key, NotificationRequestDb &requestDb) -{ - std::string value; - int32_t userId = -1; - OsAccountManagerHelper::GetInstance().GetCurrentCallingUserId(userId); - int32_t result = NotificationPreferences::GetInstance()->GetKvFromDb(key, value, userId); - if (result != ERR_OK) { - ANS_LOGE("Get notification request failed, key %{public}s.", key.c_str()); - return result; - } - auto jsonObject = nlohmann::json::parse(value); - auto *request = NotificationJsonConverter::ConvertFromJson(jsonObject); - if (request == nullptr) { - ANS_LOGE("Parse json string to request failed, str: %{public}s.", value.c_str()); - return ERR_ANS_TASK_ERR; - } - auto *bundleOption = NotificationJsonConverter::ConvertFromJson(jsonObject); - if (bundleOption == nullptr) { - delete request; - ANS_LOGE("Parse json string to bundle option failed, str: %{public}s.", value.c_str()); - return ERR_ANS_TASK_ERR; - } - - if (GetLockScreenPictureFromDb(request) != ERR_OK) { - ANS_LOGE("Get request lock screen picture failed, key %{public}s.", key.c_str()); - } - requestDb.request = request; - requestDb.bundleOption = bundleOption; - return ERR_OK; -} - int32_t AdvancedNotificationService::GetBatchNotificationRequestsFromDb( std::vector &requests, int32_t userId) { @@ -483,10 +451,17 @@ ErrCode AdvancedNotificationService::SetLockScreenPictureToDb(const sptrGetKey(); std::vector pixelsVec; uint32_t res = NotificationPreferences::GetInstance()->GetByteFromDb(key, pixelsVec, request->GetReceiverUserId()); if (res != ERR_OK) { + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(res).BranchId(BRANCH_1)); ANS_LOGE("Failed to get lock screen picture from db, res is %{public}d.", res); return res; } @@ -495,6 +470,7 @@ ErrCode AdvancedNotificationService::GetLockScreenPictureFromDb(NotificationRequ auto imageSource = Media::ImageSource::CreateImageSource((const uint8_t *)pixelsVec.data(), pixelsVec.size(), sourceOptions, res); if (res != ERR_OK) { + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(res).BranchId(BRANCH_2)); ANS_LOGE("Failed to create image source, res is %{public}d.", res); return res; } @@ -502,6 +478,7 @@ ErrCode AdvancedNotificationService::GetLockScreenPictureFromDb(NotificationRequ Media::DecodeOptions decodeOpts; auto pixelMapPtr = imageSource->CreatePixelMap(decodeOpts, res); if (res != ERR_OK) { + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(res).BranchId(BRANCH_3)); ANS_LOGE("Failed to create pixel map, res is %{public}d.", res); return res; } @@ -571,6 +548,7 @@ uint64_t AdvancedNotificationService::StartDelayPublishTimer( { ANS_LOGD("Enter"); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_12, EventBranchId::BRANCH_4); wptr wThis = this; auto timeoutFunc = [wThis, ownerUid, notificationId] { sptr sThis = wThis.promote(); @@ -584,6 +562,7 @@ uint64_t AdvancedNotificationService::StartDelayPublishTimer( sptr timer = MiscServices::TimeServiceClient::GetInstance(); if (timer == nullptr) { ANS_LOGE("Failed to start timer due to get TimeServiceClient is null."); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(NotificationConstant::INVALID_TIMER_ID)); return NotificationConstant::INVALID_TIMER_ID; } diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 63624547c..768efbbd6 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -579,6 +579,10 @@ ErrCode AdvancedNotificationService::CancelAsBundle( int32_t errCode = CheckUserIdParams(userId); if (errCode != ERR_OK) { + std::string message = "userId:" + std::to_string(userId); + HaMetaMessage haMateMessage = HaMetaMessage(EventSceneId::SCENE_13, EventBranchId::BRANCH_14) + .ErrorCode(errCode).NotificationId(notificationId); + ReportDeleteFailedEventPush(haMateMessage, reason, message); return errCode; } @@ -918,26 +922,27 @@ ErrCode AdvancedNotificationService::DeleteAll() ErrCode AdvancedNotificationService::SetShowBadgeEnabledForBundle( const sptr &bundleOption, bool enabled) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_13, EventBranchId::BRANCH_0); if (bundleOption == nullptr) { ANS_LOGE("BundleOption is null."); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(ERR_ANS_INVALID_BUNDLE)); return ERR_ANS_INVALID_BUNDLE; } - HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_8, EventBranchId::BRANCH_3); message.Message(bundleOption->GetBundleName() + "_" + std::to_string(bundleOption->GetUid()) + - " enabled:" + std::to_string(enabled)); + " en" + std::to_string(enabled)); bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { ANS_LOGE("IsSystemApp is false."); - message.ErrorCode(ERR_ANS_NON_SYSTEM_APP).Append(" Not SystemApp"); + message.ErrorCode(ERR_ANS_NON_SYSTEM_APP).BranchId(BRANCH_1); NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NON_SYSTEM_APP; } if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { ANS_LOGE("Permission Denied."); - message.ErrorCode(ERR_ANS_PERMISSION_DENIED).Append(" Permission Denied"); + message.ErrorCode(ERR_ANS_PERMISSION_DENIED).BranchId(BRANCH_2); NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_PERMISSION_DENIED; } @@ -964,7 +969,7 @@ ErrCode AdvancedNotificationService::SetShowBadgeEnabledForBundle( notificationSvrQueue_->wait(handler); ANS_LOGI("%{public}s_%{public}d, enabled: %{public}s, Set show badge enabled for bundle result: %{public}d", bundleOption->GetBundleName().c_str(), bundleOption->GetUid(), std::to_string(enabled).c_str(), result); - message.ErrorCode(result); + message.ErrorCode(result).BranchId(BRANCH_3); NotificationAnalyticsUtil::ReportModifyEvent(message); return result; } @@ -1056,9 +1061,13 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string const sptr &callback, const sptr &callerToken) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_13, EventBranchId::BRANCH_4); + message.Message(" de:" + deviceId); ANS_LOGD("%{public}s", __FUNCTION__); if (callback == nullptr) { ANS_LOGE("callback == nullptr"); + message.ErrorCode(ERR_ANS_INVALID_PARAM); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_INVALID_PARAM; } sptr bundleOption = GenerateBundleOption(); @@ -1207,21 +1216,23 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForAllBundles(const ErrCode AdvancedNotificationService::SetNotificationsEnabledForSpecialBundle( const std::string &deviceId, const sptr &bundleOption, bool enabled) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_13, EventBranchId::BRANCH_5); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("%{public}s", __FUNCTION__); if (bundleOption == nullptr) { ANS_LOGE("BundleOption is null."); + message.ErrorCode(ERR_ANS_INVALID_BUNDLE); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_INVALID_BUNDLE; } - HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_8, EventBranchId::BRANCH_4); message.Message(bundleOption->GetBundleName() + "_" + std::to_string(bundleOption->GetUid()) + - " enabled:" + std::to_string(enabled) + - " deviceId:" + deviceId); + " en:" + std::to_string(enabled) + + " dId:" + deviceId); bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { ANS_LOGE("IsSystemApp is false."); - message.ErrorCode(ERR_ANS_NON_SYSTEM_APP).Append(" Not SystemApp"); + message.ErrorCode(ERR_ANS_NON_SYSTEM_APP).BranchId(BRANCH_6); NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NON_SYSTEM_APP; } @@ -1229,14 +1240,14 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForSpecialBundle( int32_t callingUid = IPCSkeleton::GetCallingUid(); if (callingUid != ANS_UID && !AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { ANS_LOGE("Permission Denied."); - message.ErrorCode(ERR_ANS_PERMISSION_DENIED).Append(" Permission Denied"); + message.ErrorCode(ERR_ANS_PERMISSION_DENIED).BranchId(BRANCH_7); NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_PERMISSION_DENIED; } sptr bundle = GenerateValidBundleOption(bundleOption); if (bundle == nullptr) { - message.ErrorCode(ERR_ANS_INVALID_BUNDLE).Append(" Bundle is nullptr."); + message.ErrorCode(ERR_ANS_INVALID_BUNDLE).BranchId(BRANCH_8); NotificationAnalyticsUtil::ReportModifyEvent(message); ANS_LOGE(" Bundle is nullptr."); return ERR_ANS_INVALID_BUNDLE; @@ -1268,7 +1279,7 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForSpecialBundle( ANS_LOGI("%{public}s_%{public}d, deviceId: %{public}s, enable: %{public}s, " "Set notifications enabled for special bundle result: %{public}d", bundleOption->GetBundleName().c_str(), bundleOption->GetUid(), deviceId.c_str(), std::to_string(enabled).c_str(), result); - message.ErrorCode(result); + message.ErrorCode(result).BranchId(BRANCH_9); NotificationAnalyticsUtil::ReportModifyEvent(message); SendEnableNotificationHiSysEvent(bundleOption, enabled, result); return result; @@ -2878,28 +2889,26 @@ ErrCode AdvancedNotificationService::SubscribeLocalLiveView( ErrCode AdvancedNotificationService::SetDistributedEnabledByBundle(const sptr &bundleOption, const std::string &deviceType, const bool enabled) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_13, EventBranchId::BRANCH_10); ANS_LOGD("%{public}s", __FUNCTION__); if (bundleOption == nullptr) { ANS_LOGE("BundleOption is null."); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(ERR_ANS_NON_SYSTEM_APP)); return ERR_ANS_INVALID_BUNDLE; } - HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_9, EventBranchId::BRANCH_3); message.Message(bundleOption->GetBundleName() + "_" + std::to_string(bundleOption->GetUid()) + - " enabled:" + std::to_string(enabled) + - " deviceType:" + deviceType); + " en:" + std::to_string(enabled) + " dT:" + deviceType); bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { ANS_LOGE("IsSystemApp is false."); - message.ErrorCode(ERR_ANS_NON_SYSTEM_APP).Append("Not SystemApp"); - NotificationAnalyticsUtil::ReportModifyEvent(message); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(ERR_ANS_NON_SYSTEM_APP).BranchId(BRANCH_11)); return ERR_ANS_NON_SYSTEM_APP; } if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { ANS_LOGE("Permission Denied."); - message.ErrorCode(ERR_ANS_PERMISSION_DENIED).Append("No permission"); - NotificationAnalyticsUtil::ReportModifyEvent(message); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(ERR_ANS_PERMISSION_DENIED).BranchId(BRANCH_12)); return ERR_ANS_PERMISSION_DENIED; } @@ -2914,8 +2923,7 @@ ErrCode AdvancedNotificationService::SetDistributedEnabledByBundle(const sptrGetBundleName().c_str(), bundleOption->GetUid(), deviceType.c_str(), std::to_string(enabled).c_str(), result); - message.ErrorCode(result); - NotificationAnalyticsUtil::ReportModifyEvent(message); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(result).BranchId(BRANCH_13)); return result; } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 2c25b77a0..0dc1ca876 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -122,12 +122,15 @@ ErrCode AdvancedNotificationService::PrepareNotificationRequest(const sptrGetOwnerUserId()); } if (uid < 0) { + message.ErrorCode(ERR_ANS_INVALID_UID).BranchId(BRANCH_2); + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); return ERR_ANS_INVALID_UID; } } else { int32_t userId = SUBSCRIBE_USER_INIT; if (request->GetOwnerUid() < DEFAULT_UID) { + message.ErrorCode(ERR_ANS_GET_ACTIVE_USER_FAILED).BranchId(BRANCH_3); + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); return ERR_ANS_GET_ACTIVE_USER_FAILED; } if (request->GetOwnerUid() == DEFAULT_UID) { @@ -171,6 +178,8 @@ ErrCode AdvancedNotificationService::PrepareNotificationRequest(const sptrGetBundleOption()->GetUid() < DEFAULT_UID) { + message.ErrorCode(ERR_ANS_INVALID_UID).BranchId(BRANCH_5); + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); return ERR_ANS_INVALID_UID; } int32_t uid = -1; @@ -604,8 +615,10 @@ ErrCode AdvancedNotificationService::StartAutoDeletedTimer(const std::shared_ptr ErrCode AdvancedNotificationService::FillNotificationRecord( const NotificationRequestDb &requestdbObj, std::shared_ptr record) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_14, EventBranchId::BRANCH_6); if (requestdbObj.request == nullptr || requestdbObj.bundleOption == nullptr || record == nullptr) { ANS_LOGE("Invalid param."); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(ERR_ANS_INVALID_PARAM)); return ERR_ANS_INVALID_PARAM; } @@ -819,8 +832,10 @@ void AdvancedNotificationService::ReportDoNotDisturbModeChanged(const int32_t &u void AdvancedNotificationService::CheckDoNotDisturbProfile(const std::shared_ptr &record) { ANS_LOGD("Called."); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_14, EventBranchId::BRANCH_7); if (record == nullptr || record->notification == nullptr || record->bundleOption == nullptr) { ANS_LOGE("Make notification record failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return; } int32_t userId = record->notification->GetRecvUserId(); @@ -855,10 +870,14 @@ void AdvancedNotificationService::CheckDoNotDisturbProfile(const std::shared_ptr if (NotificationPreferences::GetInstance()->GetDoNotDisturbProfile(atoll(profileId.c_str()), userId, profile) != ERR_OK) { ANS_LOGE("profile failed. pid: %{public}s, userid: %{public}d", profileId.c_str(), userId); + //ceshi + message.Message("profileid:" + profileId + ",userid:" + std::to_string(userId)); + NotificationAnalyticsUtil::ReportModifyEvent(message.BranchId(BRANCH_8)); return; } if (profile == nullptr) { ANS_LOGE("The do not disturb profile is nullptr."); + NotificationAnalyticsUtil::ReportModifyEvent(message.BranchId(BRANCH_9)); return; } auto uid = record->bundleOption->GetUid(); @@ -877,13 +896,16 @@ void AdvancedNotificationService::CheckDoNotDisturbProfile(const std::shared_ptr void AdvancedNotificationService::DoNotDisturbUpdataReminderFlags(const std::shared_ptr &record) { ANS_LOGD("Called."); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_14, EventBranchId::BRANCH_10); if (record == nullptr || record->request == nullptr || record->notification == nullptr) { ANS_LOGE("Make notification record failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return; } auto flags = record->request->GetFlags(); if (flags == nullptr) { ANS_LOGE("The flags is nullptr."); + NotificationAnalyticsUtil::ReportPublishFailedEvent(record->request, message.BranchId(BRANCH_11)); return; } flags->SetSoundEnabled(NotificationConstant::FlagStatus::CLOSE); @@ -954,8 +976,8 @@ bool AdvancedNotificationService::IsNotificationExists(const std::string &key) ErrCode AdvancedNotificationService::Filter(const std::shared_ptr &record, bool isRecover) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_14, EventBranchId::BRANCH_12); ErrCode result = ERR_OK; - if (!isRecover) { auto oldRecord = GetFromNotificationList(record->notification->GetKey()); result = record->request->CheckNotificationRequest((oldRecord == nullptr) ? nullptr : oldRecord->request); @@ -963,8 +985,7 @@ ErrCode AdvancedNotificationService::Filter(const std::shared_ptrrequest->IsCommonLiveView(); int32_t slotType = liveView ? NotificationConstant::SlotType::LIVE_VIEW : NotificationConstant::SlotType::ILLEGAL_TYPE; - HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_3, EventBranchId::BRANCH_5) - .ErrorCode(result).SlotType(slotType).Message("CheckNotificationRequest failed: "); + message.ErrorCode(result).SlotType(slotType); NotificationAnalyticsUtil::ReportPublishFailedEvent(record->request, message); ANS_LOGE("Notification(key %{public}s) isn't ready on publish failed with %{public}d.", record->notification->GetKey().c_str(), result); @@ -974,6 +995,8 @@ ErrCode AdvancedNotificationService::Filter(const std::shared_ptrrequest, message); return ERR_ANS_INVALID_PARAM; } @@ -996,8 +1019,11 @@ void AdvancedNotificationService::ChangeNotificationByControlFlags(const std::sh const bool isAgentController) { ANS_LOGD("Called."); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_14, EventBranchId::BRANCH_14). + Message("iAC:" + std::to_string(isAgentController)); if (record == nullptr || record->request == nullptr || record->notification == nullptr) { ANS_LOGE("Make notification record failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return; } uint32_t notificationControlFlags = record->request->GetNotificationControlFlags(); @@ -1013,6 +1039,7 @@ void AdvancedNotificationService::ChangeNotificationByControlFlags(const std::sh auto flags = record->request->GetFlags(); if (flags == nullptr) { ANS_LOGE("The flags is nullptr."); + NotificationAnalyticsUtil::ReportPublishFailedEvent(record->request, message.BranchId(BRANCH_15)); return; } @@ -1943,8 +1970,12 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDate(int32_t userId, { ANS_LOGD("%{public}s", __FUNCTION__); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_14, EventBranchId::BRANCH_16); + message.Message("userId:" + std::to_string(userId)); if (userId <= SUBSCRIBE_USER_INIT) { ANS_LOGE("Input userId is invalidity."); + message.ErrorCode(ERR_ANS_INVALID_PARAM); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_INVALID_PARAM; } @@ -2079,8 +2110,7 @@ void AdvancedNotificationService::ResetPushCallbackProxy() pushCallBacks_.clear(); } -ErrCode AdvancedNotificationService::RegisterPushCallback( - const sptr &pushCallback, const sptr ¬ificationCheckRequest) +ErrCode AdvancedNotificationService::RegisterPushCallbackTokenCheck() { bool isSubSystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); if (!isSubSystem && !AccessTokenHelper::IsSystemApp()) { @@ -2097,14 +2127,26 @@ ErrCode AdvancedNotificationService::RegisterPushCallback( ANS_LOGW("Not have OHOS_PERMISSION_NOTIFICATION_CONTROLLER Permission!"); return ERR_ANS_PERMISSION_DENIED; } + return ERR_OK; +} +ErrCode AdvancedNotificationService::RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest) +{ + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_14, EventBranchId::BRANCH_17); + ErrCode result = RegisterPushCallbackTokenCheck(); + if (result != ERR_OK) { + return result; + } if (pushCallback == nullptr) { ANS_LOGW("pushCallback is null."); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(ERR_INVALID_VALUE)); return ERR_INVALID_VALUE; } if (notificationCheckRequest == nullptr) { ANS_LOGW("notificationCheckRequest is null."); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(ERR_INVALID_VALUE).BranchId(BRANCH_18)); return ERR_INVALID_VALUE; } @@ -2121,6 +2163,7 @@ ErrCode AdvancedNotificationService::RegisterPushCallback( if (pushCallBacks_.find(slotType) != pushCallBacks_.end()) { if (checkRequests_[slotType]->GetUid() != uid) { + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(ERROR_INTERNAL_ERROR).BranchId(BRANCH_18)); return ERROR_INTERNAL_ERROR; } } @@ -2140,6 +2183,7 @@ ErrCode AdvancedNotificationService::RegisterPushCallback( ErrCode AdvancedNotificationService::UnregisterPushCallback() { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_14, EventBranchId::BRANCH_13); if (!AccessTokenHelper::IsSystemApp()) { ANS_LOGW("Not system app!"); return ERR_ANS_NON_SYSTEM_APP; @@ -2157,6 +2201,7 @@ ErrCode AdvancedNotificationService::UnregisterPushCallback() if (pushCallBacks_.empty()) { ANS_LOGE("The registration callback has not been processed yet."); + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(ERR_INVALID_OPERATION)); return ERR_INVALID_OPERATION; } diff --git a/services/ans/src/advanced_notification_slot_service.cpp b/services/ans/src/advanced_notification_slot_service.cpp index dcd78faf4..9d666a5c0 100644 --- a/services/ans/src/advanced_notification_slot_service.cpp +++ b/services/ans/src/advanced_notification_slot_service.cpp @@ -348,6 +348,8 @@ ErrCode AdvancedNotificationService::GetEnabledForBundleSlotSelf(int32_t slotTyp NotificationConstant::SlotType slotType = static_cast(slotTypeInt); ANS_LOGD("slotType: %{public}d", slotType); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_15, EventBranchId::BRANCH_0); + message.Message("st:" + std::to_string(slotType) + "en:" + std::to_string(enabled)); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -375,7 +377,7 @@ ErrCode AdvancedNotificationService::GetEnabledForBundleSlotSelf(int32_t slotTyp enabled = slot->GetEnable(); })); notificationSvrQueue_->wait(handler); - + NotificationAnalyticsUtil::ReportModifyEvent(message); return result; } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 1e7f4e521..81a380ec8 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -312,13 +312,17 @@ bool NotificationPreferencesDatabase::PutSlotsToDisturbeDB( bool NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( const NotificationPreferencesInfo::BundleInfo &bundleInfo) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_17, EventBranchId::BRANCH_0); if (bundleInfo.GetBundleName().empty()) { ANS_LOGE("Bundle name is null."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return false; } + message.Message(bundleInfo.GetBundleName() + "_" +std::to_string(bundleInfo.GetBundleUid())); if (!CheckRdbStore()) { ANS_LOGE("RdbStore is nullptr."); + NotificationAnalyticsUtil::ReportModifyEvent(message.BranchId(BRANCH_1)); return false; } std::string values; @@ -360,8 +364,11 @@ bool NotificationPreferencesDatabase::IsNotificationSlotFlagsExists(const sptr &remoteObject, int32_t resultCode) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_23, EventBranchId::BRANCH_0); ANS_LOGI("on ability connected"); MessageParcel data; MessageParcel reply; @@ -47,19 +49,23 @@ void SystemDialogConnectStb::OnAbilityConnectDone(const AppExecFwk::ElementName ANS_LOGE("send Request to SytemDialog fail"); if (commandStr_.empty() || !nlohmann::json::accept(commandStr_)) { ANS_LOGE("Invalid JSON"); + NotificationAnalyticsUtil::ReportModifyEvent(message); return; } nlohmann::json root = nlohmann::json::parse(commandStr_); if (root.is_null() or !root.is_object()) { ANS_LOGE("Invalid JSON object"); + NotificationAnalyticsUtil::ReportModifyEvent(message.BranchId(BRANCH_1)); return; } if (!root.contains("bundleName") || !root.contains("bundleUid")) { ANS_LOGE("not found jsonKey from"); + NotificationAnalyticsUtil::ReportModifyEvent(message.BranchId(BRANCH_2)); return; } if (!root["bundleName"].is_string() || !root["bundleUid"].is_number_integer()) { ANS_LOGE("value type is not right"); + NotificationAnalyticsUtil::ReportModifyEvent(message.BranchId(BRANCH_3)); return; } std::string bundleName = root["bundleName"]; diff --git a/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp b/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp index d4bb9f243..9ae43adbb 100644 --- a/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp @@ -158,26 +158,12 @@ HWTEST_F(AnsLiveViewServiceTest, SetNotificationRequestToDb_00001, Function | Sm } /** - * @tc.name: GetNotificationRequestFromDb_00001 - * @tc.desc: Test GetNotificationRequestFromDb - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(AnsLiveViewServiceTest, GetNotificationRequestFromDb_00001, Function | SmallTest | Level1) -{ - AdvancedNotificationService::NotificationRequestDb requestsdb; - std::string key = "ans_live_view_001"; - auto ret = advancedNotificationService_->GetNotificationRequestFromDb(key, requestsdb); - EXPECT_NE(ret, (int)ERR_OK); -} - -/** - * @tc.name: GetNotificationRequestFromDb_00002 - * @tc.desc: Test GetNotificationRequestFromDb + * @tc.name: SetNotificationRequestToDb_00002 + * @tc.desc: Test SetNotificationRequestToDb * @tc.type: FUNC * @tc.require: issue */ -HWTEST_F(AnsLiveViewServiceTest, GetNotificationRequestFromDb_00002, Function | SmallTest | Level1) +HWTEST_F(AnsLiveViewServiceTest, SetNotificationRequestToDb_00002, Function | SmallTest | Level1) { auto slotType = NotificationConstant::SlotType::LIVE_VIEW; sptr request = new (std::nothrow) NotificationRequest(); -- Gitee