From 7a0a282295130cf7a0cdf7cdde2e7e47f854f2bb Mon Sep 17 00:00:00 2001 From: rookiiie Date: Thu, 19 Dec 2024 12:16:29 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UIExtension=E9=80=9A?= =?UTF-8?q?=E7=94=A8IPC=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rookiiie --- .../innerkits/wm/data_handler_interface.h | 112 ++++++++++++++++++ interfaces/innerkits/wm/window.h | 6 + .../common/include/extension_data_handler.h | 71 +++++++++++ .../zidl/session_stage_ipc_interface_code.h | 4 + .../session/host/include/extension_session.h | 3 + .../include/zidl/session_ipc_interface_code.h | 1 + 6 files changed, 197 insertions(+) create mode 100644 interfaces/innerkits/wm/data_handler_interface.h create mode 100644 window_scene/common/include/extension_data_handler.h diff --git a/interfaces/innerkits/wm/data_handler_interface.h b/interfaces/innerkits/wm/data_handler_interface.h new file mode 100644 index 0000000000..deb437adcd --- /dev/null +++ b/interfaces/innerkits/wm/data_handler_interface.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2024 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. + */ + +#pragma once + +#include +#include +#include + +namespace OHOS::AAFwk { +class Want; +} // namespace OHOS::AAFwk + +namespace OHOS::Rosen { + +enum class SubSystemId : uint32_t { WM_UIEXT = 0, ARKUI_UIEXT, ABILITY_UIEXT, INVALID }; + +enum class DataHandlerErr : uint32_t { + // common + OK = 0, + INVALID_PARAMETER, + INTERNAL_ERROR, + DUPLICATE_REGISTRATION, + NULL_PTR, + + // ipc processing errors + IPC_SEND_FAILED, + WRITE_PARCEL_ERROR, + READ_PARCEL_ERROR, + + // callback errors + NO_CONSUME_CALLBACK, + INVALID_CALLBACK, +}; + +using DataConsumeCallback = + std::function reply)>; + +/** + * @class IDataHandler + * @brief Interface for handling data operations between subsystems by using the IPC. + * + * This class defines an interface for sending and receiving data between different + * subsystems, as well as registering and unregistering data consumers. It provides + * methods for both synchronous and asynchronous data transmission. + */ +class IDataHandler { +public: + IDataHandler() = default; + virtual ~IDataHandler() = default; + + /** + * @brief Sends data synchronously to a specified subsystem and receives a reply. + * + * @param subSystemId The identifier of the target subsystem. + * @param customId A custom identifier for the data being sent. + * @param data The Want object containing the data to be sent. + * @param reply A reference to a Want object that will be filled with the reply data. + * @return DataHandlerErr::OK if the data was successfully sent and a reply was received, other errcode otherwise. + */ + virtual DataHandlerErr SendDataSync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data, + AAFwk::Want& reply) = 0; + + /** + * @brief Sends data synchronously to a specified subsystem without reply. + * + * @param subSystemId The identifier of the target subsystem. + * @param customId A custom identifier for the data being sent. + * @param data The Want object containing the data to be sent. + * @return DataHandlerErr::OK if the data was successfully sent, other errcode otherwise. + */ + virtual DataHandlerErr SendDataSync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data) = 0; + + /** + * @brief Sends data asynchronously to a specified subsystem without reply. + * + * @param subSystemId The identifier of the target subsystem. + * @param customId A custom identifier for the data being sent. + * @param data The Want object containing the data to be sent. + * @return DataHandlerErr::OK if the data was successfully sent, other errcode otherwise. + */ + virtual DataHandlerErr SendDataAsync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data) = 0; + + /** + * @brief Registers a data consumer for a specific subsystemId. + * + * @param SubSystemId The identifier of the data to be consumed. + * @param callback A DataConsumerInfo object containing the callback function and options. + * @return DataHandlerErr::OK if the data consumer was successfully registered, other errcode otherwise. + */ + virtual DataHandlerErr RegisterDataConsumer(SubSystemId subSystemId, DataConsumeCallback&& callback) = 0; + + /** + * @brief Unregisters a data consumer for a specific subSystemId. + * + * @param SubSystemId The identifier of the data to be consumed. + */ + virtual void UnregisterDataConsumer(SubSystemId subSystemId) = 0; +}; +} // namespace OHOS::Rosen diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 8df4083a71..ffbd774d06 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -24,6 +24,7 @@ #include "wm_common.h" #include "window_option.h" #include "occupied_area_change_info.h" +#include "data_handler_interface.h" typedef struct napi_env__* napi_env; typedef struct napi_value__* napi_value; @@ -2712,6 +2713,11 @@ public: */ virtual void NotifyExtensionTimeout(int32_t errorCode) {} + /** + * @brief Get Data Handler of UIExtension + */ + virtual std::shared_ptr GetExtensionDataHandler() const { return nullptr; } + /** * @brief Get the real parent id of UIExtension * diff --git a/window_scene/common/include/extension_data_handler.h b/window_scene/common/include/extension_data_handler.h new file mode 100644 index 0000000000..f95a064ebb --- /dev/null +++ b/window_scene/common/include/extension_data_handler.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 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. + */ + +#pragma once + +#include "data_handler_interface.h" + +#include +#include +#include + +#include +#include +#include "message_parcel.h" + +namespace OHOS::Rosen::Extension { + +class TransferConfig : public Parcelable { +public: + bool Marshalling(Parcel& parcel) const override; + static TransferConfig* Unmarshalling(Parcel& parcel); + std::string ToString() const; + +public: + bool needSyncSend_ { false }; + bool needReply_ { false }; + SubSystemId subSystemId_ { SubSystemId::INVALID }; + uint32_t customId_ { 0 }; +}; + +using Task = std::function; + +class DataHandler : public IDataHandler { +public: + DataHandler(std::shared_ptr& eventHandler) : eventHandler_(eventHandler) {}; + virtual ~DataHandler() = default; + + DataHandlerErr SendDataSync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data, + AAFwk::Want& reply) override; + DataHandlerErr SendDataSync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data) override; + DataHandlerErr SendDataAsync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data) override; + DataHandlerErr RegisterDataConsumer(SubSystemId dataId, DataConsumeCallback&& callback) override; + void UnregisterDataConsumer(SubSystemId dataId) override; + DataHandlerErr NotifyDataConsumer(AAFwk::Want&& data, std::optional reply, + const TransferConfig& config); + +protected: + virtual DataHandlerErr SendData(AAFwk::Want& data, AAFwk::Want& reply, const TransferConfig& config) = 0; + DataHandlerErr PrepareData(MessageParcel& data, AAFwk::Want& toSend, const TransferConfig& config); + DataHandlerErr ParseReply(MessageParcel& data, AAFwk::Want& reply, const TransferConfig& config); + void PostAsyncTask(Task&& task, const std::string& name, int64_t delayTime); + +protected: + mutable std::shared_mutex mutex_; + std::unordered_map consumers_; + std::shared_ptr eventHandler_; +}; + +} // namespace OHOS::Rosen::Extension \ No newline at end of file diff --git a/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h b/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h index 7b651df00f..a8ae377e18 100644 --- a/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h +++ b/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h @@ -59,7 +59,11 @@ enum class SessionStageInterfaceCode { TRANS_ID_COMPATIBLE_FULLSCREEN_CLOSE, TRANS_ID_NOTIFY_DENSITY_UNIQUE, TRANS_ID_NOTIFY_SESSION_FULLSCREEN, + + // Extension + TRANS_ID_SEND_EXTENSION_DATA, TRANS_ID_NOTIFY_DUMP_INFO, + TRANS_ID_SET_SPLIT_BUTTON_VISIBLE, TRANS_ID_NOTIFY_COMPATIBLE_MODE_ENABLE, TRANS_ID_SET_ENABLE_DRAG_BY_SYSTEM, diff --git a/window_scene/session/host/include/extension_session.h b/window_scene/session/host/include/extension_session.h index e46d5f46af..a1f6c883d5 100644 --- a/window_scene/session/host/include/extension_session.h +++ b/window_scene/session/host/include/extension_session.h @@ -21,6 +21,7 @@ #include "want.h" #include "session/host/include/session.h" +#include "extension_data_handler.h" namespace OHOS::Rosen { class WindowEventChannelListener : public IRemoteStub { @@ -78,6 +79,7 @@ public: explicit ExtensionSession(const SessionInfo& info); virtual ~ExtensionSession(); + std::shared_ptr GetExtensionDataHandler() const; WSError Connect(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, SystemSessionConfig& systemConfig, sptr property, sptr token, @@ -122,6 +124,7 @@ private: bool isFirstTriggerBindModal_ = true; sptr channelDeath_ = nullptr; sptr channelListener_ = nullptr; + std::shared_ptr dataHandler_; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/zidl/session_ipc_interface_code.h b/window_scene/session/host/include/zidl/session_ipc_interface_code.h index 28b22df4a1..65a61b1782 100644 --- a/window_scene/session/host/include/zidl/session_ipc_interface_code.h +++ b/window_scene/session/host/include/zidl/session_ipc_interface_code.h @@ -87,6 +87,7 @@ enum class SessionInterfaceCode { TRANS_ID_NOTIFY_EXTENSION_TIMEOUT, TRANS_ID_NOTIFY_EXTENSION_EVENT_ASYNC, TRANS_ID_NOTIFY_EXTENSION_DETACH_TO_DISPLAY, + TRANS_ID_SEND_EXTENSION_DATA, // PictureInPicture TRANS_ID_NOTIFY_PIP_WINDOW_PREPARE_CLOSE = 800, -- Gitee From 790e8c122f7cf5981de927d4040b5840cb9c193e Mon Sep 17 00:00:00 2001 From: rookiiie Date: Thu, 19 Dec 2024 13:35:32 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rookiiie --- .../innerkits/wm/data_handler_interface.h | 71 ++++++++++--------- .../common/include/extension_data_handler.h | 29 ++++---- 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/interfaces/innerkits/wm/data_handler_interface.h b/interfaces/innerkits/wm/data_handler_interface.h index deb437adcd..52c30ef4df 100644 --- a/interfaces/innerkits/wm/data_handler_interface.h +++ b/interfaces/innerkits/wm/data_handler_interface.h @@ -13,7 +13,8 @@ * limitations under the License. */ -#pragma once +#ifndef OHOS_ROSEN_DATA_HANDLER_H +#define OHOS_ROSEN_DATA_HANDLER_H #include #include @@ -25,7 +26,7 @@ class Want; namespace OHOS::Rosen { -enum class SubSystemId : uint32_t { WM_UIEXT = 0, ARKUI_UIEXT, ABILITY_UIEXT, INVALID }; +enum class SubSystemId : uint8_t { WM_UIEXT = 0, ARKUI_UIEXT, ABILITY_UIEXT, INVALID }; enum class DataHandlerErr : uint32_t { // common @@ -62,51 +63,53 @@ public: virtual ~IDataHandler() = default; /** - * @brief Sends data synchronously to a specified subsystem and receives a reply. - * - * @param subSystemId The identifier of the target subsystem. - * @param customId A custom identifier for the data being sent. - * @param data The Want object containing the data to be sent. - * @param reply A reference to a Want object that will be filled with the reply data. - * @return DataHandlerErr::OK if the data was successfully sent and a reply was received, other errcode otherwise. - */ + * @brief Sends data synchronously to a specified subsystem and receives a reply. + * + * @param subSystemId The identifier of the target subsystem. + * @param customId A custom identifier for the data being sent. + * @param data The Want object containing the data to be sent. + * @param reply A reference to a Want object that will be filled with the reply data. + * @return DataHandlerErr::OK if the data was successfully sent and a reply was received, other errcode otherwise. + */ virtual DataHandlerErr SendDataSync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data, AAFwk::Want& reply) = 0; /** - * @brief Sends data synchronously to a specified subsystem without reply. - * - * @param subSystemId The identifier of the target subsystem. - * @param customId A custom identifier for the data being sent. - * @param data The Want object containing the data to be sent. - * @return DataHandlerErr::OK if the data was successfully sent, other errcode otherwise. - */ + * @brief Sends data synchronously to a specified subsystem without reply. + * + * @param subSystemId The identifier of the target subsystem. + * @param customId A custom identifier for the data being sent. + * @param data The Want object containing the data to be sent. + * @return DataHandlerErr::OK if the data was successfully sent, other errcode otherwise. + */ virtual DataHandlerErr SendDataSync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data) = 0; /** - * @brief Sends data asynchronously to a specified subsystem without reply. - * - * @param subSystemId The identifier of the target subsystem. - * @param customId A custom identifier for the data being sent. - * @param data The Want object containing the data to be sent. - * @return DataHandlerErr::OK if the data was successfully sent, other errcode otherwise. - */ + * @brief Sends data asynchronously to a specified subsystem without reply. + * + * @param subSystemId The identifier of the target subsystem. + * @param customId A custom identifier for the data being sent. + * @param data The Want object containing the data to be sent. + * @return DataHandlerErr::OK if the data was successfully sent, other errcode otherwise. + */ virtual DataHandlerErr SendDataAsync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data) = 0; /** - * @brief Registers a data consumer for a specific subsystemId. - * - * @param SubSystemId The identifier of the data to be consumed. - * @param callback A DataConsumerInfo object containing the callback function and options. - * @return DataHandlerErr::OK if the data consumer was successfully registered, other errcode otherwise. - */ + * @brief Registers a data consumer for a specific subsystemId. + * + * @param SubSystemId The identifier of the data to be consumed. + * @param callback A DataConsumerInfo object containing the callback function and options. + * @return DataHandlerErr::OK if the data consumer was successfully registered, other errcode otherwise. + */ virtual DataHandlerErr RegisterDataConsumer(SubSystemId subSystemId, DataConsumeCallback&& callback) = 0; /** - * @brief Unregisters a data consumer for a specific subSystemId. - * - * @param SubSystemId The identifier of the data to be consumed. - */ + * @brief Unregisters a data consumer for a specific subSystemId. + * + * @param SubSystemId The identifier of the data to be consumed. + */ virtual void UnregisterDataConsumer(SubSystemId subSystemId) = 0; }; } // namespace OHOS::Rosen + +#endif // OHOS_ROSEN_DATA_HANDLER_H \ No newline at end of file diff --git a/window_scene/common/include/extension_data_handler.h b/window_scene/common/include/extension_data_handler.h index f95a064ebb..758aed9dd6 100644 --- a/window_scene/common/include/extension_data_handler.h +++ b/window_scene/common/include/extension_data_handler.h @@ -13,27 +13,26 @@ * limitations under the License. */ -#pragma once +#ifndef OHOS_ROSEN_EXTENSION_DATA_HANDLER_H +#define OHOS_ROSEN_EXTENSION_DATA_HANDLER_H #include "data_handler_interface.h" -#include #include -#include +#include +#include -#include #include +#include #include "message_parcel.h" namespace OHOS::Rosen::Extension { -class TransferConfig : public Parcelable { -public: +struct DataTransferConfig : public Parcelable { bool Marshalling(Parcel& parcel) const override; - static TransferConfig* Unmarshalling(Parcel& parcel); + static DataTransferConfig* Unmarshalling(Parcel& parcel); std::string ToString() const; -public: bool needSyncSend_ { false }; bool needReply_ { false }; SubSystemId subSystemId_ { SubSystemId::INVALID }; @@ -54,18 +53,20 @@ public: DataHandlerErr RegisterDataConsumer(SubSystemId dataId, DataConsumeCallback&& callback) override; void UnregisterDataConsumer(SubSystemId dataId) override; DataHandlerErr NotifyDataConsumer(AAFwk::Want&& data, std::optional reply, - const TransferConfig& config); + const DataTransferConfig& config); protected: - virtual DataHandlerErr SendData(AAFwk::Want& data, AAFwk::Want& reply, const TransferConfig& config) = 0; - DataHandlerErr PrepareData(MessageParcel& data, AAFwk::Want& toSend, const TransferConfig& config); - DataHandlerErr ParseReply(MessageParcel& data, AAFwk::Want& reply, const TransferConfig& config); + virtual DataHandlerErr SendData(AAFwk::Want& data, AAFwk::Want& reply, const DataTransferConfig& config) = 0; + DataHandlerErr PrepareData(MessageParcel& data, AAFwk::Want& toSend, const DataTransferConfig& config); + DataHandlerErr ParseReply(MessageParcel& data, AAFwk::Want& reply, const DataTransferConfig& config); void PostAsyncTask(Task&& task, const std::string& name, int64_t delayTime); protected: - mutable std::shared_mutex mutex_; + mutable std::mutex mutex_; std::unordered_map consumers_; std::shared_ptr eventHandler_; }; -} // namespace OHOS::Rosen::Extension \ No newline at end of file +} // namespace OHOS::Rosen::Extension + +#endif // OHOS_ROSEN_EXTENSION_DATA_HANDLER_H \ No newline at end of file -- Gitee From 26ab95fa18bfdbf0429e5f1846204f876ff70aa4 Mon Sep 17 00:00:00 2001 From: rookiiie Date: Thu, 19 Dec 2024 14:20:03 +0000 Subject: [PATCH 3/3] =?UTF-8?q?1.=20=E5=91=BD=E5=90=8D=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=202.=20=E5=A4=B4=E6=96=87=E4=BB=B6=E7=A8=B3?= =?UTF-8?q?=E5=AE=9A=E6=80=A7=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rookiiie --- window_scene/common/include/extension_data_handler.h | 12 ++++++------ .../session/host/include/extension_session.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/window_scene/common/include/extension_data_handler.h b/window_scene/common/include/extension_data_handler.h index 758aed9dd6..c8c9ed8d3a 100644 --- a/window_scene/common/include/extension_data_handler.h +++ b/window_scene/common/include/extension_data_handler.h @@ -23,8 +23,8 @@ #include #include +#include #include -#include "message_parcel.h" namespace OHOS::Rosen::Extension { @@ -33,17 +33,17 @@ struct DataTransferConfig : public Parcelable { static DataTransferConfig* Unmarshalling(Parcel& parcel); std::string ToString() const; - bool needSyncSend_ { false }; - bool needReply_ { false }; - SubSystemId subSystemId_ { SubSystemId::INVALID }; - uint32_t customId_ { 0 }; + bool needSyncSend { false }; + bool needReply { false }; + SubSystemId subSystemId { SubSystemId::INVALID }; + uint32_t customId { 0 }; }; using Task = std::function; class DataHandler : public IDataHandler { public: - DataHandler(std::shared_ptr& eventHandler) : eventHandler_(eventHandler) {}; + explicit DataHandler(const std::shared_ptr& eventHandler) : eventHandler_(eventHandler) {} virtual ~DataHandler() = default; DataHandlerErr SendDataSync(SubSystemId subSystemId, uint32_t customId, AAFwk::Want& data, diff --git a/window_scene/session/host/include/extension_session.h b/window_scene/session/host/include/extension_session.h index a1f6c883d5..91d2ac0315 100644 --- a/window_scene/session/host/include/extension_session.h +++ b/window_scene/session/host/include/extension_session.h @@ -20,8 +20,8 @@ #include "key_event.h" #include "want.h" -#include "session/host/include/session.h" #include "extension_data_handler.h" +#include "session/host/include/session.h" namespace OHOS::Rosen { class WindowEventChannelListener : public IRemoteStub { -- Gitee