From d4ac75f4705368d84394794a3033f7734fddda79 Mon Sep 17 00:00:00 2001 From: small_leek Date: Wed, 25 Jun 2025 10:07:41 +0800 Subject: [PATCH] add query bundle info event Signed-off-by: small_leek --- bundle_hisysevent.yaml | 15 +- .../bundlemgr/include/bundle_mgr_host_impl.h | 8 +- services/bundlemgr/include/event_report.h | 20 ++ .../bundlemgr/include/inner_event_report.h | 1 + .../bundlemgr/src/bundle_mgr_host_impl.cpp | 195 +++++++++++++++++- services/bundlemgr/src/inner_event_report.cpp | 32 +++ .../bms_bundle_kit_service_test.cpp | 65 ++++++ 7 files changed, 325 insertions(+), 11 deletions(-) diff --git a/bundle_hisysevent.yaml b/bundle_hisysevent.yaml index 8dfee8cd0a..2a62db4169 100644 --- a/bundle_hisysevent.yaml +++ b/bundle_hisysevent.yaml @@ -21,4 +21,17 @@ DB_ERROR: DB_NAME: {type: STRING, desc: db name} OPERATION_TYPE: {type: INT32, desc: db operation type} ERROR_CODE: {type: INT32, desc: db error code} - REBUILD_TYPE: {type: INT32, desc: db rebuild type} \ No newline at end of file + REBUILD_TYPE: {type: INT32, desc: db rebuild type} + +QUERY_BUNDLE_INFO: + __BASE: {type: BEHAVIOR, level: MINOR, desc: query bundle info} + FUNC_ID_LIST: {type: INT32, desc: function of query} + USERID_LIST: {type: INT32, arrsize: 100, desc: userId of the bundle} + BUNDLE_NAME_LIST: {type: STRING, arrsize: 100, desc: bundleName} + UID_LIST: {type: INT32, arrsize: 100, desc: uid of bundlename} + APP_INDEX_LIST: {type: INT32, arrsize: 100, desc: app index} + CALLING_UID_LIST: {type: INT32, arrsize: 100, desc: calling uid} + CALLING_APP_ID_LIST: {type: STRING, arrsize: 100, desc: calling appId} + CALLING_BUNDLE_NAME_LIST: {type: STRING, arrsize: 100, desc: calling bundleName} + GET_BUNDLE_INFO_FLAG_LIST: {type: INT32, arrsize: 100, desc: flag of bundle info} + ERROR_CODE: {type: INT32, desc: error code} \ No newline at end of file diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index 8e98379d06..498efedb42 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -28,6 +28,7 @@ #ifdef DISTRIBUTED_BUNDLE_FRAMEWORK #include "distributed_bms_interface.h" #endif +#include "event_report.h" #include "inner_bundle_user_info.h" namespace OHOS { @@ -1195,8 +1196,13 @@ private: bool GetLabelFromCache(const std::string &cacheKey, const std::string &abilityName, const std::unordered_map> &resourceCache, std::string &label); - + bool SendQueryBundleInfoEvent(const std::string &funcName, int32_t userId, int32_t uid, + int32_t appIndex, int32_t flag, const std::string &bundleName, + ErrCode errCode, bool reportNow); + bool CheckNeedAddEvent(const EventInfo &query); + bool GetCallingInfo(int32_t callingUid, std::string &callingBundleName, std::string &callingAppId); std::atomic isBrokerServiceExisted_ = false; + // used to record system event infos }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/include/event_report.h b/services/bundlemgr/include/event_report.h index d637b2373a..841df97018 100644 --- a/services/bundlemgr/include/event_report.h +++ b/services/bundlemgr/include/event_report.h @@ -54,6 +54,7 @@ enum class BMSEventType : uint8_t { DB_ERROR, DATA_PARTITION_USAGE_EVENT, DEFAULT_APP, + QUERY_BUNDLE_INFO }; enum class BundleEventType : uint8_t { @@ -166,6 +167,7 @@ struct EventInfo { int64_t freeSize = 0; int32_t errorCode = 0; int32_t rebuildType = 0; + int64_t lastReportEventTime = 0; std::string bundleName; std::string moduleName; std::string abilityName; @@ -193,6 +195,15 @@ struct EventInfo { bool isIntercepted = false; std::vector fileSize; std::vector partitionSize; + std::vector funcIdList; + std::vector uidList; + std::vector userIdList; + std::vector appIndexList; + std::vector callingUidList; + std::vector flagList; + std::vector bundleNameList; + std::vector callingAppIdList; + std::vector callingBundleNameList; std::string want; std::string utd; @@ -248,6 +259,15 @@ struct EventInfo { rebuildType = 0; want.clear(); utd.clear(); + funcIdList.clear(); + uidList.clear(); + userIdList.clear(); + appIndexList.clear(); + callingUidList.clear(); + flagList.clear(); + bundleNameList.clear(); + callingAppIdList.clear(); + callingBundleNameList.clear(); } }; diff --git a/services/bundlemgr/include/inner_event_report.h b/services/bundlemgr/include/inner_event_report.h index 94bdab6e3f..97e2a86900 100644 --- a/services/bundlemgr/include/inner_event_report.h +++ b/services/bundlemgr/include/inner_event_report.h @@ -63,6 +63,7 @@ private: static void InnerSendDbErrorEvent(const EventInfo& eventInfo); static void InnerSendDataPartitionUsageEvent(const EventInfo& eventInfo); static void InnerSendDefaultAppEvent(const EventInfo& eventInfo); + static void InnerSendQueryBundleInfoEvent(const EventInfo& eventInfo); template static void InnerEventWrite(const std::string &eventName, diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index b97019e379..2c604a45ad 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -88,6 +88,45 @@ const std::string RESOURCE_NOT_SUPPORT = const uint8_t JSON_INDENTATION = 4; const uint64_t BAD_CONTEXT_ID = 0; const uint64_t VECTOR_SIZE_MAX = 200; +const uint64_t MAX_QUERY_EVENT_REPORT_ONCE = 3; +const int64_t ONE_DAY = 10; +const std::unordered_map QUERY_FUNC_MAP = { + {"GetNameForUid", 1}, + {"GetBundleNameForUid", 2}, + {"GetBundleInfoV9", 3}, + {"GetBundleInfo", 4}, + {"GetAppProvisionInfo", 5} +}; +} + +std::shared_mutex g_queryEventMutex; +std::unordered_map g_queryEventList; + +std::unordered_map GetGlobalQueryEventInfo() +{ + std::unique_lock queryEventMutex(g_queryEventMutex); + return g_queryEventList; +} + +void AddGlobalQueryEventInfo(const EventInfo &info) +{ + std::unique_lock queryEventMutex(g_queryEventMutex); + if (g_queryEventList.find(info.errorCode) == g_queryEventList.end()) { + g_queryEventList[info.errorCode] = info; + return; + } +} + +void EraseGlobalQueryEventInfo(ErrCode errCode) +{ + std::unique_lock queryEventMutex(g_queryEventMutex); + g_queryEventList.erase(errCode); +} + +void ClearGlobalQueryEventInfo() +{ + std::unique_lock queryEventMutex(g_queryEventMutex); + g_queryEventList.clear(); } bool BundleMgrHostImpl::GetApplicationInfo( @@ -235,13 +274,22 @@ bool BundleMgrHostImpl::GetBundleInfo( auto dataMgr = GetDataMgrFromService(); if (dataMgr == nullptr) { LOG_E(BMS_TAG_QUERY, "DataMgr is nullptr"); + SendQueryBundleInfoEvent("GetBundleInfo", userId, 0, 0, flags, + bundleName, ERR_BUNDLE_MANAGER_INTERNAL_ERROR, true); return false; } bool res = dataMgr->GetBundleInfo(bundleName, flags, bundleInfo, userId); if (!res) { if (isBrokerServiceExisted_) { auto bmsExtensionClient = std::make_shared(); - return bmsExtensionClient->GetBundleInfo(bundleName, flags, bundleInfo, userId) == ERR_OK; + ErrCode ret = bmsExtensionClient->GetBundleInfo(bundleName, flags, bundleInfo, userId) == ERR_OK; + if (ret != ERR_OK) { + SendQueryBundleInfoEvent("GetBundleInfo", userId, 0, 0, flags, + bundleName, ret, false); + } + } else { + SendQueryBundleInfoEvent("GetBundleInfo", userId, 0, 0, flags, + bundleName, ERR_BUNDLE_MANAGER_INVALID_USER_ID, false); } } return res; @@ -287,13 +335,16 @@ ErrCode BundleMgrHostImpl::GetBundleInfoV9( }(); if (!permissionVerify) { APP_LOGE("verify permission failed"); + SendQueryBundleInfoEvent("GetBundleInfoV9", userId, 0, 0, flags, + bundleName, ERR_BUNDLE_MANAGER_PERMISSION_DENIED, false); return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; } LOG_D(BMS_TAG_QUERY, "verify permission success, begin to GetBundleInfoV9"); auto dataMgr = GetDataMgrFromService(); if (dataMgr == nullptr) { LOG_E(BMS_TAG_QUERY, "DataMgr is nullptr"); - return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; + SendQueryBundleInfoEvent("GetBundleInfoV9", userId, 0, 0, flags, + bundleName, ERR_BUNDLE_MANAGER_INTERNAL_ERROR, true); } auto res = dataMgr->GetBundleInfoV9(bundleName, flags, bundleInfo, userId); if (res != ERR_OK) { @@ -332,7 +383,10 @@ ErrCode BundleMgrHostImpl::BatchGetBundleInfo(const std::vector &bu auto bmsExtensionClient = std::make_shared(); bmsExtensionClient->BatchGetBundleInfo(bundleNames, flags, bundleInfos, userId, true); } - return bundleInfos.empty() ? ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST : ERR_OK; + if (bundleInfos.empty()) { + return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; + } + return ERR_OK; } ErrCode BundleMgrHostImpl::GetBundleInfoForSelf(int32_t flags, BundleInfo &bundleInfo) @@ -532,6 +586,8 @@ bool BundleMgrHostImpl::GetBundleNameForUid(const int uid, std::string &bundleNa auto dataMgr = GetDataMgrFromService(); if (dataMgr == nullptr) { APP_LOGE("DataMgr is nullptr"); + SendQueryBundleInfoEvent("GetBundleNameForUid", -1, uid, 0, 0, + bundleName, ERR_BUNDLE_MANAGER_INTERNAL_ERROR, true); return false; } return dataMgr->GetBundleNameForUid(uid, bundleName); @@ -576,19 +632,28 @@ ErrCode BundleMgrHostImpl::GetNameForUid(const int uid, std::string &name) }(); if (!permissionVerify) { APP_LOGE("verify permission failed"); + SendQueryBundleInfoEvent("GetNameForUid", -1, uid, 0, 0, + "", ERR_BUNDLE_MANAGER_PERMISSION_DENIED, true); return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; } auto dataMgr = GetDataMgrFromService(); if (dataMgr == nullptr) { APP_LOGE("DataMgr is nullptr"); + SendQueryBundleInfoEvent("GetNameForUid", -1, uid, 0, 0, + "", ERR_BUNDLE_MANAGER_INTERNAL_ERROR, true); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; } auto ret = dataMgr->GetNameForUid(uid, name); - if (ret != ERR_OK && isBrokerServiceExisted_) { - auto bmsExtensionClient = std::make_shared(); - ret = bmsExtensionClient->GetBundleNameByUid(uid, name); - if (ret != ERR_OK) { - return ERR_BUNDLE_MANAGER_INVALID_UID; + if (ret != ERR_OK) { + if (isBrokerServiceExisted_) { + auto bmsExtensionClient = std::make_shared(); + ret = bmsExtensionClient->GetBundleNameByUid(uid, name); + if (ret != ERR_OK) { + SendQueryBundleInfoEvent("GetNameForUid", -1, uid, 0, 0, "", ERR_BUNDLE_MANAGER_INVALID_UID, true); + return ERR_BUNDLE_MANAGER_INVALID_UID; + } + } else { + SendQueryBundleInfoEvent("GetNameForUid", -1, uid, 0, 0, "", ret, true); } } return ret; @@ -3722,6 +3787,8 @@ ErrCode BundleMgrHostImpl::GetAppProvisionInfo(const std::string &bundleName, in userId); if (!BundlePermissionMgr::IsSystemApp()) { APP_LOGE("non-system app calling system api"); + SendQueryBundleInfoEvent("GetAppProvisionInfo", userId, -1, 0, 0, + "", ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, true); return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED; } if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED) && @@ -3732,9 +3799,16 @@ ErrCode BundleMgrHostImpl::GetAppProvisionInfo(const std::string &bundleName, in auto dataMgr = GetDataMgrFromService(); if (dataMgr == nullptr) { APP_LOGE("DataMgr is nullptr"); + SendQueryBundleInfoEvent("GetAppProvisionInfo", userId, -1, 0, 0, + "", ERR_BUNDLE_MANAGER_INTERNAL_ERROR, true); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; } - return dataMgr->GetAppProvisionInfo(bundleName, userId, appProvisionInfo); + ErrCode ret = dataMgr->GetAppProvisionInfo(bundleName, userId, appProvisionInfo); + if (ret != ERR_OK) { + SendQueryBundleInfoEvent("GetAppProvisionInfo", userId, -1, 0, 0, + "", ret, false); + } + return ret; } ErrCode BundleMgrHostImpl::GetProvisionMetadata(const std::string &bundleName, int32_t userId, @@ -5766,6 +5840,109 @@ ErrCode BundleMgrHostImpl::GetAllShortcutInfoForSelf(std::vector & return dataMgr->GetAllShortcutInfoForSelf(shortcutInfos); } +bool BundleMgrHostImpl::CheckNeedAddEvent(const EventInfo &query) +{ + if (g_queryEventList.find(query.errorCode) == g_queryEventList.end()) { + g_queryEventList[query.errorCode] = query; + return false; + } + EventInfo info = g_queryEventList[query.errCode]; + if (info.bundleNameList.size() >= MAX_QUERY_EVENT_REPORT_ONCE) { + return false; + } + if (std::find(info.funcIdList.begin(), info.funcIdList.end(), query.funcIdList[0]) == info.funcIdList.end()|| + std::find(info.userIdList.begin(), info.userIdList.end(), query.userIdList[0]) == info.userIdList.end() || + std::find(info.uidList.begin(), info.uidList.end(), query.uidList[0]) == info.uidList.end() || + std::find(info.appIndexList.begin(), info.appIndexList.end(), + query.appIndexList[0]) == info.appIndexList.end() || + std::find(info.flagList.begin(), info.flagList.end(), query.flagList[0]) == info.flagList.end() || + std::find(info.bundleNameList.begin(), info.bundleNameList.end(), query.bundleNameList[0]) == + info.bundleNameList.end() || + std::find(info.callingUidList.begin(), info.callingUidList.end(), query.callingUidList[0]) == + info.callingUidList.end()) { + return true; + } + return false; +} + +bool BundleMgrHostImpl::GetCallingInfo(int32_t callingUid, std::string &callingBundleName, std::string &callingAppId) +{ + auto dataMgr = GetDataMgrFromService(); + if (dataMgr == nullptr) { + LOG_E(BMS_TAG_QUERY, "DataMgr is nullptr"); + return false; + } + if (!dataMgr->GetBundleNameForUid(callingUid, callingBundleName)) { + LOG_W(BMS_TAG_INSTALLER, "CallingUid %{public}d is not hap, no bundleName", callingUid); + callingBundleName = Constants::EMPTY_STRING; + } + BundleInfo bundleInfo; + if (!dataMgr->GetBundleInfo(callingBundleName, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, + callingUid / Constants::BASE_USER_RANGE)) { + LOG_E(BMS_TAG_INSTALLER, "GetBundleInfo failed, bundleName: %{public}s", callingBundleName.c_str()); + } + callingAppId = bundleInfo.appId; + return true; +} + +bool BundleMgrHostImpl::SendQueryBundleInfoEvent(const std::string &funcName, int32_t userId, int32_t uid, + int32_t appIndex, int32_t flag, const std::string &bundleName, ErrCode errCode, bool reportNow) +{ + int32_t callingUid = IPCSkeleton::GetCallingUid(); + APP_LOGI("start SendQueryBundleInfoEvent, bundleName:%{public}s, flag:%{public}d, userId:%{public}d, uid:%{public}d, appindex:%{public}d, callinguid:%{public}d, errCode:%{public}d", + bundleName.c_str(), flag, userId, uid, appIndex, callingUid, errCode); + if (QUERY_FUNC_MAP.find(funcName) == QUERY_FUNC_MAP.end()) { + LOG_E(BMS_TAG_QUERY, "No Need to report for func: %{public}s", funcName.c_str()); + return false; + } + // get calling bundle info + std::string callingBundleName; + std::string callingAppId; + GetCallingInfo(callingUid, callingBundleName, callingAppId); + + EventInfo query; + query.errCode = errCode; + query.funcIdList.push_back(QUERY_FUNC_MAP.at(funcName)); + query.userIdList.push_back(userId); + query.uidList.push_back(uid); + query.appIndexList.push_back(appIndex); + query.flagList.push_back(flag); + query.bundleNameList.push_back(bundleName); + query.callingUidList.push_back(callingUid); + query.callingBundleNameList.push_back(callingBundleName); + query.callingAppIdList.push_back(callingAppId); + + // check report now + if (reportNow) { + EventReport::SendSystemEvent(BMSEventType::QUERY_BUNDLE_INFO, query); + APP_LOGI("SendSystemEvent:QUERY_BUNDLE_INFO begin"); + return true; + } + + int32_t funcId = QUERY_FUNC_MAP.at(funcName); + std::unique_lock queryEventMutex(g_queryEventMutex); + bool needAddEvent = CheckNeedAddEvent(query); + if (needAddEvent) { + g_queryEventList[errCode].funcIdList.push_back(funcId); + g_queryEventList[errCode].userIdList.push_back(userId); + g_queryEventList[errCode].uidList.push_back(uid); + g_queryEventList[errCode].appIndexList.push_back(appIndex); + g_queryEventList[errCode].flagList.push_back(flag); + g_queryEventList[errCode].bundleNameList.push_back(bundleName); + g_queryEventList[errCode].callingUidList.push_back(callingUid); + g_queryEventList[errCode].callingBundleNameList.push_back(callingBundleName); + g_queryEventList[errCode].callingAppIdList.push_back(callingAppId); + } + if (g_queryEventList[errCode].lastReportEventTime == 0 || + (BundleUtil::GetCurrentTime() - g_queryEventList[errCode].lastReportEventTime) >= ONE_DAY) { + APP_LOGI("SendSystemEvent:QUERY_BUNDLE_INFO begin"); + EventReport::SendSystemEvent(BMSEventType::QUERY_BUNDLE_INFO, g_queryEventList[errCode]); + g_queryEventList.erase(errCode); + return true; + } + return false; +} + // Internal interface. The application compares the API version number saved in the package management. //No permission control is required bool BundleMgrHostImpl::GreatOrEqualTargetAPIVersion(const int32_t platformVersion, const int32_t minorVersion, diff --git a/services/bundlemgr/src/inner_event_report.cpp b/services/bundlemgr/src/inner_event_report.cpp index d6f4cbe716..a56202ba7c 100644 --- a/services/bundlemgr/src/inner_event_report.cpp +++ b/services/bundlemgr/src/inner_event_report.cpp @@ -49,6 +49,7 @@ constexpr const char* BMS_DISK_SPACE = "BMS_DISK_SPACE"; constexpr const char* APP_CONTROL_RULE = "APP_CONTROL_RULE"; constexpr const char* DB_ERROR = "DB_ERROR"; constexpr const char* DEFAULT_APP = "DEFAULT_APP"; +constexpr const char* QUERY_BUNDLE_INFO = "QUERY_BUNDLE_INFO"; // event params const char* EVENT_PARAM_PNAMEID = "PNAMEID"; @@ -135,6 +136,16 @@ const char* ERROR_CODE = "errorCode"; const char* REBUILD_TYPE = "rebuildType"; const char* COMPONENT_NAME = "hisevent"; const char* PARTITION_NAME = "/data"; +// query event +const char* EVENT_PARAM_FUNC_ID_LIST = "FUNC_ID_LIST"; +const char* EVENT_PARAM_USER_ID_LIST = "USER_ID_LIST"; +const char* EVENT_PARAM_UID_LIST = "UID_LIST"; +const char* EVENT_PARAM_APP_INDEX_LIST = "APP_INDEX_LIST"; +const char* EVENT_PARAM_FLAG_LIST = "FLAG_LIST"; +const char* EVENT_PARAM_BUNDLE_NAME_LIST = "BUNDLE_NAME_LIST"; +const char* EVENT_PARAM_CALLING_UID_LIST = "CALLING_UID_LIST"; +const char* EVENT_PARAM_CALLING_BUNDLE_NAME_LIST = "CALLING_BUNDLE_NAME_LIST"; +const char* EVENT_PARAM_CALLING_APP_ID_LIST = "CALLING_APP_ID_LIST"; const InstallScene INSTALL_SCENE_STR_MAP_KEY[] = { InstallScene::NORMAL, @@ -315,6 +326,10 @@ std::unordered_map [](const EventInfo& eventInfo) { InnerSendDefaultAppEvent(eventInfo); } }, + { BMSEventType::QUERY_BUNDLE_INFO, + [](const EventInfo& eventInfo) { + InnerSendQueryBundleInfoEvent(eventInfo); + } }, }; void InnerEventReport::SendSystemEvent(BMSEventType bmsEventType, const EventInfo& eventInfo) @@ -749,5 +764,22 @@ void InnerEventReport::InnerSystemEventWrite( static_cast(type), keyValues...); } + +void InnerEventReport::InnerSendQueryBundleInfoEvent(const EventInfo& eventInfo) +{ + InnerEventWrite( + QUERY_BUNDLE_INFO, + HiSysEventType::BEHAVIOR, + EVENT_PARAM_FUNC_ID_LIST, eventInfo.funcIdList, + EVENT_PARAM_USER_ID_LIST, eventInfo.userIdList, + EVENT_PARAM_UID_LIST, eventInfo.appIndex, + EVENT_PARAM_APP_INDEX_LIST, eventInfo.appIndexList, + EVENT_PARAM_FLAG_LIST, eventInfo.flagList, + EVENT_PARAM_BUNDLE_NAME_LIST, eventInfo.bundleNameList, + EVENT_PARAM_CALLING_UID_LIST, eventInfo.callingUidList, + EVENT_PARAM_CALLING_BUNDLE_NAME_LIST, eventInfo.callingBundleNameList, + EVENT_PARAM_CALLING_APP_ID_LIST, eventInfo.callingAppIdList, + ERROR_CODE, eventInfo.errorCode); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp index 2569a31729..9f93df37de 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp @@ -62,6 +62,15 @@ #include "display_power_info.h" #include "battery_srv_client.h" +namespace OHOS { +namespace AppExecFwk { + std::unordered_map GetGlobalQueryEventInfo(); + void AddGlobalQueryEventInfo(const EventInfo &info); + void EraseGlobalQueryEventInfo(ErrCode errCode); + void ClearGlobalQueryEventInfo(); +} +} + using namespace testing::ext; using namespace OHOS; using namespace OHOS::AppExecFwk; @@ -14902,4 +14911,60 @@ HWTEST_F(BmsBundleKitServiceTest, Mgr_Proxy_GetAllShortcutInfoForSelf_0100, Func auto ret = bundleMgrProxy->GetAllShortcutInfoForSelf(shortcutInfos); EXPECT_NE(ret, ERR_OK); } + +/** + * @tc.number: CheckNeedAddEvent_0100 + * @tc.name: test CheckNeedAddEvent + * @tc.desc: 1.Test the CheckNeedAddEvent by BundleMgrHostImpl + */ +HWTEST_F(BmsBundleKitServiceTest, CheckNeedAddEvent_0100, Function | SmallTest | Level1) +{ + auto hostImpl = std::make_unique(); + ASSERT_NE(hostImpl, nullptr); + ClearGlobalQueryEventInfo(); + EventInfo test; + test.errorCode = ERR_BUNDLE_MANAGER_INTERNAL_ERROR; + test.funcIdList = {1}; + test.userIdList = {100}; + test.uidList = {1}; + test.appIndexList = {0}; + test.flagList = {BundleFlag::GET_BUNDLE_DEFAULT}; + test.bundleNameList = {"test.CheckNeedAddEvent_0100"}; + test.callingUidList = {1001}; + test.callingBundleNameList = {"com.test.CheckNeedAddEvent_0100"}; + test.callingAppIdList = {"123asdf"}; + uint64_t cacheSize = 1; + ErrCode ret = 0; + bool res = hostImpl->CheckNeedAddEvent(test); + EXPECT_EQ(res, false); + res = hostImpl->CheckNeedAddEvent(test); + EXPECT_EQ(res, false); +} + +/** + * @tc.number: CheckNeedAddEvent_0200 + * @tc.name: test CheckNeedAddEvent + * @tc.desc: 1.Test the CheckNeedAddEvent by BundleMgrHostImpl + */ +HWTEST_F(BmsBundleKitServiceTest, CheckNeedAddEvent_0200, Function | SmallTest | Level1) +{ + auto hostImpl = std::make_unique(); + ASSERT_NE(hostImpl, nullptr); + ClearGlobalQueryEventInfo(); + EventInfo test; + test.errorCode = ERR_BUNDLE_MANAGER_INTERNAL_ERROR; + test.funcIdList = {1}; + test.userIdList = {100}; + test.uidList = {1}; + test.appIndexList = {0}; + test.flagList = {BundleFlag::GET_BUNDLE_DEFAULT}; + test.bundleNameList = {"test.CheckNeedAddEvent_0100"}; + test.callingUidList = {1001}; + test.callingBundleNameList = {"com.test.CheckNeedAddEvent_0100"}; + test.callingAppIdList = {"123asdf"}; + uint64_t cacheSize = 1; + ErrCode ret = 0; + bool res = hostImpl->CheckNeedAddEvent(test); + EXPECT_EQ(res, false); +} } -- Gitee