diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index fee4fb452cba019371fb5ad5517449387bd99ff8..d0fc3fe3e7074d37a190f36f62339cd895f7d71c 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 b9e7193cedf73d8ec741b05cfe0742cf108c8ca5..694e4e50dd52f6f9bdbdb58d102f52140a004f5e 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 5a6633578f768df5cd22ecc27e24b5d5aeedabb8..1843c3cf5211e3489ca249d51fa61abfc79ed6e6 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 8014d07458393df3658705e79020aa49192db1b7..db8da235fd4702b1ba6adc473dcbd378d09453ca 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 72c7df76fbd753c85246575d9f55fac95f90288f..2d474752254374b7fea80f96755ee122d618e0cc 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 da9636399c75d4a90694474ad5c4d1e45a643487..7e194bb02b431b21b3210ed8be9f7ff0ea243a70 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 e45fed7e83605aeec076f31953965ad351c17d4e..33143d8710c1880c45182e449bd10514bfd2c198 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;