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_SCENE_SESSION_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H 18 19 #include <mutex> 20 21 #include "session/host/include/session.h" 22 #include "session/host/include/move_drag_controller.h" 23 #include "wm_common.h" 24 25 namespace OHOS::PowerMgr { 26 class RunningLock; 27 } 28 29 namespace OHOS::Rosen { 30 class SceneSession; 31 32 using SpecificSessionCreateCallback = std::function<sptr<SceneSession>(const SessionInfo& info, sptr<WindowSessionProperty> property)>; 33 using SpecificSessionDestroyCallback = std::function<WSError(const int32_t& persistentId)>; 34 using CameraFloatSessionChangeCallback = std::function<void(uint32_t accessTokenId, bool isShowing)>; 35 using GetSceneSessionVectorByTypeCallback = std::function<std::vector<sptr<SceneSession>>(WindowType type)>; 36 using UpdateAvoidAreaCallback = std::function<bool(const int32_t& persistentId)>; 37 using NotifyWindowInfoUpdateCallback = std::function<void(int32_t persistentId, WindowUpdateType type)>; 38 39 using NotifyCreateSpecificSessionFunc = std::function<void(const sptr<SceneSession>& session)>; 40 using NotifyBindDialogSessionFunc = std::function<void(const sptr<SceneSession>& session)>; 41 using NotifySessionRectChangeFunc = std::function<void(const WSRect& rect, const SizeChangeReason& reason)>; 42 using NotifySessionEventFunc = std::function<void(int32_t eventId)>; 43 using NotifyRaiseToTopFunc = std::function<void()>; 44 using SetWindowPatternOpacityFunc = std::function<void(float opacity)>; 45 using NotifyIsCustomAnimationPlayingCallback = std::function<void(bool isFinish)>; 46 using NotifySystemBarPropertyChangeFunc = std::function<void( 47 const std::unordered_map<WindowType, SystemBarProperty>& propertyMap)>; 48 using NotifyNeedAvoidFunc = std::function<void(bool status)>; 49 using NotifyWindowAnimationFlagChangeFunc = std::function<void(const bool flag)>; 50 using NotifyShowWhenLockedFunc = std::function<void(bool showWhenLocked)>; 51 using NotifyReqOrientationChangeFunc = std::function<void(uint32_t orientation)>; 52 using NotifyRaiseAboveTargetFunc = std::function<void(int32_t subWindowId)>; 53 class SceneSession : public Session { 54 public: 55 // callback for notify SceneSessionManager 56 struct SpecificSessionCallback : public RefBase { 57 SpecificSessionCreateCallback onCreate_; 58 SpecificSessionDestroyCallback onDestroy_; 59 CameraFloatSessionChangeCallback onCameraFloatSessionChange_; 60 GetSceneSessionVectorByTypeCallback onGetSceneSessionVectorByType_; 61 UpdateAvoidAreaCallback onUpdateAvoidArea_; 62 NotifyWindowInfoUpdateCallback onWindowInfoUpdate_; 63 }; 64 65 // callback for notify SceneBoard 66 struct SessionChangeCallback : public RefBase { 67 NotifyCreateSpecificSessionFunc onCreateSpecificSession_; 68 NotifyBindDialogSessionFunc onBindDialogTarget_; 69 NotifySessionRectChangeFunc onRectChange_; 70 NotifyRaiseToTopFunc onRaiseToTop_; 71 NotifySessionEventFunc OnSessionEvent_; 72 NotifySystemBarPropertyChangeFunc OnSystemBarPropertyChange_; 73 NotifyNeedAvoidFunc OnNeedAvoid_; 74 NotifyWindowAnimationFlagChangeFunc onWindowAnimationFlagChange_; 75 NotifyIsCustomAnimationPlayingCallback onIsCustomAnimationPlaying_; 76 NotifyShowWhenLockedFunc OnShowWhenLocked_; 77 NotifyReqOrientationChangeFunc OnRequestedOrientationChange_; 78 NotifyRaiseAboveTargetFunc onRaiseAboveTarget_; 79 }; 80 81 // func for change window scene pattern property 82 struct SetWindowScenePatternFunc : public RefBase { 83 SetWindowPatternOpacityFunc setOpacityFunc_; 84 }; 85 86 SceneSession(const SessionInfo& info, const sptr<SpecificSessionCallback>& specificCallback); 87 ~SceneSession() = default; 88 89 WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel, 90 const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig, 91 sptr<WindowSessionProperty> property = nullptr, sptr<IRemoteObject> token = nullptr) override; 92 WSError Foreground(sptr<WindowSessionProperty> property) override; 93 WSError Background() override; 94 WSError UpdateWindowAnimationFlag(bool needDefaultAnimationFlag) override; 95 96 WSError OnSessionEvent(SessionEvent event) override; 97 WSError RaiseToAppTop() override; 98 WSError UpdateRect(const WSRect& rect, SizeChangeReason reason) override; 99 WSError UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) override; 100 WSError CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage, 101 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 102 sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session, 103 sptr<IRemoteObject> token = nullptr) override; 104 WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) override; 105 WSError SetSystemBarProperty(WindowType type, SystemBarProperty systemBarProperty); 106 WSError OnNeedAvoid(bool status) override; 107 void CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea); 108 void GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea); 109 void GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea); 110 void GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea); 111 AvoidArea GetAvoidAreaByType(AvoidAreaType type) override; 112 WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type); 113 WSError OnShowWhenLocked(bool showWhenLocked); 114 bool IsShowWhenLocked() const; 115 void RegisterSessionChangeCallback(const sptr<SceneSession::SessionChangeCallback>& sessionChangeCallback); 116 WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override; 117 WSError SetAspectRatio(float ratio) override; 118 WSError SetGlobalMaximizeMode(MaximizeMode mode) override; 119 WSError GetGlobalMaximizeMode(MaximizeMode& mode) override; 120 std::string GetSessionSnapshotFilePath(); RegisterSetWindowPatternFunc(sptr<SetWindowScenePatternFunc> func)121 void RegisterSetWindowPatternFunc(sptr<SetWindowScenePatternFunc> func) 122 { 123 setWindowScenePatternFunc_ = func; 124 }; 125 WSError UpdateWindowSceneAfterCustomAnimation(bool isAdd) override; 126 void SetZOrder(uint32_t zOrder) override; 127 std::vector<Rect> GetTouchHotAreas() const override; 128 Rect GetHotAreaRect(int32_t action); 129 WSError NotifyTouchOutside(); 130 131 static MaximizeMode maximizeMode_; 132 133 WSError SetTurnScreenOn(bool turnScreenOn); 134 bool IsTurnScreenOn() const; 135 WSError SetKeepScreenOn(bool keepScreenOn); 136 bool IsKeepScreenOn() const; 137 const std::string& GetWindowName() const; 138 bool IsDecorEnable(); 139 void UpdateNativeVisibility(bool visible); 140 void SetPrivacyMode(bool isPrivacy); 141 bool IsVisible() const; 142 bool IsFloatingWindowAppType() const; 143 void DumpSessionElementInfo(const std::vector<std::string>& params); 144 static const wptr<SceneSession> GetEnterWindow(); 145 static void ClearEnterWindow(); 146 void SetRequestedOrientation(Orientation orientation); 147 Orientation GetRequestedOrientation() const; 148 WSError BindDialogTarget(const sptr<SceneSession>& sceneSession); 149 150 std::shared_ptr<PowerMgr::RunningLock> keepScreenLock_; 151 152 int32_t GetCollaboratorType() const; 153 void SetCollaboratorType(int32_t collaboratorType); 154 std::shared_ptr<AppExecFwk::AbilityInfo> GetAbilityInfo(); 155 void SetAbilitySessionInfo(std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo); 156 void UpdateBrokerPersistentId(int32_t persistendId); 157 int32_t GetBrokerPersistentId(); 158 WSError RaiseAboveTarget(int32_t subWindowId) override; 159 private: 160 void UpdateCameraFloatWindowStatus(bool isShowing); 161 void NotifySessionRectChange(const WSRect& rect, const SizeChangeReason& reason = SizeChangeReason::UNDEFINED); 162 void SetSessionRectChangeCallback(); 163 void OnSessionRectChange(); 164 bool FixRectByAspectRatio(WSRect& rect); 165 std::string GetRatioPreferenceKey(); 166 bool SaveAspectRatio(float ratio); 167 void NotifyIsCustomAnimatiomPlaying(bool isPlaying); 168 void NotifyPropertyWhenConnect(); 169 sptr<SpecificSessionCallback> specificCallback_ = nullptr; 170 sptr<SessionChangeCallback> sessionChangeCallback_ = nullptr; 171 sptr<MoveDragController> moveDragController_ = nullptr; 172 sptr<SetWindowScenePatternFunc> setWindowScenePatternFunc_ = nullptr; 173 bool isVisible_ = false; 174 static wptr<SceneSession> enterSession_; 175 static std::mutex enterSessionMutex_; 176 int32_t brokerPersistentId_ = INVALID_SESSION_ID; 177 int32_t collaboratorType_ = CollaboratorType::DEFAULT_TYPE; 178 179 }; 180 } // namespace OHOS::Rosen 181 182 #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H 183