From 2705992f79d2e9845023b5336fa80b2ca4c124f7 Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Tue, 29 Apr 2025 01:26:59 +0000 Subject: [PATCH 1/2] =?UTF-8?q?rom=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- frameworks/BUILD.gn | 7 ++++++- frameworks/extension/BUILD.gn | 7 +++++++ interfaces/kits/cj/BUILD.gn | 8 +++++++- interfaces/kits/js/BUILD.gn | 7 +++++++ .../js/napi/work_scheduler_extension/BUILD.gn | 7 +++++++ .../work_scheduler_extension_context/BUILD.gn | 7 +++++++ services/BUILD.gn | 7 +++++++ services/native/src/work_scheduler_service.cpp | 15 ++------------- 8 files changed, 50 insertions(+), 15 deletions(-) diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index 74c6e35..d4c8782 100644 --- a/frameworks/BUILD.gn +++ b/frameworks/BUILD.gn @@ -38,7 +38,12 @@ ohos_shared_library("workschedclient") { cfi_cross_dso = true debug = false } - + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fstack-protector-strong", + "-Os", + ] output_values = get_target_outputs(":work_sched_service_interface") sources = [ "${worksched_frameworks_path}/src/work_info.cpp", diff --git a/frameworks/extension/BUILD.gn b/frameworks/extension/BUILD.gn index 786e674..0f0373e 100644 --- a/frameworks/extension/BUILD.gn +++ b/frameworks/extension/BUILD.gn @@ -29,6 +29,13 @@ ohos_shared_library("workschedextension") { cfi_cross_dso = true debug = false } + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=hidden", + "-fstack-protector-strong", + "-Os", + ] sources = [ "${worksched_service_path}/zidl/src/work_scheduler_stub_imp.cpp", "src/js_work_scheduler_extension.cpp", diff --git a/interfaces/kits/cj/BUILD.gn b/interfaces/kits/cj/BUILD.gn index c660fa6..f8ac1db 100644 --- a/interfaces/kits/cj/BUILD.gn +++ b/interfaces/kits/cj/BUILD.gn @@ -23,7 +23,13 @@ ohos_shared_library("cj_work_scheduler_ffi") { cfi_cross_dso = true debug = false } - + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=hidden", + "-fstack-protector-strong", + "-Os", + ] include_dirs = [ "${worksched_root_path}/utils/native/include", "${worksched_root_path}/frameworks/include", diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 031aabc..c1230c7 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -27,6 +27,13 @@ ohos_shared_library("workscheduler") { cfi_cross_dso = true debug = false } + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=hidden", + "-fstack-protector-strong", + "-Os", + ] public_configs = [ ":worksched_public_config" ] sources = [ diff --git a/interfaces/kits/js/napi/work_scheduler_extension/BUILD.gn b/interfaces/kits/js/napi/work_scheduler_extension/BUILD.gn index faffd1a..15ffa36 100644 --- a/interfaces/kits/js/napi/work_scheduler_extension/BUILD.gn +++ b/interfaces/kits/js/napi/work_scheduler_extension/BUILD.gn @@ -45,6 +45,13 @@ ohos_shared_library("workschedulerextensionability_napi") { cfi_cross_dso = true debug = false } + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=hidden", + "-fstack-protector-strong", + "-Os", + ] sources = [ "work_scheduler_extension_ability_module.cpp" ] deps = [ diff --git a/interfaces/kits/js/napi/work_scheduler_extension_context/BUILD.gn b/interfaces/kits/js/napi/work_scheduler_extension_context/BUILD.gn index b658318..82d3f4c 100644 --- a/interfaces/kits/js/napi/work_scheduler_extension_context/BUILD.gn +++ b/interfaces/kits/js/napi/work_scheduler_extension_context/BUILD.gn @@ -45,6 +45,13 @@ ohos_shared_library("workschedulerextensioncontext_napi") { cfi_cross_dso = true debug = false } + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=hidden", + "-fstack-protector-strong", + "-Os", + ] sources = [ "work_scheduler_extension_context_module.cpp" ] deps = [ diff --git a/services/BUILD.gn b/services/BUILD.gn index cbf5b54..da96363 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -33,6 +33,13 @@ ohos_shared_library("workschedservice") { cfi_cross_dso = true debug = false } + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=hidden", + "-fstack-protector-strong", + "-Os", + ] sources = [ "native/src/conditions/battery_level_listener.cpp", "native/src/conditions/battery_status_listener.cpp", diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index e39236f..571b4f0 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -385,25 +385,14 @@ list> WorkSchedulerService::ReadPreinstalledWorks() bool WorkSchedulerService::GetJsonFromFile(const char *filePath, Json::Value &root) { - ifstream fin; std::string realPath; if (!WorkSchedUtils::ConvertFullPath(filePath, realPath)) { WS_HILOGE("Get real path failed %{private}s", filePath); return false; } WS_HILOGD("Read from %{private}s", realPath.c_str()); - fin.open(realPath, ios::in); - WS_HILOGI("file open success"); - if (!fin.is_open()) { - WS_HILOGE("cannot open file %{private}s", realPath.c_str()); - return false; - } - char buffer[MAX_BUFFER]; - ostringstream os; - while (fin.getline(buffer, MAX_BUFFER)) { - os << buffer; - } - string data = os.str(); + std::string data; + LoadStringFromFile(realPath.c_str(), data); WS_HILOGI("data read success"); JSONCPP_STRING errs; Json::CharReaderBuilder readerBuilder; -- Gitee From 9733547d05dd35b511284a59dcfd1044a74fe46b Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Tue, 29 Apr 2025 11:41:12 +0000 Subject: [PATCH 2/2] =?UTF-8?q?rom=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- services/native/src/work_scheduler_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 571b4f0..bfe3926 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -398,7 +398,6 @@ bool WorkSchedulerService::GetJsonFromFile(const char *filePath, Json::Value &ro Json::CharReaderBuilder readerBuilder; const unique_ptr jsonReader(readerBuilder.newCharReader()); bool res = jsonReader->parse(data.c_str(), data.c_str() + data.length(), &root, &errs); - fin.close(); if (!res || !errs.empty()) { WS_HILOGE("parse %{private}s json error", realPath.c_str()); return false; -- Gitee