From 96c480293347469d4bba98b60ef037e4ed9d7a61 Mon Sep 17 00:00:00 2001 From: junyi233 Date: Wed, 6 Dec 2023 12:43:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E6=8C=91=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: junyi233 --- .../include/bundle_constants.h | 3 + .../appexecfwk_base/include/install_param.h | 2 +- .../app_control/app_control_constants.h | 1 + .../bundlemgr/include/base_bundle_installer.h | 5 + services/bundlemgr/include/bundle_util.h | 4 + .../bundlemgr/include/inner_bundle_info.h | 2 + .../bundlemgr/src/base_bundle_installer.cpp | 173 ++++++++++++++++-- .../bundlemgr/src/bundle_installer_host.cpp | 2 + .../src/bundle_mgr_service_event_handler.cpp | 1 - .../src/bundle_stream_installer_host_impl.cpp | 2 +- services/bundlemgr/src/bundle_util.cpp | 69 +++++++ services/bundlemgr/src/inner_bundle_info.cpp | 11 ++ 12 files changed, 259 insertions(+), 16 deletions(-) diff --git a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h index 61328809f1..bddc6bb46a 100644 --- a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h +++ b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h @@ -67,6 +67,9 @@ constexpr const char* COMPRESS_PROPERTY = "compress"; constexpr const char* SANDBOX_DATA_PATH = "/data/storage/el2/base"; constexpr const char* REAL_DATA_PATH = "/data/app/el2"; constexpr const char* STREAM_INSTALL_PATH = "stream_install"; +constexpr const char* SIGNATURE_FILE_PATH = "signature_files"; +constexpr const char* SECURITY_SIGNATURE_FILE_PATH = "security_signature_files"; +constexpr const char* SECURITY_STREAM_INSTALL_PATH = "security_stream_install"; constexpr const char* QUICK_FIX_PATH = "quick_fix"; constexpr const char* DEVICE_TYPE_OF_DEFAULT = "default"; constexpr const char* DEVICE_TYPE_OF_PHONE = "phone"; diff --git a/interfaces/inner_api/appexecfwk_base/include/install_param.h b/interfaces/inner_api/appexecfwk_base/include/install_param.h index 50f3854376..a2ea80e530 100644 --- a/interfaces/inner_api/appexecfwk_base/include/install_param.h +++ b/interfaces/inner_api/appexecfwk_base/include/install_param.h @@ -52,7 +52,7 @@ struct InstallParam : public Parcelable { // OTA upgrade skips the killing process bool noSkipsKill = true; bool needSendEvent = true; - bool streamInstallMode = false; + bool withCopyHaps = false; std::map hashParams; // whether need copy hap to install path bool copyHapToInstallPath = true; diff --git a/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_constants.h b/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_constants.h index 846cc6d870..a5ad026ada 100644 --- a/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_constants.h +++ b/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_constants.h @@ -22,6 +22,7 @@ namespace AppControlConstants { // app control list constexpr const char* APP_DISALLOWED_UNINSTALL = "AppDisallowedUninstall"; constexpr const char* APP_ALLOWED_INSTALL = "AppAllowedInstall"; +constexpr const char* APP_DISALLOWED_INSTALL = "AppDisallowedInstall"; constexpr const char* APP_DISALLOWED_RUN = "AppDisallowedRun"; constexpr const char* EDM_CALLING = "edm"; diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 3a3415da39..41e92da664 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -459,6 +459,7 @@ private: const std::unordered_map &infos) const; bool UninstallAppControl(const std::string &appId, int32_t userId); + ErrCode InstallNormalAppControl(const std::string &installAppId, int32_t userId, bool isPreInstallApp = false); ErrCode InstallAppControl( const std::vector &installAppIds, int32_t userId); @@ -539,6 +540,9 @@ private: int32_t userId) const; ErrCode ExtractAllArkProfileFile(const InnerBundleInfo &oldInfo) const; ErrCode CheckArkProfileDir(const InnerBundleInfo &newInfo, const InnerBundleInfo &oldInfo) const; + void CopyHapsToSecurityDir(std::vector &bundlePaths); + void DeleteTempHapPaths() const; + ErrCode RenameAllTempDir(const std::unordered_map &newInfos) const; InstallerState state_ = InstallerState::INSTALL_START; std::shared_ptr dataMgr_ = nullptr; // this pointer will get when public functions called @@ -567,6 +571,7 @@ private: // used to record system event infos EventInfo sysEventInfo_; std::unique_ptr bundleInstallChecker_ = nullptr; + std::vector toDeleteTempHapPath_; DISALLOW_COPY_AND_MOVE(BaseBundleInstaller); diff --git a/services/bundlemgr/include/bundle_util.h b/services/bundlemgr/include/bundle_util.h index 7402698874..06aca84640 100644 --- a/services/bundlemgr/include/bundle_util.h +++ b/services/bundlemgr/include/bundle_util.h @@ -27,6 +27,7 @@ namespace AppExecFwk { enum class DirType { STREAM_INSTALL_DIR = 0, QUICK_FIX_DIR = 1, + SIG_FILE_DIR = 2, UNKNOWN }; @@ -157,6 +158,9 @@ public: static bool StartWith(const std::string &source, const std::string &suffix); static bool EndWith(const std::string &source, const std::string &suffix); static int64_t GetFileSize(const std::string &filePath); + static std::string CreateTempDir(const std::string &tempDir); + static std::string CopyFileToSecurityDir(const std::string &filePath, const DirType &dirType, + std::vector &toDeletePaths); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index f69a294c13..8cd361ebd7 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -111,6 +111,7 @@ struct InnerModuleInfo { bool isLibIsolated = false; std::string nativeLibraryPath; std::string cpuAbi; + bool compressNativeLibs = true; AtomicServiceModuleType atomicServiceModuleType; std::vector preloads; }; @@ -1781,6 +1782,7 @@ public: bool IsLibIsolated(const std::string &moduleName) const; std::vector GetDeviceType(const std::string &packageName) const; void UpdateAppDetailAbilityAttrs(); + bool IsCompressNativeLibs(const std::string &moduleName) const; private: void GetBundleWithAbilities( diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 0bafbfe96e..7d377caf07 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -311,6 +311,71 @@ bool BaseBundleInstaller::UninstallAppControl(const std::string &appId, int32_t #endif } +ErrCode BaseBundleInstaller::InstallNormalAppControl( + const std::string &installAppId, + int32_t userId, + bool isPreInstallApp) +{ + APP_LOGD("InstallNormalAppControl start "); +#ifdef BUNDLE_FRAMEWORK_APP_CONTROL + if (isPreInstallApp) { + APP_LOGD("the preInstalled app does not support app control feature"); + return ERR_OK; + } + std::vector allowedAppIds; + ErrCode ret = DelayedSingleton::GetInstance()->GetAppInstallControlRule( + AppControlConstants::EDM_CALLING, AppControlConstants::APP_ALLOWED_INSTALL, userId, allowedAppIds); + if (ret != ERR_OK) { + APP_LOGE("GetAppInstallControlRule allowedInstall failed code:%{public}d", ret); + return ret; + } + + std::vector disallowedAppIds; + ret = DelayedSingleton::GetInstance()->GetAppInstallControlRule( + AppControlConstants::EDM_CALLING, AppControlConstants::APP_DISALLOWED_INSTALL, userId, disallowedAppIds); + if (ret != ERR_OK) { + APP_LOGE("GetAppInstallControlRule disallowedInstall failed code:%{public}d", ret); + return ret; + } + + // disallowed list and allowed list all empty. + if (disallowedAppIds.empty() && allowedAppIds.empty()) { + return ERR_OK; + } + + // only allowed list empty. + if (allowedAppIds.empty()) { + if (std::find(disallowedAppIds.begin(), disallowedAppIds.end(), installAppId) != disallowedAppIds.end()) { + APP_LOGE("disallowedAppIds:%{public}s is disallow install", installAppId.c_str()); + return ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL; + } + return ERR_OK; + } + + // only disallowed list empty. + if (disallowedAppIds.empty()) { + if (std::find(allowedAppIds.begin(), allowedAppIds.end(), installAppId) == allowedAppIds.end()) { + APP_LOGE("allowedAppIds:%{public}s is disallow install", installAppId.c_str()); + return ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL; + } + return ERR_OK; + } + + // disallowed list and allowed list all not empty. + if (std::find(allowedAppIds.begin(), allowedAppIds.end(), installAppId) == allowedAppIds.end()) { + APP_LOGE("allowedAppIds:%{public}s is disallow install", installAppId.c_str()); + return ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL; + } else if (std::find(disallowedAppIds.begin(), disallowedAppIds.end(), installAppId) != disallowedAppIds.end()) { + APP_LOGE("disallowedAppIds:%{public}s is disallow install", installAppId.c_str()); + return ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL; + } + return ERR_OK; +#else + APP_LOGW("app control is disable"); + return ERR_OK; +#endif +} + ErrCode BaseBundleInstaller::InstallAppControl( const std::vector &installAppIds, int32_t userId) { @@ -571,6 +636,12 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector CHECK_RESULT(result, "hap file check failed %{public}d"); UpdateInstallerState(InstallerState::INSTALL_BUNDLE_CHECKED); // ---- 5% + // copy the haps to the dir which cannot be accessed from caller + ScopeGuard securityTempHapPathsGuard([this] { DeleteTempHapPaths(); }); + if (installParam.withCopyHaps) { + CopyHapsToSecurityDir(bundlePaths); + } + // check syscap result = CheckSysCap(bundlePaths); CHECK_RESULT(result, "hap syscap check failed %{public}d"); @@ -598,6 +669,8 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector for (const auto &info : newInfos) { installAppIds.emplace_back(info.second.GetAppId()); } + result = InstallNormalAppControl((newInfos.begin()->second).GetAppId(), userId_, installParam.isPreInstallApp); + CHECK_RESULT(result, "install app control failed %{public}d"); result = InstallAppControl(installAppIds, userId_); CHECK_RESULT(result, "install app control failed %{public}d"); @@ -624,27 +697,21 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector UpdateInstallerState(InstallerState::INSTALL_REMOVE_SANDBOX_APP); // ---- 50% // this state should always be set when return - ScopeGuard stateGuard([&] { dataMgr_->UpdateBundleInstallState(bundleName_, InstallState::INSTALL_SUCCESS); }); + ScopeGuard stateGuard([&] { + dataMgr_->UpdateBundleInstallState(bundleName_, InstallState::INSTALL_SUCCESS); + dataMgr_->EnableBundle(bundleName_); + }); - // this state should always be set when return - ScopeGuard enableGuard([&] { dataMgr_->EnableBundle(bundleName_); }); InnerBundleInfo oldInfo; result = InnerProcessBundleInstall(newInfos, oldInfo, installParam, uid); CHECK_RESULT_WITH_ROLLBACK(result, "internal processing failed with result %{public}d", newInfos, oldInfo); UpdateInstallerState(InstallerState::INSTALL_INFO_SAVED); // ---- 80% // rename for all temp dirs - for (const auto &info : newInfos) { - if (info.second.IsOnlyCreateBundleUser()) { - continue; - } - if ((result = RenameModuleDir(info.second)) != ERR_OK) { - break; - } - } + result = RenameAllTempDir(newInfos); + CHECK_RESULT_WITH_ROLLBACK(result, "rename temp dirs failed with result %{public}d", newInfos, oldInfo); UpdateInstallerState(InstallerState::INSTALL_RENAMED); // ---- 90% - CHECK_RESULT_WITH_ROLLBACK(result, "rename temp dirs failed with result %{public}d", newInfos, oldInfo); if (!uninstallModuleVec_.empty()) { UninstallLowerVersionFeature(uninstallModuleVec_); } @@ -1099,7 +1166,11 @@ ErrCode BaseBundleInstaller::InnerProcessInstallByPreInstallInfo( APP_LOGE("appid:%{private}s check install app control failed", oldInfo.GetAppId().c_str()); return result; } - + result = InstallNormalAppControl(oldInfo.GetAppId(), userId_, installParam.isPreInstallApp); + if (result != ERR_OK) { + APP_LOGE("appid:%{private}s check install app control failed", oldInfo.GetAppId().c_str()); + return result; + } bool isSingleton = oldInfo.IsSingleton(); if ((isSingleton && (userId_ != Constants::DEFAULT_USERID)) || (!isSingleton && (userId_ == Constants::DEFAULT_USERID))) { @@ -2749,6 +2820,7 @@ void BaseBundleInstaller::ResetInstallProperties() singletonState_ = SingletonState::DEFAULT; accessTokenId_ = 0; sysEventInfo_.Reset(); + toDeleteTempHapPath_.clear(); } void BaseBundleInstaller::OnSingletonChange(bool noSkipsKill) @@ -2867,5 +2939,80 @@ ErrCode BaseBundleInstaller::CleanAsanDirectory(InnerBundleInfo &info) const info.SetAsanLogPath(""); return errCode; } + +void BaseBundleInstaller::CopyHapsToSecurityDir(std::vector &bundlePaths) +{ + for (size_t index = 0; index < bundlePaths.size(); ++index) { + APP_LOGD("the original dir is %{public}s", bundlePaths[index].c_str()); + std::string destination = ""; + std::string subStr = Constants::STREAM_INSTALL_PATH; + destination.append(Constants::HAP_COPY_PATH).append(Constants::PATH_SEPARATOR) + .append(Constants::SECURITY_STREAM_INSTALL_PATH); + destination = BundleUtil::CreateTempDir(destination); + + auto pos = bundlePaths[index].find(subStr); + if (pos == std::string::npos) { // this circumstance could not be considered laterly + auto lastPathSeperator = bundlePaths[index].rfind(Constants::PATH_SEPARATOR); + if ((lastPathSeperator != std::string::npos) && (lastPathSeperator != bundlePaths[index].length() - 1)) { + destination.append(Constants::PATH_SEPARATOR).append(std::to_string(std::time(0))); + destination = BundleUtil::CreateTempDir(destination); + toDeleteTempHapPath_.emplace_back(destination); + destination.append(bundlePaths[index].substr(lastPathSeperator)); + } + } else { + auto secondLastPathSep = bundlePaths[index].find(Constants::PATH_SEPARATOR, pos); + if ((secondLastPathSep == std::string::npos) || (secondLastPathSep == bundlePaths[index].length() - 1)) { + continue; + } + auto thirdLastPathSep = + bundlePaths[index].find(Constants::PATH_SEPARATOR, secondLastPathSep + 1); + if ((thirdLastPathSep == std::string::npos) || (thirdLastPathSep == bundlePaths[index].length() - 1)) { + continue; + } + std::string innerSubstr = + bundlePaths[index].substr(secondLastPathSep, thirdLastPathSep - secondLastPathSep + 1); + destination = BundleUtil::CreateTempDir(destination.append(innerSubstr)); + toDeleteTempHapPath_.emplace_back(destination); + destination.append(bundlePaths[index].substr(thirdLastPathSep + 1)); + } + APP_LOGD("the destination dir is %{public}s", destination.c_str()); + if (destination.empty()) { + continue; + } + if (!BundleUtil::CopyFile(bundlePaths[index], destination)) { + APP_LOGW("copy file from %{public}s to %{public}s failed", bundlePaths[index].c_str(), + destination.c_str()); + continue; + } + bundlePaths[index] = destination; + } +} + + +ErrCode BaseBundleInstaller::RenameAllTempDir(const std::unordered_map &newInfos) const +{ + APP_LOGD("begin to rename all temp dir"); + ErrCode ret = ERR_OK; + for (const auto &info : newInfos) { + if (info.second.IsOnlyCreateBundleUser() || + !info.second.IsCompressNativeLibs(info.second.GetCurModuleName())) { + continue; + } + if ((ret = RenameModuleDir(info.second)) != ERR_OK) { + APP_LOGE("rename dir failed"); + break; + } + } + + return ret; +} + +void BaseBundleInstaller::DeleteTempHapPaths() const +{ + for (const auto &tempDir : toDeleteTempHapPath_) { + APP_LOGD("the temp hap dir %{public}s needs to be deleted", tempDir.c_str()); + BundleUtil::DeleteDir(tempDir); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/bundle_installer_host.cpp b/services/bundlemgr/src/bundle_installer_host.cpp index 2ef7f14237..19e6b66369 100644 --- a/services/bundlemgr/src/bundle_installer_host.cpp +++ b/services/bundlemgr/src/bundle_installer_host.cpp @@ -120,6 +120,7 @@ void BundleInstallerHost::HandleInstallMessage(Parcel &data) } sptr statusReceiver = iface_cast(object); + installParam->withCopyHaps = true; Install(bundlePath, *installParam, statusReceiver); APP_LOGD("handle install message finished"); } @@ -172,6 +173,7 @@ void BundleInstallerHost::HandleInstallMultipleHapsMessage(Parcel &data) } sptr statusReceiver = iface_cast(object); + installParam->withCopyHaps = true; Install(pathVec, *installParam, statusReceiver); APP_LOGD("handle install multiple haps finished"); } diff --git a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp index dbcf10ebee..c47208de82 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -426,7 +426,6 @@ ResultCode BMSEventHandler::ReInstallAllInstallDirApps() InstallParam installParam; installParam.userId = Constants::ALL_USERID; installParam.installFlag = InstallFlag::REPLACE_EXISTING; - installParam.streamInstallMode = true; sptr innerReceiverImpl(new (std::nothrow) InnerReceiverImpl()); innerReceiverImpl->SetBundleName(hapPaths.first); std::vector tempHaps; diff --git a/services/bundlemgr/src/bundle_stream_installer_host_impl.cpp b/services/bundlemgr/src/bundle_stream_installer_host_impl.cpp index a15023af6b..966ea94a7b 100644 --- a/services/bundlemgr/src/bundle_stream_installer_host_impl.cpp +++ b/services/bundlemgr/src/bundle_stream_installer_host_impl.cpp @@ -39,7 +39,6 @@ bool BundleStreamInstallerHostImpl::Init(const InstallParam &installParam, const { installParam_ = installParam; receiver_ = statusReceiver; - installParam_.streamInstallMode = true; std::string tempDir = BundleUtil::CreateInstallTempDir(installerId_, DirType::STREAM_INSTALL_DIR); if (tempDir.empty()) { return false; @@ -100,6 +99,7 @@ bool BundleStreamInstallerHostImpl::Install() } std::vector pathVec; pathVec.emplace_back(tempDir_); + installParam_.withCopyHaps = true; auto res = installer->Install(pathVec, installParam_, receiver_); if (!res) { APP_LOGE("install bundle failed"); diff --git a/services/bundlemgr/src/bundle_util.cpp b/services/bundlemgr/src/bundle_util.cpp index 68e083e51d..0a859cac31 100644 --- a/services/bundlemgr/src/bundle_util.cpp +++ b/services/bundlemgr/src/bundle_util.cpp @@ -306,6 +306,24 @@ void BundleUtil::RemoveFsConfig(const std::string &bundleName, const std::string } } +std::string BundleUtil::CreateTempDir(const std::string &tempDir) +{ + if (!OHOS::ForceCreateDirectory(tempDir)) { + APP_LOGE("mkdir %{private}s failed", tempDir.c_str()); + return ""; + } + if (chown(tempDir.c_str(), Constants::FOUNDATION_UID, Constants::BMS_GID) != 0) { + APP_LOGE("fail to change %{private}s ownership", tempDir.c_str()); + return ""; + } + mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + if (!OHOS::ChangeModeFile(tempDir, mode)) { + APP_LOGE("change mode failed, temp install dir : %{private}s", tempDir.c_str()); + return ""; + } + return tempDir; +} + std::string BundleUtil::CreateInstallTempDir(uint32_t installerId, const DirType &type) { std::time_t curTime = std::time(0); @@ -560,5 +578,56 @@ int64_t BundleUtil::GetFileSize(const std::string &filePath) } return fileInfo.st_size; } + +std::string BundleUtil::CopyFileToSecurityDir(const std::string &filePath, const DirType &dirType, + std::vector &toDeletePaths) +{ + APP_LOGD("the original dir is %{public}s", filePath.c_str()); + std::string destination = ""; + std::string subStr = ""; + destination.append(Constants::HAP_COPY_PATH).append(Constants::PATH_SEPARATOR); + if (dirType == DirType::STREAM_INSTALL_DIR) { + subStr = Constants::STREAM_INSTALL_PATH; + destination.append(Constants::SECURITY_STREAM_INSTALL_PATH); + } + if (dirType == DirType::SIG_FILE_DIR) { + subStr = Constants::SIGNATURE_FILE_PATH; + destination.append(Constants::SECURITY_SIGNATURE_FILE_PATH); + } + destination.append(Constants::PATH_SEPARATOR).append(std::to_string(std::time(0))); + destination = CreateTempDir(destination); + auto pos = filePath.find(subStr); + if (pos == std::string::npos) { // this circumstance could not be considered laterly + auto lastPathSeperator = filePath.rfind(Constants::PATH_SEPARATOR); + if ((lastPathSeperator != std::string::npos) && (lastPathSeperator != filePath.length() - 1)) { + toDeletePaths.emplace_back(destination); + destination.append(filePath.substr(lastPathSeperator)); + } + } else { + auto secondLastPathSep = filePath.find(Constants::PATH_SEPARATOR, pos); + if ((secondLastPathSep == std::string::npos) || (secondLastPathSep == filePath.length() - 1)) { + return ""; + } + auto thirdLastPathSep = + filePath.find(Constants::PATH_SEPARATOR, secondLastPathSep + 1); + if ((thirdLastPathSep == std::string::npos) || (thirdLastPathSep == filePath.length() - 1)) { + return ""; + } + toDeletePaths.emplace_back(destination); + std::string innerSubstr = + filePath.substr(secondLastPathSep, thirdLastPathSep - secondLastPathSep + 1); + destination = CreateTempDir(destination.append(innerSubstr)); + destination.append(filePath.substr(thirdLastPathSep + 1)); + } + APP_LOGD("the destination dir is %{public}s", destination.c_str()); + if (destination.empty()) { + return ""; + } + if (!CopyFile(filePath, destination)) { + APP_LOGE("copy file from %{public}s to %{public}s failed", filePath.c_str(), destination.c_str()); + return ""; + } + return destination; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index cf0a159dbb..581023fab6 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -2870,6 +2870,17 @@ bool InnerBundleInfo::IsBundleRemovable(int32_t userId) const return true; } +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; +} + bool InnerBundleInfo::IsUserExistModule(const std::string &moduleName, int32_t userId) const { std::string stringUserId = ""; -- Gitee From 4c15b93cf97a69e20589c21b52e59bcd1de9cf62 Mon Sep 17 00:00:00 2001 From: junyi233 Date: Thu, 7 Dec 2023 12:40:39 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: junyi233 --- services/bundlemgr/include/inner_bundle_info.h | 2 -- services/bundlemgr/src/base_bundle_installer.cpp | 5 ++--- services/bundlemgr/src/inner_bundle_info.cpp | 11 ----------- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index 8cd361ebd7..f69a294c13 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -111,7 +111,6 @@ struct InnerModuleInfo { bool isLibIsolated = false; std::string nativeLibraryPath; std::string cpuAbi; - bool compressNativeLibs = true; AtomicServiceModuleType atomicServiceModuleType; std::vector preloads; }; @@ -1782,7 +1781,6 @@ public: bool IsLibIsolated(const std::string &moduleName) const; std::vector GetDeviceType(const std::string &packageName) const; void UpdateAppDetailAbilityAttrs(); - bool IsCompressNativeLibs(const std::string &moduleName) const; private: void GetBundleWithAbilities( diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 7d377caf07..569557950a 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -2994,8 +2994,7 @@ ErrCode BaseBundleInstaller::RenameAllTempDir(const std::unordered_mapcompressNativeLibs; -} - bool InnerBundleInfo::IsUserExistModule(const std::string &moduleName, int32_t userId) const { std::string stringUserId = ""; -- Gitee From 8ec955e82d3c2c41c72b838811c7c54d9263445b Mon Sep 17 00:00:00 2001 From: junyi233 Date: Thu, 7 Dec 2023 16:16:08 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=9B=9E=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: junyi233 --- services/bundlemgr/include/bundle_data_mgr.h | 2 +- services/bundlemgr/src/bundle_data_mgr.cpp | 2 +- .../bundlemgr/src/quick_fix/quick_fix_deployer.cpp | 11 +++++++++++ .../bms_bundle_quick_fix_test.cpp | 14 +++++++++++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index b4958fd5d5..d9ad26e6d3 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -665,7 +665,7 @@ public: * @brief Obtains the PreInstallBundleInfo objects in Cache. * @return Returns PreInstallBundleInfos. */ - const std::vector& GetAllPreInstallBundleInfos(); + const std::vector GetAllPreInstallBundleInfos(); /** * @brief Restore uid and gid . * @return Returns true if this function is successfully called; returns false otherwise. diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 8f995a2bb5..a30cb521a5 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -3904,7 +3904,7 @@ bool BundleDataMgr::QueryAllDeviceIds(std::vector &deviceIds) #endif } -const std::vector& BundleDataMgr::GetAllPreInstallBundleInfos() +const std::vector BundleDataMgr::GetAllPreInstallBundleInfos() { std::lock_guard lock(preInstallInfoMutex_); return preInstallBundleInfos_; diff --git a/services/bundlemgr/src/quick_fix/quick_fix_deployer.cpp b/services/bundlemgr/src/quick_fix/quick_fix_deployer.cpp index bbd110550f..d114aba0e0 100755 --- a/services/bundlemgr/src/quick_fix/quick_fix_deployer.cpp +++ b/services/bundlemgr/src/quick_fix/quick_fix_deployer.cpp @@ -679,6 +679,17 @@ ErrCode QuickFixDeployer::SaveToInnerBundleInfo(const InnerAppQuickFix &newInner ErrCode QuickFixDeployer::ProcessBundleFilePaths(const std::vector &bundleFilePaths, std::vector &realFilePaths) { + for (const auto &path : bundleFilePaths) { + if (path.find(Constants::RELATIVE_PATH) != std::string::npos) { + APP_LOGE("ProcessBundleFilePaths path is illegal."); + return ERR_BUNDLEMANAGER_QUICK_FIX_PARAM_ERROR; + } + if (path.find(Constants::HAP_COPY_PATH + Constants::PATH_SEPARATOR + + Constants::QUICK_FIX_PATH + Constants::PATH_SEPARATOR) != 0) { + APP_LOGE("ProcessBundleFilePaths path is illegal."); + return ERR_BUNDLEMANAGER_QUICK_FIX_PARAM_ERROR; + } + } ErrCode ret = BundleUtil::CheckFilePath(bundleFilePaths, realFilePaths); if (ret != ERR_OK) { APP_LOGE("ProcessBundleFilePaths CheckFilePath failed."); diff --git a/services/bundlemgr/test/unittest/bms_bundle_quick_fix_test/bms_bundle_quick_fix_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_quick_fix_test/bms_bundle_quick_fix_test.cpp index 47ce4cc2be..1621a9cb88 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_quick_fix_test/bms_bundle_quick_fix_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_quick_fix_test/bms_bundle_quick_fix_test.cpp @@ -74,6 +74,9 @@ const std::string FILE1_PATH = "/data/test/hello.hqf"; const std::string FILE2_PATH = "/data/test/world.hqf"; const std::string FILE3_PATH = "/data/test/world.hap"; const std::string INVALID_FILE_SUFFIX_PATH = "/data/test/invalidSuffix.txt"; +const std::string INVALID_FILE_PATH_1 = "/data/service/el1/public/bms/bundle_manager_service/hello.hqf"; +const std::string INVALID_FILE_PATH_2 = "/data/service/el1/public/bms/bundle_manager_service/quick_fix/../hello.hqf"; +const std::string VALID_FILE_PATH_3 = "/data/service/el1/public/bms/bundle_manager_service/quick_fix/hello.hqf"; } // namespace class BmsBundleQuickFixTest : public testing::Test { @@ -1569,10 +1572,15 @@ HWTEST_F(BmsBundleQuickFixTest, BmsBundleQuickFixTest_0049, Function | SmallTest auto deployer = GetQuickFixDeployer(); EXPECT_FALSE(deployer == nullptr); if (deployer != nullptr) { - std::vector sourceFiles {FILE1_PATH, FILE2_PATH}; - CreateFiles(sourceFiles); + QuickFixManagerHostImpl quickFixManagerHostImpl; + std::string fileName = "test.hqf"; + int32_t fd = -1; + std::string path = ""; + auto res = quickFixManagerHostImpl.CreateFd(fileName, fd, path); + EXPECT_EQ(res, ERR_OK); + const std::vector sourceFiles {path}; std::vector realFilePaths; - ErrCode ret = deployer->ProcessBundleFilePaths(sourceFiles, realFilePaths); + auto ret = deployer->ProcessBundleFilePaths(sourceFiles, realFilePaths); EXPECT_EQ(ret, ERR_OK); DeleteFiles(sourceFiles); } -- Gitee