diff --git a/frameworks/innerkits/file_access/BUILD.gn b/frameworks/innerkits/file_access/BUILD.gn index 40b029ec7f89c5eb741acdea6e071fc47ff355d3..dda54ac92fed8b0dcb480df913aca072983b1d51 100644 --- a/frameworks/innerkits/file_access/BUILD.gn +++ b/frameworks/innerkits/file_access/BUILD.gn @@ -42,7 +42,6 @@ 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", @@ -65,10 +64,6 @@ ohos_shared_library("file_access_extension_ability_kit") { "src/file_access_helper.cpp", "src/js_file_access_ext_ability.cpp", "src/napi_common_fileaccess.cpp", - "src/notify/file_access_notify_agent.cpp", - "src/notify/file_access_notify_manager.cpp", - "src/notify/file_access_notify_proxy.cpp", - "src/notify/file_access_notify_stub.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 22e4194d69aace41dd51b232a693c7de11a1aa4f..035c8ca945f514be60c107f0e77ed0711abf3f3a 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_ability.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_ability.h @@ -18,7 +18,6 @@ #include "extension_base.h" #include "file_access_extension_info.h" -#include "file_access_notify_manager.h" #include "file_filter.h" namespace OHOS { @@ -55,14 +54,9 @@ public: virtual int UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo); virtual int GetRoots(std::vector &rootInfoVec); virtual int Access(const Uri &uri, bool &isExist); - virtual int RegisterNotify(sptr ¬ify); - virtual int UnregisterNotify(sptr ¬ify); - virtual int Notify(const NotifyMessage &message); static void SetCreator(const CreatorFunc& creator); 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 0b125108f9db8f461f61d27f39d6c83ed78ef01a..e98c9f6bb4819e96b049277c85399ec6a55842da 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_proxy.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_proxy.h @@ -49,8 +49,6 @@ public: virtual int UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo) override; virtual int GetRoots(std::vector &rootInfoVec) override; virtual int Access(const Uri &uri, bool &isExist) 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 7d966173c953a1d903017e5d58e03a2d1be4d6b4..42dd0257ad52b75edcda7a34f7790ca62ee89bec 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_stub.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_stub.h @@ -46,8 +46,6 @@ private: ErrCode CmdUriToFileInfo(MessageParcel &data, MessageParcel &reply); ErrCode CmdGetRoots(MessageParcel &data, MessageParcel &reply); ErrCode CmdAccess(MessageParcel &data, MessageParcel &reply); - ErrCode CmdRegisterNotify(MessageParcel &data, MessageParcel &reply); - ErrCode CmdUnregisterNotify(MessageParcel &data, MessageParcel &reply); bool CheckCallingPermission(const std::string &permission); 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 5a9fa8a2491839868e4a38bb278707b82be11885..ca9e8b2bc78104a113159ab20af0681ac3640872 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 @@ -47,8 +47,6 @@ public: int UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo) override; int GetRoots(std::vector &rootInfoVec) override; int Access(const Uri &uri, bool &isExist) override; - int RegisterNotify(sptr ¬ify) override; - int UnregisterNotify(sptr ¬ify) override; private: std::shared_ptr GetOwner(); diff --git a/frameworks/innerkits/file_access/include/file_access_helper.h b/frameworks/innerkits/file_access/include/file_access_helper.h index b4fbb91e11cbec459faff0dd345434726e71d67a..12657b424b5ac7e687ec7a7936f7374708f823c9 100644 --- a/frameworks/innerkits/file_access/include/file_access_helper.h +++ b/frameworks/innerkits/file_access/include/file_access_helper.h @@ -25,9 +25,7 @@ #include "context.h" #include "file_access_ext_connection.h" #include "file_access_extension_info.h" -#include "file_access_notify_agent.h" #include "ifile_access_ext_base.h" -#include "inotify_callback.h" #include "iremote_object.h" #include "refbase.h" #include "uri.h" @@ -71,8 +69,6 @@ public: std::vector &fileInfoVec); int UriToFileInfo(Uri &selectFile, FileInfo &fileInfo); int GetRoots(std::vector &rootInfoVec); - int On(std::shared_ptr &callback); - int Off(); private: sptr GetProxyByUri(Uri &uri); bool GetProxy(); @@ -95,9 +91,6 @@ private: static std::string GetKeyOfWants(const AAFwk::Want &want); sptr callerDeathRecipient_ = nullptr; - - std::mutex notifyAgentMutex_; - sptr notifyAgent_ = nullptr; }; 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 cffceff056c31fbe6692dc33a10f6e06b352591b..1ec4627b741b3de1752a1c3d3fae37c344330b2f 100644 --- a/frameworks/innerkits/file_access/include/ifile_access_ext_base.h +++ b/frameworks/innerkits/file_access/include/ifile_access_ext_base.h @@ -24,7 +24,6 @@ #include "file_access_extension_info.h" #include "file_access_framework_errno.h" #include "file_filter.h" -#include "ifile_access_notify.h" #include "uri.h" namespace OHOS { @@ -47,8 +46,6 @@ public: CMD_GET_ROOTS, CMD_ACCESS, CMD_URI_TO_FILEINFO, - CMD_REGISTER_NOTIFY, - CMD_UNREGISTER_NOTIFY }; virtual int OpenFile(const Uri &uri, const int flags, int &fd) = 0; @@ -64,8 +61,6 @@ public: virtual int UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo) = 0; virtual int GetRoots(std::vector &rootInfoVec) = 0; virtual int Access(const Uri &uri, bool &isExist) = 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_agent.h b/frameworks/innerkits/file_access/include/notify/file_access_notify_agent.h deleted file mode 100644 index 8279eef87e5435f8ed49d9573927ed37f549c448..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/include/notify/file_access_notify_agent.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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_AGENT_H -#define FILE_ACCESS_NOTIFY_AGENT_H - -#include - -#include "file_access_notify_stub.h" -#include "inotify_callback.h" -#include "iremote_object.h" - -namespace OHOS { -namespace FileAccessFwk { -class FileAccessNotifyAgent final : public FileAccessNotifyStub { -public: - FileAccessNotifyAgent(std::shared_ptr ¬ifyCallback); - ~FileAccessNotifyAgent(); - int Notify(const NotifyMessage &message) override; - -private: - std::shared_ptr notifyCallback_; -}; -} // namespace FileAccessFwk -} // namespace OHOS -#endif // FILE_ACCESS_NOTIFY_AGENT_H \ No newline at end of file diff --git a/frameworks/innerkits/file_access/include/notify/file_access_notify_common.h b/frameworks/innerkits/file_access/include/notify/file_access_notify_common.h deleted file mode 100644 index 93c648af5e9ed4b82c57b5313b2237241811ce0c..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/include/notify/file_access_notify_common.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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_COMMON_H -#define FILE_ACCESS_NOTIFY_COMMON_H - -#include - -#include "file_access_extension_info.h" -#include "hilog_wrapper.h" -#include "parcel.h" - -namespace OHOS { -namespace FileAccessFwk { -constexpr int32_t NOTIFY_DEVICE_ONLINE = 1; -constexpr int32_t NOTIFY_DEVICE_OFFLINE = 2; - -struct NotifyMessage : public virtual OHOS::Parcelable { -public: - int32_t deviceType; - int32_t notifyType; - std::string srcUri; // source uri when notifyType is (NOTIFY_FILE_MOVE/NOTIFY_FILE_RENAME), other case is "". - std::string dstUri; // destination uri for all notifyType - - NotifyMessage() = default; - NotifyMessage(const int32_t deviceTypeIn, const int32_t notifyTypeIn, const std::string &srcUriIn, - const std::string &dstUriIn) - : deviceType(deviceTypeIn), notifyType(notifyTypeIn), srcUri(srcUriIn), dstUri(dstUriIn) - {} - - void ReadFromParcel(Parcel &parcel) - { - deviceType = parcel.ReadInt32(); - notifyType = parcel.ReadInt32(); - srcUri = parcel.ReadString(); - dstUri = parcel.ReadString(); - } - - virtual bool Marshalling(Parcel &parcel) const override - { - if (!parcel.WriteInt32(deviceType)) { - HILOG_ERROR("NotifyMessage Unmarshalling error:write deviceType fail."); - return false; - } - if (!parcel.WriteInt32(notifyType)) { - HILOG_ERROR("NotifyMessage Unmarshalling error:write notifyType fail."); - return false; - } - if (!parcel.WriteString(srcUri)) { - HILOG_ERROR("NotifyMessage Unmarshalling error:write srcUri fail."); - return false; - } - if (!parcel.WriteString(dstUri)) { - HILOG_ERROR("NotifyMessage Unmarshalling error:write dstUri fail."); - return false; - } - return true; - } - - static NotifyMessage *Unmarshalling(Parcel &parcel) - { - NotifyMessage *message = new(std::nothrow) NotifyMessage(); - if (message == nullptr) { - HILOG_ERROR("NotifyMessage Unmarshalling error:new object fail."); - return nullptr; - } - message->ReadFromParcel(parcel); - return message; - } -}; -} // namespace FileAccessFwk -} // namespace OHOS -#endif // FILE_ACCESS_NOTIFY_COMMON_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 deleted file mode 100644 index 1f67adcb5c94dc9b8dad11f89e99047b69a41ae1..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/include/notify/file_access_notify_manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.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 NotifyMapType = std::map, sptr>; - - FileAccessNotifyManager(); - ~FileAccessNotifyManager(); - - int RegisterNotify(sptr ¬ify); - int UnregisterNotify(sptr ¬ify); - int Notify(const NotifyMessage &message); - -private: - void OnCallBackDied(const wptr &remote); - bool AddNotifyToMap(const sptr ¬ify); - bool RemoveNotifyFromMap(const sptr &remote); - NotifyMapType notifyMap_; - static std::mutex notifyMapMutex_; -}; - -class FileAccessNotifyCallbackRecipient : public IRemoteObject::DeathRecipient { -public: - using RemoteDiedHandler = std::function &)>; - FileAccessNotifyCallbackRecipient(RemoteDiedHandler handler); - virtual ~FileAccessNotifyCallbackRecipient(); - virtual void OnRemoteDied(const wptr &remote); - -private: - RemoteDiedHandler handler_; -}; -} // 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/file_access_notify_proxy.h b/frameworks/innerkits/file_access/include/notify/file_access_notify_proxy.h deleted file mode 100644 index 34da9f5fe4b1ad788f73af8b14b63bc8e088cfa5..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/include/notify/file_access_notify_proxy.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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_PROXY_H -#define FILE_ACCESS_NOTIFY_PROXY_H - -#include "ifile_access_notify.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace FileAccessFwk { -class FileAccessNotifyProxy : public IRemoteProxy { -public: - explicit FileAccessNotifyProxy(const sptr &impl); - ~FileAccessNotifyProxy() = default; - int Notify(const NotifyMessage &message) override; -private: - static inline BrokerDelegator delegator_; -}; -} // namespace FileAccessFwk -} // namespace OHOS -#endif // FILE_ACCESS_NOTIFY_PROXY_H \ No newline at end of file diff --git a/frameworks/innerkits/file_access/include/notify/file_access_notify_stub.h b/frameworks/innerkits/file_access/include/notify/file_access_notify_stub.h deleted file mode 100644 index eafd2a9ef4c883efd2761e4446d21827f4af01a8..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/include/notify/file_access_notify_stub.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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_STUB_H -#define FILE_ACCESS_NOTIFY_STUB_H - -#include "ifile_access_notify.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace FileAccessFwk { -class FileAccessNotifyStub : public IRemoteStub { -public: - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) override; -}; -} // namespace FileAccessFwk -} // namespace OHOS -#endif // FILE_ACCESS_NOTIFY_STUB_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 deleted file mode 100644 index f71fc26791de4149a0b83235dc686c715e5e7910..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/include/notify/ifile_access_notify.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 "file_access_notify_common.h" -#include "iremote_broker.h" - -namespace OHOS { -namespace FileAccessFwk { -class IFileAccessNotify : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileAccessFwk.IFileAccessNotify"); - - enum { - CMD_NOTIFY = 1, - }; - - virtual int Notify(const NotifyMessage &message) = 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/inotify_callback.h b/frameworks/innerkits/file_access/include/notify/inotify_callback.h deleted file mode 100644 index 99a8087b3b6e2678e12d47728a6a288cef1ef3be..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/include/notify/inotify_callback.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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_NOTIFY_CALLBACK_H -#define I_NOTIFY_CALLBACK_H - -#include "file_access_notify_common.h" - -namespace OHOS { -namespace FileAccessFwk { -class INotifyCallback { -public: - virtual int OnNotify(const NotifyMessage &message) = 0; -}; -} // namespace FileAccessFwk -} // namespace OHOS -#endif // I_NOTIFY_CALLBACK_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 9856ec8a3b5e868ef6c2c3cbb5a64234ef1b4e8c..924127b4057bbe70e9ab89347c6b094a8c5c9de4 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_ability.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_ability.cpp @@ -129,63 +129,5 @@ int FileAccessExtAbility::Access(const Uri &uri, bool &isExist) return ERR_OPERATION_NOT_SUPPORT; } -bool FileAccessExtAbility::GetNotifyManager() -{ - if (notifyManager_ == nullptr) { - notifyManager_ = std::make_unique(); - if (notifyManager_ == nullptr) { - return false; - } - } - return true; -} - -int FileAccessExtAbility::RegisterNotify(sptr ¬ify) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "RegisterNotify"); - if (!GetNotifyManager()) { - HILOG_ERROR("GetNotifyManager fail."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_INVALID_PARAM; - } - int ret = notifyManager_->RegisterNotify(notify); - if (ret != ERR_OK) { - HILOG_ERROR("NotifyManager register notify fail."); - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; -} - -int FileAccessExtAbility::UnregisterNotify(sptr ¬ify) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "UnregisterNotify"); - if (!GetNotifyManager()) { - HILOG_ERROR("GetNotifyManager fail."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_INVALID_PARAM; - } - int ret = notifyManager_->UnregisterNotify(notify); - if (ret != ERR_OK) { - HILOG_ERROR("NotifyManager unregister notify fail."); - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; -} - -int FileAccessExtAbility::Notify(const NotifyMessage& message) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Notify"); - if (!GetNotifyManager()) { - HILOG_ERROR("GetNotifyManager fail."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_INVALID_PARAM; - } - int ret = notifyManager_->Notify(message); - if (ret != ERR_OK) { - HILOG_ERROR("NotifyManager handle notify fail."); - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - 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 867f04b48eb7b441314d535a59048026e97199fa..89a98fb4ea91a597d8273f4242a8381de80e8c4e 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp @@ -656,87 +656,5 @@ int FileAccessExtProxy::Access(const Uri &uri, bool &isExist) FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ERR_OK; } - -int FileAccessExtProxy::RegisterNotify(sptr ¬ify) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "RegisterNotify"); - MessageParcel data; - if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { - HILOG_ERROR("WriteInterfaceToken failed"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - if (!data.WriteRemoteObject(notify->AsObject())) { - HILOG_ERROR("write subscribe type or parcel failed."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - MessageParcel reply; - MessageOption option; - int err = Remote()->SendRequest(CMD_REGISTER_NOTIFY, data, reply, option); - if (err != ERR_OK) { - HILOG_ERROR("fail to SendRequest. err: %{public}d", err); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return err; - } - - int ret = ERR_PARCEL_FAIL; - if (!reply.ReadInt32(ret)) { - HILOG_ERROR("fail to ReadInt32 ret"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - if (ret != ERR_OK) { - HILOG_ERROR("RegisterNotify operation failed ret : %{public}d", ret); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_OK; -} - -int FileAccessExtProxy::UnregisterNotify(sptr ¬ify) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "UnregisterNotify"); - MessageParcel data; - if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { - HILOG_ERROR("WriteInterfaceToken failed"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - if (!data.WriteRemoteObject(notify->AsObject())) { - HILOG_ERROR("write subscribe type or parcel failed."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - MessageParcel reply; - MessageOption option; - int err = Remote()->SendRequest(CMD_UNREGISTER_NOTIFY, data, reply, option); - if (err != ERR_OK) { - HILOG_ERROR("fail to SendRequest. err: %{public}d", err); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return err; - } - - int ret = ERR_PARCEL_FAIL; - if (!reply.ReadInt32(ret)) { - HILOG_ERROR("fail to ReadInt32 ret"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - if (ret != ERR_OK) { - HILOG_ERROR("UnregisterNotify operation failed ret : %{public}d", ret); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_OK; -} } // 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 e99785d2d60a88c238b85c2ca8f4bfbebd21e28e..79b71e29736d6b73443d7d028fbdc0a43064f765 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp @@ -51,8 +51,6 @@ FileAccessExtStub::FileAccessExtStub() stubFuncMap_[CMD_GET_ROOTS] = &FileAccessExtStub::CmdGetRoots; stubFuncMap_[CMD_ACCESS] = &FileAccessExtStub::CmdAccess; stubFuncMap_[CMD_URI_TO_FILEINFO] = &FileAccessExtStub::CmdUriToFileInfo; - stubFuncMap_[CMD_REGISTER_NOTIFY] = &FileAccessExtStub::CmdRegisterNotify; - stubFuncMap_[CMD_UNREGISTER_NOTIFY] = &FileAccessExtStub::CmdUnregisterNotify; } FileAccessExtStub::~FileAccessExtStub() @@ -528,59 +526,5 @@ bool FileAccessExtStub::CheckCallingPermission(const std::string &permission) FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return true; } - -ErrCode FileAccessExtStub::CmdRegisterNotify(MessageParcel &data, MessageParcel &reply) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "CmdRegisterNotify"); - auto remote = data.ReadRemoteObject(); - if (remote == nullptr) { - HILOG_INFO("get remote obj fail."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - auto notify = iface_cast(remote); - if (notify == nullptr) { - HILOG_INFO("get notify fail"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - int ret = RegisterNotify(notify); - if (!reply.WriteInt32(ret)) { - HILOG_ERROR("Parameter RegisterNotify fail to WriteInt32 ret"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_OK; -} - -ErrCode FileAccessExtStub::CmdUnregisterNotify(MessageParcel &data, MessageParcel &reply) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "CmdUnregisterNotify"); - auto remote = data.ReadRemoteObject(); - if (remote == nullptr) { - HILOG_INFO("get remote obj fail."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - auto notify = iface_cast(remote); - if (notify == nullptr) { - HILOG_INFO("get notify fail"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - - int ret = UnregisterNotify(notify); - if (!reply.WriteInt32(ret)) { - HILOG_ERROR("Parameter UnregisterNotify fail to WriteInt32 ret"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_PARCEL_FAIL; - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - 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 5686bcaf81afd3560fd62e5a6c9526f1905c75c4..9a2e18c38d1381d9aac012ddfa728ec41ca9c551 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 @@ -183,41 +183,5 @@ int FileAccessExtStubImpl::Access(const Uri &uri, bool &isExist) FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ret; } - -int FileAccessExtStubImpl::RegisterNotify(sptr ¬ify) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "RegisterNotify"); - auto extension = GetOwner(); - if (extension == nullptr) { - HILOG_ERROR("get extension failed."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_IPC_ERROR; - } - - int ret = extension->RegisterNotify(notify); - if (ret != ERR_OK) { - HILOG_ERROR("RegisterNotify failed."); - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; -} - -int FileAccessExtStubImpl::UnregisterNotify(sptr ¬ify) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "UnregisterNotify"); - auto extension = GetOwner(); - if (extension == nullptr) { - HILOG_ERROR("get extension failed."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_IPC_ERROR; - } - - int ret = extension->UnregisterNotify(notify); - if (ret != ERR_OK) { - HILOG_ERROR("UnregisterNotify failed."); - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - 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 4d5c9c2ceb8f8bac41b09e152695e9cfe2403dab..f2e50b8f9148cfbdc030ce09fc628c87c4ecb078 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -766,88 +766,6 @@ int FileAccessHelper::UriToFileInfo(Uri &selectFile, FileInfo &fileInfo) return ERR_OK; } -int FileAccessHelper::On(std::shared_ptr &callback) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "On"); - if (callback == nullptr) { - HILOG_ERROR("failed with invalid callback"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_INVALID_PARAM; - } - - if (!GetProxy()) { - HILOG_ERROR("failed with invalid fileAccessExtProxy"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_IPC_ERROR; - } - - std::lock_guard lock(notifyAgentMutex_); - if (notifyAgent_ == nullptr) { - notifyAgent_ = new(std::nothrow) FileAccessNotifyAgent(callback); - if (notifyAgent_ == nullptr) { - HILOG_ERROR("new FileAccessNotifyAgent fail"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_INVALID_PARAM; - } - } - - int errorCode = ERR_OK; - for (auto iter = cMap_.begin(); iter != cMap_.end(); ++iter) { - auto connectInfo = iter->second; - auto fileAccessExtProxy = connectInfo->fileAccessExtConnection->GetFileExtProxy(); - if (fileAccessExtProxy == nullptr) { - HILOG_ERROR("fileAccessExtProxy RegisterNotify fail"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_IPC_ERROR; - } - - errorCode = fileAccessExtProxy->RegisterNotify(notifyAgent_); - if (errorCode != ERR_OK) { - HILOG_ERROR("fileAccessExtProxy RegisterNotify fail, bundleName:%{public}s, ret:%{public}d.", - connectInfo->want.GetElement().GetBundleName().c_str(), errorCode); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return errorCode; - } - } - - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_OK; -} - -int FileAccessHelper::Off() -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Off"); - std::lock_guard lock(notifyAgentMutex_); - if (notifyAgent_ == nullptr) { - HILOG_ERROR("not registered notify"); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_NOTIFY_NOT_EXIST; - } - - int errorCode = ERR_OK; - for (auto [key, value] : cMap_) { - auto connectInfo = value; - auto fileAccessExtProxy = connectInfo->fileAccessExtConnection->GetFileExtProxy(); - if (fileAccessExtProxy == nullptr) { - HILOG_INFO("fileAccessExtProxy UnregisterNotify fail, bundleName:%{public}s", - connectInfo->want.GetElement().GetBundleName().c_str()); - continue; - } - - errorCode = fileAccessExtProxy->UnregisterNotify(notifyAgent_); - if (errorCode != ERR_OK) { - HILOG_ERROR("fileAccessExtProxy UnregisterNotify fail, bundleName:%{public}s, ret:%{public}d.", - connectInfo->want.GetElement().GetBundleName().c_str(), errorCode); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return errorCode; - } - } - - notifyAgent_.clear(); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ERR_OK; -} - 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 e60ef35a713f9f83d7aec6e628f38bfc3cdbfb4d..2dcf4799a7d7b41d94f5a2ee05adad2fa533bc5c 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 @@ -90,56 +90,6 @@ void JsFileAccessExtAbility::Init(const std::shared_ptr &rec FinishTrace(HITRACE_TAG_FILEMANAGEMENT); } -NativeValue* JsFileAccessExtAbility::FuncCallback(NativeEngine* engine, NativeCallbackInfo* info) -{ - StartTrace(HITRACE_TAG_FILEMANAGEMENT, "FuncCallback"); - if (engine == nullptr) { - HILOG_ERROR("NativeEngine pointer is null."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return nullptr; - } - - if (info == nullptr) { - HILOG_ERROR("invalid param."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return engine->CreateUndefined(); - } - - if (info->argc != ARGC_THREE) { - HILOG_ERROR("invalid args."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return engine->CreateUndefined(); - } - - int32_t deviceType = UnwrapInt32FromJS(reinterpret_cast(engine), - reinterpret_cast(info->argv[ARGC_ZERO])); - int32_t notifyType = UnwrapInt32FromJS(reinterpret_cast(engine), - reinterpret_cast(info->argv[ARGC_ONE])); - std::string uri = UnwrapStringFromJS(reinterpret_cast(engine), - reinterpret_cast(info->argv[ARGC_TWO])); - - if (info->functionInfo == nullptr || info->functionInfo->data == nullptr) { - HILOG_ERROR("invalid object."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return engine->CreateUndefined(); - } - - JsFileAccessExtAbility* jsExtension = static_cast(info->functionInfo->data); - if (jsExtension == nullptr) { - HILOG_ERROR("invalid JsFileAccessExtAbility."); - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return engine->CreateUndefined(); - } - - NotifyMessage message(deviceType, notifyType, "", uri); - auto ret = jsExtension->Notify(message); - if (ret != ERR_OK) { - HILOG_ERROR("JsFileAccessExtAbility notify error, ret:%{public}d", ret); - } - FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return engine->CreateUndefined(); -} - void JsFileAccessExtAbility::OnStart(const AAFwk::Want &want) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "OnStart"); @@ -150,13 +100,6 @@ void JsFileAccessExtAbility::OnStart(const AAFwk::Want &want) NativeValue* nativeWant = reinterpret_cast(napiWant); NativeValue* argv[] = {nativeWant}; CallObjectMethod("onCreate", argv, ARGC_ONE); - - const std::string funcName = "FuncCallback"; - auto& nativeEngine = jsRuntime_.GetNativeEngine(); - NativeValue* func = nativeEngine.CreateFunction(funcName.c_str(), funcName.length(), - JsFileAccessExtAbility::FuncCallback, this); - NativeValue* argvCallback[] = {func}; - CallObjectMethod("registerCallback", argvCallback, ARGC_ONE); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); } diff --git a/frameworks/innerkits/file_access/src/notify/file_access_notify_agent.cpp b/frameworks/innerkits/file_access/src/notify/file_access_notify_agent.cpp deleted file mode 100644 index 4db5778f04f2a36acffb9e7c0fb3e00a2db1bd6c..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/src/notify/file_access_notify_agent.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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_agent.h" -#include "hilog_wrapper.h" - -namespace OHOS { -namespace FileAccessFwk { -FileAccessNotifyAgent::FileAccessNotifyAgent(std::shared_ptr ¬ifyCallback) - : notifyCallback_(notifyCallback) -{ -} - -FileAccessNotifyAgent::~FileAccessNotifyAgent() -{ -} - -int FileAccessNotifyAgent::Notify(const NotifyMessage &message) -{ - int ret = ERR_OK; - if (notifyCallback_ != nullptr) { - ret = notifyCallback_->OnNotify(message); - } - return ret; -} -} // 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 deleted file mode 100644 index f4af93c0b529467168db02f3c7346d1314359a80..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/src/notify/file_access_notify_manager.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 "file_access_framework_errno.h" -#include "hilog_wrapper.h" - -namespace OHOS { -namespace FileAccessFwk { -std::mutex FileAccessNotifyManager::notifyMapMutex_; - -FileAccessNotifyManager::FileAccessNotifyManager() -{ -} - -FileAccessNotifyManager::~FileAccessNotifyManager() -{ -} - -int FileAccessNotifyManager::RegisterNotify(sptr ¬ify) -{ - if (!AddNotifyToMap(notify)) { - HILOG_ERROR("the remote obj is nullptr."); - return ERR_INVALID_NOTIFY; - } - HILOG_INFO("FileAccessNotifyManager::RegisterNotify success."); - return ERR_OK; -} - -int FileAccessNotifyManager::UnregisterNotify(sptr ¬ify) -{ - if (notify == nullptr || notify->AsObject() == nullptr) { - HILOG_ERROR("the remote obj is nullptr."); - return ERR_INVALID_NOTIFY; - } - - if (!RemoveNotifyFromMap(notify->AsObject())) { - HILOG_ERROR("remove remote obj from map fail."); - return ERR_REMOVE_NOTIFY_FAIL; - } - HILOG_INFO("FileAccessNotifyManager::UnregisterNotify success."); - return ERR_OK; -} - -int FileAccessNotifyManager::Notify(const NotifyMessage &message) -{ - std::lock_guard lock(notifyMapMutex_); - for (auto iter = notifyMap_.begin(); iter != notifyMap_.end(); iter++) { - if (iter->first != nullptr) { - iter->first->Notify(message); - } - } - return ERR_OK; -} - -bool FileAccessNotifyManager::AddNotifyToMap(const sptr ¬ify) -{ - if (notify == nullptr || notify->AsObject() == nullptr) { - HILOG_ERROR("the death notify obj is nullptr."); - return false; - } - - std::lock_guard lock(notifyMapMutex_); - for (auto iter = notifyMap_.begin(); iter != notifyMap_.end(); iter++) { - if (iter->first == notify) { - iter->first->AsObject()->RemoveDeathRecipient(iter->second); - notifyMap_.erase(iter); - } - } - sptr deathRecipient = new FileAccessNotifyCallbackRecipient( - std::bind(&FileAccessNotifyManager::OnCallBackDied, this, std::placeholders::_1)); - notify->AsObject()->AddDeathRecipient(deathRecipient); - notifyMap_.emplace(notify, deathRecipient); - return true; -} - -bool FileAccessNotifyManager::RemoveNotifyFromMap(const sptr &remote) -{ - if (remote == nullptr) { - HILOG_ERROR("the death remote obj is nullptr."); - return false; - } - - std::lock_guard lock(notifyMapMutex_); - for (auto iter = notifyMap_.begin(); iter != notifyMap_.end(); iter++) { - if (iter->first->AsObject() == remote) { - iter->first->AsObject()->RemoveDeathRecipient(iter->second); - notifyMap_.erase(iter); - return true; - } - } - HILOG_ERROR("find remote object fail."); - return false; -} - -void FileAccessNotifyManager::OnCallBackDied(const wptr &remote) -{ - auto object = remote.promote(); - if (object == nullptr) { - HILOG_INFO("the death remote obj is nullptr"); - return; - } - - if (!RemoveNotifyFromMap(object)) { - HILOG_ERROR("remove remote obj from map fail."); - return; - } -} - -FileAccessNotifyCallbackRecipient::FileAccessNotifyCallbackRecipient(RemoteDiedHandler handler) : handler_(handler) -{ -} - -FileAccessNotifyCallbackRecipient::~FileAccessNotifyCallbackRecipient() -{ -} - -void FileAccessNotifyCallbackRecipient::OnRemoteDied(const wptr &remote) -{ - if (handler_ != nullptr) { - handler_(remote); - } -} -} // namespace FileAccessFwk -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_access/src/notify/file_access_notify_proxy.cpp b/frameworks/innerkits/file_access/src/notify/file_access_notify_proxy.cpp deleted file mode 100644 index 5d4dc22b5d9bff000b8b5345cc740a5d2082181c..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/src/notify/file_access_notify_proxy.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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_proxy.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) -{ -} - -int FileAccessNotifyProxy::Notify(const NotifyMessage& message) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(FileAccessNotifyProxy::GetDescriptor())) { - HILOG_ERROR("write descriptor failed"); - return ERR_IPC_ERROR; - } - - if (!data.WriteParcelable(&message)) { - HILOG_ERROR("write parcel message failed"); - return ERR_IPC_ERROR; - } - - int error = Remote()->SendRequest(CMD_NOTIFY, data, reply, option); - if (error != 0) { - HILOG_ERROR("SendRequest failed, error %{public}d", error); - } - return error; -} -} // namespace FileAccessFwk -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_access/src/notify/file_access_notify_stub.cpp b/frameworks/innerkits/file_access/src/notify/file_access_notify_stub.cpp deleted file mode 100644 index 0330b37b6e922b469ff6f2d4f50d5283f1473a1f..0000000000000000000000000000000000000000 --- a/frameworks/innerkits/file_access/src/notify/file_access_notify_stub.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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_stub.h" - -#include "file_access_framework_errno.h" -#include "hilog_wrapper.h" -#include "message_parcel.h" - -namespace OHOS { -namespace FileAccessFwk { -int32_t FileAccessNotifyStub::OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - auto descriptor = FileAccessNotifyStub::GetDescriptor(); - auto remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - HILOG_ERROR("local descriptor is not equal to remote"); - return ERR_INVALID_PARAM; - } - HILOG_INFO("FileAccessNotifyStub::OnRemoteRequest, code:%{public}u", code); - switch (code) { - case CMD_NOTIFY: { - std::shared_ptr message(data.ReadParcelable()); - if (message == nullptr) { - HILOG_ERROR("read parcelable message fail"); - return ERR_IPC_ERROR; - } - auto ret = Notify(*message); - if (ret != ERR_OK) { - HILOG_ERROR("FileAccessNotifyStub::OnRemoteRequest, Notify error, ret:%{public}d", ret); - } - return ret; - } - default: - HILOG_DEBUG("FileAccessNotifyStub::OnRemoteRequest error code:%{public}u", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} -} // namespace FileAccessFwk -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/common/file_extension_info_napi.cpp b/interfaces/kits/napi/common/file_extension_info_napi.cpp index 386b921f90e6fc723ddbe73293468f2432cb0eb4..5db3a820982833c61e0770acf49188aa527e3d5b 100644 --- a/interfaces/kits/napi/common/file_extension_info_napi.cpp +++ b/interfaces/kits/napi/common/file_extension_info_napi.cpp @@ -21,7 +21,6 @@ #include "filemgmt_libn.h" #include "file_access_extension_info.h" -#include "file_access_notify_common.h" #include "hilog_wrapper.h" #include "js_native_api.h" #include "napi/native_common.h" @@ -100,19 +99,6 @@ void InitDocumentFlag(napi_env env, napi_value exports) napi_set_named_property(env, exports, propertyName, obj); } -void InitNotifyType(napi_env env, napi_value exports) -{ - char propertyName[] = "NotifyType"; - napi_property_descriptor desc[] = { - DECLARE_NAPI_STATIC_PROPERTY("DEVICE_ONLINE", NVal::CreateInt32(env, NOTIFY_DEVICE_ONLINE).val_), - DECLARE_NAPI_STATIC_PROPERTY("DEVICE_OFFLINE", NVal::CreateInt32(env, NOTIFY_DEVICE_OFFLINE).val_) - }; - napi_value obj = nullptr; - napi_create_object(env, &obj); - napi_define_properties(env, obj, sizeof(desc) / sizeof(desc[0]), desc); - napi_set_named_property(env, exports, propertyName, obj); -} - void InitFileInfo(napi_env env, napi_value exports) { char className[] = "FileInfo"; diff --git a/interfaces/kits/napi/common/file_extension_info_napi.h b/interfaces/kits/napi/common/file_extension_info_napi.h index 3bf190e54ae4ac8a7b5c2bb44bd8dc88705e912c..531c856e5ecbb194283743d69f2ef9ee6d773735 100644 --- a/interfaces/kits/napi/common/file_extension_info_napi.h +++ b/interfaces/kits/napi/common/file_extension_info_napi.h @@ -22,7 +22,6 @@ namespace OHOS { namespace FileAccessFwk { void InitDeviceFlag(napi_env env, napi_value exports); void InitDocumentFlag(napi_env env, napi_value exports); -void InitNotifyType(napi_env env, napi_value exports); void InitDeviceType(napi_env env, napi_value exports); void InitFileInfo(napi_env env, napi_value exports); void InitRootInfo(napi_env env, napi_value exports); diff --git a/interfaces/kits/napi/file_access_module/BUILD.gn b/interfaces/kits/napi/file_access_module/BUILD.gn index ccb243f0d041f6aceac4392c4ff1600cc29ada95..497f7703afc54f46678cc4453d667a0997add9b6 100644 --- a/interfaces/kits/napi/file_access_module/BUILD.gn +++ b/interfaces/kits/napi/file_access_module/BUILD.gn @@ -35,7 +35,6 @@ ohos_shared_library("fileaccess") { "file_info/napi_file_info_exporter.cpp", "file_info/napi_file_iterator_exporter.cpp", "napi_fileaccess_helper.cpp", - "napi_notify_callback.cpp", "napi_utils.cpp", "native_fileaccess_module.cpp", "root_info/napi_root_info_exporter.cpp", 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 8e9fb32cb538ca60279860e34cf0168ec4e944e3..b9d8f02b06e3801b2e37758911112f4fe7db881c 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -23,12 +23,10 @@ #include "file_info_entity.h" #include "filemgmt_libn.h" #include "hilog_wrapper.h" -#include "ifile_access_notify.h" #include "napi_base_context.h" #include "napi_common_fileaccess.h" #include "napi_error.h" #include "napi_file_info_exporter.h" -#include "napi_notify_callback.h" #include "napi_root_iterator_exporter.h" #include "root_iterator_entity.h" #include "securec.h" @@ -228,8 +226,6 @@ napi_value FileAccessHelperInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getRoots", NAPI_GetRoots), DECLARE_NAPI_FUNCTION("access", NAPI_Access), DECLARE_NAPI_FUNCTION("uriToFileInfo", NAPI_UriToFileInfo), - DECLARE_NAPI_FUNCTION("on", NAPI_On), - DECLARE_NAPI_FUNCTION("off", NAPI_Off) }; napi_value cons = nullptr; NAPI_CALL(env, @@ -848,61 +844,5 @@ napi_value NAPI_UriToFileInfo(napi_env env, napi_callback_info info) } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; } - -napi_value NAPI_On(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - FileAccessHelper *fileAccessHelper = GetFileAccessHelper(env, funcArg.GetThisVar()); - if (fileAccessHelper == nullptr) { - NError(EINVAL).ThrowErr(env, "Get FileAccessHelper fail"); - return nullptr; - } - - napi_value napiCallback = funcArg[NARG_POS::FIRST]; - if (!NVal(env, napiCallback).TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "Argument must be function"); - return nullptr; - } - - std::shared_ptr callback = std::make_shared(env, napiCallback); - if (callback == nullptr) { - NError(EINVAL).ThrowErr(env, "new NapiNotifyCallback fail."); - return nullptr; - } - - auto retCode = fileAccessHelper->On(callback); - if (retCode != ERR_OK) { - NError(retCode).ThrowErr(env, "FileAccessHelper::On fail."); - return nullptr; - } - return NVal::CreateUndefined(env).val_; -} - -napi_value NAPI_Off(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ZERO)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - FileAccessHelper *fileAccessHelper = GetFileAccessHelper(env, funcArg.GetThisVar()); - if (fileAccessHelper == nullptr) { - NError(EINVAL).ThrowErr(env, "Get FileAccessHelper fail"); - return nullptr; - } - - auto retCode = fileAccessHelper->Off(); - if (retCode != ERR_OK) { - NError(retCode).ThrowErr(env, "FileAccessHelper::Off fail."); - return nullptr; - } - return NVal::CreateUndefined(env).val_; -} } // namespace FileAccessFwk } // 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 6e0a04784dd8e72c9f031be3692fd589f17f7508..4d33046c673f396453b12850fd0c537feb3c7558 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -33,8 +33,6 @@ namespace FileAccessFwk { napi_value NAPI_GetRoots(napi_env env, napi_callback_info info); napi_value NAPI_Access(napi_env env, napi_callback_info info); napi_value NAPI_UriToFileInfo(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 } // namespace OHOS #endif // NAPI_FILEACCESS_HELPER_H \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_notify_callback.cpp b/interfaces/kits/napi/file_access_module/napi_notify_callback.cpp deleted file mode 100644 index 2b9e47a18d4833b1312e6f05d74cc5b631b65742..0000000000000000000000000000000000000000 --- a/interfaces/kits/napi/file_access_module/napi_notify_callback.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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_notify_callback.h" - -#include - -#include "n_val.h" -#include "uv.h" - -using namespace OHOS::FileManagement::LibN; -namespace OHOS { -namespace FileAccessFwk { -namespace { - const int ARGS_ONE = 1; -} - -NapiNotifyCallback::NapiNotifyCallback(napi_env env, napi_value callback) -{ - env_ = env; - napi_create_reference(env_, callback, 1, &callback_); - napi_get_uv_event_loop(env_, &loop_); -} - -NapiNotifyCallback::~NapiNotifyCallback() -{ - napi_delete_reference(env_, callback_); -} - -int NapiNotifyCallback::OnNotify(const NotifyMessage& message) -{ - uv_work_t* work = new uv_work_t(); - if (work == nullptr) { - HILOG_ERROR("failed to new uv_work_t"); - return ERR_INVALID_PARAM; - } - CallbackParam* param = new CallbackParam(this, message); - if (param == nullptr) { - HILOG_ERROR("failed to new param"); - delete work; - return ERR_INVALID_PARAM; - } - work->data = param; - int ret = uv_queue_work(loop_, work, - [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - CallbackParam *param = reinterpret_cast(work->data); - NVal napiNotifyMessage = NVal::CreateObject(param->callback_->env_); - napiNotifyMessage.AddProp("deviceType", - NVal::CreateInt32(param->callback_->env_, param->message_.deviceType).val_); - napiNotifyMessage.AddProp("notifyType", - NVal::CreateInt32(param->callback_->env_, param->message_.notifyType).val_); - napiNotifyMessage.AddProp("srcUri", - NVal::CreateUTF8String(param->callback_->env_, param->message_.srcUri).val_); - napiNotifyMessage.AddProp("dstUri", - NVal::CreateUTF8String(param->callback_->env_, param->message_.dstUri).val_); - - napi_value callback = nullptr; - napi_value args[ARGS_ONE] = {napiNotifyMessage.val_}; - napi_get_reference_value(param->callback_->env_, param->callback_->callback_, &callback); - napi_value global = nullptr; - napi_get_global(param->callback_->env_, &global); - napi_value result = nullptr; - napi_status ret = napi_call_function(param->callback_->env_, global, callback, ARGS_ONE, args, &result); - if (ret != napi_ok) { - HILOG_ERROR("Notify failed, status:%{public}d.", ret); - } - delete param; - delete work; - }); - if (ret != 0) { - delete (CallbackParam *)(work->data); - work->data = nullptr; - delete work; - work = nullptr; - return ERR_NOTIFY_FAIL; - } - - delete (CallbackParam *)(work->data); - work->data = nullptr; - delete work; - work = nullptr; - return ERR_OK; -} -} // namespace FileAccessFwk -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_notify_callback.h b/interfaces/kits/napi/file_access_module/napi_notify_callback.h deleted file mode 100644 index 2f89b00623c39153eb63eed7bf4740f9329543f8..0000000000000000000000000000000000000000 --- a/interfaces/kits/napi/file_access_module/napi_notify_callback.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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_NOTIFY_CALLBACK_H -#define NAPI_NOTIFY_CALLBACK_H - -#include "file_access_framework_errno.h" -#include "hilog_wrapper.h" -#include "inotify_callback.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 NapiNotifyCallback : public INotifyCallback { -public: - NapiNotifyCallback(napi_env env, napi_value callback); - virtual ~NapiNotifyCallback(); - int OnNotify(const NotifyMessage &message) override; - -private: - struct CallbackParam { - NapiNotifyCallback *callback_; - NotifyMessage message_; - CallbackParam(NapiNotifyCallback *callback, NotifyMessage message) - : callback_(callback), message_(message) - {} - }; - napi_ref callback_ = nullptr; - napi_env env_; - uv_loop_s *loop_ = nullptr; -}; -} // namespace FileAccessFwk -} // namespace OHOS -#endif // NAPI_NOTIFY_CALLBACK_H \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp index 8ccb330d44ab14db500c4547213f9a57e7c36fb1..286f20906e6bf494daa2ab55dfad188944378dbe 100644 --- a/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp +++ b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp @@ -38,7 +38,6 @@ static napi_value Init(napi_env env, napi_value exports) FileAccessHelperInit(env, exports); InitDeviceFlag(env, exports); InitDocumentFlag(env, exports); - InitNotifyType(env, exports); InitDeviceType(env, exports); InitFileInfo(env, exports); InitRootInfo(env, exports); diff --git a/interfaces/kits/napi/file_extension_info_module/BUILD.gn b/interfaces/kits/napi/file_extension_info_module/BUILD.gn index 003382b922a8a8e9c139f1e0a80e3734fe9dbb72..7bb5d1ec1b7427fedc64e49960854aa90bba51cf 100644 --- a/interfaces/kits/napi/file_extension_info_module/BUILD.gn +++ b/interfaces/kits/napi/file_extension_info_module/BUILD.gn @@ -25,7 +25,6 @@ ohos_shared_library("fileextensioninfo") { ".", "//foundation/filemanagement/file_api/utils/filemgmt_libn/include", "${FRAMEWORK_PATH}/innerkits/file_access/include", - "${FRAMEWORK_PATH}/innerkits/file_access/include/notify", "${UFS_BASE_PATH}/interfaces/kits/napi/common", "${UFS_BASE_PATH}/utils", "//foundation/ability/ability_base/interfaces/kits/native/uri/include", diff --git a/interfaces/kits/napi/file_extension_info_module/module_export_napi.cpp b/interfaces/kits/napi/file_extension_info_module/module_export_napi.cpp index aecf94166f3e7a7a63e9da384e3bcbc4d4516b02..bd33c5bd634714b8f748effb65d5b723cfd4520d 100644 --- a/interfaces/kits/napi/file_extension_info_module/module_export_napi.cpp +++ b/interfaces/kits/napi/file_extension_info_module/module_export_napi.cpp @@ -25,7 +25,6 @@ napi_value FileExtensionInfoExport(napi_env env, napi_value exports) { InitDeviceFlag(env, exports); InitDocumentFlag(env, exports); - InitNotifyType(env, exports); InitDeviceType(env, exports); InitFileInfo(env, exports); InitRootInfo(env, exports); diff --git a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts index b9c69e6181a37e36b350135a3f7b42a4821f74f3..06f70537621238ba82b0b418df972265f4788ace 100644 --- a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts +++ b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -23,7 +23,6 @@ import process from '@ohos.process'; const DeviceFlag = fileExtensionInfo.DeviceFlag; const DocumentFlag = fileExtensionInfo.DocumentFlag; -const NotifyType = fileExtensionInfo.NotifyType; const DeviceType = fileExtensionInfo.DeviceType; const BUNDLE_NAME = 'com.ohos.UserFile.ExternalFileManager'; const DEFAULT_MODE = 0o666; @@ -33,38 +32,19 @@ const DOMAIN_CODE = 0x0001; const TAG = 'js_server'; const ERR_OK = 0; const ERR_ERROR = -1; -let callbackFun = null; export default class FileExtAbility extends Extension { onCreate(want) { init(); onReceiveEvent(function (data) { if (data.event == 'usual.event.data.VOLUME_MOUNTED') { - if (callbackFun != null) { - let uri = path2uri('', data.parameters.path); - callbackFun(data.parameters.type, NotifyType.DEVICE_ONLINE, uri); - } process.exit(0); } else { - if (callbackFun != null) { - let uri = ''; - let deviceType = 0; - let volumeInfo = findVolumeInfo(data.parameters.id); - if (volumeInfo) { - uri = volumeInfo.uri; - deviceType = volumeInfo.type; - } - callbackFun(deviceType, NotifyType.DEVICE_OFFLINE, uri); - } delVolumeInfo(data.parameters.id); } }); } - registerCallback(callback) { - callbackFun = callback; - } - checkUri(uri) { if (uri.indexOf(URI_SCHEME) == 0) { uri = uri.replace(URI_SCHEME, '');