From 0919a2876a02ac8594b6dca245450c5fbb6eb94d 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 | 3 +- services/bundlemgr/include/bundle_parser.h | 3 +- services/bundlemgr/include/event_report.h | 15 ++++++ .../bundlemgr/include/inner_bundle_info.h | 4 ++ .../bundlemgr/src/base_bundle_installer.cpp | 30 +++++++++++ services/bundlemgr/src/bundle_extractor.cpp | 14 +++++ .../bundlemgr/src/bundle_install_checker.cpp | 9 ++-- .../bundlemgr/src/bundle_mgr_host_impl.cpp | 9 ++-- .../src/bundle_mgr_service_event_handler.cpp | 3 +- services/bundlemgr/src/bundle_parser.cpp | 4 +- .../extend_resource_manager_host_impl.cpp | 3 +- .../bundlemgr/src/hmp_bundle_installer.cpp | 3 +- services/bundlemgr/src/inner_bundle_info.cpp | 11 ++++ services/bundlemgr/src/inner_event_report.cpp | 20 +++++++- .../bms_bundle_install_checker_test.cpp | 3 +- .../bms_bundle_installer_test.cpp | 3 +- .../bms_bundle_parser_test.cpp | 51 ++++++++++++++++--- .../bms_bundle_parser_module_test.cpp | 3 +- .../parse_fuzzer/parse_fuzzer.cpp | 3 +- 21 files changed, 174 insertions(+), 25 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..7e8116a5a4 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; + + void IsHapCompress(bool &isAbcCompressed) 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..c8dbcad2c2 100644 --- a/services/bundlemgr/include/bundle_install_checker.h +++ b/services/bundlemgr/include/bundle_install_checker.h @@ -206,7 +206,8 @@ private: ErrCode ParseBundleInfo( const std::string &bundleFilePath, InnerBundleInfo &info, - BundlePackInfo &packInfo); + BundlePackInfo &packInfo, + bool &isAbcCompressed); ErrCode CheckSystemSize( const std::string &bundlePath, diff --git a/services/bundlemgr/include/bundle_parser.h b/services/bundlemgr/include/bundle_parser.h index 672f4b98d8..0bb4f69d14 100644 --- a/services/bundlemgr/include/bundle_parser.h +++ b/services/bundlemgr/include/bundle_parser.h @@ -42,7 +42,8 @@ public: */ ErrCode Parse( const std::string &pathName, - InnerBundleInfo &innerBundleInfo) const; + InnerBundleInfo &innerBundleInfo, + bool &isAbcCompressed) const; ErrCode ParsePackInfo(const std::string &pathName, BundlePackInfo &bundlePackInfo) const; /** 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/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index dd651a927e..ed846ceb03 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -2306,6 +2306,8 @@ public: void SetUninstallState(const bool &uninstallState); bool IsNeedSendNotify() const; void SetNeedSendNotify(const bool needStatus); + bool GetIsAbcCompressed() const; + void SetIsAbcCompressed(const bool &isAbcCompressed); void UpdateMultiAppMode(const InnerBundleInfo &newInfo); void UpdateReleaseType(const InnerBundleInfo &newInfo); ErrCode AddCloneBundle(const InnerBundleCloneInfo &attr); @@ -2397,6 +2399,8 @@ private: // need to send a notification when uninstallState_ change bool isNeedSendNotify_ = false; + + bool isAbcCompressed_ = false; BundleStatus bundleStatus_ = BundleStatus::ENABLED; int32_t appIndex_ = Constants::INITIAL_APP_INDEX; // apply quick fix frequency diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 875a4746fb..073e52942a 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(cacheInfo.GetBaseApplicationInfo().apiTargetVersion, + cacheInfo.GetBaseApplicationInfo().apiCompatibleVersion, + cacheInfo.GetBaseApplicationInfo().compileSdkVersion); + SetUid(uid); + SetIsAbcCompressed(cacheInfo.GetIsAbcCompressed()); LOG_I(BMS_TAG_INSTALLER, "finish install %{public}s", bundleName_.c_str()); UtdHandler::InstallUtdAsync(bundleName_, userId_); CheckAddResultMsg(newInfos, oldInfo, isContainEntry_); @@ -2335,6 +2341,12 @@ ErrCode BaseBundleInstaller::InnerProcessInstallByPreInstallInfo( } // process resource BundleResourceHelper::AddResourceInfoByBundleName(bundleName, userId_, ADD_RESOURCE_TYPE::CREATE_USER); + // set api and sdk version to systemevent + SetAPIAndSdkVersions(oldInfo.GetBaseApplicationInfo().apiTargetVersion, + oldInfo.GetBaseApplicationInfo().apiCompatibleVersion, + oldInfo.GetBaseApplicationInfo().compileSdkVersion); + SetUid(uid); + SetIsAbcCompressed(oldInfo.GetIsAbcCompressed()); return ERR_OK; } } @@ -7988,5 +8000,23 @@ bool BaseBundleInstaller::CheckAddResultMsg(const std::unordered_mapsecond.SetIsAbcCompressed(isAbcCompressed); } if ((result = CheckModuleNameForMulitHaps(infos)) != ERR_OK) { @@ -837,10 +839,11 @@ void BundleInstallChecker::SetPackInstallationFree(BundlePackInfo &bundlePackInf ErrCode BundleInstallChecker::ParseBundleInfo( const std::string &bundleFilePath, InnerBundleInfo &info, - BundlePackInfo &packInfo) + BundlePackInfo &packInfo, + bool &isAbcCompressed) { BundleParser bundleParser; - ErrCode result = bundleParser.Parse(bundleFilePath, info); + ErrCode result = bundleParser.Parse(bundleFilePath, info, isAbcCompressed); if (result != ERR_OK) { LOG_E(BMS_TAG_INSTALLER, "parse bundle info failed, error: %{public}d", result); if (result == ERR_APPEXECFWK_PARSE_NATIVE_SO_FAILED) { diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index 2a42a0e1d4..492fe0f273 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -1428,7 +1428,8 @@ bool BundleMgrHostImpl::GetBundleArchiveInfo( InnerBundleInfo info; BundleParser bundleParser; - ret = bundleParser.Parse(realPath, info); + bool isAbcCompressed = false; + ret = bundleParser.Parse(realPath, info, isAbcCompressed); if (ret != ERR_OK) { APP_LOGE("parse bundle info failed, error: %{public}d", ret); return false; @@ -1472,7 +1473,8 @@ ErrCode BundleMgrHostImpl::GetBundleArchiveInfoV9( } InnerBundleInfo info; BundleParser bundleParser; - ret = bundleParser.Parse(realPath, info); + bool isAbcCompressed = false; + ret = bundleParser.Parse(realPath, info, isAbcCompressed); if (ret != ERR_OK) { APP_LOGE("parse bundle info failed, error: %{public}d", ret); return ERR_BUNDLE_MANAGER_INVALID_HAP_PATH; @@ -1528,7 +1530,8 @@ ErrCode BundleMgrHostImpl::GetBundleArchiveInfoBySandBoxPath(const std::string & } InnerBundleInfo info; BundleParser bundleParser; - ret = bundleParser.Parse(realPath, info); + bool isAbcCompressed = false; + ret = bundleParser.Parse(realPath, info, isAbcCompressed); if (ret != ERR_OK) { APP_LOGE("parse bundle info failed, error: %{public}d", ret); BundleUtil::DeleteDir(tempHapPath); diff --git a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp index d7de503ef5..5a577ee2bb 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -3766,7 +3766,8 @@ bool BMSEventHandler::ParseHapFiles( BundleParser bundleParser; for (auto realPath : realPaths) { InnerBundleInfo innerBundleInfo; - ret = bundleParser.Parse(realPath, innerBundleInfo); + bool isAbcCompressed = false; + ret = bundleParser.Parse(realPath, innerBundleInfo, isAbcCompressed); if (ret != ERR_OK) { LOG_E(BMS_TAG_DEFAULT, "Parse bundle info failed, error: %{public}d", ret); continue; diff --git a/services/bundlemgr/src/bundle_parser.cpp b/services/bundlemgr/src/bundle_parser.cpp index d61ae4273a..34b5a77282 100644 --- a/services/bundlemgr/src/bundle_parser.cpp +++ b/services/bundlemgr/src/bundle_parser.cpp @@ -103,7 +103,8 @@ bool BundleParser::ReadFileIntoJson(const std::string &filePath, nlohmann::json ErrCode BundleParser::Parse( const std::string &pathName, - InnerBundleInfo &innerBundleInfo) const + InnerBundleInfo &innerBundleInfo, + bool &isAbcCompressed) const { APP_LOGD("parse from %{private}s", pathName.c_str()); BundleExtractor bundleExtractor(pathName); @@ -144,6 +145,7 @@ ErrCode BundleParser::Parse( } } + bundleExtractor.IsHapCompress(isAbcCompressed); return ERR_OK; } diff --git a/services/bundlemgr/src/extend_resource/extend_resource_manager_host_impl.cpp b/services/bundlemgr/src/extend_resource/extend_resource_manager_host_impl.cpp index e2afc24c52..eb8ab197b1 100644 --- a/services/bundlemgr/src/extend_resource/extend_resource_manager_host_impl.cpp +++ b/services/bundlemgr/src/extend_resource/extend_resource_manager_host_impl.cpp @@ -219,7 +219,8 @@ ErrCode ExtendResourceManagerHostImpl::ParseExtendResourceFile( for (uint32_t i = 0; i < filePaths.size(); ++i) { BundleParser bundleParser; InnerBundleInfo innerBundleInfo; - ErrCode result = bundleParser.Parse(filePaths[i], innerBundleInfo); + bool isAbcCompressed = false; + ErrCode result = bundleParser.Parse(filePaths[i], innerBundleInfo, isAbcCompressed); if (result != ERR_OK) { APP_LOGE("parse bundle info %{public}s failed, err %{public}d", filePaths[i].c_str(), result); diff --git a/services/bundlemgr/src/hmp_bundle_installer.cpp b/services/bundlemgr/src/hmp_bundle_installer.cpp index 66b4129111..dba5482b9e 100644 --- a/services/bundlemgr/src/hmp_bundle_installer.cpp +++ b/services/bundlemgr/src/hmp_bundle_installer.cpp @@ -236,7 +236,8 @@ bool HmpBundleInstaller::ParseHapFiles( BundleParser bundleParser; for (auto realPath : realPaths) { InnerBundleInfo innerBundleInfo; - ret = bundleParser.Parse(realPath, innerBundleInfo); + bool isAbcCompressed = false; + ret = bundleParser.Parse(realPath, innerBundleInfo, isAbcCompressed); if (ret != ERR_OK) { APP_LOGE("Parse bundle info failed, error: %{public}d", ret); continue; diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index 596862263e..64342eb65a 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -372,6 +372,7 @@ InnerBundleInfo &InnerBundleInfo::operator=(const InnerBundleInfo &info) this->odid_ = info.odid_; this->uninstallState_ = info.uninstallState_; this->pluginBundleInfos_ = info.pluginBundleInfos_; + this->isAbcCompressed_ = info.isAbcCompressed_; return *this; } @@ -4737,6 +4738,16 @@ void InnerBundleInfo::SetNeedSendNotify(const bool needStatus) isNeedSendNotify_ = needStatus; } +bool InnerBundleInfo::GetIsAbcCompressed() const +{ + return isAbcCompressed_; +} + +void InnerBundleInfo::SetIsAbcCompressed(const bool &isAbcCompressed) +{ + isAbcCompressed_ = isAbcCompressed; +} + std::vector InnerBundleInfo::GetAllExtensionDirsInSpecifiedModule(const std::string &moduleName) const { std::vector dirVec; 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_installer_test/bms_bundle_install_checker_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_checker_test.cpp index 184d2bf56b..99a64f3c7d 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_checker_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_checker_test.cpp @@ -2504,7 +2504,8 @@ HWTEST_F(BmsBundleInstallCheckerTest, ParseBundleInfo_0100, Function | SmallTest std::string bundlePath = ""; InnerBundleInfo info; BundlePackInfo packInfo; - bool ret = installChecker.ParseBundleInfo(bundlePath, info, packInfo); + bool isAbcCompressed = false; + bool ret = installChecker.ParseBundleInfo(bundlePath, info, packInfo, isAbcCompressed); EXPECT_NE(ret, ERR_OK); } 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 c220cd66b3..e8e24b123f 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 @@ -3928,7 +3928,8 @@ HWTEST_F(BmsBundleInstallerTest, InstallChecker_0800, Function | SmallTest | Lev BundleInstallChecker installChecker; InnerBundleInfo info; BundlePackInfo packInfo; - auto ret = installChecker.ParseBundleInfo("", info, packInfo); + bool isAbcCompressed = false; + auto ret = installChecker.ParseBundleInfo("", info, packInfo, isAbcCompressed); EXPECT_EQ(ret, ERR_APPEXECFWK_PARSE_UNEXPECTED); } 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..f480e2d71e 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 @@ -2136,7 +2137,8 @@ HWTEST_F(BmsBundleParserTest, TestParse_0200, Function | SmallTest | Level0) BundleParser bundleParser; InnerBundleInfo innerBundleInfo; pathStream_ << RESOURCE_ROOT_PATH << UNKOWN_PATH << INSTALL_FILE_SUFFIX; - ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo); + bool isAbcCompressed = false; + ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo, isAbcCompressed); EXPECT_EQ(result, ERR_APPEXECFWK_PARSE_UNEXPECTED); } @@ -2349,17 +2351,18 @@ HWTEST_F(BmsBundleParserTest, TestParse_1600, Function | SmallTest | Level0) BundleParser bundleParser; InnerBundleInfo innerBundleInfo; pathStream_ << RESOURCE_ROOT_PATH << "demo.error_type"; - ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo); + bool isAbcCompressed = false; + ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo, isAbcCompressed); EXPECT_EQ(result, ERR_APPEXECFWK_PARSE_UNEXPECTED); pathStream_.str(""); pathStream_ << RESOURCE_ROOT_PATH << "demo."; - result = bundleParser.Parse(pathStream_.str(), innerBundleInfo); + result = bundleParser.Parse(pathStream_.str(), innerBundleInfo, isAbcCompressed); EXPECT_EQ(result, ERR_APPEXECFWK_PARSE_UNEXPECTED); pathStream_.str(""); pathStream_ << RESOURCE_ROOT_PATH << "bundle_suffix_test.BUNDLE"; - result = bundleParser.Parse(pathStream_.str(), innerBundleInfo); + result = bundleParser.Parse(pathStream_.str(), innerBundleInfo, isAbcCompressed); EXPECT_EQ(result, ERR_APPEXECFWK_PARSE_UNEXPECTED); } @@ -2379,7 +2382,8 @@ HWTEST_F(BmsBundleParserTest, TestParse_1700, Function | SmallTest | Level1) pathStream_ << "test/"; } pathStream_ << NEW_APP << INSTALL_FILE_SUFFIX; - ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo); + bool isAbcCompressed = false; + ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo, isAbcCompressed); EXPECT_EQ(result, ERR_APPEXECFWK_PARSE_UNEXPECTED) << pathStream_.str(); } @@ -2399,7 +2403,8 @@ HWTEST_F(BmsBundleParserTest, TestParse_1800, Function | SmallTest | Level1) pathStream_ << "test/"; } pathStream_ << NEW_APP << INSTALL_FILE_SUFFIX; - ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo); + bool isAbcCompressed = false; + ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo, isAbcCompressed); EXPECT_EQ(result, ERR_APPEXECFWK_PARSE_UNEXPECTED); } @@ -2416,7 +2421,8 @@ HWTEST_F(BmsBundleParserTest, TestParse_1900, Function | SmallTest | Level1) pathStream_ << RESOURCE_ROOT_PATH; std::string specialChars = "~!@#$%^&*(){}[]:;'?<>,.|`/./+_-"; pathStream_ << specialChars << "new" << INSTALL_FILE_SUFFIX; - ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo); + bool isAbcCompressed = false; + ErrCode result = bundleParser.Parse(pathStream_.str(), innerBundleInfo, isAbcCompressed); EXPECT_EQ(result, ERR_APPEXECFWK_PARSE_UNEXPECTED); } @@ -4992,4 +4998,35 @@ 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 = false; + + BundleExtractor bundleExtractor(pathStream_.str()); + bundleExtractor.IsHapCompress(result); + EXPECT_FALSE(result); + + ZipEntry zipEntry; + zipEntry.compressionMethod = 0; + bundleExtractor.zipFile_.entriesMap_.emplace( + std::string("ets/modules.abc"), zipEntry); + bundleExtractor.IsHapCompress(result); + EXPECT_FALSE(result); + + BundleExtractor bundleExtractor2(pathStream_.str()); + zipEntry.compressionMethod = 1; + bundleExtractor2.zipFile_.entriesMap_.emplace( + std::string("ets/modules.abc"), zipEntry); + bundleExtractor2.IsHapCompress(result); + EXPECT_TRUE(result); +} + } // OHOS \ No newline at end of file diff --git a/services/test/moduletest/common/bms/bundle_parser_test/bms_bundle_parser_module_test.cpp b/services/test/moduletest/common/bms/bundle_parser_test/bms_bundle_parser_module_test.cpp index 991c71528f..96dd841e8e 100644 --- a/services/test/moduletest/common/bms/bundle_parser_test/bms_bundle_parser_module_test.cpp +++ b/services/test/moduletest/common/bms/bundle_parser_test/bms_bundle_parser_module_test.cpp @@ -36,7 +36,8 @@ public: { BundleParser bundleParser; InnerBundleInfo innerBundleInfo; - ErrCode result = bundleParser.Parse(pathStream.str(), innerBundleInfo); + bool isAbcCompressed = false; + ErrCode result = bundleParser.Parse(pathStream.str(), innerBundleInfo, isAbcCompressed); BundleInfo bundleInfo = innerBundleInfo.GetBaseBundleInfo(); EXPECT_EQ(result, ERR_OK); diff --git a/test/fuzztest/fuzztest_others/parse_fuzzer/parse_fuzzer.cpp b/test/fuzztest/fuzztest_others/parse_fuzzer/parse_fuzzer.cpp index 9fd78bd7c2..0f91d4b070 100644 --- a/test/fuzztest/fuzztest_others/parse_fuzzer/parse_fuzzer.cpp +++ b/test/fuzztest/fuzztest_others/parse_fuzzer/parse_fuzzer.cpp @@ -51,7 +51,8 @@ namespace OHOS { pFile = nullptr; InnerBundleInfo info; BundleParser bundleParser; - auto ret = bundleParser.Parse("myHap.hap", info); + bool isAbcCompressed = false; + auto ret = bundleParser.Parse("myHap.hap", info, isAbcCompressed); if (ret != ERR_OK) { return false; } -- Gitee