diff --git a/frameworks/js/napi/file_access_module/file_info/napi_file_iterator_exporter.cpp b/frameworks/js/napi/file_access_module/file_info/napi_file_iterator_exporter.cpp index 0550ce8418828862776c3c78ca0a0da3b1e4328b..b4ebc81e4e2e8b7917adaa718fb89369267b33e4 100644 --- a/frameworks/js/napi/file_access_module/file_info/napi_file_iterator_exporter.cpp +++ b/frameworks/js/napi/file_access_module/file_info/napi_file_iterator_exporter.cpp @@ -204,6 +204,9 @@ static int GetNextIterator(napi_value &objFileInfoExporter, FileIteratorEntity * } while (!isDone && FilterTrashAndRecentDir(fileInfoEntity->fileInfo.uri)) { fileInfoEntity = NClass::GetEntityOf(env, objFileInfoExporter); + if (fileInfoEntity == nullptr) { + return E_GETRESULT; + } retNVal = NVal::CreateObject(env); HILOG_DEBUG("TRASH_DIR or RECENT_DIR: %{public}s", fileInfoEntity->fileInfo.uri.c_str()); if (fileIteratorEntity->flag == CALL_LISTFILE) { diff --git a/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp b/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp index 38a3abb5ca51db58278036e99389815c520ccecc..09273855d87f2024821b26a5ebe5201b5b278a13 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp @@ -572,8 +572,8 @@ static int ReadFileFilterResults(MessageParcel &reply, SharedMemoryInfo &memInfo return ERR_OK; } -int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter, - SharedMemoryInfo &memInfo) +int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset, + const FileFilter &filter, SharedMemoryInfo &memInfo) { UserAccessTracer trace; trace.Start("ListFile"); diff --git a/interfaces/inner_api/file_access/src/file_access_helper.cpp b/interfaces/inner_api/file_access/src/file_access_helper.cpp index 36419b3c5d64a11038a247775fa659a71654152c..6bbd80be4e01d9ed1590fee7abc321c7bbb533af 100644 --- a/interfaces/inner_api/file_access/src/file_access_helper.cpp +++ b/interfaces/inner_api/file_access/src/file_access_helper.cpp @@ -219,6 +219,7 @@ std::pair, int> FileAccessHelper::DoCreatorHel connectInfo->want = wants[i]; connectInfo->fileAccessExtConnection = fileAccessExtConnection; std::string bundleName = wants[i].GetElement().GetBundleName(); + HILOG_INFO("DoCreatorHelper bundleName is %{public}s", bundleName.c_str()); cMap.insert(std::pair>(bundleName, connectInfo)); } @@ -341,6 +342,7 @@ sptr FileAccessHelper::GetProxyByUri(Uri &uri) sptr FileAccessHelper::GetProxyByBundleName(const std::string &bundleName) { auto connectInfo = GetConnectInfo(bundleName); + HILOG_INFO("GetProxyByBundleName start %{public}s", bundleName.c_str()); if (connectInfo == nullptr) { HILOG_ERROR("GetProxyByUri failed with invalid connectInfo"); return nullptr; diff --git a/interfaces/kits/native/recent/recent_n_exporter.cpp b/interfaces/kits/native/recent/recent_n_exporter.cpp index bcf2c01103214b681d8094f57cc2d0cd14da9c8a..8bfc639cdafee38639a89077ffd3ca6c1b0d6d1f 100644 --- a/interfaces/kits/native/recent/recent_n_exporter.cpp +++ b/interfaces/kits/native/recent/recent_n_exporter.cpp @@ -164,6 +164,8 @@ static void Deleter(struct NameListArg *arg) (arg->namelist)[i] = nullptr; } free(arg->namelist); + free(arg); + arg = nullptr; } static int64_t GetFileMtime(const string &fileName) @@ -171,7 +173,7 @@ static int64_t GetFileMtime(const string &fileName) string filePath = RecentNExporter::recentPath_ + fileName; struct stat statBuf; if (lstat(filePath.c_str(), &statBuf) < 0) { - HILOG_ERROR("Failed to lstat uri, errno=%{public}d, fileName=%{public}s", errno, fileName.c_str()); + HILOG_ERROR("Failed to lstat uri, errno=%{public}d, fileName=%{private}s", errno, fileName.c_str()); return errno; } return static_cast(statBuf.st_mtime); @@ -181,7 +183,7 @@ static string GetName(const string &path) { auto pos = path.find_last_of('/'); if (pos == string::npos) { - HILOGE("Failed to split filename from path, path: %{public}s", path.c_str()); + HILOGE("Failed to split filename from path, path: %{private}s", path.c_str()); } return path.substr(pos + 1); } diff --git a/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp b/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp index dfb19a2e525bfd03a012e251c853fd5c3182110e..52da410004f5f018d248b2337b2bff93044cd2c8 100644 --- a/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp +++ b/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp @@ -185,7 +185,7 @@ static napi_value CreateObjectArray(napi_env env, vector result) static string FindSourceFilePath(const string &path) { - HILOG_INFO("FindSourceFilePath: curFilePath = %{public}s", path.c_str()); + HILOG_INFO("FindSourceFilePath: curFilePath = %{private}s", path.c_str()); size_t slashSize = 1; // 获取/trash目录位置 size_t trashPathPrefixPos = path.find(FileTrashNExporter::trashPath_); @@ -213,7 +213,7 @@ static string FindSourceFilePath(const string &path) string realFileName = realFilePath.substr(pos + TRASH_SUB_DIR.length() + timeSlot.length() + slashSize); realFilePath = "/" + realFilePathPrefix + realFileName; - HILOG_INFO("FindSourceFilePath: realFilePath After = %{public}s", realFilePath.c_str()); + HILOG_INFO("FindSourceFilePath: realFilePath After = %{private}s", realFilePath.c_str()); return realFilePath; } diff --git a/interfaces/kits/picker/include/picker_n_exporter.h b/interfaces/kits/picker/include/picker_n_exporter.h index d85f9d2a745aac0818c303987de636f74c5887d8..fc72bc9cb4ff3516cac1a3834b77043b99d64063 100644 --- a/interfaces/kits/picker/include/picker_n_exporter.h +++ b/interfaces/kits/picker/include/picker_n_exporter.h @@ -24,6 +24,7 @@ #include "picker_napi_utils.h" #include "napi_base_context.h" #include "napi_common_want.h" +#include "ui_extension_context.h" namespace OHOS { @@ -51,6 +52,8 @@ struct PickerAsyncContext { std::shared_ptr pickerCallBack; }; +static sptr window_; + class PickerNExporter final : public FileManagement::LibN::NExporter { public: inline static const std::string className_ = "Picker"; diff --git a/interfaces/kits/picker/include/picker_napi_utils.h b/interfaces/kits/picker/include/picker_napi_utils.h index 474181568f6c2d251a3abd1ad5d2161d4557fa75..2816b337c6cce19e0bbbf4a2a47325e8a20db6ca 100644 --- a/interfaces/kits/picker/include/picker_napi_utils.h +++ b/interfaces/kits/picker/include/picker_napi_utils.h @@ -44,9 +44,10 @@ constexpr uint32_t NAPI_INIT_REF_COUNT = 1; constexpr size_t NAPI_ARGC_MAX = 5; // Error codes -const int32_t ERR_DEFAULT = 0; +const int32_t ERR_OK = 0; const int32_t ERR_MEM_ALLOCATION = 2; const int32_t ERR_INVALID_OUTPUT = 3; +const int32_t ERR_INV = -1; struct JSAsyncContextOutput { napi_value error; diff --git a/interfaces/kits/picker/picker.js b/interfaces/kits/picker/picker.js index 52626fb892269eaa98ec666032e83c03670b44e3..c74df7d748e38dbd2e1f6535f51b11f5f3c5e780 100644 --- a/interfaces/kits/picker/picker.js +++ b/interfaces/kits/picker/picker.js @@ -37,6 +37,7 @@ const DocumentPickerMode = { const ExtTypes = { DOWNLOAD_TYPE: 'filePicker', AUDIO_PICKER_TYPE: 'audioPicker', + PHOTO_PICKER_TYPE: 'photoPicker', }; const PickerDetailType = { @@ -78,6 +79,7 @@ const ARGS_ONE = 1; const ARGS_TWO = 2; const RESULT_CODE_ERROR = -1; const RESULT_CODE_OK = 0; +const FILENAME_LENGTH = 3; /* * UTF-8字符编码数值对应的存储长度: @@ -147,6 +149,7 @@ function parsePhotoPickerSelectOption(args) { type: 'multipleselect', parameters: { uri: 'multipleselect', + extType: ExtTypes.PHOTO_PICKER_TYPE, }, }; @@ -199,11 +202,9 @@ function getPhotoPickerSelectResult(args) { }; if (args.resultCode === 0) { - if (args.want && args.want.parameters) { - let uris = args.want.parameters['select-item-list']; - let isOrigin = args.want.parameters.isOriginal; - selectResult.data = new PhotoSelectResult(uris, isOrigin); - } + let uris = args.photoUris; + let isOriginal = args.isOriginal; + selectResult.data = new PhotoSelectResult(uris, isOriginal); } else if (args.resultCode === -1) { selectResult.data = new PhotoSelectResult([], undefined); } else { @@ -224,6 +225,7 @@ async function photoPickerSelect(...args) { console.log('[picker] Photo config: ' + JSON.stringify(config)); let photoSelectContext = undefined; + let photoSelectWindow = undefined; try { if (this.context !== undefined) { photoSelectContext = this.context; @@ -239,9 +241,9 @@ async function photoPickerSelect(...args) { console.error('[picker] photoSelectContext == undefined'); throw getErr(ErrCode.CONTEXT_NO_EXIST); } - let result = await photoSelectContext.startAbilityForResult(config, {windowMode: 0}); - console.log('[picker] photo select result: ' + JSON.stringify(result)); - const photoSelectResult = getPhotoPickerSelectResult(result); + let modalSelectResult = await modalPicker(photoSelectContext, config, photoSelectWindow); + console.log('[picker] photo select result: ' + JSON.stringify(modalSelectResult)); + const photoSelectResult = getPhotoPickerSelectResult(modalSelectResult); console.log('[picker] photoSelectResult: ' + JSON.stringify(photoSelectResult)); if (args.length === ARGS_TWO && typeof args[ARGS_ONE] === 'function') { return args[ARGS_ONE](photoSelectResult.error, photoSelectResult.data); @@ -307,7 +309,7 @@ function parseAudioPickerSelectOption(args, action) { config.parameters.key_pick_num = option.maxSelectNumber; } } - console.log('modal picker: audio select config: ' + JSON.stringify(config)); + console.log('[picker] audio select config: ' + JSON.stringify(config)); return config; } @@ -316,7 +318,7 @@ function getDocumentPickerSelectResult(args) { error: undefined, data: undefined }; - if (args.resultCode === undefined) { + if (args === undefined || args.resultCode === undefined) { selectResult.error = getErr(ErrCode.RESULT_ERROR); console.log('[picker] document select selectResult: ' + JSON.stringify(selectResult)); return selectResult; @@ -347,6 +349,7 @@ async function documentPickerSelect(...args) { let documentSelectConfig = undefined; let documentSelectResult = undefined; let selectResult = undefined; + let documentSelectWindow = undefined; try { if (this.context !== undefined) { @@ -363,9 +366,12 @@ async function documentPickerSelect(...args) { console.error('[picker] documentSelectContext == undefined'); throw getErr(ErrCode.CONTEXT_NO_EXIST); } + if (this.window !== undefined) { + documentSelectWindow = this.window; + } documentSelectConfig = parseDocumentPickerSelectOption(args, ACTION.SELECT_ACTION_MODAL); console.error('[picker] DocumentSelect documentSelectConfig: ' + JSON.stringify(documentSelectConfig)); - documentSelectResult = await modalPicker(args, documentSelectContext, documentSelectConfig); + documentSelectResult = await modalPicker(documentSelectContext, documentSelectConfig, documentSelectWindow); } catch (paramError) { console.error('[picker] DocumentSelect paramError: ' + JSON.stringify(paramError)); } @@ -413,7 +419,7 @@ function getAudioPickerSelectResult(args) { error: undefined, data: undefined }; - if (args.resultCode === undefined) { + if (args === undefined || args.resultCode === undefined) { selectResult.error = getErr(ErrCode.RESULT_ERROR); console.log('[picker] getAudioPickerSelectResult selectResult: ' + JSON.stringify(selectResult)); return selectResult; @@ -441,7 +447,7 @@ function getDocumentPickerSaveResult(args) { error: undefined, data: undefined }; - if (args.resultCode === undefined) { + if (args === undefined || args.resultCode === undefined) { saveResult.error = getErr(ErrCode.RESULT_ERROR); console.log('[picker] getDocumentPickerSaveResult saveResult: ' + JSON.stringify(saveResult)); return saveResult; @@ -460,33 +466,36 @@ function getDocumentPickerSaveResult(args) { return saveResult; } -function startModalPicker(context, config) { +function startModalPicker(context, config, window) { if (context === undefined) { - console.log('[picker] modal picker: startModalPicker context undefined.'); - throw Error('[picker] modal picker: startModalPicker context undefined.'); + throw Error('[picker] Context undefined.'); } if (config === undefined) { - console.log('[picker] modal picker: startModalPicker config undefined.'); - throw Error('[picker] modal picker: startModalPicker config undefined.'); + throw Error('[picker] Config undefined.'); } gContext = context; if (pickerHelper === undefined) { - console.log('[picker] modal picker: pickerHelper undefined.'); + throw Error('[picker] PickerHelper undefined.'); + } + let helper; + if (window !== undefined) { + helper = pickerHelper.startModalPicker(gContext, config, window); + } else { + helper = pickerHelper.startModalPicker(gContext, config); } - let helper = pickerHelper.startModalPicker(gContext, config); if (helper === undefined) { - console.log('[picker] modal picker: startModalPicker helper undefined.'); + throw Error('[picker] Please check the parameter you entered.'); } return helper; } -async function modalPicker(args, context, config) { +async function modalPicker(context, config, window) { try { - console.log('[picker] modal picker: config: ' + JSON.stringify(config)); - let modalResult = await startModalPicker(context, config); + console.log('[picker] Config: ' + JSON.stringify(config)); + let modalResult = await startModalPicker(context, config, window); return modalResult; } catch (resultError) { - console.error('[picker] modal picker: Result error: ' + resultError); + console.error('[picker] Result error: ' + resultError); return undefined; } } @@ -502,6 +511,7 @@ async function documentPickerSave(...args) { let documentSaveConfig = undefined; let documentSaveResult = undefined; let saveResult = undefined; + let documentSaveWindow = undefined; try { if (this.context !== undefined) { @@ -513,11 +523,14 @@ async function documentPickerSave(...args) { console.error('[picker] getContext error: ' + getContextError); throw getErr(ErrCode.CONTEXT_NO_EXIST); } + if (this.window !== undefined) { + documentSaveWindow = this.window; + } documentSaveConfig = parseDocumentPickerSaveOption(args, ACTION.SAVE_ACTION_MODAL); console.log('[picker] document save start'); - documentSaveResult = await modalPicker(args, documentSaveContext, documentSaveConfig); + documentSaveResult = await modalPicker(documentSaveContext, documentSaveConfig, documentSaveWindow); saveResult = getDocumentPickerSaveResult(documentSaveResult); return sendResult(args, saveResult); } @@ -557,6 +570,7 @@ async function audioPickerSelect(...args) { console.log('[picker] audio select config: ' + JSON.stringify(audioSelectConfig)); let audioSelectContext = undefined; + let audipSelectWindow = undefined; try { if (this.context !== undefined) { audioSelectContext = this.context; @@ -572,7 +586,7 @@ async function audioPickerSelect(...args) { console.error('[picker] audioSelectContext == undefined'); throw getErr(ErrCode.CONTEXT_NO_EXIST); } - let modalSelectResult = await modalPicker(args, audioSelectContext, audioSelectConfig); + let modalSelectResult = await modalPicker(audioSelectContext, audioSelectConfig, audipSelectWindow); let saveResult = getAudioPickerSelectResult(modalSelectResult); return sendResult(args, saveResult); } catch (error) { @@ -617,12 +631,26 @@ function AudioSaveOptions() { function ParseContext(args) { - if (args.length > ARGS_ONE || args.length < ARGS_ZERO || typeof args[ARGS_ZERO] !== 'object') { + if (args.length > ARGS_TWO || args.length < ARGS_ZERO || typeof args[ARGS_ZERO] !== 'object') { return undefined; } return args[ARGS_ZERO]; } +function parseWindow(args) +{ + if (args.length !== ARGS_TWO) { + console.log('[picker] ParseWindow: not window mode.'); + return undefined; + } + if (args.length === ARGS_TWO && typeof args[ARGS_ONE] !== 'object') { + console.log('[picker] ParseWindow: not window mode or type err.'); + return undefined; + } + console.log('[picker] ParseWindow: window mode.'); + return args[ARGS_ONE]; +} + function PhotoViewPicker(...args) { this.select = photoPickerSelect; this.save = documentPickerSave; @@ -633,6 +661,7 @@ function DocumentViewPicker(...args) { this.select = documentPickerSelect; this.save = documentPickerSave; this.context = ParseContext(args); + this.window = parseWindow(args); } function AudioViewPicker(...args) { diff --git a/interfaces/kits/picker/src/modal_ui_callback.cpp b/interfaces/kits/picker/src/modal_ui_callback.cpp index e9b24d9ea1c9fbafd754eafed61cb849d5d345f7..6c09f6bccb82a5cc7fc4c52ed50e159b7b085e06 100644 --- a/interfaces/kits/picker/src/modal_ui_callback.cpp +++ b/interfaces/kits/picker/src/modal_ui_callback.cpp @@ -33,14 +33,14 @@ void ModalUICallback::SetSessionId(int32_t sessionId) void ModalUICallback::OnRelease(int32_t releaseCode) { - HILOG_INFO("modal picker: OnRelease enter. release code is %{public}d", releaseCode); + HILOG_INFO("[picker] OnRelease enter. release code is %{public}d", releaseCode); this->uiContent->CloseModalUIExtension(this->sessionId_); pickerCallBack_->ready = true; } void ModalUICallback::OnError(int32_t code, const std::string& name, const std::string& message) { - HILOG_ERROR("modal picker: OnError enter. errorCode=%{public}d, name=%{public}s, message=%{public}s", + HILOG_ERROR("[picker] OnError enter. errorCode=%{public}d, name=%{public}s, message=%{public}s", code, name.c_str(), message.c_str()); this->uiContent->CloseModalUIExtension(this->sessionId_); } @@ -54,12 +54,12 @@ void ModalUICallback::OnResultForModal(int32_t resultCode, const OHOS::AAFwk::Wa void ModalUICallback::OnReceive(const OHOS::AAFwk::WantParams &request) { - HILOG_INFO("modal picker: OnReceive enter."); + HILOG_INFO("[picker] OnReceive enter."); } void ModalUICallback::OnDestroy() { - HILOG_INFO("modal picker: OnDestroy enter."); + HILOG_INFO("[picker] OnDestroy enter."); } } // namespace Picker } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/picker/src/picker_n_exporter.cpp b/interfaces/kits/picker/src/picker_n_exporter.cpp index 11b684df9315a9128bd678b30d5096a7d7db49de..92100f00f97a9de624b736eec11aecf029ef6dd9 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -33,6 +33,8 @@ using namespace FileManagement::LibN; using namespace AppExecFwk; #define WAIT_TIME_MS 100 +static const string PHOTO_URIS_KEY = "photoUris"; + bool PickerNExporter::Export() { return exports_.AddProp({ @@ -47,12 +49,12 @@ string PickerNExporter::GetClassName() static void StartModalPickerExecute(napi_env env, void *data) { - HILOG_INFO("modal picker: StartModalPickerExecute begin"); + HILOG_INFO("[picker]: StartModalPickerExecute begin"); auto *context = static_cast(data); while (!context->pickerCallBack->ready) { std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME_MS)); } - HILOG_INFO("modal picker: StartModalPickerExecute is ready."); + HILOG_INFO("[picker]: StartModalPickerExecute is ready."); } static void MakeResultWithArr(napi_env env, std::string key, napi_value &result, @@ -63,7 +65,7 @@ static void MakeResultWithArr(napi_env env, std::string key, napi_value &result, napi_status status = napi_generic_failure; if (pickerCallBack->want.GetParams().HasParam(key.c_str())) { std::vector list = pickerCallBack->want.GetStringArrayParam(key.c_str()); - HILOG_INFO("modal picker: %{public}s size. %{public}zu ", key.c_str(), list.size()); + HILOG_INFO("[picker]: %{public}s size. %{public}zu ", key.c_str(), list.size()); for (size_t i = 0; i < list.size(); i++) { napi_value uri = nullptr; napi_create_string_utf8(env, list[i].c_str(), NAPI_AUTO_LENGTH, &uri); @@ -72,9 +74,28 @@ static void MakeResultWithArr(napi_env env, std::string key, napi_value &result, if (key == "ability.params.stream") { key = "ability_params_stream"; } + if (key == "select-item-list") { + key = PHOTO_URIS_KEY; + } status = napi_set_named_property(env, result, key.c_str(), array); if (status != napi_ok) { - HILOG_ERROR("modal picker: napi_set_named_property uri failed"); + HILOG_ERROR("[picker]: napi_set_named_property %{public}s failed", key.c_str()); + } + } +} + +static void MakeResultWithBool(napi_env env, std::string key, napi_value &result, + std::shared_ptr pickerCallBack) +{ + napi_status status = napi_generic_failure; + if (pickerCallBack->want.GetParams().HasParam(key.c_str())) { + const bool boolVal = pickerCallBack->want.GetBoolParam(key.c_str(), false); + HILOG_INFO("[picker]: %{public}s is %{public}d ", key.c_str(), boolVal); + napi_value nBoolVal = nullptr; + napi_get_boolean(env, boolVal, &nBoolVal); + status = napi_set_named_property(env, result, key.c_str(), nBoolVal); + if (status != napi_ok) { + HILOG_ERROR("[picker]: napi_set_named_property %{public}s failed", key.c_str()); } } } @@ -95,16 +116,18 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr(data); if (context == nullptr) { HILOG_ERROR("Async context is null"); @@ -114,11 +137,11 @@ static void StartModalPickerAsyncCallbackComplete(napi_env env, napi_status stat jsContext->status = false; status = napi_get_undefined(env, &jsContext->data); if (status != napi_ok) { - HILOG_ERROR("modal picker: napi_get_undefined jsContext->data failed"); + HILOG_ERROR("[picker]: napi_get_undefined jsContext->data failed"); } status = napi_get_undefined(env, &jsContext->error); if (status != napi_ok) { - HILOG_ERROR("modal picker: napi_get_undefined jsContext->error failed"); + HILOG_ERROR("[picker]: napi_get_undefined jsContext->error failed"); } napi_value result = MakeResultWithPickerCallBack(env, context->pickerCallBack); if (result != nullptr) { @@ -133,6 +156,83 @@ static void StartModalPickerAsyncCallbackComplete(napi_env env, napi_status stat context->work, *jsContext); } delete context; + if (window_) { + window_ = nullptr; + } +} + +static bool IsTypeRight(napi_env env, napi_value val, napi_valuetype type) +{ + napi_valuetype valueType; + napi_status status = napi_typeof(env, val, &valueType); + if (status != napi_ok || valueType != type) { + HILOG_ERROR("[picker] Type is not right, type: %{public}d", valueType); + return false; + } + return true; +} + +static ErrCode GetWindowName(napi_env env, napi_value properties, sptr &window) +{ + HILOG_INFO("[picker] Begin GetWindowName."); + napi_value name; + napi_status status = napi_get_named_property(env, properties, "name", &name); + if (status != napi_ok) { + HILOG_ERROR("Get name from properties fail."); + return ERR_INV; + } + size_t nameLen; + status = napi_get_value_string_utf8(env, name, NULL, 0, &nameLen); + if (status != napi_ok) { + HILOG_ERROR("[picker] Get window name length fail."); + return ERR_INV; + } + char *nameBuf = new char[nameLen + 1]; + status = napi_get_value_string_utf8(env, name, nameBuf, nameLen + 1, &nameLen); + if (status != napi_ok) { + HILOG_ERROR("[picker] Get value string UTF8 fail."); + return ERR_INV; + } + HILOG_INFO("[picker] Get window name: %{public}s", nameBuf); + auto customWindow = Rosen::Window::Find(nameBuf); + if (!customWindow) { + HILOG_ERROR("[picker] Window find fail."); + return ERR_INV; + } + window = customWindow; + HILOG_INFO("[picker] Window found: %{public}s", nameBuf); + delete[] nameBuf; + return ERR_OK; +} + +template +static ErrCode GetCustomShowingWindow(napi_env env, AsyncContext &asyncContext, + const napi_callback_info info, sptr &window) +{ + HILOG_INFO("[picker] GetCustomShowingWindow enter."); + napi_status status; + if (!IsTypeRight(env, asyncContext->argv[ARGS_TWO], napi_object)) { + HILOG_ERROR("[picker] The type of the parameter transferred to the window is not object."); + return ERR_INV; + } + auto windowObj = asyncContext->argv[ARGS_TWO]; + napi_value getPropertiesFunc; + status = napi_get_named_property(env, windowObj, "getWindowProperties", &getPropertiesFunc); + if (status != napi_ok || !getPropertiesFunc) { + HILOG_ERROR("[picker] getWindowProperties fail."); + return ERR_INV; + } + if (!IsTypeRight(env, getPropertiesFunc, napi_function)) { + HILOG_ERROR("[picker] The type of the parameter transferred to the getPropertiesFunc is not function."); + return ERR_INV; + } + napi_value properties; + status = napi_call_function(env, windowObj, getPropertiesFunc, 0, nullptr, &properties); + if (status != napi_ok || !properties) { + HILOG_INFO("[picker] Call getPropertiesFunc fail."); + return ERR_INV; + } + return GetWindowName(env, properties, window); } Ace::UIContent *GetUIContent(napi_env env, napi_callback_info info, @@ -141,19 +241,19 @@ Ace::UIContent *GetUIContent(napi_env env, napi_callback_info info, bool isStageMode = false; napi_status status = AbilityRuntime::IsStageContext(env, AsyncContext->argv[ARGS_ZERO], isStageMode); if (status != napi_ok || !isStageMode) { - HILOG_ERROR("modal picker: is not StageMode context"); + HILOG_ERROR("[picker]: is not StageMode context"); return nullptr; } auto context = AbilityRuntime::GetStageModeContext(env, AsyncContext->argv[ARGS_ZERO]); if (context == nullptr) { - HILOG_ERROR("modal picker: Failed to get native stage context instance"); + HILOG_ERROR("[picker]: Failed to get native stage context instance"); return nullptr; } auto abilityContext = AbilityRuntime::Context::ConvertTo(context); if (abilityContext == nullptr) { auto uiExtensionContext = AbilityRuntime::Context::ConvertTo(context); if (uiExtensionContext == nullptr) { - HILOG_ERROR("modal picker: Fail to convert to abilityContext or uiExtensionContext"); + HILOG_ERROR("[picker]: Fail to convert to abilityContext or uiExtensionContext"); return nullptr; } return uiExtensionContext->GetUIContent(); @@ -162,16 +262,24 @@ Ace::UIContent *GetUIContent(napi_env env, napi_callback_info info, } static napi_value StartPickerExtension(napi_env env, napi_callback_info info, - unique_ptr &AsyncContext) + unique_ptr &asyncContext) { - HILOG_INFO("modal picker: StartPickerExtension begin."); - Ace::UIContent *uiContent = GetUIContent(env, info, AsyncContext); + HILOG_INFO("[picker]: StartPickerExtension begin."); + Ace::UIContent *uiContent; + if (asyncContext->argc == ARGS_THREE && window_) { + HILOG_INFO("[picker] Will get uiContent by window."); + uiContent = window_->GetUIContent(); + } else { + HILOG_INFO("[picker] Will get uiContent by context."); + uiContent= GetUIContent(env, info, asyncContext); + } + if (uiContent == nullptr) { - HILOG_ERROR("modal picker: get uiContent failed"); + HILOG_ERROR("[picker]: get uiContent failed"); return nullptr; } AAFwk::Want request; - AppExecFwk::UnwrapWant(env, AsyncContext->argv[ARGS_ONE], request); + AppExecFwk::UnwrapWant(env, asyncContext->argv[ARGS_ONE], request); std::string targetType = request.GetStringParam("extType"); std::string pickerType; @@ -179,8 +287,8 @@ static napi_value StartPickerExtension(napi_env env, napi_callback_info info, pickerType = request.GetStringParam("pickerType"); } request.SetParam(ABILITY_WANT_PARAMS_UIEXTENSIONTARGETTYPE, targetType); - AsyncContext->pickerCallBack = make_shared(); - auto callback = std::make_shared(uiContent, AsyncContext->pickerCallBack); + asyncContext->pickerCallBack = make_shared(); + auto callback = std::make_shared(uiContent, asyncContext->pickerCallBack); Ace::ModalUIExtensionCallbacks extensionCallback = { .onRelease = std::bind(&ModalUICallback::OnRelease, callback, std::placeholders::_1), .onResult = std::bind(&ModalUICallback::OnResultForModal, callback, std::placeholders::_1, @@ -191,11 +299,11 @@ static napi_value StartPickerExtension(napi_env env, napi_callback_info info, .onDestroy = std::bind(&ModalUICallback::OnDestroy, callback), }; Ace::ModalUIExtensionConfig config; - HILOG_INFO("modal picker: will CreateModalUIExtension by extType: %{public}s, pickerType: %{public}s", + HILOG_INFO("[picker]: will CreateModalUIExtension by extType: %{public}s, pickerType: %{public}s", targetType.c_str(), pickerType.c_str()); int sessionId = uiContent->CreateModalUIExtension(request, extensionCallback, config); if (sessionId == 0) { - HILOG_ERROR("modal picker: create modalUIExtension failed"); + HILOG_ERROR("[picker]: create modalUIExtension failed"); return nullptr; } callback->SetSessionId(sessionId); @@ -208,22 +316,29 @@ template static napi_status AsyncContextSetStaticObjectInfo(napi_env env, napi_callback_info info, AsyncContext &asyncContext, const size_t minArgs, const size_t maxArgs) { - HILOG_INFO("modal picker: AsyncContextSetStaticObjectInfo begin."); + HILOG_INFO("[picker]: AsyncContextSetStaticObjectInfo begin."); napi_value thisVar = nullptr; asyncContext->argc = maxArgs; napi_status ret = napi_get_cb_info(env, info, &asyncContext->argc, &(asyncContext->argv[ARGS_ZERO]), &thisVar, nullptr); if (ret != napi_ok) { - HILOG_ERROR("modal picker: Failed to get cb info"); + HILOG_ERROR("[picker]: Failed to get cb info"); return ret; } + if (asyncContext->argc == ARGS_THREE) { + int res = GetCustomShowingWindow(env, asyncContext, info, window_); + if (res != ERR_OK) { + HILOG_ERROR("[picker] Failed to get cb window_ info."); + return napi_invalid_arg; + } + } if (!((asyncContext->argc >= minArgs) && (asyncContext->argc <= maxArgs))) { - HILOG_ERROR("modal picker: Number of args is invalid"); + HILOG_ERROR("[picker]: Number of args is invalid"); return napi_invalid_arg; } if (minArgs > 0) { if (asyncContext->argv[ARGS_ZERO] == nullptr) { - HILOG_ERROR("modal picker: Argument list is empty"); + HILOG_ERROR("[picker]: Argument list is empty"); return napi_invalid_arg; } } @@ -233,12 +348,13 @@ static napi_status AsyncContextSetStaticObjectInfo(napi_env env, napi_callback_i static napi_value ParseArgsStartModalPicker(napi_env env, napi_callback_info info, unique_ptr &context) { - HILOG_INFO("modal picker: ParseArgsStartModalPicker begin."); + HILOG_INFO("[picker]: ParseArgsStartModalPicker begin."); constexpr size_t minArgs = ARGS_TWO; constexpr size_t maxArgs = ARGS_THREE; napi_status status = AsyncContextSetStaticObjectInfo(env, info, context, minArgs, maxArgs); if (status != napi_ok) { - HILOG_ERROR("modal picker: AsyncContextSetStaticObjectInfo faild"); + HILOG_ERROR("[picker]: AsyncContextSetStaticObjectInfo faild"); + return nullptr; } napi_value result = nullptr; napi_value ret = StartPickerExtension(env, info, context); @@ -251,7 +367,7 @@ static napi_value ParseArgsStartModalPicker(napi_env env, napi_callback_info inf napi_value PickerNExporter::StartModalPicker(napi_env env, napi_callback_info info) { - HILOG_INFO("modal picker: StartModalPicker begin."); + HILOG_INFO("[picker]: StartModalPicker begin."); unique_ptr asyncContext = make_unique(); napi_value ret = ParseArgsStartModalPicker(env, info, asyncContext); if (ret == nullptr) { diff --git a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts index a5e6ed3b9619de399f660ccee071e8bf726de87b..7e4faa9b8e72c9e792abe3653286b26b588efaf3 100644 --- a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts +++ b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -769,6 +769,7 @@ export default class FileExtAbility extends Extension { deviceType: deviceType.DEVICE_SHARED_TERMINAL, deviceFlags: deviceFlag.SUPPORTS_READ | deviceFlag.SUPPORTS_WRITE, }; + hilog.info(DOMAIN_CODE, TAG, `df count: ${hmdfsInfo.length}`); hmdfsInfoList.push(hmdfsInfo); hilog.info(DOMAIN_CODE, TAG, `df count: ${hmdfsInfo.length}`); } @@ -807,7 +808,7 @@ export default class FileExtAbility extends Extension { volumeInfoList.push(volumeInfo); } roots = roots.concat(volumeInfoList); - + hilog.info(DOMAIN_CODE, TAG, `External file count: ${volumeInfoList.length}`); try { roots = roots.concat(getHmdfsPath()); } catch (e) { diff --git a/test/fuzztest/fileaccessextconnection_fuzzer/fileaccessextconnection_fuzzer.cpp b/test/fuzztest/fileaccessextconnection_fuzzer/fileaccessextconnection_fuzzer.cpp index 6392cae815d8bb84b37e5a1884510097e54d2fa2..aeca7c1a08b0bcbc2b6f41f2342fa66a0d1bfc56 100644 --- a/test/fuzztest/fileaccessextconnection_fuzzer/fileaccessextconnection_fuzzer.cpp +++ b/test/fuzztest/fileaccessextconnection_fuzzer/fileaccessextconnection_fuzzer.cpp @@ -24,7 +24,7 @@ namespace OHOS { using namespace std; using namespace FileAccessFwk; -bool OnAbilityConnectDoneFuzzTest(shared_ptr conn) +bool OnAbilityConnectDoneFuzzTest(sptr conn) { AppExecFwk::ElementName element; sptr remoteObject = nullptr; @@ -32,20 +32,20 @@ bool OnAbilityConnectDoneFuzzTest(shared_ptr conn) return true; } -bool OnAbilityDisconnectDoneFuzzTest(shared_ptr conn) +bool OnAbilityDisconnectDoneFuzzTest(sptr conn) { AppExecFwk::ElementName element; conn->OnAbilityDisconnectDone(element, 0); return true; } -bool IsExtAbilityConnectedFuzzTest(shared_ptr conn) +bool IsExtAbilityConnectedFuzzTest(sptr conn) { conn->IsExtAbilityConnected(); return true; } -bool GetFileExtProxyFuzzTest(shared_ptr conn) +bool GetFileExtProxyFuzzTest(sptr conn) { conn->GetFileExtProxy(); return true; @@ -71,7 +71,7 @@ bool DisconnectFileExtAbility(shared_ptr conn) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - auto conn = std::make_shared(); + auto conn = OHOS::sptr(); if (conn == nullptr) { return 0; } diff --git a/utils/file_util.h b/utils/file_util.h index 5d497add728e4d46e23e7c67027136125a53134c..32487323b07cd6f52fbc6d30c72d3722499cb7f5 100644 --- a/utils/file_util.h +++ b/utils/file_util.h @@ -57,6 +57,8 @@ static void Deleter(struct NameListArg *arg) (arg->namelist)[i] = nullptr; } free(arg->namelist); + free(arg); + arg = nullptr; } static int32_t FilterFunc(const struct dirent *filename)