From fd7ee174e328869aa47b74122d8e6d38f238b288 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 19 Jun 2025 15:18:44 +0800 Subject: [PATCH 1/7] fixed picker. Signed-off-by: BrainL Change-Id: Ie76181a59cc2ad7cb0772a502f15795f816a3f4c --- bundle.json | 1 + interfaces/kits/picker/BUILD.gn | 1 + interfaces/kits/picker/picker.js | 7 +- .../kits/picker/src/picker_n_exporter.cpp | 58 ++++++++ picker.diff | 125 ++++++++++++++++++ 5 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 picker.diff diff --git a/bundle.json b/bundle.json index f26d9f73..aacfe376 100644 --- a/bundle.json +++ b/bundle.json @@ -42,6 +42,7 @@ "cJSON", "image_framework", "common_event_service", + "udmf", "selinux_adapter" ] }, diff --git a/interfaces/kits/picker/BUILD.gn b/interfaces/kits/picker/BUILD.gn index 3ffd4037..83a187d4 100644 --- a/interfaces/kits/picker/BUILD.gn +++ b/interfaces/kits/picker/BUILD.gn @@ -81,6 +81,7 @@ ohos_shared_library("picker") { "ipc:ipc_napi", "ipc:ipc_single", "napi:ace_napi", + "udmf:udmf_client", ] sanitize = { diff --git a/interfaces/kits/picker/picker.js b/interfaces/kits/picker/picker.js index 9acacc4d..739528f5 100644 --- a/interfaces/kits/picker/picker.js +++ b/interfaces/kits/picker/picker.js @@ -350,7 +350,12 @@ function getDocumentPickerSelectResult(args) { if (args.ability_params_stream) { selectResult.data = args.ability_params_stream; selectResult.error = args.resultCode; - } + } + + if (args.ability_params_udkey) { + selectResult.data = args.ability_params_udkey; + selectResult.error = args.resultCode; + } } else if (args.resultCode === RESULT_CODE_ERROR) { selectResult.data = []; selectResult.error = args.resultCode; diff --git a/interfaces/kits/picker/src/picker_n_exporter.cpp b/interfaces/kits/picker/src/picker_n_exporter.cpp index e4b1b7a0..d67d18a1 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -24,6 +24,8 @@ #endif #include "ui_extension_context.h" #include "want.h" +#include "unified_data.h" +#include "udmf_client.h" namespace OHOS { namespace Picker { @@ -136,6 +138,61 @@ static void MakeResultWithBool(napi_env env, std::string key, napi_value &result } } +static void MakeResultWithUdkey(napi_env env, std::string key, napi_value &result, + std::shared_ptr pickerCallBack) +{ + if (pickerCallBack == nullptr) { + HILOG_ERROR("[picker]: pickerCallBack is nullptr"); + return; + } + napi_value array; + napi_create_array(env, &array); + napi_status status = napi_generic_failure; + if (pickerCallBack->want.GetParams().HasParam(key.c_str())) { + const std::string udkey = pickerCallBack->want.GetStringParam(key.c_str()); + HILOG_INFO("[picker]: %{public}s is %{public}s", key.c_str(), udkey.c_str()); + UDMF::QueryOption query = {.key = udkey}; + std::vector unifiedDataSet; + auto stat = UDMF::UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet); + if (stat != UDMF::Status::E_OK) { + HILOG_ERROR("[picker]: stat is not E_OK, stat: %{public}d", stat); + return; + } + size_t len = unifiedDataSet[0].GetRecords().size(); + for (size_t i = 0; i < len; ++i) { + auto readRecord = unifiedDataSet[0].GetRecordAt(i); + auto entry = readRecord->GetEntry("general.file-uri"); + + if (!std::holds_alternative>(entry)) { + HILOG_ERROR("[picker]: entry is not Object"); + continue; + } + auto obj = std::get>(entry); + std::string uri; + obj->GetValue("oriUri", uri); + if (uri.empty()) { + HILOG_ERROR("[picker]: uri is empty"); + continue; + } + + napi_value uriVal = nullptr; + napi_create_string_utf8(env, uri.c_str(), NAPI_AUTO_LENGTH, &uriVal); + status = napi_set_element(env, array, i, uriVal); + if (status != napi_ok) { + HILOG_ERROR("[picker]: napi_set_element failed, error: %{public}d", status); + continue; + } + } + if (key == "ability.params.udkey") { + key = "ability_params_udkey"; + } + status = napi_set_named_property(env, result, key.c_str(), array); + if (status != napi_ok) { + HILOG_ERROR("[picker]: napi_set_named_property %{public}s failed", key.c_str()); + } + } +} + static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr pickerCallBack) { if (pickerCallBack == nullptr) { @@ -155,6 +212,7 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr pickerCallBack) ++{ ++ if (pickerCallBack == nullptr) { ++ HILOG_ERROR("[picker]: pickerCallBack is nullptr"); ++ return; ++ } ++ napi_value array; ++ napi_create_array(env, &array); ++ napi_status status = napi_generic_failure; ++ if (pickerCallBack->want.GetParams().HasParam(key.c_str())) { ++ const std::string udkey = pickerCallBack->want.GetStringParam(key.c_str()); ++ HILOG_INFO("[picker]: %{public}s is %{public}s", key.c_str(), udkey.c_str()); ++ UDMF::QueryOption query = {.key = udkey}; ++ std::vector unifiedDataSet; ++ auto stat = UDMF::UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet); ++ if (stat != UDMF::Status::E_OK) { ++ HILOG_ERROR("[picker]: stat is not E_OK, stat: %{public}d", stat); ++ return; ++ } ++ size_t len = unifiedDataSet[0].GetRecords().size(); ++ for (size_t i = 0; i < len; ++i) { ++ auto readRecord = unifiedDataSet[0].GetRecordAt(i); ++ auto entry = readRecord->GetEntry("general.file-uri"); ++ ++ if (!std::holds_alternative>(entry)) { ++ HILOG_ERROR("[picker]: entry is not Object"); ++ continue; ++ } ++ auto obj = std::get>(entry); ++ std::string uri; ++ obj->GetValue("oriUri", uri); ++ if (uri.empty()) { ++ HILOG_ERROR("[picker]: uri is empty"); ++ continue; ++ } ++ ++ napi_value uriVal = nullptr; ++ napi_create_string_utf8(env, uri.c_str(), NAPI_AUTO_LENGTH, &uriVal); ++ status = napi_set_element(env, array, i, uriVal); ++ if (status != napi_ok) { ++ HILOG_ERROR("[picker]: napi_set_element failed, error: %{public}d", status); ++ continue; ++ } ++ } ++ if (key == "ability.params.udkey") { ++ key = "ability_params_udkey"; ++ } ++ status = napi_set_named_property(env, result, key.c_str(), array); ++ if (status != napi_ok) { ++ HILOG_ERROR("[picker]: napi_set_named_property %{public}s failed", key.c_str()); ++ } ++ } ++} ++ + static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr pickerCallBack) + { + if (pickerCallBack == nullptr) { +@@ -155,6 +212,7 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr Date: Thu, 19 Jun 2025 15:37:00 +0800 Subject: [PATCH 2/7] fixed the codecheck. Signed-off-by: BrainL Change-Id: I2714c0491f404540484d6f91e7d2a11c43bca5a4 --- .../kits/picker/src/picker_n_exporter.cpp | 2 - picker.diff | 125 ------------------ 2 files changed, 127 deletions(-) delete mode 100644 picker.diff diff --git a/interfaces/kits/picker/src/picker_n_exporter.cpp b/interfaces/kits/picker/src/picker_n_exporter.cpp index d67d18a1..0f4c9f6b 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -162,7 +162,6 @@ static void MakeResultWithUdkey(napi_env env, std::string key, napi_value &resul for (size_t i = 0; i < len; ++i) { auto readRecord = unifiedDataSet[0].GetRecordAt(i); auto entry = readRecord->GetEntry("general.file-uri"); - if (!std::holds_alternative>(entry)) { HILOG_ERROR("[picker]: entry is not Object"); continue; @@ -174,7 +173,6 @@ static void MakeResultWithUdkey(napi_env env, std::string key, napi_value &resul HILOG_ERROR("[picker]: uri is empty"); continue; } - napi_value uriVal = nullptr; napi_create_string_utf8(env, uri.c_str(), NAPI_AUTO_LENGTH, &uriVal); status = napi_set_element(env, array, i, uriVal); diff --git a/picker.diff b/picker.diff deleted file mode 100644 index a6b329f1..00000000 --- a/picker.diff +++ /dev/null @@ -1,125 +0,0 @@ -diff --git a/bundle.json b/bundle.json -index f26d9f7..aacfe37 100644 ---- a/bundle.json -+++ b/bundle.json -@@ -42,6 +42,7 @@ - "cJSON", - "image_framework", - "common_event_service", -+ "udmf", - "selinux_adapter" - ] - }, -diff --git a/interfaces/kits/picker/BUILD.gn b/interfaces/kits/picker/BUILD.gn -index 3ffd403..83a187d 100644 ---- a/interfaces/kits/picker/BUILD.gn -+++ b/interfaces/kits/picker/BUILD.gn -@@ -81,6 +81,7 @@ ohos_shared_library("picker") { - "ipc:ipc_napi", - "ipc:ipc_single", - "napi:ace_napi", -+ "udmf:udmf_client", - ] - - sanitize = { -diff --git a/interfaces/kits/picker/picker.js b/interfaces/kits/picker/picker.js -index 9acacc4..739528f 100644 ---- a/interfaces/kits/picker/picker.js -+++ b/interfaces/kits/picker/picker.js -@@ -350,7 +350,12 @@ function getDocumentPickerSelectResult(args) { - if (args.ability_params_stream) { - selectResult.data = args.ability_params_stream; - selectResult.error = args.resultCode; -- } -+ } -+ -+ if (args.ability_params_udkey) { -+ selectResult.data = args.ability_params_udkey; -+ selectResult.error = args.resultCode; -+ } - } else if (args.resultCode === RESULT_CODE_ERROR) { - selectResult.data = []; - selectResult.error = args.resultCode; -diff --git a/interfaces/kits/picker/src/picker_n_exporter.cpp b/interfaces/kits/picker/src/picker_n_exporter.cpp -index e4b1b7a..d67d18a 100644 ---- a/interfaces/kits/picker/src/picker_n_exporter.cpp -+++ b/interfaces/kits/picker/src/picker_n_exporter.cpp -@@ -24,6 +24,8 @@ - #endif - #include "ui_extension_context.h" - #include "want.h" -+#include "unified_data.h" -+#include "udmf_client.h" - - namespace OHOS { - namespace Picker { -@@ -136,6 +138,61 @@ static void MakeResultWithBool(napi_env env, std::string key, napi_value &result - } - } - -+static void MakeResultWithUdkey(napi_env env, std::string key, napi_value &result, -+ std::shared_ptr pickerCallBack) -+{ -+ if (pickerCallBack == nullptr) { -+ HILOG_ERROR("[picker]: pickerCallBack is nullptr"); -+ return; -+ } -+ napi_value array; -+ napi_create_array(env, &array); -+ napi_status status = napi_generic_failure; -+ if (pickerCallBack->want.GetParams().HasParam(key.c_str())) { -+ const std::string udkey = pickerCallBack->want.GetStringParam(key.c_str()); -+ HILOG_INFO("[picker]: %{public}s is %{public}s", key.c_str(), udkey.c_str()); -+ UDMF::QueryOption query = {.key = udkey}; -+ std::vector unifiedDataSet; -+ auto stat = UDMF::UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet); -+ if (stat != UDMF::Status::E_OK) { -+ HILOG_ERROR("[picker]: stat is not E_OK, stat: %{public}d", stat); -+ return; -+ } -+ size_t len = unifiedDataSet[0].GetRecords().size(); -+ for (size_t i = 0; i < len; ++i) { -+ auto readRecord = unifiedDataSet[0].GetRecordAt(i); -+ auto entry = readRecord->GetEntry("general.file-uri"); -+ -+ if (!std::holds_alternative>(entry)) { -+ HILOG_ERROR("[picker]: entry is not Object"); -+ continue; -+ } -+ auto obj = std::get>(entry); -+ std::string uri; -+ obj->GetValue("oriUri", uri); -+ if (uri.empty()) { -+ HILOG_ERROR("[picker]: uri is empty"); -+ continue; -+ } -+ -+ napi_value uriVal = nullptr; -+ napi_create_string_utf8(env, uri.c_str(), NAPI_AUTO_LENGTH, &uriVal); -+ status = napi_set_element(env, array, i, uriVal); -+ if (status != napi_ok) { -+ HILOG_ERROR("[picker]: napi_set_element failed, error: %{public}d", status); -+ continue; -+ } -+ } -+ if (key == "ability.params.udkey") { -+ key = "ability_params_udkey"; -+ } -+ status = napi_set_named_property(env, result, key.c_str(), array); -+ if (status != napi_ok) { -+ HILOG_ERROR("[picker]: napi_set_named_property %{public}s failed", key.c_str()); -+ } -+ } -+} -+ - static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr pickerCallBack) - { - if (pickerCallBack == nullptr) { -@@ -155,6 +212,7 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr Date: Thu, 19 Jun 2025 18:20:18 +0800 Subject: [PATCH 3/7] fix gn Signed-off-by: BrainL Change-Id: I47d615b615c2269a97f74c489f1c96af67ff8755 --- filemanagement_aafwk.gni | 6 ++++++ interfaces/kits/picker/BUILD.gn | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/filemanagement_aafwk.gni b/filemanagement_aafwk.gni index e3737174..35df622f 100644 --- a/filemanagement_aafwk.gni +++ b/filemanagement_aafwk.gni @@ -15,3 +15,9 @@ ability_runtime_path = "//foundation/ability/ability_runtime" file_api_path = "//foundation/filemanagement/file_api" user_file_service_path = "//foundation/filemanagement/user_file_service" commonlibrary_path = "//commonlibrary" +udmf_enabled = true + +if (defined(global_parts_info) && + !defined(global_parts_info.distributeddatamgr_udmf)) { + udmf_enabled = false +} \ No newline at end of file diff --git a/interfaces/kits/picker/BUILD.gn b/interfaces/kits/picker/BUILD.gn index 83a187d4..9fa01af0 100644 --- a/interfaces/kits/picker/BUILD.gn +++ b/interfaces/kits/picker/BUILD.gn @@ -81,9 +81,12 @@ ohos_shared_library("picker") { "ipc:ipc_napi", "ipc:ipc_single", "napi:ace_napi", - "udmf:udmf_client", ] + if (udmf_enabled) { + external_deps += [ "udmf:udmf_client" ] + } + sanitize = { integer_overflow = true ubsan = true -- Gitee From 6820588bbeb61a7aa4ca3a8436f6346d2ad3365c Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 20 Jun 2025 17:03:52 +0800 Subject: [PATCH 4/7] fixed the comments. Signed-off-by: BrainL Change-Id: If17607251a58eb151715b1f8a5076cc18c2bff52 --- filemanagement_aafwk.gni | 9 ++- interfaces/kits/picker/BUILD.gn | 3 +- .../kits/picker/src/picker_n_exporter.cpp | 74 ++++++++++--------- 3 files changed, 45 insertions(+), 41 deletions(-) diff --git a/filemanagement_aafwk.gni b/filemanagement_aafwk.gni index 35df622f..92a939f8 100644 --- a/filemanagement_aafwk.gni +++ b/filemanagement_aafwk.gni @@ -15,9 +15,10 @@ ability_runtime_path = "//foundation/ability/ability_runtime" file_api_path = "//foundation/filemanagement/file_api" user_file_service_path = "//foundation/filemanagement/user_file_service" commonlibrary_path = "//commonlibrary" -udmf_enabled = true -if (defined(global_parts_info) && - !defined(global_parts_info.distributeddatamgr_udmf)) { - udmf_enabled = false +declare_args() { + picker_udmf_enabled = true + if (defined(global_parts_info) && !defined(global_parts_info.distributeddatamgr_udmf)) { + picker_udmf_enabled = false + } } \ No newline at end of file diff --git a/interfaces/kits/picker/BUILD.gn b/interfaces/kits/picker/BUILD.gn index 9fa01af0..c6fa0e1d 100644 --- a/interfaces/kits/picker/BUILD.gn +++ b/interfaces/kits/picker/BUILD.gn @@ -83,7 +83,8 @@ ohos_shared_library("picker") { "napi:ace_napi", ] - if (udmf_enabled) { + if (picker_udmf_enabled) { + defines = [ "UDMF_ENABLED" ] external_deps += [ "udmf:udmf_client" ] } diff --git a/interfaces/kits/picker/src/picker_n_exporter.cpp b/interfaces/kits/picker/src/picker_n_exporter.cpp index 0f4c9f6b..af1f49da 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -24,8 +24,10 @@ #endif #include "ui_extension_context.h" #include "want.h" +#ifdef UDMF_ENABLED #include "unified_data.h" #include "udmf_client.h" +#endif namespace OHOS { namespace Picker { @@ -138,9 +140,10 @@ static void MakeResultWithBool(napi_env env, std::string key, napi_value &result } } -static void MakeResultWithUdkey(napi_env env, std::string key, napi_value &result, +static void MakeResultWithUdkey(napi_env env, const std::string key, napi_value &result, std::shared_ptr pickerCallBack) { +#ifdef UDMF_ENABLED if (pickerCallBack == nullptr) { HILOG_ERROR("[picker]: pickerCallBack is nullptr"); return; @@ -148,47 +151,46 @@ static void MakeResultWithUdkey(napi_env env, std::string key, napi_value &resul napi_value array; napi_create_array(env, &array); napi_status status = napi_generic_failure; - if (pickerCallBack->want.GetParams().HasParam(key.c_str())) { - const std::string udkey = pickerCallBack->want.GetStringParam(key.c_str()); - HILOG_INFO("[picker]: %{public}s is %{public}s", key.c_str(), udkey.c_str()); - UDMF::QueryOption query = {.key = udkey}; - std::vector unifiedDataSet; - auto stat = UDMF::UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet); - if (stat != UDMF::Status::E_OK) { - HILOG_ERROR("[picker]: stat is not E_OK, stat: %{public}d", stat); - return; + if (!pickerCallBack->want.GetParams().HasParam(key.c_str())) { + return; + } + const std::string udkey = pickerCallBack->want.GetStringParam(key.c_str()); + HILOG_INFO("[picker]: %{public}s is %{public}s", key.c_str(), udkey.c_str()); + UDMF::QueryOption query = {.key = udkey}; + std::vector unifiedDataSet; + auto stat = UDMF::UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet); + if (stat != UDMF::Status::E_OK || unifiedDataSet.empty()) { + HILOG_ERROR("[picker]: unifiedDataSet isEmpty or GetBatchData failed, stat=%{public}d", stat); + return; + } + size_t len = unifiedDataSet[0].GetRecords().size(); + for (size_t i = 0; i < len; ++i) { + auto readRecord = unifiedDataSet[0].GetRecordAt(i); + auto entry = readRecord->GetEntry("general.file-uri"); + if (!std::holds_alternative>(entry)) { + HILOG_ERROR("[picker]: entry is not Object"); + continue; } - size_t len = unifiedDataSet[0].GetRecords().size(); - for (size_t i = 0; i < len; ++i) { - auto readRecord = unifiedDataSet[0].GetRecordAt(i); - auto entry = readRecord->GetEntry("general.file-uri"); - if (!std::holds_alternative>(entry)) { - HILOG_ERROR("[picker]: entry is not Object"); - continue; - } - auto obj = std::get>(entry); - std::string uri; - obj->GetValue("oriUri", uri); - if (uri.empty()) { - HILOG_ERROR("[picker]: uri is empty"); - continue; - } - napi_value uriVal = nullptr; - napi_create_string_utf8(env, uri.c_str(), NAPI_AUTO_LENGTH, &uriVal); - status = napi_set_element(env, array, i, uriVal); - if (status != napi_ok) { - HILOG_ERROR("[picker]: napi_set_element failed, error: %{public}d", status); - continue; - } + auto obj = std::get>(entry); + std::string uri; + obj->GetValue("oriUri", uri); + if (uri.empty()) { + HILOG_ERROR("[picker]: uri is empty"); + continue; } - if (key == "ability.params.udkey") { - key = "ability_params_udkey"; + napi_value uriVal = nullptr; + napi_create_string_utf8(env, uri.c_str(), NAPI_AUTO_LENGTH, &uriVal); + status = napi_set_element(env, array, i, uriVal); + if (status != napi_ok) { + HILOG_ERROR("[picker]: napi_set_element failed, error: %{public}d", status); + continue; } - status = napi_set_named_property(env, result, key.c_str(), array); + status = napi_set_named_property(env, result, "ability_params_udkey", array); if (status != napi_ok) { - HILOG_ERROR("[picker]: napi_set_named_property %{public}s failed", key.c_str()); + HILOG_ERROR("[picker]: napi_set_named_property failed"); } } +#endif } static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr pickerCallBack) -- Gitee From 2c01b4ae0f3d524a928adbd9b79a063d19e983a5 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 20 Jun 2025 17:19:24 +0800 Subject: [PATCH 5/7] fixed the comments. Signed-off-by: BrainL Change-Id: Ie30ae8dfb90e0b76d1d1d35bfe6407691c46952d --- interfaces/kits/picker/src/picker_n_exporter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/picker/src/picker_n_exporter.cpp b/interfaces/kits/picker/src/picker_n_exporter.cpp index af1f49da..b9e4c62f 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -185,10 +185,10 @@ static void MakeResultWithUdkey(napi_env env, const std::string key, napi_value HILOG_ERROR("[picker]: napi_set_element failed, error: %{public}d", status); continue; } - status = napi_set_named_property(env, result, "ability_params_udkey", array); - if (status != napi_ok) { - HILOG_ERROR("[picker]: napi_set_named_property failed"); - } + } + status = napi_set_named_property(env, result, "ability_params_udkey", array); + if (status != napi_ok) { + HILOG_ERROR("[picker]: napi_set_named_property failed"); } #endif } -- Gitee From 9a8fe987b9b6b180b61478d75231aeaca6077db5 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 20 Jun 2025 20:00:25 +0800 Subject: [PATCH 6/7] fixed the comments. Signed-off-by: BrainL Change-Id: Id97c67bb9c99c6fd4793a9f5232842106ac377dd --- interfaces/kits/picker/picker.js | 4 +--- interfaces/kits/picker/src/picker_n_exporter.cpp | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/interfaces/kits/picker/picker.js b/interfaces/kits/picker/picker.js index 739528f5..ba7200c3 100644 --- a/interfaces/kits/picker/picker.js +++ b/interfaces/kits/picker/picker.js @@ -350,9 +350,7 @@ function getDocumentPickerSelectResult(args) { if (args.ability_params_stream) { selectResult.data = args.ability_params_stream; selectResult.error = args.resultCode; - } - - if (args.ability_params_udkey) { + } else if (args.ability_params_udkey) { selectResult.data = args.ability_params_udkey; selectResult.error = args.resultCode; } diff --git a/interfaces/kits/picker/src/picker_n_exporter.cpp b/interfaces/kits/picker/src/picker_n_exporter.cpp index b9e4c62f..5e40c929 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -143,7 +143,6 @@ static void MakeResultWithBool(napi_env env, std::string key, napi_value &result static void MakeResultWithUdkey(napi_env env, const std::string key, napi_value &result, std::shared_ptr pickerCallBack) { -#ifdef UDMF_ENABLED if (pickerCallBack == nullptr) { HILOG_ERROR("[picker]: pickerCallBack is nullptr"); return; @@ -155,7 +154,6 @@ static void MakeResultWithUdkey(napi_env env, const std::string key, napi_value return; } const std::string udkey = pickerCallBack->want.GetStringParam(key.c_str()); - HILOG_INFO("[picker]: %{public}s is %{public}s", key.c_str(), udkey.c_str()); UDMF::QueryOption query = {.key = udkey}; std::vector unifiedDataSet; auto stat = UDMF::UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet); @@ -183,14 +181,12 @@ static void MakeResultWithUdkey(napi_env env, const std::string key, napi_value status = napi_set_element(env, array, i, uriVal); if (status != napi_ok) { HILOG_ERROR("[picker]: napi_set_element failed, error: %{public}d", status); - continue; } } status = napi_set_named_property(env, result, "ability_params_udkey", array); if (status != napi_ok) { HILOG_ERROR("[picker]: napi_set_named_property failed"); } -#endif } static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr pickerCallBack) @@ -212,7 +208,9 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr Date: Fri, 20 Jun 2025 20:11:07 +0800 Subject: [PATCH 7/7] fixed the comments. Signed-off-by: BrainL Change-Id: I2d633651513db2efeb662f8d5dad69e4f38f8040 --- interfaces/kits/picker/src/picker_n_exporter.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interfaces/kits/picker/src/picker_n_exporter.cpp b/interfaces/kits/picker/src/picker_n_exporter.cpp index 5e40c929..767a8f78 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -178,6 +178,10 @@ static void MakeResultWithUdkey(napi_env env, const std::string key, napi_value } napi_value uriVal = nullptr; napi_create_string_utf8(env, uri.c_str(), NAPI_AUTO_LENGTH, &uriVal); + if (uriVal == nullptr) { + HILOG_ERROR("[picker]: create uri js value fail."); + continue; + } status = napi_set_element(env, array, i, uriVal); if (status != napi_ok) { HILOG_ERROR("[picker]: napi_set_element failed, error: %{public}d", status); -- Gitee