From edebb00ba8e72883e2bf20f0f1cb2e165972eb0e Mon Sep 17 00:00:00 2001 From: hunili Date: Thu, 27 Jun 2024 19:26:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=A2=84=E5=88=B6=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E9=80=82=E9=85=8D=20issue:=20https://gitee.c?= =?UTF-8?q?om/openharmony/filemanagement=5Fuser=5Ffile=5Fservice/issues/IA?= =?UTF-8?q?8VNA=20Signed-off-by:=20hunili=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publicity.xml | 16 ++++++++++++++++ services/BUILD.gn | 1 + 2 files changed, 17 insertions(+) create mode 100644 publicity.xml diff --git a/publicity.xml b/publicity.xml new file mode 100644 index 00000000..08c7f26a --- /dev/null +++ b/publicity.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/services/BUILD.gn b/services/BUILD.gn index fa3f9b31..37b5784f 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -29,6 +29,7 @@ ohos_hap("external_file_manager_hap") { ":external_file_manager_js_assets", ":external_file_manager_resources", ] + publicity_file = "../publicity.xml" certificate_profile = "signature/fileextension.p7b" hap_name = "external_file_manager" subsystem_name = "filemanagement" -- Gitee From e7d7ab4e1be018382c1fb7c8237352ad5950538d Mon Sep 17 00:00:00 2001 From: hunili Date: Tue, 16 Jul 2024 21:05:23 +0800 Subject: [PATCH 2/2] Connect extService by fileAccessService issue: https://gitee.com/openharmony/filemanagement_user_file_service/issues/IADFZE Signed-off-by: hunili --- .../include/file_access_extension_info.h | 16 ++++++++-- .../src/file_access_ext_connection.cpp | 9 +++++- .../include/file_access_service.h | 1 + .../file_access_service_ipc_interface_code.h | 3 +- .../include/file_access_service_proxy.h | 1 + .../include/file_access_service_stub.h | 1 + .../include/ifile_access_service_base.h | 1 + .../src/file_access_service.cpp | 9 ++++++ .../src/file_access_service_proxy.cpp | 29 +++++++++++++++++++ .../src/file_access_service_stub.cpp | 14 +++++++++ 10 files changed, 80 insertions(+), 4 deletions(-) diff --git a/interfaces/inner_api/file_access/include/file_access_extension_info.h b/interfaces/inner_api/file_access/include/file_access_extension_info.h index 2be9daa5..b4819906 100644 --- a/interfaces/inner_api/file_access/include/file_access_extension_info.h +++ b/interfaces/inner_api/file_access/include/file_access_extension_info.h @@ -304,11 +304,14 @@ struct ConnectExtensionInfo : public MessageParcelable { public: AAFwk::Want want = {}; sptr token = nullptr; + sptr extConnection_ = nullptr; ConnectExtensionInfo() = default; ConnectExtensionInfo(AAFwk::Want want, sptr token) : want(want), token(token) {} + ConnectExtensionInfo(AAFwk::Want want, sptr token, sptr connect) : want(want), + token(token), extConnection_(connect){} - bool WriteToParcel(MessageParcel &parcel) const override + bool WriteToParcel(MessageParcel &parcel, bool ifWriteConnect = false) const override { if (!parcel.WriteParcelable(&want)) { return false; @@ -316,10 +319,13 @@ public: if (!parcel.WriteRemoteObject(token)) { return false; } + if (ifWriteConnect && !parcel.WriteRemoteObject(extConnection_)) { + return false; + } return true; } - bool ReadFromParcel(MessageParcel &parcel) override + bool ReadFromParcel(MessageParcel &parcel, bool ifReadConnect = false) override { std::shared_ptr wantPtr(parcel.ReadParcelable()); token = parcel.ReadRemoteObject(); @@ -327,6 +333,12 @@ public: return false; } want = AAFwk::Want(*wantPtr); + if (ifReadConnect) { + extConnection_ = parcel.ReadRemoteObject(); + if (extConnection_ == nullptr) { + return false; + } + } return true; } }; diff --git a/interfaces/inner_api/file_access/src/file_access_ext_connection.cpp b/interfaces/inner_api/file_access/src/file_access_ext_connection.cpp index be93711e..dd184676 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_connection.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_connection.cpp @@ -65,7 +65,14 @@ void FileAccessExtConnection::ConnectFileExtAbility(const AAFwk::Want &want, con fileExtProxy_ = nullptr; } isConnected_.store(false); - ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, token); + auto proxy = FileAccessServiceProxy::GetInstance(); + if (proxy == nullptr) { + HILOG_ERROR("ConnectFileExtAbility get SA failed"); + return E_LOAD_SA; + } + std::shared_ptr connectExtensionInfo = + std::make_shared(connectInfo->want, token, this->AsObject()); + int32_t ret = proxy->ConnectExtService(connectExtensionInfo); if (ret != ERR_OK) { HILOG_ERROR("ConnectAbility failed, ret=%{public}d", ret); return; diff --git a/services/native/file_access_service/include/file_access_service.h b/services/native/file_access_service/include/file_access_service.h index b70b9222..0f7b355a 100644 --- a/services/native/file_access_service/include/file_access_service.h +++ b/services/native/file_access_service/include/file_access_service.h @@ -231,6 +231,7 @@ protected: int32_t OnChange(Uri uri, NotifyType notifyType) override; int32_t GetExensionProxy(const std::shared_ptr &info, sptr &extensionProxy) override; + int32_t ConnectExtService(const std::shared_ptr &info) override; private: class ExtensionDeathRecipient : public IRemoteObject::DeathRecipient { diff --git a/services/native/file_access_service/include/file_access_service_ipc_interface_code.h b/services/native/file_access_service/include/file_access_service_ipc_interface_code.h index 6e16398d..5c36dfca 100644 --- a/services/native/file_access_service/include/file_access_service_ipc_interface_code.h +++ b/services/native/file_access_service/include/file_access_service_ipc_interface_code.h @@ -22,7 +22,8 @@ namespace FileAccessFwk { CMD_REGISTER_NOTIFY = 0, CMD_UNREGISTER_NOTIFY, CMD_ONCHANGE, - CMD_GET_EXTENSION_PROXY + CMD_GET_EXTENSION_PROXY, + CMD_CONNECT_EXT_SERVICE }; } // namespace FileAccessFwk } // namespace OHOS diff --git a/services/native/file_access_service/include/file_access_service_proxy.h b/services/native/file_access_service/include/file_access_service_proxy.h index 4f932036..1f2536f9 100644 --- a/services/native/file_access_service/include/file_access_service_proxy.h +++ b/services/native/file_access_service/include/file_access_service_proxy.h @@ -35,6 +35,7 @@ public: const std::shared_ptr &info) override; int32_t GetExensionProxy(const std::shared_ptr &info, sptr &extensionProxy) override; + int32_t ConnectExtService(const std::shared_ptr &info); class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { public: diff --git a/services/native/file_access_service/include/file_access_service_stub.h b/services/native/file_access_service/include/file_access_service_stub.h index cc01c4e4..4f5d9a1a 100644 --- a/services/native/file_access_service/include/file_access_service_stub.h +++ b/services/native/file_access_service/include/file_access_service_stub.h @@ -38,6 +38,7 @@ private: ErrCode CmdRegisterNotify(MessageParcel &data, MessageParcel &reply); ErrCode CmdUnregisterNotify(MessageParcel &data, MessageParcel &reply); ErrCode CmdGetExensionProxy(MessageParcel &data, MessageParcel &reply); + ErrCode CmdConnectExtService(MessageParcel &data, MessageParcel &reply); bool CheckCallingPermission(const std::string &permission); using RequestFuncType = int (FileAccessServiceStub::*)(MessageParcel &data, MessageParcel &reply); std::map stubFuncMap_; diff --git a/services/native/file_access_service/include/ifile_access_service_base.h b/services/native/file_access_service/include/ifile_access_service_base.h index fc0c44d2..5c8797f4 100644 --- a/services/native/file_access_service/include/ifile_access_service_base.h +++ b/services/native/file_access_service/include/ifile_access_service_base.h @@ -38,6 +38,7 @@ protected: //Get exension proxy by SA virtual int32_t GetExensionProxy(const std::shared_ptr &info, sptr &extensionProxy) = 0; + virtual int32_t ConnectExtension(const std::shared_ptr &info) = 0; }; } // namespace FileAccessFwk } // namespace OHOS diff --git a/services/native/file_access_service/src/file_access_service.cpp b/services/native/file_access_service/src/file_access_service.cpp index 4811f71c..5016d6e4 100644 --- a/services/native/file_access_service/src/file_access_service.cpp +++ b/services/native/file_access_service/src/file_access_service.cpp @@ -656,5 +656,14 @@ int32_t FileAccessService::RmUriObsNodeRelations(std::string &uriStr, std::share RemoveRelations(uriStr, obsNode); return ERR_OK; } + +int32_t FileAccessService::ConnectExtService(const std::shared_ptr &info) +{ + if (info == nullptr || info->token == nullptr || info->connect_ == nullptr) { + HILOG_ERROR("ConnectExtensionInfo is invalid"); + return E_CONNECT; + } + return AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(info->want, info->connect_, info->token); +} } // namespace FileAccessFwk } // namespace OHOS 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 83b679ac..75798356 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 @@ -324,5 +324,34 @@ int32_t FileAccessServiceProxy::GetExensionProxy(const std::shared_ptr &info) { + UserAccessTracer trace; + trace.Start("ConnectExtension"); + MessageParcel data; + if (!data.WriteInterfaceToken(FileAccessServiceProxy::GetDescriptor())) { + HILOG_ERROR("WriteInterfaceToken failed"); + return E_IPCS; + } + + if (info == nullptr) { + HILOG_ERROR("ExtensionInfo is nullptr"); + return E_GETINFO; + } + + if (!info->WriteToParcel(data, true)) { + HILOG_ERROR("fail to WriteParcelable Info"); + return E_IPCS; + } + + MessageParcel reply; + MessageOption option; + int err = Remote()->SendRequest(static_cast(FileAccessServiceInterfaceCode::CMD_CONNECT_EXT_SERVICE), + data, reply, option); + if (err != ERR_OK) { + HILOG_ERROR("fail to SendRequest. err: %{public}d", err); + } + return err; +} } // namespace FileAccessFwk } // namespace OHOS diff --git a/services/native/file_access_service/src/file_access_service_stub.cpp b/services/native/file_access_service/src/file_access_service_stub.cpp index 1ffe1759..813174ae 100644 --- a/services/native/file_access_service/src/file_access_service_stub.cpp +++ b/services/native/file_access_service/src/file_access_service_stub.cpp @@ -43,6 +43,8 @@ FileAccessServiceStub::FileAccessServiceStub() &FileAccessServiceStub::CmdUnregisterNotify; stubFuncMap_[static_cast(FileAccessServiceInterfaceCode::CMD_ONCHANGE)] = &FileAccessServiceStub::CmdOnChange; + stubFuncMap_[static_cast(FileAccessServiceInterfaceCode::CMD_CONNECT_EXT_SERVICE)] = + &FileAccessServiceStub::CmdConnectExtService; } FileAccessServiceStub::~FileAccessServiceStub() @@ -212,5 +214,17 @@ ErrCode FileAccessServiceStub::CmdGetExensionProxy(MessageParcel &data, MessageP } return ERR_OK; } + +ErrCode FileAccessServiceStub::CmdConnectExtService(MessageParcel &data, MessageParcel &reply) +{ + UserAccessTracer trace; + trace.Start("CmdConnectExtService"); + std::shared_ptr connectExtensionInfo = std::make_shared(); + if (!connectExtensionInfo->ReadFromParcel(data, true)) { + HILOG_ERROR("fail to read info"); + return E_IPCS; + } + return ConnectExtService(connectExtensionInfo); +} } // namespace FileAccessFwk } // namespace OHOS \ No newline at end of file -- Gitee