diff --git a/frameworks/innerkits/file_access/BUILD.gn b/frameworks/innerkits/file_access/BUILD.gn index 26aabbc68ae265ef57f32a37a8c37026797c2e8a..fc5407c050d2600cb458f43dab60a7ca43ffd998 100644 --- a/frameworks/innerkits/file_access/BUILD.gn +++ b/frameworks/innerkits/file_access/BUILD.gn @@ -39,6 +39,7 @@ config("ability_public_config") { visibility = [ ":*" ] include_dirs = [ "include", + "include/notify", "${BASE_DIR}/utils", "${ability_runtime_kits_path}/appkit/native/ability_runtime/app", "${ability_runtime_kits_path}/appkit/native/app/include", @@ -56,6 +57,9 @@ ohos_shared_library("file_access_extension_ability_kit") { "src/file_access_ext_stub.cpp", "src/file_access_ext_stub_impl.cpp", "src/file_access_helper.cpp", + "src/notify/file_access_notify_client.cpp", + "src/notify/file_access_notify_ipc.cpp", + "src/notify/file_access_notify_manager.cpp", "src/js_file_access_ext_ability.cpp", "src/napi_common_fileaccess.cpp", ] @@ -79,6 +83,7 @@ ohos_shared_library("file_access_extension_ability_kit") { "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", + "eventhandler:libeventhandler", "ipc:ipc_core", "ipc_js:rpc", "utils_base:utils", @@ -108,6 +113,7 @@ ohos_shared_library("file_access_extension_ability_module") { "ability_base:want", "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", "utils_base:utils", ] 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 7689afb012fc2e765a6746b0093e6616db4b2827..9357af73846f08a0f32a260026ee26ea03aa3d7f 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_ability.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_ability.h @@ -18,6 +18,7 @@ #include "extension_base.h" #include "file_access_extension_info.h" +#include "file_access_notify_manager.h" namespace OHOS { namespace AbilityRuntime { @@ -49,8 +50,13 @@ public: virtual std::vector ListFile(const Uri &sourceFile); virtual std::vector GetRoots(); static void SetCreator(const CreatorFunc& creator); + virtual int RegisterNotify(sptr ¬ify); + virtual int UnregisterNotify(sptr ¬ify); + virtual int Notify(const Uri &uri, const NotifyType notifyType); private: + bool GetNotifyManager(); static CreatorFunc creator_; + std::unique_ptr notifyManager_; }; } // namespace FileAccessFwk } // namespace OHOS 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 d4918e22c9c5107d9f5e83953be78387cad94773..6aa9f8fec30afc0a78cf8361edc318012f89b81c 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_proxy.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_proxy.h @@ -38,6 +38,8 @@ public: virtual std::vector ListFile(const Uri &sourceFile) override; virtual std::vector GetRoots() override; + virtual int RegisterNotify(sptr ¬ify) override; + virtual int UnregisterNotify(sptr ¬ify) override; private: static inline BrokerDelegator delegator_; }; diff --git a/frameworks/innerkits/file_access/include/file_access_ext_stub.h b/frameworks/innerkits/file_access/include/file_access_ext_stub.h index 73c1552a19cc3d038137adf15fd9db787d7a3ca2..f79129e338a5c468c409cc23c9db530f2b6a9bf3 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_stub.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_stub.h @@ -38,7 +38,8 @@ private: ErrCode CmdRename(MessageParcel &data, MessageParcel &reply); ErrCode CmdListFile(MessageParcel &data, MessageParcel &reply); ErrCode CmdGetRoots(MessageParcel &data, MessageParcel &reply); - bool CheckCallingPermission(const std::string &permission); + ErrCode CmdRegisterNotify(MessageParcel &data, MessageParcel &reply); + ErrCode CmdUnregisterNotify(MessageParcel &data, MessageParcel &reply); using RequestFuncType = int (FileAccessExtStub::*)(MessageParcel &data, MessageParcel &reply); std::map stubFuncMap_; }; diff --git a/frameworks/innerkits/file_access/include/file_access_ext_stub_impl.h b/frameworks/innerkits/file_access/include/file_access_ext_stub_impl.h index 1cd130ba5c0ec93b4b4003c6dbf30038c3060341..34528539a26b655d5bbdeb7e6b88bc0621a57a72 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_stub_impl.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_stub_impl.h @@ -40,7 +40,8 @@ public: int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) override; std::vector ListFile(const Uri &sourceFileUri) override; std::vector GetRoots() override; - + int RegisterNotify(sptr ¬ify) override; + int UnregisterNotify(sptr ¬ify) override; private: std::shared_ptr GetOwner(); std::shared_ptr extension_; diff --git a/frameworks/innerkits/file_access/include/file_access_helper.h b/frameworks/innerkits/file_access/include/file_access_helper.h index be151480047119289242ca56f6042df89e7c62ab..63068f9bba202ac358c2cc18380c26a30555029a 100644 --- a/frameworks/innerkits/file_access/include/file_access_helper.h +++ b/frameworks/innerkits/file_access/include/file_access_helper.h @@ -22,8 +22,10 @@ #include "context.h" #include "file_access_ext_connection.h" #include "file_access_extension_info.h" +#include "file_access_notify_client.h" #include "hilog_wrapper.h" #include "ifile_access_ext_base.h" +#include "ifile_access_notify.h" #include "uri.h" #include "want.h" @@ -50,7 +52,8 @@ public: int Rename(Uri &sourceFile, const std::string &displayName, Uri &newFile); std::vector ListFile(Uri &sourceFile); std::vector GetRoots(); - + int On(std::shared_ptr ¬ify); + int Off(); private: FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, const sptr &fileAccessExtProxy); @@ -65,6 +68,8 @@ private: bool isSystemCaller_ = false; sptr callerDeathRecipient_ = nullptr; sptr fileAccessExtConnection_ = nullptr; + + sptr notifyClient_; }; class FileAccessDeathRecipient : public IRemoteObject::DeathRecipient { diff --git a/frameworks/innerkits/file_access/include/ifile_access_ext_base.h b/frameworks/innerkits/file_access/include/ifile_access_ext_base.h index 5c79a87b62b8fea0fa0cdb801b4171aeacd876d4..089253f3d19287b8e9173d08e46e6b0b8995247a 100644 --- a/frameworks/innerkits/file_access/include/ifile_access_ext_base.h +++ b/frameworks/innerkits/file_access/include/ifile_access_ext_base.h @@ -22,6 +22,8 @@ #include #include "file_access_extension_info.h" +#include "file_access_framework_errno.h" +#include "ifile_access_notify_ipc.h" #include "uri.h" namespace OHOS { @@ -38,7 +40,9 @@ public: CMD_MOVE = 5, CMD_RENAME = 6, CMD_LIST_FILE = 7, - CMD_GET_ROOTS = 8 + CMD_GET_ROOTS = 8, + CMD_REGISTER_NOTIFY = 9, + CMD_UNREGISTER_NOTIFY = 10, }; virtual int OpenFile(const Uri &uri, int flags) = 0; @@ -50,6 +54,8 @@ public: virtual std::vector ListFile(const Uri &sourceFile) = 0; virtual std::vector GetRoots() = 0; + virtual int RegisterNotify(sptr ¬ify) = 0; + virtual int UnregisterNotify(sptr ¬ify) = 0; }; } // namespace FileAccessFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_access/include/notify/file_access_notify_client.h b/frameworks/innerkits/file_access/include/notify/file_access_notify_client.h new file mode 100644 index 0000000000000000000000000000000000000000..318d75e2df7e80ad3554d712271ef5dcd7330143 --- /dev/null +++ b/frameworks/innerkits/file_access/include/notify/file_access_notify_client.h @@ -0,0 +1,37 @@ +/* + * 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_ACCESS_NOTIFY_CLIENT_H__ +#define __FILE_ACCESS_NOTIFY_CLIENT_H__ + +#include +#include "ifile_access_notify.h" +#include "ifile_access_notify_ipc.h" +#include "iremote_object.h" + +namespace OHOS { +namespace FileAccessFwk { +class FileAccessNotifyClient final : public FileAccessNotifyStub { +public: + FileAccessNotifyClient(std::shared_ptr ¬ify); + ~FileAccessNotifyClient(); + void OnNotify(const Uri &uri, const NotifyType notifyType) override; + +private: + std::shared_ptr notify_; +}; +} // namespace FileAccessFwk +} // namespace OHOS +#endif // __FILE_ACCESS_NOTIFY_CLIENT_H__ \ No newline at end of file diff --git a/frameworks/innerkits/file_access/include/notify/file_access_notify_manager.h b/frameworks/innerkits/file_access/include/notify/file_access_notify_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..0d208102a9181fb60e56c3200cc01183a853ac43 --- /dev/null +++ b/frameworks/innerkits/file_access/include/notify/file_access_notify_manager.h @@ -0,0 +1,54 @@ +/* + * 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_ACCESS_NOTIFY_MANAGER_H__ +#define __FILE_ACCESS_NOTIFY_MANAGER_H__ + +#include +#include +#include + +#include "event_handler.h" +#include "ifile_access_notify_ipc.h" +#include "iremote_object.h" + +namespace OHOS { +namespace FileAccessFwk { +using EventHandler = OHOS::AppExecFwk::EventHandler; + +class FileAccessNotifyManager final : public std::enable_shared_from_this { +public: + using RecipientMapType = std::map, sptr>; + + FileAccessNotifyManager(); + ~FileAccessNotifyManager(); + + int RegisterNotify(sptr ¬ify); + int UnregisterNotify(sptr ¬ify); + int Notify(const Uri uri, const NotifyType notifyType); + void OnCallBackDied(const wptr &remote); + +private: + void AddDeathRecipient(const sptr ¬ify); + void RemoveDeathRecipient(const sptr ¬ify); + void HandleCallBackDiedTask(const sptr &remote); + std::shared_ptr handler_ = nullptr; + RecipientMapType recipientMap_; + static std::mutex notifyVecMutex_; + std::vector> notifyVec; +}; +} // namespace FileAccessFwk +} // namespace OHOS +#endif // __FILE_ACCESS_NOTIFY_MANAGER_H__ \ No newline at end of file diff --git a/frameworks/innerkits/file_access/include/notify/ifile_access_notify.h b/frameworks/innerkits/file_access/include/notify/ifile_access_notify.h new file mode 100644 index 0000000000000000000000000000000000000000..0bb801fee2d0f55e8eb23a164a60fc13a663f61e --- /dev/null +++ b/frameworks/innerkits/file_access/include/notify/ifile_access_notify.h @@ -0,0 +1,34 @@ +/* + * 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 __I_FILE_ACCESS_NOTIFY_H__ +#define __I_FILE_ACCESS_NOTIFY_H__ + +#include "uri.h" + +namespace OHOS { +namespace FileAccessFwk { +enum NotifyType { + NOTIFY_DEVICE_CHANGE, + NOTIFY_FILE_CHANGE, +}; + +class IFileAccessNotify { +public: + virtual void OnNotify(const Uri &uri, const NotifyType notifyType) = 0; +}; +} // namespace FileAccessFwk +} // namespace OHOS +#endif // __I_FILE_ACCESS_NOTIFY_H__ \ No newline at end of file diff --git a/frameworks/innerkits/file_access/include/notify/ifile_access_notify_ipc.h b/frameworks/innerkits/file_access/include/notify/ifile_access_notify_ipc.h new file mode 100644 index 0000000000000000000000000000000000000000..4110b86a9cf5a97cdff46a922b3c4a1a5ac0c811 --- /dev/null +++ b/frameworks/innerkits/file_access/include/notify/ifile_access_notify_ipc.h @@ -0,0 +1,65 @@ +/* + * 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 __I_FILE_ACCESS_NOTIFY_IPC_H__ +#define __I_FILE_ACCESS_NOTIFY_IPC_H__ + +#include "ifile_access_notify.h" +#include "iremote_broker.h" +#include "iremote_proxy.h" +#include "iremote_stub.h" +#include "uri.h" + +namespace OHOS { +namespace FileAccessFwk { +class IFileAccessNotifyIPC : public IFileAccessNotify, public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileAccessFwk.IFileAccessNotifyIPC"); + + enum { + CMD_ON_NOTIFY = 1, + }; + + virtual void OnNotify(const Uri &uri, const NotifyType notifyType) override = 0; +}; + +class FileAccessNotifyStub : public IRemoteStub { +public: + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) override; +}; + +class FileAccessNotifyCallbackRecipient : public IRemoteObject::DeathRecipient { +public: + using RemoteDiedHandler = std::function &)>; + FileAccessNotifyCallbackRecipient(RemoteDiedHandler handler); + virtual ~FileAccessNotifyCallbackRecipient(); + virtual void OnRemoteDied(const wptr &remote); + +private: + RemoteDiedHandler handler_; +}; + +class FileAccessNotifyProxy : public IRemoteProxy { +public: + explicit FileAccessNotifyProxy(const sptr &impl); + ~FileAccessNotifyProxy() = default; + void OnNotify(const Uri &uri, const NotifyType notifyType) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace FileAccessFwk +} // namespace OHOS +#endif // __I_FILE_ACCESS_NOTIFY_IPC_H__ \ No newline at end of file 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 a570e63dfeb44e19b89cac3d42911277400e88fe..416f3ca77fbd10e756e1087871ea4e4304e375da 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_ability.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_ability.cpp @@ -99,5 +99,55 @@ std::vector FileAccessExtAbility::GetRoots() std::vector vec; return vec; } + +bool FileAccessExtAbility::GetNotifyManager() +{ + if (notifyManager_ == nullptr) { + notifyManager_ = std::make_unique(); + if (notifyManager_ == nullptr) { + return false; + } + } + return true; +} + +int FileAccessExtAbility::RegisterNotify(sptr ¬ify) +{ + if (!GetNotifyManager()) { + HILOG_ERROR("GetNotifyManager fail."); + return ERR_ERROR; + } + int ret = notifyManager_->RegisterNotify(notify); + if (ret != ERR_OK) { + HILOG_ERROR("NotifyManager register notify fail."); + } + return ret; +} + +int FileAccessExtAbility::UnregisterNotify(sptr ¬ify) +{ + if (!GetNotifyManager()) { + HILOG_ERROR("GetNotifyManager fail."); + return ERR_ERROR; + } + int ret = notifyManager_->UnregisterNotify(notify); + if (ret != ERR_OK) { + HILOG_ERROR("NotifyManager unregister notify fail."); + } + return ret; +} + +int FileAccessExtAbility::Notify(const Uri &uri, const NotifyType notifyType) +{ + if (!GetNotifyManager()) { + HILOG_ERROR("GetNotifyManager fail."); + return ERR_ERROR; + } + int ret = notifyManager_->Notify(uri, notifyType); + if (ret != ERR_OK) { + HILOG_ERROR("NotifyManager handle notify fail."); + } + return ret; +} } // 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 index 129d687d54585a4772b6fd838b654d5c41bab5a8..b3f154dc8b134aeb4108307372de4cb6c5ba12f2 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp @@ -334,5 +334,47 @@ std::vector FileAccessExtProxy::GetRoots() return vec; } + +int FileAccessExtProxy::RegisterNotify(sptr ¬ify) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("WriteInterfaceToken failed"); + return ERR_PARCEL_ERROR; + } + if (!data.WriteRemoteObject(notify->AsObject())) { + HILOG_ERROR("write subscribe type or parcel failed."); + return ERR_PARCEL_ERROR; + } + MessageParcel reply; + MessageOption option; + int err = Remote()->SendRequest(CMD_REGISTER_NOTIFY, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("fail to SendRequest. err: %d", err); + return err; + } + return err; +} + +int FileAccessExtProxy::UnregisterNotify(sptr ¬ify) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { + HILOG_ERROR("WriteInterfaceToken failed"); + return ERR_PARCEL_ERROR; + } + if (!data.WriteRemoteObject(notify->AsObject())) { + HILOG_ERROR("write subscribe type or parcel failed."); + return ERR_PARCEL_ERROR; + } + MessageParcel reply; + MessageOption option; + int err = Remote()->SendRequest(CMD_UNREGISTER_NOTIFY, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("%{public}s fail to SendRequest. err: %d", __func__, err); + return err; + } + return err; +} } // namespace FileAccessFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp b/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp index a7a5b8c1c795288626130bcc3b6db765d25e7a6d..86455856506a28c030c2783e8f3941310ecf2e7b 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp @@ -35,6 +35,8 @@ FileAccessExtStub::FileAccessExtStub() stubFuncMap_[CMD_RENAME] = &FileAccessExtStub::CmdRename; stubFuncMap_[CMD_LIST_FILE] = &FileAccessExtStub::CmdListFile; stubFuncMap_[CMD_GET_ROOTS] = &FileAccessExtStub::CmdGetRoots; + stubFuncMap_[CMD_REGISTER_NOTIFY] = &FileAccessExtStub::CmdRegisterNotify; + stubFuncMap_[CMD_UNREGISTER_NOTIFY] = &FileAccessExtStub::CmdUnregisterNotify; } FileAccessExtStub::~FileAccessExtStub() @@ -319,5 +321,41 @@ bool FileAccessExtStub::CheckCallingPermission(const std::string &permission) } return true; } + +ErrCode FileAccessExtStub::CmdRegisterNotify(MessageParcel &data, MessageParcel &reply) +{ + auto remote = data.ReadRemoteObject(); + if (remote == nullptr) { + return ERR_PARCEL_ERROR; + } + auto notify = iface_cast(remote); + if (notify == nullptr) { + return ERR_PARCEL_ERROR; + } + int ret = RegisterNotify(notify); + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("WriteInt32 failed"); + return ERR_PARCEL_ERROR; + } + return ERR_OK; +} + +ErrCode FileAccessExtStub::CmdUnregisterNotify(MessageParcel &data, MessageParcel &reply) +{ + auto remote = data.ReadRemoteObject(); + if (remote == nullptr) { + return ERR_PARCEL_ERROR; + } + auto notify = iface_cast(remote); + if (notify == nullptr) { + return ERR_PARCEL_ERROR; + } + int ret = UnregisterNotify(notify); + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("WriteInt32 failed"); + return ERR_PARCEL_ERROR; + } + return ERR_OK; +} } // namespace FileAccessFwk } // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_access/src/file_access_ext_stub_impl.cpp b/frameworks/innerkits/file_access/src/file_access_ext_stub_impl.cpp index d7355fa734cf9a1e6755ea6de5335fd3ac5100cc..d565ed3519e7e9e7a8e3309e5bd96e7d5ef3cc6d 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_stub_impl.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_stub_impl.cpp @@ -122,5 +122,33 @@ std::vector FileAccessExtStubImpl::GetRoots() vec = extension->GetRoots(); return vec; } + +int FileAccessExtStubImpl::RegisterNotify(sptr ¬ify) +{ + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("get extension failed."); + return ERR_ERROR; + } + int ret = extension->RegisterNotify(notify); + if (ret != ERR_OK) { + HILOG_ERROR("RegisterNotify failed."); + } + return ret; +} + +int FileAccessExtStubImpl::UnregisterNotify(sptr ¬ify) +{ + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("get extension failed."); + return ERR_ERROR; + } + int ret = extension->UnregisterNotify(notify); + if (ret != ERR_OK) { + HILOG_ERROR("UnregisterNotify failed."); + } + return ret; +} } // namespace FileAccessFwk } // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index 6e04cb8e01c379bba13bbf655de3cff069e5719e..f46c3cf0da0bdf763bd2bdf42403ceff14123485 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -234,6 +234,40 @@ std::vector FileAccessHelper::GetRoots() return results; } +int FileAccessHelper::On(std::shared_ptr ¬ify) +{ + notifyClient_ = new (std::nothrow) FileAccessNotifyClient(notify); + if (notifyClient_ == nullptr) { + return ERR_NOTIFY_NOT_EXIST; + } + if (!GetProxy()) { + HILOG_ERROR("failed with invalid fileAccessExtProxy_"); + return ERR_IPC_ERROR; + } + int ret = fileAccessExtProxy_->RegisterNotify(notifyClient_); + if (ret != ERR_OK) { + HILOG_ERROR("fileAccessExtProxy_ RegisterNotify fail"); + } + return ret; +} + +int FileAccessHelper::Off() +{ + if (notifyClient_ == nullptr) { + HILOG_ERROR("not registered notify"); + return ERR_NOTIFY_NOT_EXIST; + } + if (!GetProxy()) { + HILOG_ERROR("failed with invalid fileAccessExtProxy_"); + return ERR_IPC_ERROR; + } + int ret = fileAccessExtProxy_->UnregisterNotify(notifyClient_); + if (ret != ERR_OK) { + HILOG_ERROR("fileAccessExtProxy_ unregisterNotify fail"); + } + return ret; +} + void FileAccessDeathRecipient::OnRemoteDied(const wptr &remote) { if (handler_) { diff --git a/frameworks/innerkits/file_access/src/js_file_access_ext_ability.cpp b/frameworks/innerkits/file_access/src/js_file_access_ext_ability.cpp index 9bdefbef080602a6182f5b3d416f5de4723682bf..ba67290d95658c97fb09e4c677c5eeedfa7678a6 100644 --- a/frameworks/innerkits/file_access/src/js_file_access_ext_ability.cpp +++ b/frameworks/innerkits/file_access/src/js_file_access_ext_ability.cpp @@ -269,6 +269,8 @@ int JsFileAccessExtAbility::CreateFile(const Uri &parent, const std::string &dis ret = NO_ERROR; } newFile = Uri(uriStr); + + Notify(newFile, NotifyType::NOTIFY_FILE_CHANGE); return ret; } diff --git a/frameworks/innerkits/file_access/src/notify/file_access_notify_client.cpp b/frameworks/innerkits/file_access/src/notify/file_access_notify_client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f37ea20648dbd2a7cb506eaec0366990a60d20a6 --- /dev/null +++ b/frameworks/innerkits/file_access/src/notify/file_access_notify_client.cpp @@ -0,0 +1,37 @@ +/* + * 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 "hilog_wrapper.h" +#include "file_access_notify_client.h" + +namespace OHOS { +namespace FileAccessFwk { +FileAccessNotifyClient::FileAccessNotifyClient(std::shared_ptr ¬ify) + : notify_(notify) +{ +} + +FileAccessNotifyClient::~FileAccessNotifyClient() +{ +} + +void FileAccessNotifyClient::OnNotify(const Uri &uri, const NotifyType notifyType) +{ + if (notify_ != nullptr) { + notify_->OnNotify(uri, notifyType); + } +} +} // namespace FileAccessFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_access/src/notify/file_access_notify_ipc.cpp b/frameworks/innerkits/file_access/src/notify/file_access_notify_ipc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c61e70db8ee6f71080f2af8b80d8989c0b790a7 --- /dev/null +++ b/frameworks/innerkits/file_access/src/notify/file_access_notify_ipc.cpp @@ -0,0 +1,101 @@ +/* + * 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 "ifile_access_notify_ipc.h" + +#include "file_access_framework_errno.h" +#include "hilog_wrapper.h" +#include "message_parcel.h" + +namespace OHOS { +namespace FileAccessFwk { +FileAccessNotifyProxy::FileAccessNotifyProxy(const sptr &impl) : IRemoteProxy(impl) +{ +} + +void FileAccessNotifyProxy::OnNotify(const Uri &uri, const NotifyType notifyType) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(FileAccessNotifyProxy::GetDescriptor())) { + HILOG_ERROR("write descriptor failed"); + return; + } + if (!data.WriteParcelable(&uri)) { + HILOG_ERROR("write parcel uri failed"); + return; + } + if (!data.WriteInt32((int32_t)notifyType)) { + HILOG_ERROR("write parcel notifyType failed"); + return; + } + int error = Remote()->SendRequest(CMD_ON_NOTIFY, data, reply, option); + if (error != 0) { + HILOG_ERROR("SendRequest failed, error %d", error); + } +} + +int32_t FileAccessNotifyStub::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + HILOG_INFO("%{public}s, called start", __func__); + auto descriptor = FileAccessNotifyStub::GetDescriptor(); + auto remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + HILOG_ERROR("local descriptor is not equal to remote"); + return ERR_ERROR; + } + HILOG_INFO("%{public}s, called 1", __func__); + switch (code) { + case CMD_ON_NOTIFY: { + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { + HILOG_ERROR("read parcel uri fail"); + return ERR_PARCEL_ERROR; + } + NotifyType notifyType = (NotifyType)data.ReadInt32(); + OnNotify(*uri, notifyType); + HILOG_DEBUG("FileAccessNotifyStub::OnRemoteRequest End"); + return ERR_OK; + } + default: + HILOG_DEBUG("code error, FileAccessNotifyStub::OnRemoteRequest End"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } +} + +void FileAccessNotifyCallbackRecipient::OnRemoteDied(const wptr &remote) +{ + HILOG_INFO("%{public}s, called start", __func__); + if (handler_) { + handler_(remote); + } + HILOG_INFO("%{public}s, called end", __func__); +} + +FileAccessNotifyCallbackRecipient::FileAccessNotifyCallbackRecipient(RemoteDiedHandler handler) : handler_(handler) +{ + HILOG_INFO("%{public}s, called start", __func__); + HILOG_INFO("%{public}s, called end", __func__); +} + +FileAccessNotifyCallbackRecipient::~FileAccessNotifyCallbackRecipient() +{ + HILOG_INFO("%{public}s, called start", __func__); + HILOG_INFO("%{public}s, called end", __func__); +} +} // namespace FileAccessFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_access/src/notify/file_access_notify_manager.cpp b/frameworks/innerkits/file_access/src/notify/file_access_notify_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41423987da1941a2bc91a6202193876203061098 --- /dev/null +++ b/frameworks/innerkits/file_access/src/notify/file_access_notify_manager.cpp @@ -0,0 +1,149 @@ +/* + * 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_notify_manager.h" + +#include + +#include "file_access_framework_errno.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace FileAccessFwk { +std::mutex FileAccessNotifyManager::notifyVecMutex_; + +FileAccessNotifyManager::FileAccessNotifyManager() +{ +} + +FileAccessNotifyManager::~FileAccessNotifyManager() +{ +} + +int FileAccessNotifyManager::RegisterNotify(sptr ¬ify) +{ + std::lock_guard lock(notifyVecMutex_); + for (auto notify : notifyVec) { + if (notify->AsObject() == notify->AsObject()) { + HILOG_ERROR("the notify exist. no need to register."); + return ERR_NOTIFY_EXIST; + } + } + notifyVec.emplace_back(notify); + // AddDeathRecipient(notify); + return ERR_OK; +} + +int FileAccessNotifyManager::UnregisterNotify(sptr ¬ify) +{ + std::lock_guard lock(notifyVecMutex_); + std::vector>::iterator it = notifyVec.begin(); + for (; it != notifyVec.end(); it++) { + if ((*it)->AsObject() == notify->AsObject()) { + notifyVec.erase(it); + // RemoveDeathRecipient(notify); + return ERR_OK; + } + } + + + return ERR_NOTIFY_EXIST; +} + +int FileAccessNotifyManager::Notify(const Uri uri, const NotifyType notifyType) +{ + std::lock_guard lock(notifyVecMutex_); + for (auto notify : notifyVec) { + if (notify != nullptr) { + notify->OnNotify(uri, notifyType); + } + } + return ERR_OK; +} + +void FileAccessNotifyManager::AddDeathRecipient(const sptr ¬ify) +{ + if ((notify == nullptr) || notify->AsObject() == nullptr) { + HILOG_ERROR("the death recipient obj is nullptr."); + return; + } + auto it = recipientMap_.find(notify->AsObject()); + if (it != recipientMap_.end()) { + HILOG_ERROR("the death recipient obj has been added."); + return; + } + std::weak_ptr thisWeakPtr(shared_from_this()); + sptr deathRecipient = + new FileAccessNotifyCallbackRecipient([thisWeakPtr](const wptr &remote) { + auto fileAccessNotifyManager = thisWeakPtr.lock(); + if (fileAccessNotifyManager) { + fileAccessNotifyManager->OnCallBackDied(remote); + } + }); + notify->AsObject()->AddDeathRecipient(deathRecipient); + recipientMap_.emplace(notify->AsObject(), deathRecipient); +} + +void FileAccessNotifyManager::RemoveDeathRecipient(const sptr ¬ify) +{ + if ((notify == nullptr) || notify->AsObject() == nullptr) { + return; + } + auto it = recipientMap_.find(notify->AsObject()); + if (it != recipientMap_.end()) { + it->first->RemoveDeathRecipient(it->second); + recipientMap_.erase(it); + } +} + +void FileAccessNotifyManager::OnCallBackDied(const wptr &remote) +{ + auto object = remote.promote(); + if (object == nullptr) { + return; + } + if (handler_) { + auto task = [object, fileAccessNotifyManager = shared_from_this()]() { + fileAccessNotifyManager->HandleCallBackDiedTask(object); + }; + handler_->PostTask(task); + } +} + +void FileAccessNotifyManager::HandleCallBackDiedTask(const sptr &remote) +{ + std::lock_guard lock_l(notifyVecMutex_); + if (remote == nullptr) { + return; + } + sptr notify = iface_cast(remote); + if (notify == nullptr) { + return; + } + auto recipientIter = recipientMap_.find(notify->AsObject()); + if (recipientIter != recipientMap_.end()) { + recipientIter->first->RemoveDeathRecipient(recipientIter->second); + recipientMap_.erase(recipientIter); + } + auto it = std::find(notifyVec.begin(), notifyVec.end(), notify); + if (it != notifyVec.end()) { + if ((*it)->AsObject() == notify->AsObject()) { + notifyVec.erase(it); + } + } +} + +} // namespace FileAccessFwk +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/BUILD.gn b/interfaces/kits/napi/file_access_module/BUILD.gn index c3317d50c0a86fe20c8d473380feb0533312f9a9..1a4949e53d96d3421a5191cb9ebb994784f093b1 100644 --- a/interfaces/kits/napi/file_access_module/BUILD.gn +++ b/interfaces/kits/napi/file_access_module/BUILD.gn @@ -31,6 +31,7 @@ ohos_shared_library("fileaccess") { sources = [ "${BASE_DIR}/interfaces/kits/napi/common/file_extension_info_napi.cpp", "napi_fileaccess_helper.cpp", + "napi_fileaccess_notify.cpp", "native_fileaccess_module.cpp", ] @@ -47,6 +48,7 @@ ohos_shared_library("fileaccess") { "ability_runtime:abilitykit_native", "ability_runtime:napi_base_context", "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", "napi:ace_napi", "utils_base:utils", ] diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp index 074bdba878c8dd547e32c54ba89b3d985461b1fc..027be3f69c70587f9ebd5be17df9b7a6bf87d3b6 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -20,7 +20,9 @@ #include "file_access_framework_errno.h" #include "hilog_wrapper.h" +#include "ifile_access_notify.h" #include "napi_base_context.h" +#include "napi_fileaccess_notify.h" #include "napi_common_fileaccess.h" #include "n_func_arg.h" #include "n_val.h" @@ -174,6 +176,8 @@ napi_value FileAccessHelperInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("rename", NAPI_Rename), DECLARE_NAPI_FUNCTION("listFile", NAPI_ListFile), DECLARE_NAPI_FUNCTION("getRoots", NAPI_GetRoots), + DECLARE_NAPI_FUNCTION("on", NAPI_On), + DECLARE_NAPI_FUNCTION("off", NAPI_Off) }; napi_value cons = nullptr; NAPI_CALL(env, @@ -1700,5 +1704,89 @@ napi_value NAPI_GetRoots(napi_env env, napi_callback_info info) } return ret; } + +napi_value NAPI_On(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value argv[1] = {nullptr}; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + if (status != napi_ok) { + napi_throw_type_error(env, "-1", "get arguments fail."); + return nullptr; + } + if (argc != 1) { + napi_throw_type_error(env, "-1", "Wrong number of arguments, requires 1."); + return nullptr; + } + FileAccessHelper *helper = nullptr; + status = napi_unwrap(env, thisVar, (void **)&helper); + if (status != napi_ok) { + napi_throw_type_error(env, "-1", "get FileAccessHelper argument fail."); + return nullptr; + } + if (helper == nullptr) { + napi_throw_type_error(env, "-1", "FileAccessHelper is nullptr."); + return nullptr; + } + napi_valuetype valueType = napi_undefined; + status = napi_typeof(env, argv[0], &valueType); + if (status != napi_ok) { + napi_throw_type_error(env, "-1", "get callback argument fail."); + return nullptr; + } + if (valueType != napi_function) { + napi_throw_type_error(env, "-1", "callback is not a function."); + return nullptr; + } + std::shared_ptr notify = std::make_shared(env, argv[0]); + if (notify == nullptr) { + napi_throw_type_error(env, "-1", "new NapiFileAccessNotify fail."); + return nullptr; + } + if (helper->On(notify) != ERR_OK) { + napi_throw_type_error(env, "-1", "FileAccessHelper::On fail."); + return nullptr; + } + + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} + +napi_value NAPI_Off(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value argv[1] = {nullptr}; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + if (status != napi_ok) { + napi_throw_type_error(env, "-1", "get arguments fail."); + return nullptr; + } + if (argc != 0) { + napi_throw_type_error(env, "-1", "Wrong number of arguments, requires 1."); + return nullptr; + } + FileAccessHelper *helper = nullptr; + status = napi_unwrap(env, thisVar, (void **)&helper); + if (status != napi_ok) { + napi_throw_type_error(env, "-1", "get FileAccessHelper argument fail."); + return nullptr; + } + if (helper == nullptr) { + napi_throw_type_error(env, "-1", "FileAccessHelper is nullptr."); + return nullptr; + } + if (helper->Off() != ERR_OK) { + napi_throw_type_error(env, "-1", "FileAccessHelper::Off fail."); + return nullptr; + } + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h index 748a528fa3b80a136cc09600e9ffc4d45704f118..3874414714a6d813b4e7631b06feb9b21136e40b 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -29,6 +29,8 @@ namespace FileAccessFwk { napi_value NAPI_Rename(napi_env env, napi_callback_info info); napi_value NAPI_ListFile(napi_env env, napi_callback_info info); napi_value NAPI_GetRoots(napi_env env, napi_callback_info info); + napi_value NAPI_On(napi_env env, napi_callback_info info); + napi_value NAPI_Off(napi_env env, napi_callback_info info); } } // namespace FileAccessFwk #endif // FILE_ACCESS_NAPI_H \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_notify.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_notify.cpp new file mode 100644 index 0000000000000000000000000000000000000000..affe83658c7af7da41c7846a84aae6ebed108490 --- /dev/null +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_notify.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 "napi_fileaccess_notify.h" + +#include +#include + +namespace OHOS { +namespace FileAccessFwk { +namespace { + const int ARGS_TWO = 2; +} +NapiFileAccessNotify::NapiFileAccessNotify(napi_env env, napi_value callback) + : env_(env) +{ + napi_create_reference(env, callback, 1, &callback_); + napi_get_uv_event_loop(env, &loop_); +} + +NapiFileAccessNotify::~NapiFileAccessNotify() +{ + napi_delete_reference(env_, callback_); +} + +void NapiFileAccessNotify::OnNotify(const Uri &uri, const NotifyType notifyType) +{ + + std::shared_ptr work = std::make_shared(); + if (work == nullptr) { + HILOG_ERROR("failed to new uv_work_t"); + return; + } + CallbackParam* param = new CallbackParam(this, uri.ToString(), notifyType); + if (param == nullptr) { + HILOG_ERROR("failed to new param"); + return; + } + work->data = std::move(param); + uv_queue_work(loop_, work.get(), + [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + std::shared_ptr param; + param.reset(std::move(reinterpret_cast(work->data))); + + napi_value uri = nullptr; + napi_status ret = napi_create_string_utf8(param->notify_->env_, param->uri_.c_str(), + param->uri_.length(), &uri); + if (ret != napi_ok) { + return; + } + + napi_value notifyType = nullptr; + ret = napi_create_int32(param->notify_->env_, (int32_t)(param->notifyType_), ¬ifyType); + if (ret != napi_ok) { + return; + } + napi_value callback = nullptr; + napi_value args[ARGS_TWO] = {uri, notifyType}; + napi_get_reference_value(param->notify_->env_, param->notify_->callback_, &callback); + napi_value global = nullptr; + napi_get_global(param->notify_->env_, &global); + napi_value result = nullptr; + ret = napi_call_function(param->notify_->env_, global, callback, ARGS_TWO, args, &result); + if (ret != napi_ok) { + HILOG_ERROR("notify failed status:%{public}d.", ret); + } + }); + +} +} // namespace FileAccessFwk +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_notify.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_notify.h new file mode 100644 index 0000000000000000000000000000000000000000..0cdd43c9f60ce2e736036251bf08ffa6ab8cbd8d --- /dev/null +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_notify.h @@ -0,0 +1,49 @@ +/* + * 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 __NAPI_FILE_ACCESS_NOTIFY_H__ +#define __NAPI_FILE_ACCESS_NOTIFY_H__ + +#include "hilog_wrapper.h" +#include "ifile_access_notify.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" +#include "napi/native_api.h" +#include "uri.h" + +namespace OHOS { +namespace FileAccessFwk { +class NapiFileAccessNotify : public IFileAccessNotify { +public: + NapiFileAccessNotify(napi_env env, napi_value callback); + virtual ~NapiFileAccessNotify(); + void OnNotify(const Uri &uri, const NotifyType notifyType) override; + + struct CallbackParam { + NapiFileAccessNotify *notify_; + std::string uri_; + NotifyType notifyType_; + CallbackParam(NapiFileAccessNotify *notify, std::string uri, NotifyType notifyType) + : notify_(notify), uri_(uri), notifyType_(notifyType) + {} + }; +private: + napi_ref callback_ = nullptr; + napi_env env_; + uv_loop_s *loop_ = nullptr; +}; +} // FileAccessFwk +} // OHOS +#endif // __NAPI_FILE_ACCESS_NOTIFY_H__ \ No newline at end of file diff --git a/utils/file_access_framework_errno.h b/utils/file_access_framework_errno.h index 6f8bfd17d80e235503e9b3584a5dc147b90c949d..c25ec28630633163f084938ad7eb9855fb61cf1c 100644 --- a/utils/file_access_framework_errno.h +++ b/utils/file_access_framework_errno.h @@ -26,12 +26,15 @@ enum { ERR_OK = 0, ERR_ERROR = -1, ERR_IPC_ERROR = BASE_OFFSET, // ipc error + ERR_PARCEL_ERROR, // parcel write/read fail ERR_PERMISSION_DENIED, // no permission ERR_INVALID_FD, // invalid fd ERR_INVALID_URI, // invalid uri ERR_URI_CHECK, // check uri head fail ERR_FILEIO_FAIL, // fileio fail - ERR_INVALID_PARAM // invalid parameter + ERR_INVALID_PARAM, // invalid parameter + ERR_NOTIFY_EXIST, // the notify to register exist + ERR_NOTIFY_NOT_EXIST // the notify to unregister not exist }; } // namespace FileAccessFwk } // namespace OHOS