diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index d95edf3f7e..408889e5ec 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -33,6 +33,11 @@ BundleMgrHelper::~BundleMgrHelper() } } +void BundleMgrHelper::PreConnect() +{ + Connect(); +} + ErrCode BundleMgrHelper::GetNameForUid(const int32_t uid, std::string &name) { TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called"); @@ -204,7 +209,7 @@ std::string BundleMgrHelper::GetAppIdByBundleName(const std::string &bundleName, TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to connect."); return ""; } - + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); return bundleMgr->GetAppIdByBundleName(bundleName, userId); } diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index ca3bb9e854..6da357339f 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -364,6 +364,13 @@ void MainThread::Attach() return; } mainThreadState_ = MainThreadState::ATTACH; + isDeveloperMode_ = system::GetBoolParameter(DEVELOPER_MODE_STATE, false); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); + if (bundleMgrHelper == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "The bundleMgrHelper is nullptr"); + return; + } + bundleMgrHelper->PreConnect(); } /** @@ -1042,10 +1049,6 @@ void MainThread::OnStartAbility(const std::string &bundleName, loadPath = std::regex_replace(loadPath, pattern, std::string(LOCAL_CODE_PATH)); TAG_LOGD(AAFwkTag::APPKIT, "ModuleResPath: %{public}s", loadPath.c_str()); // getOverlayPath - auto res = GetOverlayModuleInfos(bundleName, entryHapModuleInfo.moduleName, overlayModuleInfos_); - if (res != ERR_OK) { - TAG_LOGW(AAFwkTag::APPKIT, "getOverlayPath failed"); - } if (overlayModuleInfos_.size() == 0) { if (!resourceManager->AddResource(loadPath.c_str())) { TAG_LOGE(AAFwkTag::APPKIT, "AddResource failed"); @@ -1527,7 +1530,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con debugOption.perfCmd = perfCmd; runtime->StartProfiler(debugOption); } else { - runtime->StartDebugMode(debugOption); + if (isDeveloperMode_) { + runtime->StartDebugMode(debugOption); + } } std::vector hqfInfos = appInfo.appQuickFix.deployedAppqfInfo.hqfInfos; @@ -1676,11 +1681,10 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con entryHapModuleInfo.hapPath.empty() ? entryHapModuleInfo.resourcePath : entryHapModuleInfo.hapPath; std::regex inner_pattern(std::string(ABS_CODE_PATH) + std::string(FILE_SEPARATOR) + bundleInfo.name); loadPath = std::regex_replace(loadPath, inner_pattern, LOCAL_CODE_PATH); - std::vector overlayModuleInfos; - auto res = GetOverlayModuleInfos(bundleInfo.name, moduleName, overlayModuleInfos); + auto res = GetOverlayModuleInfos(bundleInfo.name, moduleName, overlayModuleInfos_); std::vector overlayPaths; if (res == ERR_OK) { - overlayPaths = GetAddOverlayPaths(overlayModuleInfos); + overlayPaths = GetAddOverlayPaths(overlayModuleInfos_); } std::unique_ptr resConfig(Global::Resource::CreateResConfig()); int32_t appType; @@ -3244,12 +3248,12 @@ void MainThread::AssertFaultResumeMainThreadDetection() void MainThread::HandleInitAssertFaultTask(bool isDebugModule, bool isDebugApp) { - if (!system::GetBoolParameter(PRODUCT_ASSERT_FAULT_DIALOG_ENABLED, false)) { - TAG_LOGD(AAFwkTag::APPKIT, "Unsupport assert fault dialog"); + if (!isDeveloperMode_) { + TAG_LOGE(AAFwkTag::APPKIT, "Developer Mode is false"); return; } - if (!system::GetBoolParameter(DEVELOPER_MODE_STATE, false)) { - TAG_LOGE(AAFwkTag::APPKIT, "Developer Mode is false"); + if (!system::GetBoolParameter(PRODUCT_ASSERT_FAULT_DIALOG_ENABLED, false)) { + TAG_LOGD(AAFwkTag::APPKIT, "Unsupport assert fault dialog"); return; } if (!isDebugApp) { diff --git a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h index e0ca6ad6d1..5ce22db0d8 100644 --- a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h +++ b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h @@ -27,6 +27,7 @@ using Want = OHOS::AAFwk::Want; class BundleMgrHelper : public std::enable_shared_from_this { public: DISALLOW_COPY_AND_MOVE(BundleMgrHelper); + void PreConnect(); ErrCode GetNameForUid(const int32_t uid, std::string &name); ErrCode GetNameAndIndexForUid(const int32_t uid, std::string &bundleName, int32_t &appIndex); bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId); @@ -109,7 +110,7 @@ private: sptr ConnectBundleInstaller(); void OnDeath(); std::string ParseBundleNameByAppId(const std::string &appId) const; - + private: DECLARE_DELAYED_SINGLETON(BundleMgrHelper) std::mutex mutex_; diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index 94582d35fa..05c0c3af85 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -661,6 +661,7 @@ private: std::string pathSeparator_ = "/"; std::string abilityLibraryType_ = ".so"; static std::weak_ptr applicationForDump_; + bool isDeveloperMode_ = false; #ifdef ABILITY_LIBRARY_LOADER /**