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