!18825 merge master into master

启动流程新增 InitJSLeakWatcher

Created-by: liuzongze
Commit-by: liuzongze
Merged-by: openharmony_ci
Description: **IssueNo**:
https://gitcode.com/openharmony/hiviewdfx_hichecker/issues/188
**Description**:

**稳定性自检:**
| 自检项                                                       | 自检结果  |
| ------------------------------------------------------------ | -------- |
| 涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发              |    不涉及      |
| 成员变量进行赋值或创建需要排查并发                               |    不涉及      |
| 谨慎在lambda表达式中使用引用捕获                                |     不涉及     |
| 谨慎在未经拷贝的情况下使用外部传入的string、C字符串               |  不涉及        |
| map\vector\list\set等stl模板类使用时需要排查并发                |    不涉及      |
| 谨慎考虑加锁范围                                               |     不涉及     |
| 在IPC通信中谨慎使用同步通信方式                                 |     不涉及     |
| 禁止传递this指针至其他模块或线程(特别是eventhandler任务)        |    不涉及      |
| 禁止将外部传入的裸指针在内部直接构造智能指针                      |   不涉及       |
| 禁止多个独立创建的智能指针管理同一地址                           |   不涉及       |
| 禁止在析构函数中抛异步任务                                      |      不涉及    |
| 禁止js对象在非js线程(例如在IPC线程)创建、使用或销毁             |     不涉及     |
| 禁止在对外接口中未经判空直接使用外部传入的指针                    |     不涉及     |
| 禁止接口返回局部变量引用                                        |     不涉及     |
| 禁止在信号函数中加锁                                            |     不涉及     |
| 禁止在关键流程(SA启动、应用启动等主流程)执行耗时的操作           |    不涉及      |
| 禁止将同一个cpp编译在不同的so中                                 |    不涉及      |

**安全编码自检:**
| 自检项                                                          | 自检结果 |
| -------------------------------------------------------------- | -------- |
| 裸指针避免通过隐式转换构造为sptr                                 |    不涉及      |
| json对象在取值之前必须先判断类型,避免类型不匹配                   |   不涉及       |
| 序列化时必须对传入的数组大小进行校验,避免出现超大数组              |    不涉及      |
| 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型            |    不涉及      |
| 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验 |     不涉及     |
| 指针变量、表示资源描述符的变量、bool变量必须赋初值                  |   不涉及       |
| readParcelable获取的对象使用前需要判空                            |    不涉及      |
| 分配和释放内存的函数需要成对出现                                   |    不涉及      |
| 申请内存后异常退出前需要及时进行内存释放                            |    不涉及      |
| 内存申请前必须对内存大小进行合法性校验                              |      不涉及    |
| 内存分配后必须判断是否成功                                         |    不涉及      |
| 禁止使用realloc、alloca函数                                       |    不涉及      |
| 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰          |    不涉及      |
| 禁止打印内存地址                                                  |   不涉及       |
| 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0               |    不涉及      |
| 禁止对有符号整数进行位操作符运算                                    |    不涉及      |
| 禁止对指针进行逻辑或位运算                                         |  不涉及        |
| 循环次数如果收外部数据控制,需要检验其合法性                         |     不涉及     |
| 禁止使用内存操作类危险函数,需要使用安全函数                         |      不涉及    |
| 谨慎使用不可重入函数                                               |  不涉及        |
| 必须检查安全函数的返回值,并进行正确处理                             |   不涉及       |
| 禁止仅通过TokenType类型判断绕过权限校验                             |   不涉及       |

**TDD Result**:

**XTS Result**:

### 是否已执行L0用例
- [x] 已验证
- [ ] 不涉及。如不涉及,请写明理由


