From ebefe6a0ccf1ab2abede1fd1b7d41ce1ee72c669 Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Fri, 12 Sep 2025 10:27:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- frameworks/BUILD.gn | 5 ++++- frameworks/extension/BUILD.gn | 5 ++++- .../extension/src/js_work_scheduler_extension.cpp | 7 ++++++- frameworks/src/work_info.cpp | 7 ++++++- frameworks/src/workscheduler_srv_client.cpp | 1 + services/BUILD.gn | 10 ++++++++-- services/native/src/work_scheduler_service.cpp | 7 ++++++- 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index fee4fb4..d0fc3fe 100644 --- a/frameworks/BUILD.gn +++ b/frameworks/BUILD.gn @@ -51,7 +51,10 @@ ohos_shared_library("workschedclient") { ] sources += filter_include(output_values, [ "*_proxy.cpp" ]) - configs = [ ":worksched_private_config" ] + configs = [ + ":worksched_private_config", + "//build/config/compiler:exceptions", + ] public_configs = [ ":worksched_public_config" ] diff --git a/frameworks/extension/BUILD.gn b/frameworks/extension/BUILD.gn index b9e7193..694e4e5 100644 --- a/frameworks/extension/BUILD.gn +++ b/frameworks/extension/BUILD.gn @@ -45,7 +45,10 @@ ohos_shared_library("workschedextension") { "src/work_scheduler_extension_module_loader.cpp", ] - configs = [ ":worksched_private_config" ] + configs = [ + ":worksched_private_config", + "//build/config/compiler:exceptions", + ] public_configs = [ ":worksched_public_config" ] diff --git a/frameworks/extension/src/js_work_scheduler_extension.cpp b/frameworks/extension/src/js_work_scheduler_extension.cpp index 5a66335..1843c3c 100644 --- a/frameworks/extension/src/js_work_scheduler_extension.cpp +++ b/frameworks/extension/src/js_work_scheduler_extension.cpp @@ -494,7 +494,12 @@ bool JsWorkSchedulerExtension::GetExtrasJsonStr(const WorkInfo& workInfo, std::s WS_HILOGE("parameters type not supported."); } } - extrasStr = extrasJson.dump(JSON_INDENT_WIDTH); + try { + extrasStr = extrasJson.dump(JSON_INDENT_WIDTH); + } catch (...) { + WS_HILOGE("failed to convert to string."); + return false; + } return true; } } // namespace WorkScheduler diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index 8014d07..db8da23 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -500,7 +500,12 @@ std::string WorkInfo::ParseToJsonStr() root["parameters"] = extras; root["parametersType"] = extrasType; } - std::string result = root.dump(JSON_INDENT_WIDTH); + std::string result = ""; + try { + result = root.dump(JSON_INDENT_WIDTH); + } catch (...) { + WS_HILOGE("failed to convert to string."); + } return result; } diff --git a/frameworks/src/workscheduler_srv_client.cpp b/frameworks/src/workscheduler_srv_client.cpp index 72c7df7..2d47475 100644 --- a/frameworks/src/workscheduler_srv_client.cpp +++ b/frameworks/src/workscheduler_srv_client.cpp @@ -30,6 +30,7 @@ WorkSchedulerSrvClient::~WorkSchedulerSrvClient() {} ErrCode WorkSchedulerSrvClient::Connect() { + std::lock_guard lock(mutex_); if (iWorkSchedService_ != nullptr) { return ERR_OK; } diff --git a/services/BUILD.gn b/services/BUILD.gn index da96363..7e194bb 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -73,7 +73,10 @@ ohos_shared_library("workschedservice") { "native/src/work_status.cpp", ] - configs = [ ":worksched_private_config" ] + configs = [ + ":worksched_private_config", + "//build/config/compiler:exceptions", + ] public_configs = [ ":worksched_public_config" ] @@ -189,7 +192,10 @@ ohos_static_library("workschedservice_static") { "native/src/work_status.cpp", ] - configs = [ ":worksched_private_config" ] + configs = [ + ":worksched_private_config", + "//build/config/compiler:exceptions", + ] public_configs = [ ":worksched_public_config" ] diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index e45fed7..33143d8 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -1328,7 +1328,12 @@ void WorkSchedulerService::RefreshPersistedWorks() root[it.first] = workJson; } } - string result = root.dump(4); + std::string result = ""; + try { + result = root.dump(JSON_INDENT_WIDTH); + } catch (...) { + WS_HILOGE("failed to convert to string."); + } CreateNodeDir(PERSISTED_PATH); CreateNodeFile(); ofstream fout; -- Gitee