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