From 4680b4af960603d9ff47b80ac7b34efff39054b0 Mon Sep 17 00:00:00 2001 From: zhangyuhang72 Date: Tue, 26 Mar 2024 17:37:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=94=AF=E6=8C=81JIT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyuhang72 Change-Id: Ia80e0b88b1d4f23964b467f28f67704f9aae66e3 --- .../child_process_manager.cpp | 12 ++- .../native/appkit/app/child_main_thread.cpp | 2 +- frameworks/native/appkit/app/main_thread.cpp | 3 + frameworks/native/runtime/js_runtime.cpp | 6 ++ .../native/runtime/native_runtime_impl.cpp | 1 + .../include/appmgr/app_launch_data.h | 11 +++ .../include/appmgr/child_process_info.h | 1 + .../src/appmgr/app_launch_data.cpp | 6 ++ .../src/appmgr/child_process_info.cpp | 2 + .../include/child_process_manager.h | 3 +- .../inner_api/runtime/include/runtime.h | 1 + services/appmgr/BUILD.gn | 1 + .../include/advanced_security_mode_manager.h | 36 +++++++++ .../appmgr/include/app_mgr_service_inner.h | 4 + services/appmgr/include/app_running_record.h | 4 + .../src/advanced_security_mode_manager.cpp | 55 ++++++++++++++ services/appmgr/src/app_mgr_service_inner.cpp | 24 +++++- services/appmgr/src/app_running_record.cpp | 12 +++ test/unittest/BUILD.gn | 1 + .../BUILD.gn | 50 +++++++++++++ .../advanced_security_mode_manager_test.cpp | 73 +++++++++++++++++++ .../ams_ability_running_record_test/BUILD.gn | 1 + .../ams_recent_app_list_test/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../ams_service_startup_test/BUILD.gn | 1 + .../BUILD.gn | 1 + .../app_running_processes_info_test/BUILD.gn | 1 + .../main_thread_test/main_thread_test.cpp | 4 + .../child_process_manager_test.cpp | 2 +- 30 files changed, 315 insertions(+), 6 deletions(-) create mode 100644 services/appmgr/include/advanced_security_mode_manager.h create mode 100644 services/appmgr/src/advanced_security_mode_manager.cpp create mode 100755 test/unittest/advanced_security_mode_manager_test/BUILD.gn create mode 100755 test/unittest/advanced_security_mode_manager_test/advanced_security_mode_manager_test.cpp diff --git a/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp b/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp index a1263cfc55..83409143fd 100644 --- a/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp +++ b/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp @@ -43,6 +43,9 @@ namespace OHOS { namespace AbilityRuntime { +namespace { + bool g_jitEnabled = false; +} bool ChildProcessManager::signalRegistered_ = false; ChildProcessManager::ChildProcessManager() @@ -155,7 +158,7 @@ void ChildProcessManager::HandleChildProcessBySelfFork(const std::string &srcEnt return; } - auto runtime = CreateRuntime(bundleInfo, hapModuleInfo, false); + auto runtime = CreateRuntime(bundleInfo, hapModuleInfo, false, g_jitEnabled); if (!runtime) { HILOG_ERROR("Failed to create child process runtime"); return; @@ -192,7 +195,7 @@ bool ChildProcessManager::LoadJsFile(const std::string &srcEntry, const AppExecF } std::unique_ptr ChildProcessManager::CreateRuntime(const AppExecFwk::BundleInfo &bundleInfo, - const AppExecFwk::HapModuleInfo &hapModuleInfo, const bool fromAppSpawn) + const AppExecFwk::HapModuleInfo &hapModuleInfo, const bool fromAppSpawn, const bool jitEnabled) { AppExecFwk::ApplicationInfo applicationInfo = bundleInfo.applicationInfo; AbilityRuntime::Runtime::Options options; @@ -206,6 +209,7 @@ std::unique_ptr ChildProcessManager::CreateRuntime(cons options.arkNativeFilePath = applicationInfo.arkNativeFilePath; options.apiTargetVersion = applicationInfo.apiTargetVersion; options.loadAce = true; + options.jitEnabled = jitEnabled; std::shared_ptr eventRunner = fromAppSpawn ? AppExecFwk::EventRunner::GetMainEventRunner() : AppExecFwk::EventRunner::Create(); @@ -282,5 +286,9 @@ sptr ChildProcessManager::GetAppMgr() return iface_cast(object); } +void ChildProcessManager::SetForkProcessJITEnabled(bool jitEnabled) +{ + g_jitEnabled = jitEnabled; +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/appkit/app/child_main_thread.cpp b/frameworks/native/appkit/app/child_main_thread.cpp index 95655abb99..9a03ac72bf 100644 --- a/frameworks/native/appkit/app/child_main_thread.cpp +++ b/frameworks/native/appkit/app/child_main_thread.cpp @@ -146,7 +146,7 @@ void ChildMainThread::HandleLoadJs() return; } - runtime_ = childProcessManager.CreateRuntime(bundleInfoCopy, hapModuleInfo, true); + runtime_ = childProcessManager.CreateRuntime(bundleInfoCopy, hapModuleInfo, true, processInfo_->jitEnabled); if (!runtime_) { HILOG_ERROR("Failed to create child process runtime"); return; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 964424da57..a9a4b379b3 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -39,6 +39,7 @@ #include "bundle_mgr_proxy.h" #include "hitrace_meter.h" #include "child_main_thread.h" +#include "child_process_manager.h" #include "configuration_convertor.h" #include "common_event_manager.h" #include "context_deal.h" @@ -1339,6 +1340,8 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con options.arkNativeFilePath = bundleInfo.applicationInfo.arkNativeFilePath; options.uid = bundleInfo.applicationInfo.uid; options.apiTargetVersion = appInfo.apiTargetVersion; + options.jitEnabled = appLaunchData.IsJITEnabled(); + AbilityRuntime::ChildProcessManager::GetInstance().SetForkProcessJITEnabled(appLaunchData.IsJITEnabled()); if (!bundleInfo.hapModuleInfos.empty()) { for (auto hapModuleInfo : bundleInfo.hapModuleInfos) { options.hapModulePath[hapModuleInfo.moduleName] = hapModuleInfo.hapPath; diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 5c17891874..2f1bc67227 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -32,6 +32,7 @@ #include "extract_resource_manager.h" #include "file_path_utils.h" #include "hdc_register.h" +#include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" #include "hot_reloader.h" @@ -612,6 +613,8 @@ void JsRuntime::PostPreload(const Options& options) } bool profileEnabled = OHOS::system::GetBoolParameter("ark.profile", false); postOption.SetEnableProfile(profileEnabled); + TAG_LOGD(AAFwkTag::JSRUNTIME, "ASMM JIT Verify PostFork, jitEnabled: %{public}d", options.jitEnabled); + postOption.SetEnableJIT(options.jitEnabled); panda::JSNApi::PostFork(vm, postOption); reinterpret_cast(env)->ReinitUVLoop(); uv_loop_s* loop = nullptr; @@ -772,6 +775,8 @@ bool JsRuntime::CreateJsEnv(const Options& options) std::string asmOpcodeDisableRange = OHOS::system::GetParameter("persist.ark.asmopcodedisablerange", ""); pandaOption.SetEnableAsmInterpreter(asmInterpreterEnabled); pandaOption.SetAsmOpcodeDisableRange(asmOpcodeDisableRange); + TAG_LOGD(AAFwkTag::JSRUNTIME, "ASMM JIT Verify CreateJsEnv, jitEnabled: %{public}d", options.jitEnabled); + pandaOption.SetEnableJIT(options.jitEnabled); if (IsUseAbilityRuntime(options)) { // aot related @@ -1549,6 +1554,7 @@ void JsRuntime::SetChildOptions(const Options& options) childOptions_->apiTargetVersion = options.apiTargetVersion; childOptions_->packagePathStr = options.packagePathStr; childOptions_->assetBasePathStr = options.assetBasePathStr; + childOptions_->jitEnabled = options.jitEnabled; } std::shared_ptr JsRuntime::GetChildOptions() diff --git a/frameworks/native/runtime/native_runtime_impl.cpp b/frameworks/native/runtime/native_runtime_impl.cpp index 2f9491f084..1c35093e57 100644 --- a/frameworks/native/runtime/native_runtime_impl.cpp +++ b/frameworks/native/runtime/native_runtime_impl.cpp @@ -86,6 +86,7 @@ napi_status NativeRuntimeImpl::CreateJsEnv(const Options& options, std::shared_p std::string asmOpcodeDisableRange = OHOS::system::GetParameter("persist.ark.asmopcodedisablerange", ""); pandaOption.SetEnableAsmInterpreter(asmInterpreterEnabled); pandaOption.SetAsmOpcodeDisableRange(asmOpcodeDisableRange); + pandaOption.SetEnableJIT(options.jitEnabled); bool useAbilityRuntime = (options.isStageModel) || (options.isTestFramework); if (useAbilityRuntime) { diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h b/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h index 28124b9295..4e03e45ed4 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h @@ -172,6 +172,16 @@ public: return perfCmd_; } + inline void SetJITEnabled(const bool jitEnabled) + { + jitEnabled_ = jitEnabled; + } + + inline bool IsJITEnabled() const + { + return jitEnabled_; + } + /** * @brief read this Sequenceable object from a Parcel. * @@ -204,6 +214,7 @@ private: std::shared_ptr userTestRecord_ = nullptr; bool debugApp_ = false; std::string perfCmd_; + bool jitEnabled_ = false; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/include/appmgr/child_process_info.h b/interfaces/inner_api/app_manager/include/appmgr/child_process_info.h index 0ffcfe737c..cc0e4430d2 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/child_process_info.h +++ b/interfaces/inner_api/app_manager/include/appmgr/child_process_info.h @@ -29,6 +29,7 @@ struct ChildProcessInfo : public Parcelable { std::string bundleName; std::string processName; std::string srcEntry; + bool jitEnabled = false; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp index f25bd85945..3238d88ff1 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp @@ -97,6 +97,11 @@ bool AppLaunchData::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteBool(jitEnabled_)) { + HILOG_ERROR("Failed to write jitEnabled."); + return false; + } + return true; } @@ -138,6 +143,7 @@ bool AppLaunchData::ReadFromParcel(Parcel &parcel) debugApp_ = parcel.ReadBool(); perfCmd_ = parcel.ReadString(); + jitEnabled_ = parcel.ReadBool(); return true; } diff --git a/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp index e297194dd2..d23c61957b 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp @@ -39,6 +39,7 @@ bool ChildProcessInfo::ReadFromParcel(Parcel &parcel) bundleName = Str16ToStr8(parcel.ReadString16()); processName = Str16ToStr8(parcel.ReadString16()); srcEntry = Str16ToStr8(parcel.ReadString16()); + jitEnabled = parcel.ReadBool(); return true; } @@ -62,6 +63,7 @@ bool ChildProcessInfo::Marshalling(Parcel &parcel) const WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(processName)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcEntry)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, jitEnabled); return true; } } // namespace AppExecFwk diff --git a/interfaces/inner_api/child_process_manager/include/child_process_manager.h b/interfaces/inner_api/child_process_manager/include/child_process_manager.h index 5d1623e254..f4eb2f167f 100644 --- a/interfaces/inner_api/child_process_manager/include/child_process_manager.h +++ b/interfaces/inner_api/child_process_manager/include/child_process_manager.h @@ -44,9 +44,10 @@ public: bool GetBundleInfo(AppExecFwk::BundleInfo &bundleInfo); bool GetHapModuleInfo(const AppExecFwk::BundleInfo &bundleInfo, AppExecFwk::HapModuleInfo &hapModuleInfo); std::unique_ptr CreateRuntime(const AppExecFwk::BundleInfo &bundleInfo, - const AppExecFwk::HapModuleInfo &hapModuleInfo, const bool fromAppSpawn); + const AppExecFwk::HapModuleInfo &hapModuleInfo, const bool fromAppSpawn, const bool jitEnabled); bool LoadJsFile(const std::string &srcEntry, const AppExecFwk::HapModuleInfo &hapModuleInfo, std::unique_ptr &runtime); + void SetForkProcessJITEnabled(bool jitEnabled); private: ChildProcessManager(); diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 5fdc02edb6..d5786cb7e8 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -59,6 +59,7 @@ public: bool isJsFramework = false; bool isStageModel = true; bool isTestFramework = false; + bool jitEnabled = false; int32_t uid = -1; // ArkTsCard start bool isUnique = false; diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index ca023592c0..c523967107 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -38,6 +38,7 @@ ohos_shared_library("libappms") { include_dirs = [ "${ability_runtime_services_path}/appdfr/include" ] sources = [ "src/ability_running_record.cpp", + "src/advanced_security_mode_manager.cpp", "src/ams_mgr_scheduler.cpp", "src/app_config_data_manager.cpp", "src/app_death_recipient.cpp", diff --git a/services/appmgr/include/advanced_security_mode_manager.h b/services/appmgr/include/advanced_security_mode_manager.h new file mode 100644 index 0000000000..1abd7da13b --- /dev/null +++ b/services/appmgr/include/advanced_security_mode_manager.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_ADVANCED_SECURITY_MODE_MANAGER_H +#define OHOS_ABILITY_RUNTIME_ADVANCED_SECURITY_MODE_MANAGER_H + +#include + +namespace OHOS { +namespace AppExecFwk { +class AdvancedSecurityModeManager { +public: + AdvancedSecurityModeManager(); + virtual ~AdvancedSecurityModeManager(); + + void Init(); + bool IsJITEnabled(); + +private: + bool isAdvSecModeEnabled_ = false; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ADVANCED_SECURITY_MODE_MANAGER_H diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 9707115649..22e6893ed1 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -26,6 +26,7 @@ #include "ability_debug_response_interface.h" #include "ability_foreground_state_observer_interface.h" #include "ability_info.h" +#include "advanced_security_mode_manager.h" #include "app_death_recipient.h" #include "app_debug_listener_interface.h" #include "app_debug_manager.h" @@ -1254,6 +1255,8 @@ private: int32_t NotifyAbilitysDebugChange(const std::string &bundleName, const bool &isAppDebug); int32_t NotifyAbilitysAssertDebugChange(const std::shared_ptr &appRecord, bool isAssertDebug); + void SetProcessJITState(const std::shared_ptr appRecord); + bool JudgeSelfCalledByToken(const sptr &token, const PageStateData &pageStateData); void ParseServiceExtMultiProcessWhiteList(); @@ -1329,6 +1332,7 @@ private: mutable std::map killedPorcessMap_; std::shared_ptr appRunningStatusModule_; std::vector serviceExtensionWhiteList_; + std::shared_ptr securityModeManager_; std::shared_ptr dfxTaskHandler_; }; } // namespace AppExecFwk diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 653428673c..bcc0eba0ce 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -731,6 +731,9 @@ public: void SetAssertionPauseFlag(bool flag); bool IsAssertionPause() const; + + void SetJITEnabled(const bool jitEnabled); + bool IsJITEnabled() const; private: /** * SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilityStage data. @@ -842,6 +845,7 @@ private: std::string perfCmd_; int64_t startTimeMillis_ = 0; // The time of app start(CLOCK_MONOTONIC) int64_t restartTimeMillis_ = 0; // The time of last trying app restart + bool jitEnabled_ = false; std::shared_ptr userTestRecord_ = nullptr; diff --git a/services/appmgr/src/advanced_security_mode_manager.cpp b/services/appmgr/src/advanced_security_mode_manager.cpp new file mode 100644 index 0000000000..67d924aaf3 --- /dev/null +++ b/services/appmgr/src/advanced_security_mode_manager.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "advanced_security_mode_manager.h" + +#include + +#include "hilog_tag_wrapper.h" +#include "hitrace_meter.h" +#include "parameters.h" +#include "time_util.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +const std::string PARAM_GLOBAL_ADVANCED_MODE_STATE = "ohos.boot.advsecmode.state"; +} +AdvancedSecurityModeManager::AdvancedSecurityModeManager() +{ + TAG_LOGD(AAFwkTag::APPMGR, "ASMM constructor"); +} + +AdvancedSecurityModeManager::~AdvancedSecurityModeManager() +{ + TAG_LOGD(AAFwkTag::APPMGR, "ASMM deconstructor"); +} + +void AdvancedSecurityModeManager::Init() +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + int32_t state = OHOS::system::GetIntParameter(PARAM_GLOBAL_ADVANCED_MODE_STATE, 0); + isAdvSecModeEnabled_ = state > 0; + TAG_LOGI(AAFwkTag::APPMGR, "ASMM Init isAdvSecModeEnabled:%{public}d.", isAdvSecModeEnabled_); +} + +bool AdvancedSecurityModeManager::IsJITEnabled() +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::APPMGR, "ASMM IsJITEnabled %{public}d", !isAdvSecModeEnabled_); + return !isAdvSecModeEnabled_; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 4c34751f00..55aa0943d5 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -230,7 +230,8 @@ AppMgrServiceInner::AppMgrServiceInner() appRunningManager_(std::make_shared()), configuration_(std::make_shared()), appDebugManager_(std::make_shared()), - appRunningStatusModule_(std::make_shared()) + appRunningStatusModule_(std::make_shared()), + securityModeManager_(std::make_shared()) {} void AppMgrServiceInner::Init() @@ -243,6 +244,9 @@ void AppMgrServiceInner::Init() DelayedSingleton::GetInstance()->Init(); DelayedSingleton::GetInstance()->Init(); dfxTaskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("dfx_freeze_task_queue"); + if (securityModeManager_) { + securityModeManager_->Init(); + } } AppMgrServiceInner::~AppMgrServiceInner() @@ -2227,6 +2231,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str startMsg.procName = processName; startMsg.accessTokenIdEx = bundleInfo.applicationInfo.accessTokenIdEx; + SetProcessJITState(appRecord); PerfProfile::GetInstance().SetAppForkStartTime(GetTickCount()); pid_t pid = 0; TAG_LOGD(AAFwkTag::APPMGR, "bundleName: %{public}s.", bundleName.c_str()); @@ -2254,6 +2259,22 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str ProcessAppDebug(appRecord, appRecord->IsDebugApp()); } +void AppMgrServiceInner::SetProcessJITState(const std::shared_ptr appRecord) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::APPMGR, "SetProcessJITState called."); + if (!appRecord) { + HILOG_ERROR("appRecord is nullptr."); + return; + } + if (!securityModeManager_) { + HILOG_ERROR("securityModeManager_ is nullptr."); + appRecord->SetJITEnabled(true); + return; + } + appRecord->SetJITEnabled(securityModeManager_->IsJITEnabled()); +} + AppDebugInfo AppMgrServiceInner::MakeAppDebugInfo( const std::shared_ptr &appRecord, const bool &isDebugStart) { @@ -5404,6 +5425,7 @@ int32_t AppMgrServiceInner::GetChildProcessInfo(const std::shared_ptrGetBundleName(); info.processName = childProcessRecord->GetProcessName(); info.srcEntry = childProcessRecord->GetSrcEntry(); + info.jitEnabled = appRecord->IsJITEnabled(); return ERR_OK; } diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 6f4d4b1ab3..82c0e7860c 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -431,6 +431,8 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) launchData.SetAppIndex(appIndex_); launchData.SetDebugApp(isDebugApp_); launchData.SetPerfCmd(perfCmd_); + launchData.SetJITEnabled(jitEnabled_); + TAG_LOGD(AAFwkTag::APPMGR, "app is %{public}s.", GetName().c_str()); appLifeCycleDeal_->LaunchApplication(launchData, config); } @@ -1976,6 +1978,16 @@ std::map> AppRunningRecord::GetChil return childProcessRecordMap_; } +void AppRunningRecord::SetJITEnabled(const bool jitEnabled) +{ + jitEnabled_ = jitEnabled; +} + +bool AppRunningRecord::IsJITEnabled() const +{ + return jitEnabled_; +} + int32_t AppRunningRecord::GetAssignTokenId() const { return assignTokenId_; diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 441d4767a6..fe83829419 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -349,6 +349,7 @@ group("unittest") { "ability_timeout_test", "ability_token_proxy_test:unittest", "ability_token_stub_test:unittest", + "advanced_security_mode_manager_test:unittest", "ams_ability_running_record_test:unittest", "ams_app_death_recipient_test:unittest", "ams_app_life_cycle_test:unittest", diff --git a/test/unittest/advanced_security_mode_manager_test/BUILD.gn b/test/unittest/advanced_security_mode_manager_test/BUILD.gn new file mode 100755 index 0000000000..d640e5b779 --- /dev/null +++ b/test/unittest/advanced_security_mode_manager_test/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/appmgrservice" + +ohos_unittest("advanced_security_mode_manager_test") { + module_out_path = module_output_path + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + include_dirs = [ + "${ability_runtime_services_path}/appmgr/include", + "${ability_runtime_path}/utils/global/time/include", + ] + + sources = [ + "${ability_runtime_services_path}/appmgr/src/advanced_security_mode_manager.cpp", + "advanced_security_mode_manager_test.cpp", + ] + + deps = [ + "${ability_runtime_services_path}/appmgr:libappms", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":advanced_security_mode_manager_test" ] +} diff --git a/test/unittest/advanced_security_mode_manager_test/advanced_security_mode_manager_test.cpp b/test/unittest/advanced_security_mode_manager_test/advanced_security_mode_manager_test.cpp new file mode 100755 index 0000000000..4715e38f72 --- /dev/null +++ b/test/unittest/advanced_security_mode_manager_test/advanced_security_mode_manager_test.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#include "advanced_security_mode_manager.h" +#undef private +#include "hilog_tag_wrapper.h" +#include "parameters.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class AdvancedSecurityModeManagerTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + +protected: + bool deviceAdvSecModeEnabled_ = false; +}; + +void AdvancedSecurityModeManagerTest::SetUp() +{ + int32_t state = OHOS::system::GetIntParameter("ohos.boot.advsecmode.state", 0); + deviceAdvSecModeEnabled_ = state > 0; +} + +void AdvancedSecurityModeManagerTest::TearDown() +{} + +/** + * @tc.number: AdvancedSecurityModeManager_Init_0100 + * @tc.desc: Test Init works + * @tc.type: FUNC + */ +HWTEST_F(AdvancedSecurityModeManagerTest, AdvancedSecurityModeManager_Init_0100, TestSize.Level0) +{ + TAG_LOGD(AAFwkTag::TEST, "AdvancedSecurityModeManager_Init_0100 start."); + auto manager = std::make_shared(); + manager->Init(); + EXPECT_EQ(manager->isAdvSecModeEnabled_, deviceAdvSecModeEnabled_); +} + +/** + * @tc.number: AdvancedSecurityModeManager_IsJITEnabled_0100 + * @tc.desc: Test IsJITEnabled works + * @tc.type: FUNC + */ +HWTEST_F(AdvancedSecurityModeManagerTest, AdvancedSecurityModeManager_IsJITEnabled_0100, TestSize.Level0) +{ + TAG_LOGD(AAFwkTag::TEST, "AdvancedSecurityModeManager_IsJITEnabled_0100 start."); + auto manager = std::make_shared(); + manager->isAdvSecModeEnabled_ = true; + EXPECT_EQ(manager->IsJITEnabled(), false); +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index f4a377ff78..b15c9fc842 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -28,6 +28,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { sources = [ "${ability_runtime_services_path}/appmgr/src/ability_running_record.cpp", + "${ability_runtime_services_path}/appmgr/src/advanced_security_mode_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_config_data_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_death_recipient.cpp", "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", diff --git a/test/unittest/ams_recent_app_list_test/BUILD.gn b/test/unittest/ams_recent_app_list_test/BUILD.gn index 0eee45ac08..5ef291f46c 100644 --- a/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -27,6 +27,7 @@ ohos_unittest("AmsRecentAppListTest") { sources = [ "${ability_runtime_services_path}/appmgr/src/ability_running_record.cpp", + "${ability_runtime_services_path}/appmgr/src/advanced_security_mode_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_config_data_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_death_recipient.cpp", "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", diff --git a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn index d8284b9bd5..207e89cf4d 100644 --- a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn +++ b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn @@ -31,6 +31,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { sources = [ "${ability_runtime_services_path}/appmgr/src/ability_running_record.cpp", + "${ability_runtime_services_path}/appmgr/src/advanced_security_mode_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_config_data_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_death_recipient.cpp", "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", diff --git a/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/test/unittest/ams_service_load_ability_process_test/BUILD.gn index be4c18acee..7fbf48d17a 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -27,6 +27,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { sources = [ "${ability_runtime_services_path}/appmgr/src/ability_running_record.cpp", + "${ability_runtime_services_path}/appmgr/src/advanced_security_mode_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_config_data_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_death_recipient.cpp", "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index d81dcd9f56..276e1b9aa4 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -29,6 +29,7 @@ ohos_unittest("AmsServiceStartupTest") { sources = [ "${ability_runtime_services_path}/appmgr/src/ability_running_record.cpp", + "${ability_runtime_services_path}/appmgr/src/advanced_security_mode_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_config_data_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_death_recipient.cpp", "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index 2cf6e41743..10b20671d5 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -23,6 +23,7 @@ ohos_unittest("AMSEventHandlerTest") { sources = [ "${ability_runtime_services_path}/appmgr/src/ability_running_record.cpp", + "${ability_runtime_services_path}/appmgr/src/advanced_security_mode_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_config_data_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_death_recipient.cpp", "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", diff --git a/test/unittest/app_running_processes_info_test/BUILD.gn b/test/unittest/app_running_processes_info_test/BUILD.gn index 0436d272c3..cb6f23c604 100644 --- a/test/unittest/app_running_processes_info_test/BUILD.gn +++ b/test/unittest/app_running_processes_info_test/BUILD.gn @@ -28,6 +28,7 @@ ohos_unittest("AppRunningProcessesInfoTest") { sources = [ "${ability_runtime_services_path}/appmgr/src/ability_running_record.cpp", + "${ability_runtime_services_path}/appmgr/src/advanced_security_mode_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_config_data_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", diff --git a/test/unittest/appkit/main_thread_test/main_thread_test.cpp b/test/unittest/appkit/main_thread_test/main_thread_test.cpp index 872b6d7d9f..e402408742 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -1748,6 +1748,10 @@ HWTEST_F(MainThreadTest, HandleLaunchApplication_0500, TestSize.Level1) launchData.SetPerfCmd(perfCmd); EXPECT_EQ(launchData.GetPerfCmd(), perfCmd); + // check JIT enabled + launchData.SetJITEnabled(true) + EXPECT_EQ(launchData.IsJITEnabled(), true); + // check debug app bool appDebug = true; launchData.SetDebugApp(appDebug); diff --git a/test/unittest/child_process_manager_test/child_process_manager_test.cpp b/test/unittest/child_process_manager_test/child_process_manager_test.cpp index 367b13c48b..4a8f58ac4f 100644 --- a/test/unittest/child_process_manager_test/child_process_manager_test.cpp +++ b/test/unittest/child_process_manager_test/child_process_manager_test.cpp @@ -155,7 +155,7 @@ HWTEST_F(ChildProcessManagerTest, CreateRuntime_0100, TestSize.Level0) ret = ChildProcessManager::GetInstance().GetHapModuleInfo(bundleInfo, hapModuleInfo); EXPECT_TRUE(ret); - auto runtime = ChildProcessManager::GetInstance().CreateRuntime(bundleInfo, hapModuleInfo, false); + auto runtime = ChildProcessManager::GetInstance().CreateRuntime(bundleInfo, hapModuleInfo, false, false); EXPECT_TRUE(runtime != nullptr); }