From 8edb5a85aff2b66d4706462788404548b14ae313 Mon Sep 17 00:00:00 2001 From: amao Date: Mon, 18 Nov 2024 20:14:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E6=9F=A5BaseBundleInstaller=20?= =?UTF-8?q?=E4=B8=8D=E5=90=88=E7=90=86=E7=9A=84Disable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: amao Change-Id: I22a701e83d82873356658322094d068f1b05427a --- .../bundlemgr/include/base_bundle_installer.h | 1 + .../bundlemgr/src/base_bundle_installer.cpp | 44 ++++++++++--------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 5f01291b3..39bc743a9 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -757,6 +757,7 @@ private: bool DeleteDisposedRuleWhenBundleUpdateEnd(const InnerBundleInfo &oldBundleInfo); void ProcessAddResourceInfo(const InstallParam &installParam, const std::string &bundleName, int32_t userId); + bool FetchInnerBundleInfo(InnerBundleInfo &info); InstallerState state_ = InstallerState::INSTALL_START; std::shared_ptr dataMgr_ = nullptr; // this pointer will get when public functions called diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 883f158f1..71d89aa3b 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -2422,8 +2422,7 @@ void BaseBundleInstaller::ProcessQuickFixWhenInstallNewModule(const InstallParam #ifdef BUNDLE_FRAMEWORK_QUICK_FIX // hqf extract diff file or apply diff patch failed does not affect the hap installation InnerBundleInfo bundleInfo; - bool isBundleExist = false; - if (!GetInnerBundleInfoWithDisable(bundleInfo, isBundleExist) || !isBundleExist) { + if (!FetchInnerBundleInfo(bundleInfo)) { return; } for (auto &info : newInfos) { @@ -4237,6 +4236,14 @@ bool BaseBundleInstaller::GetInnerBundleInfoWithDisable(InnerBundleInfo &info, b return true; } +bool BaseBundleInstaller::FetchInnerBundleInfo(InnerBundleInfo &info) +{ + if (!InitDataMgr()) { + return false; + } + return dataMgr_->FetchInnerBundleInfo(bundleName_, info); +} + bool BaseBundleInstaller::InitDataMgr() { if (dataMgr_ == nullptr) { @@ -4957,7 +4964,14 @@ void BaseBundleInstaller::OnSingletonChange(bool killProcess) if (singletonState_ == SingletonState::DEFAULT) { return; } - + if (!InitDataMgr()) { + return; + } + // need enable bundle when return + ScopeGuard enableGuard([&] { + dataMgr_->EnableBundle(bundleName_); + }); + InnerBundleInfo info; bool isExist = false; if (!GetInnerBundleInfoWithDisable(info, isExist) || !isExist) { @@ -5029,8 +5043,7 @@ void BaseBundleInstaller::GetInstallEventInfo(EventInfo &eventInfo) { LOG_D(BMS_TAG_INSTALLER, "GetInstallEventInfo start, bundleName:%{public}s", bundleName_.c_str()); InnerBundleInfo info; - bool isExist = false; - if (!GetInnerBundleInfoWithDisable(info, isExist) || !isExist) { + if (!FetchInnerBundleInfo(info)) { LOG_E(BMS_TAG_INSTALLER, "Get innerBundleInfo failed, bundleName: %{public}s", bundleName_.c_str()); return; } @@ -5436,12 +5449,8 @@ void BaseBundleInstaller::RemoveOldHapIfOTA(const InstallParam &installParam, if (!installParam.isOTA || installParam.copyHapToInstallPath) { return; } - if (!InitDataMgr()) { - LOG_E(BMS_TAG_INSTALLER, "init failed"); - return; - } InnerBundleInfo newInfo; - if (!dataMgr_->FetchInnerBundleInfo(bundleName_, newInfo)) { + if (!FetchInnerBundleInfo(newInfo)) { LOG_E(BMS_TAG_INSTALLER, "get failed for %{public}s", bundleName_.c_str()); return; } @@ -5577,8 +5586,7 @@ ErrCode BaseBundleInstaller::CheckHapEncryption(const std::unordered_map::GetInstance()->GetDataMgr(); - if (dataMgr == nullptr) { - APP_LOGE("Get dataMgr shared_ptr nullptr"); + if (!InitDataMgr()) { return false; } InnerBundleInfo info; - bool isAppExist = dataMgr->FetchInnerBundleInfo(bundleName, info); + bool isAppExist = dataMgr_->FetchInnerBundleInfo(bundleName, info); if (isAppExist) { const auto extensions = info.GetInnerExtensionInfos(); for (const auto &item : extensions) {