diff --git a/bundle.json b/bundle.json index 32a20417dfdd506f5e14ee4c9a607fdead18c80b..4a2cca14639c3bbd240ef2c3b14f940c7cd55d3b 100644 --- a/bundle.json +++ b/bundle.json @@ -35,8 +35,7 @@ "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/frameworks/innerkits:frameworks_innerkits" + "//foundation/filemanagement/user_file_service/interfaces/kits/js:filemanager" ], "test": [ "//foundation/filemanagement/user_file_service/services/test:user_file_manager_test" diff --git a/frameworks/innerkits/file_access/BUILD.gn b/frameworks/innerkits/file_access/BUILD.gn index 79a2c34095416004d5280e1313acad1497097864..30d9b2ccc1021e5ea0144b1162d799d2d41a407c 100644 --- a/frameworks/innerkits/file_access/BUILD.gn +++ b/frameworks/innerkits/file_access/BUILD.gn @@ -47,11 +47,17 @@ config("ability_public_config") { } ohos_shared_library("file_access_extension_ability_kit") { - include_dirs = [] + include_dirs = [ "//foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context" ] sources = [ "src/file_access_ext_ability.cpp", + "src/file_access_ext_connection.cpp", + "src/file_access_ext_proxy.cpp", + "src/file_access_ext_stub.cpp", + "src/file_access_ext_stub_impl.cpp", + "src/file_access_helper.cpp", "src/js_file_access_ext_ability.cpp", + "src/napi_common_fileaccess.cpp", ] configs = [ ":ability_config" ] public_configs = [ diff --git a/frameworks/innerkits/file_access/include/file_access_ext_ability.h b/frameworks/innerkits/file_access/include/file_access_ext_ability.h index 255a01f98b82edaebabe35e1ff2bf7ea54b333f3..7689afb012fc2e765a6746b0093e6616db4b2827 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_ability.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_ability.h @@ -17,6 +17,7 @@ #define FILE_EXT_ABILITY_H #include "extension_base.h" +#include "file_access_extension_info.h" namespace OHOS { namespace AbilityRuntime { @@ -37,6 +38,16 @@ public: const sptr &token) override; static FileAccessExtAbility* Create(const std::unique_ptr& runtime); + + virtual int OpenFile(const Uri &uri, int flags); + virtual int CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile); + virtual int Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile); + virtual int Delete(const Uri &sourceFile); + virtual int Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile); + virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile); + + virtual std::vector ListFile(const Uri &sourceFile); + virtual std::vector GetRoots(); static void SetCreator(const CreatorFunc& creator); private: static CreatorFunc creator_; diff --git a/frameworks/innerkits/file_access/include/file_access_ext_connection.h b/frameworks/innerkits/file_access/include/file_access_ext_connection.h new file mode 100644 index 0000000000000000000000000000000000000000..e47b0cffd9a9cd1cb0abdcc1414f3caf827135d0 --- /dev/null +++ b/frameworks/innerkits/file_access/include/file_access_ext_connection.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 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 FILE_EXT_CONNECTION_H +#define FILE_EXT_CONNECTION_H + +#include + +#include "ability_connect_callback_stub.h" +#include "event_handler.h" +#include "ifile_access_ext_base.h" +#include "want.h" + +namespace OHOS { +namespace FileAccessFwk { +class FileAccessExtConnection : public AAFwk::AbilityConnectionStub { +public: + FileAccessExtConnection() = default; + virtual ~FileAccessExtConnection() = default; + + static sptr GetInstance(); + + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; + + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; + + void ConnectFileExtAbility(const AAFwk::Want &want, const sptr &token); + + void DisconnectFileExtAbility(); + + bool IsExtAbilityConnected(); + + sptr GetFileExtProxy(); + +private: + static sptr instance_; + static std::mutex mutex_; + std::atomic isConnected_ = {false}; + sptr fileExtProxy_; +}; +} // namespace FileAccessFwk +} // namespace OHOS +#endif // FILE_EXT_CONNECTION_H diff --git a/frameworks/innerkits/file_access/include/file_access_ext_proxy.h b/frameworks/innerkits/file_access/include/file_access_ext_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..d4918e22c9c5107d9f5e83953be78387cad94773 --- /dev/null +++ b/frameworks/innerkits/file_access/include/file_access_ext_proxy.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 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 FILE_EXT_PROXY_H +#define FILE_EXT_PROXY_H + +#include + +#include "file_access_extension_info.h" +#include "ifile_access_ext_base.h" + +namespace OHOS { +namespace FileAccessFwk { +class FileAccessExtProxy : public IRemoteProxy { +public: + explicit FileAccessExtProxy(const sptr& remote) : IRemoteProxy(remote) {} + + virtual ~FileAccessExtProxy() {} + + virtual int OpenFile(const Uri &uri, int flags) override; + virtual int CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile) override; + virtual int Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) override; + virtual int Delete(const Uri &sourceFile) override; + virtual int Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) override; + virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) override; + + virtual std::vector ListFile(const Uri &sourceFile) override; + virtual std::vector GetRoots() override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace FileAccessFwk +} // namespace OHOS +#endif // FILE_EXT_PROXY_H diff --git a/frameworks/innerkits/file_access/include/js_file_access_ext_ability.h b/frameworks/innerkits/file_access/include/js_file_access_ext_ability.h index 8ac3b18d35db49103380f3f18940af83da2ecee7..49d26194d18b5db388475caaae0850f78016741e 100644 --- a/frameworks/innerkits/file_access/include/js_file_access_ext_ability.h +++ b/frameworks/innerkits/file_access/include/js_file_access_ext_ability.h @@ -17,14 +17,32 @@ #define JS_FILE_EXT_ABILITY_H #include "file_access_ext_ability.h" - +#include "file_access_extension_info.h" #include "js_runtime.h" +#include "napi_common_fileaccess.h" #include "native_engine/native_reference.h" #include "native_engine/native_value.h" namespace OHOS { namespace FileAccessFwk { using namespace AbilityRuntime; + +struct ThreadLockInfo { + std::mutex fileOperateMutex; + std::condition_variable fileOperateCondition; + bool isReady = false; +}; + +struct CallbackParam { + ThreadLockInfo *lockInfo; + JsRuntime &jsRuntime; + std::shared_ptr jsObj; + const char *funcName; + NativeValue * const *argv; + size_t argc; + NativeValue *result; +}; + class JsFileAccessExtAbility : public FileAccessExtAbility { public: JsFileAccessExtAbility(JsRuntime& jsRuntime); @@ -36,16 +54,22 @@ public: const std::shared_ptr &application, std::shared_ptr &handler, const sptr &token) override; - void OnStart(const AAFwk::Want &want) override; - sptr OnConnect(const AAFwk::Want &want) override; - + int OpenFile(const Uri &uri, int flags) override; + int CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile) override; + int Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) override; + int Delete(const Uri &sourceFile) override; + int Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) override; + int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) override; + std::vector ListFile(const Uri &sourceFile) override; + std::vector GetRoots() override; private: + NativeValue* AsnycCallObjectMethod(const char *name, NativeValue * const *argv = nullptr, size_t argc = 0); NativeValue* CallObjectMethod(const char *name, NativeValue * const *argv = nullptr, size_t argc = 0); void GetSrcPath(std::string &srcPath); - JsRuntime& jsRuntime_; + JsRuntime &jsRuntime_; std::shared_ptr jsObj_; }; } // namespace FileAccessFwk diff --git a/frameworks/innerkits/file_access/src/file_access_ext_ability.cpp b/frameworks/innerkits/file_access/src/file_access_ext_ability.cpp index c4f0790780f7deccb35ed5a5ce21293b3e4b230e..a570e63dfeb44e19b89cac3d42911277400e88fe 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_ability.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_ability.cpp @@ -18,6 +18,7 @@ #include "ability_loader.h" #include "connection_manager.h" #include "extension_context.h" +#include "file_access_framework_errno.h" #include "hilog_wrapper.h" #include "js_file_access_ext_ability.h" #include "runtime.h" @@ -56,5 +57,47 @@ void FileAccessExtAbility::Init(const std::shared_ptr &recor { ExtensionBase<>::Init(record, application, handler, token); } + +int FileAccessExtAbility::OpenFile(const Uri &uri, int flags) +{ + return ERR_OK; +} + +int FileAccessExtAbility::CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile) +{ + return ERR_OK; +} + +int FileAccessExtAbility::Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) +{ + return ERR_OK; +} + +int FileAccessExtAbility::Delete(const Uri &sourceFile) +{ + return ERR_OK; +} + +int FileAccessExtAbility::Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) +{ + return ERR_OK; +} + +int FileAccessExtAbility::Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) +{ + return ERR_OK; +} + +std::vector FileAccessExtAbility::ListFile(const Uri &sourceFile) +{ + std::vector vec; + return vec; +} + +std::vector FileAccessExtAbility::GetRoots() +{ + std::vector vec; + return vec; +} } // namespace FileAccessFwk } // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp b/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7e9604213e8ac10430d82dd8cc09d3760a57b9b --- /dev/null +++ b/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 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_access_ext_connection.h" + +#include "ability_manager_client.h" +#include "file_access_ext_proxy.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace FileAccessFwk { +sptr FileAccessExtConnection::instance_ = nullptr; +std::mutex FileAccessExtConnection::mutex_; + +sptr FileAccessExtConnection::GetInstance() +{ + if (instance_ == nullptr) { + std::lock_guard lock(mutex_); + if (instance_ == nullptr) { + instance_ = sptr(new (std::nothrow) FileAccessExtConnection()); + } + } + return instance_; +} + +void FileAccessExtConnection::OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) +{ + if (remoteObject == nullptr) { + HILOG_ERROR("%{public}s failed, remote is nullptr", __func__); + return; + } + fileExtProxy_ = iface_cast(remoteObject); + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("%{public}s failed, fileExtProxy_ is nullptr", __func__); + return; + } + isConnected_.store(true); +} + +void FileAccessExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) +{ + fileExtProxy_ = nullptr; + isConnected_.store(false); +} + +void FileAccessExtConnection::ConnectFileExtAbility(const AAFwk::Want &want, const sptr &token) +{ + ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, token); + HILOG_INFO("%{public}s called end, ret=%{public}d", __func__, ret); +} + +void FileAccessExtConnection::DisconnectFileExtAbility() +{ + fileExtProxy_ = nullptr; + isConnected_.store(false); + ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(this); + HILOG_INFO("%{public}s called end, ret=%{public}d", __func__, ret); +} + +bool FileAccessExtConnection::IsExtAbilityConnected() +{ + return isConnected_.load(); +} + +sptr FileAccessExtConnection::GetFileExtProxy() +{ + return fileExtProxy_; +} +} // namespace FileAccessFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..129d687d54585a4772b6fd838b654d5c41bab5a8 --- /dev/null +++ b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp @@ -0,0 +1,338 @@ +/* + * Copyright (c) 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_access_ext_proxy.h" +#include "file_access_framework_errno.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace FileAccessFwk { +int FileAccessExtProxy::OpenFile(const Uri &uri, int flags) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&uri)) { + HILOG_ERROR("%{public}s fail to WriteParcelable uri", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteInt32(flags)) { + HILOG_ERROR("%{public}s fail to WriteString mode", __func__); + return ERR_IPC_ERROR; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_OPEN_FILE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("%{public}s fail to SendRequest. err: %d", __func__, err); + return ERR_IPC_ERROR; + } + + int fd = reply.ReadFileDescriptor(); + if (fd <= ERR_ERROR) { + HILOG_ERROR("%{public}s fail to ReadFileDescriptor fd", __func__); + return ERR_IPC_ERROR; + } + return fd; +} + +int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&parent)) { + HILOG_ERROR("%{public}s fail to WriteParcelable parent", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("%{public}s fail to WriteString mode", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&newFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); + return ERR_IPC_ERROR; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_CREATE_FILE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("%{public}s fail to SendRequest. err: %d", __func__, err); + return ERR_IPC_ERROR; + } + + int ret = reply.ReadInt32(); + if (ret < ERR_OK) { + HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); + return ERR_IPC_ERROR; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("%{public}s ReadParcelable value is nullptr.", __func__); + return ERR_IPC_ERROR; + } + + newFile = Uri(*tempUri); + return ret; +} + +int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&parent)) { + HILOG_ERROR("%{public}s fail to WriteParcelable parent", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("%{public}s fail to WriteString displayName", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&newFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); + return ERR_IPC_ERROR; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_MKDIR, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("%{public}s fail to SendRequest. err: %d", __func__, err); + return ERR_IPC_ERROR; + } + + int ret = reply.ReadInt32(); + if (ret < ERR_OK) { + HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); + return ERR_IPC_ERROR; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("%{public}s ReadParcelable value is nullptr.", __func__); + ret = ERR_IPC_ERROR; + return ret; + } + + newFile = Uri(*tempUri); + return ret; +} + +int FileAccessExtProxy::Delete(const Uri &sourceFile) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&sourceFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable sourceFile", __func__); + return ERR_IPC_ERROR; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_DELETE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("%{public}s fail to SendRequest. err: %d", __func__, err); + return ERR_IPC_ERROR; + } + + int ret = reply.ReadInt32(); + if (ret < ERR_OK) { + HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); + return ERR_IPC_ERROR; + } + + return ret; +} + +int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR(" %{public}s WriteInterfaceToken failed", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&sourceFile)) { + HILOG_ERROR(" %{public}s fail to WriteParcelable sourceFile", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&targetParent)) { + HILOG_ERROR(" %{public}s fail to WriteParcelable targetParent", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&newFile)) { + HILOG_ERROR(" %{public}s fail to WriteParcelable newFile", __func__); + return ERR_IPC_ERROR; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_MOVE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR(" %{public}s fail to SendRequest. err: %d", __func__, err); + return ERR_IPC_ERROR; + } + + int ret = reply.ReadInt32(); + if (ret < ERR_OK) { + HILOG_ERROR(" %{public}s fail to ReadInt32 ret", __func__); + return ret; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR(" %{public}s ReadParcelable value is nullptr.", __func__); + return ERR_IPC_ERROR; + } + + newFile = Uri(*tempUri); + return ret; +} + +int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&sourceFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable sourceFile", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("%{public}s fail to WriteString displayName", __func__); + return ERR_IPC_ERROR; + } + + if (!data.WriteParcelable(&newFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); + return ERR_IPC_ERROR; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_RENAME, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("%{public}s fail to SendRequest. err: %d", __func__, err); + return ERR_IPC_ERROR; + } + + int ret = reply.ReadInt32(); + if (ret < ERR_OK) { + HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); + return ERR_IPC_ERROR; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("%{public}s ReadParcelable value is nullptr.", __func__); + return ERR_IPC_ERROR; + } + + newFile = Uri(*tempUri); + return ret; +} + +std::vector FileAccessExtProxy::ListFile(const Uri &sourceFile) +{ + std::vector vec; + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return vec; + } + + if (!data.WriteParcelable(&sourceFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable sourceFileUri", __func__); + return vec; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_LIST_FILE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("%{public}s fail to SendRequest. err: %d", __func__, err); + return vec; + } + + vec.clear(); + int64_t count = reply.ReadInt64(); + for (int32_t i = 0; i < count; i++) { + std::unique_ptr fileInfo(reply.ReadParcelable()); + if (fileInfo != nullptr) { + vec.push_back(*fileInfo); + } + } + + return vec; +} + +std::vector FileAccessExtProxy::GetRoots() +{ + std::vector vec; + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return vec; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_GET_ROOTS, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("%{public}s fail to SendRequest. err: %d", __func__, err); + return vec; + } + + vec.clear(); + uint64_t count = reply.ReadUint64(); + for (uint64_t i = 0; i < count; i++) { + std::unique_ptr deviceInfo(reply.ReadParcelable()); + if (deviceInfo != nullptr) { + vec.push_back(*deviceInfo); + } + } + + return vec; +} +} // namespace FileAccessFwk +} // namespace OHOS