From 2f07ef09ff9d1a0215e53a69ca26a504671b4527 Mon Sep 17 00:00:00 2001 From: wufarong Date: Fri, 11 Apr 2025 11:06:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E7=82=B9=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wufarong Change-Id: I548e5f12f5bcbe988ea5da3ea409a432e055b05c --- .../common/notification_analytics_util.cpp | 3 ++ .../ans/src/notification_rdb_data_mgr.cpp | 51 +++++++++++++++++++ .../src/notification_subscriber_manager.cpp | 18 +++++-- services/ans/src/permission_filter.cpp | 10 +++- 4 files changed, 77 insertions(+), 5 deletions(-) diff --git a/services/ans/src/common/notification_analytics_util.cpp b/services/ans/src/common/notification_analytics_util.cpp index dabbb059b..221e916ec 100644 --- a/services/ans/src/common/notification_analytics_util.cpp +++ b/services/ans/src/common/notification_analytics_util.cpp @@ -344,6 +344,9 @@ std::string NotificationAnalyticsUtil::BuildAnsData(const sptrGetClassification(); ansData["deviceStatus"] = GetDeviceStatus(request); + auto now = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); + ansData["time"] = now; ANS_LOGI("Ansdata built, the controlFlags is %{public}d, deviceStatus is %{public}s", controlFlags, GetDeviceStatus(request).c_str()); return ansData.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace); diff --git a/services/ans/src/notification_rdb_data_mgr.cpp b/services/ans/src/notification_rdb_data_mgr.cpp index 3ea9604a3..10db5c0c2 100644 --- a/services/ans/src/notification_rdb_data_mgr.cpp +++ b/services/ans/src/notification_rdb_data_mgr.cpp @@ -178,6 +178,7 @@ int32_t NotificationDataMgr::InsertData(const std::string &key, const std::strin { ANS_LOGD("InsertData start"); { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_11, EventBranchId::BRANCH_0); std::string tableName; int32_t ret = GetUserTableName(userId, tableName); if (ret != NativeRdb::E_OK) { @@ -200,6 +201,8 @@ int32_t NotificationDataMgr::InsertData(const std::string &key, const std::strin } if (ret != NativeRdb::E_OK) { ANS_LOGE("Insert operation failed, result: %{public}d, key=%{public}s.", ret, key.c_str()); + message.ErrorCode(ret).Message("Insert operation failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return NativeRdb::E_ERROR; } } @@ -209,6 +212,7 @@ int32_t NotificationDataMgr::InsertData(const std::string &key, const std::strin int32_t NotificationDataMgr::InsertData(const std::string &key, const std::vector &value, const int32_t &userId) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_8); std::string tableName; int32_t ret = GetUserTableName(userId, tableName); if (ret != NativeRdb::E_OK) { @@ -231,6 +235,8 @@ int32_t NotificationDataMgr::InsertData(const std::string &key, const std::vecto } if (ret != NativeRdb::E_OK) { ANS_LOGE("Insert operation failed, result: %{public}d, key=%{public}s.", ret, key.c_str()); + message.ErrorCode(ret).Message("Insert operation failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return NativeRdb::E_ERROR; } return NativeRdb::E_OK; @@ -242,6 +248,7 @@ int32_t NotificationDataMgr::InsertBatchData(const std::unordered_mapDelete(rowId, absRdbPredicates); if (ret == NativeRdb::E_SQLITE_CORRUPT) { @@ -304,6 +314,8 @@ int32_t NotificationDataMgr::DeleteData(const std::string tableName, const std:: if (ret != NativeRdb::E_OK) { ANS_LOGW("Delete operation failed from %{public}s, result: %{public}d, key=%{public}s.", tableName.c_str(), ret, key.c_str()); + message.ErrorCode(ret).Message("Delete operation failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return NativeRdb::E_ERROR; } return NativeRdb::E_OK; @@ -370,6 +382,7 @@ int32_t NotificationDataMgr::QueryData(const std::string &key, std::string &valu int32_t NotificationDataMgr::QueryData(const std::string tableName, const std::string key, std::string &value) { NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_2); absRdbPredicates.EqualTo(NOTIFICATION_KEY, key); auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { @@ -384,6 +397,11 @@ int32_t NotificationDataMgr::QueryData(const std::string tableName, const std::s if (ret != NativeRdb::E_OK) { ANS_LOGW("GoToFirstRow failed from %{public}s table. It is empty!, key=%{public}s", tableName.c_str(), key.c_str()); + if (ret != NativeRdb::E_ROW_OUT_RANGE) { + ANS_LOGW("GoToFirstRow failed, rdb error is %{public}d.", ret); + message.ErrorCode(ret).Message("GoToFirstRow failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); + } return NativeRdb::E_EMPTY_VALUES_BUCKET; } ret = absSharedResultSet->GetString(NOTIFICATION_VALUE_INDEX, value); @@ -392,6 +410,8 @@ int32_t NotificationDataMgr::QueryData(const std::string tableName, const std::s } if (ret != NativeRdb::E_OK) { ANS_LOGE("GetString value failed from %{public}s table.", tableName.c_str()); + message.ErrorCode(ret).Message("GetString value failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return NativeRdb::E_ERROR; } absSharedResultSet->Close(); @@ -419,6 +439,7 @@ int32_t NotificationDataMgr::QueryData(const std::string &key, std::vector &value) { NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_3); absRdbPredicates.EqualTo(NOTIFICATION_KEY, key); auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { @@ -433,10 +454,17 @@ int32_t NotificationDataMgr::QueryData(const std::string tableName, const std::s if (ret != NativeRdb::E_OK) { ANS_LOGW("GoToFirstRow failed from %{public}s table. It is empty!, key=%{public}s", tableName.c_str(), key.c_str()); + if (ret != NativeRdb::E_ROW_OUT_RANGE) { + ANS_LOGW("GoToFirstRow failed, rdb error is %{public}d.", ret); + message.ErrorCode(ret).Message("GoToFirstRow failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); + } return NativeRdb::E_EMPTY_VALUES_BUCKET; } ret = absSharedResultSet->GetBlob(NOTIFICATION_VALUE_INDEX, value); if (ret != NativeRdb::E_OK) { + message.ErrorCode(ret).Message("GetString value failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); ANS_LOGE("GetString value failed from %{public}s table.", tableName.c_str()); return NativeRdb::E_ERROR; } @@ -472,6 +500,7 @@ int32_t NotificationDataMgr::QueryDataBeginWithKey( const std::string tableName, const std::string key, std::unordered_map &values) { NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_5); absRdbPredicates.BeginsWith(NOTIFICATION_KEY, key); auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { @@ -486,6 +515,11 @@ int32_t NotificationDataMgr::QueryDataBeginWithKey( if (ret != NativeRdb::E_OK) { ANS_LOGD("GoToFirstRow failed from %{public}s table.It is empty!, key=%{public}s", tableName.c_str(), key.c_str()); + if (ret != NativeRdb::E_ROW_OUT_RANGE) { + ANS_LOGW("GoToFirstRow failed, rdb error is %{public}d.", ret); + message.ErrorCode(ret).Message("GoToFirstRow failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); + } return NativeRdb::E_EMPTY_VALUES_BUCKET; } @@ -494,6 +528,8 @@ int32_t NotificationDataMgr::QueryDataBeginWithKey( ret = absSharedResultSet->GetString(NOTIFICATION_KEY_INDEX, resultKey); if (ret != NativeRdb::E_OK) { ANS_LOGE("Failed to GetString key from %{public}s table.", tableName.c_str()); + message.ErrorCode(ret).Message("GetString key failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return NativeRdb::E_ERROR; } @@ -501,6 +537,8 @@ int32_t NotificationDataMgr::QueryDataBeginWithKey( ret = absSharedResultSet->GetString(NOTIFICATION_VALUE_INDEX, resultValue); if (ret != NativeRdb::E_OK) { ANS_LOGE("GetString value failed from %{public}s table", tableName.c_str()); + message.ErrorCode(ret).Message("GetString value failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return NativeRdb::E_ERROR; } @@ -537,6 +575,7 @@ int32_t NotificationDataMgr::QueryAllData( const std::string tableName, std::unordered_map &datas) { NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_4); auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { ANS_LOGE("absSharedResultSet failed from %{public}s table.", tableName.c_str()); @@ -549,6 +588,11 @@ int32_t NotificationDataMgr::QueryAllData( } if (ret != NativeRdb::E_OK) { ANS_LOGD("GoToFirstRow failed from %{public}s table. It is empty!", tableName.c_str()); + if (ret != NativeRdb::E_ROW_OUT_RANGE) { + ANS_LOGW("GoToFirstRow failed, rdb error is %{public}d.", ret); + message.ErrorCode(ret).Message("GoToFirstRow failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); + } return NativeRdb::E_EMPTY_VALUES_BUCKET; } @@ -557,6 +601,8 @@ int32_t NotificationDataMgr::QueryAllData( ret = absSharedResultSet->GetString(NOTIFICATION_KEY_INDEX, resultKey); if (ret != NativeRdb::E_OK) { ANS_LOGE("GetString key failed from %{public}s table.", tableName.c_str()); + message.ErrorCode(ret).Message("GetString key failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return NativeRdb::E_ERROR; } @@ -564,6 +610,8 @@ int32_t NotificationDataMgr::QueryAllData( ret = absSharedResultSet->GetString(NOTIFICATION_VALUE_INDEX, resultValue); if (ret != NativeRdb::E_OK) { ANS_LOGE("GetString value failed from %{public}s table.", tableName.c_str()); + message.ErrorCode(ret).Message("GetString value failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return NativeRdb::E_ERROR; } @@ -600,6 +648,7 @@ int32_t NotificationDataMgr::DropUserTable(const int32_t userId) int32_t NotificationDataMgr::GetUserTableName(const int32_t &userId, std::string &tableName) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_11, EventBranchId::BRANCH_1); if (!OsAccountManagerHelper::IsSystemAccount(userId)) { tableName = notificationRdbConfig_.tableName; return NativeRdb::E_OK; @@ -621,6 +670,8 @@ int32_t NotificationDataMgr::GetUserTableName(const int32_t &userId, std::string int32_t ret = rdbStore_->ExecuteSql(createTableSql); if (ret != NativeRdb::E_OK) { ANS_LOGW("createTable %{public}s failed, code: %{public}d", tableName.c_str(), ret); + message.ErrorCode(ret).Message("create table failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ret; } createdTables_.insert(tableName); diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 2d3f23675..984ebe355 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -122,9 +122,21 @@ ErrCode NotificationSubscriberManager::AddSubscriber( })); notificationSubQueue_->wait(handler); - ANS_LOGI("%{public}s_, user: %{public}s, Add subscriber result: %{public}d", GetClientBundleName().c_str(), - std::to_string(subInfo->GetAppUserId()).c_str(), result); - message.ErrorCode(result); + std::string bundleNames; + for (auto bundleName : subInfo->GetAppNames()) { + bundleNames += bundleName; + bundleNames += " "; + } + std::string slotTypes; + for (auto slotType : subInfo->GetSlotTypes()) { + slotTypes += std::to_string(slotType); + slotTypes += " "; + } + ANS_LOGI("%{public}s_, user: %{public}s, bundleNames: %{public}s, deviceType: %{public}s, slotTypes: %{public}s, " + "Add subscriber result: %{public}d", GetClientBundleName().c_str(), + std::to_string(subInfo->GetAppUserId()).c_str(), bundleNames.c_str(), subInfo->GetDeviceType().c_str(), + slotTypes.c_str(), result); + message.ErrorCode(result).Append(bundleNames + "," + subInfo->GetDeviceType() + "," + slotTypes); NotificationAnalyticsUtil::ReportModifyEvent(message); return result; } diff --git a/services/ans/src/permission_filter.cpp b/services/ans/src/permission_filter.cpp index cc7525aae..280b7229e 100644 --- a/services/ans/src/permission_filter.cpp +++ b/services/ans/src/permission_filter.cpp @@ -52,10 +52,16 @@ ErrCode PermissionFilter::OnPublish(const std::shared_ptr &r if (slot != nullptr) { isForceControl = slot->GetForceControl(); } else { - message.ErrorCode(ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED).Message("Slot type not exist."); + message.ErrorCode(ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED).Message("Notification slot not enable."); NotificationAnalyticsUtil::ReportPublishFailedEvent(record->request, message); result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED; - ANS_LOGE("Type[%{public}d] slot does not exist", slotType); + ANS_LOGE("Notification slot not enable."); + } + } else { + if (result == ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST) { + message.ErrorCode(ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST).Message("Slot type not exist."); + NotificationAnalyticsUtil::ReportPublishFailedEvent(record->request, message); + ANS_LOGE("Slot type not exist."); } } -- Gitee