• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_H
17 #define OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_H
18 #include <future>
19 
20 #include "key_event.h"
21 #include "want.h"
22 
23 #include "extension_data_handler.h"
24 #include "session/host/include/session.h"
25 
26 namespace OHOS::Rosen {
27     bool IsExtensionSessionInvalid(int32_t persistentId);
28 
29 class WindowEventChannelListener : public IRemoteStub<IWindowEventChannelListener> {
30 public:
31     explicit WindowEventChannelListener() = default;
32     void SetTransferKeyEventForConsumedParams(int32_t keyEventId, bool isPreImeEvent,
33         const std::shared_ptr<std::promise<bool>>& isConsumedPromise, const std::shared_ptr<WSError>& retCode);
34     void ResetTransferKeyEventForConsumedParams();
35     void ResetTransferKeyEventForConsumedParams(bool isConsumed, WSError retCode);
36     void OnTransferKeyEventForConsumed(int32_t keyEventId, bool isPreImeEvent,
37                                        bool isConsumed, WSError retCode) override;
38     int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
39 
40 private:
41     std::mutex transferKeyEventForConsumedMutex_;
42     int32_t keyEventId_ = 0;
43     bool isPreImeEvent_ = false;
44     std::shared_ptr<std::promise<bool>> isConsumedPromise_ = nullptr;
45     std::shared_ptr<WSError> retCode_ = nullptr;
46 };
47 
48 class ChannelDeathRecipient : public IRemoteObject::DeathRecipient {
49 public:
ChannelDeathRecipient(const sptr<WindowEventChannelListener> & listener)50     explicit ChannelDeathRecipient(const sptr<WindowEventChannelListener>& listener): listener_(listener) {}
51     virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
52 
53 private:
54     sptr<WindowEventChannelListener> listener_ = nullptr;
55 };
56 
57 using NotifyTransferAbilityResultFunc = std::function<void(uint32_t resultCode, const AAFwk::Want& want)>;
58 using NotifyTransferExtensionDataFunc = std::function<void(const AAFwk::WantParams& wantParams)>;
59 using NotifyRemoteReadyFunc = std::function<void()>;
60 using NotifySyncOnFunc = std::function<void()>;
61 using NotifyAsyncOnFunc = std::function<void()>;
62 using NotifyGetAvoidAreaByTypeFunc = std::function<AvoidArea(AvoidAreaType type, int32_t apiVersion)>;
63 using NotifyBindModalFunc = std::function<void()>;
64 using NotifyExtensionEventFunc = std::function<void(uint32_t notifyEvent)>;
65 using GetStatusBarHeightFunc = std::function<int32_t()>;
66 
67 class ExtensionSession : public Session {
68 public:
69     struct ExtensionSessionEventCallback : public RefBase {
70         NotifyTransferAbilityResultFunc transferAbilityResultFunc_;
71         NotifyTransferExtensionDataFunc transferExtensionDataFunc_;
72         NotifyRemoteReadyFunc notifyRemoteReadyFunc_;
73         NotifySyncOnFunc notifySyncOnFunc_;
74         NotifyAsyncOnFunc notifyAsyncOnFunc_;
75         NotifyGetAvoidAreaByTypeFunc notifyGetAvoidAreaByTypeFunc_;
76         NotifyBindModalFunc notifyBindModalFunc_;
77         NotifyExtensionEventFunc notifyExtensionEventFunc_;
78         GetStatusBarHeightFunc getStatusBarHeightFunc_;
79     };
80 
81     explicit ExtensionSession(const SessionInfo& info);
82     virtual ~ExtensionSession();
83 
84     std::shared_ptr<IDataHandler> GetExtensionDataHandler() const;
85     void SetEventHandler(const std::shared_ptr<AppExecFwk::EventHandler>& handler,
86         const std::shared_ptr<AppExecFwk::EventHandler>& exportHandler) override;
87     WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
88         const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig,
89         sptr<WindowSessionProperty> property, sptr<IRemoteObject> token,
90         const std::string& identityToken = "") override;
91     WSError ConnectInner(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
92         const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig,
93         sptr<WindowSessionProperty> property, sptr<IRemoteObject> token, int32_t pid, int32_t uid,
94         const std::string& identityToken = "") override;
95 
96     AvoidArea GetAvoidAreaByType(AvoidAreaType type, const WSRect& rect = WSRect::EMPTY_RECT,
97         int32_t apiVersion = API_VERSION_INVALID) override;
98     int32_t GetStatusBarHeight() override;
99 
100     WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override;
101     WSError TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want) override;
102     WSError TransferExtensionData(const AAFwk::WantParams& wantParams) override;
103     WSError TransferComponentData(const AAFwk::WantParams& wantParams);
104     WSErrorCode TransferComponentDataSync(const AAFwk::WantParams& wantParams,
105                                           AAFwk::WantParams& reWantParams);
106     WSError TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
107         int64_t uiExtensionIdLevel) override;
108     WSError TransferAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType, int32_t eventType,
109         int64_t timeMs);
110     WSError TransferAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId);
111     WSError TransferAccessibilityChildTreeUnregister();
112     WSError TransferAccessibilityDumpChildInfo(const std::vector<std::string>& params, std::vector<std::string>& info);
113     void NotifySyncOn() override;
114     void NotifyAsyncOn() override;
115     WSError NotifyDensityFollowHost(bool isFollowHost, float densityValue = 1.0f);
116     WSError UpdateSessionViewportConfig(const SessionViewportConfig& config);
117     void TriggerBindModalUIExtension() override;
118     void RegisterExtensionSessionEventCallback(const sptr<ExtensionSessionEventCallback>& extSessionEventCallback);
119     WSError TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed,
120         bool& isTimeOut, bool isPreImeEvent = false);
121     WSError TransferKeyEventAsync(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool isPreImeEvent = false);
122     sptr<ExtensionSessionEventCallback> GetExtensionSessionEventCallback();
123     WSError Background(bool isFromClient = false, const std::string& identityToken = "") override;
124     void NotifyExtensionEventAsync(uint32_t notifyEvent) override;
125     WSError NotifyDumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info);
126     WSError SendExtensionData(MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
127 
128 private:
129     sptr<ExtensionSessionEventCallback> extSessionEventCallback_ = nullptr;
130     bool isFirstTriggerBindModal_ = true;
131     sptr<ChannelDeathRecipient> channelDeath_ = nullptr;
132     sptr<WindowEventChannelListener> channelListener_ = nullptr;
133     std::shared_ptr<Extension::DataHandler> dataHandler_;
134 };
135 } // namespace OHOS::Rosen
136 
137 #endif // OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_H
138