From 389e13432e6d2595123a4401f085e91f62c8bba3 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Mon, 27 Jun 2022 11:18:34 +0800 Subject: [PATCH 1/5] add extenstion code Signed-off-by: wangjianqiang --- frameworks/innerkits/file_access/BUILD.gn | 8 +- .../include/file_access_ext_ability.h | 11 +++ .../include/file_access_ext_connection.h | 56 +++++++++++++ .../include/js_file_access_ext_ability.h | 32 ++++++- .../src/file_access_ext_ability.cpp | 43 ++++++++++ .../src/file_access_ext_connection.cpp | 84 +++++++++++++++++++ 6 files changed, 231 insertions(+), 3 deletions(-) create mode 100644 frameworks/innerkits/file_access/include/file_access_ext_connection.h create mode 100644 frameworks/innerkits/file_access/src/file_access_ext_connection.cpp diff --git a/frameworks/innerkits/file_access/BUILD.gn b/frameworks/innerkits/file_access/BUILD.gn index 79a2c340..30d9b2cc 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 255a01f9..7689afb0 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 00000000..e47b0cff --- /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/js_file_access_ext_ability.h b/frameworks/innerkits/file_access/include/js_file_access_ext_ability.h index 8ac3b18d..9a0eca63 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); @@ -41,11 +59,21 @@ public: 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 c4f07907..a570e63d 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 00000000..45f0b67a --- /dev/null +++ b/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp @@ -0,0 +1,84 @@ +/* + * 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 -- Gitee From 422b188ecc4030b635c5f4be67f40eeeaed85ee5 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Mon, 27 Jun 2022 11:20:47 +0800 Subject: [PATCH 2/5] add file extension code Signed-off-by: wangjianqiang --- .../include/file_access_ext_proxy.h | 47 +++ .../file_access/src/file_access_ext_proxy.cpp | 347 ++++++++++++++++++ 2 files changed, 394 insertions(+) create mode 100644 frameworks/innerkits/file_access/include/file_access_ext_proxy.h create mode 100644 frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp 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 00000000..51437ecf --- /dev/null +++ b/frameworks/innerkits/file_access/include/file_access_ext_proxy.h @@ -0,0 +1,47 @@ +/* + * 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/src/file_access_ext_proxy.cpp b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp new file mode 100644 index 00000000..55a9d526 --- /dev/null +++ b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp @@ -0,0 +1,347 @@ +/* + * 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) +{ + int fd = ERR_ERROR; + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return fd; + } + + if (!data.WriteParcelable(&uri)) { + HILOG_ERROR("%{public}s fail to WriteParcelable uri", __func__); + return fd; + } + + if (!data.WriteInt32(flags)) { + HILOG_ERROR("%{public}s fail to WriteString mode", __func__); + return fd; + } + + 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 fd; + } + + fd = reply.ReadFileDescriptor(); + if (fd == ERR_ERROR) { + HILOG_ERROR("%{public}s fail to ReadFileDescriptor fd", __func__); + return fd; + } + return fd; +} + +int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile) +{ + int ret = ERR_ERROR; + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&parent)) { + HILOG_ERROR("%{public}s fail to WriteParcelable parent", __func__); + return ret; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("%{public}s fail to WriteString mode", __func__); + return ret; + } + + if (!data.WriteParcelable(&newFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); + return ret; + } + + 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 ret; + } + + 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__); + ret = ERR_ERROR; + return ret; + } + + newFile = Uri(*tempUri); + return ret; +} + +int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) +{ + int ret = ERR_ERROR; + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&parent)) { + HILOG_ERROR("%{public}s fail to WriteParcelable parent", __func__); + return ret; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("%{public}s fail to WriteString displayName", __func__); + return ret; + } + + if (!data.WriteParcelable(&newFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); + return ret; + } + + 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 ret; + } + + 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__); + ret = ERR_ERROR; + return ret; + } + + newFile = Uri(*tempUri); + return ret; +} + +int FileAccessExtProxy::Delete(const Uri &sourceFile) +{ + int ret = ERR_ERROR; + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&sourceFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable sourceFile", __func__); + return ret; + } + + 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 ret; + } + + ret = reply.ReadInt32(); + if (ret < ERR_OK) { + HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); + return ret; + } + + return ret; +} + +int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) +{ + int ret = ERR_ERROR; + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR(" %{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&sourceFile)) { + HILOG_ERROR(" %{public}s fail to WriteParcelable sourceFile", __func__); + return ret; + } + + if (!data.WriteParcelable(&targetParent)) { + HILOG_ERROR(" %{public}s fail to WriteParcelable targetParent", __func__); + return ret; + } + + if (!data.WriteParcelable(&newFile)) { + HILOG_ERROR(" %{public}s fail to WriteParcelable newFile", __func__); + return ret; + } + + 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 ret; + } + + 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__); + ret = ERR_ERROR; + return ret; + } + + newFile = Uri(*tempUri); + return ret; +} + +int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) +{ + int ret = ERR_ERROR; + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&sourceFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable sourceFile", __func__); + return ret; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("%{public}s fail to WriteString displayName", __func__); + return ret; + } + + if (!data.WriteParcelable(&newFile)) { + HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); + return ret; + } + + 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 ret; + } + + 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__); + ret = ERR_ERROR; + return ret; + } + + 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 -- Gitee From 8b15ad784852bf9fc42fc55d8fb9c42b1e8dc4df Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Tue, 28 Jun 2022 09:11:49 +0800 Subject: [PATCH 3/5] add file extension code Signed-off-by: wangjianqiang --- bundle.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bundle.json b/bundle.json index edb76103..d0045a52 100644 --- a/bundle.json +++ b/bundle.json @@ -35,9 +35,8 @@ "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/napi/file_access_ext_ability:fileaccessextensionability_napi" + "//foundation/filemanagement/user_file_service/interfaces/kits/js:filemanager" + ], "test": [ "//foundation/filemanagement/user_file_service/services/test:user_file_manager_test" -- Gitee From 46e8eb20808ae1eede901be13f6aed95d6819278 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Tue, 28 Jun 2022 22:50:07 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=91=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjianqiang --- .../include/file_access_ext_proxy.h | 1 - .../include/js_file_access_ext_ability.h | 4 - .../src/file_access_ext_connection.cpp | 1 - .../file_access/src/file_access_ext_proxy.cpp | 93 ++-- .../napi_fileaccess_helper.cpp | 524 ++++++++++++++++++ 5 files changed, 566 insertions(+), 57 deletions(-) create mode 100644 interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp diff --git a/frameworks/innerkits/file_access/include/file_access_ext_proxy.h b/frameworks/innerkits/file_access/include/file_access_ext_proxy.h index 51437ecf..d4918e22 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_proxy.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_proxy.h @@ -44,4 +44,3 @@ private: } // 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 9a0eca63..49d26194 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 @@ -54,18 +54,14 @@ 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: diff --git a/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp b/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp index 45f0b67a..e7e96042 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp @@ -19,7 +19,6 @@ #include "file_access_ext_proxy.h" #include "hilog_wrapper.h" - namespace OHOS { namespace FileAccessFwk { sptr FileAccessExtConnection::instance_ = nullptr; diff --git a/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp index 55a9d526..195cbbe4 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp @@ -21,21 +21,20 @@ namespace OHOS { namespace FileAccessFwk { int FileAccessExtProxy::OpenFile(const Uri &uri, int flags) { - int fd = ERR_ERROR; MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return fd; + return ERR_ERROR; } if (!data.WriteParcelable(&uri)) { HILOG_ERROR("%{public}s fail to WriteParcelable uri", __func__); - return fd; + return ERR_ERROR; } if (!data.WriteInt32(flags)) { HILOG_ERROR("%{public}s fail to WriteString mode", __func__); - return fd; + return ERR_ERROR; } MessageParcel reply; @@ -43,39 +42,38 @@ int FileAccessExtProxy::OpenFile(const Uri &uri, int flags) 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 fd; + return ERR_ERROR; } - fd = reply.ReadFileDescriptor(); - if (fd == ERR_ERROR) { + int fd = reply.ReadFileDescriptor(); + if (fd <= ERR_OK) { HILOG_ERROR("%{public}s fail to ReadFileDescriptor fd", __func__); - return fd; + return ERR_ERROR; } return fd; } int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile) { - int ret = ERR_ERROR; MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&parent)) { HILOG_ERROR("%{public}s fail to WriteParcelable parent", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteString(displayName)) { HILOG_ERROR("%{public}s fail to WriteString mode", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&newFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); - return ret; + return ERR_ERROR; } MessageParcel reply; @@ -83,20 +81,19 @@ int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &display 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 ret; + return ERR_ERROR; } - ret = reply.ReadInt32(); + int ret = reply.ReadInt32(); if (ret < ERR_OK) { HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); - return ret; + return ERR_ERROR; } std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR("%{public}s ReadParcelable value is nullptr.", __func__); - ret = ERR_ERROR; - return ret; + return ERR_ERROR; } newFile = Uri(*tempUri); @@ -105,26 +102,25 @@ int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &display int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) { - int ret = ERR_ERROR; MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&parent)) { HILOG_ERROR("%{public}s fail to WriteParcelable parent", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteString(displayName)) { HILOG_ERROR("%{public}s fail to WriteString displayName", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&newFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); - return ret; + return ERR_ERROR; } MessageParcel reply; @@ -132,13 +128,13 @@ int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName, 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 ret; + return ERR_ERROR; } - ret = reply.ReadInt32(); + int ret = reply.ReadInt32(); if (ret < ERR_OK) { HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); - return ret; + return ERR_ERROR; } std::unique_ptr tempUri(reply.ReadParcelable()); @@ -154,16 +150,15 @@ int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName, int FileAccessExtProxy::Delete(const Uri &sourceFile) { - int ret = ERR_ERROR; MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&sourceFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable sourceFile", __func__); - return ret; + return ERR_ERROR; } MessageParcel reply; @@ -171,13 +166,13 @@ int FileAccessExtProxy::Delete(const Uri &sourceFile) 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 ret; + return ERR_ERROR; } - ret = reply.ReadInt32(); + int ret = reply.ReadInt32(); if (ret < ERR_OK) { HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); - return ret; + return ERR_ERROR; } return ret; @@ -185,26 +180,25 @@ int FileAccessExtProxy::Delete(const Uri &sourceFile) int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) { - int ret = ERR_ERROR; MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR(" %{public}s WriteInterfaceToken failed", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&sourceFile)) { HILOG_ERROR(" %{public}s fail to WriteParcelable sourceFile", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&targetParent)) { HILOG_ERROR(" %{public}s fail to WriteParcelable targetParent", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&newFile)) { HILOG_ERROR(" %{public}s fail to WriteParcelable newFile", __func__); - return ret; + return ERR_ERROR; } MessageParcel reply; @@ -212,10 +206,10 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri 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 ret; + return ERR_ERROR; } - ret = reply.ReadInt32(); + int ret = reply.ReadInt32(); if (ret < ERR_OK) { HILOG_ERROR(" %{public}s fail to ReadInt32 ret", __func__); return ret; @@ -224,8 +218,7 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR(" %{public}s ReadParcelable value is nullptr.", __func__); - ret = ERR_ERROR; - return ret; + return ERR_ERROR; } newFile = Uri(*tempUri); @@ -234,26 +227,25 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) { - int ret = ERR_ERROR; MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&sourceFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable sourceFile", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteString(displayName)) { HILOG_ERROR("%{public}s fail to WriteString displayName", __func__); - return ret; + return ERR_ERROR; } if (!data.WriteParcelable(&newFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); - return ret; + return ERR_ERROR; } MessageParcel reply; @@ -261,20 +253,19 @@ int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &display 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 ret; + return ERR_ERROR; } - ret = reply.ReadInt32(); + int ret = reply.ReadInt32(); if (ret < ERR_OK) { HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); - return ret; + return ERR_ERROR; } std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR("%{public}s ReadParcelable value is nullptr.", __func__); - ret = ERR_ERROR; - return ret; + return ERR_ERROR; } newFile = Uri(*tempUri); diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp new file mode 100644 index 00000000..6a09d304 --- /dev/null +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -0,0 +1,524 @@ +napi_value NAPI_Rename(napi_env env, napi_callback_info info) +{ + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { + HILOG_ERROR("%{public}s, Number of arguments unmatched.", __func__); + UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + return nullptr; + } + if (funcArg.GetArgc() == NARG_CNT::THREE && !NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_function)) { + UniError(EINVAL).ThrowErr(env, "Type of arguments unmatched"); + return nullptr; + } + FileAccessHelperRenameCB *renameCB = new (std::nothrow) FileAccessHelperRenameCB; + if (renameCB == nullptr) { + HILOG_ERROR("%{public}s, renameCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + renameCB->cbBase.cbInfo.env = env; + renameCB->cbBase.asyncWork = nullptr; + renameCB->cbBase.deferred = nullptr; + renameCB->cbBase.ability = nullptr; + + napi_value ret = RenameWrap(env, info, renameCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s,ret == nullptr", __func__); + if (renameCB != nullptr) { + delete renameCB; + renameCB = nullptr; + } + ret = WrapVoidToJS(env); + } + return ret; +} + +napi_value RenameWrap(napi_env env, napi_callback_info info, FileAccessHelperRenameCB *renameCB) +{ + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valueType)); + if (valueType != napi_string) { + UniError(EINVAL).ThrowErr(env, "Type of arguments unmatched"); + return nullptr; + } + renameCB->sourceFileUri = NapiValueToStringUtf8(env, args[PARAM0]); + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valueType)); + if (valueType != napi_string) { + UniError(EINVAL).ThrowErr(env, "Type of arguments unmatched"); + return nullptr; + } + renameCB->displayName = NapiValueToStringUtf8(env, args[PARAM1]); + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + renameCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = RenameAsync(env, args, ARGS_TWO, renameCB); + } else { + ret = RenamePromise(env, renameCB); + } + return ret; +} + +napi_value RenameAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperRenameCB *renameCB) +{ + if (args == nullptr || renameCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valueType)); + if (valueType == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &renameCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + RenameExecuteCB, + RenameAsyncCompleteCB, + (void *)renameCB, + &renameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, renameCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + return result; +} + +napi_value RenamePromise(napi_env env, FileAccessHelperRenameCB *renameCB) +{ + if (renameCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + renameCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + RenameExecuteCB, + RenamePromiseCompleteCB, + (void *)renameCB, + &renameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, renameCB->cbBase.asyncWork)); + return promise; +} + +void RenameExecuteCB(napi_env env, void *data) +{ + FileAccessHelperRenameCB *renameCB = static_cast(data); + renameCB->execResult = ERR_ERROR; + if (renameCB->fileAccessHelper == nullptr) { + HILOG_ERROR("NAPI_Rename, fileAccessHelper == nullptr"); + return ; + } + if (renameCB->sourceFileUri.empty()) { + HILOG_ERROR("NAPI_Rename, fileAccessHelper sourceFileUri is empty"); + return ; + } + OHOS::Uri sourceFileUri(renameCB->sourceFileUri); + std::string newFile = ""; + OHOS::Uri newFileUri(newFile); + int err = renameCB->fileAccessHelper->Rename(sourceFileUri, renameCB->displayName, newFileUri); + renameCB->result = newFileUri.ToString(); + renameCB->execResult = err; +} + +void RenameAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + FileAccessHelperRenameCB *renameCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, renameCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, renameCB->execResult); + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, renameCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (renameCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, renameCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, renameCB->cbBase.asyncWork)); + delete renameCB; + renameCB = nullptr; +} + +void RenamePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + FileAccessHelperRenameCB *renameCB = static_cast(data); + napi_value result = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, renameCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, renameCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, renameCB->cbBase.asyncWork)); + delete renameCB; + renameCB = nullptr; +} + +napi_value NAPI_ListFile(napi_env env, napi_callback_info info) +{ + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { + HILOG_ERROR("%{public}s, Number of arguments unmatched.", __func__); + UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + return nullptr; + } + if (funcArg.GetArgc() == NARG_CNT::TWO && !NVal(env, funcArg[NARG_POS::SECOND]).TypeIs(napi_function)) { + UniError(EINVAL).ThrowErr(env, "Type of arguments unmatched"); + return nullptr; + } + + FileAccessHelperListFileCB *listFileCB = new (std::nothrow) FileAccessHelperListFileCB; + if (listFileCB == nullptr) { + HILOG_ERROR("%{public}s, listFileCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + listFileCB->cbBase.cbInfo.env = env; + listFileCB->cbBase.asyncWork = nullptr; + listFileCB->cbBase.deferred = nullptr; + listFileCB->cbBase.ability = nullptr; + + napi_value ret = ListFileWrap(env, info, listFileCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s,ret == nullptr", __func__); + if (listFileCB != nullptr) { + delete listFileCB; + listFileCB = nullptr; + } + ret = WrapVoidToJS(env); + } + return ret; +} + +napi_value ListFileWrap(napi_env env, napi_callback_info info, FileAccessHelperListFileCB *listFileCB) +{ + size_t argcAsync = ARGS_TWO; + const size_t argcPromise = ARGS_ONE; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valueType)); + if (valueType != napi_string) { + UniError(EINVAL).ThrowErr(env, "Type of arguments unmatched"); + return nullptr; + } + listFileCB->sourceFileUri = NapiValueToStringUtf8(env, args[PARAM0]); + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + listFileCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = ListFileAsync(env, args, ARGS_ONE, listFileCB); + } else { + ret = ListFilePromise(env, listFileCB); + } + return ret; +} + +napi_value ListFileAsync(napi_env env, + napi_value *args, + const size_t argCallback, + FileAccessHelperListFileCB *listFileCB) +{ + if (args == nullptr || listFileCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valueType)); + if (valueType == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &listFileCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + ListFileExecuteCB, + ListFileAsyncCompleteCB, + (void *)listFileCB, + &listFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, listFileCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + return result; +} + +napi_value ListFilePromise(napi_env env, FileAccessHelperListFileCB *listFileCB) +{ + if (listFileCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + listFileCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + ListFileExecuteCB, + ListFilePromiseCompleteCB, + (void *)listFileCB, + &listFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, listFileCB->cbBase.asyncWork)); + return promise; +} + +void ListFileExecuteCB(napi_env env, void *data) +{ + FileAccessHelperListFileCB *listFileCB = static_cast(data); + listFileCB->execResult = ERR_ERROR; + if (listFileCB->fileAccessHelper == nullptr) { + HILOG_ERROR(" NAPI_ListFile, fileAccessHelper == nullptr"); + return ; + } + if (listFileCB->sourceFileUri.empty()) { + HILOG_ERROR(" NAPI_ListFile, fileAccessHelper sourceFileUri is empty"); + return ; + } + OHOS::Uri sourceFileUri(listFileCB->sourceFileUri); + listFileCB->result = listFileCB->fileAccessHelper->ListFile(sourceFileUri); + listFileCB->execResult = 0; +} + +void ListFileAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + FileAccessHelperListFileCB *listFileCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, listFileCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, listFileCB->execResult); + result[PARAM1] = WrapArrayFileInfoToJS(env, listFileCB->result); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (listFileCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, listFileCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, listFileCB->cbBase.asyncWork)); + delete listFileCB; + listFileCB = nullptr; +} + +void ListFilePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + FileAccessHelperListFileCB *listFileCB = static_cast(data); + napi_value result = nullptr; + result = WrapArrayFileInfoToJS(env, listFileCB->result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, listFileCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, listFileCB->cbBase.asyncWork)); + delete listFileCB; + listFileCB = nullptr; +} + +napi_value NAPI_GetRoots(napi_env env, napi_callback_info info) +{ + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) { + HILOG_ERROR("%{public}s, Number of arguments unmatched.", __func__); + UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + return nullptr; + } + if (funcArg.GetArgc() == NARG_CNT::ONE && !NVal(env, funcArg[NARG_POS::FIRST]).TypeIs(napi_function)) { + UniError(EINVAL).ThrowErr(env, "Type of arguments unmatched"); + return nullptr; + } + + FileAccessHelperGetRootsCB *getRootsCB = new (std::nothrow) FileAccessHelperGetRootsCB; + if (getRootsCB == nullptr) { + HILOG_ERROR("%{public}s, getRootsCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + getRootsCB->cbBase.cbInfo.env = env; + getRootsCB->cbBase.asyncWork = nullptr; + getRootsCB->cbBase.deferred = nullptr; + getRootsCB->cbBase.ability = nullptr; + + napi_value ret = GetRootsWrap(env, info, getRootsCB); + if (ret == nullptr) { + HILOG_ERROR("%{public}s,ret == nullptr", __func__); + if (getRootsCB != nullptr) { + delete getRootsCB; + getRootsCB = nullptr; + } + ret = WrapVoidToJS(env); + } + return ret; +} + +napi_value GetRootsWrap(napi_env env, napi_callback_info info, FileAccessHelperGetRootsCB *getRootsCB) +{ + size_t argcAsync = ARGS_ONE; + const size_t argcPromise = ARGS_ZERO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + getRootsCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = GetRootsAsync(env, args, ARGS_ZERO, getRootsCB); + } else { + ret = GetRootsPromise(env, getRootsCB); + } + return ret; +} + +napi_value GetRootsAsync(napi_env env, + napi_value *args, + const size_t argCallback, + FileAccessHelperGetRootsCB *getRootsCB) +{ + if (args == nullptr || getRootsCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valueType)); + if (valueType == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &getRootsCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetRootsExecuteCB, + GetRootsAsyncCompleteCB, + (void *)getRootsCB, + &getRootsCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, getRootsCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + return result; +} + +napi_value GetRootsPromise(napi_env env, FileAccessHelperGetRootsCB *getRootsCB) +{ + if (getRootsCB == nullptr) { + HILOG_ERROR("%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + getRootsCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + GetRootsExecuteCB, + GetRootsPromiseCompleteCB, + (void *)getRootsCB, + &getRootsCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, getRootsCB->cbBase.asyncWork)); + return promise; +} + +void GetRootsExecuteCB(napi_env env, void *data) +{ + FileAccessHelperGetRootsCB *getRootsCB = static_cast(data); + getRootsCB->execResult = ERR_ERROR; + if (getRootsCB->fileAccessHelper == nullptr) { + HILOG_ERROR(" NAPI_GetRoots, fileAccessHelper == nullptr"); + return ; + } + getRootsCB->result = getRootsCB->fileAccessHelper->GetRoots(); + getRootsCB->execResult = ERR_OK; +} + +void GetRootsAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + FileAccessHelperGetRootsCB *getRootsCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, getRootsCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, getRootsCB->execResult); + result[PARAM1] = WrapArrayDeviceInfoToJS(env, getRootsCB->result); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (getRootsCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, getRootsCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, getRootsCB->cbBase.asyncWork)); + delete getRootsCB; + getRootsCB = nullptr; +} + +void GetRootsPromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + FileAccessHelperGetRootsCB *getRootsCB = static_cast(data); + napi_value result = nullptr; + result = WrapArrayDeviceInfoToJS(env, getRootsCB->result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, getRootsCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, getRootsCB->cbBase.asyncWork)); + delete getRootsCB; + getRootsCB = nullptr; +} \ No newline at end of file -- Gitee From c4e712a7ec8ed72b6b9cf7c074622e7f5fd258d6 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Wed, 29 Jun 2022 16:22:05 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjianqiang --- .../file_access/src/file_access_ext_proxy.cpp | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp index 195cbbe4..129d687d 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp @@ -24,17 +24,17 @@ int FileAccessExtProxy::OpenFile(const Uri &uri, int flags) MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&uri)) { HILOG_ERROR("%{public}s fail to WriteParcelable uri", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteInt32(flags)) { HILOG_ERROR("%{public}s fail to WriteString mode", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } MessageParcel reply; @@ -42,13 +42,13 @@ int FileAccessExtProxy::OpenFile(const Uri &uri, int flags) 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_ERROR; + return ERR_IPC_ERROR; } int fd = reply.ReadFileDescriptor(); - if (fd <= ERR_OK) { + if (fd <= ERR_ERROR) { HILOG_ERROR("%{public}s fail to ReadFileDescriptor fd", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } return fd; } @@ -58,22 +58,22 @@ int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &display MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&parent)) { HILOG_ERROR("%{public}s fail to WriteParcelable parent", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteString(displayName)) { HILOG_ERROR("%{public}s fail to WriteString mode", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&newFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } MessageParcel reply; @@ -81,19 +81,19 @@ int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &display 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_ERROR; + return ERR_IPC_ERROR; } int ret = reply.ReadInt32(); if (ret < ERR_OK) { HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR("%{public}s ReadParcelable value is nullptr.", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } newFile = Uri(*tempUri); @@ -105,22 +105,22 @@ int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName, MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&parent)) { HILOG_ERROR("%{public}s fail to WriteParcelable parent", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteString(displayName)) { HILOG_ERROR("%{public}s fail to WriteString displayName", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&newFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } MessageParcel reply; @@ -128,19 +128,19 @@ int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName, 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_ERROR; + return ERR_IPC_ERROR; } int ret = reply.ReadInt32(); if (ret < ERR_OK) { HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR("%{public}s ReadParcelable value is nullptr.", __func__); - ret = ERR_ERROR; + ret = ERR_IPC_ERROR; return ret; } @@ -153,12 +153,12 @@ int FileAccessExtProxy::Delete(const Uri &sourceFile) MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&sourceFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable sourceFile", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } MessageParcel reply; @@ -166,13 +166,13 @@ int FileAccessExtProxy::Delete(const Uri &sourceFile) 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_ERROR; + return ERR_IPC_ERROR; } int ret = reply.ReadInt32(); if (ret < ERR_OK) { HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } return ret; @@ -183,22 +183,22 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR(" %{public}s WriteInterfaceToken failed", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&sourceFile)) { HILOG_ERROR(" %{public}s fail to WriteParcelable sourceFile", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&targetParent)) { HILOG_ERROR(" %{public}s fail to WriteParcelable targetParent", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&newFile)) { HILOG_ERROR(" %{public}s fail to WriteParcelable newFile", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } MessageParcel reply; @@ -206,7 +206,7 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri 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_ERROR; + return ERR_IPC_ERROR; } int ret = reply.ReadInt32(); @@ -218,7 +218,7 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR(" %{public}s ReadParcelable value is nullptr.", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } newFile = Uri(*tempUri); @@ -230,22 +230,22 @@ int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &display MessageParcel data; if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { HILOG_ERROR("%{public}s WriteInterfaceToken failed", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&sourceFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable sourceFile", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteString(displayName)) { HILOG_ERROR("%{public}s fail to WriteString displayName", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } if (!data.WriteParcelable(&newFile)) { HILOG_ERROR("%{public}s fail to WriteParcelable newFile", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } MessageParcel reply; @@ -253,19 +253,19 @@ int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &display 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_ERROR; + return ERR_IPC_ERROR; } int ret = reply.ReadInt32(); if (ret < ERR_OK) { HILOG_ERROR("%{public}s fail to ReadInt32 ret", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR("%{public}s ReadParcelable value is nullptr.", __func__); - return ERR_ERROR; + return ERR_IPC_ERROR; } newFile = Uri(*tempUri); -- Gitee