/* * 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_SCENE_SESSION_H #define OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H #include #include "session/host/include/session.h" #include "session/host/include/move_drag_controller.h" #include "wm_common.h" namespace OHOS::PowerMgr { class RunningLock; } namespace OHOS::Rosen { class SceneSession; using SpecificSessionCreateCallback = std::function(const SessionInfo& info, sptr property)>; using SpecificSessionDestroyCallback = std::function; using CameraFloatSessionChangeCallback = std::function; using GetSceneSessionVectorByTypeCallback = std::function>(WindowType type)>; using UpdateAvoidAreaCallback = std::function; using NotifyWindowInfoUpdateCallback = std::function; using NotifyCreateSpecificSessionFunc = std::function& session)>; using NotifyBindDialogSessionFunc = std::function& session)>; using NotifySessionRectChangeFunc = std::function; using NotifySessionEventFunc = std::function; using NotifyRaiseToTopFunc = std::function; using SetWindowPatternOpacityFunc = std::function; using NotifyIsCustomAnimationPlayingCallback = std::function; using NotifySystemBarPropertyChangeFunc = std::function& propertyMap)>; using NotifyNeedAvoidFunc = std::function; using NotifyWindowAnimationFlagChangeFunc = std::function; using NotifyShowWhenLockedFunc = std::function; using NotifyReqOrientationChangeFunc = std::function; using NotifyRaiseAboveTargetFunc = std::function; class SceneSession : public Session { public: // callback for notify SceneSessionManager struct SpecificSessionCallback : public RefBase { SpecificSessionCreateCallback onCreate_; SpecificSessionDestroyCallback onDestroy_; CameraFloatSessionChangeCallback onCameraFloatSessionChange_; GetSceneSessionVectorByTypeCallback onGetSceneSessionVectorByType_; UpdateAvoidAreaCallback onUpdateAvoidArea_; NotifyWindowInfoUpdateCallback onWindowInfoUpdate_; }; // callback for notify SceneBoard struct SessionChangeCallback : public RefBase { NotifyCreateSpecificSessionFunc onCreateSpecificSession_; NotifyBindDialogSessionFunc onBindDialogTarget_; NotifySessionRectChangeFunc onRectChange_; NotifyRaiseToTopFunc onRaiseToTop_; NotifySessionEventFunc OnSessionEvent_; NotifySystemBarPropertyChangeFunc OnSystemBarPropertyChange_; NotifyNeedAvoidFunc OnNeedAvoid_; NotifyWindowAnimationFlagChangeFunc onWindowAnimationFlagChange_; NotifyIsCustomAnimationPlayingCallback onIsCustomAnimationPlaying_; NotifyShowWhenLockedFunc OnShowWhenLocked_; NotifyReqOrientationChangeFunc OnRequestedOrientationChange_; NotifyRaiseAboveTargetFunc onRaiseAboveTarget_; }; // func for change window scene pattern property struct SetWindowScenePatternFunc : public RefBase { SetWindowPatternOpacityFunc setOpacityFunc_; }; SceneSession(const SessionInfo& info, const sptr& specificCallback); ~SceneSession() = default; WSError Connect(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, SystemSessionConfig& systemConfig, sptr property = nullptr, sptr token = nullptr) override; WSError Foreground(sptr property) override; WSError Background() override; WSError UpdateWindowAnimationFlag(bool needDefaultAnimationFlag) override; WSError OnSessionEvent(SessionEvent event) override; WSError RaiseToAppTop() override; WSError UpdateRect(const WSRect& rect, SizeChangeReason reason) override; WSError UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) override; WSError CreateAndConnectSpecificSession(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, sptr property, int32_t& persistentId, sptr& session, sptr token = nullptr) override; WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) override; WSError SetSystemBarProperty(WindowType type, SystemBarProperty systemBarProperty); WSError OnNeedAvoid(bool status) override; void CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea); void GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea); void GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea); void GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea); AvoidArea GetAvoidAreaByType(AvoidAreaType type) override; WSError UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type); WSError OnShowWhenLocked(bool showWhenLocked); bool IsShowWhenLocked() const; void RegisterSessionChangeCallback(const sptr& sessionChangeCallback); WSError TransferPointerEvent(const std::shared_ptr& pointerEvent) override; WSError SetAspectRatio(float ratio) override; WSError SetGlobalMaximizeMode(MaximizeMode mode) override; WSError GetGlobalMaximizeMode(MaximizeMode& mode) override; std::string GetSessionSnapshotFilePath(); void RegisterSetWindowPatternFunc(sptr func) { setWindowScenePatternFunc_ = func; }; WSError UpdateWindowSceneAfterCustomAnimation(bool isAdd) override; void SetZOrder(uint32_t zOrder) override; std::vector GetTouchHotAreas() const override; Rect GetHotAreaRect(int32_t action); WSError NotifyTouchOutside(); static MaximizeMode maximizeMode_; WSError SetTurnScreenOn(bool turnScreenOn); bool IsTurnScreenOn() const; WSError SetKeepScreenOn(bool keepScreenOn); bool IsKeepScreenOn() const; const std::string& GetWindowName() const; bool IsDecorEnable(); void UpdateNativeVisibility(bool visible); void SetPrivacyMode(bool isPrivacy); bool IsVisible() const; bool IsFloatingWindowAppType() const; void DumpSessionElementInfo(const std::vector& params); static const wptr GetEnterWindow(); static void ClearEnterWindow(); void SetRequestedOrientation(Orientation orientation); Orientation GetRequestedOrientation() const; WSError BindDialogTarget(const sptr& sceneSession); std::shared_ptr keepScreenLock_; int32_t GetCollaboratorType() const; void SetCollaboratorType(int32_t collaboratorType); std::shared_ptr GetAbilityInfo(); void SetAbilitySessionInfo(std::shared_ptr abilityInfo); void UpdateBrokerPersistentId(int32_t persistendId); int32_t GetBrokerPersistentId(); WSError RaiseAboveTarget(int32_t subWindowId) override; private: void UpdateCameraFloatWindowStatus(bool isShowing); void NotifySessionRectChange(const WSRect& rect, const SizeChangeReason& reason = SizeChangeReason::UNDEFINED); void SetSessionRectChangeCallback(); void OnSessionRectChange(); bool FixRectByAspectRatio(WSRect& rect); std::string GetRatioPreferenceKey(); bool SaveAspectRatio(float ratio); void NotifyIsCustomAnimatiomPlaying(bool isPlaying); void NotifyPropertyWhenConnect(); sptr specificCallback_ = nullptr; sptr sessionChangeCallback_ = nullptr; sptr moveDragController_ = nullptr; sptr setWindowScenePatternFunc_ = nullptr; bool isVisible_ = false; static wptr enterSession_; static std::mutex enterSessionMutex_; int32_t brokerPersistentId_ = INVALID_SESSION_ID; int32_t collaboratorType_ = CollaboratorType::DEFAULT_TYPE; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H