diff --git a/interfaces/inner_api/file_access/BUILD.gn b/interfaces/inner_api/file_access/BUILD.gn index 8acb5aaf23082d891b705464889e5e760450ec5d..096555c1ee967972fee5658b03a47a1d1f96d8c2 100644 --- a/interfaces/inner_api/file_access/BUILD.gn +++ b/interfaces/inner_api/file_access/BUILD.gn @@ -55,6 +55,7 @@ ohos_shared_library("file_access_extension_ability_kit") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "//foundation/communication/ipc/ipc/native/src/napi/include", + "//foundation/filemanagement/file_api/utils/filemgmt_libn/include", ] sources = [ @@ -80,7 +81,6 @@ ohos_shared_library("file_access_extension_ability_kit") { ] deps = [ - "${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native", "${ability_runtime_path}/frameworks/native/appkit:app_context", "${access_token_path}/interfaces/innerkits/accesstoken:libtokenid_sdk", ] @@ -89,6 +89,8 @@ ohos_shared_library("file_access_extension_ability_kit") { "ability_base:want", "ability_base:zuri", "ability_runtime:ability_manager", + "ability_runtime:extensionkit_native", + "ability_runtime:napi_common", "ability_runtime:runtime", "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", diff --git a/interfaces/inner_api/file_access/include/file_access_ext_ability.h b/interfaces/inner_api/file_access/include/file_access_ext_ability.h index 0cba3acfe521edbd8d6394c683f55b4d938dde97..8c2858f860674b3195f397fe8535633ebc48fec0 100644 --- a/interfaces/inner_api/file_access/include/file_access_ext_ability.h +++ b/interfaces/inner_api/file_access/include/file_access_ext_ability.h @@ -49,6 +49,7 @@ public: virtual int Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile); virtual int Delete(const Uri &sourceFile); virtual int Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile); + virtual int Copy(const Uri &sourceUri, const Uri &destUri, std::vector ©Result); virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile); virtual int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, const FileFilter &filter, std::vector &fileInfoVec); @@ -70,4 +71,4 @@ private: }; } // namespace FileAccessFwk } // namespace OHOS -#endif // FILE_ACCESS_EXT_ABILITY_H \ No newline at end of file +#endif // FILE_ACCESS_EXT_ABILITY_H diff --git a/interfaces/inner_api/file_access/include/file_access_ext_stub.h b/interfaces/inner_api/file_access/include/file_access_ext_stub.h index 84e1fdf9830e34bceedb84e2d76f271629cb344c..d1e482ba8ea4663629709e0c9813fc2afab1ba5b 100644 --- a/interfaces/inner_api/file_access/include/file_access_ext_stub.h +++ b/interfaces/inner_api/file_access/include/file_access_ext_stub.h @@ -40,6 +40,7 @@ private: ErrCode CmdMkdir(MessageParcel &data, MessageParcel &reply); ErrCode CmdDelete(MessageParcel &data, MessageParcel &reply); ErrCode CmdMove(MessageParcel &data, MessageParcel &reply); + ErrCode CmdCopy(MessageParcel &data, MessageParcel &reply); ErrCode CmdRename(MessageParcel &data, MessageParcel &reply); ErrCode CmdListFile(MessageParcel &data, MessageParcel &reply); ErrCode CmdScanFile(MessageParcel &data, MessageParcel &reply); @@ -56,4 +57,4 @@ private: }; } // namespace FileAccessFwk } // namespace OHOS -#endif // FILE_ACCESS_EXT_STUB_H \ No newline at end of file +#endif // FILE_ACCESS_EXT_STUB_H diff --git a/interfaces/inner_api/file_access/include/file_access_ext_stub_impl.h b/interfaces/inner_api/file_access/include/file_access_ext_stub_impl.h index cce44dcedf572b85c85f3ba35ac4319a6bbe2eb1..1cad57a547074a4c8793706f58235819a2b22d3d 100644 --- a/interfaces/inner_api/file_access/include/file_access_ext_stub_impl.h +++ b/interfaces/inner_api/file_access/include/file_access_ext_stub_impl.h @@ -41,6 +41,7 @@ public: int Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) override; int Delete(const Uri &sourceFile) override; int Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) override; + int Copy(const Uri &sourceUri, const Uri &destUri, std::vector ©Result) override; int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) override; int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, const FileFilter &filter, std::vector &fileInfoVec) override; @@ -60,4 +61,4 @@ private: }; } // namespace FileAccessFwk } // namespace OHOS -#endif // FILE_ACCESS_EXT_STUB_IMPL_H \ No newline at end of file +#endif // FILE_ACCESS_EXT_STUB_IMPL_H diff --git a/interfaces/inner_api/file_access/include/file_access_extension_info.h b/interfaces/inner_api/file_access/include/file_access_extension_info.h index 0f51b3b8914b4e5308293b6e0951347f6a0da030..f7b63ce71935c9fb17c148b77fd6d9e8c3fc0a41 100644 --- a/interfaces/inner_api/file_access/include/file_access_extension_info.h +++ b/interfaces/inner_api/file_access/include/file_access_extension_info.h @@ -207,6 +207,54 @@ public: return size; } }; + +struct CopyResult : public virtual OHOS::Parcelable { +public: + std::string uri { "" }; + int32_t errCode { 0 }; + std::string errMsg { "" }; + + CopyResult() = default; + CopyResult(std::string uri, int32_t errCode, std::string errMsg) + : uri(uri), errCode(errCode), errMsg(errMsg) + {} + + bool ReadFromParcel(Parcel &parcel) + { + uri = parcel.ReadString(); + errCode = parcel.ReadInt32(); + errMsg = parcel.ReadString(); + return true; + } + + virtual bool Marshalling(Parcel &parcel) const override + { + if (!parcel.WriteString(uri)) { + return false; + } + if (!parcel.WriteInt32(errCode)) { + return false; + } + if (!parcel.WriteString(errMsg)) { + return false; + } + return true; + } + + static CopyResult *Unmarshalling(Parcel &parcel) + { + CopyResult *result = new (std::nothrow)CopyResult(); + if (result == nullptr) { + return nullptr; + } + + if (!result->ReadFromParcel(parcel)) { + delete result; + result = nullptr; + } + return result; + } +}; } // namespace FileAccessFwk } // namespace OHOS -#endif // FILE_ACCESS_EXTENSION_INFO_H \ No newline at end of file +#endif // FILE_ACCESS_EXTENSION_INFO_H diff --git a/interfaces/inner_api/file_access/include/ifile_access_ext_base.h b/interfaces/inner_api/file_access/include/ifile_access_ext_base.h index ad54e35e694bd44806e139248cdaedb9d815ed28..191ff9a58abbfea473f4ccc4ae2f8f4e9d40e745 100644 --- a/interfaces/inner_api/file_access/include/ifile_access_ext_base.h +++ b/interfaces/inner_api/file_access/include/ifile_access_ext_base.h @@ -43,6 +43,7 @@ public: CMD_MKDIR, CMD_DELETE, CMD_MOVE, + CMD_COPY, CMD_RENAME, CMD_LIST_FILE, CMD_SCAN_FILE, @@ -60,6 +61,7 @@ public: virtual int Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) = 0; virtual int Delete(const Uri &sourceFile) = 0; virtual int Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) = 0; + virtual int Copy(const Uri &sourceUri, const Uri &destUri, std::vector ©Result) = 0; virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) = 0; virtual int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, const FileFilter &filter, std::vector &fileInfoVec) = 0; diff --git a/interfaces/inner_api/file_access/include/js_file_access_ext_ability.h b/interfaces/inner_api/file_access/include/js_file_access_ext_ability.h index 8c3eb4d9f05f82a4472e2dc0cd3b36f79214d6c7..b1933b1a761d1e0ffb59af52b0add2d15f23bc70 100644 --- a/interfaces/inner_api/file_access/include/js_file_access_ext_ability.h +++ b/interfaces/inner_api/file_access/include/js_file_access_ext_ability.h @@ -84,4 +84,4 @@ private: }; } // namespace FileAccessFwk } // namespace OHOS -#endif // JS_FILE_ACCESS_EXT_ABILITY_H \ No newline at end of file +#endif // JS_FILE_ACCESS_EXT_ABILITY_H diff --git a/interfaces/inner_api/file_access/src/file_access_ext_ability.cpp b/interfaces/inner_api/file_access/src/file_access_ext_ability.cpp index 05e9a590b196583097b328e821385930f467e17a..a967b94f9fa25ecf846448b4571c4a1ec473076c 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_ability.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_ability.cpp @@ -15,7 +15,6 @@ #include "file_access_ext_ability.h" -#include "ability_loader.h" #include "connection_manager.h" #include "extension_context.h" #include "file_access_framework_errno.h" @@ -91,6 +90,12 @@ int FileAccessExtAbility::Move(const Uri &sourceFile, const Uri &targetParent, U return EPERM; } +int FileAccessExtAbility::Copy(const Uri &sourceUri, const Uri &destUri, std::vector ©Result) +{ + HILOG_ERROR("FileAccessExtAbility::Copy Undefined operation"); + return EPERM; +} + int FileAccessExtAbility::Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) { HILOG_ERROR("FileAccessExtAbility::Rename Undefined operation"); @@ -200,4 +205,4 @@ int FileAccessExtAbility::Notify(const NotifyMessage& message) return ret; } } // namespace FileAccessFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp b/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp index db82016b7e18af8d1a9b4081e139ec85f25b6d82..3e7b6f01deb85492b4a95cf53023ad9dd77c6dcc 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp @@ -47,6 +47,7 @@ FileAccessExtStub::FileAccessExtStub() stubFuncMap_[CMD_MKDIR] = &FileAccessExtStub::CmdMkdir; stubFuncMap_[CMD_DELETE] = &FileAccessExtStub::CmdDelete; stubFuncMap_[CMD_MOVE] = &FileAccessExtStub::CmdMove; + stubFuncMap_[CMD_COPY] = &FileAccessExtStub::CmdCopy; stubFuncMap_[CMD_RENAME] = &FileAccessExtStub::CmdRename; stubFuncMap_[CMD_LIST_FILE] = &FileAccessExtStub::CmdListFile; stubFuncMap_[CMD_SCAN_FILE] = &FileAccessExtStub::CmdScanFile; @@ -273,6 +274,49 @@ ErrCode FileAccessExtStub::CmdMove(MessageParcel &data, MessageParcel &reply) return ERR_OK; } +ErrCode FileAccessExtStub::CmdCopy(MessageParcel &data, MessageParcel &reply) +{ + StartTrace(HITRACE_TAG_FILEMANAGEMENT, "CmdCopy"); + std::shared_ptr sourceUri(data.ReadParcelable()); + if (sourceUri == nullptr) { + HILOG_ERROR("Parameter Copy fail to ReadParcelable sourceUri"); + FinishTrace(HITRACE_TAG_FILEMANAGEMENT); + return E_IPCS; + } + + std::shared_ptr destUri(data.ReadParcelable()); + if (destUri == nullptr) { + HILOG_ERROR("Parameter Copy fail to ReadParcelable destUri"); + FinishTrace(HITRACE_TAG_FILEMANAGEMENT); + return E_IPCS; + } + + std::vector copyResult; + int ret = Copy(*sourceUri, *destUri, copyResult); + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("Parameter Copy fail to WriteInt32 ret"); + FinishTrace(HITRACE_TAG_FILEMANAGEMENT); + return E_IPCS; + } + + if (!reply.WriteInt32(copyResult.size())) { + HILOG_ERROR("Parameter Copy fail to WriteInt32 size of copyResult"); + FinishTrace(HITRACE_TAG_FILEMANAGEMENT); + return E_IPCS; + } + + for (auto &cr : copyResult) { + if (!reply.WriteParcelable(&cr)) { + HILOG_ERROR("Parameter Copy fail to WriteParcelable copyResult"); + FinishTrace(HITRACE_TAG_FILEMANAGEMENT); + return E_IPCS; + } + } + + FinishTrace(HITRACE_TAG_FILEMANAGEMENT); + return ERR_OK; +} + ErrCode FileAccessExtStub::CmdRename(MessageParcel &data, MessageParcel &reply) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "CmdRename"); @@ -645,4 +689,4 @@ ErrCode FileAccessExtStub::CmdUnregisterNotify(MessageParcel &data, MessageParce return ERR_OK; } } // namespace FileAccessFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp b/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp index b7bab8f68a5b09a1bfb86cfa470667401e8d1c33..b0cfc4d9f616a58558c0c9189f1a0bf2e69c7ff5 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp @@ -98,6 +98,19 @@ int FileAccessExtStubImpl::Move(const Uri &sourceFile, const Uri &targetParent, return ret; } +int FileAccessExtStubImpl::Copy(const Uri &sourceUri, const Uri &destUri, std::vector ©Result) +{ + StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Copy"); + if (extension_ == nullptr) { + HILOG_ERROR("Copy get extension failed."); + FinishTrace(HITRACE_TAG_FILEMANAGEMENT); + return E_IPCS; + } + int ret = extension_->Copy(sourceUri, destUri, copyResult); + FinishTrace(HITRACE_TAG_FILEMANAGEMENT); + return ret; +} + int FileAccessExtStubImpl::Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Rename"); @@ -255,4 +268,4 @@ int FileAccessExtStubImpl::UnregisterNotify(sptr ¬ify) return ret; } } // namespace FileAccessFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/utils/file_access_framework_errno.h b/utils/file_access_framework_errno.h index e3d7928598c9180e79cef28f865ffbabde7b272a..6c02a8d893c94df1326d19782e0adb0709b804a7 100644 --- a/utils/file_access_framework_errno.h +++ b/utils/file_access_framework_errno.h @@ -16,6 +16,8 @@ #ifndef FILE_ACCESS_FRAMEWORK_ERRNO_H #define FILE_ACCESS_FRAMEWORK_ERRNO_H +#include +#include #include "errors.h" namespace OHOS { @@ -36,6 +38,52 @@ enum { E_PERMISSION = 201, // Permission verification failed E_PERMISSION_SYS // is not system app }; + +// General error code for FAF +enum { + ERR_FAF_SUCCESS = 0, + ERR_FAF_FAIL, + ERR_FAF_PERM, + ERR_FAF_NOENT, + ERR_FAF_INTR, + ERR_FAF_IO, + ERR_FAF_NXIO, + ERR_FAF_2BIG, + ERR_FAF_NOMEM, + ERR_FAF_ACCES, + ERR_FAF_FAULT, + ERR_FAF_BUSY, + ERR_FAF_EXIST, + ERR_FAF_NOTDIR, + ERR_FAF_INVAL, + ERR_FAF_FBIG, + ERR_FAF_NOSPC, + ERR_FAF_ROFS, + ERR_FAF_NAMETOOLONG, +}; + +// {FAF error code, error message} +const std::unordered_map FAFErrCodeTable = { + { ERR_FAF_SUCCESS, "Execute succeed" }, + { ERR_FAF_FAIL, "Execute failed" }, + { ERR_FAF_PERM, "Operation not permitted" }, + { ERR_FAF_NOENT, "No such file or directory" }, + { ERR_FAF_INTR, "Interrupted system call" }, + { ERR_FAF_IO, "I/O error" }, + { ERR_FAF_NXIO, "No such device or address" }, + { ERR_FAF_2BIG, "Arg list too long" }, + { ERR_FAF_NOMEM, "Out of memory" }, + { ERR_FAF_ACCES, "Permission denied" }, + { ERR_FAF_FAULT, "Bad address" }, + { ERR_FAF_BUSY, "Device or resource busy" }, + { ERR_FAF_EXIST, "File exists" }, + { ERR_FAF_NOTDIR, "Not a directory" }, + { ERR_FAF_INVAL, "Invalid argument" }, + { ERR_FAF_FBIG, "File too large" }, + { ERR_FAF_NOSPC, "No space left on device" }, + { ERR_FAF_ROFS, "Read-only file system" }, + { ERR_FAF_NAMETOOLONG, "File name too long" } +}; } // namespace FileAccessFwk } // namespace OHOS -#endif // FILE_ACCESS_FRAMEWORK_ERRNO_H \ No newline at end of file +#endif // FILE_ACCESS_FRAMEWORK_ERRNO_H