/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_H #define OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_H #include #include "key_event.h" #include "want.h" #include "session/host/include/session.h" namespace OHOS::Rosen { class WindowEventChannelListener : public IRemoteStub { public: explicit WindowEventChannelListener() = default; void SetTransferKeyEventForConsumedParams(int32_t keyEventId, bool isPreImeEvent, const std::shared_ptr>& isConsumedPromise, const std::shared_ptr& retCode); void ResetTransferKeyEventForConsumedParams(); void ResetTransferKeyEventForConsumedParams(bool isConsumed, WSError retCode); void OnTransferKeyEventForConsumed(int32_t keyEventId, bool isPreImeEvent, bool isConsumed, WSError retCode) override; int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; private: std::mutex transferKeyEventForConsumedMutex_; int32_t keyEventId_ = 0; bool isPreImeEvent_ = false; std::shared_ptr> isConsumedPromise_ = nullptr; std::shared_ptr retCode_ = nullptr; }; class ChannelDeathRecipient : public IRemoteObject::DeathRecipient { public: explicit ChannelDeathRecipient(const sptr& listener): listener_(listener) {} virtual void OnRemoteDied(const wptr& wptrDeath) override; private: sptr listener_ = nullptr; }; using NotifyTransferAbilityResultFunc = std::function; using NotifyTransferExtensionDataFunc = std::function; using NotifyRemoteReadyFunc = std::function; using NotifySyncOnFunc = std::function; using NotifyAsyncOnFunc = std::function; using NotifyGetAvoidAreaByTypeFunc = std::function; using NotifyBindModalFunc = std::function; using NotifyExtensionEventFunc = std::function; class ExtensionSession : public Session { public: struct ExtensionSessionEventCallback : public RefBase { NotifyTransferAbilityResultFunc transferAbilityResultFunc_; NotifyTransferExtensionDataFunc transferExtensionDataFunc_; NotifyRemoteReadyFunc notifyRemoteReadyFunc_; NotifySyncOnFunc notifySyncOnFunc_; NotifyAsyncOnFunc notifyAsyncOnFunc_; NotifyGetAvoidAreaByTypeFunc notifyGetAvoidAreaByTypeFunc_; NotifyBindModalFunc notifyBindModalFunc_; NotifyExtensionEventFunc notifyExtensionEventFunc_; }; explicit ExtensionSession(const SessionInfo& info); virtual ~ExtensionSession(); WSError Connect(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, SystemSessionConfig& systemConfig, sptr property, sptr token, const std::string& identityToken = "") override; WSError ConnectInner(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, SystemSessionConfig& systemConfig, sptr property, sptr token, int32_t pid, int32_t uid, const std::string& identityToken = "") override; AvoidArea GetAvoidAreaByType(AvoidAreaType type) override; WSError UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) override; WSError TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want) override; WSError TransferExtensionData(const AAFwk::WantParams& wantParams) override; WSError TransferComponentData(const AAFwk::WantParams& wantParams); WSErrorCode TransferComponentDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams); WSError TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t uiExtensionIdLevel) override; WSError TransferAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType, int32_t eventType, int64_t timeMs); WSError TransferAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId); WSError TransferAccessibilityChildTreeUnregister(); WSError TransferAccessibilityDumpChildInfo(const std::vector& params, std::vector& info); void NotifySyncOn() override; void NotifyAsyncOn() override; WSError NotifyDensityFollowHost(bool isFollowHost, float densityValue = 1.0f); void TriggerBindModalUIExtension() override; void RegisterExtensionSessionEventCallback(const sptr& extSessionEventCallback); WSError TransferKeyEventForConsumed(const std::shared_ptr& keyEvent, bool& isConsumed, bool& isTimeOut, bool isPreImeEvent = false); WSError TransferKeyEventAsync(const std::shared_ptr& keyEvent, bool isPreImeEvent = false); sptr GetExtensionSessionEventCallback(); WSError Background(bool isFromClient = false, const std::string& identityToken = "") override; void NotifyExtensionEventAsync(uint32_t notifyEvent) override; WSError NotifyDumpInfo(const std::vector& params, std::vector& info); private: sptr extSessionEventCallback_ = nullptr; bool isFirstTriggerBindModal_ = true; sptr channelDeath_ = nullptr; sptr channelListener_ = nullptr; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_H