From be389c9bfd0ab5be9aca25abef92f7309ab78724 Mon Sep 17 00:00:00 2001 From: CaoChuan Date: Wed, 24 May 2023 06:19:23 +0000 Subject: [PATCH] feat: faf add helper Signed-off-by: CaoChuan --- interfaces/inner_api/file_access/BUILD.gn | 1 + .../file_access/include/file_access_helper.h | 3 ++ .../file_access/src/file_access_helper.cpp | 49 +++++++++++++++++++ .../src/file_access_service_proxy.cpp | 20 ++------ .../src/file_access_service_stub.cpp | 4 +- utils/file_access_framework_errno.h | 3 +- 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/interfaces/inner_api/file_access/BUILD.gn b/interfaces/inner_api/file_access/BUILD.gn index 2deb848a..d48847a9 100644 --- a/interfaces/inner_api/file_access/BUILD.gn +++ b/interfaces/inner_api/file_access/BUILD.gn @@ -38,6 +38,7 @@ config("ability_public_config") { include_dirs = [ "include", "${user_file_service_path}/utils", + "${user_file_service_path}/services/native/file_access_service/include", "${ability_runtime_kits_path}/appkit/native/ability_runtime/app", "${ability_runtime_kits_path}/appkit/native/app/include", "${ability_runtime_kits_path}/appkit/native/ability_runtime/context", diff --git a/interfaces/inner_api/file_access/include/file_access_helper.h b/interfaces/inner_api/file_access/include/file_access_helper.h index b7521bce..34823dfa 100644 --- a/interfaces/inner_api/file_access/include/file_access_helper.h +++ b/interfaces/inner_api/file_access/include/file_access_helper.h @@ -28,6 +28,7 @@ #include "file_access_extension_info.h" #include "ifile_access_ext_base.h" #include "image_source.h" +#include "iobserver_callback.h" #include "iremote_object.h" #include "refbase.h" #include "uri.h" @@ -84,6 +85,8 @@ public: int GetFileInfoFromUri(Uri &selectFile, FileInfo &fileInfo); int GetFileInfoFromRelativePath(std::string &selectFile, FileInfo &fileInfo); int GetRoots(std::vector &rootInfoVec); + int RegisterNotify(Uri uri, sptr &observer, bool notifyForDescendants); + int UnregisterNotify(Uri uri, sptr &observer); private: sptr GetProxyByUri(Uri &uri); sptr GetProxyByBundleName(const std::string &bundleName); diff --git a/interfaces/inner_api/file_access/src/file_access_helper.cpp b/interfaces/inner_api/file_access/src/file_access_helper.cpp index 1e394393..66962312 100644 --- a/interfaces/inner_api/file_access/src/file_access_helper.cpp +++ b/interfaces/inner_api/file_access/src/file_access_helper.cpp @@ -20,6 +20,7 @@ #include "bundle_mgr_proxy.h" #include "file_access_framework_errno.h" #include "file_access_extension_info.h" +#include "file_access_service_proxy.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" #include "if_system_ability_manager.h" @@ -1173,6 +1174,54 @@ int FileAccessHelper::GetFileInfoFromRelativePath(std::string &selectFile, FileI return ERR_OK; } +int FileAccessHelper::RegisterNotify(Uri uri, sptr &observer,bool notifyForDescendants) +{ + StartTrace(HITRACE_TAG_FILEMANAGEMENT, "RegisterNotify"); + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + return E_GETRESULT; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(5010); + if (!remoteObject) { + HILOG_ERROR("remoteObject is nullptr"); + return E_LOAD_SA; + } + auto proxy = iface_cast(remoteObject); + int ret = proxy->RegisterNotify(uri, observer, notifyForDescendants); + if (ret != ERR_OK) { + HILOG_ERROR("RegisterNotify operation failed ret : %{public}d", ret); + return ret; + } + + return ERR_OK; +} + +int FileAccessHelper::UnregisterNotify(Uri uri, sptr &observer) +{ + StartTrace(HITRACE_TAG_FILEMANAGEMENT, "UnregisterNotify"); + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + return E_GETRESULT; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(5010); + if (!remoteObject) { + HILOG_ERROR("remoteObject is nullptr"); + return E_LOAD_SA; + } + auto proxy = iface_cast(remoteObject); + int ret = proxy->UnregisterNotify(uri, observer); + if (ret != ERR_OK) { + HILOG_ERROR("UnregisterNotify operation failed ret : %{public}d", ret); + return ret; + } + + return ret; +} + void FileAccessDeathRecipient::OnRemoteDied(const wptr &remote) { if (handler_) { diff --git a/services/native/file_access_service/src/file_access_service_proxy.cpp b/services/native/file_access_service/src/file_access_service_proxy.cpp index af393f40..2999fa6b 100644 --- a/services/native/file_access_service/src/file_access_service_proxy.cpp +++ b/services/native/file_access_service/src/file_access_service_proxy.cpp @@ -60,16 +60,10 @@ int32_t FileAccessServiceProxy::RegisterNotify(Uri uri, const sptr