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 GetInstanceIdFromHost() 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 114 private: 115 int32_t GetFrameNodeId() const; 116 void InitAllCallback(); 117 void InitForegroundCallback(); 118 void InitBackgroundCallback(); 119 void InitDestructionCallback(); 120 void InitTransferAbilityResultFunc(); 121 void InitTransferExtensionDataFunc(); 122 void InitNotifyRemoteReadyFunc(); 123 void InitNotifySyncOnFunc(); 124 void InitNotifyAsyncOnFunc(); 125 void InitNotifyBindModalFunc(); 126 void InitNotifyGetAvoidAreaByTypeFunc(); 127 void InitNotifyExtensionEventFunc(); 128 void InitGetStatusBarHeightFunc(); 129 void UpdateSessionConfig(); 130 RefPtr<SystemWindowScene> GetWindowScene(); 131 int32_t GetWindowSceneId(); 132 Rosen::WSRect GetWindowSceneRect(); 133 bool InnerNotifyOccupiedAreaChangeInfo( 134 sptr<Rosen::OccupiedAreaChangeInfo> info, bool isWaitTask, int64_t occupiedAreaTime); 135 bool RegisterDataConsumer(); 136 void PostBusinessDataConsumeAsync(uint32_t customId, AAFwk::Want&& data); 137 void PostBusinessDataConsumeSyncReply(uint32_t customId, AAFwk::Want&& data, std::optional<AAFwk::Want>& reply); 138 void UpdateWantPtr(std::shared_ptr<AAFwk::Want>& wantPtr); 139 140 WeakPtr<UIExtensionPattern> hostPattern_; 141 RefPtr<TaskExecutor> taskExecutor_; 142 int32_t instanceId_; 143 bool isTransferringCaller_; 144 bool isNotifyOccupiedAreaChange_ = true; 145 SessionType sessionType_ = SessionType::UI_EXTENSION_ABILITY; 146 int32_t uiExtensionId_ = 0; 147 int64_t lastOccupiedAreaTime_ = 0; 148 sptr<Rosen::ExtensionSession> session_; 149 Rect displayAreaWindow_; 150 RectF displayArea_; 151 uint32_t reason_ = (uint32_t)Rosen::SizeChangeReason::UNDEFINED; 152 std::shared_ptr<Rosen::ILifecycleListener> lifecycleListener_; 153 std::function<void((OHOS::Rosen::WSError))> foregroundCallback_; 154 std::function<void((OHOS::Rosen::WSError))> backgroundCallback_; 155 std::function<void((OHOS::Rosen::WSError))> destructionCallback_; 156 std::weak_ptr<Rosen::RSTransaction> transaction_; 157 std::shared_ptr<AAFwk::Want> customWant_; 158 OHOS::Rosen::SubSystemId subSystemId_ = OHOS::Rosen::SubSystemId::ARKUI_UIEXT; 159 }; 160 } // namespace OHOS::Ace::NG 161 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UEC_SESSION_WRAPPER_IMPL_H 162