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 INVALID_TYPE = 100, 67 }; 68 69 enum class UIExtensionUsage : uint32_t { 70 MODAL = 0, 71 EMBEDDED = 1, 72 CONSTRAINED_EMBEDDED = 2, 73 }; 74 75 struct SessionConfig { 76 bool isAsyncModalBinding = false; 77 UIExtensionUsage uiExtensionUsage = UIExtensionUsage::MODAL; 78 }; 79 80 class SessionWrapper : public AceType { 81 DECLARE_ACE_TYPE(SessionWrapper, AceType); 82 83 public: 84 virtual ~SessionWrapper() = default; 85 86 // About session 87 virtual void CreateSession( 88 const AAFwk::Want& want, const SessionConfig& config) = 0; 89 virtual void DestroySession() = 0; 90 virtual bool IsSessionValid() = 0; 91 virtual int32_t GetSessionId() const = 0; 92 virtual const std::shared_ptr<AAFwk::Want> GetWant() = 0; 93 94 // Synchronous interface for event notify 95 virtual bool NotifyFocusEventSync(bool isFocus) = 0; 96 virtual bool NotifyFocusStateSync(bool focusState) = 0; 97 virtual bool NotifyBackPressedSync() = 0; 98 virtual bool NotifyPointerEventSync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) = 0; 99 virtual bool NotifyKeyEventSync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) = 0; 100 virtual bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) = 0; 101 virtual bool NotifyAxisEventSync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) = 0; 102 103 // Asynchronous interface for event notify 104 virtual bool NotifyFocusEventAsync(bool isFocus) = 0; 105 virtual bool NotifyFocusStateAsync(bool focusState) = 0; 106 virtual bool NotifyBackPressedAsync() = 0; 107 virtual bool NotifyPointerEventAsync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) = 0; 108 virtual bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) = 0; 109 virtual bool NotifyAxisEventAsync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) = 0; 110 111 // The lifecycle interface 112 virtual void NotifyCreate() = 0; 113 virtual void NotifyForeground() = 0; 114 virtual void NotifyBackground(bool isHandleError = true) = 0; 115 virtual void NotifyDestroy(bool isHandleError = true) = 0; 116 virtual void NotifyConfigurationUpdate() = 0; 117 118 // The interface for responsing provider 119 virtual void OnConnect() = 0; 120 virtual void OnDisconnect(bool isAbnormal) = 0; OnReleaseDone()121 virtual void OnReleaseDone() {} 122 virtual void OnExtensionTimeout(int32_t errorCode) = 0; OnExtensionDetachToDisplay()123 virtual void OnExtensionDetachToDisplay() {}; 124 virtual void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t offset) = 0; 125 126 // The interface about the accessibility 127 virtual void TransferAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType, int32_t eventType, 128 int64_t timeMs) = 0; 129 virtual void TransferAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId) = 0; 130 virtual void TransferAccessibilityChildTreeDeregister() = 0; 131 virtual void TransferAccessibilityDumpChildInfo( 132 const std::vector<std::string>& params, std::vector<std::string>& info) = 0; 133 134 // The interface to control the display area and the avoid area 135 virtual std::shared_ptr<Rosen::RSSurfaceNode> GetSurfaceNode() const = 0; 136 virtual void NotifyDisplayArea(const RectF& displayArea) = 0; 137 virtual void NotifySizeChangeReason( 138 WindowSizeChangeReason type, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) = 0; 139 virtual void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const = 0; 140 virtual bool NotifyOccupiedAreaChangeInfo( 141 sptr<Rosen::OccupiedAreaChangeInfo> info, bool needWaitLayout = false) = 0; SetDensityDpiImpl(bool densityDpi)142 virtual void SetDensityDpiImpl(bool densityDpi) {} 143 144 // The interface to send the data for ArkTS 145 virtual void SendDataAsync(const AAFwk::WantParams& params) const = 0; 146 virtual int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const = 0; 147 148 // The interface to update viewport config UpdateSessionViewportConfig()149 virtual void UpdateSessionViewportConfig() {} 150 151 // The interface for UEC dump 152 virtual uint32_t GetReasonDump() const = 0; 153 virtual void NotifyUieDump(const std::vector<std::string>& params, std::vector<std::string>& info) = 0; 154 virtual bool SendBusinessDataSyncReply(UIContentBusinessCode code, const AAFwk::Want& data, AAFwk::Want& reply, 155 RSSubsystemId subSystemId = RSSubsystemId::ARKUI_UIEXT) = 0; 156 virtual bool SendBusinessData(UIContentBusinessCode code, const AAFwk::Want& data, BusinessDataSendType type, 157 RSSubsystemId subSystemId = RSSubsystemId::ARKUI_UIEXT) = 0; 158 NotifyHostWindowMode(int32_t mode)159 virtual void NotifyHostWindowMode(int32_t mode) {} 160 }; 161 } // namespace OHOS::Ace::NG 162 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_H 163