diff --git a/interfaces/kits/js/src/file_manager_napi.cpp b/interfaces/kits/js/src/file_manager_napi.cpp index d1e506ac89c48b31145c5aa7d71d9d22b2d6c458..1eeb3683456bab9f09bf76af8e45c849f5460a07 100644 --- a/interfaces/kits/js/src/file_manager_napi.cpp +++ b/interfaces/kits/js/src/file_manager_napi.cpp @@ -43,12 +43,6 @@ struct AsyncUriArg { ~AsyncUriArg() = default; }; -struct ListFileOptionArgs { - int64_t offset = 0; - int64_t count = 0; - bool hasOp = false; -}; - tuple FileManagerNapi::GetFmsClient() { if (fmsClient_ == nullptr) { @@ -185,42 +179,64 @@ napi_value FileManagerNapi::GetRoot(napi_env env, napi_callback_info info) } } -tuple, unique_ptr, unique_ptr, ListFileOptionArgs> GetListFileArg( +bool GetLstFileOption(const NVal &argv, ListFileOption &option) +{ + bool ret = false; + if (argv.HasProp("dev")) { + unique_ptr devName; + NVal dev(argv.GetProp("dev")); + if (dev.HasProp("name")) { + tie(ret, devName, ignore) = dev.GetProp("name").ToUTF8String(); + if (!ret) { + ERR_LOG("ListFileArgs LF_OPTION dev para fails"); + return false; + } + option.dev.name = devName.get(); + } + } + if (argv.HasProp("offset")) { + tie(ret, option.offset) = argv.GetProp("offset").ToInt64(); + if (!ret) { + ERR_LOG("ListFileArgs LF_OPTION offset para fails"); + return false; + } + } + if (argv.HasProp("count")) { + tie(ret, option.count) = argv.GetProp("count").ToInt64(); + if (!ret) { + ERR_LOG("ListFileArgs LF_OPTION count para fails"); + return false; + } + } + return true; +} + +tuple, unique_ptr, ListFileOption> GetListFileArg( napi_env env, NFuncArg &funcArg) { bool succ = false; - unique_ptr type; - ListFileOptionArgs option; - tie(succ, type, ignore) = NVal(env, funcArg[ListFileArgs::LF_TYPE]).ToUTF8String(); - if (!succ) { - ERR_LOG("ListFileArgs LF_TYPE para fails"); - return {false, nullptr, nullptr, nullptr, option}; - } unique_ptr path; + unique_ptr type; + ListFileOption option; tie(succ, path, ignore) = NVal(env, funcArg[ListFileArgs::LF_PATH]).ToUTF8String(); if (!succ) { ERR_LOG("ListFileArgs LF_PATH para fails"); - return {false, nullptr, nullptr, nullptr, option}; + return {false, nullptr, nullptr, option}; + } + tie(succ, type, ignore) = NVal(env, funcArg[ListFileArgs::LF_TYPE]).ToUTF8String(); + if (!succ) { + ERR_LOG("ListFileArgs LF_TYPE para fails"); + return {false, nullptr, nullptr, option}; } NVal op(env, NVal(env, funcArg[ListFileArgs::LF_OPTION]).val_); - if (op.HasProp("offset")) { - tie(succ, option.offset) = op.GetProp("offset").ToInt64(); - if (!succ) { - ERR_LOG("ListFileArgs LF_OPTION offset para fails"); - return {false, nullptr, nullptr, nullptr, option}; - } - option.hasOp = true; + if (op.TypeIs(napi_function)) { + return {true, move(type), move(path), option}; } - if (op.HasProp("count")) { - tie(succ, option.count) = op.GetProp("count").ToInt64(); - if (!succ) { - ERR_LOG("ListFileArgs LF_OPTION count para fails"); - return {false, nullptr, nullptr, nullptr, option}; - } - option.hasOp = true; + option.hasOpt = true; + if (!GetLstFileOption(op, option)) { + return {false, nullptr, nullptr, option}; } - // currently devName is ignore - return {true, nullptr, move(type), move(path), option}; + return {true, move(type), move(path), option}; } napi_value FileManagerNapi::ListFile(napi_env env, napi_callback_info info) @@ -231,13 +247,14 @@ napi_value FileManagerNapi::ListFile(napi_env env, napi_callback_info info) return nullptr; } bool succ = false; - // first is devName for extention - // second is type unique_ptr type; unique_ptr path; - ListFileOptionArgs option; - // currently devName is ignore - tie(succ, ignore, type, path, option) = GetListFileArg(env, funcArg); + ListFileOption option; + tie(succ, type, path, option) = GetListFileArg(env, funcArg); + if (!succ) { + UniError(EINVAL).ThrowErr(env, "Get argments fails"); + return nullptr; + } napi_value fileArr; napi_create_array(env, &fileArr); auto arg = make_shared(NVal(env, fileArr)); @@ -250,7 +267,7 @@ napi_value FileManagerNapi::ListFile(napi_env env, napi_callback_info info) return UniError(ESRCH); } vector fileRes; - int err = client->ListFile(type, path, option.offset, option.count, fileRes); + int err = client->ListFile(type, path, option, fileRes); arg->fileRes_ = fileRes; return DealWithErrno(err); }; @@ -266,10 +283,10 @@ napi_value FileManagerNapi::ListFile(napi_env env, napi_callback_info info) string procedureName = "ListFile"; int argc = funcArg.GetArgc(); NVal thisVar(env, funcArg.GetThisVar()); - if (argc == LIST_FILE_PARA_MIN || (argc != LIST_FILE_PARA_MAX && option.hasOp)) { + if (argc == LIST_FILE_PARA_MIN || (argc != LIST_FILE_PARA_MAX && option.hasOpt)) { return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; } else { - int cbIdx = ((!option.hasOp) ? ListFileArgs::LF_CALLBACK_WITHOUT_OP : ListFileArgs::LF_CALLBACK_WITH_OP); + int cbIdx = ((!option.hasOpt) ? ListFileArgs::LF_CALLBACK_WITHOUT_OP : ListFileArgs::LF_CALLBACK_WITH_OP); NVal cb(env, funcArg[cbIdx]); return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; } diff --git a/interfaces/kits/js/src/file_manager_napi_def.h b/interfaces/kits/js/src/file_manager_napi_def.h index c1549c67910c9e340e4aa3de3720e0a99ae233c1..1d008cd986bbe5e1f303b1f4e76bc0cf85e2cf4d 100644 --- a/interfaces/kits/js/src/file_manager_napi_def.h +++ b/interfaces/kits/js/src/file_manager_napi_def.h @@ -34,20 +34,19 @@ enum GetRootArgs { }; enum ListFileArgs { - LF_DEV = 0, + LF_PATH = 0, LF_TYPE = 1, - LF_PATH = 2, - LF_OPTION = 3, - LF_CALLBACK_WITHOUT_OP = 3, - LF_CALLBACK_WITH_OP = 4, + LF_OPTION = 2, + LF_CALLBACK_WITHOUT_OP = 2, + LF_CALLBACK_WITH_OP = 3, }; constexpr int CREATE_FILE_PARA_MAX = 4; constexpr int CREATE_FILE_PARA_MIN = 3; constexpr int GET_ROOT_PARA_MAX = 2; constexpr int GET_ROOT_PARA_MIN = 1; -constexpr int LIST_FILE_PARA_MAX = 5; -constexpr int LIST_FILE_PARA_MIN = 3; +constexpr int LIST_FILE_PARA_MAX = 4; +constexpr int LIST_FILE_PARA_MIN = 2; } // namespace FileManagerService } // namespace OHOS #endif // STORAGE_FILE_MANAGER_NAPI_DEF_H diff --git a/services/BUILD.gn b/services/BUILD.gn index f265421e45e261fc6c3f826a8bd99528d3ef9b76..3664929817e8aa62c763d583808cf1ba9450fe1a 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -43,6 +43,9 @@ ohos_shared_library("fms_server") { sources = [ "src/client/file_manager_proxy.cpp", + "src/fileoper/external_storage_oper.cpp", + "src/fileoper/external_storage_utils.cpp", + "src/fileoper/utils.cpp", "src/fileoper/media_file_oper.cpp", "src/fileoper/media_file_utils.cpp", "src/fileoper/oper_factory.cpp", diff --git a/services/src/client/file_manager_proxy.cpp b/services/src/client/file_manager_proxy.cpp index 78621283a98aea141078a66bcda99f4347dd73f3..26130d1fd8c7253913783d11fd205faa33b1d055 100644 --- a/services/src/client/file_manager_proxy.cpp +++ b/services/src/client/file_manager_proxy.cpp @@ -71,16 +71,23 @@ IFmsClient *IFmsClient::GetFmsInstance() return &proxy; } -int FileManagerProxy::ListFile(const string &type, const string &path, int off, int count, vector &fileRes) +int FileManagerProxy::ListFile(const std::string &type, const std::string &path, const ListFileOption &option, + std::vector &fileRes) { MessageParcel data; + data.WriteString(option.dev.name); + data.WriteString(option.dev.path); data.WriteString(type); data.WriteString(path); - data.WriteInt32(off); - data.WriteInt32(count); + data.WriteInt32(option.offset); + data.WriteInt32(option.count); MessageParcel reply; - MessageOption option; - int err = Remote()->SendRequest(Operation::LIST_FILE, data, reply, option); + MessageOption messageOption; + uint32_t code = Equipment::INTERNAL_STORAGE; + if (option.dev.name == "external_storage") { + code = (Equipment::EXTERNAL_STORAGE << EQUIPMENT_SHIFT) | Operation::LIST_FILE; + } + int err = Remote()->SendRequest(code, data, reply, messageOption); if (err != ERR_NONE) { ERR_LOG("inner error send request fail %{public}d", err); return FAIL; diff --git a/services/src/client/file_manager_proxy.h b/services/src/client/file_manager_proxy.h index 2d93d10ded0dec08f90996a050e43a9d0f0186a8..cc384c7bf6eb892644347bfafbd19a15c3b4ea6c 100644 --- a/services/src/client/file_manager_proxy.h +++ b/services/src/client/file_manager_proxy.h @@ -28,8 +28,8 @@ public: explicit FileManagerProxy(const sptr &impl); virtual ~FileManagerProxy() = default; int Mkdir(const std::string &name, const std::string &path) override; - int ListFile(const std::string &type, const std::string &path, - int off, int count, std::vector &fileRes) override; + int ListFile(const std::string &type, const std::string &path, const ListFileOption &option, + std::vector &fileRes) override; int CreateFile(const std::string &name, const std::string &path, std::string &uri) override; int GetRoot(const std::string &devName, std::vector &fileRes) const override; private: diff --git a/services/src/client/ifms_client.h b/services/src/client/ifms_client.h index 99b656e235b885488f8b774b1ee2af146af8f99c..c5f660bb47de6861ebf4f0a1093e2b969c3fefea 100644 --- a/services/src/client/ifms_client.h +++ b/services/src/client/ifms_client.h @@ -15,7 +15,7 @@ #ifndef STORAGE_IFILE_MANAGER_CLIENT_H #define STORAGE_IFILE_MANAGER_CLIENT_H #include "file_info.h" - +#include "list_file_option.h" namespace OHOS { namespace FileManagerService { class IFmsClient { @@ -23,8 +23,8 @@ public: virtual ~IFmsClient() {} static IFmsClient *GetFmsInstance(); virtual int Mkdir(const std::string &name, const std::string &path) = 0; - virtual int ListFile(const std::string &type, const std::string &path, - int off, int count, std::vector &fileRes) = 0; + virtual int ListFile(const std::string &type, const std::string &path, const ListFileOption &option, + std::vector &fileRes) = 0; virtual int GetRoot(const std::string &devName, std::vector &fileRes) const = 0; virtual int CreateFile(const std::string &name, const std::string &path, std::string &uri) = 0; }; diff --git a/services/src/fileoper/external_storage_oper.cpp b/services/src/fileoper/external_storage_oper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..612f6d3ee78010c170ef8b415ac8f3ce287ed876 --- /dev/null +++ b/services/src/fileoper/external_storage_oper.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "external_storage_oper.h" + +#include + +#include "external_storage_utils.h" +#include "file_info.h" +#include "file_manager_service_def.h" +#include "file_manager_service_errno.h" +#include "log.h" + +namespace OHOS { +namespace FileManagerService { +int ExternalStorageOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const +{ + DEBUG_LOG("ExternalStorageOper::OperProcess"); + int errCode = SUCCESS; + switch (code) { + case Operation::LIST_FILE: { + ListFileOption option; + option.dev.name = data.ReadString(); + option.dev.path = data.ReadString(); + std::string type = data.ReadString(); + std::string path = data.ReadString(); + option.offset = data.ReadInt64(); + option.count = data.ReadInt64(); + errCode = this->ListFile(type, path, option, reply); + break; + } + case Operation::CREATE_FILE: { + std::string name = data.ReadString(); + std::string uri = data.ReadString(); + errCode = this->CreateFile(uri, name, reply); + break; + } + default: { + DEBUG_LOG("not valid code %{public}d.", code); + break; + } + } + return errCode; +} + +int ExternalStorageOper::CreateFile(const std::string &uri, const std::string &name, MessageParcel &reply) const +{ + DEBUG_LOG("ExternalStorageOper::CreateFile"); + return ExternalStorageUtils::DoCreateFile(uri, name, reply); +} + +int ExternalStorageOper::ListFile(const std::string &type, const std::string &uri, const ListFileOption &option, + MessageParcel &reply) const +{ + DEBUG_LOG("ExternalStorageOper::ListFile"); + return ExternalStorageUtils::DoListFile(type, uri, reply); +} +} // namespace FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/external_storage_oper.h b/services/src/fileoper/external_storage_oper.h new file mode 100644 index 0000000000000000000000000000000000000000..949571cd987e52491874ffd5bb5d9d833fbd6155 --- /dev/null +++ b/services/src/fileoper/external_storage_oper.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef STORAGE_SERIVCES_EXTERNAL_STORAGE_OPER_H +#define STORAGE_SERIVCES_EXTERNAL_STORAGE_OPER_H + +#include +#include "file_oper.h" +#include "list_file_option.h" +namespace OHOS { +namespace FileManagerService { +class ExternalStorageOper : public FileOper { +public: + ExternalStorageOper() = default; + virtual ~ExternalStorageOper() = default; + int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const override; +private: + int CreateFile(const std::string &uri, const std::string &name, MessageParcel &reply) const; + int ListFile(const std::string &type, const std::string &uri, const ListFileOption &option, + MessageParcel &reply) const; +}; +} // namespace FileManagerService +} // namespace OHOS +#endif // STORAGE_SERIVCES_EXTERNAL_STORAGE_OPER_H \ No newline at end of file diff --git a/services/src/fileoper/external_storage_utils.cpp b/services/src/fileoper/external_storage_utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d35567b67e47430d902085278cd92d20eb68d28c --- /dev/null +++ b/services/src/fileoper/external_storage_utils.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "external_storage_utils.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include "file_manager_service_def.h" +#include "file_manager_service_errno.h" +#include "log.h" +#include "utils.h" + +namespace OHOS { +namespace FileManagerService { +static bool GetFileInfo(const std::string &path, const std::string &name, FileInfo &fileInfo) +{ + std::string fullPath(""); + fullPath.append(path).append("/").append(name); + struct stat st; + if (lstat(fullPath.c_str(), &st) != 0) { + ERR_LOG("check file info fail."); + return false; + } + std::string fPath(path.c_str()); + std::string fName(name.c_str()); + + fileInfo.SetPath(fPath); + fileInfo.SetName(fName); + fileInfo.SetSize(st.st_size); + fileInfo.SetAddedTime(static_cast(st.st_ctim.tv_sec)); + fileInfo.SetModifiedTime(static_cast(st.st_mtim.tv_sec)); + std::string type = GetMimeType(fName); + fileInfo.SetType(type); + return true; +} + +static bool ConvertUriToAbsolutePath(const std::string &uri, std::string &path) +{ + // TODO convert uri to absolute path + path = "/data/media"; + return true; +} + +int ExternalStorageUtils::DoListFile(const std::string &type, const std::string &uri, MessageParcel &reply) +{ + DEBUG_LOG("ExternalStorageUtils::DoListFile"); + + std::string path; + if (!ConvertUriToAbsolutePath(uri, path)) { + ERR_LOG("invalid uri[%{public}s].", uri.c_str()); + return E_NOEXIST; + } + + DIR *dir = opendir(path.c_str()); + if (!dir) { + ERR_LOG("opendir path[%{public}s] fail.", path.c_str()); + return E_NOEXIST; + } + std::vector fileList; + for (struct dirent *ent = readdir(dir); ent != nullptr; ent = readdir(dir)) { + if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { + continue; + } + FileInfo fileInfo; + if (!GetFileInfo(path, ent->d_name, fileInfo)) { + continue; + } + fileList.push_back(fileInfo); + } + closedir(dir); + int64_t fileCount = fileList.size(); + reply.WriteInt64(fileCount); + if (fileCount == 0) { + return E_EMPTYFOLDER; + } + for (auto file : fileList) { + reply.WriteString(file.GetPath()); + reply.WriteString(file.GetName()); + reply.WriteString(file.GetType()); + reply.WriteInt64(file.GetSize()); + reply.WriteInt64(file.GetAddedTime()); + reply.WriteInt64(file.GetModifiedTime()); + } + return SUCCESS; +} + +int ExternalStorageUtils::DoCreateFile(const std::string &uri, const std::string &name, MessageParcel &reply) +{ + DEBUG_LOG("ExternalStorageUtils::DoCreateFile"); + + std::string path; + if (!ConvertUriToAbsolutePath(uri, path)) { + ERR_LOG("invalid uri[%{public}s].", uri.c_str()); + return E_NOEXIST; + } + + path.append("/").append(name); + if (access(path.c_str(), F_OK) == 0) { + ERR_LOG("target file[%{public}s] exist.", path.c_str()); + return E_CREATE_FAIL; + } + + int fd = open(path.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0771); + if (fd == -1) { + ERR_LOG("create file[%{public}s] fail.", path.c_str()); + return E_CREATE_FAIL; + } + close(fd); + + reply.WriteString(uri); + return SUCCESS; +} + +bool ExternalStorageUtils::PopFileInfo(FileInfo &fileInfo, MessageParcel &reply) +{ + std::string path; + std::string name; + std::string type; + int64_t size = 0; + int64_t at = 0; + int64_t mt = 0; + + reply.ReadString(path); + reply.ReadString(name); + reply.ReadString(type); + reply.ReadInt64(size); + reply.ReadInt64(at); + reply.ReadInt64(mt); + fileInfo = FileInfo(name, path, type); + fileInfo.SetSize(size); + fileInfo.SetAddedTime(at); + fileInfo.SetModifiedTime(mt); + return true; +} +} // namespace FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/external_storage_utils.h b/services/src/fileoper/external_storage_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..e5c17213ccb3635ee32d4d4be398f586cc56e056 --- /dev/null +++ b/services/src/fileoper/external_storage_utils.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H +#define STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H + +#include +#include + +#include "file_info.h" +#include "file_oper.h" +#include "list_file_option.h" + +namespace OHOS { +namespace FileManagerService { +class ExternalStorageUtils { +public: + ExternalStorageUtils(); + ~ExternalStorageUtils(); + static int DoListFile(const std::string &type, const std::string &uri, MessageParcel &reply); + static int DoCreateFile(const std::string &uri, const std::string &name, MessageParcel &reply); + static bool PopFileInfo(FileInfo &fileInfo, MessageParcel &reply); +}; +} // namespace FileManagerService +} // namespace OHOS +#endif // STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H \ No newline at end of file diff --git a/services/src/fileoper/list_file_option.h b/services/src/fileoper/list_file_option.h new file mode 100644 index 0000000000000000000000000000000000000000..78cfcb275c2ad176a6de32da2d707c553e790343 --- /dev/null +++ b/services/src/fileoper/list_file_option.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef STORAGE_SERVICES_DEV_INFO_H +#define STORAGE_SERVICES_DEV_INFO_H + +#include + +namespace OHOS { +namespace FileManagerService { +struct DevInfo { + std::string name{""}; + std::string path{""}; + + DevInfo() = default; + DevInfo(const std::string &nameIn, const std::string &pathIn) : + name(nameIn), path(pathIn) + {} + DevInfo(const DevInfo &dev) : + name(dev.name), path(dev.path) + {} +}; + +struct ListFileOption { + DevInfo dev; + int64_t offset{0}; + int64_t count{0}; + bool hasOpt{false}; + + ListFileOption() = default; + ListFileOption(DevInfo devIn, int64_t offsetIn, int64_t countIn, bool hasOptIn) : + dev(devIn), offset(offsetIn), count(countIn), hasOpt(hasOptIn) + {} + ListFileOption(const std::string &nameIn, const std::string &pathIn, + int64_t offsetIn, int64_t countIn, bool hasOptIn) : + dev(nameIn, pathIn), offset(offsetIn), count(countIn), hasOpt(hasOptIn) + {} +}; +} // namespace FileManagerService +} // namespace OHOS +#endif // STORAGE_SERVICES_DEV_INFO_H \ No newline at end of file diff --git a/services/src/fileoper/media_file_oper.cpp b/services/src/fileoper/media_file_oper.cpp index b858055b4fed13a84b0056a7ddc9fefbc51794f5..849ee0ab39117c88c4f360408ce0b0febfe2ce99 100644 --- a/services/src/fileoper/media_file_oper.cpp +++ b/services/src/fileoper/media_file_oper.cpp @@ -24,6 +24,7 @@ #include "iremote_broker.h" #include "iremote_proxy.h" #include "iremote_stub.h" +#include "list_file_option.h" #include "log.h" #include "media_data_ability_const.h" #include "media_file_utils.h" @@ -44,6 +45,9 @@ int MediaFileOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel break; } case Operation::LIST_FILE: { + DevInfo dev; + dev.name = data.ReadString(); + dev.path = data.ReadString(); string type = data.ReadString(); string path = data.ReadString(); int off = data.ReadInt32(); diff --git a/services/src/fileoper/media_file_utils.cpp b/services/src/fileoper/media_file_utils.cpp index 600ee20cdd8b2223ba13fce365d0972e675e1e7e..28f93efa25a8736f691e021d7aabdac69d7665f8 100644 --- a/services/src/fileoper/media_file_utils.cpp +++ b/services/src/fileoper/media_file_utils.cpp @@ -24,6 +24,7 @@ #include "media_data_ability_const.h" #include "medialibrary_data_ability.h" #include "log.h" +#include "utils.h" using namespace std; namespace OHOS { @@ -83,26 +84,6 @@ bool GetPathID(const string &uriPath, string &index) return true; } -int GetMediaType(const string &name) -{ - int mediaType = Media::MediaAsset::GetMediaType(name); - if (FILE_MIME_TYPE_MAPS.count(mediaType) == 0) { - ERR_LOG("invalid mediaType %{public}d", mediaType); - return FILE_MEDIA_TYPE; - } - return mediaType; -} - -string GetMimeType(const string &name) -{ - int mediaType = GetMediaType(name); - if (FILE_MIME_TYPE_MAPS.count(mediaType) == 0) { - ERR_LOG("invalid mediaType %{public}d", mediaType); - return FILE_MIME_TYPE; - } - return FILE_MIME_TYPE_MAPS.at(mediaType); -} - bool GetPathFromAlbumPath(const string &albumUri, string &path) { string id; diff --git a/services/src/fileoper/oper_factory.cpp b/services/src/fileoper/oper_factory.cpp index 23f25ceda7a6ca854d6f3f7232f111297fcaf897..e0b8ea24e41297c2f9ffd3c512e09c6c5d1548a1 100644 --- a/services/src/fileoper/oper_factory.cpp +++ b/services/src/fileoper/oper_factory.cpp @@ -15,6 +15,7 @@ #include "oper_factory.h" +#include "external_storage_oper.h" #include "file_manager_service_def.h" #include "file_oper.h" #include "log.h" @@ -33,8 +34,7 @@ unique_ptr OperFactory::GetFileOper(int equipmentId) break; } case Equipment::EXTERNAL_STORAGE: { - DEBUG_LOG("FileOper exter %{public}d %{public}d.", Equipment::EXTERNAL_STORAGE, equipmentId); - // do Exteranl storage process; + fp = make_unique(); break; } default: { diff --git a/services/src/fileoper/utils.cpp b/services/src/fileoper/utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8dfe0a9e010f8992ae760a35f4d17f1544bfb73f --- /dev/null +++ b/services/src/fileoper/utils.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "utils.h" + +#include + +#include "file_manager_service_def.h" +#include "file_manager_service_errno.h" +#include "log.h" +#include "media_asset.h" + +namespace OHOS { +namespace FileManagerService { +int GetMediaType(const std::string &name) +{ + int mediaType = Media::MediaAsset::GetMediaType(name); + if (FILE_MIME_TYPE_MAPS.count(mediaType) == 0) { + ERR_LOG("invalid mediaType %{public}d", mediaType); + return FILE_MEDIA_TYPE; + } + return mediaType; +} + +std::string GetMimeType(const std::string &name) +{ + int mediaType = GetMediaType(name); + if (FILE_MIME_TYPE_MAPS.count(mediaType) == 0) { + ERR_LOG("invalid mediaType %{public}d", mediaType); + return FILE_MIME_TYPE; + } + return FILE_MIME_TYPE_MAPS.at(mediaType); +} +} // namespace FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/utils.h b/services/src/fileoper/utils.h new file mode 100644 index 0000000000000000000000000000000000000000..8ca0b13b7a7b438c63d4009a69d696c872152c5e --- /dev/null +++ b/services/src/fileoper/utils.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef STORAGE_SERIVCES_FILE_OPER_UTILS_H +#define STORAGE_SERIVCES_FILE_OPER_UTILS_H + +#include + +namespace OHOS { +namespace FileManagerService { +int GetMediaType(const std::string &name); +std::string GetMimeType(const std::string &name); +} // namespace FileManagerService +} // namespace OHOS +#endif // STORAGE_SERIVCES_FILE_OPER_UTILS_H \ No newline at end of file