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_IMPL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_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_pattern.h" 28 29 namespace OHOS::Ace::NG { 30 class SessionWrapperImpl : public SessionWrapper { 31 DECLARE_ACE_TYPE(SessionWrapperImpl, SessionWrapper); 32 33 public: 34 SessionWrapperImpl(const WeakPtr<UIExtensionPattern>& hostPattern, int32_t instanceId, bool isTransferringCaller, 35 SessionType sessionType); 36 ~SessionWrapperImpl() override; 37 38 // About session 39 void CreateSession(const AAFwk::Want& want, const SessionConfig& config) override; 40 void DestroySession() override; 41 bool IsSessionValid() override; 42 int32_t GetSessionId() const override; 43 const std::shared_ptr<AAFwk::Want> GetWant() override; 44 45 // Synchronous interface for event notify 46 bool NotifyFocusEventSync(bool isFocus) override; 47 bool NotifyFocusStateSync(bool focusState) override; 48 bool NotifyBackPressedSync() override; 49 bool NotifyPointerEventSync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override; 50 bool NotifyKeyEventSync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) override; 51 bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) override; 52 bool NotifyAxisEventSync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override; 53 54 // Asynchronous interface for event notify 55 bool NotifyFocusEventAsync(bool isFocus) override; 56 bool NotifyFocusStateAsync(bool focusState) override; 57 bool NotifyBackPressedAsync() override; 58 bool NotifyPointerEventAsync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override; 59 bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override; 60 bool NotifyAxisEventAsync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override; 61 62 // The lifecycle interface 63 void NotifyCreate() override; 64 void NotifyForeground() override; 65 void NotifyBackground(bool isHandleError) override; 66 void NotifyDestroy(bool isHandleError = true) override; 67 void NotifyConfigurationUpdate() override; 68 69 // The interface for responsing provider 70 void OnConnect() override; 71 void OnDisconnect(bool isAbnormal) override; 72 void OnReleaseDone() override; 73 void OnExtensionTimeout(int32_t errorCode) override; 74 void OnExtensionDetachToDisplay() override; 75 void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t offset) override; 76 77 // The interface about the accessibility 78 void TransferAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType, int32_t eventType, 79 int64_t timeMs) override; 80 void TransferAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId) override; 81 void TransferAccessibilityChildTreeDeregister() override; 82 void TransferAccessibilityDumpChildInfo( 83 const std::vector<std::string>& params, std::vector<std::string>& info) override; 84 85 // The interface to control the display area and the avoid area 86 std::shared_ptr<Rosen::RSSurfaceNode> GetSurfaceNode() const override; 87 void NotifyDisplayArea(const RectF& displayArea) override; 88 void NotifySizeChangeReason( 89 WindowSizeChangeReason type, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) override; 90 void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const override; 91 bool NotifyOccupiedAreaChangeInfo( 92 sptr<Rosen::OccupiedAreaChangeInfo> info, bool needWaitLayout) override; 93 void SetDensityDpiImpl(bool isDensityDpi) override; 94 95 // The interface to send the data for ArkTS 96 void SendDataAsync(const AAFwk::WantParams& params) const override; 97 int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const override; 98 99 // The interface for UEC dump 100 uint32_t GetReasonDump() const override; 101 void NotifyUieDump(const std::vector<std::string>& params, std::vector<std::string>& info) override; 102 103 private: 104 void InitAllCallback(); 105 void UpdateSessionConfig(); 106 int32_t GetWindowSceneId(); 107 bool InnerNotifyOccupiedAreaChangeInfo( 108 sptr<Rosen::OccupiedAreaChangeInfo> info, bool isWaitTask, int64_t occupiedAreaTime); 109 110 WeakPtr<UIExtensionPattern> hostPattern_; 111 RefPtr<TaskExecutor> taskExecutor_; 112 int32_t instanceId_; 113 bool isTransferringCaller_; 114 SessionType sessionType_ = SessionType::UI_EXTENSION_ABILITY; 115 int32_t uiExtensionId_ = 0; 116 int64_t lastOccupiedAreaTime_ = 0; 117 sptr<Rosen::ExtensionSession> session_; 118 bool isNotifyOccupiedAreaChange_ = true; 119 Rect displayAreaWindow_; 120 RectF displayArea_; 121 uint32_t reason_ = (uint32_t)Rosen::SizeChangeReason::UNDEFINED; 122 std::shared_ptr<Rosen::ILifecycleListener> lifecycleListener_; 123 std::function<void((OHOS::Rosen::WSError))> foregroundCallback_; 124 std::function<void((OHOS::Rosen::WSError))> backgroundCallback_; 125 std::function<void((OHOS::Rosen::WSError))> destructionCallback_; 126 std::weak_ptr<Rosen::RSTransaction> transaction_; 127 }; 128 } // namespace OHOS::Ace::NG 129 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_IMPL_H 130