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 "session/host/include/session.h" 20 #include "session/host/include/move_drag_controller.h" 21 #include "wm_common.h" 22 23 namespace OHOS::PowerMgr { 24 class RunningLock; 25 } 26 27 namespace OHOS::Rosen { 28 namespace PARAM_KEY { 29 const std::string PARAM_MISSION_AFFINITY_KEY = "ohos.anco.param.missionAffinity"; 30 } 31 class SceneSession; 32 33 using SpecificSessionCreateCallback = 34 std::function<sptr<SceneSession>(const SessionInfo& info, sptr<WindowSessionProperty> property)>; 35 using SpecificSessionDestroyCallback = std::function<WSError(const int32_t& persistentId)>; 36 using CameraFloatSessionChangeCallback = std::function<void(uint32_t accessTokenId, bool isShowing)>; 37 using GetSceneSessionVectorByTypeCallback = std::function<std::vector<sptr<SceneSession>>(WindowType type)>; 38 using UpdateAvoidAreaCallback = std::function<void(const int32_t& persistentId)>; 39 using NotifyWindowInfoUpdateCallback = std::function<void(int32_t persistentId, WindowUpdateType type)>; 40 using NotifyWindowPidChangeCallback = std::function<void(int32_t windowId, bool startMoving)>; 41 using NotifySessionTouchOutsideCallback = std::function<void(int32_t persistentId)>; 42 using GetAINavigationBarArea = std::function<WSRect()>; 43 using RecoveryCallback = std::function<void(int32_t persistentId, Rect rect)>; 44 using NotifyBindDialogSessionFunc = std::function<void(const sptr<SceneSession>& session)>; 45 using NotifySessionRectChangeFunc = std::function<void(const WSRect& rect, const SizeChangeReason& reason)>; 46 using NotifySessionEventFunc = std::function<void(int32_t eventId)>; 47 using NotifyRaiseToTopFunc = std::function<void()>; 48 using SetWindowPatternOpacityFunc = std::function<void(float opacity)>; 49 using NotifyIsCustomAnimationPlayingCallback = std::function<void(bool isFinish)>; 50 using NotifyWindowAnimationFlagChangeFunc = std::function<void(const bool flag)>; 51 using NotifySystemBarPropertyChangeFunc = std::function<void( 52 const std::unordered_map<WindowType, SystemBarProperty>& propertyMap)>; 53 using NotifyNeedAvoidFunc = std::function<void(bool status)>; 54 using NotifyShowWhenLockedFunc = std::function<void(bool showWhenLocked)>; 55 using NotifyReqOrientationChangeFunc = std::function<void(uint32_t orientation)>; 56 using NotifyRaiseAboveTargetFunc = std::function<void(int32_t subWindowId)>; 57 using NotifyForceHideChangeFunc = std::function<void(bool hide)>; 58 using NotifyTouchOutsideFunc = std::function<void()>; 59 using ClearCallbackMapFunc = std::function<void(bool needRemove, int32_t persistentId)>; 60 using NotifyPrepareClosePiPSessionFunc = std::function<void()>; 61 using OnOutsideDownEvent = std::function<void(int32_t x, int32_t y)>; 62 class SceneSession : public Session { 63 public: 64 // callback for notify SceneSessionManager 65 struct SpecificSessionCallback : public RefBase { 66 SpecificSessionCreateCallback onCreate_; 67 SpecificSessionDestroyCallback onDestroy_; 68 CameraFloatSessionChangeCallback onCameraFloatSessionChange_; 69 GetSceneSessionVectorByTypeCallback onGetSceneSessionVectorByType_; 70 UpdateAvoidAreaCallback onUpdateAvoidArea_; 71 NotifyWindowInfoUpdateCallback onWindowInfoUpdate_; 72 NotifyWindowPidChangeCallback onWindowInputPidChangeCallback_; 73 NotifySessionTouchOutsideCallback onSessionTouchOutside_; 74 GetAINavigationBarArea onGetAINavigationBarArea_; 75 RecoveryCallback onRecoveryPullPiPMainWindow_; 76 OnOutsideDownEvent onOutsideDownEvent_; 77 }; 78 79 // callback for notify SceneBoard 80 struct SessionChangeCallback : public RefBase { 81 NotifyBindDialogSessionFunc onBindDialogTarget_; 82 NotifySessionRectChangeFunc onRectChange_; 83 NotifyRaiseToTopFunc onRaiseToTop_; 84 NotifySessionEventFunc OnSessionEvent_; 85 NotifySystemBarPropertyChangeFunc OnSystemBarPropertyChange_; 86 NotifyNeedAvoidFunc OnNeedAvoid_; 87 NotifyIsCustomAnimationPlayingCallback onIsCustomAnimationPlaying_; 88 NotifyWindowAnimationFlagChangeFunc onWindowAnimationFlagChange_; 89 NotifyShowWhenLockedFunc OnShowWhenLocked_; 90 NotifyReqOrientationChangeFunc OnRequestedOrientationChange_; 91 NotifyRaiseAboveTargetFunc onRaiseAboveTarget_; 92 NotifyForceHideChangeFunc OnForceHideChange_; 93 NotifyTouchOutsideFunc OnTouchOutside_; 94 ClearCallbackMapFunc clearCallbackFunc_; 95 NotifyPrepareClosePiPSessionFunc onPrepareClosePiPSession_; 96 }; 97 98 // func for change window scene pattern property 99 struct SetWindowScenePatternFunc : public RefBase { 100 SetWindowPatternOpacityFunc setOpacityFunc_; 101 }; 102 103 SceneSession(const SessionInfo& info, const sptr<SpecificSessionCallback>& specificCallback); 104 virtual ~SceneSession(); 105 106 WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel, 107 const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig, 108 sptr<WindowSessionProperty> property = nullptr, sptr<IRemoteObject> token = nullptr, 109 int32_t pid = -1, int32_t uid = -1) override; 110 WSError Reconnect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel, 111 const std::shared_ptr<RSSurfaceNode>& surfaceNode, sptr<WindowSessionProperty> property = nullptr, 112 sptr<IRemoteObject> token = nullptr, int32_t pid = -1, int32_t uid = -1); 113 WSError Foreground(sptr<WindowSessionProperty> property) override; 114 WSError Background() override; 115 WSError Disconnect(bool isFromClient = false) override; 116 117 WSError UpdateActiveStatus(bool isActive) override; 118 WSError OnSessionEvent(SessionEvent event) override; 119 WSError RaiseToAppTop() override; 120 WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, 121 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override; 122 WSError UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) override; 123 WSError PendingSessionActivation(const sptr<AAFwk::SessionInfo> info) override; 124 WSError TerminateSession(const sptr<AAFwk::SessionInfo> info) override; 125 WSError NotifySessionException( 126 const sptr<AAFwk::SessionInfo> info, bool needRemoveSession = false) override; 127 WSError NotifyClientToUpdateRect(std::shared_ptr<RSTransaction> rsTransaction) override; 128 WSError OnNeedAvoid(bool status) override; 129 AvoidArea GetAvoidAreaByType(AvoidAreaType type) override; 130 WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 131 bool needNotifyClient = true) override; 132 WSError RequestSessionBack(bool needMoveToBackground) override; 133 WSError SetAspectRatio(float ratio) override; 134 WSError SetGlobalMaximizeMode(MaximizeMode mode) override; 135 WSError GetGlobalMaximizeMode(MaximizeMode& mode) override; 136 WSError UpdateWindowSceneAfterCustomAnimation(bool isAdd) override; 137 WSError UpdateWindowAnimationFlag(bool needDefaultAnimationFlag) override; 138 void SetZOrder(uint32_t zOrder) override; 139 std::vector<Rect> GetTouchHotAreas() const override; 140 void SetFloatingScale(float floatingScale) override; 141 WSError RaiseAboveTarget(int32_t subWindowId) override; 142 WSError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override; 143 WSError UpdatePiPRect(uint32_t width, uint32_t height, PiPRectUpdateReason reason) override; 144 void NotifyPiPWindowPrepareClose() override; 145 WSError RecoveryPullPiPMainWindow(int32_t persistentId, const Rect& rect) override; 146 void SetScale(float scaleX, float scaleY, float pivotX, float pivotY) override; 147 void RequestHideKeyboard(bool isAppColdStart = false); 148 WSError ProcessPointDownSession(int32_t posX, int32_t posY) override; 149 WSError SendPointEventForMoveDrag(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override; 150 void NotifyOutsideDownEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 151 void SetForegroundInteractiveStatus(bool interactive) override; 152 153 WSError SetKeepScreenOn(bool keepScreenOn); 154 void SetParentPersistentId(int32_t parentId); 155 WSError SetTurnScreenOn(bool turnScreenOn); 156 void SetPrivacyMode(bool isPrivacy); 157 void SetSystemSceneOcclusionAlpha(double alpha); 158 void SetRequestedOrientation(Orientation orientation); 159 void SetWindowAnimationFlag(bool needDefaultAnimationFlag); 160 void SetCollaboratorType(int32_t collaboratorType); 161 void SetSelfToken(sptr<IRemoteObject> selfToken); 162 void SetLastSafeRect(WSRect rect); 163 WSError SetSystemBarProperty(WindowType type, SystemBarProperty systemBarProperty); 164 void SetAbilitySessionInfo(std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo); 165 void SetWindowDragHotAreaListener(const NotifyWindowDragHotAreaFunc& func); 166 void SetSessionRectChangeCallback(const NotifySessionRectChangeFunc& func); 167 168 int32_t GetCollaboratorType() const; 169 sptr<IRemoteObject> GetSelfToken() const; 170 WSRect GetLastSafeRect() const; 171 WSRect GetSessionTargetRect() const; 172 std::string GetUpdatedIconPath() const; 173 std::string GetSessionSnapshotFilePath() const; 174 int32_t GetParentPersistentId() const; 175 const std::string& GetWindowName() const; 176 const std::string& GetWindowNameAllType() const; 177 Orientation GetRequestedOrientation() const; 178 std::vector<sptr<SceneSession>> GetSubSession() const; 179 std::shared_ptr<AppExecFwk::AbilityInfo> GetAbilityInfo() const; 180 181 bool IsVisible() const; 182 bool IsDecorEnable() const; 183 bool IsAppSession() const; 184 bool IsTurnScreenOn() const; 185 bool IsKeepScreenOn() const; 186 bool IsShowWhenLocked() const; 187 bool IsFloatingWindowAppType() const; 188 bool IsNeedDefaultAnimation() const; 189 bool IsDirtyWindow(); 190 void NotifyUILostFocus() override; 191 void SetSystemTouchable(bool touchable) override; 192 bool IsVisibleForAccessibility() const; 193 194 WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override; 195 WSError OnShowWhenLocked(bool showWhenLocked); 196 void SaveUpdatedIcon(const std::shared_ptr<Media::PixelMap> &icon); 197 void NotifyTouchOutside(); 198 void NotifyWindowVisibility(); 199 bool CheckOutTouchOutsideRegister(); 200 void UpdateNativeVisibility(bool visible); 201 void UpdateRotationAvoidArea(); 202 void DumpSessionElementInfo(const std::vector<std::string>& params); 203 void NotifyForceHideChange(bool hide); 204 WSError BindDialogSessionTarget(const sptr<SceneSession>& sceneSession); 205 void DumpSessionInfo(std::vector<std::string> &info) const; 206 bool AddSubSession(const sptr<SceneSession>& subSession); 207 bool RemoveSubSession(int32_t persistentId); 208 void NotifySessionForeground(uint32_t reason, bool withAnimation); 209 void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits); 210 void RegisterSessionChangeCallback(const sptr<SceneSession::SessionChangeCallback>& sessionChangeCallback); 211 WSError UpdateSizeChangeReason(SizeChangeReason reason); 212 void ClearSpecificSessionCbMap(); 213 void SendPointerEventToUI(std::shared_ptr<MMI::PointerEvent> pointerEvent); 214 void SendKeyEventToUI(std::shared_ptr<MMI::KeyEvent> keyEvent); 215 bool IsStartMoving() const; 216 void SetIsStartMoving(const bool startMoving); 217 218 void SetSessionState(SessionState state) override; 219 void UpdateSessionState(SessionState state) override; 220 221 double textFieldPositionY_ = 0.0; 222 double textFieldHeight_ = 0.0; 223 std::shared_ptr<PowerMgr::RunningLock> keepScreenLock_; 224 225 static const wptr<SceneSession> GetEnterWindow(); 226 static void ClearEnterWindow(); 227 static MaximizeMode maximizeMode_; 228 static std::map<int32_t, WSRect> windowDragHotAreaMap_; 229 230 protected: 231 void NotifyIsCustomAnimationPlaying(bool isPlaying); 232 void SetMoveDragCallback(); 233 std::string GetRatioPreferenceKey(); 234 GetRectInfo(const WSRect & rect)235 std::string GetRectInfo(const WSRect& rect) 236 { 237 using std::to_string; 238 return "[" + to_string(rect.width_) + ", " + to_string(rect.height_) + "; " 239 + to_string(rect.posX_) + ", " + to_string(rect.posY_) + "]"; 240 } 241 242 sptr<SpecificSessionCallback> specificCallback_ = nullptr; 243 sptr<SessionChangeCallback> sessionChangeCallback_ = nullptr; 244 sptr<MoveDragController> moveDragController_ = nullptr; 245 246 private: 247 void NotifyAccessibilityVisibilityChange(); 248 void CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea) const; 249 void GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea); 250 void GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea); 251 void GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea); 252 void GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea); 253 void HandleStyleEvent(MMI::WindowArea area) override; 254 WSError HandleEnterWinwdowArea(int32_t windowX, int32_t windowY); 255 WSError HandlePointerStyle(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 256 257 void NotifySessionRectChange(const WSRect& rect, const SizeChangeReason& reason = SizeChangeReason::UNDEFINED); 258 void OnMoveDragCallback(const SizeChangeReason& reason); 259 void FixRectByLimits(WindowLimits limits, WSRect& rect, float ratio, bool isDecor, float vpr); 260 bool FixRectByAspectRatio(WSRect& rect); 261 bool SaveAspectRatio(float ratio); 262 void NotifyPropertyWhenConnect(); 263 WSError RaiseAppMainWindowToTop() override; 264 void SetSurfaceBounds(const WSRect &rect); 265 void UpdateWinRectForSystemBar(WSRect& rect); 266 bool UpdateInputMethodSessionRect(const WSRect& rect, WSRect& newWinRect, WSRect& newRequestRect); 267 void OnPiPMoveCallback(const WSRect& rect, const SizeChangeReason& reason); 268 bool InitPiPRectInfo(); 269 void ClearPiPRectPivotInfo(); 270 void SavePiPRectInfo(); 271 void GetNewPiPRect(const uint32_t displayWidth, const uint32_t displayHeight, Rect& rect); 272 void ProcessUpdatePiPRect(SizeChangeReason reason); 273 274 NotifySessionRectChangeFunc sessionRectChangeFunc_; 275 static wptr<SceneSession> enterSession_; 276 static std::mutex enterSessionMutex_; 277 mutable std::mutex sessionChangeCbMutex_; 278 int32_t collaboratorType_ = CollaboratorType::DEFAULT_TYPE; 279 sptr<IRemoteObject> selfToken_ = nullptr; 280 WSRect lastSafeRect = { 0, 0, 0, 0 }; 281 std::vector<sptr<SceneSession>> subSession_; 282 bool needDefaultAnimationFlag_ = true; 283 PiPRectInfo pipRectInfo_; 284 SizeChangeReason reason_ = SizeChangeReason::UNDEFINED; 285 std::atomic_bool isStartMoving_ { false }; 286 std::atomic_bool isVisibleForAccessibility_ { true }; 287 }; 288 } // namespace OHOS::Rosen 289 #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H