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 
28 namespace OHOS {
29 template<typename T>
30 class sptr;
31 
32 namespace MMI {
33 class PointerEvent;
34 class KeyEvent;
35 class AxisEvent;
36 } // namespace MMI
37 
38 namespace Rosen {
39 class OccupiedAreaChangeInfo;
40 class RSSurfaceNode;
41 class RSTransaction;
42 class AvoidArea;
43 } // namespace Rosen
44 
45 namespace AAFwk {
46 class Want;
47 class WantParams;
48 } // namespace AAFwk
49 
50 namespace Accessibility {
51 class AccessibilityElementInfo;
52 class AccessibilityEventInfo;
53 } // namespace Accessibility
54 
55 } // namespace OHOS
56 
57 namespace OHOS::Ace::NG {
58 enum class SessionType : int32_t {
59     EMBEDDED_UI_EXTENSION = 0,
60     UI_EXTENSION_ABILITY = 1,
61     CLOUD_CARD = 2,
62     SECURITY_UI_EXTENSION_ABILITY = 3,
63 };
64 
65 enum class UIExtensionUsage : uint32_t {
66     MODAL = 0,
67     EMBEDDED = 1,
68     CONSTRAINED_EMBEDDED = 2,
69 };
70 
71 struct SessionConfig {
72     bool isAsyncModalBinding = false;
73     UIExtensionUsage uiExtensionUsage = UIExtensionUsage::MODAL;
74 };
75 
76 class SessionWrapper : public AceType {
77     DECLARE_ACE_TYPE(SessionWrapper, AceType);
78 
79 public:
80     virtual ~SessionWrapper() = default;
81 
82     // About session
83     virtual void CreateSession(
84         const AAFwk::Want& want, const SessionConfig& config) = 0;
85     virtual void DestroySession() = 0;
86     virtual bool IsSessionValid() = 0;
87     virtual int32_t GetSessionId() const = 0;
88     virtual const std::shared_ptr<AAFwk::Want> GetWant() = 0;
89 
90     // Synchronous interface for event notify
91     virtual bool NotifyFocusEventSync(bool isFocus) = 0;
92     virtual bool NotifyFocusStateSync(bool focusState) = 0;
93     virtual bool NotifyBackPressedSync() = 0;
94     virtual bool NotifyPointerEventSync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) = 0;
95     virtual bool NotifyKeyEventSync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) = 0;
96     virtual bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) = 0;
97     virtual bool NotifyAxisEventSync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) = 0;
98 
99     // Asynchronous interface for event notify
100     virtual bool NotifyFocusEventAsync(bool isFocus) = 0;
101     virtual bool NotifyFocusStateAsync(bool focusState) = 0;
102     virtual bool NotifyBackPressedAsync() = 0;
103     virtual bool NotifyPointerEventAsync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) = 0;
104     virtual bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) = 0;
105     virtual bool NotifyAxisEventAsync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) = 0;
106 
107     // The lifecycle interface
108     virtual void NotifyCreate() = 0;
109     virtual void NotifyForeground() = 0;
110     virtual void NotifyBackground(bool isHandleError = true) = 0;
111     virtual void NotifyDestroy(bool isHandleError = true) = 0;
112     virtual void NotifyConfigurationUpdate() = 0;
113 
114     // The interface for responsing provider
115     virtual void OnConnect() = 0;
116     virtual void OnDisconnect(bool isAbnormal) = 0;
OnReleaseDone()117     virtual void OnReleaseDone() {}
118     virtual void OnExtensionTimeout(int32_t errorCode) = 0;
OnExtensionDetachToDisplay()119     virtual void OnExtensionDetachToDisplay() {};
120     virtual void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t offset) = 0;
121 
122     // The interface about the accessibility
123     virtual void TransferAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType, int32_t eventType,
124         int64_t timeMs) = 0;
125     virtual void TransferAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId) = 0;
126     virtual void TransferAccessibilityChildTreeDeregister() = 0;
127     virtual void TransferAccessibilityDumpChildInfo(
128         const std::vector<std::string>& params, std::vector<std::string>& info) = 0;
129 
130     // The interface to control the display area and the avoid area
131     virtual std::shared_ptr<Rosen::RSSurfaceNode> GetSurfaceNode() const = 0;
132     virtual void NotifyDisplayArea(const RectF& displayArea) = 0;
133     virtual void NotifySizeChangeReason(
134         WindowSizeChangeReason type, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) = 0;
135     virtual void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const = 0;
136     virtual bool NotifyOccupiedAreaChangeInfo(
137         sptr<Rosen::OccupiedAreaChangeInfo> info, bool needWaitLayout = false) = 0;
138     virtual void SetDensityDpiImpl(bool densityDpi) = 0;
139 
140     // The interface to send the data for ArkTS
141     virtual void SendDataAsync(const AAFwk::WantParams& params) const = 0;
142     virtual int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const = 0;
143     // The interface for UEC dump
144     virtual uint32_t GetReasonDump() const = 0;
145     virtual void NotifyUieDump(const std::vector<std::string>& params, std::vector<std::string>& info) = 0;
146 };
147 } // namespace OHOS::Ace::NG
148 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_H
149