From 54466dcbf4c89d8f9eedf252c64f8fe64777a327 Mon Sep 17 00:00:00 2001 From: small_leek Date: Wed, 3 Sep 2025 12:03:56 +0800 Subject: [PATCH] add apiversion, sdkversion and uid to isntall/update sysytem event Signed-off-by: small_leek --- .../bundlemgr/include/base_bundle_installer.h | 3 ++ services/bundlemgr/include/bundle_extractor.h | 2 ++ .../include/bundle_install_checker.h | 1 + services/bundlemgr/include/bundle_parser.h | 2 ++ services/bundlemgr/include/event_report.h | 15 +++++++++ .../bundlemgr/src/base_bundle_installer.cpp | 24 ++++++++++++++ services/bundlemgr/src/bundle_extractor.cpp | 12 +++++++ .../bundlemgr/src/bundle_install_checker.cpp | 13 ++++++++ services/bundlemgr/src/bundle_parser.cpp | 12 +++++++ services/bundlemgr/src/inner_event_report.cpp | 20 +++++++++-- .../bms_bundle_parser_test.cpp | 33 +++++++++++++++++++ 11 files changed, 135 insertions(+), 2 deletions(-) diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 446ee0de21..63a6b7525d 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -597,6 +597,9 @@ 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, const std::string &compileSdlVersion); + void SetUid(int32_t uid); + void SetIsAbcCompressed(bool isAbcCompressed); ErrCode CheckNativeFileWithOldInfo( const InnerBundleInfo &oldInfo, std::unordered_map &newInfos); bool HasAllOldModuleUpdate( diff --git a/services/bundlemgr/include/bundle_extractor.h b/services/bundlemgr/include/bundle_extractor.h index 1be34ccb59..c39ba5a133 100644 --- a/services/bundlemgr/include/bundle_extractor.h +++ b/services/bundlemgr/include/bundle_extractor.h @@ -44,6 +44,8 @@ public: * @return Returns true if the Profile is successfully extracted; returns false otherwise. */ bool ExtractModuleProfile(std::ostream &dest) const; + + bool IsHapCompress() const; }; class BundleParallelExtractor : public BundleExtractor { diff --git a/services/bundlemgr/include/bundle_install_checker.h b/services/bundlemgr/include/bundle_install_checker.h index e43813e4e3..5c9ed58fbb 100644 --- a/services/bundlemgr/include/bundle_install_checker.h +++ b/services/bundlemgr/include/bundle_install_checker.h @@ -197,6 +197,7 @@ public: int32_t GetAppDistributionTypeEnum(const std::string distributionType) const; ErrCode CheckNoU1Enable(const std::unordered_map &newInfos); + bool ParseHapsAbcCompressed(const std::vector &bundlePaths); ErrCode CheckU1EnableSameInHaps(const std::unordered_map &infos, const std::string &bundleName, bool &u1Enable); diff --git a/services/bundlemgr/include/bundle_parser.h b/services/bundlemgr/include/bundle_parser.h index 672f4b98d8..645a86b35a 100644 --- a/services/bundlemgr/include/bundle_parser.h +++ b/services/bundlemgr/include/bundle_parser.h @@ -135,6 +135,8 @@ public: std::unordered_set &bundleNames); ErrCode ParseTestRunner(const std::string &hapPath, ModuleTestRunner &testRunner) const; + + bool IsHapCompress(const std::string &bundlePath) const; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/include/event_report.h b/services/bundlemgr/include/event_report.h index 00c70805e6..487fce748a 100644 --- a/services/bundlemgr/include/event_report.h +++ b/services/bundlemgr/include/event_report.h @@ -142,6 +142,9 @@ struct EventInfo { bool isPatch = false; + // abc compressed + bool isAbcCompressed = false; + InstallScene preBundleScene = InstallScene::NORMAL; // only used in user event @@ -160,6 +163,11 @@ struct EventInfo { 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; int64_t costTimeSeconds = 0; @@ -183,6 +191,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; @@ -268,6 +279,10 @@ struct EventInfo { bundleNameList.clear(); callingAppIdList.clear(); callingBundleNameList.clear(); + targetAPIVersion = 0; + minAPIVersion = 0; + uid = 0; + isAbcCompressed = false; } }; diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 875a4746fb..de8fe5320e 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -1552,6 +1552,12 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector LOG_W(BMS_TAG_INSTALLER, "ProcessExtProfile failed"); } SetHybridSpawn(); + // 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); + SetIsAbcCompressed(bundleInstallChecker_->ParseHapsAbcCompressed(bundlePaths)); LOG_I(BMS_TAG_INSTALLER, "finish install %{public}s", bundleName_.c_str()); UtdHandler::InstallUtdAsync(bundleName_, userId_); CheckAddResultMsg(newInfos, oldInfo, isContainEntry_); @@ -7988,5 +7994,23 @@ bool BaseBundleInstaller::CheckAddResultMsg(const std::unordered_map 0; +} + BundleParallelExtractor::BundleParallelExtractor(const std::string &source) : BundleExtractor(source, true) { APP_LOGD("BundleParallelExtractor is created"); diff --git a/services/bundlemgr/src/bundle_install_checker.cpp b/services/bundlemgr/src/bundle_install_checker.cpp index 16d00b90bb..c55c000dc3 100644 --- a/services/bundlemgr/src/bundle_install_checker.cpp +++ b/services/bundlemgr/src/bundle_install_checker.cpp @@ -1813,5 +1813,18 @@ bool BundleInstallChecker::DetermineCloneApp(InnerBundleInfo &innerBundleInfo) } return true; } + +bool BundleInstallChecker::ParseHapsAbcCompressed( + const std::vector &bundlePaths) +{ + LOG_D(BMS_TAG_INSTALLER, "Parse abc in hap"); + BundleParser bundleParser; + for (uint32_t i = 0; i < bundlePaths.size(); ++i) { + if (bundleParser.IsHapCompress(bundlePaths[i])) { + return true; + } + } + return false; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/src/bundle_parser.cpp b/services/bundlemgr/src/bundle_parser.cpp index d61ae4273a..1f441d4163 100644 --- a/services/bundlemgr/src/bundle_parser.cpp +++ b/services/bundlemgr/src/bundle_parser.cpp @@ -458,5 +458,17 @@ ErrCode BundleParser::ParseTestRunner( ModuleProfile moduleProfile; return moduleProfile.TransformToTestRunner(outStream, testRunner); } + +bool BundleParser::IsHapCompress( + const std::string &bundlePath) const +{ + APP_LOGD("parse from %{private}s", bundlePath.c_str()); + BundleExtractor bundleExtractor(bundlePath); + if (!bundleExtractor.Init()) { + APP_LOGE("bundle extractor init failed"); + return false; + } + return bundleExtractor.IsHapCompress(); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/inner_event_report.cpp b/services/bundlemgr/src/inner_event_report.cpp index 26f77d06c8..568b66206b 100644 --- a/services/bundlemgr/src/inner_event_report.cpp +++ b/services/bundlemgr/src/inner_event_report.cpp @@ -95,6 +95,12 @@ const char* REMAIN_PARTITION_SIZE_KEY = "REMAIN_PARTITION_SIZE"; const char* USER_DATA_SIZE = "USER_DATA_SIZE"; const char* EVENT_PARAM_WANT = "WANT"; const char* EVENT_PARAM_UTD = "UTD"; +// API and SDK version +const char* EVENT_PARAM_MIN_API_VERSION = "MIN_API_VERSION"; +const char* EVENT_PARAM_TARGET_API_VERSION = "TARGET_API_VERSION"; +const char* EVENT_PARAM_COMPILE_SDK_VERSION = "COMPILE_SDK_VERSION"; +const char* EVENT_PARAM_UID = "UID"; +const char* EVENT_PARAM_IS_ABC_COMPRESSED = "IS_ABC_COMPRESSED"; const char* FREE_INSTALL_TYPE = "FreeInstall"; const char* PRE_BUNDLE_INSTALL_TYPE = "PreBundleInstall"; @@ -493,7 +499,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, + EVENT_PARAM_IS_ABC_COMPRESSED, eventInfo.isAbcCompressed); } void InnerEventReport::InnerSendBundleUninstallEvent(const EventInfo& eventInfo) @@ -533,7 +544,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, + EVENT_PARAM_IS_ABC_COMPRESSED, eventInfo.isAbcCompressed); } void InnerEventReport::InnerSendPreBundleRecoverEvent(const EventInfo& eventInfo) diff --git a/services/bundlemgr/test/unittest/bms_bundle_parser_test/bms_bundle_parser_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_parser_test/bms_bundle_parser_test.cpp index c696411921..3af2d7d3c7 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_parser_test/bms_bundle_parser_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_parser_test/bms_bundle_parser_test.cpp @@ -14,6 +14,7 @@ */ #define private public +#define protected public #include #include @@ -4992,4 +4993,36 @@ HWTEST_F(BmsBundleParserTest, ParseArkStartupCacheConfig_0100, Function | Medium ret = BundleParser::ParseArkStartupCacheConfig(ServiceConstants::APP_STARTUP_CACHE_CONG, arkStartupCacheList); EXPECT_EQ(ret, ERR_OK); } + +/** + * @tc.number: IsHapCompress_0100 + * @tc.name: parse abc compressed in hap + * @tc.desc: 1. test IsHapCompress in bundleExtractor + */ +HWTEST_F(BmsBundleParserTest, IsHapCompress_0100, Function | SmallTest | Level1) +{ + BundleParser bundleParser; + pathStream_ << RESOURCE_ROOT_PATH << UNKOWN_PATH << INSTALL_FILE_SUFFIX; + bool result = bundleParser.IsHapCompress(pathStream_.str()); + EXPECT_FALSE(result); + + BundleExtractor bundleExtractor(pathStream_.str()); + result = bundleExtractor.IsHapCompress(); + EXPECT_FALSE(result); + + ZipEntry zipEntry; + zipEntry.compressionMethod = 0; + bundleExtractor.zipFile_.entriesMap_.emplace( + std::string("ets/modules.abc"), zipEntry); + result = bundleExtractor.IsHapCompress(); + EXPECT_FALSE(result); + + BundleExtractor bundleExtractor2(pathStream_.str()); + zipEntry.compressionMethod = 1; + bundleExtractor2.zipFile_.entriesMap_.emplace( + std::string("ets/modules.abc"), zipEntry); + result = bundleExtractor2.IsHapCompress(); + EXPECT_TRUE(result); +} + } // OHOS \ No newline at end of file -- Gitee