diff --git a/interfaces/innerkits/wm/data_handler_interface.h b/interfaces/innerkits/wm/data_handler_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..52c30ef4df815e7f56aa9a9e706f80c00d04b22c --- /dev/null +++ b/interfaces/innerkits/wm/data_handler_interface.h @@ -0,0 +1,115 @@ +/* + * 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. + */ + +#ifndef OHOS_ROSEN_DATA_HANDLER_H +#define OHOS_ROSEN_DATA_HANDLER_H + +#include +#include +#include + +namespace OHOS::AAFwk { +class Want; +} // namespace OHOS::AAFwk + +namespace OHOS::Rosen { + +enum class SubSystemId : uint8_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 + +#endif // OHOS_ROSEN_DATA_HANDLER_H \ No newline at end of file diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 8df4083a7156ef020ddbac6b0f91e26e141b7744..ffbd774d06047e0a85bc61c7d3bdae2598549a14 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 0000000000000000000000000000000000000000..c8c9ed8d3a0c5ade5a8ba145c2306da5b5e53ef6 --- /dev/null +++ b/window_scene/common/include/extension_data_handler.h @@ -0,0 +1,72 @@ +/* + * 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. + */ + +#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 + +namespace OHOS::Rosen::Extension { + +struct DataTransferConfig : public Parcelable { + bool Marshalling(Parcel& parcel) const override; + static DataTransferConfig* Unmarshalling(Parcel& parcel); + std::string ToString() const; + + bool needSyncSend { false }; + bool needReply { false }; + SubSystemId subSystemId { SubSystemId::INVALID }; + uint32_t customId { 0 }; +}; + +using Task = std::function; + +class DataHandler : public IDataHandler { +public: + explicit DataHandler(const 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 DataTransferConfig& config); + +protected: + 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::mutex mutex_; + std::unordered_map consumers_; + std::shared_ptr eventHandler_; +}; + +} // namespace OHOS::Rosen::Extension + +#endif // OHOS_ROSEN_EXTENSION_DATA_HANDLER_H \ 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 7b651df00f71cbabf6d93fb796fc1f3f746aee15..a8ae377e188eee28eac366de37d658bed0ff78b8 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 e46d5f46afb9ca9bfac7fb5909fb2a6a677036c5..91d2ac031505d212a1b2fdb702b83ad60e9bbb02 100644 --- a/window_scene/session/host/include/extension_session.h +++ b/window_scene/session/host/include/extension_session.h @@ -20,6 +20,7 @@ #include "key_event.h" #include "want.h" +#include "extension_data_handler.h" #include "session/host/include/session.h" namespace OHOS::Rosen { @@ -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 28b22df4a16c963aa9952cdcd83b4f27b8a123ce..65a61b1782ca9f7afb76ffced3b72f9a1fbc90dc 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,