diff --git a/interfaces/inner_api/appexecfwk_base/include/hap_module_info.h b/interfaces/inner_api/appexecfwk_base/include/hap_module_info.h index 17b822bb0e9c6a5e6a14c5d150b44e5c1bc0103f..6d7db48fc15f436c205163fe614be308f46d7289 100644 --- a/interfaces/inner_api/appexecfwk_base/include/hap_module_info.h +++ b/interfaces/inner_api/appexecfwk_base/include/hap_module_info.h @@ -102,6 +102,8 @@ struct HapModuleInfo : public Parcelable { bool isLibIsolated = false; std::string nativeLibraryPath; std::string cpuAbi; + bool compressNativeLibs = true; + std::vector nativeLibraryFileNames; // quick fix hqf info HqfInfo hqfInfo; diff --git a/interfaces/inner_api/appexecfwk_base/src/hap_module_info.cpp b/interfaces/inner_api/appexecfwk_base/src/hap_module_info.cpp index 95deeb1787eebb865e2e294d4c69d484cc08399e..3034afe3b53e63869b07310f1c5141399cab7579 100644 --- a/interfaces/inner_api/appexecfwk_base/src/hap_module_info.cpp +++ b/interfaces/inner_api/appexecfwk_base/src/hap_module_info.cpp @@ -78,6 +78,8 @@ const std::string PROXY_DATA_REQUIRED_WRITE_PERMISSION = "requiredWritePermissio const std::string PROXY_DATA_METADATA = "metadata"; const std::string HAP_MODULE_INFO_BUILD_HASH = "buildHash"; const std::string HAP_MODULE_INFO_ISOLATION_MODE = "isolationMode"; +const std::string HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS = "compressNativeLibs"; +const std::string HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES = "nativeLibraryFileNames"; const size_t MODULE_CAPACITY = 10240; // 10K } @@ -598,7 +600,9 @@ void to_json(nlohmann::json &jsonObject, const HapModuleInfo &hapModuleInfo) {HAP_MODULE_INFO_PRELOADS, hapModuleInfo.preloads}, {HAP_MODULE_INFO_PROXY_DATAS, hapModuleInfo.proxyDatas}, {HAP_MODULE_INFO_BUILD_HASH, hapModuleInfo.buildHash}, - {HAP_MODULE_INFO_ISOLATION_MODE, hapModuleInfo.isolationMode} + {HAP_MODULE_INFO_ISOLATION_MODE, hapModuleInfo.isolationMode}, + {HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS, hapModuleInfo.compressNativeLibs}, + {HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES, hapModuleInfo.nativeLibraryFileNames} }; } @@ -998,6 +1002,22 @@ void from_json(const nlohmann::json &jsonObject, HapModuleInfo &hapModuleInfo) false, parseResult, ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS, + hapModuleInfo.compressNativeLibs, + JsonType::BOOLEAN, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES, + hapModuleInfo.nativeLibraryFileNames, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); if (parseResult != ERR_OK) { APP_LOGW("HapModuleInfo from_json error, error code : %{public}d", parseResult); } diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 94e91594cd7837e6423d517ecce84bc02a15c8c7..d3cbca3af8bfa6b5ac3ef47d8b80fa70877068a3 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -575,6 +575,7 @@ private: bool CheckDuplicateProxyData(const std::unordered_map &newInfos); bool CheckDuplicateProxyData(const InnerBundleInfo &newInfo, const InnerBundleInfo &oldInfo); bool CheckDuplicateProxyData(const std::vector &proxyDatas); + ErrCode InnerProcessNativeLibs(InnerBundleInfo &info, const std::string &modulePath); InstallerState state_ = InstallerState::INSTALL_START; std::shared_ptr dataMgr_ = nullptr; // this pointer will get when public functions called std::string bundleName_; diff --git a/services/bundlemgr/include/common_profile.h b/services/bundlemgr/include/common_profile.h index 3d84ee3cebf40b630047f5d684cde4432aa3a41a..63b6ce198866304efc087ff41f71f00b30d6870a 100644 --- a/services/bundlemgr/include/common_profile.h +++ b/services/bundlemgr/include/common_profile.h @@ -363,6 +363,7 @@ constexpr const char* MODULE_ATOMIC_SERVICE = "atomicService"; constexpr const char* MODULE_PROXY_DATAS = "proxyDatas"; constexpr const char* MODULE_BUILD_HASH = "buildHash"; constexpr const char* MODULE_ISOLATION_MODE = "isolationMode"; +constexpr const char* MODULE_COMPRESS_NATIVE_LIBS = "compressNativeLibs"; // module type constexpr const char* MODULE_TYPE_ENTRY = "entry"; constexpr const char* MODULE_TYPE_FEATURE = "feature"; diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index f84d925441d57825a37c56526a8e7d2707895270..409c184e56cda051465c9206d9ce96fe6efe6ced 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -120,6 +120,8 @@ struct InnerModuleInfo { std::vector proxyDatas; std::string buildHash; std::string isolationMode; + bool compressNativeLibs = true; + std::vector nativeLibraryFileNames; }; struct SkillUri { @@ -872,18 +874,7 @@ public: } } - void SetModuleHapPath(const std::string &hapPath) - { - if (innerModuleInfos_.count(currentPackage_) == 1) { - innerModuleInfos_.at(currentPackage_).hapPath = hapPath; - for (auto &abilityInfo : baseAbilityInfos_) { - abilityInfo.second.hapPath = hapPath; - } - for (auto &extensionInfo : baseExtensionInfos_) { - extensionInfo.second.hapPath = hapPath; - } - } - } + void SetModuleHapPath(const std::string &hapPath); const std::string &GetModuleHapPath(const std::string &modulePackage) const { @@ -1975,6 +1966,8 @@ public: bool GetSharedBundleInfo(int32_t flags, BundleInfo &bundleInfo) const; ErrCode GetProxyDataInfos(const std::string &moduleName, std::vector &proxyDatas) const; void GetAllProxyDataInfos(std::vector &proxyDatas) const; + bool IsCompressNativeLibs(const std::string &moduleName) const; + void SetNativeLibraryFileNames(const std::string &moduleName, const std::vector &fileNames); private: bool IsExistLauncherAbility() const; diff --git a/services/bundlemgr/include/installd/installd_host_impl.h b/services/bundlemgr/include/installd/installd_host_impl.h index b1dd9929084ff5a4723c7c46023e50148effc14f..f83bf75b5b8b603728e854311a12d133f1e9215a 100644 --- a/services/bundlemgr/include/installd/installd_host_impl.h +++ b/services/bundlemgr/include/installd/installd_host_impl.h @@ -142,6 +142,9 @@ public: virtual ErrCode CopyFiles(const std::string &sourceDir, const std::string &destinationDir) override; + virtual ErrCode GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames) override; + private: std::string GetBundleDataDir(const std::string &el, const int userid) const; }; diff --git a/services/bundlemgr/include/installd/installd_operator.h b/services/bundlemgr/include/installd/installd_operator.h index 6e9e471ec727ab91dee8ae8b627d4c2cbe16c193..8601a186708ad3b9a7fe02f813b76fe38a09e98f 100644 --- a/services/bundlemgr/include/installd/installd_operator.h +++ b/services/bundlemgr/include/installd/installd_operator.h @@ -190,6 +190,9 @@ public: static bool CopyFiles(const std::string &sourceDir, const std::string &destinationDir); + static bool GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames); + private: static bool OpenHandle(void **handle); diff --git a/services/bundlemgr/include/installd_client.h b/services/bundlemgr/include/installd_client.h index 569c20f914198c4b6c4d6b07fcfa92c150583612..362c3120525d5ca28c2012dfe3ca5f58a8d78425 100644 --- a/services/bundlemgr/include/installd_client.h +++ b/services/bundlemgr/include/installd_client.h @@ -148,6 +148,9 @@ public: ErrCode ExtractFiles(const ExtractParam &extractParam); + ErrCode GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames); + private: /** * @brief Get the installd proxy object. diff --git a/services/bundlemgr/include/ipc/installd_host.h b/services/bundlemgr/include/ipc/installd_host.h index b15976117bdb097da74f1b30217db8fe0d95283c..f829c5d4008a487e9af1c68a047cfe9ff9fbf8ce 100644 --- a/services/bundlemgr/include/ipc/installd_host.h +++ b/services/bundlemgr/include/ipc/installd_host.h @@ -146,6 +146,8 @@ private: bool HandCopyFiles(MessageParcel &data, MessageParcel &reply); + bool HandGetNativeLibraryFileNames(MessageParcel &data, MessageParcel &reply); + using InstalldFunc = bool (InstalldHost::*)(MessageParcel &, MessageParcel &); std::unordered_map funcMap_; }; diff --git a/services/bundlemgr/include/ipc/installd_interface.h b/services/bundlemgr/include/ipc/installd_interface.h index 71679aab2372f9da159e5f8f9a2a3599c01fedbf..8d34dde554bb3ab94d11897e1627bbf34ff59d26 100644 --- a/services/bundlemgr/include/ipc/installd_interface.h +++ b/services/bundlemgr/include/ipc/installd_interface.h @@ -184,6 +184,9 @@ public: virtual ErrCode CopyFiles(const std::string &sourceDir, const std::string &destinationDir) = 0; + virtual ErrCode GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames) = 0; + protected: enum Message : uint32_t { CREATE_BUNDLE_DIR = 1, @@ -208,7 +211,8 @@ protected: IS_DIR_EMPTY, OBTAIN_QUICK_FIX_DIR, COPY_FILES, - EXTRACT_FILES + EXTRACT_FILES, + GET_NATIVE_LIBRARY_FILE_NAMES }; }; diff --git a/services/bundlemgr/include/ipc/installd_proxy.h b/services/bundlemgr/include/ipc/installd_proxy.h index 32a80cef535882406d163fa7846f9771160e8738..c6794da997a3076b279c08322264ffd87828036d 100644 --- a/services/bundlemgr/include/ipc/installd_proxy.h +++ b/services/bundlemgr/include/ipc/installd_proxy.h @@ -143,6 +143,9 @@ public: virtual ErrCode CopyFiles(const std::string &sourceDir, const std::string &destinationDir) override; + virtual ErrCode GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames) override; + private: ErrCode TransactInstalldCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 33380b2bd932186acb473de23e1d56cfab12b082..850fa2ef9e29a9131144c39db12ec8778b6d2853 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -871,7 +871,8 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector // rename for all temp dirs for (const auto &info : newInfos) { - if (info.second.IsOnlyCreateBundleUser()) { + if (info.second.IsOnlyCreateBundleUser() || + !info.second.IsCompressNativeLibs(info.second.GetCurModuleName())) { continue; } if ((result = RenameModuleDir(info.second)) != ERR_OK) { @@ -2223,28 +2224,11 @@ ErrCode BaseBundleInstaller::DeleteArkProfile(const std::string &bundleName, int ErrCode BaseBundleInstaller::ExtractModule(InnerBundleInfo &info, const std::string &modulePath) { - std::string targetSoPath; - std::string cpuAbi; - std::string nativeLibraryPath; - if (info.FetchNativeSoAttrs(modulePackage_, cpuAbi, nativeLibraryPath)) { - bool isLibIsolated = info.IsLibIsolated(info.GetCurModuleName()); - if (isLibIsolated && BundleUtil::EndWith(modulePath, Constants::TMP_SUFFIX)) { - nativeLibraryPath = BuildTempNativeLibraryPath(nativeLibraryPath); - APP_LOGD("Need extract to temp dir: %{public}s", nativeLibraryPath.c_str()); - } - targetSoPath.append(Constants::BUNDLE_CODE_DIR).append(Constants::PATH_SEPARATOR) - .append(info.GetBundleName()).append(Constants::PATH_SEPARATOR) - .append(nativeLibraryPath).append(Constants::PATH_SEPARATOR); - } - - APP_LOGD("begin to extract module files, modulePath : %{private}s, targetSoPath : %{private}s, cpuAbi : %{public}s", - modulePath.c_str(), targetSoPath.c_str(), cpuAbi.c_str()); - auto result = ExtractModuleFiles(info, modulePath, targetSoPath, cpuAbi); + auto result = InnerProcessNativeLibs(info, modulePath); if (result != ERR_OK) { - APP_LOGE("fail to extrace module dir, error is %{public}d", result); + APP_LOGE("fail to InnerProcessNativeLibs, error is %{public}d", result); return result; } - result = ExtractArkNativeFile(info, modulePath); if (result != ERR_OK) { APP_LOGE("fail to extractArkNativeFile, error is %{public}d", result); @@ -3455,5 +3439,44 @@ void BaseBundleInstaller::AddAppProvisionInfo(const std::string &bundleName, } } } + +ErrCode BaseBundleInstaller::InnerProcessNativeLibs(InnerBundleInfo &info, const std::string &modulePath) +{ + std::string targetSoPath; + std::string cpuAbi; + std::string nativeLibraryPath; + bool isCompressNativeLibrary = info.IsCompressNativeLibs(info.GetCurModuleName()); + if (info.FetchNativeSoAttrs(modulePackage_, cpuAbi, nativeLibraryPath)) { + if (isCompressNativeLibrary) { + bool isLibIsolated = info.IsLibIsolated(info.GetCurModuleName()); + if (isLibIsolated && BundleUtil::EndWith(modulePath, Constants::TMP_SUFFIX)) { + nativeLibraryPath = BuildTempNativeLibraryPath(nativeLibraryPath); + APP_LOGD("Need extract to temp dir: %{public}s", nativeLibraryPath.c_str()); + } + targetSoPath.append(Constants::BUNDLE_CODE_DIR).append(Constants::PATH_SEPARATOR) + .append(info.GetBundleName()).append(Constants::PATH_SEPARATOR) + .append(nativeLibraryPath).append(Constants::PATH_SEPARATOR); + } + } + + APP_LOGD("begin to extract module files, modulePath : %{private}s, targetSoPath : %{private}s, cpuAbi : %{public}s", + modulePath.c_str(), targetSoPath.c_str(), cpuAbi.c_str()); + if (isCompressNativeLibrary) { + auto result = ExtractModuleFiles(info, modulePath, targetSoPath, cpuAbi); + if (result != ERR_OK) { + APP_LOGE("fail to extract module dir, error is %{public}d", result); + return result; + } + } else { + std::vector fileNames; + auto result = InstalldClient::GetInstance()->GetNativeLibraryFileNames(modulePath_, cpuAbi, fileNames); + if (result != ERR_OK) { + APP_LOGE("fail to GetNativeLibraryFileNames, error is %{public}d", result); + return result; + } + info.SetNativeLibraryFileNames(info.GetCurModuleName(), fileNames); + } + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/bundle_profile.cpp b/services/bundlemgr/src/bundle_profile.cpp index 52401a77f2aa7da1acaadbdde31288982a43516c..3188c9e48eec0299a0b9e7dbe7323bdf777ccd88 100644 --- a/services/bundlemgr/src/bundle_profile.cpp +++ b/services/bundlemgr/src/bundle_profile.cpp @@ -2009,6 +2009,14 @@ void UpdateNativeSoAttrs( APP_LOGD("cpuAbi %{public}s, soRelativePath : %{public}s, isLibIsolated : %{public}d", cpuAbi.c_str(), soRelativePath.c_str(), isLibIsolated); innerBundleInfo.SetCpuAbi(cpuAbi); + if (!innerBundleInfo.IsCompressNativeLibs(innerBundleInfo.GetCurModuleName())) { + APP_LOGD("UpdateNativeSoAttrs compressNativeLibs is false, no need to decompress so"); + innerBundleInfo.SetNativeLibraryPath(soRelativePath); + innerBundleInfo.SetModuleNativeLibraryPath(soRelativePath); + innerBundleInfo.SetSharedModuleNativeLibraryPath(soRelativePath); + innerBundleInfo.SetModuleCpuAbi(cpuAbi); + return; + } if (!isLibIsolated) { innerBundleInfo.SetNativeLibraryPath(soRelativePath); return; diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index 9439e8707a0b9de826eb75ec8698143cd4f8d5ce..d37b246fa07fb91ded77ce755ca1f6cc3d0b42dc 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -131,12 +131,15 @@ const std::string MODULE_VERSION_NAME = "versionName"; const std::string MODULE_PROXY_DATAS = "proxyDatas"; const std::string MODULE_BUILD_HASH = "buildHash"; const std::string MODULE_ISOLATION_MODE = "isolationMode"; +const std::string MODULE_COMPRESS_NATIVE_LIBS = "compressNativeLibs"; +const std::string MODULE_NATIVE_LIBRARY_FILE_NAMES = "nativeLibraryFileNames"; const int32_t SINGLE_HSP_VERSION = 1; const std::map ISOLATION_MODE_MAP = { {"isolationOnly", IsolationMode::ISOLATION_ONLY}, {"nonisolationOnly", IsolationMode::NONISOLATION_ONLY}, {"isolationFirst", IsolationMode::ISOLATION_FIRST}, }; +const std::string NATIVE_LIBRARY_PATH_SYMBOL = "!/"; inline CompileMode ConvertCompileMode(const std::string& compileMode) { @@ -564,7 +567,9 @@ void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info) {MODULE_VERSION_NAME, info.versionName}, {MODULE_PROXY_DATAS, info.proxyDatas}, {MODULE_BUILD_HASH, info.buildHash}, - {MODULE_ISOLATION_MODE, info.isolationMode} + {MODULE_ISOLATION_MODE, info.isolationMode}, + {MODULE_COMPRESS_NATIVE_LIBS, info.compressNativeLibs}, + {MODULE_NATIVE_LIBRARY_FILE_NAMES, info.nativeLibraryFileNames} }; } @@ -1084,6 +1089,22 @@ void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info) false, parseResult, ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + MODULE_COMPRESS_NATIVE_LIBS, + info.compressNativeLibs, + JsonType::BOOLEAN, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + MODULE_NATIVE_LIBRARY_FILE_NAMES, + info.nativeLibraryFileNames, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); if (parseResult != ERR_OK) { APP_LOGE("read InnerModuleInfo from database error, error code : %{public}d", parseResult); } @@ -1753,6 +1774,8 @@ std::optional InnerBundleInfo::FindHapModuleInfo(const std::strin } hapInfo.buildHash = it->second.buildHash; hapInfo.isolationMode = GetIsolationMode(it->second.isolationMode); + hapInfo.compressNativeLibs = it->second.compressNativeLibs; + hapInfo.nativeLibraryFileNames = it->second.nativeLibraryFileNames; return hapInfo; } @@ -3689,6 +3712,12 @@ bool InnerBundleInfo::FetchNativeSoAttrs( } auto &moduleInfo = moduleIter->second; + if (!moduleInfo.compressNativeLibs) { + cpuAbi = moduleInfo.cpuAbi; + nativeLibraryPath = moduleInfo.nativeLibraryPath; + return !nativeLibraryPath.empty(); + } + if (moduleInfo.isLibIsolated) { cpuAbi = moduleInfo.cpuAbi; nativeLibraryPath = moduleInfo.nativeLibraryPath; @@ -3806,5 +3835,44 @@ IsolationMode InnerBundleInfo::GetIsolationMode(const std::string &isolationMode return IsolationMode::NONISOLATION_FIRST; } } + +void InnerBundleInfo::SetModuleHapPath(const std::string &hapPath) +{ + if (innerModuleInfos_.count(currentPackage_) == 1) { + innerModuleInfos_.at(currentPackage_).hapPath = hapPath; + for (auto &abilityInfo : baseAbilityInfos_) { + abilityInfo.second.hapPath = hapPath; + } + for (auto &extensionInfo : baseExtensionInfos_) { + extensionInfo.second.hapPath = hapPath; + } + if (!innerModuleInfos_.at(currentPackage_).compressNativeLibs && + !innerModuleInfos_.at(currentPackage_).nativeLibraryPath.empty()) { + innerModuleInfos_.at(currentPackage_).nativeLibraryPath = + hapPath + NATIVE_LIBRARY_PATH_SYMBOL + innerModuleInfos_.at(currentPackage_).nativeLibraryPath; + } + } +} + +bool InnerBundleInfo::IsCompressNativeLibs(const std::string &moduleName) const +{ + auto moduleInfo = GetInnerModuleInfoByModuleName(moduleName); + if (!moduleInfo) { + APP_LOGE("Get moduleInfo(%{public}s) failed.", moduleName.c_str()); + return true; // compressNativeLibs default true + } + + return moduleInfo->compressNativeLibs; +} + +void InnerBundleInfo::SetNativeLibraryFileNames(const std::string &moduleName, + const std::vector &fileNames) +{ + if (innerModuleInfos_.find(moduleName) == innerModuleInfos_.end()) { + APP_LOGE("innerBundleInfo does not contain the module: %{public}s.", moduleName.c_str()); + return; + } + innerModuleInfos_.at(moduleName).nativeLibraryFileNames = fileNames; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/installd/installd_host_impl.cpp b/services/bundlemgr/src/installd/installd_host_impl.cpp index ba050ad01a02024e7edb60582ec6e296fc023a43..d1c9c15063ac3c7744ebb418bc6fdfaaed58ccff 100644 --- a/services/bundlemgr/src/installd/installd_host_impl.cpp +++ b/services/bundlemgr/src/installd/installd_host_impl.cpp @@ -637,5 +637,17 @@ ErrCode InstalldHostImpl::CopyFiles(const std::string &sourceDir, const std::str InstalldOperator::CopyFiles(sourceDir, destinationDir); return ERR_OK; } + +ErrCode InstalldHostImpl::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames) +{ + if (!InstalldPermissionMgr::VerifyCallingPermission(Constants::FOUNDATION_UID)) { + APP_LOGE("installd permission denied, only used for foundation process"); + return ERR_APPEXECFWK_INSTALLD_PERMISSION_DENIED; + } + + InstalldOperator::GetNativeLibraryFileNames(filePath, cpuAbi, fileNames); + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/installd/installd_operator.cpp b/services/bundlemgr/src/installd/installd_operator.cpp index a8cdce5b486192a47c2721deabb129b3123cd4d1..ca0da41cf2b4b478b039a255f5278f9e91d1bc64 100644 --- a/services/bundlemgr/src/installd/installd_operator.cpp +++ b/services/bundlemgr/src/installd/installd_operator.cpp @@ -912,5 +912,27 @@ bool InstalldOperator::CopyFiles(const std::string &sourceDir, const std::string closedir(directory); return true; } + +bool InstalldOperator::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames) +{ + BundleExtractor extractor(filePath); + if (!extractor.Init()) { + return false; + } + std::vector entryNames; + if (!extractor.GetZipFileNames(entryNames)) { + return false; + } + std::string prefix = Constants::LIBS + cpuAbi + Constants::PATH_SEPARATOR; + for (const auto &entryName : entryNames) { + if ((entryName.find(prefix) == 0) && + (entryName.find(Constants::SO_SUFFIX) != std::string::npos)) { + fileNames.push_back(entryName.substr(prefix.length(), entryName.length())); + } + } + APP_LOGD("InstalldOperator::GetNativeLibraryFileNames end"); + return true; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/src/installd_client.cpp b/services/bundlemgr/src/installd_client.cpp index 1f9065d8df60c3f4407b7005ab2a0bfba832ee92..d9a28d7cdc4171ad68cb74aed7e4e0f93cae640c 100644 --- a/services/bundlemgr/src/installd_client.cpp +++ b/services/bundlemgr/src/installd_client.cpp @@ -267,5 +267,11 @@ ErrCode InstalldClient::CopyFiles(const std::string &sourceDir, const std::strin { return CallService(&IInstalld::CopyFiles, sourceDir, destinationDir); } + +ErrCode InstalldClient::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames) +{ + return CallService(&IInstalld::GetNativeLibraryFileNames, filePath, cpuAbi, fileNames); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/ipc/installd_host.cpp b/services/bundlemgr/src/ipc/installd_host.cpp index 122a593d007e086b4428e35283b2953217a17e4c..590acb2b573eb8cbd985852ee6823e92d860113a 100644 --- a/services/bundlemgr/src/ipc/installd_host.cpp +++ b/services/bundlemgr/src/ipc/installd_host.cpp @@ -60,6 +60,7 @@ void InstalldHost::init() funcMap_.emplace(IInstalld::Message::OBTAIN_QUICK_FIX_DIR, &InstalldHost::HandObtainQuickFixFileDir); funcMap_.emplace(IInstalld::Message::COPY_FILES, &InstalldHost::HandCopyFiles); funcMap_.emplace(IInstalld::Message::EXTRACT_FILES, &InstalldHost::HandleExtractFiles); + funcMap_.emplace(IInstalld::Message::GET_NATIVE_LIBRARY_FILE_NAMES, &InstalldHost::HandGetNativeLibraryFileNames); } int InstalldHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -341,5 +342,19 @@ bool InstalldHost::HandCopyFiles(MessageParcel &data, MessageParcel &reply) WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result); return true; } + +bool InstalldHost::HandGetNativeLibraryFileNames(MessageParcel &data, MessageParcel &reply) +{ + std::string filePath = Str16ToStr8(data.ReadString16()); + std::string cupAbi = Str16ToStr8(data.ReadString16()); + std::vector fileNames; + ErrCode result = GetNativeLibraryFileNames(filePath, cupAbi, fileNames); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result); + if ((result == ERR_OK) && !reply.WriteStringVector(fileNames)) { + APP_LOGE("fail to obtain fileNames from reply"); + return false; + } + return true; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/ipc/installd_proxy.cpp b/services/bundlemgr/src/ipc/installd_proxy.cpp index 5d041e201958561ed857aacc4c41fe8a9d0c80d7..7ac2888300578d10f8b4467bc1738c7af080cab9 100644 --- a/services/bundlemgr/src/ipc/installd_proxy.cpp +++ b/services/bundlemgr/src/ipc/installd_proxy.cpp @@ -388,6 +388,28 @@ ErrCode InstalldProxy::CopyFiles(const std::string &sourceDir, const std::string return ERR_OK; } +ErrCode InstalldProxy::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames) +{ + MessageParcel data; + INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor())); + INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(filePath)); + INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi)); + + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + auto ret = TransactInstalldCmd(IInstalld::Message::GET_NATIVE_LIBRARY_FILE_NAMES, data, reply, option); + if (ret != ERR_OK) { + APP_LOGE("TransactInstalldCmd failed"); + return ret; + } + if (!reply.ReadStringVector(&fileNames)) { + APP_LOGE("ReadStringVector failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + return ERR_OK; +} + ErrCode InstalldProxy::TransactInstalldCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { diff --git a/services/bundlemgr/src/module_profile.cpp b/services/bundlemgr/src/module_profile.cpp index f30af3d4494f23375ca2ef96f04aa97bdb946eb7..dffe80427a009da1f0baa9ea1bd65709ef1499a8 100644 --- a/services/bundlemgr/src/module_profile.cpp +++ b/services/bundlemgr/src/module_profile.cpp @@ -250,6 +250,7 @@ struct Module { std::vector proxyDatas; std::string buildHash; std::string isolationMode; + bool compressNativeLibs = true; }; struct ModuleJson { @@ -1325,6 +1326,14 @@ void from_json(const nlohmann::json &jsonObject, Module &module) false, g_parseResult, ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + MODULE_COMPRESS_NATIVE_LIBS, + module.compressNativeLibs, + JsonType::BOOLEAN, + false, + g_parseResult, + ArrayType::NOT_ARRAY); } void from_json(const nlohmann::json &jsonObject, ModuleJson &moduleJson) @@ -1413,6 +1422,14 @@ void UpdateNativeSoAttrs( APP_LOGD("cpuAbi %{public}s, soRelativePath : %{public}s, isLibIsolated : %{public}d", cpuAbi.c_str(), soRelativePath.c_str(), isLibIsolated); innerBundleInfo.SetCpuAbi(cpuAbi); + if (!innerBundleInfo.IsCompressNativeLibs(innerBundleInfo.GetCurModuleName())) { + APP_LOGD("UpdateNativeSoAttrs compressNativeLibs is false, no need to decompress so"); + innerBundleInfo.SetNativeLibraryPath(soRelativePath); + innerBundleInfo.SetModuleNativeLibraryPath(soRelativePath); + innerBundleInfo.SetSharedModuleNativeLibraryPath(soRelativePath); + innerBundleInfo.SetModuleCpuAbi(cpuAbi); + return; + } if (!isLibIsolated) { innerBundleInfo.SetNativeLibraryPath(soRelativePath); return; diff --git a/services/bundlemgr/test/mock/src/mock_install_client.cpp b/services/bundlemgr/test/mock/src/mock_install_client.cpp index 69d6737f15ff81d4cb6c56a34526d28a227f7349..6458e22f58f1280f42a0db8dc5a93f2c7169edff 100644 --- a/services/bundlemgr/test/mock/src/mock_install_client.cpp +++ b/services/bundlemgr/test/mock/src/mock_install_client.cpp @@ -154,5 +154,10 @@ ErrCode InstalldClient::CopyFiles(const std::string &sourceDir, const std::strin return 0; } +ErrCode InstalldClient::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames) +{ + return 0; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/test/mock/src/mock_installd_host_impl.cpp b/services/bundlemgr/test/mock/src/mock_installd_host_impl.cpp index 824d3cc677377f480c2884c12229705539e7c1f2..73543a973f4f5d086f1f5dd490e37fe7efdcd6ee 100755 --- a/services/bundlemgr/test/mock/src/mock_installd_host_impl.cpp +++ b/services/bundlemgr/test/mock/src/mock_installd_host_impl.cpp @@ -155,5 +155,11 @@ ErrCode InstalldHostImpl::ExtractFiles(const ExtractParam &extractParam) { return ERR_OK; } + +ErrCode InstalldHostImpl::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, + std::vector &fileNames) +{ + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp index 8e4d34bca24a07920d337579b14b54ab732dfb8e..cc4c5602ee6c72848001950b5de65d72eee058df 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp @@ -682,7 +682,9 @@ const nlohmann::json INNER_BUNDLE_INFO_JSON_3_2 = R"( "srcPath":"", "uiSyntax":"hml", "upgradeFlag":0, - "virtualMachine":"ark" + "virtualMachine":"ark", + "compressNativeLibs": true, + "nativeLibraryFileNames": [] } }, "installMark":{ @@ -1303,7 +1305,9 @@ protected: "srcEntrance": "", "srcPath": "", "uiSyntax": "", - "virtualMachine": "" + "virtualMachine": "", + "compressNativeLibs": true, + "nativeLibraryFileNames": [] }, "com.ohos.launcher.recents": { "abilityKeys": [ @@ -1360,7 +1364,9 @@ protected: "srcEntrance": "", "srcPath": "", "uiSyntax": "", - "virtualMachine": "" + "virtualMachine": "", + "compressNativeLibs": true, + "nativeLibraryFileNames": [] }, "com.ohos.launcher.settings": { "abilityKeys": [ @@ -1417,7 +1423,9 @@ protected: "srcEntrance": "", "srcPath": "", "uiSyntax": "", - "virtualMachine": "" + "virtualMachine": "", + "compressNativeLibs": true, + "nativeLibraryFileNames": [] } }, "installMark": {