1 /* 2 * Copyright (c) 2023 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_SESSION_WRAPPER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_H 18 19 #include <cstdint> 20 #include <list> 21 #include <map> 22 #include <memory> 23 24 #include "base/geometry/ng/rect_t.h" 25 #include "base/memory/ace_type.h" 26 #include "core/common/window_animation_config.h" 27 #include "core/components_ng/pattern/ui_extension/ui_extension_config.h" 28 29 namespace OHOS { 30 template<typename T> 31 class sptr; 32 33 namespace MMI { 34 class PointerEvent; 35 class KeyEvent; 36 class AxisEvent; 37 } // namespace MMI 38 39 namespace Rosen { 40 class OccupiedAreaChangeInfo; 41 class RSSurfaceNode; 42 class RSTransaction; 43 class AvoidArea; 44 } // namespace Rosen 45 46 namespace AAFwk { 47 class Want; 48 class WantParams; 49 } // namespace AAFwk 50 51 namespace Accessibility { 52 class AccessibilityElementInfo; 53 class AccessibilityEventInfo; 54 } // namespace Accessibility 55 56 } // namespace OHOS 57 58 namespace OHOS::Ace::NG { 59 enum class SessionType : int32_t { 60 EMBEDDED_UI_EXTENSION = 0, 61 UI_EXTENSION_ABILITY = 1, 62 CLOUD_CARD = 2, 63 SECURITY_UI_EXTENSION_ABILITY = 3, 64 DYNAMIC_COMPONENT = 4, 65 ISOLATED_COMPONENT = 5, 66 PREVIEW_UI_EXTENSION_ABILITY = 6, 67 INVALID_TYPE = 100, 68 }; 69 70 enum class UIExtensionUsage : uint32_t { 71 MODAL = 0, 72 EMBEDDED = 1, 73 CONSTRAINED_EMBEDDED = 2, 74 PREVIEW_EMBEDDED = 3, 75 }; 76 77 struct SessionConfig { 78 bool isAsyncModalBinding = false; 79 UIExtensionUsage uiExtensionUsage = UIExtensionUsage::MODAL; 80 }; 81 82 class SessionWrapper : public AceType { 83 DECLARE_ACE_TYPE(SessionWrapper, AceType); 84 85 public: 86 virtual ~SessionWrapper() = default; 87 88 // About session 89 virtual void CreateSession( 90 const AAFwk::Want& want, const SessionConfig& config) = 0; 91 virtual void DestroySession() = 0; 92 virtual bool IsSessionValid() = 0; 93 virtual int32_t GetSessionId() const = 0; 94 virtual const std::shared_ptr<AAFwk::Want> GetWant() = 0; 95 96 // Synchronous interface for event notify 97 virtual bool NotifyFocusEventSync(bool isFocus) = 0; 98 virtual bool NotifyFocusStateSync(bool focusState) = 0; 99 virtual bool NotifyBackPressedSync() = 0; 100 virtual bool NotifyPointerEventSync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) = 0; 101 virtual bool NotifyKeyEventSync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) = 0; 102 virtual bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) = 0; 103 virtual bool NotifyAxisEventSync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) = 0; 104 105 // Asynchronous interface for event notify 106 virtual bool NotifyFocusEventAsync(bool isFocus) = 0; 107 virtual bool NotifyFocusStateAsync(bool focusState) = 0; 108 virtual bool NotifyBackPressedAsync() = 0; 109 virtual bool NotifyPointerEventAsync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) = 0; 110 virtual bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) = 0; 111 virtual bool NotifyAxisEventAsync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) = 0; 112 113 // The lifecycle interface 114 virtual void NotifyCreate() = 0; 115 virtual void NotifyForeground() = 0; 116 virtual void NotifyBackground(bool isHandleError = true) = 0; 117 virtual void NotifyDestroy(bool isHandleError = true) = 0; 118 virtual void NotifyConfigurationUpdate() = 0; 119 120 // The interface for responsing provider 121 virtual void OnConnect() = 0; 122 virtual void OnDisconnect(bool isAbnormal) = 0; OnReleaseDone()123 virtual void OnReleaseDone() {} 124 virtual void OnExtensionTimeout(int32_t errorCode) = 0; OnExtensionDetachToDisplay()125 virtual void OnExtensionDetachToDisplay() {}; 126 virtual void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t offset) = 0; 127 128 // The interface about the accessibility 129 virtual void TransferAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType, int32_t eventType, 130 int64_t timeMs) = 0; 131 virtual void TransferAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId) = 0; 132 virtual void TransferAccessibilityChildTreeDeregister() = 0; 133 virtual void TransferAccessibilityDumpChildInfo( 134 const std::vector<std::string>& params, std::vector<std::string>& info) = 0; 135 136 // The interface to control the display area and the avoid area 137 virtual std::shared_ptr<Rosen::RSSurfaceNode> GetSurfaceNode() const = 0; 138 virtual void NotifyDisplayArea(const RectF& displayArea) = 0; 139 virtual void NotifySizeChangeReason( 140 WindowSizeChangeReason type, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) = 0; 141 virtual void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const = 0; 142 virtual bool NotifyOccupiedAreaChangeInfo( 143 sptr<Rosen::OccupiedAreaChangeInfo> info, bool needWaitLayout = false) = 0; SetDensityDpiImpl(bool densityDpi)144 virtual void SetDensityDpiImpl(bool densityDpi) {} 145 146 // The interface to send the data for ArkTS 147 virtual void SendDataAsync(const AAFwk::WantParams& params) const = 0; 148 virtual int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const = 0; 149 150 // The interface to update viewport config UpdateSessionViewportConfig()151 virtual void UpdateSessionViewportConfig() {} 152 153 // The interface for UEC dump 154 virtual uint32_t GetReasonDump() const = 0; 155 virtual void NotifyUieDump(const std::vector<std::string>& params, std::vector<std::string>& info) = 0; 156 virtual bool SendBusinessDataSyncReply(UIContentBusinessCode code, const AAFwk::Want& data, AAFwk::Want& reply, 157 RSSubsystemId subSystemId = RSSubsystemId::ARKUI_UIEXT) = 0; 158 virtual bool SendBusinessData(UIContentBusinessCode code, const AAFwk::Want& data, BusinessDataSendType type, 159 RSSubsystemId subSystemId = RSSubsystemId::ARKUI_UIEXT) = 0; 160 NotifyHostWindowMode(int32_t mode)161 virtual void NotifyHostWindowMode(int32_t mode) {} ReDispatchWantParams()162 virtual void ReDispatchWantParams() {} 163 }; 164 } // namespace OHOS::Ace::NG 165 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_H 166