See merge request: openharmony/ability_ability_runtime!18825
This commit is contained in:
openharmony_ci
2026-03-29 18:03:10 +08:00
13 changed files with 144 additions and 0 deletions
+1
View File
@@ -214,6 +214,7 @@ ohos_shared_library("appkit_native") {
"graphic_2d:librender_service_base",
"hicollie:libhicollie",
"hilog:libhilog",
"hichecker:libhichecker",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"i18n:preferred_language",
@@ -2024,6 +2024,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
application_->SetAbilityRecordMgr(abilityRecordMgr_);
application_->SetConfiguration(appConfig);
contextImpl->SetConfiguration(application_->GetConfiguration());
application_->InitJSLeakWatcher(bundleInfo.name);
applicationImpl_->SetRecordId(appLaunchData.GetRecordId());
applicationImpl_->SetApplication(application_);
@@ -43,6 +43,7 @@
#include "syspara/parameter.h"
#include "ui_ability.h"
#include "application_configuration_manager.h"
#include "js_leak_watcher_ts.h"
#ifdef SUPPORT_GRAPHICS
#include "display_manager.h"
#include "window.h"
@@ -1298,6 +1299,21 @@ bool OHOSApplication::UpdateETSRuntime(AbilityRuntime::Runtime::Options &option)
return true;
}
void OHOSApplication::InitJSLeakWatcher(const std::string &bundleName)
{
TAG_LOGD(AAFwkTag::APPKIT, "InitJSLeakWatcher call");
if (runtime_ == nullptr) {
TAG_LOGE(AAFwkTag::APPKIT, "null runtime");
return;
}
if (runtime_->GetLanguage() != AbilityRuntime::Runtime::Language::JS) {
return;
}
auto env = (static_cast<AbilityRuntime::JsRuntime&>(*runtime_)).GetNapiEnv();
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
JSLeakWatcherEarlyInit(env, bundleName);
}
#ifdef SUPPORT_SCREEN
void OHOSApplication::RegisterGetAllUIAbilitiesCallback(
const std::shared_ptr<AbilityRuntime::ApplicationContext> &context,
@@ -245,6 +245,8 @@ public:
bool UpdateETSRuntime(AbilityRuntime::Runtime::Options &option);
void InitJSLeakWatcher(const std::string &bundleName);
#ifdef SUPPORT_GRAPHICS
bool GetDisplayConfig(uint64_t displayId, float &density, std::string &directionStr);
#endif
@@ -72,6 +72,7 @@ ohos_unittest("ability_service_extension_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -71,6 +71,7 @@ ohos_unittest("app_service_extension_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -32,6 +32,7 @@ ohos_unittest("ohos_application_test") {
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_test_path}/mock/frameworks_kits_runtime_test/",
"${ability_runtime_test_path}/mock/frameworks_kits_appkit_native_test/include",
"${ability_runtime_test_path}/unittest/runtime_test/",
]
sources = [ "ohos_application_test.cpp" ]
@@ -37,6 +37,7 @@
#endif
#undef private
#include "mock_ability_stage.h"
#include "mock_js_runtime.h"
using namespace testing;
using namespace testing::ext;
@@ -1703,5 +1704,96 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_LaunchElement_0300,
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_LaunchElement_0300 end.";
}
/*
* @tc.number: AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0100
* @tc.name: InitJSLeakWatcher
* @tc.desc: Verify function InitJSLeakWatcher when runtime_ is nullptr
*/
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0100 start.";
// Ensure runtime_ is nullptr
ohosApplication_->runtime_ = nullptr;
// Call InitJSLeakWatcher - should handle gracefully without crashing
std::string bundleName = "com.example.test";
ohosApplication_->InitJSLeakWatcher(bundleName);
// Verify runtime_ is still nullptr (no crash occurred)
EXPECT_TRUE(ohosApplication_->runtime_ == nullptr);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0100 end.";
}
/*
* @tc.number: AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0200
* @tc.name: InitJSLeakWatcher
* @tc.desc: Verify function InitJSLeakWatcher with valid runtime_
*/
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0200 start.";
// Set runtime_ to MockJsRuntime
ohosApplication_->runtime_ = std::make_unique<AbilityRuntime::MockJsRuntime>();
ASSERT_NE(ohosApplication_->runtime_, nullptr);
// Call InitJSLeakWatcher with bundle name
std::string bundleName = "com.example.test";
ohosApplication_->InitJSLeakWatcher(bundleName);
// Verify runtime_ is still valid after the call
EXPECT_TRUE(ohosApplication_->runtime_ != nullptr);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0200 end.";
}
/*
* @tc.number: AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0300
* @tc.name: InitJSLeakWatcher
* @tc.desc: Verify function InitJSLeakWatcher with empty bundle name
*/
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0300, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0300 start.";
// Set runtime_ to MockJsRuntime
ohosApplication_->runtime_ = std::make_unique<AbilityRuntime::MockJsRuntime>();
ASSERT_NE(ohosApplication_->runtime_, nullptr);
// Call InitJSLeakWatcher with empty bundle name
std::string bundleName = "";
ohosApplication_->InitJSLeakWatcher(bundleName);
// Verify runtime_ is still valid after the call
EXPECT_TRUE(ohosApplication_->runtime_ != nullptr);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0300 end.";
}
/*
* @tc.number: AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0400
* @tc.name: InitJSLeakWatcher
* @tc.desc: Verify function InitJSLeakWatcher with long bundle name
*/
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0400, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0400 start.";
// Set runtime_ to MockJsRuntime
ohosApplication_->runtime_ = std::make_unique<AbilityRuntime::MockJsRuntime>();
ASSERT_NE(ohosApplication_->runtime_, nullptr);
// Call InitJSLeakWatcher with long bundle name
std::string bundleName = "com.very.long.package.name.for.testing.purposes.bundle";
ohosApplication_->InitJSLeakWatcher(bundleName);
// Verify runtime_ is still valid after the call
EXPECT_TRUE(ohosApplication_->runtime_ != nullptr);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_InitJSLeakWatcher_0400 end.";
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -81,6 +81,7 @@ ohos_unittest("cj_ability_stage_object_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -86,6 +86,7 @@ ohos_unittest("cj_ability_stage_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -89,6 +89,7 @@ ohos_unittest("cj_ui_ability_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbegetutil",
@@ -118,6 +118,7 @@ ohos_unittest("ability_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"input:libmmi-client",
@@ -612,6 +613,7 @@ ohos_unittest("ability_impl_active_test") {
"ffrt:libffrt",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -670,6 +672,7 @@ ohos_unittest("ability_impl_test") {
"ffrt:libffrt",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -736,6 +739,7 @@ ohos_unittest("ui_ability_impl_test") {
"ffrt:libffrt",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -819,6 +823,7 @@ ohos_unittest("ability_thread_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -906,6 +911,7 @@ ohos_unittest("fa_ability_thread_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -1033,6 +1039,7 @@ ohos_unittest("ui_ability_thread_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -1478,6 +1485,7 @@ ohos_unittest("data_ability_impl_test") {
"ffrt:libffrt",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbegetutil",
@@ -1549,6 +1557,7 @@ ohos_unittest("data_ability_impl_file_secondpart_test") {
"ffrt:libffrt",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -1617,6 +1626,7 @@ ohos_unittest("data_ability_impl_file_test") {
"ffrt:libffrt",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -1687,6 +1697,7 @@ ohos_unittest("ability_thread_dataability_test") {
"ffrt:libffrt",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -1935,6 +1946,7 @@ ohos_unittest("ui_ability_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -2031,6 +2043,7 @@ ohos_unittest("form_host_client_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"i18n:intl_util",
"init:libbegetutil",
@@ -2089,6 +2102,7 @@ ohos_unittest("continuation_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -2321,6 +2335,7 @@ ohos_unittest("ability_window_test") {
"graphic_2d:librender_service_base",
"graphic_2d:librender_service_client",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"image_framework:image",
"init:libbegetutil",
@@ -2392,6 +2407,7 @@ ohos_unittest("ability_handler_test") {
"ffrt:libffrt",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -2459,6 +2475,7 @@ ohos_unittest("ability_impl_factory_test") {
"ffrt:libffrt",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbegetutil",
@@ -3420,6 +3437,7 @@ ohos_unittest("ability_second_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"input:libmmi-client",
@@ -103,6 +103,7 @@ ohos_unittest("application_test") {
"form_fwk:fmskit_native",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -175,6 +176,7 @@ ohos_unittest("context_impl_test") {
"form_fwk:fmskit_native",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -238,6 +240,7 @@ ohos_unittest("context_impl_second_test") {
"form_fwk:fmskit_native",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -300,6 +303,7 @@ ohos_unittest("context_impl_third_test") {
"form_fwk:fmskit_native",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -355,6 +359,7 @@ ohos_unittest("context_container_test") {
"form_fwk:fmskit_native",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -561,6 +566,7 @@ ohos_unittest("context_deal_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -625,6 +631,7 @@ ohos_unittest("application_impl_test") {
"form_fwk:fmskit_native",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@@ -777,6 +784,7 @@ ohos_unittest("form_extension_context_test") {
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hichecker:libhichecker",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",