From 41c3962478fff8cc4572153172eb1be80adbec20 Mon Sep 17 00:00:00 2001 From: small_leek Date: Sat, 30 Aug 2025 09:46:43 +0800 Subject: [PATCH 1/2] add isPatch ro hisysevent Signed-off-by: small_leek --- services/bundlemgr/include/event_report.h | 2 ++ .../bundlemgr/src/base_bundle_installer.cpp | 1 + services/bundlemgr/src/inner_event_report.cpp | 13 ++++++++---- .../bms_bundle_installer_test.cpp | 20 +++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/services/bundlemgr/include/event_report.h b/services/bundlemgr/include/event_report.h index 86cfa9625b..a4f5fa8255 100644 --- a/services/bundlemgr/include/event_report.h +++ b/services/bundlemgr/include/event_report.h @@ -131,6 +131,8 @@ struct EventInfo { // AOT bool compileResult = false; + + bool isPatch = false; InstallScene preBundleScene = InstallScene::NORMAL; // only used in user event diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index a4d50e5df1..8299d11bde 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -5191,6 +5191,7 @@ void BaseBundleInstaller::SendBundleSystemEvent(const std::string &bundleName, B sysEventInfo_.userId = userId_; sysEventInfo_.versionCode = versionCode_; sysEventInfo_.preBundleScene = preBundleScene; + sysEventInfo_.isPatch = installParam.isPatch; GetCallingEventInfo(sysEventInfo_); EventReport::SendBundleSystemEvent(bundleEventType, sysEventInfo_); } diff --git a/services/bundlemgr/src/inner_event_report.cpp b/services/bundlemgr/src/inner_event_report.cpp index 102c8f4a9b..ffa9b65d4b 100644 --- a/services/bundlemgr/src/inner_event_report.cpp +++ b/services/bundlemgr/src/inner_event_report.cpp @@ -85,6 +85,7 @@ const char* EVENT_PARAM_OPERATION_TYPE = "OPERATION_TYPE"; const char* EVENT_PARAM_ACTION_TYPE = "ACTION_TYPE"; const char* EVENT_PARAM_RULE = "ACTION_RULE"; const char* EVENT_PARAM_APP_INDEX = "APP_INDEX"; +const char* EVENT_PARAM_IS_PATCH = "IS_PATCH"; const char* FREE_INSTALL_TYPE = "FreeInstall"; const char* PRE_BUNDLE_INSTALL_TYPE = "PreBundleInstall"; @@ -322,7 +323,8 @@ void InnerEventReport::InnerSendBundleInstallExceptionEvent(const EventInfo& eve EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo), EVENT_PARAM_SCENE, std::to_string(eventInfo.callingUid), EVENT_PARAM_ERROR_CODE, eventInfo.errCode, - EVENT_PARAM_APP_INDEX, eventInfo.appIndex); + EVENT_PARAM_APP_INDEX, eventInfo.appIndex, + EVENT_PARAM_IS_PATCH, eventInfo.isPatch); } void InnerEventReport::InnerSendBundleUninstallExceptionEvent(const EventInfo& eventInfo) @@ -356,7 +358,8 @@ void InnerEventReport::InnerSendBundleUpdateExceptionEvent(const EventInfo& even EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName, EVENT_PARAM_VERSION, eventInfo.versionCode, EVENT_PARAM_INSTALL_TYPE, std::to_string(eventInfo.callingUid), - EVENT_PARAM_ERROR_CODE, eventInfo.errCode); + EVENT_PARAM_ERROR_CODE, eventInfo.errCode, + EVENT_PARAM_IS_PATCH, eventInfo.isPatch); } void InnerEventReport::InnerSendPreBundleRecoverExceptionEvent(const EventInfo& eventInfo) @@ -443,7 +446,8 @@ void InnerEventReport::InnerSendBundleInstallEvent(const EventInfo& eventInfo) EVENT_PARAM_HIDE_DESKTOP_ICON, eventInfo.hideDesktopIcon, EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo), EVENT_PARAM_SCENE, GetInstallScene(eventInfo), - EVENT_PARAM_APP_INDEX, eventInfo.appIndex); + EVENT_PARAM_APP_INDEX, eventInfo.appIndex, + EVENT_PARAM_IS_PATCH, eventInfo.isPatch); } void InnerEventReport::InnerSendBundleUninstallEvent(const EventInfo& eventInfo) @@ -482,7 +486,8 @@ void InnerEventReport::InnerSendBundleUpdateEvent(const EventInfo& eventInfo) EVENT_PARAM_HASH_VALUE, eventInfo.hashValue, EVENT_PARAM_FINGERPRINT, eventInfo.fingerprint, EVENT_PARAM_HIDE_DESKTOP_ICON, eventInfo.hideDesktopIcon, - EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo)); + EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo), + EVENT_PARAM_IS_PATCH, eventInfo.isPatch); } void InnerEventReport::InnerSendPreBundleRecoverEvent(const EventInfo& eventInfo) diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp index 488f79984e..9f2445dc48 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp @@ -6543,6 +6543,26 @@ HWTEST_F(BmsBundleInstallerTest, SendBundleSystemEvent_0010, Function | SmallTes ASSERT_FALSE(bundleInstaller.innerInstallers_["test"]->isBundleExist_); } +/** + * @tc.number: SendBundleSystemEvent_0020 + * @tc.name: test SendBundleSystemEvent + * @tc.desc: 1.SendBundleSystemEvent + */ +HWTEST_F(BmsBundleInstallerTest, SendBundleSystemEvent_0020, Function | SmallTest | Level0) +{ + InstallParam installParam; + installParam.isPatch = true; + BaseBundleInstaller installer; + installer.SendBundleSystemEvent( + "bundleName", BundleEventType::INSTALL, installParam, InstallScene::NORMAL, ERR_OK); + ASSERT_TRUE(installer.sysEventInfo_.isPatch); + + installParam.isPatch = false; + installer.SendBundleSystemEvent( + "bundleName", BundleEventType::INSTALL, installParam, InstallScene::NORMAL, ERR_OK); + ASSERT_FALSE(installer.sysEventInfo_.isPatch); +} + /** * @tc.number: CreateSharedBundleTempDir_0100 * @tc.name: test CreateSharedBundleTempDir -- Gitee From 7442281bb13c59968e4b77d66005315aab18e59c Mon Sep 17 00:00:00 2001 From: small_leek Date: Wed, 3 Sep 2025 11:55:54 +0800 Subject: [PATCH 2/2] add apiversion, sdkversion and uid to isntall/update sysytem event Signed-off-by: small_leek --- .../bundlemgr/include/base_bundle_installer.h | 2 ++ services/bundlemgr/include/event_report.h | 13 ++++++++++++- .../bundlemgr/src/base_bundle_installer.cpp | 18 ++++++++++++++++++ services/bundlemgr/src/inner_event_report.cpp | 19 +++++++++++++++++-- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index f028ca0ddd..25dbfcce6e 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -586,6 +586,8 @@ private: bool CheckReleaseTypeIsCompatible(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo) const; void SendBundleSystemEvent(const std::string &bundleName, BundleEventType bundleEventType, const InstallParam &installParam, InstallScene preBundleScene, ErrCode errCode); + void SetAPIAndSdkVersions(int32_t targetAPIVersion, uint32_t minAPIVersion, std::string &compileSdlVersion); + void SetUid(int32_t uid); ErrCode CheckNativeFileWithOldInfo( const InnerBundleInfo &oldInfo, std::unordered_map &newInfos); bool HasAllOldModuleUpdate( diff --git a/services/bundlemgr/include/event_report.h b/services/bundlemgr/include/event_report.h index a4f5fa8255..33584520e6 100644 --- a/services/bundlemgr/include/event_report.h +++ b/services/bundlemgr/include/event_report.h @@ -131,7 +131,7 @@ struct EventInfo { // AOT bool compileResult = false; - + bool isPatch = false; InstallScene preBundleScene = InstallScene::NORMAL; @@ -150,6 +150,11 @@ struct EventInfo { int32_t actionType = 0; uint32_t versionCode = 0; uint32_t successCnt = 0; + + // only used in install and update + int32_t targetAPIVersion = 0; + uint32_t minAPIVersion = 0; + int32_t uid = 0; // only used in fault event ErrCode errCode = ERR_OK; @@ -173,6 +178,9 @@ struct EventInfo { std::string failureReason; std::string processName; + // only used in install and update + std::string compileSdkVersion; + //for query of continue type std::string continueType; std::string fileName; @@ -230,6 +238,9 @@ struct EventInfo { dbName.clear(); errorCode = 0; rebuildType = 0; + targetAPIVersion = 0; + minAPIVersion = 0; + uid = 0; } }; diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 8299d11bde..772fe654c1 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -1437,6 +1437,11 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector if (!ProcessExtProfile(installParam)) { LOG_W(BMS_TAG_INSTALLER, "ProcessExtProfile failed"); } + // set api and sdk version to systemevent + SetAPIAndSdkVersions(newInfos.begin()->second.GetBaseApplicationInfo().apiTargetVersion, + newInfos.begin()->second.GetBaseApplicationInfo().apiCompatibleVersion, + newInfos.begin()->second.GetBaseApplicationInfo().compileSdkVersion); + SetUid(uid); LOG_I(BMS_TAG_INSTALLER, "finish install %{public}s", bundleName_.c_str()); UtdHandler::InstallUtdAsync(bundleName_, userId_); return result; @@ -7314,5 +7319,18 @@ bool BaseBundleInstaller::ProcessExtProfile(const InstallParam &installParam) } return true; } + +void BaseBundleInstaller::SetAPIAndSdkVersions(int32_t targetAPIVersion, + uint32_t minAPIVersion, std::string &compileSdlVersion) +{ + sysEventInfo_.minAPIVersion = minAPIVersion; + sysEventInfo_.targetAPIVersion = targetAPIVersion; + sysEventInfo_.compileSdkVersion = compileSdlVersion; +} + +void BaseBundleInstaller::SetUid(int32_t uid) +{ + sysEventInfo_.uid = uid; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/inner_event_report.cpp b/services/bundlemgr/src/inner_event_report.cpp index ffa9b65d4b..dd77615fdd 100644 --- a/services/bundlemgr/src/inner_event_report.cpp +++ b/services/bundlemgr/src/inner_event_report.cpp @@ -124,6 +124,11 @@ const char* DB_NAME = "dbName"; const char* ERROR_CODE = "errorCode"; const char* REBUILD_TYPE = "rebuildType"; +// API and SDK version +const char* EVENT_PARAM_MIN_API_VERSION = "minAPIVersion"; +const char* EVENT_PARAM_TARGET_API_VERSION = "targetAPIVersion"; +const char* EVENT_PARAM_COMPILE_SDK_VERSION = "compileSdkVersion"; + const InstallScene INSTALL_SCENE_STR_MAP_KEY[] = { InstallScene::NORMAL, InstallScene::BOOT, @@ -447,7 +452,12 @@ void InnerEventReport::InnerSendBundleInstallEvent(const EventInfo& eventInfo) EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo), EVENT_PARAM_SCENE, GetInstallScene(eventInfo), EVENT_PARAM_APP_INDEX, eventInfo.appIndex, - EVENT_PARAM_IS_PATCH, eventInfo.isPatch); + EVENT_PARAM_IS_PATCH, eventInfo.isPatch, + EVENT_PARAM_MIN_API_VERSION, eventInfo.minAPIVersion, + EVENT_PARAM_TARGET_API_VERSION, eventInfo.targetAPIVersion, + EVENT_PARAM_COMPILE_SDK_VERSION, eventInfo.compileSdkVersion, + EVENT_PARAM_UID, eventInfo.uid + ); } void InnerEventReport::InnerSendBundleUninstallEvent(const EventInfo& eventInfo) @@ -487,7 +497,12 @@ void InnerEventReport::InnerSendBundleUpdateEvent(const EventInfo& eventInfo) EVENT_PARAM_FINGERPRINT, eventInfo.fingerprint, EVENT_PARAM_HIDE_DESKTOP_ICON, eventInfo.hideDesktopIcon, EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo), - EVENT_PARAM_IS_PATCH, eventInfo.isPatch); + EVENT_PARAM_IS_PATCH, eventInfo.isPatch, + EVENT_PARAM_MIN_API_VERSION, eventInfo.minAPIVersion, + EVENT_PARAM_TARGET_API_VERSION, eventInfo.targetAPIVersion, + EVENT_PARAM_COMPILE_SDK_VERSION, eventInfo.compileSdkVersion, + EVENT_PARAM_UID, eventInfo.uid + ); } void InnerEventReport::InnerSendPreBundleRecoverEvent(const EventInfo& eventInfo) -- Gitee