diff --git a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h index 7fed4bf25..170303345 100644 --- a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h +++ b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h @@ -233,6 +233,7 @@ enum { ERR_APPEXECFWK_AOT_ARGS_EMPTY = 8519929, ERR_APPEXECFWK_INSTALLD_GENERATE_KEY_FAILED = 8519930, ERR_APPEXECFWK_INSTALLD_DELETE_KEY_FAILED = 8519931, + ERR_APPEXECFWK_INSTALLD_SIGN_AOT_FAILED = 8519932, ERR_APPEXECFWK_RECOVER_GET_BUNDLEPATH_ERROR = APPEXECFWK_BUNDLEMGR_ERR_OFFSET + 0x0201, // 8520193 ERR_APPEXECFWK_RECOVER_INVALID_BUNDLE_NAME = 8520194, diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h index 70f9f90f0..c968b2863 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h @@ -802,8 +802,8 @@ public: * @param isAllBundle Does it represent all bundlenames. * @return Returns true if the compile result is successfully obtained; returns false otherwise. */ - virtual ErrCode CompileProcessAOT( - const std::string &bundleName, const std::string &compileMode, bool isAllBundle) + virtual ErrCode CompileProcessAOT(const std::string &bundleName, const std::string &compileMode, + bool isAllBundle, std::vector &compileResults) { return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; } diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h index 1c1664319..90fcf8d66 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h @@ -570,8 +570,8 @@ public: * @param isAllBundle Does it represent all bundlenames. * @return Returns result of the operation. */ - virtual ErrCode CompileProcessAOT( - const std::string &bundleName, const std::string &compileMode, bool isAllBundle) override; + virtual ErrCode CompileProcessAOT(const std::string &bundleName, const std::string &compileMode, + bool isAllBundle, std::vector &compileResults) override; /** * @brief Reset the bundle informations with specific flags through the proxy object. * @param bundleName Indicates the bundle name if needed. diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp index 4f69455d0..20d788599 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp @@ -1557,14 +1557,21 @@ ErrCode BundleMgrHost::HandleCompileProcessAOT(MessageParcel &data, MessageParce std::string bundleName = data.ReadString(); std::string compileMode = data.ReadString(); bool isAllBundle = data.ReadBool(); + std::vector compileResults; APP_LOGI("compile info name %{public}s", bundleName.c_str()); - ErrCode ret = CompileProcessAOT(bundleName, compileMode, isAllBundle); + ErrCode ret = CompileProcessAOT(bundleName, compileMode, isAllBundle, compileResults); APP_LOGI("ret is %{public}d", ret); if (!reply.WriteInt32(ret)) { APP_LOGE("write failed"); return ERR_APPEXECFWK_PARCEL_ERROR; } + if (ret != ERR_OK) { + if (!reply.WriteStringVector(compileResults)) { + APP_LOGE("write compile process AOT results failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } return ERR_OK; } diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp index f254758a5..c29ea53af 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp @@ -4723,8 +4723,8 @@ ErrCode BundleMgrProxy::InnerGetBigString(MessageParcel &reply, std::string &res return ERR_OK; } -ErrCode BundleMgrProxy::CompileProcessAOT( - const std::string &bundleName, const std::string &compileMode, bool isAllBundle) +ErrCode BundleMgrProxy::CompileProcessAOT(const std::string &bundleName, const std::string &compileMode, + bool isAllBundle, std::vector &compileResults) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); APP_LOGD("begin to compile"); @@ -4751,7 +4751,14 @@ ErrCode BundleMgrProxy::CompileProcessAOT( APP_LOGE("fail to compile from server"); return ERR_APPEXECFWK_PARCEL_ERROR; } - return ERR_OK; + ErrCode ret = reply.ReadInt32(); + if (ret != ERR_OK) { + if (!reply.ReadStringVector(&compileResults)) { + APP_LOGE("fail to get compile results from reply"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } + return ret; } ErrCode BundleMgrProxy::CompileReset(const std::string &bundleName, bool isAllBundle) diff --git a/services/bundlemgr/include/aot/aot_handler.h b/services/bundlemgr/include/aot/aot_handler.h index a4a71de06..e9429170a 100644 --- a/services/bundlemgr/include/aot/aot_handler.h +++ b/services/bundlemgr/include/aot/aot_handler.h @@ -36,7 +36,8 @@ public: void HandleInstall(const std::unordered_map &infos) const; void HandleOTA(); void HandleIdle() const; - void HandleCompile(const std::string &bundleName, const std::string &compileMode, bool isAllBundle) const; + ErrCode HandleCompile(const std::string &bundleName, const std::string &compileMode, bool isAllBundle, + std::vector &compileResults) const; void HandleResetAOT(const std::string &bundleName, bool isAllBundle) const; ErrCode HandleCopyAp(const std::string &bundleName, bool isAllBundle, std::vector &results) const; private: @@ -57,6 +58,10 @@ private: const InnerBundleInfo &info, const std::string &moduleName, const std::string &compileMode) const; EventInfo HandleCompileWithBundle(const std::string &bundleName, const std::string &compileMode, std::shared_ptr dataMgr) const; + ErrCode HandleCompileBundles(const std::vector &bundleNames, const std::string &compileMode, + std::shared_ptr &dataMgr, std::vector &compileResults) const; + ErrCode HandleCompileModules(const std::vector &moduleNames, const std::string &compileMode, + InnerBundleInfo &info, std::string &compileResult) const; void ClearArkCacheDir() const; void ResetAOTFlags() const; void HandleIdleWithSingleHap( diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index 5725dfcfe..1ba5b3ae9 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -550,8 +550,8 @@ public: * @param isAllBundle Does it represent all bundlenames. * @return Returns true if the compile result is successfully obtained; returns false otherwise. */ - virtual ErrCode CompileProcessAOT( - const std::string &bundleName, const std::string &compileMode, bool isAllBundle) override; + virtual ErrCode CompileProcessAOT(const std::string &bundleName, const std::string &compileMode, + bool isAllBundle, std::vector &compileResults) override; /** * @brief Compile the bundle informations with specific flags. * @param bundleName Indicates the bundle name if needed. diff --git a/services/bundlemgr/src/aot/aot_executor.cpp b/services/bundlemgr/src/aot/aot_executor.cpp index e4775e851..2e723dca2 100644 --- a/services/bundlemgr/src/aot/aot_executor.cpp +++ b/services/bundlemgr/src/aot/aot_executor.cpp @@ -58,6 +58,7 @@ constexpr const char* APP_IDENTIFIER = "appIdentifier"; constexpr const char* IS_ENCRYPTED_BUNDLE = "isEncryptedBundle"; constexpr const char* IS_SCREEN_OFF = "isScreenOff"; constexpr const char* PGO_DIR = "pgoDir"; +const int32_t ERR_AOT_COMPILER_SIGN_FAILED = 10004; } AOTExecutor& AOTExecutor::GetInstance() @@ -194,12 +195,12 @@ ErrCode AOTExecutor::EnforceCodeSign(const AOTArgs &aotArgs, const std::vector &compileResults) const { APP_LOGI("HandleCompile begin"); std::unique_lock lock(compileMutex_, std::defer_lock); if (!lock.try_lock()) { APP_LOGI("compile task is running, skip %{public}s", bundleName.c_str()); - return; + std::string compileResult = "info: compile task is running, skip."; + compileResults.emplace_back(compileResult); + return ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED; } if (!IsSupportARM64()) { APP_LOGI("current device doesn't support arm64, no need to AOT"); - return; + std::string compileResult = "info: current device doesn't support arm64, no need to AOT."; + compileResults.emplace_back(compileResult); + return ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED; } if (compileMode == COMPILE_NONE) { APP_LOGI("%{public}s = none, no need to AOT", IDLE_COMPILE_MODE); - return; + std::string compileResult = "info: persist.bm.idle.arkopt = none, no need to AOT."; + compileResults.emplace_back(compileResult); + return ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED; } auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); if (!dataMgr) { APP_LOGE("dataMgr is null"); - return; + std::string compileResult = "error: dataMgr is null, compile fail."; + compileResults.emplace_back(compileResult); + return ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED; } std::vector bundleNames; if (isAllBundle) { @@ -734,25 +743,78 @@ void AOTHandler::HandleCompile(const std::string &bundleName, const std::string } else { bundleNames = {bundleName}; } - std::for_each(bundleNames.cbegin(), bundleNames.cend(), [this, dataMgr, &compileMode](const auto &bundleToCompile) { + ErrCode ret = HandleCompileBundles(bundleNames, compileMode, dataMgr, compileResults); + if (ret == ERR_OK) { + compileResults.clear(); + } + APP_LOGI("HandleCompile end"); + return ret; +} + +ErrCode AOTHandler::HandleCompileBundles(const std::vector &bundleNames, const std::string &compileMode, + std::shared_ptr &dataMgr, std::vector &compileResults) const +{ + ErrCode ret = ERR_OK; + std::for_each(bundleNames.cbegin(), bundleNames.cend(), + [this, dataMgr, &compileMode, &ret, &compileResults](const auto &bundleToCompile) { APP_LOGD("HandleCompile bundleToCompile : %{public}s", bundleToCompile.c_str()); InnerBundleInfo info; if (!dataMgr->QueryInnerBundleInfo(bundleToCompile, info)) { APP_LOGE("QueryInnerBundleInfo failed. bundleToCompile: %{public}s", bundleToCompile.c_str()); + std::string compileResult = bundleToCompile + ": QueryInnerBundleInfo failed."; + compileResults.emplace_back(compileResult); + ret = ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED; return; } if (!info.GetIsNewVersion()) { APP_LOGD("not stage model, no need to AOT"); + std::string compileResult = bundleToCompile + ": not stage model, no need to AOT."; + compileResults.emplace_back(compileResult); + ret = ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED; return; } std::vector moduleNames; info.GetModuleNames(moduleNames); - std::for_each(moduleNames.cbegin(), moduleNames.cend(), - [this, &info, &compileMode](const auto &moduleName) { - (void)HandleCompileWithSingleHap(info, moduleName, compileMode); - }); + std::string compileResult = ""; + if (HandleCompileModules(moduleNames, compileMode, info, compileResult) == ERR_OK) { + compileResult = bundleToCompile + ": compile success."; + } else { + compileResult = bundleToCompile + ":" + compileResult; + ret = ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED; + } + compileResults.emplace_back(compileResult); }); - APP_LOGI("HandleCompile end"); + return ret; +} + +ErrCode AOTHandler::HandleCompileModules(const std::vector &moduleNames, const std::string &compileMode, + InnerBundleInfo &info, std::string &compileResult) const +{ + ErrCode ret = ERR_OK; + std::for_each(moduleNames.cbegin(), moduleNames.cend(), + [this, &info, &compileMode, &ret, &compileResult](const auto &moduleName) { + ErrCode errCode = HandleCompileWithSingleHap(info, moduleName, compileMode); + switch (errCode) { + case ERR_OK: + break; + case ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED: + compileResult += " " + moduleName + ":compile-fail"; + break; + case ERR_APPEXECFWK_INSTALLD_SIGN_AOT_FAILED: + compileResult += " " + moduleName + ":signature-fail"; + break; + case ERR_APPEXECFWK_AOT_ARGS_EMPTY: + compileResult += " " + moduleName + ":args-empty"; + break; + default: + compileResult += " " + moduleName + ":other-fail"; + break; + } + if (errCode != ERR_OK) { + ret = ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED; + } + }); + return ret; } } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index d0df34c4d..ac60c1cee 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -1709,15 +1709,14 @@ bool BundleMgrHostImpl::UnregisterBundleStatusCallback() return dataMgr->UnregisterBundleStatusCallback(); } -ErrCode BundleMgrHostImpl::CompileProcessAOT( - const std::string &bundleName, const std::string &compileMode, bool isAllBundle) +ErrCode BundleMgrHostImpl::CompileProcessAOT(const std::string &bundleName, const std::string &compileMode, + bool isAllBundle, std::vector &compileResults) { if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED)) { APP_LOGE("verify permission failed"); return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; } - AOTHandler::GetInstance().HandleCompile(bundleName, compileMode, isAllBundle); - return ERR_OK; + return AOTHandler::GetInstance().HandleCompile(bundleName, compileMode, isAllBundle, compileResults); } ErrCode BundleMgrHostImpl::CompileReset(const std::string &bundleName, bool isAllBundle) diff --git a/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp index 8d40c8a5c..fcf7201c3 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp @@ -575,15 +575,16 @@ HWTEST_F(BmsAOTMgrTest, AOTHandler_1100, Function | SmallTest | Level0) HWTEST_F(BmsAOTMgrTest, AOTHandler_1200, Function | SmallTest | Level0) { std::string bundleName = ""; + std::vector results; ClearDataMgr(); - AOTHandler::GetInstance().HandleCompile(bundleName, COMPILE_NONE, true); + AOTHandler::GetInstance().HandleCompile(bundleName, COMPILE_NONE, true, results); EXPECT_EQ(bundleName, ""); ResetDataMgr(); - AOTHandler::GetInstance().HandleCompile(bundleName, Constants::COMPILE_PARTIAL, true); + AOTHandler::GetInstance().HandleCompile(bundleName, Constants::COMPILE_PARTIAL, true, results); EXPECT_EQ(bundleName, ""); - AOTHandler::GetInstance().HandleCompile(bundleName, Constants::COMPILE_PARTIAL, false); + AOTHandler::GetInstance().HandleCompile(bundleName, Constants::COMPILE_PARTIAL, false, results); EXPECT_EQ(bundleName, ""); } diff --git a/test/systemtest/common/bms/bms_install_system_test/bms_install_system_test.cpp b/test/systemtest/common/bms/bms_install_system_test/bms_install_system_test.cpp index db2252316..37cbeb68e 100644 --- a/test/systemtest/common/bms/bms_install_system_test/bms_install_system_test.cpp +++ b/test/systemtest/common/bms/bms_install_system_test/bms_install_system_test.cpp @@ -1902,7 +1902,8 @@ HWTEST_F(BmsInstallSystemTest, CompileProcessAOT_0100, Function | SmallTest | Le APP_LOGE("bundle mgr proxy is nullptr."); EXPECT_EQ(bundleMgrProxy, nullptr); } - ErrCode ret = bundleMgrProxy->CompileProcessAOT("", "", false); + std::vector results; + ErrCode ret = bundleMgrProxy->CompileProcessAOT("", "", false, results); EXPECT_EQ(ret, ERR_OK); }