diff --git a/bundle.json b/bundle.json index f26d9f737aab1c1cebfd9426387c26a3cf74a8f2..aacfe3760019c2de0f1990d3ff590dddebcd7287 100644 --- a/bundle.json +++ b/bundle.json @@ -42,6 +42,7 @@ "cJSON", "image_framework", "common_event_service", + "udmf", "selinux_adapter" ] }, diff --git a/filemanagement_aafwk.gni b/filemanagement_aafwk.gni index e37371747c18493c742e4a0d4ff8ac6c955aad0a..92a939f8cfd686bdb88d0edc252a3df34b313cfd 100644 --- a/filemanagement_aafwk.gni +++ b/filemanagement_aafwk.gni @@ -15,3 +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" + +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 3ffd40376950c6673a6ac42fc0e623a0cb4655d0..c6fa0e1d10a3a765f762b38099c1cb6ec2ca3408 100644 --- a/interfaces/kits/picker/BUILD.gn +++ b/interfaces/kits/picker/BUILD.gn @@ -83,6 +83,11 @@ ohos_shared_library("picker") { "napi:ace_napi", ] + if (picker_udmf_enabled) { + defines = [ "UDMF_ENABLED" ] + external_deps += [ "udmf:udmf_client" ] + } + sanitize = { integer_overflow = true ubsan = true diff --git a/interfaces/kits/picker/picker.js b/interfaces/kits/picker/picker.js index 9acacc4d459308662531f8c2dcfaf5f7f4a9eaf5..ba7200c3962587ccec5cb1dccf9d153846206642 100644 --- a/interfaces/kits/picker/picker.js +++ b/interfaces/kits/picker/picker.js @@ -350,7 +350,10 @@ function getDocumentPickerSelectResult(args) { if (args.ability_params_stream) { selectResult.data = args.ability_params_stream; selectResult.error = args.resultCode; - } + } else 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 e4b1b7a017fc68db852e276b4ed36a6660b0e8ed..767a8f78d68a5ab17e51f6d5dadf9d951745d240 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -24,6 +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 { @@ -136,6 +140,59 @@ 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) +{ + 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())) { + return; + } + const std::string udkey = pickerCallBack->want.GetStringParam(key.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; + } + 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); + 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); + } + } + status = napi_set_named_property(env, result, "ability_params_udkey", array); + if (status != napi_ok) { + HILOG_ERROR("[picker]: napi_set_named_property failed"); + } +} + static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr pickerCallBack) { if (pickerCallBack == nullptr) { @@ -155,6 +212,9 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr