1 /* 2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UEC_SESSION_WRAPPER_IMPL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UEC_SESSION_WRAPPER_IMPL_H 18 19 #include <refbase.h> 20 21 #include "session/host/include/extension_session.h" 22 #include "want.h" 23 24 #include "base/geometry/ng/rect_t.h" 25 #include "base/memory/referenced.h" 26 #include "core/components_ng/pattern/ui_extension/session_wrapper.h" 27 #include "core/components_ng/pattern/ui_extension/ui_extension_component/ui_extension_pattern.h" 28 #include "core/components_ng/pattern/window_scene/scene/system_window_scene.h" 29 30 namespace OHOS::Ace::NG { 31 class SessionWrapperImpl : public SessionWrapper { 32 DECLARE_ACE_TYPE(SessionWrapperImpl, SessionWrapper); 33 34 public: 35 SessionWrapperImpl(const WeakPtr<UIExtensionPattern>& hostPattern, int32_t instanceId, bool isTransferringCaller, 36 SessionType sessionType); 37 ~SessionWrapperImpl() override; 38 39 // About session 40 void CreateSession(const AAFwk::Want& want, const SessionConfig& config) override; 41 void DestroySession() override; 42 bool IsSessionValid() override; 43 int32_t GetSessionId() const override; 44 const std::shared_ptr<AAFwk::Want> GetWant() override; 45 void UpdateInstanceId(int32_t instanceId); 46 47 // Synchronous interface for event notify 48 bool NotifyFocusEventSync(bool isFocus) override; 49 bool NotifyFocusStateSync(bool focusState) override; 50 bool NotifyBackPressedSync() override; 51 bool NotifyPointerEventSync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override; 52 bool NotifyKeyEventSync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) override; 53 bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) override; 54 bool NotifyAxisEventSync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override; 55 56 // Asynchronous interface for event notify 57 bool NotifyFocusEventAsync(bool isFocus) override; 58 bool NotifyFocusStateAsync(bool focusState) override; 59 bool NotifyBackPressedAsync() override; 60 bool NotifyPointerEventAsync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override; 61 bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override; 62 bool NotifyAxisEventAsync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override; 63 64 // The lifecycle interface 65 void NotifyCreate() override; 66 void NotifyForeground() override; 67 void NotifyBackground(bool isHandleError) override; 68 void NotifyDestroy(bool isHandleError = true) override; 69 void NotifyConfigurationUpdate() override; 70 71 // The interface for responsing provider 72 void OnConnect() override; 73 void OnDisconnect(bool isAbnormal) override; 74 void OnReleaseDone() override; 75 void OnExtensionTimeout(int32_t errorCode) override; 76 void OnExtensionDetachToDisplay() override; 77 void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t offset) override; 78 79 // The interface about the accessibility 80 void TransferAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType, int32_t eventType, 81 int64_t timeMs) override; 82 void TransferAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId) override; 83 void TransferAccessibilityChildTreeDeregister() override; 84 void TransferAccessibilityDumpChildInfo( 85 const std::vector<std::string>& params, std::vector<std::string>& info) override; 86 87 // The interface to control the display area and the avoid area 88 std::shared_ptr<Rosen::RSSurfaceNode> GetSurfaceNode() const override; 89 void NotifyDisplayArea(const RectF& displayArea) override; 90 void NotifySizeChangeReason( 91 WindowSizeChangeReason type, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) override; 92 void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const override; 93 bool NotifyOccupiedAreaChangeInfo( 94 sptr<Rosen::OccupiedAreaChangeInfo> info, bool needWaitLayout) override; 95 96 // The interface to send the data for ArkTS 97 void SendDataAsync(const AAFwk::WantParams& params) const override; 98 int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const override; 99 100 // The interface to update viewport config 101 void UpdateSessionViewportConfig() override; 102 103 // The interface for UEC dump 104 uint32_t GetReasonDump() const override; 105 void NotifyUieDump(const std::vector<std::string>& params, std::vector<std::string>& info) override; 106 int32_t GetInstanceId() const; 107 bool SendBusinessDataSyncReply(UIContentBusinessCode code, const AAFwk::Want& data, AAFwk::Want& reply, 108 RSSubsystemId subSystemId = RSSubsystemId::ARKUI_UIEXT) override; 109 bool SendBusinessData(UIContentBusinessCode code, const AAFwk::Want& data, BusinessDataSendType type, 110 RSSubsystemId subSystemId = RSSubsystemId::ARKUI_UIEXT) override; 111 112 void NotifyHostWindowMode(int32_t mode) override; 113 void ReDispatchWantParams() override; 114 115 private: 116 int32_t GetFrameNodeId() const; 117 void InitAllCallback(); 118 void InitForegroundCallback(); 119 void InitBackgroundCallback(); 120 void InitDestructionCallback(); 121 void InitTransferAbilityResultFunc(); 122 void InitTransferExtensionDataFunc(); 123 void InitNotifyRemoteReadyFunc(); 124 void InitNotifySyncOnFunc(); 125 void InitNotifyAsyncOnFunc(); 126 void InitNotifyBindModalFunc(); 127 void InitNotifyGetAvoidAreaByTypeFunc(); 128 void InitNotifyExtensionEventFunc(); 129 void InitGetStatusBarHeightFunc(); 130 void UpdateSessionConfig(); 131 RefPtr<SystemWindowScene> GetWindowScene(); 132 int32_t GetWindowSceneId(); 133 Rosen::WSRect GetWindowSceneRect(); 134 RectF GetDisplayAreaWithWindowScene(); 135 bool InnerNotifyOccupiedAreaChangeInfo( 136 sptr<Rosen::OccupiedAreaChangeInfo> info, bool isWaitTask, int64_t occupiedAreaTime); 137 bool RegisterDataConsumer(); 138 void PostBusinessDataConsumeAsync(uint32_t customId, const AAFwk::Want& data); 139 void PostBusinessDataConsumeSyncReply( 140 uint32_t customId, const AAFwk::Want& data, std::optional<AAFwk::Want>& reply); 141 void DispatchExtensionDataToHostWindow(uint32_t customId, const AAFwk::Want& data); 142 void UpdateWantPtr(std::shared_ptr<AAFwk::Want>& wantPtr); 143 144 WeakPtr<UIExtensionPattern> hostPattern_; 145 RefPtr<TaskExecutor> taskExecutor_; 146 int32_t instanceId_; 147 bool isTransferringCaller_; 148 bool isNotifyOccupiedAreaChange_ = true; 149 SessionType sessionType_ = SessionType::UI_EXTENSION_ABILITY; 150 int32_t uiExtensionId_ = 0; 151 int64_t lastOccupiedAreaTime_ = 0; 152 sptr<Rosen::ExtensionSession> session_; 153 Rect displayAreaWindow_; 154 RectF displayArea_; 155 uint32_t reason_ = (uint32_t)Rosen::SizeChangeReason::UNDEFINED; 156 std::shared_ptr<Rosen::ILifecycleListener> lifecycleListener_; 157 std::function<void((OHOS::Rosen::WSError))> foregroundCallback_; 158 std::function<void((OHOS::Rosen::WSError))> backgroundCallback_; 159 std::function<void((OHOS::Rosen::WSError))> destructionCallback_; 160 std::weak_ptr<Rosen::RSTransaction> transaction_; 161 std::shared_ptr<AAFwk::Want> customWant_; 162 OHOS::Rosen::SubSystemId subSystemId_ = OHOS::Rosen::SubSystemId::ARKUI_UIEXT; 163 }; 164 } // namespace OHOS::Ace::NG 165 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UEC_SESSION_WRAPPER_IMPL_H 166