diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index f028ca0ddd8da0add6d24365884e4edcc5f9fc22..25dbfcce6e73dbd196f228850682572373554e01 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 86cfa9625b72eb29f528affbe32f0cb02195c98c..33584520e6e2b3dde7da7b4240e7c422b13f9daf 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 @@ -148,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; @@ -171,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; @@ -228,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 a4d50e5df1d94d789472c11fb8ee0c93140dc5f3..772fe654c1d60a62eb0edfb4a32017d5837709a3 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; @@ -5191,6 +5196,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_); } @@ -7313,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 102c8f4a9b05207786063380aede9960eba918eb..dd77615fdd17374bf79913614b8e3b03fe1cc4dd 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"; @@ -123,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, @@ -322,7 +328,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 +363,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 +451,13 @@ 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, + 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) @@ -482,7 +496,13 @@ 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, + 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) 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 488f79984ecf3f0dab2a26bc11bd5473caa44fe3..9f2445dc4827cf3265b0c9586a03708aa8eb3b05 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