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 #include "fold_screen_controller/super_fold_state_manager.h"
27 #include "fold_screen_state_internel.h"
28
29 namespace OHOS::Rosen {
30 namespace {
31 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenSessionManagerClient" };
32 std::mutex g_instanceMutex;
33 } // namespace
34
GetInstance()35 ScreenSessionManagerClient& ScreenSessionManagerClient::GetInstance()
36 {
37 std::lock_guard<std::mutex> lock(g_instanceMutex);
38 static sptr<ScreenSessionManagerClient> instance = nullptr;
39 if (instance == nullptr) {
40 instance = new ScreenSessionManagerClient();
41 }
42 return *instance;
43 }
44
ConnectToServer()45 void ScreenSessionManagerClient::ConnectToServer()
46 {
47 if (screenSessionManager_) {
48 WLOGFI("Success to get screen session manager proxy");
49 return;
50 }
51 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
52 if (!systemAbilityMgr) {
53 WLOGFE("Failed to get system ability mgr");
54 return;
55 }
56
57 auto remoteObject = systemAbilityMgr->GetSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID);
58 if (!remoteObject) {
59 WLOGFE("Failed to get display manager service");
60 return;
61 }
62
63 screenSessionManager_ = iface_cast<IScreenSessionManager>(remoteObject);
64 if (!screenSessionManager_) {
65 WLOGFE("Failed to get screen session manager proxy");
66 return;
67 }
68 screenSessionManager_->SetClient(this);
69 }
70
RegisterScreenConnectionListener(IScreenConnectionListener * listener)71 void ScreenSessionManagerClient::RegisterScreenConnectionListener(IScreenConnectionListener* listener)
72 {
73 if (listener == nullptr) {
74 WLOGFE("Failed to register screen connection listener, listener is null");
75 return;
76 }
77
78 screenConnectionListener_ = listener;
79 ConnectToServer();
80 WLOGFI("Success to register screen connection listener");
81 }
82
RegisterScreenConnectionChangeListener(const sptr<IScreenConnectionChangeListener> & listener)83 void ScreenSessionManagerClient::RegisterScreenConnectionChangeListener(
84 const sptr<IScreenConnectionChangeListener>& listener)
85 {
86 if (listener == nullptr) {
87 TLOGE(WmsLogTag::DMS, "Failed: listener is null");
88 return;
89 }
90 screenConnectionChangeListener_ = listener;
91 TLOGI(WmsLogTag::DMS, "Success");
92 }
93
NotifyScreenConnect(const sptr<ScreenSession> & screenSession)94 void ScreenSessionManagerClient::NotifyScreenConnect(const sptr<ScreenSession>& screenSession)
95 {
96 if (screenConnectionListener_) {
97 screenConnectionListener_->OnScreenConnected(screenSession);
98 }
99 if (screenConnectionChangeListener_) {
100 screenConnectionChangeListener_->OnScreenConnected(screenSession);
101 }
102 }
103
NotifyScreenDisconnect(const sptr<ScreenSession> & screenSession)104 void ScreenSessionManagerClient::NotifyScreenDisconnect(const sptr<ScreenSession>& screenSession)
105 {
106 if (screenConnectionListener_) {
107 screenConnectionListener_->OnScreenDisconnected(screenSession);
108 }
109 if (screenConnectionChangeListener_) {
110 screenConnectionChangeListener_->OnScreenDisconnected(screenSession);
111 }
112 }
113
CheckIfNeedConnectScreen(SessionOption option)114 bool ScreenSessionManagerClient::CheckIfNeedConnectScreen(SessionOption option)
115 {
116 if (option.rsId_ == SCREEN_ID_INVALID) {
117 WLOGFE("rsId is invalid");
118 return false;
119 }
120 if (!screenSessionManager_) {
121 WLOGFE("screenSessionManager_ is nullptr");
122 return false;
123 }
124 if (screenSessionManager_->GetScreenProperty(option.screenId_).GetScreenType() == ScreenType::VIRTUAL) {
125 if (option.name_ == "HiCar" || option.name_ == "SuperLauncher" || option.name_ == "CastEngine" ||
126 option.name_ == "DevEcoViewer" || option.innerName_ == "CustomScbScreen" || option.name_ == "CeliaView") {
127 WLOGFI("HiCar or SuperLauncher or CastEngine or DevEcoViewer or CeliaView, need to connect the screen");
128 return true;
129 } else {
130 WLOGFE("ScreenType is virtual, no need to connect the screen");
131 return false;
132 }
133 }
134 return true;
135 }
136
OnScreenConnectionChanged(SessionOption option,ScreenEvent screenEvent)137 void ScreenSessionManagerClient::OnScreenConnectionChanged(SessionOption option, ScreenEvent screenEvent)
138 {
139 WLOGFI("sId: %{public}" PRIu64 " sEvent: %{public}d rsId: %{public}" PRIu64 " name: %{public}s iName: %{public}s",
140 option.screenId_, static_cast<int>(screenEvent), option.rsId_, option.name_.c_str(), option.innerName_.c_str());
141 if (screenEvent == ScreenEvent::CONNECTED) {
142 if (!CheckIfNeedConnectScreen(option)) {
143 WLOGFE("There is no need to connect the screen");
144 return;
145 }
146 ScreenSessionConfig config = {
147 .screenId = option.screenId_,
148 .rsId = option.rsId_,
149 .name = option.name_,
150 .innerName = option.innerName_,
151 };
152 config.property = screenSessionManager_->GetScreenProperty(option.screenId_);
153 config.displayNode = screenSessionManager_->GetDisplayNode(option.screenId_);
154 sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
155 screenSession->SetScreenCombination(screenSessionManager_->GetScreenCombination(option.screenId_));
156 {
157 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
158 screenSessionMap_.emplace(option.screenId_, screenSession);
159 extraScreenSessionMap_[option.screenId_] = screenSession;
160 }
161 screenSession->SetIsExtend(option.isExtend_);
162 screenSession->SetIsRealScreen(screenSessionManager_->GetIsRealScreen(option.screenId_));
163 NotifyScreenConnect(screenSession);
164 if (screenConnectionListener_) {
165 WLOGFI("screenId: %{public}" PRIu64 " density: %{public}f ",
166 option.screenId_, config.property.GetDensity());
167 screenSession->SetScreenSceneDpi(config.property.GetDensity());
168 }
169 screenSession->Connect();
170 return;
171 }
172 if (screenEvent == ScreenEvent::DISCONNECTED) {
173 auto screenSession = GetScreenSession(option.screenId_);
174 if (!screenSession) {
175 WLOGFE("screenSession is null");
176 return;
177 }
178 screenSession->DestroyScreenScene();
179 NotifyScreenDisconnect(screenSession);
180 {
181 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
182 screenSessionMap_.erase(option.screenId_);
183 }
184 screenSession->Disconnect();
185 }
186 }
187
ExtraDestroyScreen(ScreenId screenId)188 void ScreenSessionManagerClient::ExtraDestroyScreen(ScreenId screenId)
189 {
190 auto screenSession = GetScreenSessionExtra(screenId);
191 if (!screenSession) {
192 WLOGFE("extra screenSession is null");
193 return;
194 }
195 screenSession->DestroyScreenScene();
196 {
197 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
198 extraScreenSessionMap_.erase(screenId);
199 }
200 WLOGFI("ExtraDestroyScreen end");
201 }
202
OnScreenExtendChanged(ScreenId mainScreenId,ScreenId extendScreenId)203 void ScreenSessionManagerClient::OnScreenExtendChanged(ScreenId mainScreenId, ScreenId extendScreenId)
204 {
205 auto screenSession = GetScreenSession(mainScreenId);
206 if (!screenSession) {
207 WLOGFE("screenSession is null");
208 return;
209 }
210 WLOGI("mainScreenId=%{public}" PRIu64" extendScreenId=%{public}" PRIu64, mainScreenId, extendScreenId);
211 screenSession->ScreenExtendChange(mainScreenId, extendScreenId);
212 }
213
GetScreenSession(ScreenId screenId) const214 sptr<ScreenSession> ScreenSessionManagerClient::GetScreenSession(ScreenId screenId) const
215 {
216 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
217 auto iter = screenSessionMap_.find(screenId);
218 if (iter == screenSessionMap_.end()) {
219 WLOGFE("Error found screen session with id: %{public}" PRIu64, screenId);
220 return nullptr;
221 }
222 return iter->second;
223 }
224
GetScreenSessionExtra(ScreenId screenId) const225 sptr<ScreenSession> ScreenSessionManagerClient::GetScreenSessionExtra(ScreenId screenId) const
226 {
227 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
228 auto iter = extraScreenSessionMap_.find(screenId);
229 if (iter == extraScreenSessionMap_.end()) {
230 WLOGFE("Error found extra screen session with id: %{public}" PRIu64, screenId);
231 return nullptr;
232 }
233 return iter->second;
234 }
235
OnPropertyChanged(ScreenId screenId,const ScreenProperty & property,ScreenPropertyChangeReason reason)236 void ScreenSessionManagerClient::OnPropertyChanged(ScreenId screenId,
237 const ScreenProperty& property, ScreenPropertyChangeReason reason)
238 {
239 auto screenSession = GetScreenSession(screenId);
240 if (!screenSession) {
241 WLOGFE("screenSession is null");
242 return;
243 }
244 screenSession->PropertyChange(property, reason);
245 }
246
OnPowerStatusChanged(DisplayPowerEvent event,EventStatus status,PowerStateChangeReason reason)247 void ScreenSessionManagerClient::OnPowerStatusChanged(DisplayPowerEvent event, EventStatus status,
248 PowerStateChangeReason reason)
249 {
250 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
251 if (screenSessionMap_.empty()) {
252 WLOGFE("[UL_POWER]screenSessionMap_ is nullptr");
253 return;
254 }
255 auto screenSession = screenSessionMap_.begin()->second;
256 if (!screenSession) {
257 WLOGFE("[UL_POWER]screenSession is null");
258 return;
259 }
260 screenSession->PowerStatusChange(event, status, reason);
261 }
262
OnSensorRotationChanged(ScreenId screenId,float sensorRotation)263 void ScreenSessionManagerClient::OnSensorRotationChanged(ScreenId screenId, float sensorRotation)
264 {
265 auto screenSession = GetScreenSession(screenId);
266 if (!screenSession) {
267 WLOGFE("screenSession is null");
268 return;
269 }
270 screenSession->SensorRotationChange(sensorRotation);
271 }
272
OnHoverStatusChanged(ScreenId screenId,int32_t hoverStatus,bool needRotate)273 void ScreenSessionManagerClient::OnHoverStatusChanged(ScreenId screenId, int32_t hoverStatus, bool needRotate)
274 {
275 auto screenSession = GetScreenSession(screenId);
276 if (!screenSession) {
277 WLOGFE("screenSession is null");
278 return;
279 }
280 screenSession->HandleHoverStatusChange(hoverStatus, needRotate);
281 }
282
OnScreenOrientationChanged(ScreenId screenId,float screenOrientation)283 void ScreenSessionManagerClient::OnScreenOrientationChanged(ScreenId screenId, float screenOrientation)
284 {
285 auto screenSession = GetScreenSession(screenId);
286 if (!screenSession) {
287 WLOGFE("screenSession is null");
288 return;
289 }
290 screenSession->ScreenOrientationChange(screenOrientation);
291 }
292
OnScreenRotationLockedChanged(ScreenId screenId,bool isLocked)293 void ScreenSessionManagerClient::OnScreenRotationLockedChanged(ScreenId screenId, bool isLocked)
294 {
295 auto screenSession = GetScreenSession(screenId);
296 if (!screenSession) {
297 WLOGFE("screenSession is null");
298 return;
299 }
300 screenSession->SetScreenRotationLocked(isLocked);
301 }
302
OnCameraBackSelfieChanged(ScreenId screenId,bool isCameraBackSelfie)303 void ScreenSessionManagerClient::OnCameraBackSelfieChanged(ScreenId screenId, bool isCameraBackSelfie)
304 {
305 auto screenSession = GetScreenSession(screenId);
306 if (!screenSession) {
307 WLOGFE("screenSession is null");
308 return;
309 }
310 screenSession->HandleCameraBackSelfieChange(isCameraBackSelfie);
311 }
312
RegisterDisplayChangeListener(const sptr<IDisplayChangeListener> & listener)313 void ScreenSessionManagerClient::RegisterDisplayChangeListener(const sptr<IDisplayChangeListener>& listener)
314 {
315 displayChangeListener_ = listener;
316 }
317
RegisterSwitchingToAnotherUserFunction(std::function<void ()> && func)318 void ScreenSessionManagerClient::RegisterSwitchingToAnotherUserFunction(std::function<void()>&& func)
319 {
320 switchingToAnotherUserFunc_ = func;
321 }
322
OnDisplayStateChanged(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)323 void ScreenSessionManagerClient::OnDisplayStateChanged(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
324 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
325 {
326 if (displayChangeListener_) {
327 displayChangeListener_->OnDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
328 }
329 }
330
OnUpdateFoldDisplayMode(FoldDisplayMode displayMode)331 void ScreenSessionManagerClient::OnUpdateFoldDisplayMode(FoldDisplayMode displayMode)
332 {
333 displayMode_ = displayMode;
334 }
335
OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t> & missionIds,std::vector<uint64_t> & surfaceNodeIds,bool isBlackList)336 void ScreenSessionManagerClient::OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t>& missionIds,
337 std::vector<uint64_t>& surfaceNodeIds, bool isBlackList)
338 {
339 if (displayChangeListener_) {
340 displayChangeListener_->OnGetSurfaceNodeIdsFromMissionIds(missionIds, surfaceNodeIds, isBlackList);
341 }
342 }
343
OnScreenshot(DisplayId displayId)344 void ScreenSessionManagerClient::OnScreenshot(DisplayId displayId)
345 {
346 if (displayChangeListener_) {
347 displayChangeListener_->OnScreenshot(displayId);
348 }
349 }
350
OnImmersiveStateChanged(ScreenId screenId,bool & immersive)351 void ScreenSessionManagerClient::OnImmersiveStateChanged(ScreenId screenId, bool& immersive)
352 {
353 if (displayChangeListener_ != nullptr) {
354 displayChangeListener_->OnImmersiveStateChange(screenId, immersive);
355 }
356 }
357
GetAllScreensProperties() const358 std::map<ScreenId, ScreenProperty> ScreenSessionManagerClient::GetAllScreensProperties() const
359 {
360 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
361 std::map<ScreenId, ScreenProperty> screensProperties;
362 for (const auto& iter: screenSessionMap_) {
363 if (iter.second == nullptr) {
364 continue;
365 }
366 screensProperties[iter.first] = iter.second->GetScreenProperty();
367 }
368 return screensProperties;
369 }
370
GetFoldDisplayMode() const371 FoldDisplayMode ScreenSessionManagerClient::GetFoldDisplayMode() const
372 {
373 return displayMode_;
374 }
375
UpdateScreenRotationProperty(ScreenId screenId,const RRect & bounds,ScreenDirectionInfo directionInfo,ScreenPropertyChangeType screenPropertyChangeType)376 void ScreenSessionManagerClient::UpdateScreenRotationProperty(ScreenId screenId, const RRect& bounds,
377 ScreenDirectionInfo directionInfo, ScreenPropertyChangeType screenPropertyChangeType)
378 {
379 if (!screenSessionManager_) {
380 WLOGFE("screenSessionManager_ is null");
381 return;
382 }
383 screenSessionManager_->UpdateScreenDirectionInfo(screenId, directionInfo.screenRotation_, directionInfo.rotation_,
384 directionInfo.phyRotation_, screenPropertyChangeType);
385 screenSessionManager_->UpdateScreenRotationProperty(screenId, bounds, directionInfo.notifyRotation_,
386 screenPropertyChangeType);
387
388 // not need update property to input manager
389 if (screenPropertyChangeType == ScreenPropertyChangeType::ROTATION_END ||
390 screenPropertyChangeType == ScreenPropertyChangeType::ROTATION_UPDATE_PROPERTY_ONLY ||
391 screenPropertyChangeType == ScreenPropertyChangeType::ROTATION_UPDATE_PROPERTY_ONLY_NOT_NOTIFY) {
392 return;
393 }
394 auto screenSession = GetScreenSession(screenId);
395 if (!screenSession) {
396 WLOGFE("screenSession is null");
397 return;
398 }
399 auto foldDisplayMode = screenSessionManager_->GetFoldDisplayMode();
400 screenSession->SetPhysicalRotation(directionInfo.phyRotation_);
401 screenSession->SetScreenComponentRotation(directionInfo.screenRotation_);
402 screenSession->UpdateToInputManager(bounds, directionInfo.notifyRotation_, directionInfo.rotation_,
403 foldDisplayMode, screenSessionManager_->IsOrientationNeedChanged());
404 screenSession->UpdateTouchBoundsAndOffset();
405 if (currentstate_ != SuperFoldStatus::KEYBOARD) {
406 screenSession->SetValidHeight(bounds.rect_.GetHeight());
407 screenSession->SetValidWidth(bounds.rect_.GetWidth());
408 }
409 }
410
SetDisplayNodeScreenId(ScreenId screenId,ScreenId displayNodeScreenId)411 void ScreenSessionManagerClient::SetDisplayNodeScreenId(ScreenId screenId, ScreenId displayNodeScreenId)
412 {
413 auto screenSession = GetScreenSession(screenId);
414 if (!screenSession) {
415 WLOGFE("screenSession is null");
416 return;
417 }
418 screenSession->SetDisplayNodeScreenId(displayNodeScreenId);
419 }
420
GetCurvedCompressionArea()421 uint32_t ScreenSessionManagerClient::GetCurvedCompressionArea()
422 {
423 if (!screenSessionManager_) {
424 WLOGFE("screenSessionManager_ is null");
425 return 0;
426 }
427 return screenSessionManager_->GetCurvedCompressionArea();
428 }
429
GetPhyScreenProperty(ScreenId screenId)430 ScreenProperty ScreenSessionManagerClient::GetPhyScreenProperty(ScreenId screenId)
431 {
432 if (!screenSessionManager_) {
433 WLOGFE("screenSessionManager_ is null");
434 return {};
435 }
436 return screenSessionManager_->GetPhyScreenProperty(screenId);
437 }
438
NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo> & info)439 __attribute__((no_sanitize("cfi"))) void ScreenSessionManagerClient::NotifyDisplayChangeInfoChanged(
440 const sptr<DisplayChangeInfo>& info)
441 {
442 if (!screenSessionManager_) {
443 WLOGFE("screenSessionManager_ is null");
444 return;
445 }
446 screenSessionManager_->NotifyDisplayChangeInfoChanged(info);
447 }
448
SetScreenPrivacyState(bool hasPrivate)449 void ScreenSessionManagerClient::SetScreenPrivacyState(bool hasPrivate)
450 {
451 if (!screenSessionManager_) {
452 WLOGFE("screenSessionManager_ is null");
453 return;
454 }
455 WLOGFD("Begin calling the SetScreenPrivacyState() of screenSessionManager_, hasPrivate: %{public}d", hasPrivate);
456 screenSessionManager_->SetScreenPrivacyState(hasPrivate);
457 WLOGFD("End calling the SetScreenPrivacyState() of screenSessionManager_");
458 }
459
SetPrivacyStateByDisplayId(DisplayId id,bool hasPrivate)460 void ScreenSessionManagerClient::SetPrivacyStateByDisplayId(DisplayId id, bool hasPrivate)
461 {
462 if (!screenSessionManager_) {
463 WLOGFE("screenSessionManager_ is null");
464 return;
465 }
466 WLOGFD("Begin calling the SetPrivacyStateByDisplayId, hasPrivate: %{public}d", hasPrivate);
467 screenSessionManager_->SetPrivacyStateByDisplayId(id, hasPrivate);
468 WLOGFD("End calling the SetPrivacyStateByDisplayId");
469 }
470
SetScreenPrivacyWindowList(DisplayId id,std::vector<std::string> privacyWindowList)471 void ScreenSessionManagerClient::SetScreenPrivacyWindowList(DisplayId id, std::vector<std::string> privacyWindowList)
472 {
473 if (!screenSessionManager_) {
474 WLOGFE("screenSessionManager_ is null");
475 return;
476 }
477 WLOGFD("Begin calling the SetScreenPrivacyWindowList(), id: %{public}" PRIu64, id);
478 screenSessionManager_->SetScreenPrivacyWindowList(id, privacyWindowList);
479 WLOGFD("End calling the SetScreenPrivacyWindowList()");
480 }
481
UpdateAvailableArea(ScreenId screenId,DMRect area)482 void ScreenSessionManagerClient::UpdateAvailableArea(ScreenId screenId, DMRect area)
483 {
484 if (!screenSessionManager_) {
485 WLOGFE("screenSessionManager_ is null");
486 return;
487 }
488 screenSessionManager_->UpdateAvailableArea(screenId, area);
489 }
490
UpdateSuperFoldAvailableArea(ScreenId screenId,DMRect bArea,DMRect cArea)491 void ScreenSessionManagerClient::UpdateSuperFoldAvailableArea(ScreenId screenId, DMRect bArea, DMRect cArea)
492 {
493 if (!screenSessionManager_) {
494 WLOGFE("screenSessionManager_ is null");
495 return;
496 }
497 screenSessionManager_->UpdateSuperFoldAvailableArea(screenId, bArea, cArea);
498 }
499
UpdateSuperFoldExpandAvailableArea(ScreenId screenId,DMRect area)500 void ScreenSessionManagerClient::UpdateSuperFoldExpandAvailableArea(ScreenId screenId, DMRect area)
501 {
502 if (!screenSessionManager_) {
503 WLOGFE("screenSessionManager_ is null");
504 return;
505 }
506 screenSessionManager_->UpdateSuperFoldExpandAvailableArea(screenId, area);
507 }
508
SetScreenOffDelayTime(int32_t delay)509 int32_t ScreenSessionManagerClient::SetScreenOffDelayTime(int32_t delay)
510 {
511 if (!screenSessionManager_) {
512 WLOGFE("screenSessionManager_ is null");
513 return 0;
514 }
515 return screenSessionManager_->SetScreenOffDelayTime(delay);
516 }
517
SetScreenOnDelayTime(int32_t delay)518 int32_t ScreenSessionManagerClient::SetScreenOnDelayTime(int32_t delay)
519 {
520 if (!screenSessionManager_) {
521 WLOGFE("screenSessionManager_ is null");
522 return 0;
523 }
524 return screenSessionManager_->SetScreenOnDelayTime(delay);
525 }
526
SetCameraStatus(int32_t cameraStatus,int32_t cameraPosition)527 void ScreenSessionManagerClient::SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition)
528 {
529 if (!screenSessionManager_) {
530 WLOGFE("screenSessionManager_ is null");
531 return;
532 }
533 return screenSessionManager_->SetCameraStatus(cameraStatus, cameraPosition);
534 }
535
NotifyFoldToExpandCompletion(bool foldToExpand)536 void ScreenSessionManagerClient::NotifyFoldToExpandCompletion(bool foldToExpand)
537 {
538 if (!screenSessionManager_) {
539 WLOGFE("screenSessionManager_ is null");
540 return;
541 }
542 screenSessionManager_->NotifyFoldToExpandCompletion(foldToExpand);
543 }
544
RecordEventFromScb(std::string description,bool needRecordEvent)545 void ScreenSessionManagerClient::RecordEventFromScb(std::string description, bool needRecordEvent)
546 {
547 if (!screenSessionManager_) {
548 WLOGFE("screenSessionManager_ is null");
549 return;
550 }
551 screenSessionManager_->RecordEventFromScb(description, needRecordEvent);
552 }
553
SwitchUserCallback(std::vector<int32_t> oldScbPids,int32_t currentScbPid)554 void ScreenSessionManagerClient::SwitchUserCallback(std::vector<int32_t> oldScbPids, int32_t currentScbPid)
555 {
556 if (screenSessionManager_ == nullptr) {
557 WLOGFE("screenSessionManager_ is null");
558 return;
559 }
560 if (oldScbPids.size() == 0) {
561 WLOGFE("oldScbPids size 0");
562 return;
563 }
564 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
565 for (const auto& iter : screenSessionMap_) {
566 auto displayNode = screenSessionManager_->GetDisplayNode(iter.first);
567 if (displayNode == nullptr) {
568 WLOGFE("display node is null");
569 continue;
570 }
571 auto transactionProxy = RSTransactionProxy::GetInstance();
572 if (transactionProxy != nullptr) {
573 displayNode->SetScbNodePid(oldScbPids, currentScbPid);
574 transactionProxy->FlushImplicitTransaction();
575 } else {
576 displayNode->SetScbNodePid(oldScbPids, currentScbPid);
577 WLOGFW("transactionProxy is null");
578 }
579 ScreenId screenId = iter.first;
580 sptr<ScreenSession> screenSession = iter.second;
581 if (screenSession == nullptr) {
582 WLOGFE("screenSession is null");
583 return;
584 }
585 ScreenProperty screenProperty = screenSession->GetScreenProperty();
586 RRect bounds = screenProperty.GetBounds();
587 float rotation = screenSession->ConvertRotationToFloat(screenSession->GetRotation());
588 if (FoldScreenStateInternel::IsSuperFoldDisplayDevice()) {
589 UpdatePropertyWhenSwitchUser(screenSession, rotation, bounds, screenId);
590 } else {
591 screenSessionManager_->UpdateScreenRotationProperty(screenId, bounds, rotation,
592 ScreenPropertyChangeType::ROTATION_UPDATE_PROPERTY_ONLY);
593 }
594 }
595 WLOGFI("switch user callback end");
596 }
597
SwitchingCurrentUser()598 void ScreenSessionManagerClient::SwitchingCurrentUser()
599 {
600 if (screenSessionManager_ == nullptr) {
601 WLOGFE("screenSessionManager_ is null");
602 return;
603 }
604 screenSessionManager_->SwitchUser();
605 WLOGFI("switch to current user end");
606 }
607
DisconnectAllExternalScreen()608 void ScreenSessionManagerClient::DisconnectAllExternalScreen()
609 {
610 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
611 for (auto sessionIt = screenSessionMap_.rbegin(); sessionIt != screenSessionMap_.rend(); ++sessionIt) {
612 auto screenSession = sessionIt->second;
613 if (screenSession == nullptr) {
614 TLOGE(WmsLogTag::DMS, "screenSession is nullptr!");
615 continue;
616 }
617 if (screenSession->GetScreenProperty().GetScreenType() == ScreenType::REAL && screenSession->GetIsExtend()) {
618 TLOGI(WmsLogTag::DMS, "disconnect extend screen, screenId = %{public}" PRIu64, sessionIt->first);
619 screenSession->DestroyScreenScene();
620 NotifyScreenDisconnect(screenSession);
621 ScreenId screenId = sessionIt->first;
622 screenSessionMap_.erase(screenId);
623 screenSession->Disconnect();
624 break;
625 }
626 }
627 }
628
GetFoldStatus()629 FoldStatus ScreenSessionManagerClient::GetFoldStatus()
630 {
631 if (!screenSessionManager_) {
632 WLOGFE("screenSessionManager_ is null");
633 return FoldStatus::UNKNOWN;
634 }
635 return screenSessionManager_->GetFoldStatus();
636 }
637
GetSuperFoldStatus()638 SuperFoldStatus ScreenSessionManagerClient::GetSuperFoldStatus()
639 {
640 if (!screenSessionManager_) {
641 WLOGFE("screenSessionManager_ is null");
642 return SuperFoldStatus::UNKNOWN;
643 }
644 return screenSessionManager_->GetSuperFoldStatus();
645 }
646
SetLandscapeLockStatus(bool isLocked)647 void ScreenSessionManagerClient::SetLandscapeLockStatus(bool isLocked)
648 {
649 if (!screenSessionManager_) {
650 WLOGFE("screenSessionManager_ is null");
651 return;
652 }
653 return screenSessionManager_->SetLandscapeLockStatus(isLocked);
654 }
655
GetExtendScreenConnectStatus()656 ExtendScreenConnectStatus ScreenSessionManagerClient::GetExtendScreenConnectStatus()
657 {
658 if (!screenSessionManager_) {
659 WLOGFE("screenSessionManager_ is null");
660 return ExtendScreenConnectStatus::UNKNOWN;
661 }
662 return screenSessionManager_->GetExtendScreenConnectStatus();
663 }
664
GetScreenSnapshot(ScreenId screenId,float scaleX,float scaleY)665 std::shared_ptr<Media::PixelMap> ScreenSessionManagerClient::GetScreenSnapshot(ScreenId screenId,
666 float scaleX, float scaleY)
667 {
668 auto screenSession = GetScreenSession(screenId);
669 if (!screenSession) {
670 WLOGFE("get screen session is null");
671 return nullptr;
672 }
673 return screenSession->GetScreenSnapshot(scaleX, scaleY);
674 }
675
GetDeviceScreenConfig()676 DeviceScreenConfig ScreenSessionManagerClient::GetDeviceScreenConfig()
677 {
678 if (!screenSessionManager_) {
679 TLOGE(WmsLogTag::DMS, "screenSessionManager_ is null");
680 return {};
681 }
682 return screenSessionManager_->GetDeviceScreenConfig();
683 }
684
GetScreenSessionById(const ScreenId id)685 sptr<ScreenSession> ScreenSessionManagerClient::GetScreenSessionById(const ScreenId id)
686 {
687 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
688 auto iter = screenSessionMap_.find(id);
689 if (iter == screenSessionMap_.end()) {
690 return nullptr;
691 }
692 return iter->second;
693 }
694
GetDefaultScreenId()695 ScreenId ScreenSessionManagerClient::GetDefaultScreenId()
696 {
697 std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
698 auto iter = screenSessionMap_.begin();
699 if (iter != screenSessionMap_.end()) {
700 return iter->first;
701 }
702 return SCREEN_ID_INVALID;
703 }
704
IsFoldable()705 bool ScreenSessionManagerClient::IsFoldable()
706 {
707 if (!screenSessionManager_) {
708 WLOGFE("screenSessionManager_ is null");
709 return false;
710 }
711 return screenSessionManager_->IsFoldable();
712 }
713
SetVirtualPixelRatioSystem(ScreenId screenId,float virtualPixelRatio)714 void ScreenSessionManagerClient::SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio)
715 {
716 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
717 if (!screenSession) {
718 WLOGFE("screen session is null");
719 return;
720 }
721 if (screenSession->isScreenGroup_) {
722 WLOGFE("cannot set virtual pixel ratio to the combination. screen: %{public}" PRIu64, screenId);
723 return;
724 }
725 screenSession->SetScreenSceneDpi(virtualPixelRatio);
726 }
727
UpdateDisplayHookInfo(int32_t uid,bool enable,const DMHookInfo & hookInfo)728 void ScreenSessionManagerClient::UpdateDisplayHookInfo(int32_t uid, bool enable, const DMHookInfo& hookInfo)
729 {
730 if (!screenSessionManager_) {
731 WLOGFE("screenSessionManager_ is null");
732 return;
733 }
734 screenSessionManager_->UpdateDisplayHookInfo(uid, enable, hookInfo);
735 }
736
GetDisplayHookInfo(int32_t uid,DMHookInfo & hookInfo)737 void ScreenSessionManagerClient::GetDisplayHookInfo(int32_t uid, DMHookInfo& hookInfo)
738 {
739 if (!screenSessionManager_) {
740 WLOGFE("screenSessionManager_ is null");
741 return;
742 }
743 screenSessionManager_->GetDisplayHookInfo(uid, hookInfo);
744 }
745
OnFoldStatusChangedReportUE(const std::vector<std::string> & screenFoldInfo)746 void ScreenSessionManagerClient::OnFoldStatusChangedReportUE(const std::vector<std::string>& screenFoldInfo)
747 {
748 if (displayChangeListener_) {
749 displayChangeListener_->OnScreenFoldStatusChanged(screenFoldInfo);
750 }
751 }
752
UpdateDisplayScale(ScreenId id,float scaleX,float scaleY,float pivotX,float pivotY,float translateX,float translateY)753 void ScreenSessionManagerClient::UpdateDisplayScale(ScreenId id, float scaleX, float scaleY, float pivotX, float pivotY,
754 float translateX, float translateY)
755 {
756 auto session = GetScreenSession(id);
757 if (session == nullptr) {
758 TLOGE(WmsLogTag::DMS, "session is null");
759 return;
760 }
761 auto displayNode = session->GetDisplayNode();
762 if (displayNode == nullptr) {
763 TLOGE(WmsLogTag::DMS, "displayNode is null");
764 return;
765 }
766 TLOGD(WmsLogTag::DMS, "scale [%{public}f, %{public}f] translate [%{public}f, %{public}f]", scaleX, scaleY,
767 translateX, translateY);
768 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER,
769 "ssmc:UpdateDisplayScale(ScreenId = %" PRIu64
770 " scaleX=%f, scaleY=%f, pivotX=%f, pivotY=%f, translateX=%f, translateY=%f",
771 id, scaleX, scaleY, pivotX, pivotY, translateX, translateY);
772 session->SetScreenScale(scaleX, scaleY, pivotX, pivotY, translateX, translateY);
773 session->PropertyChange(session->GetScreenProperty(), ScreenPropertyChangeReason::ACCESS_INFO_CHANGE);
774 }
775
ScreenCaptureNotify(ScreenId mainScreenId,int32_t uid,const std::string & clientName)776 void ScreenSessionManagerClient::ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName)
777 {
778 sptr<ScreenSession> screenSession = GetScreenSession(mainScreenId);
779 if (!screenSession) {
780 WLOGFE("screen session is null");
781 return;
782 }
783 WLOGFI("capture screenId: %{public}" PRIu64", uid=%{public}d", mainScreenId, uid);
784 screenSession->ScreenCaptureNotify(mainScreenId, uid, clientName);
785 }
786
OnSuperFoldStatusChanged(ScreenId screenId,SuperFoldStatus superFoldStatus)787 void ScreenSessionManagerClient::OnSuperFoldStatusChanged(ScreenId screenId, SuperFoldStatus superFoldStatus)
788 {
789 currentstate_ = superFoldStatus;
790 auto screenSession = GetScreenSession(screenId);
791 if (!screenSession) {
792 WLOGFE("screenSession is null");
793 return;
794 }
795 WLOGI("screenId=%{public}" PRIu64 " superFoldStatus=%{public}d", screenId,
796 static_cast<uint32_t>(superFoldStatus));
797 screenSession->SuperFoldStatusChange(screenId, superFoldStatus);
798 }
799
OnSecondaryReflexionChanged(ScreenId screenId,bool isSecondaryReflexion)800 void ScreenSessionManagerClient::OnSecondaryReflexionChanged(ScreenId screenId, bool isSecondaryReflexion)
801 {
802 auto screenSession = GetScreenSession(screenId);
803 if (!screenSession) {
804 WLOGFE("screenSession is null");
805 return;
806 }
807 WLOGI("screenId=%{public}" PRIu64 " isSecondaryReflexion=%{public}d", screenId, isSecondaryReflexion);
808 screenSession->SecondaryReflexionChange(screenId, isSecondaryReflexion);
809 }
810
OnExtendScreenConnectStatusChanged(ScreenId screenId,ExtendScreenConnectStatus extendScreenConnectStatus)811 void ScreenSessionManagerClient::OnExtendScreenConnectStatusChanged(ScreenId screenId,
812 ExtendScreenConnectStatus extendScreenConnectStatus)
813 {
814 auto screenSession = GetScreenSession(GetDefaultScreenId());
815 if (!screenSession) {
816 WLOGFE("screenSession is null");
817 return;
818 }
819 WLOGI("screenId=%{public}" PRIu64 " extendScreenConnectStatus=%{public}d", screenId,
820 static_cast<uint32_t>(extendScreenConnectStatus));
821 screenSession->ExtendScreenConnectStatusChange(screenId, extendScreenConnectStatus);
822 }
823
UpdatePropertyWhenSwitchUser(const sptr<ScreenSession> & screenSession,float rotation,RRect bounds,ScreenId screenId)824 void ScreenSessionManagerClient::UpdatePropertyWhenSwitchUser(const sptr <ScreenSession>& screenSession,
825 float rotation, RRect bounds, ScreenId screenId)
826 {
827 screenSession->UpdateToInputManager(bounds, static_cast<int>(rotation), static_cast<int>(rotation),
828 FoldDisplayMode::UNKNOWN, screenSessionManager_->IsOrientationNeedChanged());
829 screenSession->SetPhysicalRotation(rotation);
830 screenSession->SetScreenComponentRotation(rotation);
831 screenSession->SetValidHeight(bounds.rect_.GetHeight());
832 screenSession->SetValidWidth(bounds.rect_.GetWidth());
833 screenSessionManager_->UpdateScreenDirectionInfo(screenId, rotation, rotation, rotation,
834 ScreenPropertyChangeType::UNSPECIFIED);
835 screenSessionManager_->UpdateScreenRotationProperty(screenId, bounds, rotation,
836 ScreenPropertyChangeType::UNSPECIFIED);
837 }
838 } // namespace OHOS::Rosen