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_SCREEN_SESSION_MANAGER_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_MANAGER_H 18 19 #include <shared_mutex> 20 #include <system_ability.h> 21 #include <mutex> 22 #include <condition_variable> 23 #include <pixel_map.h> 24 25 #include "common/include/task_scheduler.h" 26 #include "dm_common.h" 27 #include "event_tracker.h" 28 #include "session/screen/include/screen_session.h" 29 #include "zidl/screen_session_manager_stub.h" 30 #include "client_agent_container.h" 31 #include "session_display_power_controller.h" 32 #include "wm_single_instance.h" 33 #include "screen_edid_parse.h" 34 35 #include "agent_death_recipient.h" 36 #include "screen.h" 37 #include "screen_cutout_controller.h" 38 #include "fold_screen_controller/fold_screen_controller.h" 39 #include "fold_screen_controller/fold_screen_sensor_manager.h" 40 #include "fold_screen_controller/super_fold_state_manager.h" 41 42 namespace OHOS::Rosen { 43 class RSInterfaces; 44 45 struct ScaleProperty { 46 float scaleX; 47 float scaleY; 48 float pivotX; 49 float pivotY; 50 ScalePropertyScaleProperty51 ScaleProperty(float scaleX, float scaleY, float pivotX, float pivotY) : scaleX(scaleX), scaleY(scaleY), 52 pivotX(pivotX), pivotY(pivotY) {} 53 }; 54 55 static const std::map<ScreenPowerStatus, DisplayPowerEvent> SCREEN_STATUS_POWER_EVENT_MAP = { 56 {ScreenPowerStatus::POWER_STATUS_ON, DisplayPowerEvent::DISPLAY_ON}, 57 {ScreenPowerStatus::POWER_STATUS_OFF, DisplayPowerEvent::DISPLAY_OFF}, 58 {ScreenPowerStatus::POWER_STATUS_DOZE, DisplayPowerEvent::DISPLAY_DOZE}, 59 {ScreenPowerStatus::POWER_STATUS_DOZE_SUSPEND, DisplayPowerEvent::DISPLAY_DOZE_SUSPEND} 60 }; 61 62 class ScreenSessionManager : public SystemAbility, public ScreenSessionManagerStub, public IScreenChangeListener { 63 DECLARE_SYSTEM_ABILITY(ScreenSessionManager) 64 WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenSessionManager) 65 66 public: 67 sptr<ScreenSession> GetScreenSession(ScreenId screenId) const; 68 sptr<ScreenSession> GetDefaultScreenSession(); 69 std::vector<ScreenId> GetAllScreenIds(); 70 71 sptr<DisplayInfo> GetDefaultDisplayInfo() override; 72 DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override; 73 DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) override; 74 DMError SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio) override; 75 DMError SetDefaultDensityDpi(ScreenId screenId, float densityDpi) override; 76 DMError SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio) override; 77 DMError GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio) override; 78 void NotifyScreenChanged(sptr<ScreenInfo> screenInfo, ScreenChangeEvent event); 79 // inner interface of multimodal-input 80 void NotifyScreenModeChange(ScreenId disconnectedScreenId = INVALID_SCREEN_ID); 81 void NotifyAbnormalScreenConnectChange(ScreenId screenId); 82 DMError SetPrimaryDisplaySystemDpi(float dpi) override; 83 84 DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut) override; 85 DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx) override; 86 DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap) override; 87 DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap) override; 88 DMError SetScreenColorTransform(ScreenId screenId) override; 89 90 DMError GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat) override; 91 DMError SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat) override; 92 DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<ScreenHDRFormat>& hdrFormats) override; 93 DMError GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat) override; 94 DMError SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx) override; 95 DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<GraphicCM_ColorSpaceType>& colorSpaces) override; 96 DMError GetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType& colorSpace) override; 97 DMError SetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType colorSpace) override; 98 99 void DumpAllScreensInfo(std::string& dumpInfo) override; 100 void DumpSpecialScreenInfo(ScreenId id, std::string& dumpInfo) override; 101 102 virtual DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 103 DisplayManagerAgentType type) override; 104 virtual DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 105 DisplayManagerAgentType type) override; 106 107 ScreenId GetInternalScreenId() override; 108 bool SetScreenPowerById(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason) override; 109 bool SetScreenPowerByIdForPC(ScreenId screenId, ScreenPowerState state); 110 bool SetScreenPowerByIdDefault(ScreenId screenId, ScreenPowerState state); 111 DisplayState GetDisplayState(DisplayId displayId) override; 112 bool SetScreenBrightness(uint64_t screenId, uint32_t level) override; 113 uint32_t GetScreenBrightness(uint64_t screenId) override; 114 bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason) override; 115 void ForceSkipScreenOffAnimation(); 116 ScreenPowerState GetScreenPower() override; 117 118 void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener); 119 bool NotifyDisplayStateChanged(DisplayId id, DisplayState state); 120 void NotifyScreenshot(DisplayId displayId); 121 ScreenId CreateVirtualScreen(VirtualScreenOption option, const sptr<IRemoteObject>& displayManagerAgent) override; 122 virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface) override; 123 DMError AddVirtualScreenBlockList(const std::vector<int32_t>& persistentIds) override; 124 DMError RemoveVirtualScreenBlockList(const std::vector<int32_t>& persistentIds) override; 125 virtual DMError SetScreenPrivacyMaskImage(ScreenId screenId, 126 const std::shared_ptr<Media::PixelMap>& privacyMaskImg) override; 127 virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool autoRotate) override; 128 virtual DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode) override; 129 virtual DMError DestroyVirtualScreen(ScreenId screenId) override; 130 DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height) override; 131 virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds, 132 ScreenId& screenGroupId) override; 133 virtual DMError MakeMirrorForRecord(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds, 134 ScreenId& screenGroupId) override; 135 virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds, 136 DMRect mainScreenRegion, ScreenId& screenGroupId) override; 137 virtual DMError SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId, 138 MultiScreenMode screenMode) override; 139 virtual DMError SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions, 140 MultiScreenPositionOptions secondScreenOption) override; 141 virtual DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds) override; 142 DMError DisableMirror(bool disableOrNot) override; 143 virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, 144 ScreenId& screenGroupId) override; 145 virtual DMError StopExpand(const std::vector<ScreenId>& expandScreenIds) override; 146 DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds, std::vector<DisplayId>& displayIds) override; 147 virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId) override; 148 virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens) override; 149 virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId, 150 DmErrorCode* errorCode, bool isUseDma, bool isCaptureFullOfScreen) override; 151 virtual std::vector<std::shared_ptr<Media::PixelMap>> GetDisplayHDRSnapshot(DisplayId displayId, 152 DmErrorCode& errorCode, bool isUseDma, bool isCaptureFullOfScreen) override; 153 virtual std::shared_ptr<Media::PixelMap> GetSnapshotByPicker(Media::Rect &rect, DmErrorCode* errorCode) override; 154 virtual sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override; 155 virtual sptr<DisplayInfo> GetVisibleAreaDisplayInfoById(DisplayId displayId) override; 156 sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) override; 157 std::vector<DisplayId> GetAllDisplayIds() override; 158 virtual sptr<ScreenInfo> GetScreenInfoById(ScreenId screenId) override; 159 virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos) override; 160 virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, 161 std::vector<ScreenColorGamut>& colorGamuts) override; 162 DMError GetPhysicalScreenIds(std::vector<ScreenId>& screenIds) override; 163 DMError IsScreenRotationLocked(bool& isLocked) override; 164 DMError SetScreenRotationLocked(bool isLocked) override; 165 DMError SetScreenRotationLockedFromJs(bool isLocked) override; 166 DMError SetOrientation(ScreenId screenId, Orientation orientation) override; 167 bool SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow); 168 void SetSensorSubscriptionEnabled(); 169 bool SetRotationFromWindow(Rotation targetRotation); 170 sptr<SupportedScreenModes> GetScreenModesByDisplayId(DisplayId displayId); 171 sptr<ScreenInfo> GetScreenInfoByDisplayId(DisplayId displayId); 172 void NotifyDisplayCreate(sptr<DisplayInfo> displayInfo); 173 void NotifyDisplayDestroy(DisplayId displayId); 174 void NotifyAndPublishEvent(sptr<DisplayInfo> displayInfo, ScreenId screenId, sptr<ScreenSession> screenSession); 175 void NotifyDisplayChanged(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event); 176 177 std::vector<ScreenId> GetAllScreenIds() const; 178 const std::shared_ptr<RSDisplayNode> GetRSDisplayNodeByScreenId(ScreenId smsScreenId) const; 179 std::shared_ptr<Media::PixelMap> GetScreenSnapshot(DisplayId displayId, bool isUseDma = false, 180 bool isCaptureFullOfScreen = false, const std::vector<NodeId>& surfaceNodesList = {}); 181 182 sptr<ScreenSession> InitVirtualScreen(ScreenId smsScreenId, ScreenId rsId, VirtualScreenOption option); 183 sptr<ScreenSession> InitAndGetScreen(ScreenId rsScreenId); 184 bool InitAbstractScreenModesInfo(sptr<ScreenSession>& absScreen); 185 std::vector<ScreenId> GetAllValidScreenIds(const std::vector<ScreenId>& screenIds) const; 186 187 sptr<ScreenSessionGroup> AddToGroupLocked(sptr<ScreenSession> newScreen, bool isUnique = false); 188 sptr<ScreenSessionGroup> AddAsFirstScreenLocked(sptr<ScreenSession> newScreen, bool isUnique = false); 189 sptr<ScreenSessionGroup> AddAsSuccedentScreenLocked(sptr<ScreenSession> newScreen); 190 sptr<ScreenSessionGroup> RemoveFromGroupLocked(sptr<ScreenSession> screen); 191 sptr<ScreenSessionGroup> GetAbstractScreenGroup(ScreenId smsScreenId); 192 193 void SetMultiScreenFrameControl(void); 194 bool IsPhysicalScreenAndInUse(sptr<ScreenSession> screenSession) const; 195 bool HandleFoldScreenSessionCreate(ScreenId screenId); 196 197 void ChangeScreenGroup(sptr<ScreenSessionGroup> group, const std::vector<ScreenId>& screens, 198 const std::vector<Point>& startPoints, bool filterScreen, ScreenCombination combination, 199 DMRect mainScreenRegion = DMRect::NONE()); 200 201 bool RemoveChildFromGroup(sptr<ScreenSession> screen, sptr<ScreenSessionGroup> screenGroup); 202 203 void AddScreenToGroup(sptr<ScreenSessionGroup> group, 204 const std::vector<ScreenId>& addScreens, const std::vector<Point>& addChildPos, 205 std::map<ScreenId, bool>& removeChildResMap); 206 bool CheckScreenInScreenGroup(sptr<ScreenSession> screen) const; 207 208 DMError SetMirror(ScreenId screenId, std::vector<ScreenId> screens, DMRect mainScreenRegion); 209 DMError StopScreens(const std::vector<ScreenId>& screenIds, ScreenCombination stopCombination); 210 211 void NotifyScreenConnected(sptr<ScreenInfo> screenInfo); 212 void NotifyScreenDisconnected(ScreenId screenId); 213 void NotifyScreenGroupChanged(const sptr<ScreenInfo>& screenInfo, ScreenGroupChangeEvent event); 214 void NotifyScreenGroupChanged(const std::vector<sptr<ScreenInfo>>& screenInfo, ScreenGroupChangeEvent event); 215 216 void NotifyPrivateSessionStateChanged(bool hasPrivate); 217 void NotifyPrivateWindowListChanged(DisplayId id, std::vector<std::string> privacyWindowList); 218 DMError HasPrivateWindow(DisplayId id, bool& hasPrivateWindow) override; 219 bool ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId) override; 220 void UpdateDisplayHookInfo(int32_t uid, bool enable, const DMHookInfo& hookInfo) override; 221 void GetDisplayHookInfo(int32_t uid, DMHookInfo& hookInfo) override; 222 223 void OnScreenConnect(const sptr<ScreenInfo> screenInfo); 224 void OnScreenDisconnect(ScreenId screenId); 225 void OnScreenGroupChange(const std::string& trigger, 226 const sptr<ScreenInfo>& screenInfo, ScreenGroupChangeEvent groupEvent); 227 void OnScreenGroupChange(const std::string& trigger, 228 const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent groupEvent); 229 void OnScreenshot(sptr<ScreenshotInfo> info); 230 bool IsMultiScreenCollaboration(); 231 bool HasCastEngineOrPhyMirror(const std::vector<ScreenId>& screenIdsToExclude); 232 void HandlePhysicalMirrorConnect(sptr<ScreenSession> screenSession, bool phyMirrorEnable); 233 sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId) override; 234 sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId, int32_t width, int32_t height, Rotation rotation) override; 235 DMError HasImmersiveWindow(ScreenId screenId, bool& immersive) override; 236 void SetLowTemp(LowTempMode lowTemp); 237 238 /** 239 * On/Off screen 240 */ 241 bool WakeUpBegin(PowerStateChangeReason reason) override; 242 bool WakeUpEnd() override; 243 bool SuspendBegin(PowerStateChangeReason reason) override; 244 bool SuspendEnd() override; 245 void BlockScreenOnByCV(void); 246 void BlockScreenOffByCV(void); 247 bool BlockScreenWaitPictureFrameByCV(bool isStartDream); 248 bool BlockSetDisplayState(void); 249 bool IsScreenLockSuspend(void); 250 bool IsPreBrightAuthFail(void); 251 void ScreenOffCVNotify(void); 252 bool SetDisplayState(DisplayState state) override; 253 bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason) override; 254 ScreenPowerState GetScreenPower(ScreenId screenId) override; 255 void NotifyDisplayEvent(DisplayEvent event) override; 256 bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status, PowerStateChangeReason reason); 257 bool TryToCancelScreenOff() override; 258 259 void DisablePowerOffRenderControl(ScreenId screenId) override; 260 bool SetVirtualScreenStatus(ScreenId screenId, VirtualScreenStatus screenStatus) override; 261 sptr<ScreenSession> GetOrCreateFakeScreenSession(sptr<ScreenSession> screenSession); 262 void InitFakeScreenSession(sptr<ScreenSession> screenSession); 263 264 // Fold Screen 265 void SetFoldDisplayMode(const FoldDisplayMode displayMode) override; 266 DMError SetFoldDisplayModeInner(const FoldDisplayMode displayMode, std::string reason = ""); 267 DMError SetFoldDisplayModeFromJs(const FoldDisplayMode displayMode, std::string reason = "") override; 268 void SetDisplayNodeScreenId(ScreenId screenId, ScreenId displayNodeScreenId); 269 270 void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, 271 float pivotX, float pivotY) override; 272 273 void SetFoldStatusLocked(bool locked) override; 274 DMError SetFoldStatusLockedFromJs(bool locked) override; 275 void SetFoldStatusExpandAndLocked(bool locked) override; 276 277 FoldDisplayMode GetFoldDisplayMode() override; 278 279 bool IsFoldable() override; 280 bool IsCaptured() override; 281 282 FoldStatus GetFoldStatus() override; 283 SuperFoldStatus GetSuperFoldStatus() override; 284 float GetSuperRotation() override; 285 void SetLandscapeLockStatus(bool isLocked) override; 286 bool GetTentMode(); 287 bool IsLapTopLidOpen() const; 288 void SetLapTopLidOpenStatus(bool isLapTopLidOpen); 289 ExtendScreenConnectStatus GetExtendScreenConnectStatus() override; 290 bool GetIsExtendScreenConnected(); 291 void SetIsExtendScreenConnected(bool isExtendScreenConnected); 292 void HandleExtendScreenConnect(ScreenId screenId); 293 void HandleExtendScreenDisconnect(ScreenId screenId); 294 bool GetIsFoldStatusLocked(); 295 void SetIsFoldStatusLocked(bool isFoldStatusLocked); 296 bool GetIsLandscapeLockStatus(); 297 void SetIsLandscapeLockStatus(bool isLandscapeLockStatus); 298 bool GetIsOuterOnlyMode(); 299 void SetIsOuterOnlyMode(bool isOuterOnlyMode); 300 bool GetIsOuterOnlyModeBeforePowerOff(); 301 void SetIsOuterOnlyModeBeforePowerOff(bool isOuterOnlyModeBeforePowerOff); 302 void OnVerticalChangeBoundsWhenSwitchUser(sptr<ScreenSession> screenSession); 303 304 bool SetScreenPower(ScreenPowerStatus status, PowerStateChangeReason reason); 305 void SetScreenPowerForFold(ScreenPowerStatus status); 306 void SetScreenPowerForFold(ScreenId screenId, ScreenPowerStatus status); 307 void TriggerDisplayModeUpdate(FoldDisplayMode targetDisplayMode); 308 void CallRsSetScreenPowerStatusSync(ScreenId screenId, ScreenPowerStatus status); 309 void CallRsSetScreenPowerStatusSyncForFold(ScreenPowerStatus status); 310 void TryToRecoverFoldDisplayMode(ScreenPowerStatus status); 311 312 void SetKeyguardDrawnDoneFlag(bool flag); 313 314 sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion() override; 315 DMError GetLiveCreaseRegion(FoldCreaseRegion& region) override; 316 317 void TriggerFoldStatusChange(FoldStatus foldStatus); 318 void NotifyFoldStatusChanged(FoldStatus foldStatus); 319 void NotifyFoldAngleChanged(std::vector<float> foldAngles); 320 int NotifyFoldStatusChanged(const std::string& statusParam); 321 void NotifyDisplayModeChanged(FoldDisplayMode displayMode); 322 void NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo>& info) override; 323 void NotifyScreenMagneticStateChanged(bool isMagneticState); 324 void OnTentModeChanged(int tentType, int32_t hall = -1); 325 void RegisterSettingDpiObserver(); 326 void RegisterSettingRotationObserver(); 327 OnConnect(ScreenId screenId)328 void OnConnect(ScreenId screenId) override {} OnDisconnect(ScreenId screenId)329 void OnDisconnect(ScreenId screenId) override {} 330 void OnPropertyChange(const ScreenProperty& newProperty, ScreenPropertyChangeReason reason, 331 ScreenId screenId) override; 332 void OnPowerStatusChange(DisplayPowerEvent event, EventStatus status, 333 PowerStateChangeReason reason) override; 334 void OnSensorRotationChange(float sensorRotation, ScreenId screenId) override; 335 void OnHoverStatusChange(int32_t hoverStatus, bool needRotate, ScreenId screenId) override; 336 void OnScreenOrientationChange(float screenOrientation, ScreenId screenId) override; 337 void OnScreenRotationLockedChange(bool isLocked, ScreenId screenId) override; 338 void OnCameraBackSelfieChange(bool isCameraBackSelfie, ScreenId screenId) override; 339 340 void SetHdrFormats(ScreenId screenId, sptr<ScreenSession>& session); 341 void SetColorSpaces(ScreenId screenId, sptr<ScreenSession>& session); 342 void SetSupportedRefreshRate(sptr<ScreenSession>& session); 343 void SetClient(const sptr<IScreenSessionManagerClient>& client) override; 344 ScreenProperty GetScreenProperty(ScreenId screenId) override; 345 std::shared_ptr<RSDisplayNode> GetDisplayNode(ScreenId screenId) override; 346 void UpdateScreenRotationProperty(ScreenId screenId, const RRect& bounds, float rotation, 347 ScreenPropertyChangeType screenPropertyChangeType, bool isSwitchUser = false) override; 348 void UpdateScreenRotationPropertyForRs(sptr<ScreenSession>& screenSession, 349 ScreenPropertyChangeType screenPropertyChangeType, const RRect& bounds, float rotation, bool isSwitchUser); 350 void UpdateScreenDirectionInfo(ScreenId screenId, const ScreenDirectionInfo& directionInfo, 351 ScreenPropertyChangeType screenPropertyChangeType, const RRect& bounds) override; 352 uint32_t GetCurvedCompressionArea() override; 353 ScreenProperty GetPhyScreenProperty(ScreenId screenId) override; 354 void SetScreenPrivacyState(bool hasPrivate) override; 355 void SetPrivacyStateByDisplayId(DisplayId id, bool hasPrivate) override; 356 void SetScreenPrivacyWindowList(DisplayId id, std::vector<std::string> privacyWindowList) override; 357 void UpdateAvailableArea(ScreenId screenId, DMRect area) override; 358 void UpdateSuperFoldAvailableArea(ScreenId screenId, DMRect bArea, DMRect cArea) override; 359 void UpdateSuperFoldExpandAvailableArea(ScreenId screenId, DMRect area) override; 360 int32_t SetScreenOffDelayTime(int32_t delay) override; 361 int32_t SetScreenOnDelayTime(int32_t delay) override; 362 DMError GetAvailableArea(DisplayId displayId, DMRect& area) override; 363 DMError GetExpandAvailableArea(DisplayId displayId, DMRect& area) override; 364 void NotifyAvailableAreaChanged(DMRect area, DisplayId displayId); 365 void NotifyFoldToExpandCompletion(bool foldToExpand) override; 366 void NotifyScreenConnectCompletion(ScreenId screenId) override; 367 void RecordEventFromScb(std::string description, bool needRecordEvent) override; 368 void SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition) override; 369 bool GetSnapshotArea(Media::Rect &rect, DmErrorCode* errorCode, ScreenId &screenId); 370 int32_t GetCameraStatus(); 371 int32_t GetCameraPosition(); IsCameraBackSelfie()372 bool IsCameraBackSelfie() { return isCameraBackSelfie_; }; 373 void UpdateCameraBackSelfie(bool isCameraBackSelfie); 374 void SetScreenCorrection(); 375 void ReportFoldDisplayTime(uint64_t screenId, int64_t rsFirstFrameTime); 376 void RegisterFirstFrameCommitCallback(); 377 void SetForceCloseHdr(ScreenId screenId, bool isForceCloseHdr) override; 378 DMError SetScreenPrivacyWindowTagSwitch(ScreenId screenId, const std::vector<std::string>& privacyWindowTag, 379 bool enable) override; 380 381 VirtualScreenFlag GetVirtualScreenFlag(ScreenId screenId) override; 382 DMError SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag) override; 383 384 DeviceScreenConfig GetDeviceScreenConfig() override; 385 DMError SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval) override; 386 void SetVirtualScreenBlackList(ScreenId screenId, std::vector<uint64_t>& windowIdList, 387 std::vector<uint64_t> surfaceIdList = {}, std::vector<uint8_t> typeBlackList = {}) override; 388 void SetVirtualDisplayMuteFlag(ScreenId screenId, bool muteFlag) override; 389 // notify scb virtual screen change 390 void OnVirtualScreenChange(ScreenId screenId, ScreenEvent screenEvent); 391 DMError VirtualScreenUniqueSwitch(const std::vector<ScreenId>& screenIds); 392 void FixPowerStatus(); 393 void FoldScreenPowerInit(); 394 DMError ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy) override; 395 DMError ResetAllFreezeStatus() override; 396 397 void ReportFoldStatusToScb(std::vector<std::string>& screenFoldInfo); 398 std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution() override; 399 400 DMError GetDisplayCapability(std::string& capabilitInfo) override; 401 nlohmann::ordered_json GetCapabilityJson(FoldStatus foldStatus, FoldDisplayMode displayMode, 402 std::vector<std::string> rotation, std::vector<std::string> orientation); 403 DMError GetSecondaryDisplayCapability(std::string& capabilitInfo); 404 DMError GetFoldableDeviceCapability(std::string& capabilitInfo); 405 DMError GetSuperFoldCapability(std::string& capabilitInfo); 406 407 void OnScreenExtendChange(ScreenId mainScreenId, ScreenId extendScreenId) override; 408 void OnSuperFoldStatusChange(ScreenId screenId, SuperFoldStatus superFoldStatus) override; 409 void OnSecondaryReflexionChange(ScreenId screenId, bool isSecondaryReflexion) override; 410 void OnExtendScreenConnectStatusChange(ScreenId screenId, 411 ExtendScreenConnectStatus extendScreenConnectStatus) override; 412 void OnBeforeScreenPropertyChange(FoldStatus foldStatus) override; 413 void SetDefaultScreenId(ScreenId defaultId); 414 sptr<IScreenSessionManagerClient> GetClientProxy(); 415 void SetClientProxy(const sptr<IScreenSessionManagerClient>& client); 416 void NotifyCastWhenScreenConnectChange(bool isConnected); 417 void NotifyCastWhenSwitchScbNode(); 418 void MultiScreenModeChange(const std::string& mainScreenId, const std::string& secondaryScreenId, 419 const std::string& secondaryScreenMode); 420 void SwitchScrollParam(FoldDisplayMode displayMode); 421 void OnScreenChange(ScreenId screenId, ScreenEvent screenEvent, 422 ScreenChangeReason reason = ScreenChangeReason::DEFAULT); 423 void OnScreenChangeForPC(ScreenId screenId, ScreenEvent screenEvent, ScreenChangeReason reason); 424 void OnScreenChangeDefault(ScreenId screenId, ScreenEvent screenEvent, ScreenChangeReason reason); 425 void OnFoldScreenChange(sptr<ScreenSession>& screenSession); 426 void OnFoldStatusChange(bool isSwitching); 427 void SetCoordinationFlag(bool isCoordinationFlag); 428 bool GetCoordinationFlag(void); 429 DMError SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate, 430 uint32_t& actualRefreshRate) override; 431 void OnScreenModeChange(ScreenModeChangeEvent screenModeChangeEvent) override; 432 433 void SetLastScreenMode(sptr<ScreenSession> firstSession, sptr<ScreenSession> secondarySession); 434 /* 435 * multi user 436 */ 437 void SwitchUser() override; 438 void SetDefaultMultiScreenModeWhenSwitchUser() override; 439 void SwitchScbNodeHandle(int32_t userId, int32_t newScbPid, bool coldBoot); 440 void HotSwitch(int32_t newUserId, int32_t newScbPid); 441 void AddScbClientDeathRecipient(const sptr<IScreenSessionManagerClient>& scbClient, int32_t scbPid); 442 void ScbClientDeathCallback(int32_t deathScbPid); 443 void ScbStatusRecoveryWhenSwitchUser(std::vector<int32_t> oldScbPids, int32_t newScbPid); 444 void RecoverMultiScreenModeWhenSwitchUser(std::vector<int32_t> oldScbPids, int32_t newScbPid); 445 void FlushDisplayNodeWhenSwtichUser(std::vector<int32_t> oldScbPids, int32_t newScbPid, 446 sptr<ScreenSession> screenSession); 447 int32_t GetCurrentUserId(); 448 449 std::shared_ptr<Media::PixelMap> GetScreenCapture(const CaptureOption& captureOption, 450 DmErrorCode* errorCode = nullptr) override; 451 void OnScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) override; 452 sptr<DisplayInfo> GetPrimaryDisplayInfo() override; 453 std::shared_ptr<Media::PixelMap> GetDisplaySnapshotWithOption(const CaptureOption& captureOption, 454 DmErrorCode* errorCode) override; 455 std::vector<std::shared_ptr<Media::PixelMap>> GetDisplayHDRSnapshotWithOption(const CaptureOption& captureOption, 456 DmErrorCode& errorCode) override; 457 ScreenCombination GetScreenCombination(ScreenId screenId) override; 458 DMError SetScreenSkipProtectedWindow(const std::vector<ScreenId>& screenIds, bool isEnable) override; 459 void UpdateValidArea(ScreenId screenId, uint32_t validWidth, uint32_t validHeight); 460 bool GetIsRealScreen(ScreenId screenId) override; 461 void UnregisterSettingWireCastObserver(ScreenId screenId); 462 void RegisterSettingWireCastObserver(sptr<ScreenSession>& screenSession); 463 SessionOption GetSessionOption(sptr<ScreenSession> screenSession); 464 SessionOption GetSessionOption(sptr<ScreenSession> screenSession, ScreenId screenId); 465 virtual DMError SetSystemKeyboardStatus(bool isTpKeyboardOn = false) override; 466 467 sptr<ScreenSession> GetPhysicalScreenSession(ScreenId screenId) const; 468 sptr<ScreenSession> GetScreenSessionByRsId(ScreenId rsScreenId); 469 void NotifyExtendScreenCreateFinish() override; 470 void NotifyExtendScreenDestroyFinish() override; 471 void NotifyCreatedScreen(sptr<ScreenSession> screenSession); 472 void UpdateScreenIdManager(sptr<ScreenSession>& innerScreen, sptr<ScreenSession>& externalScreen); 473 std::string DumperClientScreenSessions(); 474 void SetMultiScreenModeChangeTracker(std::string changeProc); 475 void SetRSScreenPowerStatus(ScreenId screenId, ScreenPowerStatus status); 476 void NotifyScreenMaskAppear() override; 477 bool IsSystemSleep(); 478 void SwitchSubscriberInit(); 479 bool GetKeyboardState() override; 480 DMError GetScreenAreaOfDisplayArea(DisplayId displayId, const DMRect& displayArea, 481 ScreenId& screenId, DMRect& screenArea) override; 482 DMError SetVirtualScreenAutoRotation(ScreenId screenId, bool enable) override; 483 bool SetScreenOffset(ScreenId screenId, float offsetX, float offsetY); 484 bool SynchronizePowerStatus(ScreenPowerState state) override; 485 void RegisterSettingDuringCallStateObserver(); 486 void UpdateDuringCallState(); 487 void SetDuringCallState(bool value); 488 std::shared_ptr<TaskScheduler> GetPowerTaskScheduler() const; 489 bool GetCancelSuspendStatus() const; 490 void RemoveScreenCastInfo(ScreenId screenId); 491 492 protected: 493 ScreenSessionManager(); 494 virtual ~ScreenSessionManager() = default; 495 496 private: 497 void OnStart() override; 498 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 499 void Init(); 500 void LoadScreenSceneXml(); 501 void ConfigureScreenScene(); 502 void ConfigureDpi(); 503 void ConfigureCastParams(); 504 void ConfigureWaterfallDisplayCompressionParams(); 505 void ConfigureScreenSnapshotParams(); 506 void RegisterScreenChangeListener(); 507 void RegisterFoldNotSwitchingListener(); 508 void RegisterRefreshRateChangeListener(); 509 void OnHgmRefreshRateChange(uint32_t refreshRate); 510 sptr<ScreenSession> GetOrCreateScreenSession(ScreenId screenId); 511 void CreateScreenProperty(ScreenId screenId, ScreenProperty& property); 512 void InitScreenProperty(ScreenId screenId, RSScreenModeInfo& screenMode, 513 RSScreenCapability& screenCapability, ScreenProperty& property); 514 RRect GetScreenBounds(ScreenId screenId, RSScreenModeInfo& screenMode); 515 void InitSecondaryDisplayPhysicalParams(); 516 ScreenId GetPhyScreenId(ScreenId screenId); 517 void UpdateCoordinationRefreshRate(uint32_t refreshRate); 518 void GetInternalWidth(); 519 void InitExtendScreenDensity(sptr<ScreenSession> session, ScreenProperty property); 520 void InitExtendScreenProperty(ScreenId screenId, sptr<ScreenSession> session, ScreenProperty property); 521 sptr<ScreenSession> GetScreenSessionInner(ScreenId screenId, ScreenProperty property); 522 sptr<ScreenSession> CreatePhysicalMirrorSessionInner(ScreenId screenId, ScreenId defaultScreenId, 523 ScreenProperty property); 524 525 /* physical screen session */ 526 sptr<ScreenSession> GetOrCreatePhysicalScreenSession(ScreenId screenId); 527 sptr<ScreenSession> GetPhysicalScreenSessionInner(ScreenId screenId, ScreenProperty property); 528 sptr<ScreenSession> CreateFakePhysicalMirrorSessionInner(ScreenId screenId, ScreenId defaultScreenId, 529 ScreenProperty property); 530 sptr<ScreenSession> GetFakePhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property); 531 sptr<ScreenSession> GetPhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property); 532 void FreeDisplayMirrorNodeInner(const sptr<ScreenSession> mirrorSession); 533 void MirrorSwitchNotify(ScreenId screenId); 534 ScreenId GetDefaultScreenId(); 535 void AddVirtualScreenDeathRecipient(const sptr<IRemoteObject>& displayManagerAgent, ScreenId smsScreenId); 536 void SendCastEvent(const bool &isPlugIn); 537 void PhyMirrorConnectWakeupScreen(); 538 bool GetIsCurrentInUseById(ScreenId screenId); 539 void GetAndMergeEdidInfo(sptr<ScreenSession> screenSession); 540 std::string ConvertEdidToString(const struct BaseEdid edidData); 541 bool RecoverRestoredMultiScreenMode(sptr<ScreenSession> screenSession); 542 bool CheckMultiScreenInfoMap(std::map<std::string, MultiScreenInfo> multiScreenInfoMap, 543 const std::string& serialNumber); 544 void SetExtendedScreenFallbackPlan(ScreenId screenId); 545 void SetExtendedScreenFallbackPlanEvent(int32_t res); 546 void SetInnerScreenFallbackPlan(sptr<ScreenSession> screenSession); 547 int32_t GetCurrentInUseScreenNumber(); 548 void ReportHandleScreenEvent(ScreenEvent screenEvent, ScreenCombination screenCombination); 549 void HandleScreenConnectEvent(sptr<ScreenSession> screenSession, ScreenId screenId, ScreenEvent screenEvent); 550 void HandleScreenDisconnectEvent(sptr<ScreenSession> screenSession, ScreenId screenId, ScreenEvent screenEvent); 551 void HandlePhysicalMirrorDisconnect(sptr<ScreenSession> screenSession, ScreenId screenId, bool phyMirrorEnable); 552 void HandleMapWhenScreenDisconnect(ScreenId screenId); 553 void HandlePCScreenDisconnect(sptr<ScreenSession>& screenSession); 554 void HandleMainScreenDisconnect(sptr<ScreenSession>& screenSession); 555 void ResetInternalScreenSession(sptr<ScreenSession>& innerScreen, sptr<ScreenSession>& externalScreen); 556 ScreenRotation ConvertOffsetToCorrectRotation(int32_t phyOffset); 557 Rotation ConvertIntToRotation(int32_t rotation); 558 void MultiScreenModeChange(ScreenId mainScreenId, ScreenId secondaryScreenId, const std::string& operateType); 559 void OperateModeChange(ScreenId mainScreenId, ScreenId secondaryScreenId, sptr<ScreenSession>& firstSession, 560 sptr<ScreenSession>& secondarySession, const std::string& operateMode); 561 void SetClientInner(); 562 void RecoverMultiScreenMode(sptr<ScreenSession> screenSession); 563 void GetCurrentScreenPhyBounds(float& phyWidth, float& phyHeight, bool& isReset, const ScreenId& screenid); 564 void SetPhysicalRotationClientInner(ScreenId screenId, int rotation); 565 sptr<ScreenSession> GetInternalScreenSession(); 566 void ExitOuterOnlyMode(ScreenId mainScreenId, ScreenId secondaryScreenId, MultiScreenMode screenMode); 567 void AdaptSuperHorizonalBoot(sptr<ScreenSession> screenSession, ScreenId screenId); 568 569 void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 570 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type); 571 void NotifyCaptureStatusChanged(); 572 void NotifyCaptureStatusChanged(bool IsCaptured); 573 DMError DoMakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds, 574 DMRect mainScreenRegion, ScreenId& screenGroupId); 575 bool OnMakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint); 576 bool OnRemoteDied(const sptr<IRemoteObject>& agent); 577 std::string TransferTypeToString(ScreenType type) const; 578 std::string TransferPropertyChangeTypeToString(ScreenPropertyChangeType type) const; 579 void CheckAndSendHiSysEvent(const std::string& eventName, const std::string& bundleName) const; 580 void HandlerSensor(ScreenPowerStatus status, PowerStateChangeReason reason); 581 void UnregisterInHandlerSensorWithPowerOff(PowerStateChangeReason reason); 582 bool GetPowerStatus(ScreenPowerState state, PowerStateChangeReason reason, ScreenPowerStatus& status); 583 DMError CheckDisplayMangerAgentTypeAndPermission( 584 const sptr<IDisplayManagerAgent>& displayManagerAgent, DisplayManagerAgentType type); 585 void SetMultiScreenDefaultRelativePosition(); 586 void SetRelativePositionForDisconnect(MultiScreenPositionOptions defaultScreenOptions); 587 int Dump(int fd, const std::vector<std::u16string>& args) override; 588 sptr<DisplayInfo> HookDisplayInfoByUid(sptr<DisplayInfo> displayInfo, const sptr<ScreenSession>& screenSession); 589 DisplayId GetFakeDisplayId(sptr<ScreenSession> screenSession); 590 DMError SetVirtualScreenSecurityExemption(ScreenId screenId, uint32_t pid, 591 std::vector<uint64_t>& windowIdList) override; 592 void GetInternalAndExternalSession(sptr<ScreenSession>& internalSession, sptr<ScreenSession>& externalSession); 593 void AddPermissionUsedRecord(const std::string& permission, int32_t successCount, int32_t failCount); 594 std::shared_ptr<RSDisplayNode> GetDisplayNodeByDisplayId(DisplayId displayId); 595 void RefreshMirrorScreenRegion(ScreenId screenId); 596 void DestroyExtendVirtualScreen(); 597 DMError IsPhysicalExtendScreenInUse(ScreenId mainScreenId, ScreenId secondaryScreenId); 598 void CreateExtendVirtualScreen(ScreenId screenId); 599 void SetMultiScreenModeInner(ScreenId mainScreenId, ScreenId secondaryScreenId, 600 MultiScreenMode screenMode); 601 std::vector<std::shared_ptr<Media::PixelMap>> GetScreenHDRSnapshot(DisplayId displayId, bool isUseDma = false, 602 bool isCaptureFullOfScreen = false, const std::vector<NodeId>& surfaceNodesList = {}); 603 604 void IsEnableRegionRotation(sptr<ScreenSession> screenSession); 605 void CalculateXYPosition(sptr<ScreenSession> firstScreenSession, 606 sptr<ScreenSession> secondaryScreenSession = nullptr); 607 void CalculateSecondryXYPosition(sptr<ScreenSession> firstScreenSession, 608 609 sptr<ScreenSession> secondaryScreenSession); 610 bool IsSpecialApp(); 611 void SetMultiScreenRelativePositionInner(sptr<ScreenSession>& firstScreenSession, 612 sptr<ScreenSession>& secondScreenSession, MultiScreenPositionOptions mainScreenOptions, 613 MultiScreenPositionOptions secondScreenOption); 614 void HandleSuperFoldStatusLocked(bool isLocked); 615 void CalculateRotatedDisplay(Rotation rotation, const DMRect& screenRegion, DMRect& displayRegion, DMRect& displayArea); 616 void CalculateScreenArea(const DMRect& displayRegion, const DMRect& displayArea, const DMRect& screenRegion, DMRect& screenArea); 617 void DisconnectScreenIfScreenInfoNull(sptr<ScreenSession>& screenSession); 618 void RecoverDefaultScreenModeInner(ScreenId innerRsId, ScreenId externalRsId); 619 void SetDefaultScreenModeWhenCreateMirror(sptr<ScreenSession>& screenSession); 620 #ifdef DEVICE_STATUS_ENABLE 621 void SetDragWindowScreenId(ScreenId screenId, ScreenId displayNodeScreenId); 622 #endif // DEVICE_STATUS_ENABLE 623 void ShowFoldStatusChangedInfo(int errCode, std::string& dumpInfo); 624 void SetMirrorScreenIds(std::vector<ScreenId>& mirrorScreenIds); 625 bool IsFreezed(const int32_t& agentPid, const DisplayManagerAgentType& agentType); 626 void NotifyUnfreezed(const std::set<int32_t>& unfreezedPidList, const sptr<ScreenSession>& screenSession); 627 void NotifyUnfreezedAgents(const int32_t& pid, const std::set<int32_t>& unfreezedPidList, 628 const std::set<DisplayManagerAgentType>& pidAgentTypes, const sptr<ScreenSession>& screenSession); 629 int NotifyPowerEventForDualDisplay(DisplayPowerEvent event, EventStatus status, 630 PowerStateChangeReason reason); 631 bool IsExtendMode(); 632 bool IsScreenCasting(); 633 bool GetPcStatus() const; 634 void SetPcStatus(bool isPc); 635 const std::set<std::string> g_packageNames_ {}; 636 637 /** 638 * On/Off screen 639 */ 640 void SetGotScreenOffAndWakeUpBlock(); 641 void WakeUpPictureFrameBlock(DisplayEvent event); 642 643 class ScreenIdManager { 644 friend class ScreenSessionGroup; 645 public: 646 ScreenIdManager() = default; 647 ~ScreenIdManager() = default; 648 WM_DISALLOW_COPY_AND_MOVE(ScreenIdManager); 649 ScreenId CreateAndGetNewScreenId(ScreenId rsScreenId); 650 void UpdateScreenId(ScreenId rsScreenId, ScreenId smsScreenId); 651 bool DeleteScreenId(ScreenId smsScreenId); 652 bool HasRsScreenId(ScreenId smsScreenId) const; 653 bool ConvertToRsScreenId(ScreenId, ScreenId&) const; 654 ScreenId ConvertToRsScreenId(ScreenId) const; 655 bool ConvertToSmsScreenId(ScreenId, ScreenId&) const; 656 ScreenId ConvertToSmsScreenId(ScreenId) const; 657 658 private: 659 std::atomic<ScreenId> smsScreenCount_ { 1000 }; 660 std::map<ScreenId, ScreenId> rs2SmsScreenIdMap_; 661 std::map<ScreenId, ScreenId> sms2RsScreenIdMap_; 662 mutable std::shared_mutex screenIdMapMutex_; 663 }; 664 665 EventTracker screenEventTracker_; 666 RSInterfaces& rsInterface_; 667 std::shared_ptr<TaskScheduler> taskScheduler_; 668 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler_; 669 670 /* 671 * multi user 672 */ 673 std::mutex oldScbPidsMutex_; 674 std::condition_variable scbSwitchCV_; 675 int32_t currentUserId_ { 0 }; 676 int32_t currentUserIdForSettings_ { 0 }; 677 int32_t currentScbPId_ { -1 }; 678 int32_t switchId_ { -1 }; 679 std::vector<int32_t> oldScbPids_ {}; 680 std::map<int32_t, sptr<IScreenSessionManagerClient>> clientProxyMap_; 681 FoldDisplayMode oldScbDisplayMode_ = FoldDisplayMode::UNKNOWN; 682 683 sptr<IScreenSessionManagerClient> clientProxy_; 684 std::mutex clientProxyMutex_; // above guarded by clientProxyMutex_ 685 ClientAgentContainer<IDisplayManagerAgent, DisplayManagerAgentType> dmAgentContainer_; 686 DeviceScreenConfig deviceScreenConfig_; 687 std::mutex allDisplayPhysicalResolutionMutex_; 688 std::vector<DisplayPhysicalResolution> allDisplayPhysicalResolution_ {}; 689 std::vector<uint32_t> screenParams_ {}; 690 std::map<int32_t, std::set<DisplayManagerAgentType>> pidAgentTypeMap_; 691 std::vector<float> lastFoldAngles_ {}; 692 sptr<DisplayChangeInfo> lastDisplayChangeInfo_; 693 ScreenChangeEvent lastScreenChangeEvent_ = ScreenChangeEvent::UNKNOWN; 694 std::mutex lastStatusUpdateMutex_; 695 696 mutable std::recursive_mutex screenSessionMapMutex_; 697 std::mutex screenAgentMapMutex_; 698 std::map<ScreenId, sptr<ScreenSession>> screenSessionMap_; 699 mutable std::recursive_mutex physicalScreenSessionMapMutex_; 700 std::map<ScreenId, sptr<ScreenSession>> physicalScreenSessionMap_; 701 std::recursive_mutex mutex_; 702 std::recursive_mutex displayInfoMutex_; 703 std::shared_mutex hookInfoMutex_; 704 std::mutex shareProtectMutex_; 705 706 ScreenId defaultScreenId_ = SCREEN_ID_INVALID; 707 ScreenIdManager screenIdManager_; 708 709 std::atomic<ScreenId> defaultRsScreenId_ { SCREEN_ID_INVALID }; 710 std::map<sptr<IRemoteObject>, std::vector<ScreenId>> screenAgentMap_; 711 std::map<ScreenId, sptr<ScreenSessionGroup>> smsScreenGroupMap_; 712 std::map<uint32_t, DMHookInfo> displayHookMap_; 713 714 bool userSwitching_ = false; 715 bool isAutoRotationOpen_ = false; 716 bool isExpandCombination_ = false; 717 bool isScreenShot_ = false; 718 bool isCoordinationFlag_ = false; 719 bool isFoldScreenOuterScreenReady_ = false; 720 bool isCameraBackSelfie_ = false; 721 bool isDeviceShutDown_ = false; 722 bool needWaitAvailableArea_ = false; 723 uint32_t hdmiScreenCount_ = 0; 724 uint32_t virtualScreenCount_ = 0; 725 uint32_t currentExpandScreenCount_ = 0; 726 int32_t connectScreenNumber_ = 0; 727 int32_t connectScreenGroupNumber_ = 0; 728 sptr<AgentDeathRecipient> deathRecipient_ { nullptr }; 729 730 sptr<SessionDisplayPowerController> sessionDisplayPowerController_; 731 sptr<ScreenCutoutController> screenCutoutController_; 732 sptr<FoldScreenController> foldScreenController_; 733 734 bool isDensityDpiLoad_ = false; 735 float densityDpi_ { 1.0f }; 736 float subDensityDpi_ { 1.0f }; 737 std::atomic<uint32_t> cachedSettingDpi_ {0}; 738 float pcModeDpi_ { 1.0f }; 739 740 uint32_t defaultDpi {0}; 741 uint32_t extendDefaultDpi_ {0}; 742 uint32_t defaultDeviceRotationOffset_ { 0 }; 743 std::atomic<ExtendScreenConnectStatus> extendScreenConnectStatus_ = ExtendScreenConnectStatus::UNKNOWN; 744 bool isExtendScreenConnected_ = false; 745 std::atomic<bool> isOuterOnlyMode_ = false; 746 std::atomic<bool> isOuterOnlyModeBeforePowerOff_ = false; 747 std::atomic<bool> isFoldStatusLocked_ = false; 748 std::atomic<bool> isLandscapeLockStatus_ = false; 749 std::atomic<bool> isLapTopLidOpen_ = true; 750 751 /** 752 * On/Off screen 753 */ 754 bool isMultiScreenCollaboration_ = false; 755 bool screenPrivacyStates = false; 756 bool keyguardDrawnDone_ = true; 757 bool needScreenOnWhenKeyguardNotify_ = false; 758 bool gotScreenOffNotify_ = false; 759 bool needScreenOffNotify_ = false; 760 bool dozeNotifyFinish_ = false; 761 bool pictureFrameReady_ = false; 762 bool pictureFrameBreak_ = false; 763 764 std::mutex screenOnMutex_; 765 std::condition_variable screenOnCV_; 766 std::mutex screenOffMutex_; 767 std::condition_variable screenOffCV_; 768 std::mutex screenWaitPictureFrameMutex_; 769 std::condition_variable screenWaitPictureFrameCV_; 770 int32_t screenOffDelay_ {0}; 771 int32_t screenOnDelay_ {0}; 772 773 std::vector<ScreenId> mirrorScreenIds_; 774 std::mutex mirrorScreenIdsMutex_; 775 std::mutex snapBypickerMutex_; 776 std::mutex switchUserMutex_; 777 std::condition_variable switchUserCV_; 778 std::mutex screenPowerMutex_; 779 std::mutex screenChangeMutex_; 780 std::mutex screenMaskMutex_; 781 std::condition_variable screenMaskCV_; 782 std::mutex displayAddMutex_; 783 std::mutex screenModeChangeMutex_; 784 std::condition_variable displayAddCV_; 785 mutable std::mutex setPcStatusMutex_; 786 787 std::mutex freezedPidListMutex_; 788 std::set<int32_t> freezedPidList_; 789 790 std::atomic<PowerStateChangeReason> prePowerStateChangeReason_ = 791 PowerStateChangeReason::STATE_CHANGE_REASON_UNKNOWN; 792 std::atomic<PowerStateChangeReason> lastWakeUpReason_ = PowerStateChangeReason::STATE_CHANGE_REASON_INIT; 793 std::atomic<PowerStateChangeReason> currentWakeUpReason_ = PowerStateChangeReason::STATE_CHANGE_REASON_INIT; 794 std::atomic<bool> isScreenLockSuspend_ = false; 795 std::atomic<bool> gotScreenlockFingerprint_ = false; 796 std::atomic<bool> isPhyScreenConnected_ = false; 797 std::atomic<ScreenPowerStatus> lastPowerForAllStatus_ = ScreenPowerStatus::INVALID_POWER_STATUS; 798 std::atomic<ScreenId> lastScreenId_ = SCREEN_ID_INVALID; 799 int32_t cameraStatus_ = {0}; 800 int32_t cameraPosition_ = {0}; 801 PowerStateChangeReason powerStateChangeReason_ = PowerStateChangeReason::STATE_CHANGE_REASON_UNKNOWN; 802 803 // Fold Screen 804 std::map<ScreenId, ScreenProperty> phyScreenPropMap_; 805 mutable std::recursive_mutex phyScreenPropMapMutex_; 806 static void BootFinishedCallback(const char *key, const char *value, void *context); 807 std::function<void()> foldScreenPowerInit_ = nullptr; 808 void HandleFoldScreenPowerInit(); 809 void SetFoldScreenPowerInit(std::function<void()> foldScreenPowerInit); 810 void SetDpiFromSettingData(); 811 void SetRotateLockedFromSettingData(); 812 void NotifyClientProxyUpdateFoldDisplayMode(FoldDisplayMode displayMode); 813 void UpdateDisplayScaleState(ScreenId screenId); 814 void SetDisplayScaleInner(ScreenId screenId, const float& scaleX, const float& scaleY, const float& pivotX, 815 const float& pivotY); 816 void CalcDisplayNodeTranslateOnFoldableRotation(sptr<ScreenSession>& session, const float& scaleX, 817 const float& scaleY, const float& pivotX, const float& pivotY, 818 float& translateX, float& translateY); 819 void CalcDisplayNodeTranslateOnPocketFoldRotation(sptr<ScreenSession>& session, const float& scaleX, 820 const float& scaleY, const float& pivotX, const float& pivotY, 821 float& translateX, float& translateY); 822 void CalcDisplayNodeTranslateOnRotation(sptr<ScreenSession>& session, const float& scaleX, const float& scaleY, 823 const float& pivotX, const float& pivotY, float& translateX, 824 float& translateY); 825 void CalcDisplayNodeTranslateOnVerticalScanRotation(const sptr<ScreenSession>& session, 826 const ScaleProperty& scalep, 827 float& translateX, float& translateY); 828 void RegisterApplicationStateObserver(); 829 void SetPostureAndHallSensorEnabled(); 830 bool IsDefaultMirrorMode(ScreenId screenId); 831 void SetCastFromSettingData(); 832 void RegisterCastObserver(std::vector<ScreenId>& mirrorScreenIds); 833 void SetCastPrivacyFromSettingData(); 834 bool SetCastPrivacyToRS(sptr<ScreenSession> screenSession, bool enable); 835 void ExitCoordination(const std::string& reason); 836 void UpdateDisplayState(std::vector<ScreenId> screenIds, DisplayState state); 837 void SetExtendPixelRatio(const float& dpi); 838 void CallRsSetScreenPowerStatusSyncForExtend(const std::vector<ScreenId>& screenIds, ScreenPowerStatus status); 839 void SetRsSetScreenPowerStatusSync(std::vector<ScreenId>& screenIds, ScreenPowerStatus status); 840 DisplayState lastDisplayState_ { DisplayState::UNKNOWN }; 841 bool IsFakeDisplayExist(); 842 DMError DoMakeUniqueScreenOld(const std::vector<ScreenId>& allUniqueScreenIds, std::vector<DisplayId>& displayIds, 843 bool isCallingByThirdParty); 844 bool IsSupportCoordination(); 845 void RegisterSettingExtendScreenDpiObserver(); 846 void SetExtendScreenDpi(); 847 bool HandleSwitchPcMode(); 848 void SwitchModeHandleExternalScreen(bool isSwitchToPcMode); 849 void WaitUpdateAvailableAreaForPc(); 850 851 std::unordered_map<ScreenId, std::pair<ScreenId, ScreenCombination>> screenCastInfoMap_; 852 std::shared_mutex screenCastInfoMapMutex_; 853 bool HasSameScreenCastInfo(ScreenId screenId, ScreenId castScreenId, ScreenCombination screenCombination); 854 void SetScreenCastInfo(ScreenId screenId, ScreenId castScreenId, ScreenCombination screenCombination); 855 void ChangeMirrorScreenConfig(const sptr<ScreenSessionGroup>& group, 856 const DMRect& mainScreenRegion, sptr<ScreenSession>& screen); 857 858 LowTempMode lowTemp_ {LowTempMode::UNKNOWN}; 859 std::mutex lowTempMutex_; 860 std::mutex pcModeSwitchMutex_; 861 std::atomic<DisplayGroupId> displayGroupNum_ { 1 }; 862 863 // Fold Screen duringcall 864 bool duringCallState_ = false; 865 866 private: 867 class ScbClientListenerDeathRecipient : public IRemoteObject::DeathRecipient { 868 public: ScbClientListenerDeathRecipient(int32_t scbPid)869 explicit ScbClientListenerDeathRecipient(int32_t scbPid) 870 : scbPid_(scbPid) 871 {} 872 OnRemoteDied(const wptr<IRemoteObject> & wptrDeath)873 void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override 874 { 875 ScreenSessionManager::GetInstance().ScbClientDeathCallback(scbPid_); 876 } 877 878 private: 879 int32_t scbPid_; 880 }; 881 }; 882 } // namespace OHOS::Rosen 883 884 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_MANAGER_H 885