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 using NotifyExtensionEventFunc = std::function<void(uint32_t notifyEvent)>; 61 62 class ExtensionSession : public Session { 63 public: 64 struct ExtensionSessionEventCallback : public RefBase { 65 NotifyTransferAbilityResultFunc transferAbilityResultFunc_; 66 NotifyTransferExtensionDataFunc transferExtensionDataFunc_; 67 NotifyRemoteReadyFunc notifyRemoteReadyFunc_; 68 NotifySyncOnFunc notifySyncOnFunc_; 69 NotifyAsyncOnFunc notifyAsyncOnFunc_; 70 NotifyGetAvoidAreaByTypeFunc notifyGetAvoidAreaByTypeFunc_; 71 NotifyBindModalFunc notifyBindModalFunc_; 72 NotifyExtensionEventFunc notifyExtensionEventFunc_; 73 }; 74 75 explicit ExtensionSession(const SessionInfo& info); 76 virtual ~ExtensionSession(); 77 78 WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel, 79 const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig, 80 sptr<WindowSessionProperty> property, sptr<IRemoteObject> token, 81 const std::string& identityToken = "") override; 82 WSError ConnectInner(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel, 83 const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig, 84 sptr<WindowSessionProperty> property, sptr<IRemoteObject> token, int32_t pid, int32_t uid, 85 const std::string& identityToken = "") override; 86 87 AvoidArea GetAvoidAreaByType(AvoidAreaType type) override; 88 89 WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override; 90 WSError TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want) override; 91 WSError TransferExtensionData(const AAFwk::WantParams& wantParams) override; 92 WSError TransferComponentData(const AAFwk::WantParams& wantParams); 93 WSErrorCode TransferComponentDataSync(const AAFwk::WantParams& wantParams, 94 AAFwk::WantParams& reWantParams); 95 WSError TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, 96 int64_t uiExtensionIdLevel) override; 97 WSError TransferAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType, int32_t eventType, 98 int64_t timeMs); 99 WSError TransferAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId); 100 WSError TransferAccessibilityChildTreeUnregister(); 101 WSError TransferAccessibilityDumpChildInfo(const std::vector<std::string>& params, std::vector<std::string>& info); 102 void NotifySyncOn() override; 103 void NotifyAsyncOn() override; 104 WSError NotifyDensityFollowHost(bool isFollowHost, float densityValue = 1.0f); 105 void TriggerBindModalUIExtension() override; 106 void RegisterExtensionSessionEventCallback(const sptr<ExtensionSessionEventCallback>& extSessionEventCallback); 107 WSError TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed, 108 bool& isTimeOut, bool isPreImeEvent = false); 109 WSError TransferKeyEventAsync(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool isPreImeEvent = false); 110 sptr<ExtensionSessionEventCallback> GetExtensionSessionEventCallback(); 111 WSError Background(bool isFromClient = false, const std::string& identityToken = "") override; 112 void NotifyExtensionEventAsync(uint32_t notifyEvent) override; 113 WSError NotifyDumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info); 114 115 private: 116 sptr<ExtensionSessionEventCallback> extSessionEventCallback_ = nullptr; 117 bool isFirstTriggerBindModal_ = true; 118 sptr<ChannelDeathRecipient> channelDeath_ = nullptr; 119 sptr<WindowEventChannelListener> channelListener_ = nullptr; 120 }; 121 } // namespace OHOS::Rosen 122 123 #endif // OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_H 124