• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "screen_session_manager_client.h"
17 
18 #include <hitrace_meter.h>
19 #include <iservice_registry.h>
20 #include <system_ability_definition.h>
21 #include <transaction/rs_transaction.h>
22 #include <transaction/rs_interfaces.h>
23 #include "dm_common.h"
24 #include "pipeline/rs_node_map.h"
25 #include "window_manager_hilog.h"
26 
27 namespace OHOS::Rosen {
28 namespace {
29 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenSessionManagerClient" };
30 std::mutex g_instanceMutex;
31 } // namespace
32 
GetInstance()33 ScreenSessionManagerClient& ScreenSessionManagerClient::GetInstance()
34 {
35     std::lock_guard<std::mutex> lock(g_instanceMutex);
36     static sptr<ScreenSessionManagerClient> instance = nullptr;
37     if (instance == nullptr) {
38         instance = new ScreenSessionManagerClient();
39     }
40     return *instance;
41 }
42 
ConnectToServer()43 void ScreenSessionManagerClient::ConnectToServer()
44 {
45     if (screenSessionManager_) {
46         WLOGFI("Success to get screen session manager proxy");
47         return;
48     }
49     auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
50     if (!systemAbilityMgr) {
51         WLOGFE("Failed to get system ability mgr");
52         return;
53     }
54 
55     auto remoteObject = systemAbilityMgr->GetSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID);
56     if (!remoteObject) {
57         WLOGFE("Failed to get display manager service");
58         return;
59     }
60 
61     screenSessionManager_ = iface_cast<IScreenSessionManager>(remoteObject);
62     if (!screenSessionManager_) {
63         WLOGFE("Failed to get screen session manager proxy");
64         return;
65     }
66     screenSessionManager_->SetClient(this);
67 }
68 
RegisterScreenConnectionListener(IScreenConnectionListener * listener)69 void ScreenSessionManagerClient::RegisterScreenConnectionListener(IScreenConnectionListener* listener)
70 {
71     if (listener == nullptr) {
72         WLOGFE("Failed to register screen connection listener, listener is null");
73         return;
74     }
75 
76     screenConnectionListener_ = listener;
77     ConnectToServer();
78     WLOGFI("Success to register screen connection listener");
79 }
80 
81 
CheckIfNeedCennectScreen(ScreenId screenId,ScreenId rsId,const std::string & name)82 bool ScreenSessionManagerClient::CheckIfNeedCennectScreen(ScreenId screenId, ScreenId rsId, const std::string& name)
83 {
84     if (rsId == SCREEN_ID_INVALID) {
85         WLOGFE("rsId is invalid");
86         return false;
87     }
88     if (!screenSessionManager_) {
89         WLOGFE("screenSessionManager_ is nullptr");
90         return false;
91     }
92     if (screenSessionManager_->GetScreenProperty(screenId).GetScreenType() == ScreenType::VIRTUAL) {
93         if (name == "HiCar" || name == "SuperLauncher" || name == "CastEngine") {
94             WLOGFI("HiCar or SuperLauncher or CastEngine, need to connect the screen");
95             return true;
96         } else {
97             WLOGFE("ScreenType is virtual, no need to connect the screen");
98             return false;
99         }
100     }
101     return true;
102 }
103 
OnScreenConnectionChanged(ScreenId screenId,ScreenEvent screenEvent,ScreenId rsId,const std::string & name)104 void ScreenSessionManagerClient::OnScreenConnectionChanged(ScreenId screenId, ScreenEvent screenEvent,
105     ScreenId rsId, const std::string& name)
106 {
107     WLOGFI("screenId: %{public}" PRIu64 " screenEvent: %{public}d rsId: %{public}" PRIu64 " name: %{public}s",
108         screenId, static_cast<int>(screenEvent), rsId, name.c_str());
109     if (screenEvent == ScreenEvent::CONNECTED) {
110         if (!CheckIfNeedCennectScreen(screenId, rsId, name)) {
111             WLOGFE("There is no need to connect the screen");
112             return;
113         }
114         ScreenSessionConfig config = {
115             .screenId = screenId,
116             .rsId = rsId,
117             .name = name,
118         };
119         config.property = screenSessionManager_->GetScreenProperty(screenId);
120         config.displayNode = screenSessionManager_->GetDisplayNode(screenId);
121         sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
122         screenSession->SetScreenCombination(screenSessionManager_->GetScreenCombination(screenId));
123         {
124             std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
125             screenSessionMap_.emplace(screenId, screenSession);
126         }
127         if (screenConnectionListener_) {
128             screenConnectionListener_->OnScreenConnected(screenSession);
129             WLOGFI("screenId: %{public}" PRIu64 " density: %{public}f ", screenId, config.property.GetDensity());
130             screenSession->SetScreenSceneDpi(config.property.GetDensity());
131         }
132         screenSession->Connect();
133         return;
134     }
135     if (screenEvent == ScreenEvent::DISCONNECTED) {
136         auto screenSession = GetScreenSession(screenId);
137         if (!screenSession) {
138             WLOGFE("screenSession is null");
139             return;
140         }
141         screenSession->DestroyScreenScene();
142         if (screenConnectionListener_) {
143             screenConnectionListener_->OnScreenDisconnected(screenSession);
144         }
145         {
146             std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
147             screenSessionMap_.erase(screenId);
148         }
149         screenSession->Disconnect();
150     }
151 }
152 
GetScreenSession(ScreenId screenId) const153 sptr<ScreenSession> ScreenSessionManagerClient::GetScreenSession(ScreenId screenId) const
154 {
155     std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
156     auto iter = screenSessionMap_.find(screenId);
157     if (iter == screenSessionMap_.end()) {
158         WLOGFE("Error found screen session with id: %{public}" PRIu64, screenId);
159         return nullptr;
160     }
161     return iter->second;
162 }
163 
OnPropertyChanged(ScreenId screenId,const ScreenProperty & property,ScreenPropertyChangeReason reason)164 void ScreenSessionManagerClient::OnPropertyChanged(ScreenId screenId,
165     const ScreenProperty& property, ScreenPropertyChangeReason reason)
166 {
167     auto screenSession = GetScreenSession(screenId);
168     if (!screenSession) {
169         WLOGFE("screenSession is null");
170         return;
171     }
172     screenSession->PropertyChange(property, reason);
173 }
174 
OnPowerStatusChanged(DisplayPowerEvent event,EventStatus status,PowerStateChangeReason reason)175 void ScreenSessionManagerClient::OnPowerStatusChanged(DisplayPowerEvent event, EventStatus status,
176     PowerStateChangeReason reason)
177 {
178     std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
179     if (screenSessionMap_.empty()) {
180         WLOGFE("[UL_POWER]screenSessionMap_ is nullptr");
181         return;
182     }
183     auto screenSession = screenSessionMap_.begin()->second;
184     if (!screenSession) {
185         WLOGFE("[UL_POWER]screenSession is null");
186         return;
187     }
188     screenSession->PowerStatusChange(event, status, reason);
189 }
190 
OnSensorRotationChanged(ScreenId screenId,float sensorRotation)191 void ScreenSessionManagerClient::OnSensorRotationChanged(ScreenId screenId, float sensorRotation)
192 {
193     auto screenSession = GetScreenSession(screenId);
194     if (!screenSession) {
195         WLOGFE("screenSession is null");
196         return;
197     }
198     screenSession->SensorRotationChange(sensorRotation);
199 }
200 
OnHoverStatusChanged(ScreenId screenId,int32_t hoverStatus,bool needRotate)201 void ScreenSessionManagerClient::OnHoverStatusChanged(ScreenId screenId, int32_t hoverStatus, bool needRotate)
202 {
203     auto screenSession = GetScreenSession(screenId);
204     if (!screenSession) {
205         WLOGFE("screenSession is null");
206         return;
207     }
208     screenSession->HandleHoverStatusChange(hoverStatus, needRotate);
209 }
210 
OnScreenOrientationChanged(ScreenId screenId,float screenOrientation)211 void ScreenSessionManagerClient::OnScreenOrientationChanged(ScreenId screenId, float screenOrientation)
212 {
213     auto screenSession = GetScreenSession(screenId);
214     if (!screenSession) {
215         WLOGFE("screenSession is null");
216         return;
217     }
218     screenSession->ScreenOrientationChange(screenOrientation);
219 }
220 
OnScreenRotationLockedChanged(ScreenId screenId,bool isLocked)221 void ScreenSessionManagerClient::OnScreenRotationLockedChanged(ScreenId screenId, bool isLocked)
222 {
223     auto screenSession = GetScreenSession(screenId);
224     if (!screenSession) {
225         WLOGFE("screenSession is null");
226         return;
227     }
228     screenSession->SetScreenRotationLocked(isLocked);
229 }
230 
OnCameraBackSelfieChanged(ScreenId screenId,bool isCameraBackSelfie)231 void ScreenSessionManagerClient::OnCameraBackSelfieChanged(ScreenId screenId, bool isCameraBackSelfie)
232 {
233     auto screenSession = GetScreenSession(screenId);
234     if (!screenSession) {
235         WLOGFE("screenSession is null");
236         return;
237     }
238     screenSession->HandleCameraBackSelfieChange(isCameraBackSelfie);
239 }
240 
RegisterDisplayChangeListener(const sptr<IDisplayChangeListener> & listener)241 void ScreenSessionManagerClient::RegisterDisplayChangeListener(const sptr<IDisplayChangeListener>& listener)
242 {
243     displayChangeListener_ = listener;
244 }
245 
RegisterSwitchingToAnotherUserFunction(std::function<void ()> && func)246 void ScreenSessionManagerClient::RegisterSwitchingToAnotherUserFunction(std::function<void()>&& func)
247 {
248     switchingToAnotherUserFunc_ = func;
249 }
250 
OnDisplayStateChanged(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)251 void ScreenSessionManagerClient::OnDisplayStateChanged(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
252     const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
253 {
254     if (displayChangeListener_) {
255         displayChangeListener_->OnDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
256     }
257 }
258 
OnUpdateFoldDisplayMode(FoldDisplayMode displayMode)259 void ScreenSessionManagerClient::OnUpdateFoldDisplayMode(FoldDisplayMode displayMode)
260 {
261     displayMode_ = displayMode;
262 }
263 
OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t> & missionIds,std::vector<uint64_t> & surfaceNodeIds,bool isBlackList)264 void ScreenSessionManagerClient::OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t>& missionIds,
265     std::vector<uint64_t>& surfaceNodeIds, bool isBlackList)
266 {
267     if (displayChangeListener_) {
268         displayChangeListener_->OnGetSurfaceNodeIdsFromMissionIds(missionIds, surfaceNodeIds, isBlackList);
269     }
270 }
271 
OnScreenshot(DisplayId displayId)272 void ScreenSessionManagerClient::OnScreenshot(DisplayId displayId)
273 {
274     if (displayChangeListener_) {
275         displayChangeListener_->OnScreenshot(displayId);
276     }
277 }
278 
OnImmersiveStateChanged(bool & immersive)279 void ScreenSessionManagerClient::OnImmersiveStateChanged(bool& immersive)
280 {
281     if (displayChangeListener_ != nullptr) {
282         displayChangeListener_->OnImmersiveStateChange(immersive);
283     }
284 }
285 
GetAllScreensProperties() const286 std::map<ScreenId, ScreenProperty> ScreenSessionManagerClient::GetAllScreensProperties() const
287 {
288     std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
289     std::map<ScreenId, ScreenProperty> screensProperties;
290     for (const auto& iter: screenSessionMap_) {
291         if (iter.second == nullptr) {
292             continue;
293         }
294         screensProperties[iter.first] = iter.second->GetScreenProperty();
295     }
296     return screensProperties;
297 }
298 
GetFoldDisplayMode() const299 FoldDisplayMode ScreenSessionManagerClient::GetFoldDisplayMode() const
300 {
301     return displayMode_;
302 }
303 
UpdateScreenRotationProperty(ScreenId screenId,const RRect & bounds,ScreenDirectionInfo directionInfo,ScreenPropertyChangeType screenPropertyChangeType)304 void ScreenSessionManagerClient::UpdateScreenRotationProperty(ScreenId screenId, const RRect& bounds,
305     ScreenDirectionInfo directionInfo, ScreenPropertyChangeType screenPropertyChangeType)
306 {
307     if (!screenSessionManager_) {
308         WLOGFE("screenSessionManager_ is null");
309         return;
310     }
311     screenSessionManager_->UpdateScreenDirectionInfo(screenId, directionInfo.screenRotation_, directionInfo.rotation_,
312         directionInfo.phyRotation_, screenPropertyChangeType);
313     screenSessionManager_->UpdateScreenRotationProperty(screenId, bounds, directionInfo.notifyRotation_,
314         screenPropertyChangeType);
315 
316     // not need update property to input manager
317     if (screenPropertyChangeType == ScreenPropertyChangeType::ROTATION_END ||
318         screenPropertyChangeType == ScreenPropertyChangeType::ROTATION_UPDATE_PROPERTY_ONLY) {
319         return;
320     }
321     auto screenSession = GetScreenSession(screenId);
322     if (!screenSession) {
323         WLOGFE("screenSession is null");
324         return;
325     }
326     auto foldDisplayMode = screenSessionManager_->GetFoldDisplayMode();
327     screenSession->SetPhysicalRotation(directionInfo.phyRotation_);
328     screenSession->SetScreenComponentRotation(directionInfo.screenRotation_);
329     screenSession->UpdateToInputManager(bounds, directionInfo.notifyRotation_, directionInfo.rotation_,
330         foldDisplayMode);
331     screenSession->UpdateTouchBoundsAndOffset(foldDisplayMode);
332 }
333 
SetDisplayNodeScreenId(ScreenId screenId,ScreenId displayNodeScreenId)334 void ScreenSessionManagerClient::SetDisplayNodeScreenId(ScreenId screenId, ScreenId displayNodeScreenId)
335 {
336     auto screenSession = GetScreenSession(screenId);
337     if (!screenSession) {
338         WLOGFE("screenSession is null");
339         return;
340     }
341     screenSession->SetDisplayNodeScreenId(displayNodeScreenId);
342 }
343 
GetCurvedCompressionArea()344 uint32_t ScreenSessionManagerClient::GetCurvedCompressionArea()
345 {
346     if (!screenSessionManager_) {
347         WLOGFE("screenSessionManager_ is null");
348         return 0;
349     }
350     return screenSessionManager_->GetCurvedCompressionArea();
351 }
352 
GetPhyScreenProperty(ScreenId screenId)353 ScreenProperty ScreenSessionManagerClient::GetPhyScreenProperty(ScreenId screenId)
354 {
355     if (!screenSessionManager_) {
356         WLOGFE("screenSessionManager_ is null");
357         return {};
358     }
359     return screenSessionManager_->GetPhyScreenProperty(screenId);
360 }
361 
NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo> & info)362 __attribute__((no_sanitize("cfi"))) void ScreenSessionManagerClient::NotifyDisplayChangeInfoChanged(
363     const sptr<DisplayChangeInfo>& info)
364 {
365     if (!screenSessionManager_) {
366         WLOGFE("screenSessionManager_ is null");
367         return;
368     }
369     screenSessionManager_->NotifyDisplayChangeInfoChanged(info);
370 }
371 
SetScreenPrivacyState(bool hasPrivate)372 void ScreenSessionManagerClient::SetScreenPrivacyState(bool hasPrivate)
373 {
374     if (!screenSessionManager_) {
375         WLOGFE("screenSessionManager_ is null");
376         return;
377     }
378     WLOGFD("Begin calling the SetScreenPrivacyState() of screenSessionManager_, hasPrivate: %{public}d", hasPrivate);
379     screenSessionManager_->SetScreenPrivacyState(hasPrivate);
380     WLOGFD("End calling the SetScreenPrivacyState() of screenSessionManager_");
381 }
382 
SetPrivacyStateByDisplayId(DisplayId id,bool hasPrivate)383 void ScreenSessionManagerClient::SetPrivacyStateByDisplayId(DisplayId id, bool hasPrivate)
384 {
385     if (!screenSessionManager_) {
386         WLOGFE("screenSessionManager_ is null");
387         return;
388     }
389     WLOGFD("Begin calling the SetPrivacyStateByDisplayId, hasPrivate: %{public}d", hasPrivate);
390     screenSessionManager_->SetPrivacyStateByDisplayId(id, hasPrivate);
391     WLOGFD("End calling the SetPrivacyStateByDisplayId");
392 }
393 
SetScreenPrivacyWindowList(DisplayId id,std::vector<std::string> privacyWindowList)394 void ScreenSessionManagerClient::SetScreenPrivacyWindowList(DisplayId id, std::vector<std::string> privacyWindowList)
395 {
396     if (!screenSessionManager_) {
397         WLOGFE("screenSessionManager_ is null");
398         return;
399     }
400     WLOGFD("Begin calling the SetScreenPrivacyWindowList(), id: %{public}" PRIu64, id);
401     screenSessionManager_->SetScreenPrivacyWindowList(id, privacyWindowList);
402     WLOGFD("End calling the SetScreenPrivacyWindowList()");
403 }
404 
UpdateAvailableArea(ScreenId screenId,DMRect area)405 void ScreenSessionManagerClient::UpdateAvailableArea(ScreenId screenId, DMRect area)
406 {
407     if (!screenSessionManager_) {
408         WLOGFE("screenSessionManager_ is null");
409         return;
410     }
411     screenSessionManager_->UpdateAvailableArea(screenId, area);
412 }
413 
SetScreenOffDelayTime(int32_t delay)414 int32_t ScreenSessionManagerClient::SetScreenOffDelayTime(int32_t delay)
415 {
416     if (!screenSessionManager_) {
417         WLOGFE("screenSessionManager_ is null");
418         return 0;
419     }
420     return screenSessionManager_->SetScreenOffDelayTime(delay);
421 }
422 
SetCameraStatus(int32_t cameraStatus,int32_t cameraPosition)423 void ScreenSessionManagerClient::SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition)
424 {
425     if (!screenSessionManager_) {
426         WLOGFE("screenSessionManager_ is null");
427         return;
428     }
429     return screenSessionManager_->SetCameraStatus(cameraStatus, cameraPosition);
430 }
431 
NotifyFoldToExpandCompletion(bool foldToExpand)432 void ScreenSessionManagerClient::NotifyFoldToExpandCompletion(bool foldToExpand)
433 {
434     if (!screenSessionManager_) {
435         WLOGFE("screenSessionManager_ is null");
436         return;
437     }
438     screenSessionManager_->NotifyFoldToExpandCompletion(foldToExpand);
439 }
440 
RecordEventFromScb(std::string description,bool needRecordEvent)441 void ScreenSessionManagerClient::RecordEventFromScb(std::string description, bool needRecordEvent)
442 {
443     if (!screenSessionManager_) {
444         WLOGFE("screenSessionManager_ is null");
445         return;
446     }
447     screenSessionManager_->RecordEventFromScb(description, needRecordEvent);
448 }
449 
SwitchUserCallback(std::vector<int32_t> oldScbPids,int32_t currentScbPid)450 void ScreenSessionManagerClient::SwitchUserCallback(std::vector<int32_t> oldScbPids, int32_t currentScbPid)
451 {
452     if (!screenSessionManager_) {
453         WLOGFE("screenSessionManager_ is null");
454         return;
455     }
456     if (oldScbPids.size() == 0) {
457         WLOGFE("oldScbPids size 0");
458         return;
459     }
460     std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
461     for (const auto& iter : screenSessionMap_) {
462         auto displayNode = screenSessionManager_->GetDisplayNode(iter.first);
463         if (displayNode == nullptr) {
464             WLOGFE("display node is null");
465             continue;
466         }
467         auto transactionProxy = RSTransactionProxy::GetInstance();
468         if (transactionProxy != nullptr) {
469             displayNode->SetScbNodePid(oldScbPids, currentScbPid);
470             transactionProxy->FlushImplicitTransaction();
471         } else {
472             displayNode->SetScbNodePid(oldScbPids, currentScbPid);
473             WLOGFW("transactionProxy is null");
474         }
475         ScreenId screenId = iter.first;
476         sptr<ScreenSession> screenSession = iter.second;
477         if (screenSession == nullptr) {
478             WLOGFE("screenSession is null");
479             return;
480         }
481         ScreenProperty screenProperty = screenSession->GetScreenProperty();
482         RRect bounds = screenProperty.GetBounds();
483         float rotation = screenSession->ConvertRotationToFloat(screenSession->GetRotation());
484         screenSessionManager_->UpdateScreenRotationProperty(screenId, bounds, rotation,
485             ScreenPropertyChangeType::ROTATION_UPDATE_PROPERTY_ONLY);
486     }
487     WLOGFI("switch user callback end");
488 }
489 
SwitchingCurrentUser()490 void ScreenSessionManagerClient::SwitchingCurrentUser()
491 {
492     if (screenSessionManager_ == nullptr) {
493         WLOGFE("screenSessionManager_ is null");
494         return;
495     }
496     screenSessionManager_->SwitchUser();
497     WLOGFI("switch to current user end");
498 }
499 
GetFoldStatus()500 FoldStatus ScreenSessionManagerClient::GetFoldStatus()
501 {
502     if (!screenSessionManager_) {
503         WLOGFE("screenSessionManager_ is null");
504         return FoldStatus::UNKNOWN;
505     }
506     return screenSessionManager_->GetFoldStatus();
507 }
508 
GetScreenSnapshot(ScreenId screenId,float scaleX,float scaleY)509 std::shared_ptr<Media::PixelMap> ScreenSessionManagerClient::GetScreenSnapshot(ScreenId screenId,
510     float scaleX, float scaleY)
511 {
512     auto screenSession = GetScreenSession(screenId);
513     if (!screenSession) {
514         WLOGFE("get screen session is null");
515         return nullptr;
516     }
517     return screenSession->GetScreenSnapshot(scaleX, scaleY);
518 }
519 
GetDeviceScreenConfig()520 DeviceScreenConfig ScreenSessionManagerClient::GetDeviceScreenConfig()
521 {
522     if (!screenSessionManager_) {
523         TLOGE(WmsLogTag::DMS, "screenSessionManager_ is null");
524         return {};
525     }
526     return screenSessionManager_->GetDeviceScreenConfig();
527 }
528 
GetScreenSessionById(const ScreenId id)529 sptr<ScreenSession> ScreenSessionManagerClient::GetScreenSessionById(const ScreenId id)
530 {
531     std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
532     auto iter = screenSessionMap_.find(id);
533     if (iter == screenSessionMap_.end()) {
534         return nullptr;
535     }
536     return iter->second;
537 }
538 
GetDefaultScreenId()539 ScreenId ScreenSessionManagerClient::GetDefaultScreenId()
540 {
541     std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
542     auto iter = screenSessionMap_.begin();
543     if (iter != screenSessionMap_.end()) {
544         return iter->first;
545     }
546     return SCREEN_ID_INVALID;
547 }
548 
IsFoldable()549 bool ScreenSessionManagerClient::IsFoldable()
550 {
551     if (hasCheckFoldableStatus_) {
552         return isFoldable_;
553     }
554     if (!screenSessionManager_) {
555         WLOGFE("screenSessionManager_ is null");
556         return false;
557     }
558     isFoldable_ = screenSessionManager_->IsFoldable();
559     hasCheckFoldableStatus_ = true;
560     return isFoldable_;
561 }
562 
SetVirtualPixelRatioSystem(ScreenId screenId,float virtualPixelRatio)563 void ScreenSessionManagerClient::SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio)
564 {
565     sptr<ScreenSession> screenSession = GetScreenSession(screenId);
566     if (!screenSession) {
567         WLOGFE("screen session is null");
568         return;
569     }
570     if (screenSession->isScreenGroup_) {
571         WLOGFE("cannot set virtual pixel ratio to the combination. screen: %{public}" PRIu64, screenId);
572         return;
573     }
574     screenSession->SetScreenSceneDpi(virtualPixelRatio);
575 }
576 
UpdateDisplayHookInfo(int32_t uid,bool enable,const DMHookInfo & hookInfo)577 void ScreenSessionManagerClient::UpdateDisplayHookInfo(int32_t uid, bool enable, const DMHookInfo& hookInfo)
578 {
579     if (!screenSessionManager_) {
580         WLOGFE("screenSessionManager_ is null");
581         return;
582     }
583     screenSessionManager_->UpdateDisplayHookInfo(uid, enable, hookInfo);
584 }
585 
OnFoldStatusChangedReportUE(const std::vector<std::string> & screenFoldInfo)586 void ScreenSessionManagerClient::OnFoldStatusChangedReportUE(const std::vector<std::string>& screenFoldInfo)
587 {
588     if (displayChangeListener_) {
589         displayChangeListener_->OnScreenFoldStatusChanged(screenFoldInfo);
590     }
591 }
592 
UpdateDisplayScale(ScreenId id,float scaleX,float scaleY,float pivotX,float pivotY,float translateX,float translateY)593 void ScreenSessionManagerClient::UpdateDisplayScale(ScreenId id, float scaleX, float scaleY, float pivotX, float pivotY,
594                                                     float translateX, float translateY)
595 {
596     auto session = GetScreenSession(id);
597     if (session == nullptr) {
598         TLOGE(WmsLogTag::DMS, "session is null");
599         return;
600     }
601     auto displayNode = session->GetDisplayNode();
602     if (displayNode == nullptr) {
603         TLOGE(WmsLogTag::DMS, "displayNode is null");
604         return;
605     }
606     TLOGD(WmsLogTag::DMS, "scale [%{public}f, %{public}f] translate [%{public}f, %{public}f]", scaleX, scaleY,
607           translateX, translateY);
608     HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER,
609                       "ssmc:UpdateDisplayScale(ScreenId = %" PRIu64
610                       " scaleX=%f, scaleY=%f, pivotX=%f, pivotY=%f, translateX=%f, translateY=%f",
611                       id, scaleX, scaleY, pivotX, pivotY, translateX, translateY);
612     displayNode->SetScale(scaleX, scaleY);
613     displayNode->SetTranslateX(translateX);
614     displayNode->SetTranslateY(translateY);
615     auto transactionProxy = RSTransactionProxy::GetInstance();
616     if (transactionProxy != nullptr) {
617         transactionProxy->FlushImplicitTransaction();
618     } else {
619         TLOGE(WmsLogTag::DMS, "transactionProxy is nullptr");
620     }
621     session->SetScreenScale(scaleX, scaleY, pivotX, pivotY, translateX, translateY);
622 }
623 
ScreenCaptureNotify(ScreenId mainScreenId,int32_t uid,const std::string & clientName)624 void ScreenSessionManagerClient::ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName)
625 {
626     sptr<ScreenSession> screenSession = GetScreenSession(mainScreenId);
627     if (!screenSession) {
628         WLOGFE("screen session is null");
629         return;
630     }
631     WLOGFI("capture screenId: %{public}" PRIu64", uid=%{public}d", mainScreenId, uid);
632     screenSession->ScreenCaptureNotify(mainScreenId, uid, clientName);
633 }
634 
OnSecondaryReflexionChanged(ScreenId screenId,bool isSecondaryReflexion)635 void ScreenSessionManagerClient::OnSecondaryReflexionChanged(ScreenId screenId, bool isSecondaryReflexion)
636 {
637     auto screenSession = GetScreenSession(screenId);
638     if (!screenSession) {
639         WLOGFE("screenSession is null");
640         return;
641     }
642     WLOGI("screenId=%{public}" PRIu64 " isSecondaryReflexion=%{public}d", screenId, isSecondaryReflexion);
643     screenSession->SecondaryReflexionChange(screenId, isSecondaryReflexion);
644 }
645 } // namespace OHOS::Rosen