From ed8f1036147dca09466c0d42c4251146e5effcea Mon Sep 17 00:00:00 2001 From: s30030188 Date: Mon, 11 Aug 2025 11:43:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B0=83=E8=AF=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30030188 --- frameworks/native/runtime/hdc_register.cpp | 30 ++++++++++++----- frameworks/native/runtime/hdc_register.h | 1 + frameworks/native/runtime/js_runtime.cpp | 16 ++++++++-- .../inner_api/runtime/include/js_runtime.h | 1 + services/appmgr/src/app_mgr_service_inner.cpp | 4 +-- .../app_mgr_service_inner_test.cpp | 4 +-- .../unittest/runtime_test/js_runtime_test.cpp | 32 +++++++++++++++++++ 7 files changed, 74 insertions(+), 14 deletions(-) diff --git a/frameworks/native/runtime/hdc_register.cpp b/frameworks/native/runtime/hdc_register.cpp index 496c1bdc464..d3d16882530 100644 --- a/frameworks/native/runtime/hdc_register.cpp +++ b/frameworks/native/runtime/hdc_register.cpp @@ -41,14 +41,8 @@ void HdcRegister::StartHdcRegister(const std::string& bundleName, const std::str { TAG_LOGD(AAFwkTag::JSRUNTIME, "called"); - if (debugMode == BOTH_REG) { - registerLocalHandler_ = dlopen("libda_register.z.so", RTLD_LAZY); - registerHdcHandler_ = dlopen("libhdc_register.z.so", RTLD_LAZY); - } else if (debugMode == LOCAL_DEBUG_REG) { - registerLocalHandler_ = dlopen("libda_register.z.so", RTLD_LAZY); - } else { - registerHdcHandler_ = dlopen("libhdc_register.z.so", RTLD_LAZY); - } + OpenRegisterSo(debugMode); + if (registerLocalHandler_ != nullptr) { auto startRegister = reinterpret_cast(dlsym(registerLocalHandler_, "StartConnect")); if (startRegister != nullptr) { @@ -97,4 +91,24 @@ void HdcRegister::StopHdcRegister() TAG_LOGE(AAFwkTag::JSRUNTIME, "null registerHdcHandler_"); } } + +void HdcRegister::OpenRegisterSo(DebugRegisterMode debugMode) +{ + if (debugMode == BOTH_REG) { + if (registerLocalHandler_ == nullptr) { + registerLocalHandler_ = dlopen("libda_register.z.so", RTLD_LAZY); + } + if (registerHdcHandler_ == nullptr) { + registerHdcHandler_ = dlopen("libhdc_register.z.so", RTLD_LAZY); + } + } else if (debugMode == LOCAL_DEBUG_REG) { + if (registerLocalHandler_ == nullptr) { + registerLocalHandler_ = dlopen("libda_register.z.so", RTLD_LAZY); + } + } else { + if (registerHdcHandler_ == nullptr) { + registerHdcHandler_ = dlopen("libhdc_register.z.so", RTLD_LAZY); + } + } +} } // namespace OHOS::AbilityRuntime diff --git a/frameworks/native/runtime/hdc_register.h b/frameworks/native/runtime/hdc_register.h index 132a818fa28..08089194ab4 100644 --- a/frameworks/native/runtime/hdc_register.h +++ b/frameworks/native/runtime/hdc_register.h @@ -39,6 +39,7 @@ private: ~HdcRegister(); void StopHdcRegister(); + void OpenRegisterSo(DebugRegisterMode debugMode); void* registerHdcHandler_ = nullptr; void* registerLocalHandler_ = nullptr; diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 5084526ede9..50a67d444a8 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -164,8 +164,8 @@ void JsRuntime::StartDebugMode(const DebugOption dOption) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::JSRUNTIME, "localDebug %{public}d", dOption.isDebugFromLocal); - if (!dOption.isDebugFromLocal && !dOption.isDeveloperMode) { - TAG_LOGE(AAFwkTag::JSRUNTIME, "developer Mode false"); + if (!IsAllowStartWithDebug(dOption)) { + TAG_LOGE(AAFwkTag::JSRUNTIME, "developer mode false or no locl debug"); return; } CHECK_POINTER(jsEnv_); @@ -1766,5 +1766,17 @@ void JsRuntime::StartLocalDebugMode(bool isDebugFromLocal) debugOption_.isDebugFromLocal = isDebugFromLocal; StartDebugMode(debugOption_); } + +bool JsRuntime::IsAllowStartWithDebug(const DebugOption debugOption) +{ + if (debugOption.isDebugFromLocal && debugOption.isStartWithDebug) { + return true; + } + if (debugOption.isDeveloperMode && !debugOption.isDebugFromLocal) { + return true; + } + TAG_LOGE(AAFwkTag::JSRUNTIME, "not allow debug"); + return false; +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index 58283c8a7a5..2a2c0c30a25 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -199,6 +199,7 @@ private: void PostPreload(const Options& options); void LoadAotFile(const Options& options); void SetRequestAotCallback(); + bool IsAllowStartWithDebug(const DebugOption debugOption); std::string GetSystemKitPath(); std::vector GetSystemKitsMap(uint32_t version); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index afdb5a6f85d..801ed6f8cbb 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -7875,8 +7875,8 @@ int32_t AppMgrServiceInner::UnregisterAppDebugListener(const sptrappRunningManager_ = std::make_shared(); appMgrServiceInner->appDebugManager_ = std::make_shared(); - auto result = appMgrServiceInner->AttachAppDebug(bundleName, false); + auto result = appMgrServiceInner->AttachAppDebug(bundleName, true); EXPECT_EQ(result, ERR_OK); } @@ -4506,7 +4506,7 @@ HWTEST_F(AppMgrServiceInnerTest, AttachAppDebug_002, TestSize.Level2) std::string bundleName; appMgrServiceInner->appRunningManager_ = nullptr; appMgrServiceInner->appDebugManager_ = std::make_shared(); - auto result = appMgrServiceInner->AttachAppDebug(bundleName, false); + auto result = appMgrServiceInner->AttachAppDebug(bundleName, true); EXPECT_EQ(result, ERR_NO_INIT); } diff --git a/test/unittest/runtime_test/js_runtime_test.cpp b/test/unittest/runtime_test/js_runtime_test.cpp index 35729356218..d97eb92fe0c 100755 --- a/test/unittest/runtime_test/js_runtime_test.cpp +++ b/test/unittest/runtime_test/js_runtime_test.cpp @@ -1891,5 +1891,37 @@ HWTEST_F(JsRuntimeTest, RegisterUncatchableExceptionHandler_0100, TestSize.Level EXPECT_NE(jsRuntime, nullptr); TAG_LOGI(AAFwkTag::TEST, "RegisterUncatchableExceptionHandler_0100 end"); } + +/** + * @tc.name: IsAllowStartWithDebug_0100 + * @tc.desc: JsRuntime test for IsAllowStartWithDebug. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(JsRuntimeTest, IsAllowStartWithDebug_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsAllowStartWithDebug_0100 start"); + auto jsRuntime = std::make_unique(); + AbilityRuntime::Runtime::DebugOption debugOption; + debugOption.isDeveloperMode = false; + debugOption.isDebugFromLocal = false; + debugOption.isStartWithDebug = false; + TAG_LOGI(AAFwkTag::TEST, "delevlop is false, is not local debug"); + EXPECT_EQ(jsRuntime->IsAllowStartWithDebug(debugOption), false); + + debugOption.isDeveloperMode = false; + debugOption.isDebugFromLocal = true; + debugOption.isStartWithDebug = false; + TAG_LOGI(AAFwkTag::TEST, "local debug, not -D"); + EXPECT_EQ(jsRuntime->IsAllowStartWithDebug(debugOption), false); + + debugOption.isDeveloperMode = false; + debugOption.isDebugFromLocal = true; + debugOption.isStartWithDebug = true; + TAG_LOGI(AAFwkTag::TEST, "local debug and -D"); + EXPECT_EQ(jsRuntime->IsAllowStartWithDebug(debugOption), true); + + TAG_LOGI(AAFwkTag::TEST, "RegisterUncatchableExceptionHandler_0100 end"); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file -- Gitee