diff --git a/bundle.json b/bundle.json index 43189cb4d32b633aef07bd480e00516becb25938..19952c979e4b155e18c2658572b07fb323c39177 100644 --- a/bundle.json +++ b/bundle.json @@ -33,15 +33,13 @@ }, "build": { "sub_component": [ - "//foundation/filemanagement/user_file_service/services:fms", - "//foundation/filemanagement/user_file_service/services/sa_profile:filemanager_service_sa_profile", - "//foundation/filemanagement/user_file_service/interfaces/kits/js:filemanager", + "//foundation/filemanagement/user_file_service/services:user_file_managers", "//foundation/filemanagement/user_file_service/frameworks/innerkits:frameworks_innerkits", "//foundation/filemanagement/user_file_service/interfaces/kits/napi/file_access_module:fileaccess", "//foundation/filemanagement/user_file_service/interfaces/kits/napi/file_access_ext_ability:fileaccessextensionability_napi", "//foundation/filemanagement/user_file_service/interfaces/kits/napi/file_extension_info_module:fileextensioninfo" ], - "test": [ + "test": [ "//foundation/filemanagement/user_file_service/frameworks/innerkits/file_access/test:user_file_service_test" ] } diff --git a/frameworks/innerkits/file_access/include/file_access_helper.h b/frameworks/innerkits/file_access/include/file_access_helper.h index 23b2a1521ffd009572860ec99b7def4458e36fba..6805823fc39601366ec069b63d4f48e9936c453c 100644 --- a/frameworks/innerkits/file_access/include/file_access_helper.h +++ b/frameworks/innerkits/file_access/include/file_access_helper.h @@ -94,8 +94,8 @@ private: sptr token_ = nullptr; std::unordered_map> cMap_; - static std::unordered_map wantsMap_; - static std::string GetKeyOfWantsMap(const AAFwk::Want &want); + static std::vector wants_; + static std::string GetKeyOfWants(const AAFwk::Want &want); sptr callerDeathRecipient_ = nullptr; diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index df86cb65ab9ade3e96843ae193b64cb08a26fd1f..dc0be0dc2d35f7dc405a595b1221073dcd9bdc82 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -36,7 +36,7 @@ namespace { static const int32_t WRITE = 1; static const int32_t WRITE_READ = 2; } -std::unordered_map FileAccessHelper::wantsMap_; +std::vector FileAccessHelper::wants_; static int GetUserId() { @@ -151,17 +151,17 @@ std::shared_ptr FileAccessHelper::GetConnectInfo(const AAFwk::Want return nullptr; } -std::string FileAccessHelper::GetKeyOfWantsMap(const AAFwk::Want &want) +std::string FileAccessHelper::GetKeyOfWants(const AAFwk::Want &want) { - for (auto iter = FileAccessHelper::wantsMap_.begin(); iter != FileAccessHelper::wantsMap_.end(); ++iter) { - auto element = iter->second.GetElement(); - auto elementTmp = want.GetElement(); + auto elementTmp = want.GetElement(); + for (auto iter = FileAccessHelper::wants_.begin(); iter != FileAccessHelper::wants_.end(); ++iter) { + auto element = iter->GetElement(); if (element.GetBundleName() == elementTmp.GetBundleName() && element.GetAbilityName() == elementTmp.GetAbilityName()) { - return iter->first; + return element.GetBundleName(); } } - HILOG_ERROR("GetKeyOfWantsMap called return nullptr"); + HILOG_ERROR("GetKeyOfWants called return nullptr"); return ""; } @@ -195,7 +195,7 @@ std::shared_ptr FileAccessHelper::Creator( } sptr bm = FileAccessHelper::GetBundleMgrProxy(); - FileAccessHelper::wantsMap_.clear(); + FileAccessHelper::wants_.clear(); std::unordered_map> cMap; std::vector extensionInfos; bool ret = bm->QueryExtensionAbilityInfos( @@ -229,7 +229,7 @@ std::shared_ptr FileAccessHelper::Creator( HILOG_ERROR("Creator, connectInfo == nullptr"); return nullptr; } - FileAccessHelper::wantsMap_.insert(std::pair(extensionInfos[i].bundleName, wantTem)); + FileAccessHelper::wants_.push_back(wantTem); connectInfo->want = wantTem; connectInfo->fileAccessExtConnection = fileAccessExtConnection; @@ -257,6 +257,11 @@ std::shared_ptr FileAccessHelper::Creator( return nullptr; } + if (GetRegisteredFileAccessExtAbilityInfo(FileAccessHelper::wants_) != ERR_OK) { + HILOG_ERROR("GetRegisteredFileAccessExtAbilityInfo failed"); + return nullptr; + } + std::unordered_map> cMap; for (size_t i = 0; i < wants.size(); i++) { sptr fileAccessExtConnection = new(std::nothrow) FileAccessExtConnection(); @@ -283,7 +288,11 @@ std::shared_ptr FileAccessHelper::Creator( connectInfo->want = wants[i]; connectInfo->fileAccessExtConnection = fileAccessExtConnection; - string bundleName = FileAccessHelper::GetKeyOfWantsMap(wants[i]); + string bundleName = FileAccessHelper::GetKeyOfWants(wants[i]); + if (bundleName.length() == 0) { + HILOG_ERROR("Creator GetKeyOfWants bundleName not found"); + return nullptr; + } cMap.insert(std::pair>(bundleName, connectInfo)); } FileAccessHelper *ptrFileAccessHelper = new (std::nothrow) FileAccessHelper(context, cMap); @@ -308,6 +317,11 @@ std::shared_ptr FileAccessHelper::Creator(const sptr> cMap; for (size_t i = 0; i < wants.size(); i++) { sptr fileAccessExtConnection = new(std::nothrow) FileAccessExtConnection(); @@ -334,7 +348,11 @@ std::shared_ptr FileAccessHelper::Creator(const sptrwant = wants[i]; connectInfo->fileAccessExtConnection = fileAccessExtConnection; - string bundleName = FileAccessHelper::GetKeyOfWantsMap(wants[i]); + string bundleName = FileAccessHelper::GetKeyOfWants(wants[i]); + if (bundleName.length() == 0) { + HILOG_ERROR("Creator GetKeyOfWants bundleName not found"); + return nullptr; + } cMap.insert(std::pair>(bundleName, connectInfo)); } FileAccessHelper *ptrFileAccessHelper = new (std::nothrow) FileAccessHelper(token, cMap); @@ -355,7 +373,7 @@ bool FileAccessHelper::Release() } cMap_.clear(); token_ = nullptr; - FileAccessHelper::wantsMap_.clear(); + FileAccessHelper::wants_.clear(); return true; } @@ -702,11 +720,11 @@ int FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(std::vector(extensionInfos[i].bundleName, want)); + FileAccessHelper::wants_.push_back(want); wantVec.push_back(want); } diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn deleted file mode 100644 index 1fd03d256a842e45a86d911f835cf34f164d50f7..0000000000000000000000000000000000000000 --- a/interfaces/kits/js/BUILD.gn +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) 2021-2022 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. - -import("//build/ohos.gni") -FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" - -ohos_shared_library("filemanager") { - subsystem_name = "filemanagement" - part_name = "user_file_service" - - relative_install_dir = "module" - - include_dirs = [ - "//third_party/node/src", - "//foundation/arkui/napi/interfaces/kits", - "//commonlibrary/c_utils/base/include", - "//third_party/libuv/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/common/napi/n_async", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/common/napi", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/common", - "//foundation/multimedia/media_library/interfaces/inner_api/media_library_helper/include", - "//foundation/multimedia/media_library/frameworks/utils/include", - ] - - sources = [ - "src/file_manager_napi.cpp", - "src/module.cpp", - ] - - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/arkui/napi:ace_napi", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js:fileio", - ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - external_deps = [ - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - ] -} diff --git a/interfaces/kits/js/src/file_manager_napi.cpp b/interfaces/kits/js/src/file_manager_napi.cpp deleted file mode 100644 index fd7acaa98efac2bbd0db80ec65cc02f6cd98ffa8..0000000000000000000000000000000000000000 --- a/interfaces/kits/js/src/file_manager_napi.cpp +++ /dev/null @@ -1,412 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "file_manager_napi.h" - -#include -#include -#include -#include - -#include "file_manager_napi_def.h" -#include "file_manager_proxy.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "ifms_client.h" -#include "log.h" -namespace OHOS { -namespace FileManagerService { -using namespace std; -using namespace DistributedFS; -struct AsyncFileInfoArg { - NRef ref_; - vector> fileRes_; - explicit AsyncFileInfoArg(NVal ref) : ref_(ref), fileRes_() {}; - ~AsyncFileInfoArg() = default; -}; - -struct AsyncUriArg { - NRef ref_; - string uri_; - explicit AsyncUriArg(NVal ref) : ref_(ref), uri_() {}; - ~AsyncUriArg() = default; -}; - -tuple FileManagerNapi::GetFmsClient() -{ - if (fmsClient_ == nullptr) { - fmsClient_ = IFmsClient::GetFmsInstance(); - } - if (fmsClient_ == nullptr) { - ERR_LOG("fms get instance fails"); - return make_tuple(false, nullptr); - } else { - return make_tuple(true, fmsClient_); - } -} - -UniError DealWithErrno(int err) -{ - unordered_map errMap = { - {FAIL, ESRCH}, - {E_CREATE_FAIL, EPERM}, - {E_NOEXIST, ENOENT}, - {E_EMPTYFOLDER, ENOTDIR}, - {SUCCESS, ERRNO_NOERR}, - }; - if (errMap.count(err) == 0) { - ERR_LOG("unhandler err number %{public}d", err); - return UniError(EACCES); - } else { - return UniError(errMap[err]); - } -} - -bool GetDevInfoArg(const NVal &prop, DevInfo &dev) -{ - if (prop.HasProp("name")) { - bool ret = false; - unique_ptr name; - tie(ret, name, ignore) = prop.GetProp("name").ToUTF8String(); - if (!ret) { - return false; - } - dev.SetName(std::string(name.get())); - } - return true; -} - -tuple, unique_ptr, CmdOptions> GetCreateFileArgs(napi_env env, NFuncArg &funcArg) -{ - bool succ = false; - unique_ptr path; - unique_ptr fileName; - CmdOptions option("local", "", 0, MAX_NUM, false); - tie(succ, path, ignore) = NVal(env, funcArg[CreateFileArgs::CF_PATH]).ToUTF8String(); - if (!succ) { - return {false, nullptr, nullptr, option}; - } - tie(succ, fileName, ignore) = NVal(env, funcArg[CreateFileArgs::CF_FILENAME]).ToUTF8String(); - if (!succ) { - return {false, nullptr, nullptr, option}; - } - - if (funcArg.GetArgc() < CreateFileArgs::CF_OPTION) { - return {false, nullptr, nullptr, option}; - } - - NVal op(env, NVal(env, funcArg[CreateFileArgs::CF_OPTION]).val_); - if (op.TypeIs(napi_function)) { - return {true, move(path), move(fileName), option}; - } - - option.SetHasOpt(true); - if (!op.HasProp("dev")) { - return {true, move(path), move(fileName), option}; - } - - NVal prop(op.GetProp("dev")); - DevInfo dev("local", ""); - if (!GetDevInfoArg(prop, dev)) { - ERR_LOG("CreateFile func get dev para fails"); - option.SetDevInfo(dev); - return {false, nullptr, nullptr, option}; - } - - option.SetDevInfo(dev); - return {true, move(path), move(fileName), option}; -} - -napi_value FileManagerNapi::CreateFile(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(CREATE_FILE_PARA_MIN, CREATE_FILE_PARA_MAX)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - bool succ = false; - unique_ptr path; - unique_ptr fileName; - CmdOptions option; - tie(succ, path, fileName, option) = GetCreateFileArgs(env, funcArg); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "CreateFile func get args fails"); - return nullptr; - } - auto arg = make_shared(NVal(env, funcArg.GetThisVar())); - auto cbExec = [arg, path = string(path.get()), fileName = string(fileName.get()), option = option] - (napi_env env) -> UniError { - IFmsClient* client = nullptr; - bool succ = false; - tie(succ, client) = GetFmsClient(); - if (!succ) { - return UniError(ESRCH); - } - string uri = ""; - int err = client->CreateFile(path, fileName, option, arg->uri_); - return DealWithErrno(err); - }; - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal::CreateUTF8String(env, arg->uri_); - } - }; - string procedureName = "CreateFile"; - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == CREATE_FILE_PARA_MIN || (argc != CREATE_FILE_PARA_MAX && option.GetHasOpt())) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = (!option.GetHasOpt() ? - CreateFileArgs::CF_CALLBACK_WITHOUT_OP : CreateFileArgs::CF_CALLBACK_WITH_OP); - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } -} - -static bool CreateFileArray(napi_env env, shared_ptr arg) -{ - for (size_t i = 0; i < arg->fileRes_.size(); i++) { - NVal obj = NVal::CreateObject(env); - shared_ptr res = arg->fileRes_[i]; - if (res == nullptr) { - ERR_LOG("inner error, lack of memory, file count %{public}zu", arg->fileRes_.size()); - return false; - } - obj.AddProp("name", NVal::CreateUTF8String(env, res->GetName()).val_); - obj.AddProp("path", NVal::CreateUTF8String(env, res->GetPath()).val_); - obj.AddProp("type", NVal::CreateUTF8String(env, res->GetType()).val_); - obj.AddProp("size", NVal::CreateInt64(env, res->GetSize()).val_); - obj.AddProp("added_time", NVal::CreateInt64(env, res->GetAddedTime()).val_); - obj.AddProp("modified_time", NVal::CreateInt64(env, res->GetModifiedTime()).val_); - napi_set_property(env, arg->ref_.Deref(env).val_, NVal::CreateInt32(env, i).val_, obj.val_); - } - return true; -} - -bool GetRootArgs(napi_env env, NFuncArg &funcArg, CmdOptions &option) -{ - NVal op(env, NVal(env, funcArg[GetRootArgs::GR_OPTION]).val_); - if (op.TypeIs(napi_function)) { - return true; - } - - option.SetHasOpt(true); - if (!op.HasProp("dev")) { - return true; - } - - NVal prop(op.GetProp("dev")); - DevInfo dev("local", ""); - if (!GetDevInfoArg(prop, dev)) { - option.SetDevInfo(dev); - return false; - } - - option.SetDevInfo(dev); - return true; -} - -napi_value FileManagerNapi::GetRoot(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(GET_ROOT_PARA_MIN, GET_ROOT_PARA_MAX)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - CmdOptions option("local", "", 0, MAX_NUM, false); - if (funcArg.GetArgc() != 0) { - if (!GetRootArgs(env, funcArg, option)) { - UniError(EINVAL).ThrowErr(env, "GetRoot func get dev para fails"); - return nullptr; - } - } - - napi_value fileArr; - napi_create_array(env, &fileArr); - auto arg = make_shared(NVal(env, fileArr)); - auto cbExec = [option = option, arg] (napi_env env) -> UniError { - IFmsClient* client = nullptr; - bool succ = false; - tie(succ, client) = GetFmsClient(); - if (!succ) { - return UniError(ESRCH); - } - int err = client->GetRoot(option, arg->fileRes_); - return DealWithErrno(err); - }; - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { - if (!err && !CreateFileArray(env, arg)) { - err = UniError(ENOMEM); - } - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal(env, arg->ref_.Deref(env).val_); - } - }; - string procedureName = "GetRoot"; - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == GET_ROOT_PARA_MIN || (argc != GET_ROOT_PARA_MAX && option.GetHasOpt())) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = (!option.GetHasOpt() ? GetRootArgs::GR_CALLBACK_WITHOUT_OP : GetRootArgs::GR_CALLBACK_WITH_OP); - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } -} - -bool GetListFileOption(const NVal &argv, CmdOptions &option) -{ - bool ret = false; - if (argv.HasProp("dev")) { - NVal prop(argv.GetProp("dev")); - DevInfo dev("local", ""); - if (!GetDevInfoArg(prop, dev)) { - option.SetDevInfo(dev); - return false; - } - option.SetDevInfo(dev); - } - if (argv.HasProp("offset")) { - int64_t offset; - tie(ret, offset) = argv.GetProp("offset").ToInt64(); - if (!ret) { - ERR_LOG("ListFileArgs LF_OPTION offset para fails"); - return false; - } - option.SetOffset(offset); - } - if (argv.HasProp("count")) { - int64_t count; - tie(ret, count) = argv.GetProp("count").ToInt64(); - if (!ret) { - ERR_LOG("ListFileArgs LF_OPTION count para fails"); - return false; - } - option.setCount(count); - } - return true; -} - -tuple, unique_ptr, CmdOptions> GetListFileArg( - napi_env env, NFuncArg &funcArg) -{ - bool succ = false; - unique_ptr path; - unique_ptr type; - CmdOptions option("local", "", 0, MAX_NUM, false); - tie(succ, path, ignore) = NVal(env, funcArg[ListFileArgs::LF_PATH]).ToUTF8String(); - if (!succ) { - ERR_LOG("ListFileArgs LF_PATH para fails"); - 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.TypeIs(napi_function)) { - return {true, move(type), move(path), option}; - } - option.SetHasOpt(true); - if (!GetListFileOption(op, option)) { - return {false, nullptr, nullptr, option}; - } - return {true, move(type), move(path), option}; -} - -napi_value FileManagerNapi::ListFile(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(LIST_FILE_PARA_MIN, LIST_FILE_PARA_MAX)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - bool succ = false; - unique_ptr type; - unique_ptr path; - CmdOptions option; - tie(succ, type, path, option) = GetListFileArg(env, funcArg); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Get arguments fails"); - return nullptr; - } - napi_value fileArr; - napi_create_array(env, &fileArr); - auto arg = make_shared(NVal(env, fileArr)); - auto cbExec = [type = string(type.get()), path = string(path.get()), option, arg](napi_env env) -> UniError { - IFmsClient* client = nullptr; - bool succ = false; - tie(succ, client) = GetFmsClient(); - if (!succ) { - return UniError(ESRCH); - } - int err = client->ListFile(type, path, option, arg->fileRes_); - return DealWithErrno(err); - }; - - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { - if (!err && !CreateFileArray(env, arg)) { - err = UniError(ENOMEM); - } - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal(env, arg->ref_.Deref(env).val_); - } - }; - string procedureName = "ListFile"; - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == LIST_FILE_PARA_MIN || (argc != LIST_FILE_PARA_MAX && option.GetHasOpt())) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = ((!option.GetHasOpt()) ? 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_; - } -} - -napi_value FileManagerNapi::Mkdir(napi_env env, napi_callback_info info) -{ - return NVal::CreateUndefined(env).val_; -} - -bool FileManagerNapi::Export() -{ - return exports_.AddProp( { - NVal::DeclareNapiFunction("listFile", ListFile), - NVal::DeclareNapiFunction("createFile", CreateFile), - NVal::DeclareNapiFunction("getRoot", GetRoot), - }); -} - -string FileManagerNapi::GetClassName() -{ - return FileManagerNapi::className_; -} - -FileManagerNapi::FileManagerNapi(napi_env env, napi_value exports) : NExporter(env, exports) {} - -FileManagerNapi::~FileManagerNapi() {} -} // namespace FileManagerService -} // namespace OHOS diff --git a/interfaces/kits/js/src/file_manager_napi.h b/interfaces/kits/js/src/file_manager_napi.h deleted file mode 100644 index 8b06b57af5786ed8d4cf9c04eab819839b870ec9..0000000000000000000000000000000000000000 --- a/interfaces/kits/js/src/file_manager_napi.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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_FILE_MANAGER_NAPI_H -#define STORAGE_FILE_MANAGER_NAPI_H - -#include "ifms_client.h" -#include "n_exporter.h" - -namespace OHOS { -namespace FileManagerService { -class FileManagerNapi final : public DistributedFS::NExporter { -public: - static napi_value CreateFile(napi_env env, napi_callback_info info); - static napi_value ListFile(napi_env env, napi_callback_info info); - static napi_value Mkdir(napi_env env, napi_callback_info info); - static napi_value GetRoot(napi_env env, napi_callback_info info); - bool Export() override; - std::string GetClassName() override; - static std::tuple GetFmsClient(); - FileManagerNapi(napi_env env, napi_value exports); - ~FileManagerNapi() override; -private: - inline static const std::string className_ = "__properities__"; - inline static IFmsClient* fmsClient_ = nullptr; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_NAPI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/file_manager_napi_def.h b/interfaces/kits/js/src/file_manager_napi_def.h deleted file mode 100644 index 05d753484fda359baf38733764dac37cc666e9fc..0000000000000000000000000000000000000000 --- a/interfaces/kits/js/src/file_manager_napi_def.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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_FILE_MANAGER_NAPI_DEF_H -#define STORAGE_FILE_MANAGER_NAPI_DEF_H -#include "n_async_work_callback.h" -#include "n_async_work_promise.h" -#include "n_func_arg.h" -#include "uni_error.h" - -namespace OHOS { -namespace FileManagerService { -enum CreateFileArgs { - CF_PATH = 0, - CF_FILENAME = 1, - CF_OPTION = 2, - CF_CALLBACK_WITHOUT_OP = 2, - CF_CALLBACK_WITH_OP = 3, -}; - -enum GetRootArgs { - GR_OPTION = 0, - GR_CALLBACK_WITHOUT_OP = 0, - GR_CALLBACK_WITH_OP = 1, -}; - -enum ListFileArgs { - LF_PATH = 0, - LF_TYPE = 1, - 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 = 2; -constexpr int GET_ROOT_PARA_MAX = 2; -constexpr int GET_ROOT_PARA_MIN = 0; -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/interfaces/kits/js/src/module.cpp b/interfaces/kits/js/src/module.cpp deleted file mode 100644 index 5c5b7a2c310e6e20d3bf722a7f493d398845c982..0000000000000000000000000000000000000000 --- a/interfaces/kits/js/src/module.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 -#include - -#include "file_manager_napi.h" -#include "log.h" - -using namespace std; - -namespace OHOS { -namespace FileManagerService { -using namespace DistributedFS; -static napi_value Export(napi_env env, napi_value exports) -{ - std::vector> products; - products.emplace_back(make_unique(env, exports)); - - for (auto &&product : products) { - if (!product->Export()) { - ERR_LOG("INNER BUG. Failed to export class %{public}s for module filemanager", - product->GetClassName().c_str()); - return nullptr; - } - } - return exports; -} - -NAPI_MODULE(filemanager, Export) -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/BUILD.gn b/services/BUILD.gn index 325562d79d926cdb87ec24ddf6963608ad97b530..9f2c88e9369de53ccaf29338b8faa9e9855bc923 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -13,74 +13,9 @@ import("//build/ohos.gni") import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") -FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" -group("fms") { - deps = [ - ":external_file_manager_hap", - ":fms_server", - ":fms_service.cfg", - ] -} - -ohos_prebuilt_etc("fms_service.cfg") { - source = "etc/fms_service.cfg" - relative_install_dir = "init" - subsystem_name = "filemanagement" - part_name = "user_file_service" -} - -ohos_shared_library("fms_server") { - subsystem_name = "filemanagement" - part_name = "user_file_service" - - include_dirs = [ - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "$FMS_BASE_DIR/include/fileoper", - "//base/hiviewdfx/hilog/interfaces/native/innerkits/include/hilog", - "//foundation/filemanagement/storage_service/services/storage_manager/include", - "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native", - "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/appdatafwk/include", - "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb/include", - ] - - sources = [ - "src/client/file_manager_proxy.cpp", - "src/fileoper/file_info.cpp", - "src/fileoper/media_file_oper.cpp", - "src/fileoper/media_file_utils.cpp", - "src/fileoper/oper_factory.cpp", - "src/server/file_manager_service.cpp", - "src/server/file_manager_service_stub.cpp", - ] - - deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/multimedia/media_library/frameworks/innerkitsimpl/media_library_helper:media_library", - "//foundation/multimedia/media_library/frameworks/innerkitsimpl/medialibrary_data_extension:medialibrary_data_extension", - ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_base:zuri", - "ability_runtime:wantagent_innerkits", - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "data_share:datashare_common", - "data_share:datashare_consumer", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] +group("user_file_managers") { + deps = [ ":external_file_manager_hap" ] } ohos_hap("external_file_manager_hap") { diff --git a/services/etc/fms_service.cfg b/services/etc/fms_service.cfg deleted file mode 100644 index 6a6f470be10d73de8f77240402347fd5fbb63302..0000000000000000000000000000000000000000 --- a/services/etc/fms_service.cfg +++ /dev/null @@ -1,10 +0,0 @@ -{ - "services" : [{ - "name" : "fms_service", - "path" : ["/system/bin/sa_main", "/system/profile/fms_service.xml"], - "uid" : "1006", - "gid" : ["system", "shell"], - "secon" : "u:r:fms_service:s0" - } - ] -} diff --git a/services/etc/fms_service.rc b/services/etc/fms_service.rc deleted file mode 100644 index 41f1e4d141e30319b75b0a9bfcf327649c68a687..0000000000000000000000000000000000000000 --- a/services/etc/fms_service.rc +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -service fms_service /system/bin/sa_main /system/profile/fms_service.xml - class z_core - seclabel u:r:audiodistributedservice:s0 - -on boot - start fms_service - diff --git a/services/include/file_manager_service_def.h b/services/include/file_manager_service_def.h deleted file mode 100644 index 02b63dcfbde4e22d01dd8d6cc6edfd41c05730ff..0000000000000000000000000000000000000000 --- a/services/include/file_manager_service_def.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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_FILE_MANAGER_SERVICE_DEF_H -#define STORAGE_FILE_MANAGER_SERVICE_DEF_H - -#include -#include -#include -#include "medialibrary_db_const.h" -#include "medialibrary_type_const.h" - -namespace OHOS { -namespace FileManagerService { -enum Operation { - GET_ROOT, - MAKE_DIR, - LIST_FILE, - CREATE_FILE -}; - -enum Equipment { - INTERNAL_STORAGE, - EXTERNAL_STORAGE -}; - -enum VolumeState { - UNMOUNTED = 0, - CHECKING, - MOUNTED, - EJECTING -}; -constexpr int64_t MAX_NUM = 200; -constexpr int32_t CODE_MASK = 0xff; -constexpr int32_t EQUIPMENT_SHIFT = 16; - -const std::string FISRT_LEVEL_ALBUM = "dataability:///album"; -// use to find out album in the root dir -const std::string RELATIVE_ROOT_PATH = ""; - -const std::string MEDIA_ROOT_PATH = "/storage/media/local/files"; -const std::string IMAGE_ROOT_NAME = "image_album"; -const std::string VIDEO_ROOT_NAME = "video_album"; -const std::string AUDIO_ROOT_NAME = "audio_album"; -const std::string FILE_ROOT_NAME = "file_folder"; - -const std::string ALBUM_TYPE = "album"; -const std::string FILE_MIME_TYPE = "file/*"; - -const std::string EXTERNAL_STORAGE_URI = "dataability:///external_storage"; -const std::string MOUNT_POINT_ROOT = "/mnt/"; - -constexpr int FILE_MEDIA_TYPE = Media::MediaType::MEDIA_TYPE_FILE; -constexpr int RESULTSET_EMPTY = 0; -constexpr int RESULTSET_ONE = 1; - -const std::unordered_map FILE_MIME_TYPE_MAPS = { - {Media::MediaType::MEDIA_TYPE_IMAGE, "image/*"}, - {Media::MediaType::MEDIA_TYPE_AUDIO, "audio/*"}, - {Media::MediaType::MEDIA_TYPE_VIDEO, "video/*"}, - {Media::MediaType::MEDIA_TYPE_FILE, "file/*"}, - {Media::MediaType::MEDIA_TYPE_ALBUM, "file/*"}, -}; - -const std::unordered_map MEDIA_TYPE_FOLDER_MAPS = { - {Media::MediaType::MEDIA_TYPE_IMAGE, "Pictures/"}, - {Media::MediaType::MEDIA_TYPE_AUDIO, "Audios/"}, - {Media::MediaType::MEDIA_TYPE_VIDEO, "Videos/"}, - {Media::MediaType::MEDIA_TYPE_FILE, "Documents/"}, -}; - -const std::unordered_map MEDIA_TYPE_URI_MAPS = { - {Media::MediaType::MEDIA_TYPE_IMAGE, Media::MEDIALIBRARY_IMAGE_URI}, - {Media::MediaType::MEDIA_TYPE_AUDIO, Media::MEDIALIBRARY_AUDIO_URI}, - {Media::MediaType::MEDIA_TYPE_VIDEO, Media::MEDIALIBRARY_VIDEO_URI}, - {Media::MediaType::MEDIA_TYPE_FILE, Media::MEDIALIBRARY_FILE_URI}, -}; - -#define GET_COLUMN_INDEX_FROM_NAME(result, name, index) \ - do { \ - if (result->GetColumnIndex(name, index) != NativeRdb::E_OK) { \ - ERR_LOG("NativeRdb gets %{public}s index fail", name.c_str()); \ - return false; \ - } \ - } while (0) -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_SERVICE_DEF_H diff --git a/services/include/file_manager_service_errno.h b/services/include/file_manager_service_errno.h deleted file mode 100644 index dcc22b5fc7bbfcddd4a7f84fcbcdd10ed83efcb4..0000000000000000000000000000000000000000 --- a/services/include/file_manager_service_errno.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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_INCLUDE_ERRNO_H -#define STORAGE_SERVICES_INCLUDE_ERRNO_H -namespace OHOS { -namespace FileManagerService { -constexpr int32_t SUCCESS = 0; -constexpr int32_t FAIL = -1; // internal Error -constexpr int32_t E_NOEXIST = -2; // file not exist -constexpr int32_t E_EMPTYFOLDER = -3; // folder empty -constexpr int32_t E_INVALID_OPERCODE = -4; // not valid oper code -constexpr int32_t E_CREATE_FAIL = -5; // create file fail -constexpr int32_t E_INVALID_FILE_NUMBER = -6; // file count or offset invalid -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_INCLUDE_ERRNO_H diff --git a/services/include/log.h b/services/include/log.h deleted file mode 100644 index db1322ef993ba3509af8465817d38da0dbf09c2f..0000000000000000000000000000000000000000 --- a/services/include/log.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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_SERIVCE_INCLUDE_LOG_H -#define STORAGE_SERIVCE_INCLUDE_LOG_H - -#include -#include "hilog/log.h" - -#undef LOG_DOMAIN -#undef LOG_TAG -#define LOG_DOMAIN 0xD00430A -#define LOG_TAG "FileManagerment:FMS" - -#define DEBUG_LOG(fmt, args...) \ - HILOG_DEBUG(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define ERR_LOG(fmt, args...) \ - HILOG_ERROR(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define WARNING_LOG(fmt, args...) \ - HILOG_WARN(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define INFO_LOG(fmt, args...) \ - HILOG_INFO(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define FATAL_LOG(fmt, args...) \ - HILOG_FATAL(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#endif // STORAGE_SERIVCE_INCLUDE_LOG_H diff --git a/services/include/storage_manager_inf.h b/services/include/storage_manager_inf.h deleted file mode 100644 index 4f294f16092a418c3a42a8b3351ea262d08fce4f..0000000000000000000000000000000000000000 --- a/services/include/storage_manager_inf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021-2022 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_MANAGER_INTERFACE_H -#define STORAGE_MANAGER_INTERFACE_H -#include -#include -#include "ipc/storage_manager_proxy.h" -#include "ipc/storage_manager.h" -#include "istorage_manager.h" -namespace OHOS { -namespace FileManagerService { -class StorageManagerInf { -public: - StorageManagerInf() = default; - ~StorageManagerInf() = default; - static int Connect(); - static std::vector GetAllVolumes(); - static bool GetMountedVolumes(std::vector &vecRootPath); - static bool StoragePathValidCheck(const std::string &path); -private: - inline static sptr storageManager_; -}; -} // FileManagerService -} // OHOS -#endif // STORAGE_MANAGER_INTERFACE_H \ No newline at end of file diff --git a/services/sa_profile/5010.xml b/services/sa_profile/5010.xml deleted file mode 100644 index 32eb4cf609b26a92bec615b0e49955316fdc9d58..0000000000000000000000000000000000000000 --- a/services/sa_profile/5010.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - fms_service - - libfms_server.z.so - - - 5010 - libfms_server.z.so - false - false - 1 - - diff --git a/services/sa_profile/BUILD.gn b/services/sa_profile/BUILD.gn deleted file mode 100644 index 16b9a8ba94688faed169197bd470cd5b5da7aea6..0000000000000000000000000000000000000000 --- a/services/sa_profile/BUILD.gn +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -import("//build/ohos/sa_profile/sa_profile.gni") - -ohos_sa_profile("filemanager_service_sa_profile") { - sources = [ "5010.xml" ] - - part_name = "user_file_service" -} diff --git a/services/src/client/file_manager_proxy.cpp b/services/src/client/file_manager_proxy.cpp deleted file mode 100644 index 0c15b609f7cdeb7e79115a1c865568ade14a77d6..0000000000000000000000000000000000000000 --- a/services/src/client/file_manager_proxy.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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 "file_manager_proxy.h" - -#include "cmd_response.h" -#include "file_info.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "file_manager_service_stub.h" -#include "log.h" -#include "media_file_utils.h" - -using namespace std; - -namespace OHOS { -namespace FileManagerService { -static int GetCmdResponse(MessageParcel &reply, sptr &cmdResponse) -{ - cmdResponse = reply.ReadParcelable(); - if (cmdResponse == nullptr) { - ERR_LOG("Unmarshalling cmdResponse fail"); - return FAIL; - } - return cmdResponse->GetErr(); -} - -FileManagerProxy::FileManagerProxy(const sptr &impl) - : IRemoteProxy(impl) {} -int FileManagerProxy::GetRoot(const CmdOptions &option, vector> &fileRes) -{ - CmdOptions op(option); - int code = Operation::GET_ROOT; - if (op.GetDevInfo().GetName() == "external_storage") { - code = (Equipment::EXTERNAL_STORAGE << EQUIPMENT_SHIFT) | Operation::GET_ROOT; - } - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(op.GetDevInfo().GetName()); - MessageParcel reply; - MessageOption messageOption; - int err = Remote()->SendRequest(code, data, reply, messageOption); - if (err != ERR_NONE) { - ERR_LOG("GetRoot inner error send request fail %{public}d", err); - return FAIL; - } - sptr cmdResponse; - err = GetCmdResponse(reply, cmdResponse); - if (err != ERR_NONE) { - return err; - } - fileRes = cmdResponse->GetFileInfoList(); - return err; -} - -int FileManagerProxy::CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) -{ - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(fileName); - data.WriteString(path); - MessageParcel reply; - MessageOption messageOption; - int code = Operation::CREATE_FILE; - CmdOptions op(option); - if (op.GetDevInfo().GetName() == "external_storage") { - code = (Equipment::EXTERNAL_STORAGE << EQUIPMENT_SHIFT) | Operation::CREATE_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; - } - sptr cmdResponse; - err = GetCmdResponse(reply, cmdResponse); - if (err != ERR_NONE) { - return err; - } - uri = cmdResponse->GetUri(); - return err; -} - -IFmsClient *IFmsClient::GetFmsInstance() -{ - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - ERR_LOG("samgr object is NULL."); - return nullptr; - } - sptr object = samgr->GetSystemAbility(FILE_MANAGER_SERVICE_ID); - if (object == nullptr) { - ERR_LOG("FileManager Service object is NULL."); - return nullptr; - } - static FileManagerProxy proxy = FileManagerProxy(object); - return &proxy; -} - -int FileManagerProxy::ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) -{ - CmdOptions op(option); - std::string devName(op.GetDevInfo().GetName()); - std::string devPath(op.GetDevInfo().GetPath()); - int64_t offset = op.GetOffset(); - int64_t count = op.GetCount(); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(devName); - data.WriteString(devPath); - data.WriteString(type); - data.WriteString(path); - data.WriteInt64(offset); - data.WriteInt64(count); - MessageParcel reply; - MessageOption messageOption; - uint32_t code = Operation::LIST_FILE; - if (op.GetDevInfo().GetName() == "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; - } - sptr cmdResponse; - err = GetCmdResponse(reply, cmdResponse); - if (err != ERR_NONE) { - return err; - } - fileRes = cmdResponse->GetFileInfoList(); - return err; -} - -int FileManagerProxy::Mkdir(const string &name, const string &path) -{ - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(name); - data.WriteString(path); - MessageParcel reply; - MessageOption option; - int err = Remote()->SendRequest(Operation::MAKE_DIR, data, reply, option); - if (err != ERR_NONE) { - ERR_LOG("inner error send request fail %{public}d", err); - return FAIL; - } - reply.ReadInt32(err); - return err; -} -} // FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/client/file_manager_proxy.h b/services/src/client/file_manager_proxy.h deleted file mode 100644 index 494648ed26703f008083ec301e84e68a30329f74..0000000000000000000000000000000000000000 --- a/services/src/client/file_manager_proxy.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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_FILE_MANAGER_PROXY_H -#define STORAGE_FILE_MANAGER_PROXY_H - -#include "file_manager_service_stub.h" -#include "ifms_client.h" -#include "iremote_proxy.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - -namespace OHOS { -namespace FileManagerService { -class FileManagerProxy : public IRemoteProxy, public IFmsClient { -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, const CmdOptions &option, - std::vector> &fileRes) override; - int CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) override; - int GetRoot(const CmdOptions &option, std::vector> &fileRes) override; -private: - static inline BrokerDelegator delegator_; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_PROXY_H \ No newline at end of file diff --git a/services/src/client/ifms_client.h b/services/src/client/ifms_client.h deleted file mode 100644 index ba0ce14abfe063493042b82988963f0a168dee63..0000000000000000000000000000000000000000 --- a/services/src/client/ifms_client.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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_IFILE_MANAGER_CLIENT_H -#define STORAGE_IFILE_MANAGER_CLIENT_H -#include "cmd_options.h" -#include "file_info.h" -namespace OHOS { -namespace FileManagerService { -class IFmsClient { -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, const CmdOptions &option, - std::vector> &fileRes) = 0; - virtual int GetRoot(const CmdOptions &option, std::vector> &fileRes) = 0; - virtual int CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) = 0; -}; -} // namespace FileManagerService { -} // namespace OHOS -#endif // STORAGE_IFILE_MANAGER_CLIENT_H \ No newline at end of file diff --git a/services/src/fileoper/cmd_options.h b/services/src/fileoper/cmd_options.h deleted file mode 100644 index b119ead8f919ce13ab53080cb181971149537dd4..0000000000000000000000000000000000000000 --- a/services/src/fileoper/cmd_options.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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 -#include "file_manager_service_def.h" -namespace OHOS { -namespace FileManagerService { -class DevInfo { -public: - DevInfo() = default; - ~DevInfo() = default; - DevInfo(const std::string &nameIn, const std::string &pathIn) : name_(nameIn), path_(pathIn) - {} - - DevInfo(const DevInfo &dev) - { - this->name_ = dev.name_; - this->path_ = dev.path_; - } - - DevInfo& operator=(const DevInfo& dev) - { - this->name_ = dev.name_; - this->path_ = dev.path_; - return *this; - } - - std::string GetName() const - { - return name_; - } - - void SetName(const std::string& name) - { - name_ = name; - } - - std::string GetPath() const - { - return path_; - } - - void SetPath(const std::string& path) - { - path_ = path; - } - -private: - std::string name_ {""}; - std::string path_ {""}; -}; - -class CmdOptions { -public: - CmdOptions() = default; - ~CmdOptions() = default; - - CmdOptions(DevInfo devIn, int64_t offsetIn, int64_t countIn, bool hasOptIn) - : dev_(devIn), offset_(offsetIn), count_(countIn), hasOpt_(hasOptIn) - {} - CmdOptions(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) - {} - - CmdOptions(const CmdOptions &option) = default; - CmdOptions& operator=(const CmdOptions& option) = default; - - DevInfo GetDevInfo() const - { - return dev_; - } - - void SetDevInfo(const DevInfo& dev) - { - dev_ = dev; - } - - int64_t GetOffset() const - { - return offset_; - } - - void SetOffset(int64_t offset) - { - offset_ = offset; - } - - int64_t GetCount() const - { - return count_; - } - - void setCount(int64_t count) - { - count_ = count; - } - - bool GetHasOpt() const - { - return hasOpt_; - } - - void SetHasOpt(bool hasOpt) - { - hasOpt_ = hasOpt; - } - -private: - DevInfo dev_; - int64_t offset_ {0}; - int64_t count_ {MAX_NUM}; - bool hasOpt_ {false}; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_DEV_INFO_H \ No newline at end of file diff --git a/services/src/fileoper/cmd_response.h b/services/src/fileoper/cmd_response.h deleted file mode 100644 index f4a3b445b6d7634f95ea52e490f6f1f1e667f14b..0000000000000000000000000000000000000000 --- a/services/src/fileoper/cmd_response.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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_CMD_RESPONSE_H -#define STORAGE_SERVICES_CMD_RESPONSE_H - -#include -#include -#include - -#include "file_info.h" -#include "log.h" -#include "parcel.h" -namespace OHOS { -namespace FileManagerService { -class CmdResponse : public Parcelable { -public: - CmdResponse() = default; - CmdResponse(int &err, std::string &uri, std::vector> &fileInfoList) - : err_(err), uri_(uri), vecFileInfo_(fileInfoList) - {} - ~CmdResponse() = default; - - void SetErr(const int err) - { - err_ = err; - } - - int GetErr() const - { - return err_; - } - - void SetUri(const std::string &uri) - { - uri_ = uri; - } - - std::string GetUri() const - { - return uri_; - } - - void SetFileInfoList(std::vector> &fileInfoList) - { - vecFileInfo_ = fileInfoList; - } - - std::vector> GetFileInfoList() - { - return vecFileInfo_; - } - - virtual bool Marshalling(Parcel &parcel) const override - { - parcel.WriteInt32(err_); - parcel.WriteString(uri_); - size_t fileCount = vecFileInfo_.size(); - parcel.WriteUint64(fileCount); - for (size_t i = 0; i < fileCount; i++) { - if (parcel.WriteParcelable(vecFileInfo_[i].get()) != true) { - ERR_LOG("Marshalling FileInfo fails!"); - return false; - } - } - return true; - } - - static CmdResponse* Unmarshalling(Parcel &parcel) - { - auto *obj = new (std::nothrow) CmdResponse(); - if (obj == nullptr) { - return nullptr; - } - obj->err_ = parcel.ReadInt32(); - obj->uri_ = parcel.ReadString(); - size_t fileCount = parcel.ReadUint64(); - for (size_t i = 0; i < fileCount; i++) { - std::shared_ptr file(parcel.ReadParcelable()); - obj->vecFileInfo_.emplace_back(file); - } - return obj; - } -private: - int err_; - std::string uri_; - std::vector> vecFileInfo_; -}; -} // FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_CMD_RESPONSE_H \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_status.h b/services/src/fileoper/ext_storage/ext_storage_status.h deleted file mode 100644 index a2b27b0e35c31b2e9f68263f888d5929efe91b8f..0000000000000000000000000000000000000000 --- a/services/src/fileoper/ext_storage/ext_storage_status.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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_EXT_STORAGE_STATUS_H -#define STORAGE_EXT_STORAGE_STATUS_H - -#include - -#include "file_manager_service_def.h" - -namespace OHOS { -namespace FileManagerService { -class ExtStorageStatus { -public: - ExtStorageStatus() = default; - ~ExtStorageStatus() = default; - ExtStorageStatus(const std::string &id, const std::string &diskId, - const std::string &fsUuid, const std::string &path, const VolumeState &volumeState) - : id_(id), diskId_(diskId), fsUuid_(fsUuid), path_(path), volumeState_(volumeState) {} - - ExtStorageStatus(const ExtStorageStatus &extStatus) - { - this->id_ = extStatus.id_; - this->diskId_ = extStatus.diskId_; - this->fsUuid_ = extStatus.fsUuid_; - this->path_ = extStatus.path_; - this->volumeState_ = extStatus.volumeState_; - } - - ExtStorageStatus& operator=(const ExtStorageStatus &extStatus) - { - if (this != &extStatus) { - this->id_ = extStatus.id_; - this->diskId_ = extStatus.diskId_; - this->fsUuid_ = extStatus.fsUuid_; - this->path_ = extStatus.path_; - this->volumeState_ = extStatus.volumeState_; - } - return *this; - } - - std::string GetId() - { - return id_; - } - - void SetId(const std::string &id) - { - id_ = id; - } - - std::string GetDiskId() - { - return diskId_; - } - - void SetDiskId(const std::string &diskId) - { - diskId_ = diskId; - } - - std::string GetFsUuid() - { - return fsUuid_; - } - - void SetFsUuid(const std::string &fsUuid) - { - fsUuid_ = fsUuid; - } - - std::string GetPath() - { - return path_; - } - - void SetPath(const std::string &path) - { - path_ = path; - } - - VolumeState GetVolumeState() - { - return volumeState_; - } - - void SetVolumeState(const VolumeState &volumeState) - { - volumeState_ = volumeState; - } - -private: - std::string id_; - std::string diskId_; - std::string fsUuid_; - std::string path_; - VolumeState volumeState_; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_EXT_STORAGE_STATUS_H \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp deleted file mode 100644 index 448b33e1185b17f7d497943746af3a0f0d424575..0000000000000000000000000000000000000000 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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 "ext_storage_subscriber.h" - -#include - -#include "appexecfwk_errors.h" -#include "bundle_info.h" -#include "common_event_manager.h" -#include "common_event_support.h" -#include "int_wrapper.h" -#include "log.h" -#include "string_wrapper.h" -#include "want.h" - -using namespace OHOS::AAFwk; -namespace OHOS { -namespace FileManagerService { -/** - * @brief Receiver Constructor. - * @param subscriberInfo Subscriber info. - */ -ExtStorageSubscriber::ExtStorageSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo) - : EventFwk::CommonEventSubscriber(subscriberInfo) -{} - -std::shared_ptr ExtStorageSubscriber_ = nullptr; -bool ExtStorageSubscriber::Subscriber(void) -{ - if (ExtStorageSubscriber_ == nullptr) { - EventFwk::MatchingSkills matchingSkills; - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_UNMOUNTED); - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED); - - EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); - ExtStorageSubscriber_ = std::make_shared(subscribeInfo); - EventFwk::CommonEventManager::SubscribeCommonEvent(ExtStorageSubscriber_); - } - return true; -} - -/** - * @brief Receive common event. - * @param eventData Common event data. - */ -void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eventData) -{ - const AAFwk::Want& want = eventData.GetWant(); - std::string action = want.GetAction(); - DEBUG_LOG("%{public}s, action:%{public}s.", __func__, action.c_str()); - - const AAFwk::WantParams wantParams = want.GetParams(); - std::string id = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("id"))); - std::string diskId = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("diskId"))); - DEBUG_LOG("%{public}s, id:%{public}s.", __func__, id.c_str()); - DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); - - if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED) { - int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); - std::string fsUuid = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("fsUuid"))); - std::string path = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("path"))); - DEBUG_LOG("%{public}s, volumeState:%{public}d.", __func__, volumeState); - DEBUG_LOG("%{public}s, id:%{public}s, fsUuid:%{public}s, path:%{public}s.", - __func__, id.c_str(), fsUuid.c_str(), path.c_str()); - - ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); - mountStatus.insert(std::pair(path, extStatus)); - } -} - -bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) -{ - auto extStorageStatus = mountStatus.find(path); - if (extStorageStatus == mountStatus.end()) { - return false; - } else { - if (extStorageStatus->second.GetVolumeState() == VolumeState::MOUNTED) { - return true; - } - return false; - } -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/services/src/fileoper/ext_storage/ext_storage_subscriber.h deleted file mode 100644 index 18a34b779970bb9b509c5aa06372bfea2e18ed16..0000000000000000000000000000000000000000 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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_FILE_SYS_EVENT_RECEIVER_H -#define STORAGE_FILE_SYS_EVENT_RECEIVER_H - -#include -#include - -#include "common_event_manager.h" -#include "common_event_subscribe_info.h" -#include "common_event_subscriber.h" -#include "common_event_support.h" -#include "ext_storage_status.h" -#include "matching_skills.h" - -namespace OHOS { -namespace FileManagerService { -/** - * @class ExtStorageSubscriber - * Receive system common event. - */ -class ExtStorageSubscriber : public EventFwk::CommonEventSubscriber { -public: - ExtStorageSubscriber() = default; - explicit ExtStorageSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo); - static bool Subscriber(void); - virtual ~ExtStorageSubscriber() = default; - /** - * @brief System common event receiver. - * @param eventData Common event data. - */ - virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; - - bool CheckMountPoint(const std::string &path); - - std::unordered_map mountStatus; -}; -} // namespace FileManagerService -} // namespace OHOS - -#endif // STORAGE_FILE_SYS_EVENT_RECEIVER_H \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/storage_manager_inf.cpp b/services/src/fileoper/ext_storage/storage_manager_inf.cpp deleted file mode 100644 index 02481edfd3ece04e0a94196ae11b68fdcad631d9..0000000000000000000000000000000000000000 --- a/services/src/fileoper/ext_storage/storage_manager_inf.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "storage_manager_inf.h" - -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -static bool GetMountPointFromPath(const string &path, string &mountPoint) -{ - size_t len = MOUNT_POINT_ROOT.size(); - std::string head = path.substr(0, len); - std::string body = path.substr(len); - if (head != MOUNT_POINT_ROOT || body.size() == 0) { - ERR_LOG("invalid mountPoint %{public}s, head check fail", path.c_str()); - return false; - } - - size_t index = body.find("/"); - if (index != std::string::npos) { - mountPoint = MOUNT_POINT_ROOT + body.substr(0, index); - } else { - mountPoint = path; - } - return true; -} - -int StorageManagerInf::Connect() -{ - DEBUG_LOG("StorageManagerConnect::Connect start"); - auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (sam == nullptr) { - ERR_LOG("StorageManagerConnect::Connect samgr == nullptr"); - return FAIL; - } - auto object = sam->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID); - if (object == nullptr) { - ERR_LOG("StorageManagerConnect::Connect object == nullptr"); - return FAIL; - } - storageManager_ = iface_cast(object); - if (storageManager_ == nullptr) { - ERR_LOG("StorageManagerConnect::Connect service == nullptr"); - return FAIL; - } - DEBUG_LOG("StorageManagerConnect::Connect end"); - return SUCCESS; -} - -std::vector StorageManagerInf::GetAllVolumes() -{ - vector result = {}; - if (Connect() != SUCCESS) { - ERR_LOG("GetTotalSizeOfVolume:Connect error"); - return result; - } - return storageManager_->GetAllVolumes(); -} - -bool StorageManagerInf::GetMountedVolumes(vector &vecRootPath) -{ - bool succ = false; - vector result = GetAllVolumes(); - if (result.size() == 0) { - ERR_LOG("empty volume result"); - return succ; - } - for (auto vol : result) { - DEBUG_LOG("find vol.GetPath() %{public}d %{public}d", vol.GetState(), VolumeState::MOUNTED); - if (vol.GetState() == VolumeState::MOUNTED) { - DEBUG_LOG("mounted find vol.GetPath() %{public}d %{public}d", vol.GetState(), VolumeState::MOUNTED); - vecRootPath.emplace_back(EXTERNAL_STORAGE_URI + vol.GetPath()); - succ = true; - } - } - return succ; -} - -bool StorageManagerInf::StoragePathValidCheck(const string &path) -{ - string mountPoint; - if (!GetMountPointFromPath(path, mountPoint)) { - ERR_LOG("uri path is invalid"); - return false; - } - vector result = GetAllVolumes(); - if (result.size() == 0) { - ERR_LOG("empty volume result"); - return false; - } - bool succ = false; - for (auto vol : result) { - if (vol.GetPath() == mountPoint && vol.GetState() == VolumeState::MOUNTED) { - succ = true; - break; - } - } - return succ; -} -} // FileManagerService -} // OHOS diff --git a/services/src/fileoper/external_storage_oper.cpp b/services/src/fileoper/external_storage_oper.cpp deleted file mode 100644 index af9c01d6b7cfccf5c6863c56bf109a062866ca96..0000000000000000000000000000000000000000 --- a/services/src/fileoper/external_storage_oper.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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 "cmd_response.h" -#include "external_storage_utils.h" -#include "file_info.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" - -using namespace std; -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: { - std::string devName = data.ReadString(); - std::string devPath = data.ReadString(); - std::string type = data.ReadString(); - std::string path = data.ReadString(); - int64_t offset = data.ReadInt64(); - int64_t count = data.ReadInt64(); - - CmdOptions option(devName, devPath, offset, count, true); - 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; - } - case Operation::GET_ROOT: { - string path = data.ReadString(); - // name for extension - string name = "name"; - errCode = GetRoot(name, path, reply); - break; - } - default: { - DEBUG_LOG("not valid code %{public}d.", code); - break; - } - } - return errCode; -} - -int ExternalStorageOper::GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const -{ - std::vector> fileList; - int ret = ExternalStorageUtils::DoGetRoot(name, path, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int ExternalStorageOper::CreateFile(const std::string &uri, const std::string &name, MessageParcel &reply) const -{ - std::string resultUir; - int ret = ExternalStorageUtils::DoCreateFile(uri, name, resultUir); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetUri(resultUir); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int ExternalStorageOper::ListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - MessageParcel &reply) const -{ - std::vector> fileList; - int ret = ExternalStorageUtils::DoListFile(type, uri, option, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return ret; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/external_storage_oper.h b/services/src/fileoper/external_storage_oper.h deleted file mode 100644 index af5ee57a4d0c23f826e175370fbc8fcd06918b99..0000000000000000000000000000000000000000 --- a/services/src/fileoper/external_storage_oper.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 "cmd_options.h" -#include "file_oper.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 CmdOptions &option, - MessageParcel &reply) const; - int GetRoot(const std::string &name, const std::string &path, 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 deleted file mode 100644 index 1cff272a39f2eb3384b77be18c2e25cbe8afb438..0000000000000000000000000000000000000000 --- a/services/src/fileoper/external_storage_utils.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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 - -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" -#include "storage_manager_inf.h" -using namespace std; -using namespace OHOS::StorageManager; -namespace OHOS { -namespace FileManagerService { -static bool GetPathFromUri(const string &uri, string &path) -{ - uint len = EXTERNAL_STORAGE_URI.size(); - string head = uri.substr(0, len); - if (head != EXTERNAL_STORAGE_URI) { - ERR_LOG("invalid format uri %{private}s, head check fail", uri.c_str()); - return false; - } - if (uri.size() == len) { - ERR_LOG("uri content is invalid %{private}s", uri.c_str()); - return false; - } - path = uri.substr(len); - return true; -} - -static bool GetRealPath(string &path) -{ - char filePath[PATH_MAX + 1] = { 0 }; - if (realpath(path.c_str(), filePath) == nullptr) { - ERR_LOG("untrustPath invalid %{public}d\n", errno); - return false; - } - path = string(filePath); - return true; -} - -static bool GetFileInfo(const std::string &path, const std::string &name, shared_ptr &fileInfo) -{ - std::string fullPath(path); - size_t len = fullPath.size(); - if (fullPath.at(len - 1) != '/') { - fullPath.append("/").append(name); - } else { - fullPath.append(name); - } - struct stat st; - if (lstat(fullPath.c_str(), &st) != 0) { - ERR_LOG("check file info fail."); - return false; - } - std::string uri(EXTERNAL_STORAGE_URI); - std::string fName(name.c_str()); - - uri.append(fullPath); - fileInfo->SetPath(uri); - std::string type = S_ISDIR(st.st_mode) ? "album" : "file"; - fileInfo->SetType(type); - 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)); - return true; -} - -static bool ConvertUriToAbsolutePath(const std::string &uri, std::string &path) -{ - if (!GetPathFromUri(uri, path)) { - ERR_LOG("GetPathFromUri fail"); - return false; - } - if (!GetRealPath(path)) { - ERR_LOG("get real path fail"); - return false; - } - if (!StorageManagerInf::StoragePathValidCheck(path)) { - ERR_LOG("external uri path was ejected"); - return false; - } - return true; -} - -int ExternalStorageUtils::DoListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - std::vector> &fileList) -{ - int64_t count = option.GetCount(); - int64_t offset = option.GetOffset(); - if (count < 0 || count > MAX_NUM || offset < 0) { - ERR_LOG("invalid file count or offset."); - return E_INVALID_FILE_NUMBER; - } - DEBUG_LOG("limit %{public}lld, offset %{public}lld", (long long)count, (long long)offset); - std::string path; - if (!ConvertUriToAbsolutePath(uri, path)) { - ERR_LOG("invalid uri[%{private}s].", uri.c_str()); - return E_NOEXIST; - } - - DIR *dir = opendir(path.c_str()); - if (!dir) { - ERR_LOG("opendir path[%{private}s] fail.", path.c_str()); - return E_NOEXIST; - } - if (offset != 0) { - int64_t index = 0; - for (dirent *ent = readdir(dir); ent != nullptr; ent = readdir(dir)) { - if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { - continue; - } - if (index == offset - 1) { - break; - } - index++; - } - } - for (dirent *ent = readdir(dir); ent != nullptr; ent = readdir(dir)) { - if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { - continue; - } - if (count > 0) { - shared_ptr fileInfo = make_shared(); - if (!GetFileInfo(path, ent->d_name, fileInfo)) { - continue; - } - fileList.push_back(fileInfo); - count--; - if (count == 0) { - break; - } - } - } - closedir(dir); - if (option.GetCount() == MAX_NUM && count == 0) { - DEBUG_LOG("get files with MAX_NUM:[%{public}lld].", (long long)MAX_NUM); - } - return SUCCESS; -} - -int ExternalStorageUtils::DoCreateFile(const std::string &uri, const std::string &name, std::string &resultUri) -{ - std::string path; - if (!ConvertUriToAbsolutePath(uri, path)) { - ERR_LOG("invalid uri[%{public}s].", uri.c_str()); - return E_NOEXIST; - } - size_t len = path.size(); - if (path.at(len - 1) != '/') { - path.append("/").append(name); - } else { - path.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); - resultUri = EXTERNAL_STORAGE_URI + path; - return SUCCESS; -} - -int ExternalStorageUtils::DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList) -{ - vector vecRootPath; - if (!StorageManagerInf::GetMountedVolumes(vecRootPath)) { - ERR_LOG("none valid extorage storage"); - return FAIL; - } - for (auto rootPath : vecRootPath) { - shared_ptr fileInfo = make_shared(FILE_ROOT_NAME, rootPath, ALBUM_TYPE); - fileList.push_back(fileInfo); - } - return SUCCESS; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/external_storage_utils.h b/services/src/fileoper/external_storage_utils.h deleted file mode 100644 index a975ba179ed3c28989364afe8ce732ccc086b831..0000000000000000000000000000000000000000 --- a/services/src/fileoper/external_storage_utils.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 - -#include "cmd_options.h" -#include "file_info.h" -#include "file_oper.h" - -namespace OHOS { -namespace FileManagerService { -class ExternalStorageUtils { -public: - ExternalStorageUtils(); - ~ExternalStorageUtils(); - static int DoListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - std::vector> &fileList); - static int DoCreateFile(const std::string &uri, const std::string &name, std::string &resultUri); - static int DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList); -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H \ No newline at end of file diff --git a/services/src/fileoper/file_info.cpp b/services/src/fileoper/file_info.cpp deleted file mode 100644 index d08871a0fb5ff26d48bc0fcc18b86cc2e403ac65..0000000000000000000000000000000000000000 --- a/services/src/fileoper/file_info.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 "file_info.h" - -#include -#include - -#include "log.h" - -using namespace std; - -namespace OHOS { -namespace FileManagerService { -bool FileInfo::Marshalling(Parcel &parcel) const -{ - parcel.WriteString(path_); - parcel.WriteString(name_); - parcel.WriteString(type_); - parcel.WriteInt64(size_); - parcel.WriteInt64(addedTime_); - parcel.WriteInt64(modifiedTime_); - return true; -} - -FileInfo* FileInfo::Unmarshalling(Parcel &parcel) -{ - auto *obj = new (std::nothrow) FileInfo(); - if (obj == nullptr) { - ERR_LOG("Unmarshalling fail"); - return nullptr; - } - obj->path_ = parcel.ReadString(); - obj->name_ = parcel.ReadString(); - obj->type_ = parcel.ReadString(); - obj->size_ = parcel.ReadInt64(); - obj->addedTime_ = parcel.ReadInt64(); - obj->modifiedTime_ = parcel.ReadInt64(); - return obj; -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/file_info.h b/services/src/fileoper/file_info.h deleted file mode 100644 index b46e662c9153e5d99bcdafc3dcc420cd77a9b784..0000000000000000000000000000000000000000 --- a/services/src/fileoper/file_info.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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_FILE_INFO_H -#define STORAGE_SERVICES_FILE_INFO_H - -#include -#include -#include - -#include "parcel.h" - -namespace OHOS { -namespace FileManagerService { -class FileInfo : public Parcelable { -public: - FileInfo(const std::string &name, const std::string &path, const std::string &type) : path_(path), - name_(name), type_(type) {} - FileInfo() = default; - ~FileInfo() = default; - - void SetName(std::string &name) - { - name_ = name; - } - void SetPath(std::string &path) - { - path_ = path; - } - void SetType(std::string &type) - { - type_ = type; - } - void SetSize(int64_t size) - { - size_ = size; - } - void SetAddedTime(int64_t time) - { - addedTime_ = time; - } - void SetModifiedTime(int64_t time) - { - modifiedTime_ = time; - } - std::string GetName() const - { - return name_; - } - std::string GetPath() const - { - return path_; - } - std::string GetType() const - { - return type_; - } - int64_t GetSize() const - { - return size_; - } - int64_t GetAddedTime() const - { - return addedTime_; - } - int64_t GetModifiedTime() const - { - return modifiedTime_; - } - bool Marshalling(Parcel &parcel) const override; - static FileInfo* Unmarshalling(Parcel &parcel); -private: - std::string path_; - std::string name_; - std::string type_; - int64_t size_ {0}; - int64_t addedTime_ {0}; - int64_t modifiedTime_ {0}; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_FILE_INFO_H \ No newline at end of file diff --git a/services/src/fileoper/file_oper.h b/services/src/fileoper/file_oper.h deleted file mode 100644 index 57839af34e1f371b0e4909ddf0081c07775c6df0..0000000000000000000000000000000000000000 --- a/services/src/fileoper/file_oper.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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_FILE_OPER_H -#define STORAGE_SERVICES_FILE_OPER_H - -#include -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace FileManagerService { -class FileOper { -public: - FileOper() = default; - virtual ~FileOper() = default; - virtual int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const = 0; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_FILE_OPER_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 deleted file mode 100644 index 118b6210939134ca836a3ac6c3fec940bd7844c3..0000000000000000000000000000000000000000 --- a/services/src/fileoper/media_file_oper.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 "media_file_oper.h" - -#include - -#include "cmd_options.h" -#include "cmd_response.h" -#include "file_info.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "log.h" -#include "medialibrary_db_const.h" -#include "media_file_utils.h" - -using namespace std; - -namespace OHOS { -namespace FileManagerService { -int MediaFileOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const -{ - int errCode = SUCCESS; - // media process - switch (code) { - case Operation::MAKE_DIR: { - string name = data.ReadString(); - string path = data.ReadString(); - errCode = Mkdir(name, path); - break; - } - case Operation::GET_ROOT: { - string path = data.ReadString(); - // name for extension - string name = "name"; - errCode = GetRoot(name, path, reply); - break; - } - case Operation::LIST_FILE: { - string devName = data.ReadString(); - string devPath = data.ReadString(); - string type = data.ReadString(); - string path = data.ReadString(); - int off = data.ReadInt64(); - int count = data.ReadInt64(); - // put fileInfo into reply - errCode = ListFile(type, path, off, count, reply); - break; - } - case Operation::CREATE_FILE: { - string name = data.ReadString(); - string path = data.ReadString(); - errCode = CreateFile(name, path, reply); - break; - } - default: { - DEBUG_LOG("not valid code %{public}u.", code); - break; - } - } - return errCode; -} - -int MediaFileOper::CreateFile(const std::string &name, const std::string &path, MessageParcel &reply) const -{ - string type = "file"; - std::string uri; - int ret = MediaFileUtils::DoInsert(name, path, type, uri); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetUri(uri); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int MediaFileOper::GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const -{ - std::vector> fileList; - int ret = MediaFileUtils::DoGetRoot(name, path, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int MediaFileOper::ListFile(const string &type, const string &path, int offset, int count, MessageParcel &reply) const -{ - shared_ptr result; - int res = MediaFileUtils::DoListFile(type, path, offset, count, result); - if (res != SUCCESS) { - return res; - } - - std::vector> fileList; - res = MediaFileUtils::GetFileInfoFromResult(result, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(res); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return res; -} - -int MediaFileOper::Mkdir(const string &name, const string &path) const -{ - (void)name; - DEBUG_LOG("MediaFileOper::mkdir path %{public}s.", path.c_str()); - return SUCCESS; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/media_file_oper.h b/services/src/fileoper/media_file_oper.h deleted file mode 100644 index bc4374b212fd9a7909a7bd1d2b5ab2e2c660b98d..0000000000000000000000000000000000000000 --- a/services/src/fileoper/media_file_oper.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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_MEDIA_FILE_OPER_H -#define STORAGE_SERVICES_MEDIA_FILE_OPER_H - -#include -#include "file_oper.h" -namespace OHOS { -namespace FileManagerService { -class MediaFileOper : public FileOper { -public: - MediaFileOper() = default; - virtual ~MediaFileOper() = default; - int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const override; -private: - int CreateFile(const std::string &name, const std::string &path, MessageParcel &reply) const; - int ListFile(const std::string &type, const std::string &path, int offset, int count, MessageParcel &data) const; - int GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const; - int Mkdir(const std::string &name, const std::string &path) const; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_MEDIA_FILE_OPER_H \ No newline at end of file diff --git a/services/src/fileoper/media_file_utils.cpp b/services/src/fileoper/media_file_utils.cpp deleted file mode 100644 index 78e84898b7451f8d1c44c5dfe64238d694bc5d70..0000000000000000000000000000000000000000 --- a/services/src/fileoper/media_file_utils.cpp +++ /dev/null @@ -1,449 +0,0 @@ -/* - * Copyright (C) 2021-2022 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 "media_file_utils.h" - -#include - -#include "datashare_predicates.h" -#include "datashare_values_bucket.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" -#include "media_asset.h" -#include "medialibrary_db_const.h" -#include "rdb_errno.h" -#include "values_bucket.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -bool GetPathFromResult(shared_ptr result, string &path) -{ - int count = 0; - result->GetRowCount(count); - if (count == RESULTSET_EMPTY) { - ERR_LOG("DataShareResultSet null"); - return false; - } - int32_t columnIndex = 0; - GET_COLUMN_INDEX_FROM_NAME(result, Media::MEDIA_DATA_DB_FILE_PATH, columnIndex); - result->GoToFirstRow(); - int ret = result->GetString(columnIndex, path); - if (ret != NativeRdb::E_OK) { - ERR_LOG("NativeRdb gets path index fail"); - return false; - } - GET_COLUMN_INDEX_FROM_NAME(result, Media::MEDIA_DATA_DB_RELATIVE_PATH, columnIndex); - string relativePath; - ret = result->GetString(columnIndex, relativePath); - if (ret != NativeRdb::E_OK) { - relativePath = ""; - DEBUG_LOG("NativeRdb gets relative path is null %{public}d", columnIndex); - } - // get relative path from absolute path - string::size_type pos = path.find_last_of('/'); - if (pos != string::npos) { - path = relativePath + path.substr(pos + 1) + "/"; - } - return true; -} - -bool IsNumber(const string &str) -{ - if (str.length() == 0) { - ERR_LOG("IsNumber input is empty "); - return false; - } - - for (char const &c : str) { - if (isdigit(c) == 0) { - ERR_LOG("Index is not a number"); - return false; - } - } - - return true; -} - -bool GetPathID(const string &uriPath, string &index) -{ - string::size_type pos = uriPath.find_last_of('/'); - if (pos == string::npos) { - ERR_LOG("invalid uri %{private}s", uriPath.c_str()); - return false; - } - index = uriPath.substr(pos + 1); - if (!IsNumber(index)) { - ERR_LOG("invalid uri %{private}s invalid id %{public}s", uriPath.c_str(), index.c_str()); - return false; - } - 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; - if (!GetPathID(albumUri, id)) { - ERR_LOG("GetPathID fails"); - return false; - } - string selection = Media::MEDIA_DATA_DB_ID + " LIKE ? "; - vector selectionArgs = {id}; - shared_ptr result = MediaFileUtils::DoQuery(selection, selectionArgs); - if (result == nullptr) { - ERR_LOG("DataShareResultSet null"); - return false; - } - return GetPathFromResult(result, path); -} - -string GetType(string type) -{ - unordered_map typeMap = { - {"image", Media::MediaType::MEDIA_TYPE_IMAGE}, - {"video", Media::MediaType::MEDIA_TYPE_VIDEO}, - {"audio", Media::MediaType::MEDIA_TYPE_AUDIO} - }; - if (typeMap.count(type) == 0) { - // type is wrong - ERR_LOG("Type %{public}s", type.c_str()); - return ""; - } - return ToString(typeMap[type]); -} - -bool IsFirstLevelUriPath(const string &path) -{ - // check whether path is first level uri - return path == FISRT_LEVEL_ALBUM; -} - -bool GetAlbumFromResult(shared_ptr &result, vector &album) -{ - int count = 0; - result->GetRowCount(count); - result->GoToFirstRow(); - int32_t columnIndex; - GET_COLUMN_INDEX_FROM_NAME(result, Media::MEDIA_DATA_DB_RELATIVE_PATH, columnIndex); - for (int i = 0; i < count; i++) { - string path; - if (result->GetString(columnIndex, path) != NativeRdb::E_OK) { - ERR_LOG("NativeRdb gets path columnIndex fail"); - return false; - } - path = MEDIA_ROOT_PATH + "/" + path.substr(0, path.size() - 1); - // add into ablum if not in album - if (find(album.begin(), album.end(), path) == album.end()) { - DEBUG_LOG(" // add into ablum path %{public}s", path.c_str()); - album.emplace_back(path); - } - result->GoToNextRow(); - } - return true; -} - -vector FindAlbumByType(string type) -{ - // find out the first level Album - // first find out file by type - // then get the album - string selection = Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ?"; - vector selectionArgs = {type}; - shared_ptr result = MediaFileUtils::DoQuery(selection, selectionArgs); - vector album; - if (result == nullptr) { - ERR_LOG("query album type returns fail"); - return album; - } - GetAlbumFromResult(result, album); - return album; -} - -/* listfile - * ----find "file" type - * --------first level view---- - * --------selection MEDIA_DATA_DB_RELATIVE_PATH == root_path && - * (MEDIA_DATA_DB_MEDIA_TYPE == "file" || MEDIA_DATA_DB_MEDIA_TYPE == "album") - * --------other level view ---- - * --------selection MEDIA_DATA_DB_RELATIVE_PATH == uri.MEDIA_DATA_DB_FILE_PATH && - * (MEDIA_DATA_DB_MEDIA_TYPE == "file" || MEDIA_DATA_DB_MEDIA_TYPE == "album") - * - * ----find "image"/"audio"/"video" type - * --------first level view---- - * --------find out all album with type file - * --------selection MEDIA_DATA_DB_MEDIA_TYPE == type - * --------Get the relative path ----> Album path - * --------selection MEDIA_DATA_DB_FILE_PATH == Album path1 || selection MEDIA_DATA_DB_FILE_PATH == Album path2 || ... - * --------second level view ---- - * --------selection MEDIA_DATA_DB_RELATIVE_PATH == uri.MEDIA_DATA_DB_FILE_PATH && MEDIA_DATA_DB_MEDIA_TYPE == type - */ -int CreateSelectionAndArgsFirstLevel(const string &type, string &selection, vector &selectionArgs) -{ - if (type == "file") { - selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND (" + Media::MEDIA_DATA_DB_MEDIA_TYPE; - selection += " LIKE ? OR " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ? )"; - selectionArgs = { - RELATIVE_ROOT_PATH, ToString(Media::MediaType::MEDIA_TYPE_FILE), - ToString(Media::MediaType::MEDIA_TYPE_ALBUM) - }; - } else { - selectionArgs = FindAlbumByType(GetType(type)); - selection = Media::MEDIA_DATA_DB_FILE_PATH + " LIKE ?"; - if (selectionArgs.size() > 1) { - for (uint32_t i = 1; i < selectionArgs.size(); i++) { - selection += " OR " + Media::MEDIA_DATA_DB_FILE_PATH + " LIKE ?"; - } - } - } - return SUCCESS; -} - -int CreateSelectionAndArgsOtherLevel(const string &type, const string &albumUri, string &selection, - vector &selectionArgs) -{ - // get the album path from the album uri - string albumPath; - if (!GetPathFromAlbumPath(albumUri, albumPath)) { - ERR_LOG("path not exist"); - return E_NOEXIST; - } - if (type == "file") { - selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND (" + Media::MEDIA_DATA_DB_MEDIA_TYPE; - selection += " LIKE ? OR " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ? )"; - selectionArgs = { - albumPath, ToString(Media::MediaType::MEDIA_TYPE_FILE), - ToString(Media::MediaType::MEDIA_TYPE_ALBUM) - }; - } else { - selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ?"; - selectionArgs = { albumPath, GetType(type) }; - } - return SUCCESS; -} - -bool GetAlbumPath(const string &name, const string &path, string &albumPath) -{ - if (IsFirstLevelUriPath(path)) { - int mediaType = GetMediaType(name); - albumPath = (MEDIA_TYPE_FOLDER_MAPS.count(mediaType) == 0) ? MEDIA_TYPE_FOLDER_MAPS.at(FILE_MEDIA_TYPE) : - MEDIA_TYPE_FOLDER_MAPS.at(mediaType); - return true; - } - return GetPathFromAlbumPath(path, albumPath); -} - -static void ShowSelecArgs(const string &selection, const vector &selectionArgs) -{ - DEBUG_LOG("selection %{public}s ", selection.c_str()); - for (auto s : selectionArgs) { - DEBUG_LOG("selectionArgs %{public}s", s.c_str()); - } -} - -int MediaFileUtils::DoListFile(const string &type, const string &path, int offset, int count, - shared_ptr &result) -{ - string selection; - vector selectionArgs; - if (IsFirstLevelUriPath(path)) { - DEBUG_LOG("IsFirstLevelUriPath"); - CreateSelectionAndArgsFirstLevel(type, selection, selectionArgs); - } else { - int err = CreateSelectionAndArgsOtherLevel(type, path, selection, selectionArgs); - if (err) { - ERR_LOG("CreateSelectionAndArgsOtherLevel returns fail"); - return err; - } - } - result = DoQuery(selection, selectionArgs, offset, count); - if (result == nullptr) { - ERR_LOG("ListFile folder is empty"); - return E_EMPTYFOLDER; - } - return SUCCESS; -} - -shared_ptr MediaFileUtils::DoQuery(const string &selection, - const vector &selectionArgs) -{ - return DoQuery(selection, selectionArgs, 0, MAX_NUM); -} - -shared_ptr MediaFileUtils::DoQuery(const string &selection, - const vector &selectionArgs, int offset, int count) -{ - ShowSelecArgs(selection, selectionArgs); - DataShare::DataSharePredicates predicates; - predicates.SetWhereClause(selection); - predicates.SetWhereArgs(selectionArgs); - predicates.SetOrder("date_taken DESC LIMIT " + ToString(offset) + "," + ToString(count)); - DEBUG_LOG("limit %{public}d, offset %{public}d", count, offset); - Uri uri = Uri(Media::MEDIALIBRARY_DATA_URI); - vector columns; - return abilityHelper->Query(uri, predicates, columns); -} - -int MediaFileUtils::DoInsert(const string &name, const string &path, const string &type, string &uri) -{ - DataShare::DataShareValuesBucket values; - string albumPath; - if (!GetAlbumPath(name, path, albumPath)) { - ERR_LOG("path not exist"); - return E_NOEXIST; - } - values.Put(Media::MEDIA_DATA_DB_RELATIVE_PATH, albumPath); - values.Put(Media::MEDIA_DATA_DB_NAME, name); - values.Put(Media::MEDIA_DATA_DB_MIME_TYPE, GetMimeType(name)); - values.Put(Media::MEDIA_DATA_DB_MEDIA_TYPE, GetMediaType(name)); - Uri createAsset(Media::MEDIALIBRARY_DATA_URI + "/" + Media::MEDIA_FILEOPRN + "/" + - Media::MEDIA_FILEOPRN_CREATEASSET); - int index = abilityHelper->Insert(createAsset, values); - if (index < 0) { - ERR_LOG("Fail to create fail file %{public}s uri %{private}s album %{public}s", name.c_str(), - path.c_str(), albumPath.c_str()); - return E_CREATE_FAIL; - } - // use file id concatenate head as uri - uri = (MEDIA_TYPE_URI_MAPS.count(GetMediaType(name)) == 0) ? MEDIA_TYPE_URI_MAPS.at(FILE_MEDIA_TYPE) : - MEDIA_TYPE_URI_MAPS.at(GetMediaType(name)); - uri += "/" + to_string(index); - - return SUCCESS; -} - -bool MediaFileUtils::InitMediaTableColIndexMap(shared_ptr result) -{ - if (mediaTableMap.size() == 0) { - DEBUG_LOG("init mediaTableMap"); - vector> mediaData = { - {Media::MEDIA_DATA_DB_ID, "string"}, - {Media::MEDIA_DATA_DB_URI, "string"}, - {Media::MEDIA_DATA_DB_MEDIA_TYPE, "string"}, - {Media::MEDIA_DATA_DB_NAME, "string"}, - {Media::MEDIA_DATA_DB_SIZE, "int"}, - {Media::MEDIA_DATA_DB_DATE_ADDED, "int"}, - {Media::MEDIA_DATA_DB_DATE_MODIFIED, "int"} - }; - for (auto i : mediaData) { - int columnIndex = 0; - GET_COLUMN_INDEX_FROM_NAME(result, i.first, columnIndex); - mediaTableMap.emplace_back(columnIndex, i.second); - } - } - return true; -} - -bool MediaFileUtils::GetFileInfo(shared_ptr result, - shared_ptr &fileInfo) -{ - if (!InitMediaTableColIndexMap(result)) { - ERR_LOG("InitMediaTableColIndexMap returns fail"); - return false; - } - int index = 0; - string id; - result->GetString(mediaTableMap[index++].first, id); - string uri; - result->GetString(mediaTableMap[index++].first, uri); - if (uri.empty()) { - DEBUG_LOG("empty uri from medialibrary"); - uri = Media::MEDIALIBRARY_FILE_URI; - } - - string path = uri + "/" + id; - fileInfo->SetPath(path); - string type; - result->GetString(mediaTableMap[index++].first, type); - fileInfo->SetType(type); - string name; - result->GetString(mediaTableMap[index++].first, name); - fileInfo->SetName(name); - int64_t value; - result->GetLong(mediaTableMap[index++].first, value); - fileInfo->SetSize(value); - result->GetLong(mediaTableMap[index++].first, value); - fileInfo->SetAddedTime(value); - result->GetLong(mediaTableMap[index++].first, value); - fileInfo->SetModifiedTime(value); - return true; -} - -int MediaFileUtils::GetFileInfoFromResult(shared_ptr result, - std::vector> &fileList) -{ - int count = 0; - result->GetRowCount(count); - if (count == 0) { - ERR_LOG("DataShareResultSet null"); - return E_EMPTYFOLDER; - } - result->GoToFirstRow(); - for (int i = 0; i < count; i++) { - shared_ptr fileInfo = make_shared(); - GetFileInfo(result, fileInfo); - fileList.push_back(fileInfo); - result->GoToNextRow(); - } - return SUCCESS; -} - -bool MediaFileUtils::InitHelper(sptr obj) -{ - if (abilityHelper == nullptr) { - abilityHelper = DataShare::DataShareHelper::Creator(obj, Media::MEDIALIBRARY_DATA_URI); - if (abilityHelper == nullptr) { - DEBUG_LOG("get %{private}s helper fail", Media::MEDIALIBRARY_DATA_URI.c_str()); - return false; - } - } - return true; -} - -int MediaFileUtils::DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList) -{ - shared_ptr image = make_shared(IMAGE_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(image); - shared_ptr video = make_shared(VIDEO_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(video); - shared_ptr audio = make_shared(AUDIO_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(audio); - shared_ptr file = make_shared(FILE_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(file); - return SUCCESS; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/media_file_utils.h b/services/src/fileoper/media_file_utils.h deleted file mode 100644 index 35d5245ff112b27acb872ecc1076d317362167e1..0000000000000000000000000000000000000000 --- a/services/src/fileoper/media_file_utils.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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_MEDIA_FILE_UTILS_H -#define STORAGE_SERIVCES_MEDIA_FILE_UTILS_H - -#include -#include - -#include "datashare_abs_result_set.h" -#include "file_info.h" -#include "file_oper.h" - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -#include "datashare_helper.h" - -namespace OHOS { -namespace FileManagerService { -class MediaFileUtils { -public: - MediaFileUtils(); - ~MediaFileUtils(); - static int DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList); - static int DoListFile(const std::string &type, const std::string &path, int offset, int count, - std::shared_ptr &result); - static std::shared_ptr DoQuery(const std::string &selection, - const std::vector &selectionArgs); - static std::shared_ptr DoQuery(const std::string &selection, - const std::vector &selectionArgs, int offset, int count); - static int DoInsert(const std::string &name, const std::string &path, const std::string &type, std::string &uri); - static bool GetFileInfo(std::shared_ptr result, std::shared_ptr &fileInfo); - static int GetFileInfoFromResult(std::shared_ptr result, - std::vector> &fileList); - static bool InitMediaTableColIndexMap(std::shared_ptr result); - static bool InitHelper(sptr obj); -private: - inline static std::vector> mediaTableMap = {}; - inline static std::shared_ptr abilityHelper = nullptr; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERIVCES_MEDIA_FILE_UTILS_H \ No newline at end of file diff --git a/services/src/fileoper/oper_factory.cpp b/services/src/fileoper/oper_factory.cpp deleted file mode 100644 index c91577e665e476aaa93a30943889f7384d7d9c2b..0000000000000000000000000000000000000000 --- a/services/src/fileoper/oper_factory.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 "oper_factory.h" - -#include "file_manager_service_def.h" -#include "file_oper.h" -#include "log.h" -#include "media_file_oper.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -unique_ptr OperFactory::GetFileOper(int equipmentId) -{ - unique_ptr fp; - DEBUG_LOG("FileOper %{public}d.", equipmentId); - switch (equipmentId) { - case Equipment::INTERNAL_STORAGE: { - fp = make_unique(); - break; - } - default: { - DEBUG_LOG("default FileOper %{public}d.", equipmentId); - break; - } - } - return fp; -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/oper_factory.h b/services/src/fileoper/oper_factory.h deleted file mode 100644 index 90443b054695ec6866aa735a58b652920c992288..0000000000000000000000000000000000000000 --- a/services/src/fileoper/oper_factory.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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_OPER_FACTORY_H -#define STORAGE_SERVICES_OPER_FACTORY_H -#pragma once - -#include - -#include "file_oper.h" - -namespace OHOS { -namespace FileManagerService { -class OperFactory { -public: - std::unique_ptr GetFileOper(int equipmentId); -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_OPER_FACTORY_H \ No newline at end of file diff --git a/services/src/server/file_manager_service.cpp b/services/src/server/file_manager_service.cpp deleted file mode 100644 index 3cfe1668ade673cecbbd3d15eaf29409a4e76c81..0000000000000000000000000000000000000000 --- a/services/src/server/file_manager_service.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 "file_manager_service.h" - -#include "ext_storage/ext_storage_subscriber.h" -#include "iservice_registry.h" -#include "log.h" -#include "system_ability_definition.h" - -namespace OHOS { -namespace FileManagerService { -REGISTER_SYSTEM_ABILITY_BY_ID(FileManagerService, FILE_MANAGER_SERVICE_ID, true); - -FileManagerService::FileManagerService(int32_t systemAbilityId, bool runOnCreate) - : SystemAbility(systemAbilityId, runOnCreate) {} -void FileManagerService::OnDump() {} - -void FileManagerService::OnStart() -{ - DEBUG_LOG("FileManagerService OnStart"); - bool res = Publish(this); - if (!res) { - ERR_LOG("FileManagerService OnStart invalid"); - } -} - -void FileManagerService::OnStop() -{ - DEBUG_LOG("FileManagerService OnStop"); -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/server/file_manager_service.h b/services/src/server/file_manager_service.h deleted file mode 100644 index 3410c40973e31563e488848469326085990e6c2e..0000000000000000000000000000000000000000 --- a/services/src/server/file_manager_service.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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_FILE_MANAGER_SERVICE_H -#define STORAGE_FILE_MANAGER_SERVICE_H - -#include "file_manager_service_stub.h" -#include "iremote_stub.h" -#include "system_ability.h" - -namespace OHOS { -namespace FileManagerService { -class FileManagerService : public SystemAbility, public FileManagerServiceStub { - DECLARE_SYSTEM_ABILITY(FileManagerService); -public: - DISALLOW_COPY_AND_MOVE(FileManagerService); - explicit FileManagerService(int32_t systemAbilityId, bool runOnCreate = true); - virtual ~FileManagerService() = default; - void OnDump() override; - void OnStart() override; - void OnStop() override; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_SERVICE_H \ No newline at end of file diff --git a/services/src/server/file_manager_service_stub.cpp b/services/src/server/file_manager_service_stub.cpp deleted file mode 100644 index 883e68c88d8e613c9de35dfc63e9c691912eb8c5..0000000000000000000000000000000000000000 --- a/services/src/server/file_manager_service_stub.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 "file_manager_service_stub.h" - -#include "accesstoken_kit.h" -#include "file_manager_service.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "ipc_singleton.h" -#include "ipc_skeleton.h" -#include "log.h" -#include "media_file_utils.h" -#include "oper_factory.h" -#include "sa_mgr_client.h" -#include "string_ex.h" -#include "system_ability_definition.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -static int GetEquipmentCode(uint32_t code) -{ - return (code >> EQUIPMENT_SHIFT) & CODE_MASK; -} - -static int GetOperCode(uint32_t code) -{ - return code & CODE_MASK; -} - -int FileManagerServiceStub::OperProcess(uint32_t code, MessageParcel &data, - MessageParcel &reply) -{ - int equipmentId = GetEquipmentCode(code); - int operCode = GetOperCode(code); - OperFactory factory = OperFactory(); - auto fp = factory.GetFileOper(equipmentId); - if (fp == nullptr) { - ERR_LOG("OnRemoteRequest inner error %{public}d", code); - return FAIL; - } - int errCode = fp->OperProcess(operCode, data, reply); - return errCode; -} - -bool CheckClientPermission(const std::string& permissionStr) -{ - Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); - int res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, - permissionStr); - if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { - ERR_LOG("Have no media permission"); - return false; - } - ERR_LOG("permission check success"); - return true; -} - -int FileManagerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - // check whether request from fms proxy - if (data.ReadInterfaceToken() != GetDescriptor()) { - ERR_LOG("reject error remote request"); - reply.WriteInt32(FAIL); - return FAIL; - } - // change permission string after finishing accessToken - string permission = "ohos.permission.READ_MEDIA"; - if (!CheckClientPermission(permission)) { - ERR_LOG("checkpermission error FAIL"); - reply.WriteInt32(FAIL); - return FAIL; - } - if (!MediaFileUtils::InitHelper(AsObject())) { - ERR_LOG("Init MediaLibraryDataAbility Helper error"); - reply.WriteInt32(FAIL); - return FAIL; - } - // do request process - int32_t errCode = OperProcess(code, data, reply); - reply.WriteInt32(errCode); - return errCode; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/server/file_manager_service_stub.h b/services/src/server/file_manager_service_stub.h deleted file mode 100644 index e00697a98cf0b7bdda1cfd05700fc87ed0ee3143..0000000000000000000000000000000000000000 --- a/services/src/server/file_manager_service_stub.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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_FILE_MANAGER_SERVICE_STUB_H -#define STORAGE_FILE_MANAGER_SERVICE_STUB_H - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "oper_factory.h" - -namespace OHOS { -namespace FileManagerService { -class IFileManagerService : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"IFileManagerService"); -}; - -class FileManagerServiceStub : public IRemoteStub { -public: - FileManagerServiceStub() = default; - virtual ~FileManagerServiceStub() = default; - int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply); - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) override; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_SERVICE_STUB_H \ No newline at end of file diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn deleted file mode 100644 index 1ab8e2a5367bb85dfb5f6bfe2120435e0a842abf..0000000000000000000000000000000000000000 --- a/services/test/BUILD.gn +++ /dev/null @@ -1,126 +0,0 @@ -# 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. - -import("//build/test.gni") -FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" -ohos_unittest("file_manager_proxy_test") { - module_out_path = "filemanagement/user_file_service" - - sources = [ "client/file_manager_proxy_test.cpp" ] - - include_dirs = [ - "//third_party/json/include", - "//base/security/huks/interfaces/innerkits/huks_standard/main/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//third_party/googletest/googlemock/include/gmock", - "//foundation/multimedia/media_library/frameworks/utils/include", - "//foundation/multimedia/media_library/interfaces/inner_api/media_library_helper/include", - ] - - configs = [ "//build/config/compiler:exceptions" ] - - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//third_party/googletest:gmock_main", - ] - - external_deps = [ - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "relational_store:native_rdb", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -ohos_unittest("oper_factory_test") { - module_out_path = "filemanagement/user_file_service" - - sources = [ "fileoper/oper_factory_test.cpp" ] - - include_dirs = [ - "//third_party/json/include", - "//base/security/huks/interfaces/innerkits/huks_standard/main/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//foundation/multimedia/media_library/frameworks/utils/include", - "//foundation/multimedia/media_library/interfaces/inner_api/media_library_helper/include", - ] - - configs = [ "//build/config/compiler:exceptions" ] - - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - ] - - external_deps = [ - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "relational_store:native_appdatafwk", - "relational_store:native_rdb", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -ohos_unittest("file_manager_service_test") { - module_out_path = "filemanagement/user_file_service" - - sources = [ "server/file_manager_service_test.cpp" ] - - include_dirs = [ - "//third_party/json/include", - "//base/security/huks/interfaces/innerkits/huks_standard/main/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//foundation/multimedia/media_library/frameworks/utils/include", - "//foundation/multimedia/media_library/interfaces/inner_api/media_library_helper/include", - ] - - configs = [ "//build/config/compiler:exceptions" ] - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - ] - - external_deps = [ - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "relational_store:native_appdatafwk", - "relational_store:native_rdb", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -group("user_file_manager_test") { - testonly = true - - deps = [ - ":file_manager_proxy_test", - ":file_manager_service_test", - ":oper_factory_test", - ] -} diff --git a/services/test/client/file_manager_proxy_test.cpp b/services/test/client/file_manager_proxy_test.cpp deleted file mode 100644 index 9c47241781df909aeac8cf810e251e2abacecc2a..0000000000000000000000000000000000000000 --- a/services/test/client/file_manager_proxy_test.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 -#include - -#include "file_manager_proxy.h" -#include "fms_manager_proxy_mock.h" -#include "ifms_client.h" - -namespace { -using namespace std; -using namespace OHOS; -using namespace FileManagerService; -class FileManagerProxyTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - cout << "FileManagerProxyTest code test" << endl; - } - static void TearDownTestCase() {}; - void SetUp(); - void TearDown() {}; - std::shared_ptr proxy_ = nullptr; - sptr mock_ = nullptr; -}; - -void FileManagerProxyTest::SetUp() -{ - mock_ = new OHOS::FileManagerService::FmsManagerProxyMock(); - proxy_ = std::make_shared(mock_); -} - -/** - * @tc.number: SUB_STORAGE_File_Manager_Proxy_GetFmsInstance_0000 - * @tc.name: File_Manager_Proxy_GetFmsInstance_0000 - * @tc.desc: Test function of GetFmsInstance interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_GetFmsInstance_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_GetFmsInstance_0000"; - try { - IFmsClient* result = IFmsClient::GetFmsInstance(); - EXPECT_NE(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerProxyTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_GetFmsInstance_0000"; -} - -/** - * @tc.number: SUB_STORAGE_File_Manager_Proxy_Mkdir_0000 - * @tc.name: File_Manager_Proxy_Mkdir_0000 - * @tc.desc: Test function of Mkdir interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_Mkdir_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_Mkdir_0000"; - std::string name = "File_Manager_Proxy_Mkdir_0000"; - std::string path = "dataability:///album"; - EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) - .Times(1) - .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); - int ret = proxy_->Mkdir(name, path); - EXPECT_EQ(ret, 1); - GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_Mkdir_0000"; -} -} // namespace diff --git a/services/test/client/fms_manager_proxy_mock.h b/services/test/client/fms_manager_proxy_mock.h deleted file mode 100644 index 811807ed6f0d52ebdc692ea00dbe1545fb69ab72..0000000000000000000000000000000000000000 --- a/services/test/client/fms_manager_proxy_mock.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 FMS_MANAGER_PROXY_MOCK_H -#define FMS_MANAGER_PROXY_MOCK_H -#include -#include "gmock/gmock.h" -#include "iremote_stub.h" -#include "iremote_proxy.h" -#include "ifms_client.h" -#include "cmd_response.h" - -namespace OHOS { -namespace FileManagerService { -class FmsManagerProxyMock : public IRemoteStub, public IFmsClient { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"FmsManagerProxyMock"); - FmsManagerProxyMock() {} - virtual ~FmsManagerProxyMock() {} - MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); - int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) - { - sptr cmdResponse = new CmdResponse(); - reply.WriteParcelable(cmdResponse); - return ERR_NONE; - } - virtual int Mkdir(const std::string &name, const std::string &path) override - { - return ERR_NONE; - } - virtual int ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) override - { - return ERR_NONE; - } - virtual int GetRoot(const CmdOptions &option, std::vector> &fileRes) override - { - return ERR_NONE; - } - virtual int CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) override - { - return ERR_NONE; - } -}; -} // namespace FileManagerService -} // namespace OHOS - -#endif // FMS_MANAGER_PROXY_MOCK_H \ No newline at end of file diff --git a/services/test/fileoper/oper_factory_test.cpp b/services/test/fileoper/oper_factory_test.cpp deleted file mode 100644 index 38b01c1c2be256491e69c5b532a5a73a7c4f588d..0000000000000000000000000000000000000000 --- a/services/test/fileoper/oper_factory_test.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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 -#include - -#include "abs_shared_result_set.h" -#include "file_manager_service_def.h" -#include "file_manager_service_stub.h" -#include "medialibrary_db_const.h" - -namespace { -using namespace std; -using namespace OHOS; -using namespace FileManagerService; -class OperFactoryTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - cout << "OperFactoryTest code test" << endl; - } - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; - -/** - * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0000 - * @tc.name: oper_factory_GetFileOper_0000 - * @tc.desc: Test function of GetFileOper interface for SUCCESS which INTERNAL_STORAGE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0000"; - try { - OperFactory *oper = new OperFactory(); - std::unique_ptr result; - if (oper != nullptr) { - result = oper->GetFileOper(Equipment::INTERNAL_STORAGE); - } - EXPECT_NE(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0000"; -} - -/** - * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0001 - * @tc.name: oper_factory_GetFileOper_0001 - * @tc.desc: Test function of GetFileOper for SUCCESS which EXTERNAL_STORAGE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0001"; - try { - OperFactory *oper = new OperFactory(); - std::unique_ptr result; - if (oper != nullptr) { - result = oper->GetFileOper(Equipment::EXTERNAL_STORAGE); - } - EXPECT_NE(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0001"; -} - -/** - * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0002 - * @tc.name: oper_factory_GetFileOper_0002 - * @tc.desc: Test function of GetFileOper interface for SUCCESS which default. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0002"; - try { - OperFactory *oper = new OperFactory(); - std::unique_ptr result; - if (oper != nullptr) { - result = oper->GetFileOper(3); - } - EXPECT_EQ(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0002"; -} -} // namespace diff --git a/services/test/server/file_manager_service_test.cpp b/services/test/server/file_manager_service_test.cpp deleted file mode 100644 index 3b572f0b4a3a580d83fa0dbd478303a559a4bdbb..0000000000000000000000000000000000000000 --- a/services/test/server/file_manager_service_test.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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 -#include - -#include "abs_shared_result_set.h" -#include "file_info.h" -#include "file_manager_service.h" -#include "file_manager_service_def.h" -#include "file_manager_service_stub.h" -#include "ifms_client.h" -#include "medialibrary_db_const.h" -#include "media_file_oper.h" - -namespace { -using namespace std; -using namespace OHOS; -using namespace FileManagerService; -class FileManagerServiceTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - cout << "FileManagerServiceTest code test" << endl; - } - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; - -/** - * @tc.number: SUB_STORAGE_file_Manager_Service_OnDump_0000 - * @tc.name: file_Manager_Service_OnDump_0000 - * @tc.desc: Test function of OnDump interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnDump_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnDump_0000"; - try { - OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr) { - service->OnDump(); - } - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnDump_0000"; -} - -/** - * @tc.number: SUB_STORAGE_file_Manager_Service_OnStart_0000 - * @tc.name: file_Manager_Service_OnStart_0000 - * @tc.desc: Test function of OnStart interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnStart_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStart_0000"; - try { - OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr) { - service->OnStart(); - } - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStart_0000"; -} - -/** - * @tc.number: SUB_STORAGE_file_Manager_Service_OnStop_0000 - * @tc.name: file_Manager_Service_OnStop_0000 - * @tc.desc: Test function of OnStop interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerServiceTest, Ffile_Manager_Service_OnStop_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStop_0000"; - try { - OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr) { - service->OnStop(); - } - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStop_0000"; -} -} // namespace