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 "session_manager/include/screen_session_manager.h"
17
18 #include <hitrace_meter.h>
19 #include <iomanip>
20 #include <parameters.h>
21 #include <transaction/rs_interfaces.h>
22 #include <xcollie/watchdog.h>
23
24 #include "session_permission.h"
25 #include "screen_scene_config.h"
26 #include "surface_capture_future.h"
27 #include "sys_cap_util.h"
28 #include "window_manager_hilog.h"
29 #include "screen_rotation_property.h"
30 #include "screen_sensor_connector.h"
31
32 namespace OHOS::Rosen {
33 namespace {
34 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ScreenSessionManager" };
35 const std::string SCREEN_SESSION_MANAGER_THREAD = "ScreenSessionManager";
36 const std::string SCREEN_CAPTURE_PERMISSION = "ohos.permission.CAPTURE_SCREEN";
37 std::recursive_mutex g_instanceMutex;
38 } // namespace
39
GetInstance()40 ScreenSessionManager& ScreenSessionManager::GetInstance()
41 {
42 std::lock_guard<std::recursive_mutex> lock(g_instanceMutex);
43 static ScreenSessionManager* instance = nullptr;
44 if (instance == nullptr) {
45 instance = new ScreenSessionManager();
46 instance->Init();
47 }
48 return *instance;
49 }
50
ScreenSessionManager()51 ScreenSessionManager::ScreenSessionManager() : rsInterface_(RSInterfaces::GetInstance())
52 {
53 LoadScreenSceneXml();
54 taskScheduler_ = std::make_shared<TaskScheduler>(SCREEN_SESSION_MANAGER_THREAD);
55 screenCutoutController_ = new (std::nothrow) ScreenCutoutController();
56 sessionDisplayPowerController_ = new SessionDisplayPowerController(
57 std::bind(&ScreenSessionManager::NotifyDisplayStateChange, this,
58 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
59 }
60
Init()61 void ScreenSessionManager::Init()
62 {
63 constexpr uint64_t interval = 5 * 1000; // 5 second
64 if (HiviewDFX::Watchdog::GetInstance().AddThread(
65 SCREEN_SESSION_MANAGER_THREAD, taskScheduler_->GetEventHandler(), interval)) {
66 WLOGFW("Add thread %{public}s to watchdog failed.", SCREEN_SESSION_MANAGER_THREAD.c_str());
67 }
68
69 RegisterScreenChangeListener();
70 }
71
RegisterScreenConnectionListener(sptr<IScreenConnectionListener> & screenConnectionListener)72 void ScreenSessionManager::RegisterScreenConnectionListener(sptr<IScreenConnectionListener>& screenConnectionListener)
73 {
74 if (screenConnectionListener == nullptr) {
75 WLOGFE("Failed to register screen connection callback, callback is null!");
76 return;
77 }
78
79 if (std::find(screenConnectionListenerList_.begin(), screenConnectionListenerList_.end(),
80 screenConnectionListener) != screenConnectionListenerList_.end()) {
81 WLOGFE("Repeat to register screen connection callback!");
82 return;
83 }
84
85 screenConnectionListenerList_.emplace_back(screenConnectionListener);
86
87 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
88 for (auto& iter : screenSessionMap_) {
89 screenConnectionListener->OnScreenConnect(iter.second);
90 }
91 }
92
UnregisterScreenConnectionListener(sptr<IScreenConnectionListener> & screenConnectionListener)93 void ScreenSessionManager::UnregisterScreenConnectionListener(sptr<IScreenConnectionListener>& screenConnectionListener)
94 {
95 if (screenConnectionListener == nullptr) {
96 WLOGFE("Failed to unregister screen connection listener, listener is null!");
97 return;
98 }
99
100 screenConnectionListenerList_.erase(
101 std::remove_if(screenConnectionListenerList_.begin(), screenConnectionListenerList_.end(),
102 [screenConnectionListener](
103 sptr<IScreenConnectionListener> listener) { return screenConnectionListener == listener; }),
104 screenConnectionListenerList_.end());
105 }
106
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)107 DMError ScreenSessionManager::RegisterDisplayManagerAgent(
108 const sptr<IDisplayManagerAgent>& displayManagerAgent, DisplayManagerAgentType type)
109 {
110 if (type == DisplayManagerAgentType::SCREEN_EVENT_LISTENER && !SessionPermission::IsSystemCalling()
111 && !SessionPermission::IsStartByHdcd()) {
112 WLOGFE("register display manager agent permission denied!");
113 return DMError::DM_ERROR_NOT_SYSTEM_APP;
114 }
115 if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) {
116 WLOGFE("displayManagerAgent invalid");
117 return DMError::DM_ERROR_NULLPTR;
118 }
119
120 return dmAgentContainer_.RegisterAgent(displayManagerAgent, type) ? DMError::DM_OK :DMError::DM_ERROR_NULLPTR;
121 }
122
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)123 DMError ScreenSessionManager::UnregisterDisplayManagerAgent(
124 const sptr<IDisplayManagerAgent>& displayManagerAgent, DisplayManagerAgentType type)
125 {
126 if (type == DisplayManagerAgentType::SCREEN_EVENT_LISTENER && !SessionPermission::IsSystemCalling()
127 && !SessionPermission::IsStartByHdcd()) {
128 WLOGFE("unregister display manager agent permission denied!");
129 return DMError::DM_ERROR_NOT_SYSTEM_APP;
130 }
131 if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) {
132 WLOGFE("displayManagerAgent invalid");
133 return DMError::DM_ERROR_NULLPTR;
134 }
135
136 return dmAgentContainer_.UnregisterAgent(displayManagerAgent, type) ? DMError::DM_OK :DMError::DM_ERROR_NULLPTR;
137 }
138
LoadScreenSceneXml()139 void ScreenSessionManager::LoadScreenSceneXml()
140 {
141 if (ScreenSceneConfig::LoadConfigXml()) {
142 ScreenSceneConfig::DumpConfig();
143 ConfigureScreenScene();
144 }
145 }
146
ConfigureScreenScene()147 void ScreenSessionManager::ConfigureScreenScene()
148 {
149 auto numbersConfig = ScreenSceneConfig::GetIntNumbersConfig();
150 auto enableConfig = ScreenSceneConfig::GetEnableConfig();
151 auto stringConfig = ScreenSceneConfig::GetStringConfig();
152 if (numbersConfig.count("dpi") != 0) {
153 uint32_t densityDpi = static_cast<uint32_t>(numbersConfig["dpi"][0]);
154 WLOGFD("densityDpi = %u", densityDpi);
155 if (densityDpi >= DOT_PER_INCH_MINIMUM_VALUE && densityDpi <= DOT_PER_INCH_MAXIMUM_VALUE) {
156 isDensityDpiLoad_ = true;
157 densityDpi_ = static_cast<float>(densityDpi) / BASELINE_DENSITY;
158 }
159 }
160 if (numbersConfig.count("defaultDeviceRotationOffset") != 0) {
161 uint32_t defaultDeviceRotationOffset = static_cast<uint32_t>(numbersConfig["defaultDeviceRotationOffset"][0]);
162 WLOGFD("defaultDeviceRotationOffset = %u", defaultDeviceRotationOffset);
163 }
164 if (enableConfig.count("isWaterfallDisplay") != 0) {
165 bool isWaterfallDisplay = static_cast<bool>(enableConfig["isWaterfallDisplay"]);
166 WLOGFD("isWaterfallDisplay = %d", isWaterfallDisplay);
167 }
168 if (numbersConfig.count("curvedScreenBoundary") != 0) {
169 std::vector<int> vtBoundary = static_cast<std::vector<int>>(numbersConfig["curvedScreenBoundary"]);
170 WLOGFD("vtBoundary");
171 }
172 if (stringConfig.count("defaultDisplayCutoutPath") != 0) {
173 std::string defaultDisplayCutoutPath = static_cast<std::string>(stringConfig["defaultDisplayCutoutPath"]);
174 WLOGFD("defaultDisplayCutoutPath = %{public}s.", defaultDisplayCutoutPath.c_str());
175 ScreenSceneConfig::SetCutoutSvgPath(defaultDisplayCutoutPath);
176 }
177 ConfigureWaterfallDisplayCompressionParams();
178
179 if (numbersConfig.count("buildInDefaultOrientation") != 0) {
180 Orientation orientation = static_cast<Orientation>(numbersConfig["buildInDefaultOrientation"][0]);
181 WLOGFD("orientation = %d", orientation);
182 }
183 }
184
ConfigureWaterfallDisplayCompressionParams()185 void ScreenSessionManager::ConfigureWaterfallDisplayCompressionParams()
186 {
187 auto numbersConfig = ScreenSceneConfig::GetIntNumbersConfig();
188 auto enableConfig = ScreenSceneConfig::GetEnableConfig();
189 if (enableConfig.count("isWaterfallAreaCompressionEnableWhenHorizontal") != 0) {
190 bool enable = static_cast<bool>(enableConfig["isWaterfallAreaCompressionEnableWhenHorizontal"]);
191 WLOGD("isWaterfallAreaCompressionEnableWhenHorizontal=%d.", enable);
192 }
193 ScreenSceneConfig::SetCurvedCompressionAreaInLandscape();
194 }
195
RegisterScreenChangeListener()196 void ScreenSessionManager::RegisterScreenChangeListener()
197 {
198 WLOGFD("Register screen change listener.");
199 auto res = rsInterface_.SetScreenChangeCallback(
200 [this](ScreenId screenId, ScreenEvent screenEvent) { OnScreenChange(screenId, screenEvent); });
201 if (res != StatusCode::SUCCESS) {
202 auto task = [this]() { RegisterScreenChangeListener(); };
203 taskScheduler_->PostAsyncTask(task, 50); // Retry after 50 ms.
204 }
205 }
206
OnScreenChange(ScreenId screenId,ScreenEvent screenEvent)207 void ScreenSessionManager::OnScreenChange(ScreenId screenId, ScreenEvent screenEvent)
208 {
209 WLOGFI("SCB: On screen change. ScreenId: %{public}" PRIu64 ", ScreenEvent: %{public}d", screenId,
210 static_cast<int>(screenEvent));
211 auto screenSession = GetOrCreateScreenSession(screenId);
212 if (!screenSession) {
213 WLOGFE("screenSession is nullptr");
214 return;
215 }
216 if (screenEvent == ScreenEvent::CONNECTED) {
217 for (auto listener : screenConnectionListenerList_) {
218 listener->OnScreenConnect(screenSession);
219 }
220 screenSession->Connect();
221 } else if (screenEvent == ScreenEvent::DISCONNECTED) {
222 screenSession->Disconnect();
223 for (auto listener : screenConnectionListenerList_) {
224 listener->OnScreenDisconnect(screenSession);
225 }
226 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
227 screenSessionMap_.erase(screenId);
228 }
229 }
230
GetScreenSession(ScreenId screenId) const231 sptr<ScreenSession> ScreenSessionManager::GetScreenSession(ScreenId screenId) const
232 {
233 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
234 auto iter = screenSessionMap_.find(screenId);
235 if (iter == screenSessionMap_.end()) {
236 WLOGFE("Error found screen session with id: %{public}" PRIu64, screenId);
237 return nullptr;
238 }
239 return iter->second;
240 }
241
GetDefaultDisplayInfo()242 sptr<DisplayInfo> ScreenSessionManager::GetDefaultDisplayInfo()
243 {
244 GetDefaultScreenId();
245 sptr<ScreenSession> screenSession = GetScreenSession(defaultScreenId_);
246 if (screenSession) {
247 return screenSession->ConvertToDisplayInfo();
248 } else {
249 WLOGFE("Get default screen session failed.");
250 return nullptr;
251 }
252 }
253
GetDisplayInfoById(DisplayId displayId)254 sptr<DisplayInfo> ScreenSessionManager::GetDisplayInfoById(DisplayId displayId)
255 {
256 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
257 for (auto sessionIt : screenSessionMap_) {
258 auto screenSession = sessionIt.second;
259 if (screenSession == nullptr) {
260 continue;
261 }
262 sptr<DisplayInfo> displayInfo = screenSession->ConvertToDisplayInfo();
263 if (displayInfo == nullptr) {
264 WLOGFE("ConvertToDisplayInfo error, displayInfo is nullptr.");
265 continue;
266 }
267 if (displayId == displayInfo->GetDisplayId()) {
268 return displayInfo;
269 }
270 }
271 WLOGFE("SCB: ScreenSessionManager::GetDisplayInfoById failed.");
272 return nullptr;
273 }
274
GetDisplayInfoByScreen(ScreenId screenId)275 sptr<DisplayInfo> ScreenSessionManager::GetDisplayInfoByScreen(ScreenId screenId)
276 {
277 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
278 for (auto sessionIt : screenSessionMap_) {
279 auto screenSession = sessionIt.second;
280 sptr<DisplayInfo> displayInfo = screenSession->ConvertToDisplayInfo();
281 if (screenId == displayInfo->GetScreenId()) {
282 return displayInfo;
283 }
284 }
285 WLOGFE("SCB: ScreenSessionManager::GetDisplayInfoByScreen failed.");
286 return nullptr;
287 }
288
GetAllDisplayIds()289 std::vector<DisplayId> ScreenSessionManager::GetAllDisplayIds()
290 {
291 std::vector<DisplayId> res;
292 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
293 for (auto sessionIt : screenSessionMap_) {
294 auto screenSession = sessionIt.second;
295 sptr<DisplayInfo> displayInfo = screenSession->ConvertToDisplayInfo();
296 DisplayId displayId = displayInfo->GetDisplayId();
297 res.push_back(displayId);
298 }
299 return res;
300 }
301
GetScreenInfoById(ScreenId screenId)302 sptr<ScreenInfo> ScreenSessionManager::GetScreenInfoById(ScreenId screenId)
303 {
304 auto screenSession = GetOrCreateScreenSession(screenId);
305 if (screenSession == nullptr) {
306 WLOGE("SCB: ScreenSessionManager::GetScreenInfoById cannot find screenInfo: %{public}" PRIu64"", screenId);
307 return nullptr;
308 }
309 return screenSession->ConvertToScreenInfo();
310 }
311
SetScreenActiveMode(ScreenId screenId,uint32_t modeId)312 DMError ScreenSessionManager::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
313 {
314 WLOGI("SetScreenActiveMode: ScreenId: %{public}" PRIu64", modeId: %{public}u", screenId, modeId);
315 if (!SessionPermission::IsSystemCalling() && !SessionPermission::IsStartByHdcd()) {
316 WLOGFE("set screen active permission denied!");
317 return DMError::DM_ERROR_NOT_SYSTEM_APP;
318 }
319 if (screenId == SCREEN_ID_INVALID) {
320 WLOGFE("SetScreenActiveMode: invalid screenId");
321 return DMError::DM_ERROR_NULLPTR;
322 }
323 {
324 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
325 if (screenSession == nullptr) {
326 WLOGFE("SetScreenActiveMode: Get ScreenSession failed");
327 return DMError::DM_ERROR_NULLPTR;
328 }
329 ScreenId rsScreenId = SCREEN_ID_INVALID;
330 if (!screenIdManager_.ConvertToRsScreenId(screenId, rsScreenId)) {
331 WLOGFE("SetScreenActiveMode: No corresponding rsId");
332 return DMError::DM_ERROR_NULLPTR;
333 }
334 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:SetScreenActiveMode(%" PRIu64", %u)", screenId, modeId);
335 rsInterface_.SetScreenActiveMode(rsScreenId, modeId);
336 screenSession->activeIdx_ = static_cast<int32_t>(modeId);
337 screenSession->UpdatePropertyByActiveMode();
338 screenSession->PropertyChange(screenSession->GetScreenProperty(), ScreenPropertyChangeReason::CHANGE_MODE);
339 NotifyScreenChanged(screenSession->ConvertToScreenInfo(), ScreenChangeEvent::CHANGE_MODE);
340 }
341 return DMError::DM_OK;
342 }
343
NotifyScreenChanged(sptr<ScreenInfo> screenInfo,ScreenChangeEvent event)344 void ScreenSessionManager::NotifyScreenChanged(sptr<ScreenInfo> screenInfo, ScreenChangeEvent event)
345 {
346 if (screenInfo == nullptr) {
347 WLOGFE("NotifyScreenChanged error, screenInfo is nullptr.");
348 return;
349 }
350 auto task = [=] {
351 WLOGFI("NotifyScreenChanged, screenId:%{public}" PRIu64"", screenInfo->GetScreenId());
352 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
353 if (agents.empty()) {
354 return;
355 }
356 for (auto& agent : agents) {
357 agent->OnScreenChange(screenInfo, event);
358 }
359 };
360 taskScheduler_->PostAsyncTask(task);
361 }
362
SetVirtualPixelRatio(ScreenId screenId,float virtualPixelRatio)363 DMError ScreenSessionManager::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)
364 {
365 if (!SessionPermission::IsSystemCalling() && !SessionPermission::IsStartByHdcd()) {
366 WLOGFE("set virtual pixel permission denied!");
367 return DMError::DM_ERROR_NOT_SYSTEM_APP;
368 }
369
370 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
371 if (!screenSession) {
372 WLOGFE("screen session is nullptr");
373 return DMError::DM_ERROR_UNKNOWN;
374 }
375 if (screenSession->isScreenGroup_) {
376 WLOGE("cannot set virtual pixel ratio to the combination. screen: %{public}" PRIu64"", screenId);
377 return DMError::DM_ERROR_NULLPTR;
378 }
379 if (fabs(screenSession->GetScreenProperty().GetVirtualPixelRatio() - virtualPixelRatio) < 1e-6) {
380 WLOGE("The density is equivalent to the original value, no update operation is required, aborted.");
381 return DMError::DM_OK;
382 }
383 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:SetVirtualPixelRatio(%" PRIu64", %f)", screenId,
384 virtualPixelRatio);
385 screenSession->SetVirtualPixelRatio(virtualPixelRatio);
386 NotifyScreenChanged(screenSession->ConvertToScreenInfo(), ScreenChangeEvent::VIRTUAL_PIXEL_RATIO_CHANGED);
387
388 return DMError::DM_OK;
389 }
390
GetScreenColorGamut(ScreenId screenId,ScreenColorGamut & colorGamut)391 DMError ScreenSessionManager::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut)
392 {
393 WLOGFI("GetScreenColorGamut::ScreenId: %{public}" PRIu64 "", screenId);
394 if (screenId == SCREEN_ID_INVALID) {
395 WLOGFE("screenId invalid");
396 return DMError::DM_ERROR_INVALID_PARAM;
397 }
398 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
399 if (screenSession == nullptr) {
400 return DMError::DM_ERROR_INVALID_PARAM;
401 }
402 return screenSession->GetScreenColorGamut(colorGamut);
403 }
404
SetScreenColorGamut(ScreenId screenId,int32_t colorGamutIdx)405 DMError ScreenSessionManager::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx)
406 {
407 WLOGFI("SetScreenColorGamut::ScreenId: %{public}" PRIu64 ", colorGamutIdx %{public}d", screenId, colorGamutIdx);
408 if (screenId == SCREEN_ID_INVALID) {
409 WLOGFE("screenId invalid");
410 return DMError::DM_ERROR_INVALID_PARAM;
411 }
412 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
413 if (screenSession == nullptr) {
414 return DMError::DM_ERROR_INVALID_PARAM;
415 }
416 return screenSession->SetScreenColorGamut(colorGamutIdx);
417 }
418
GetScreenGamutMap(ScreenId screenId,ScreenGamutMap & gamutMap)419 DMError ScreenSessionManager::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap)
420 {
421 WLOGFI("GetScreenGamutMap::ScreenId: %{public}" PRIu64 "", screenId);
422 if (screenId == SCREEN_ID_INVALID) {
423 WLOGFE("screenId invalid");
424 return DMError::DM_ERROR_INVALID_PARAM;
425 }
426 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
427 if (screenSession == nullptr) {
428 return DMError::DM_ERROR_INVALID_PARAM;
429 }
430 return screenSession->GetScreenGamutMap(gamutMap);
431 }
432
SetScreenGamutMap(ScreenId screenId,ScreenGamutMap gamutMap)433 DMError ScreenSessionManager::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap)
434 {
435 WLOGFI("SetScreenGamutMap::ScreenId: %{public}" PRIu64 ", ScreenGamutMap %{public}u",
436 screenId, static_cast<uint32_t>(gamutMap));
437 if (screenId == SCREEN_ID_INVALID) {
438 WLOGFE("screenId invalid");
439 return DMError::DM_ERROR_INVALID_PARAM;
440 }
441 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
442 if (screenSession == nullptr) {
443 return DMError::DM_ERROR_INVALID_PARAM;
444 }
445 return screenSession->SetScreenGamutMap(gamutMap);
446 }
447
SetScreenColorTransform(ScreenId screenId)448 DMError ScreenSessionManager::SetScreenColorTransform(ScreenId screenId)
449 {
450 WLOGFI("SetScreenColorTransform::ScreenId: %{public}" PRIu64 "", screenId);
451 if (screenId == SCREEN_ID_INVALID) {
452 WLOGFE("screenId invalid");
453 return DMError::DM_ERROR_INVALID_PARAM;
454 }
455 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
456 if (screenSession == nullptr) {
457 return DMError::DM_ERROR_INVALID_PARAM;
458 }
459 return screenSession->SetScreenColorTransform();
460 }
461
GetOrCreateScreenSession(ScreenId screenId)462 sptr<ScreenSession> ScreenSessionManager::GetOrCreateScreenSession(ScreenId screenId)
463 {
464 WLOGFI("SCB: ScreenSessionManager::GetOrCreateScreenSession ENTER");
465 {
466 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
467 auto sessionIt = screenSessionMap_.find(screenId);
468 if (sessionIt != screenSessionMap_.end()) {
469 return sessionIt->second;
470 }
471 }
472
473 ScreenId rsId = rsInterface_.GetDefaultScreenId();
474 screenIdManager_.UpdateScreenId(rsId, screenId);
475
476 auto screenMode = rsInterface_.GetScreenActiveMode(screenId);
477 auto screenBounds = RRect({ 0, 0, screenMode.GetScreenWidth(), screenMode.GetScreenHeight() }, 0.0f, 0.0f);
478 auto screenRefreshRate = screenMode.GetScreenRefreshRate();
479 auto screenCapability = rsInterface_.GetScreenCapability(screenId);
480 ScreenProperty property;
481 property.SetRotation(0.0f);
482 property.SetBounds(screenBounds);
483 if (isDensityDpiLoad_) {
484 property.SetVirtualPixelRatio(densityDpi_);
485 } else {
486 property.UpdateVirtualPixelRatio(screenBounds);
487 }
488 property.SetRefreshRate(screenRefreshRate);
489 property.SetPhyWidth(screenCapability.GetPhyWidth());
490 property.SetPhyHeight(screenCapability.GetPhyHeight());
491 sptr<ScreenSession> session = new(std::nothrow) ScreenSession(screenId, property, GetDefaultAbstractScreenId());
492 if (!session) {
493 WLOGFE("screen session is nullptr");
494 return session;
495 }
496 InitAbstractScreenModesInfo(session);
497 session->groupSmsId_ = 1;
498 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
499 screenSessionMap_[screenId] = session;
500 return session;
501 }
502
GetDefaultScreenId()503 ScreenId ScreenSessionManager::GetDefaultScreenId()
504 {
505 if (defaultScreenId_ == INVALID_SCREEN_ID) {
506 defaultScreenId_ = rsInterface_.GetDefaultScreenId();
507 }
508 return defaultScreenId_;
509 }
510
WakeUpBegin(PowerStateChangeReason reason)511 bool ScreenSessionManager::WakeUpBegin(PowerStateChangeReason reason)
512 {
513 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:WakeUpBegin(%u)", reason);
514 return NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, EventStatus::BEGIN);
515 }
516
WakeUpEnd()517 bool ScreenSessionManager::WakeUpEnd()
518 {
519 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:WakeUpEnd");
520 return NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, EventStatus::END);
521 }
522
SuspendBegin(PowerStateChangeReason reason)523 bool ScreenSessionManager::SuspendBegin(PowerStateChangeReason reason)
524 {
525 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:SuspendBegin(%u)", reason);
526 sessionDisplayPowerController_->SuspendBegin(reason);
527 return NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, EventStatus::BEGIN);
528 }
529
SuspendEnd()530 bool ScreenSessionManager::SuspendEnd()
531 {
532 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:SuspendEnd");
533 return NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, EventStatus::END);
534 }
535
SetDisplayState(DisplayState state)536 bool ScreenSessionManager::SetDisplayState(DisplayState state)
537 {
538 return sessionDisplayPowerController_->SetDisplayState(state);
539 }
540
NotifyDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)541 void ScreenSessionManager::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
542 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
543 {
544 if (displayChangeListener_ != nullptr) {
545 displayChangeListener_->OnDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
546 }
547 }
548
NotifyScreenshot(DisplayId displayId)549 void ScreenSessionManager::NotifyScreenshot(DisplayId displayId)
550 {
551 if (displayChangeListener_ != nullptr) {
552 displayChangeListener_->OnScreenshot(displayId);
553 }
554 }
555
SetScreenPowerForAll(ScreenPowerState state,PowerStateChangeReason reason)556 bool ScreenSessionManager::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
557 {
558 auto screenIds = GetAllScreenIds();
559 if (screenIds.empty()) {
560 WLOGFE("no screen info");
561 return false;
562 }
563
564 ScreenPowerStatus status;
565 switch (state) {
566 case ScreenPowerState::POWER_ON: {
567 status = ScreenPowerStatus::POWER_STATUS_ON;
568 break;
569 }
570 case ScreenPowerState::POWER_OFF: {
571 status = ScreenPowerStatus::POWER_STATUS_OFF;
572 break;
573 }
574 default: {
575 WLOGFW("SetScreenPowerStatus state not support");
576 return false;
577 }
578 }
579
580 for (auto screenId : screenIds) {
581 rsInterface_.SetScreenPowerStatus(screenId, status);
582 }
583
584 return NotifyDisplayPowerEvent(state == ScreenPowerState::POWER_ON ? DisplayPowerEvent::DISPLAY_ON :
585 DisplayPowerEvent::DISPLAY_OFF, EventStatus::END);
586 }
587
GetAllScreenIds()588 std::vector<ScreenId> ScreenSessionManager::GetAllScreenIds()
589 {
590 std::vector<ScreenId> res;
591 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
592 for (const auto& iter : screenSessionMap_) {
593 res.emplace_back(iter.first);
594 }
595 return res;
596 }
597
GetDisplayState(DisplayId displayId)598 DisplayState ScreenSessionManager::GetDisplayState(DisplayId displayId)
599 {
600 return sessionDisplayPowerController_->GetDisplayState(displayId);
601 }
602
NotifyDisplayEvent(DisplayEvent event)603 void ScreenSessionManager::NotifyDisplayEvent(DisplayEvent event)
604 {
605 sessionDisplayPowerController_->NotifyDisplayEvent(event);
606 }
607
GetScreenPower(ScreenId screenId)608 ScreenPowerState ScreenSessionManager::GetScreenPower(ScreenId screenId)
609 {
610 auto state = static_cast<ScreenPowerState>(RSInterfaces::GetInstance().GetScreenPowerStatus(screenId));
611 WLOGFI("GetScreenPower:%{public}u, rsscreen:%{public}" PRIu64".", state, screenId);
612 return state;
613 }
614
IsScreenRotationLocked(bool & isLocked)615 DMError ScreenSessionManager::IsScreenRotationLocked(bool& isLocked)
616 {
617 if (!SessionPermission::IsSystemCalling() && !SessionPermission::IsStartByHdcd()) {
618 WLOGFE("SCB: ScreenSessionManager is screen rotation locked permission denied!");
619 return DMError::DM_ERROR_NOT_SYSTEM_APP;
620 }
621 isLocked = ScreenRotationProperty::IsScreenRotationLocked();
622 WLOGFI("SCB: IsScreenRotationLocked:isLocked: %{public}u", isLocked);
623 return DMError::DM_OK;
624 }
625
SetScreenRotationLocked(bool isLocked)626 DMError ScreenSessionManager::SetScreenRotationLocked(bool isLocked)
627 {
628 if (!SessionPermission::IsSystemCalling() && !SessionPermission::IsStartByHdcd()) {
629 WLOGFE("SCB: ScreenSessionManager set screen rotation locked permission denied!");
630 return DMError::DM_ERROR_NOT_SYSTEM_APP;
631 }
632 WLOGFI("SCB: SetScreenRotationLocked: isLocked: %{public}u", isLocked);
633 return ScreenRotationProperty::SetScreenRotationLocked(isLocked);
634 }
635
UpdateScreenRotationProperty(ScreenId screenId,RRect bounds,int rotation)636 void ScreenSessionManager::UpdateScreenRotationProperty(ScreenId screenId, RRect bounds, int rotation)
637 {
638 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
639 if (screenSession == nullptr) {
640 WLOGFE("fail to update screen rotation property, cannot find screen %{public}" PRIu64"", screenId);
641 return;
642 }
643 Rotation targetRotation = Rotation::ROTATION_0;
644 switch (rotation) {
645 case 90: // Rotation 90 degree
646 targetRotation = Rotation::ROTATION_90;
647 break;
648 case 180: // Rotation 180 degree
649 targetRotation = Rotation::ROTATION_180;
650 break;
651 case 270: // Rotation 270 degree
652 targetRotation = Rotation::ROTATION_270;
653 break;
654 default:
655 targetRotation = Rotation::ROTATION_0;
656 break;
657 }
658 sptr<DisplayInfo> displayInfo = screenSession->ConvertToDisplayInfo();
659 displayInfo->SetRotation(targetRotation);
660 displayInfo->SetWidth(bounds.rect_.GetWidth());
661 displayInfo->SetHeight(bounds.rect_.GetHeight());
662 NotifyDisplayChanged(displayInfo, DisplayChangeEvent::DISPLAY_SIZE_CHANGED);
663 }
664
NotifyDisplayChanged(sptr<DisplayInfo> displayInfo,DisplayChangeEvent event)665 void ScreenSessionManager::NotifyDisplayChanged(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event)
666 {
667 if (displayInfo == nullptr) {
668 WLOGFE("NotifyDisplayChanged error, displayInfo is nullptr.");
669 return;
670 }
671 auto task = [=] {
672 WLOGFI("NotifyDisplayChanged, displayId:%{public}" PRIu64"", displayInfo->GetDisplayId());
673 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
674 if (agents.empty()) {
675 return;
676 }
677 for (auto& agent : agents) {
678 agent->OnDisplayChange(displayInfo, event);
679 }
680 };
681 taskScheduler_->PostAsyncTask(task);
682 }
683
SetOrientation(ScreenId screenId,Orientation orientation)684 DMError ScreenSessionManager::SetOrientation(ScreenId screenId, Orientation orientation)
685 {
686 if (!SessionPermission::IsSystemCalling() && !SessionPermission::IsStartByHdcd()) {
687 WLOGFE("SCB: ScreenSessionManager set orientation permission denied!");
688 return DMError::DM_ERROR_NOT_SYSTEM_APP;
689 }
690 if (orientation < Orientation::UNSPECIFIED || orientation > Orientation::REVERSE_HORIZONTAL) {
691 WLOGFE("SCB: ScreenSessionManager set orientation: %{public}u", static_cast<uint32_t>(orientation));
692 return DMError::DM_ERROR_INVALID_PARAM;
693 }
694 return SetOrientationController(screenId, orientation, false);
695 }
696
SetOrientationFromWindow(DisplayId displayId,Orientation orientation)697 DMError ScreenSessionManager::SetOrientationFromWindow(DisplayId displayId, Orientation orientation)
698 {
699 sptr<DisplayInfo> displayInfo = GetDisplayInfoById(displayId);
700 if (displayInfo == nullptr) {
701 return DMError::DM_ERROR_NULLPTR;
702 }
703 return SetOrientationController(displayInfo->GetScreenId(), orientation, true);
704 }
705
SetOrientationController(ScreenId screenId,Orientation newOrientation,bool isFromWindow)706 DMError ScreenSessionManager::SetOrientationController(ScreenId screenId, Orientation newOrientation,
707 bool isFromWindow)
708 {
709 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
710 if (screenSession == nullptr) {
711 WLOGFE("fail to set orientation, cannot find screen %{public}" PRIu64"", screenId);
712 return DMError::DM_ERROR_NULLPTR;
713 }
714
715 if (isFromWindow) {
716 if (newOrientation == Orientation::UNSPECIFIED) {
717 newOrientation = screenSession->GetScreenRequestedOrientation();
718 }
719 } else {
720 screenSession->SetScreenRequestedOrientation(newOrientation);
721 }
722
723 if (screenSession->GetOrientation() == newOrientation) {
724 return DMError::DM_OK;
725 }
726 if (isFromWindow) {
727 ScreenRotationProperty::ProcessOrientationSwitch(newOrientation);
728 } else {
729 Rotation rotationAfter = screenSession->CalcRotation(newOrientation);
730 SetRotation(screenId, rotationAfter, false);
731 }
732 screenSession->SetOrientation(newOrientation);
733 screenSession->PropertyChange(screenSession->GetScreenProperty(), ScreenPropertyChangeReason::ROTATION);
734 // Notify rotation event to ScreenManager
735 NotifyScreenChanged(screenSession->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ORIENTATION);
736 return DMError::DM_OK;
737 }
738
SetRotation(ScreenId screenId,Rotation rotationAfter,bool isFromWindow)739 bool ScreenSessionManager::SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow)
740 {
741 WLOGFI("Enter SetRotation, screenId: %{public}" PRIu64 ", rotation: %{public}u, isFromWindow: %{public}u,",
742 screenId, rotationAfter, isFromWindow);
743 sptr<ScreenSession> screenSession = GetScreenSession(screenId);
744 if (screenSession == nullptr) {
745 WLOGFE("SetRotation error, cannot get screen with screenId: %{public}" PRIu64, screenId);
746 return false;
747 }
748 if (rotationAfter == screenSession->GetRotation()) {
749 WLOGFE("rotation not changed. screen %{public}" PRIu64" rotation %{public}u", screenId, rotationAfter);
750 return false;
751 }
752 WLOGFD("set orientation. rotation %{public}u", rotationAfter);
753 SetDisplayBoundary(screenSession);
754 screenSession->SetRotation(rotationAfter);
755 screenSession->PropertyChange(screenSession->GetScreenProperty(), ScreenPropertyChangeReason::ROTATION);
756 NotifyScreenChanged(screenSession->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ROTATION);
757 return true;
758 }
759
SetSensorSubscriptionEnabled()760 void ScreenSessionManager::SetSensorSubscriptionEnabled()
761 {
762 isAutoRotationOpen_ = system::GetParameter("persist.display.ar.enabled", "1") == "1";
763 if (!isAutoRotationOpen_) {
764 WLOGFE("autoRotation is not open");
765 ScreenRotationProperty::Init();
766 return;
767 }
768 ScreenSensorConnector::SubscribeRotationSensor();
769 }
770
SetRotationFromWindow(Rotation targetRotation)771 bool ScreenSessionManager::SetRotationFromWindow(Rotation targetRotation)
772 {
773 sptr<DisplayInfo> displayInfo = GetDefaultDisplayInfo();
774 if (displayInfo == nullptr) {
775 return false;
776 }
777 return SetRotation(displayInfo->GetScreenId(), targetRotation, true);
778 }
779
GetScreenModesByDisplayId(DisplayId displayId)780 sptr<SupportedScreenModes> ScreenSessionManager::GetScreenModesByDisplayId(DisplayId displayId)
781 {
782 auto displayInfo = GetDisplayInfoById(displayId);
783 if (displayInfo == nullptr) {
784 WLOGFE("can not get display.");
785 return nullptr;
786 }
787 auto screenInfo = GetScreenInfoById(displayInfo->GetScreenId());
788 if (screenInfo == nullptr) {
789 WLOGFE("can not get screen.");
790 return nullptr;
791 }
792 auto modes = screenInfo->GetModes();
793 auto id = screenInfo->GetModeId();
794 if (id >= modes.size()) {
795 WLOGFE("can not get screenMode.");
796 return nullptr;
797 }
798 return modes[id];
799 }
800
GetScreenInfoByDisplayId(DisplayId displayId)801 sptr<ScreenInfo> ScreenSessionManager::GetScreenInfoByDisplayId(DisplayId displayId)
802 {
803 auto displayInfo = GetDisplayInfoById(displayId);
804 if (displayInfo == nullptr) {
805 WLOGFE("can not get displayInfo.");
806 return nullptr;
807 }
808 return GetScreenInfoById(displayInfo->GetScreenId());
809 }
810
RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)811 void ScreenSessionManager::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)
812 {
813 displayChangeListener_ = listener;
814 WLOGFD("IDisplayChangeListener registered");
815 }
816
NotifyDisplayPowerEvent(DisplayPowerEvent event,EventStatus status)817 bool ScreenSessionManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)
818 {
819 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER);
820 if (agents.empty()) {
821 return false;
822 }
823 WLOGFI("NotifyDisplayPowerEvent");
824 for (auto& agent : agents) {
825 agent->NotifyDisplayPowerEvent(event, status);
826 }
827 return true;
828 }
829
NotifyDisplayStateChanged(DisplayId id,DisplayState state)830 bool ScreenSessionManager::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
831 {
832 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_STATE_LISTENER);
833 if (agents.empty()) {
834 return false;
835 }
836 WLOGFI("NotifyDisplayStateChanged");
837 for (auto& agent : agents) {
838 agent->NotifyDisplayStateChanged(id, state);
839 }
840 return true;
841 }
GetAllScreenInfos(std::vector<sptr<ScreenInfo>> & screenInfos)842 DMError ScreenSessionManager::GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)
843 {
844 if (!SessionPermission::IsSystemCalling() && !SessionPermission::IsStartByHdcd()) {
845 WLOGFE("SCB: ScreenSessionManager::GetAllScreenInfos get all screen infos permission denied!");
846 return DMError::DM_ERROR_NOT_SYSTEM_APP;
847 }
848 std::vector<ScreenId> screenIds = GetAllScreenIds();
849 for (auto screenId: screenIds) {
850 auto screenInfo = GetScreenInfoById(screenId);
851 if (screenInfo == nullptr) {
852 WLOGE("SCB: ScreenSessionManager::GetAllScreenInfos cannot find screenInfo: %{public}" PRIu64"", screenId);
853 continue;
854 }
855 screenInfos.emplace_back(screenInfo);
856 }
857 return DMError::DM_OK;
858 }
859
GetAllScreenIds() const860 std::vector<ScreenId> ScreenSessionManager::GetAllScreenIds() const
861 {
862 std::vector<ScreenId> res;
863 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
864 for (const auto& iter : screenSessionMap_) {
865 res.emplace_back(iter.first);
866 }
867 return res;
868 }
869
GetScreenSupportedColorGamuts(ScreenId screenId,std::vector<ScreenColorGamut> & colorGamuts)870 DMError ScreenSessionManager::GetScreenSupportedColorGamuts(ScreenId screenId,
871 std::vector<ScreenColorGamut>& colorGamuts)
872 {
873 WLOGFI("SCB: ScreenSessionManager::GetScreenSupportedColorGamuts ENTER");
874 sptr<ScreenSession> screen = GetScreenSession(screenId);
875 if (screen == nullptr) {
876 WLOGFE("SCB: ScreenSessionManager::GetScreenSupportedColorGamuts nullptr");
877 return DMError::DM_ERROR_INVALID_PARAM;
878 }
879 return screen->GetScreenSupportedColorGamuts(colorGamuts);
880 }
881
CreateVirtualScreen(VirtualScreenOption option,const sptr<IRemoteObject> & displayManagerAgent)882 ScreenId ScreenSessionManager::CreateVirtualScreen(VirtualScreenOption option,
883 const sptr<IRemoteObject>& displayManagerAgent)
884 {
885 WLOGFI("SCB: ScreenSessionManager::CreateVirtualScreen ENTER");
886 ScreenId rsId = rsInterface_.CreateVirtualScreen(option.name_, option.width_,
887 option.height_, option.surface_, SCREEN_ID_INVALID, option.flags_);
888 WLOGFI("SCB: ScreenSessionManager::CreateVirtualScreen rsid: %{public}" PRIu64"", rsId);
889 if (rsId == SCREEN_ID_INVALID) {
890 WLOGFI("SCB: ScreenSessionManager::CreateVirtualScreen rsid is invalid");
891 return SCREEN_ID_INVALID;
892 }
893 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:CreateVirtualScreen(%s)", option.name_.c_str());
894 ScreenId smsScreenId = SCREEN_ID_INVALID;
895 if (!screenIdManager_.ConvertToSmsScreenId(rsId, smsScreenId)) {
896 WLOGFI("SCB: ScreenSessionManager::CreateVirtualScreen !ConvertToSmsScreenId(rsId, smsScreenId)");
897 smsScreenId = screenIdManager_.CreateAndGetNewScreenId(rsId);
898 auto screenSession = InitVirtualScreen(smsScreenId, rsId, option);
899 if (screenSession == nullptr) {
900 WLOGFI("SCB: ScreenSessionManager::CreateVirtualScreen screensession is nullptr");
901 screenIdManager_.DeleteScreenId(smsScreenId);
902 return SCREEN_ID_INVALID;
903 }
904 {
905 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
906 screenSessionMap_.insert(std::make_pair(smsScreenId, screenSession));
907 }
908 NotifyScreenConnected(screenSession->ConvertToScreenInfo());
909 if (deathRecipient_ == nullptr) {
910 WLOGFI("SCB: ScreenSessionManager::CreateVirtualScreen Create deathRecipient");
911 deathRecipient_ =
912 new AgentDeathRecipient([this](const sptr<IRemoteObject>& agent) { OnRemoteDied(agent); });
913 }
914 if (displayManagerAgent == nullptr) {
915 return smsScreenId;
916 }
917 auto agIter = screenAgentMap_.find(displayManagerAgent);
918 if (agIter == screenAgentMap_.end()) {
919 displayManagerAgent->AddDeathRecipient(deathRecipient_);
920 }
921 screenAgentMap_[displayManagerAgent].emplace_back(smsScreenId);
922 } else {
923 WLOGFI("SCB: ScreenSessionManager::CreateVirtualScreen id: %{public}" PRIu64" in screenIdManager_", rsId);
924 }
925 return smsScreenId;
926 }
927
SetVirtualScreenSurface(ScreenId screenId,sptr<IBufferProducer> surface)928 DMError ScreenSessionManager::SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface)
929 {
930 WLOGFI("SCB: ScreenSessionManager::SetVirtualScreenSurface ENTER");
931 ScreenId rsScreenId;
932 int32_t res = -1;
933 if (screenIdManager_.ConvertToRsScreenId(screenId, rsScreenId)) {
934 sptr<Surface> pSurface = Surface::CreateSurfaceAsProducer(surface);
935 res = rsInterface_.SetVirtualScreenSurface(rsScreenId, pSurface);
936 }
937 if (res != 0) {
938 WLOGE("SCB: ScreenSessionManager::SetVirtualScreenSurface failed in RenderService");
939 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
940 }
941 return DMError::DM_OK;
942 }
943
DestroyVirtualScreen(ScreenId screenId)944 DMError ScreenSessionManager::DestroyVirtualScreen(ScreenId screenId)
945 {
946 WLOGI("SCB: ScreenSessionManager::DestroyVirtualScreen Enter");
947 ScreenId rsScreenId = SCREEN_ID_INVALID;
948 screenIdManager_.ConvertToRsScreenId(screenId, rsScreenId);
949
950 bool agentFound = false;
951 for (auto &agentIter : screenAgentMap_) {
952 for (auto iter = agentIter.second.begin(); iter != agentIter.second.end(); iter++) {
953 if (*iter == screenId) {
954 iter = agentIter.second.erase(iter);
955 agentFound = true;
956 break;
957 }
958 }
959 if (agentFound) {
960 if (agentIter.first != nullptr && agentIter.second.empty()) {
961 screenAgentMap_.erase(agentIter.first);
962 }
963 break;
964 }
965 }
966 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:DestroyVirtualScreen(%" PRIu64")", screenId);
967 if (rsScreenId != SCREEN_ID_INVALID && GetScreenSession(screenId) != nullptr) {
968 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
969 auto smsScreenMapIter = screenSessionMap_.find(screenId);
970 if (smsScreenMapIter != screenSessionMap_.end()) {
971 auto screenGroup = RemoveFromGroupLocked(smsScreenMapIter->second);
972 if (screenGroup != nullptr) {
973 NotifyScreenGroupChanged(
974 smsScreenMapIter->second->ConvertToScreenInfo(), ScreenGroupChangeEvent::REMOVE_FROM_GROUP);
975 }
976 screenSessionMap_.erase(smsScreenMapIter);
977 }
978 }
979 screenIdManager_.DeleteScreenId(screenId);
980
981 if (rsScreenId == SCREEN_ID_INVALID) {
982 WLOGFE("SCB: ScreenSessionManager::DestroyVirtualScreen: No corresponding rsScreenId");
983 return DMError::DM_ERROR_INVALID_PARAM;
984 }
985 rsInterface_.RemoveVirtualScreen(rsScreenId);
986 return DMError::DM_OK;
987 }
988
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenIds,ScreenId & screenGroupId)989 DMError ScreenSessionManager::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds,
990 ScreenId& screenGroupId)
991 {
992 WLOGFI("SCB:ScreenSessionManager::MakeMirror enter!");
993 if (!SessionPermission::IsSystemCalling() && !SessionPermission::IsStartByHdcd()) {
994 WLOGFE("SCB:ScreenSessionManager::MakeMirror permission denied!");
995 return DMError::DM_ERROR_NOT_SYSTEM_APP;
996 }
997 WLOGFI("SCB:ScreenSessionManager::MakeMirror mainScreenId :%{public}" PRIu64"", mainScreenId);
998 auto allMirrorScreenIds = GetAllValidScreenIds(mirrorScreenIds);
999 auto iter = std::find(allMirrorScreenIds.begin(), allMirrorScreenIds.end(), mainScreenId);
1000 if (iter != allMirrorScreenIds.end()) {
1001 allMirrorScreenIds.erase(iter);
1002 }
1003 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:MakeMirror");
1004 auto mainScreen = GetScreenSession(mainScreenId);
1005 if (mainScreen == nullptr || allMirrorScreenIds.empty()) {
1006 WLOGFE("SCB:ScreenSessionManager::MakeMirror fail. mainScreen :%{public}" PRIu64", screens size:%{public}u",
1007 mainScreenId, static_cast<uint32_t>(allMirrorScreenIds.size()));
1008 return DMError::DM_ERROR_INVALID_PARAM;
1009 }
1010 DMError ret = SetMirror(mainScreenId, allMirrorScreenIds);
1011 if (ret != DMError::DM_OK) {
1012 WLOGFE("SCB:ScreenSessionManager::MakeMirror set mirror failed.");
1013 return ret;
1014 }
1015 if (GetAbstractScreenGroup(mainScreen->groupSmsId_) == nullptr) {
1016 WLOGFE("SCB:ScreenSessionManager::MakeMirror get screen group failed.");
1017 return DMError::DM_ERROR_NULLPTR;
1018 }
1019 screenGroupId = mainScreen->groupSmsId_;
1020 return DMError::DM_OK;
1021 }
1022
ConvertToRsScreenId(ScreenId smsScreenId,ScreenId & rsScreenId) const1023 bool ScreenSessionManager::ScreenIdManager::ConvertToRsScreenId(ScreenId smsScreenId, ScreenId& rsScreenId) const
1024 {
1025 std::shared_lock lock(screenIdMapMutex_);
1026 auto iter = sms2RsScreenIdMap_.find(smsScreenId);
1027 if (iter == sms2RsScreenIdMap_.end()) {
1028 return false;
1029 }
1030 rsScreenId = iter->second;
1031 return true;
1032 }
1033
ConvertToRsScreenId(ScreenId screenId) const1034 ScreenId ScreenSessionManager::ScreenIdManager::ConvertToRsScreenId(ScreenId screenId) const
1035 {
1036 ScreenId rsScreenId = SCREEN_ID_INVALID;
1037 ConvertToRsScreenId(screenId, rsScreenId);
1038 return rsScreenId;
1039 }
1040
ConvertToSmsScreenId(ScreenId rsScreenId) const1041 ScreenId ScreenSessionManager::ScreenIdManager::ConvertToSmsScreenId(ScreenId rsScreenId) const
1042 {
1043 ScreenId smsScreenId = SCREEN_ID_INVALID;
1044 ConvertToSmsScreenId(rsScreenId, smsScreenId);
1045 return smsScreenId;
1046 }
1047
ConvertToSmsScreenId(ScreenId rsScreenId,ScreenId & smsScreenId) const1048 bool ScreenSessionManager::ScreenIdManager::ConvertToSmsScreenId(ScreenId rsScreenId, ScreenId& smsScreenId) const
1049 {
1050 std::shared_lock lock(screenIdMapMutex_);
1051 auto iter = rs2SmsScreenIdMap_.find(rsScreenId);
1052 if (iter == rs2SmsScreenIdMap_.end()) {
1053 return false;
1054 }
1055 smsScreenId = iter->second;
1056 return true;
1057 }
1058
CreateAndGetNewScreenId(ScreenId rsScreenId)1059 ScreenId ScreenSessionManager::ScreenIdManager::CreateAndGetNewScreenId(ScreenId rsScreenId)
1060 {
1061 std::unique_lock lock(screenIdMapMutex_);
1062 ScreenId smsScreenId = smsScreenCount_++;
1063 WLOGFI("SCB: ScreenSessionManager::CreateAndGetNewScreenId screenId: %{public}" PRIu64"", smsScreenId);
1064 if (sms2RsScreenIdMap_.find(smsScreenId) != sms2RsScreenIdMap_.end()) {
1065 WLOGFW("SCB: ScreenSessionManager::CreateAndGetNewScreenId screenId: %{public}" PRIu64" exit", smsScreenId);
1066 }
1067 sms2RsScreenIdMap_[smsScreenId] = rsScreenId;
1068 if (rsScreenId == SCREEN_ID_INVALID) {
1069 return smsScreenId;
1070 }
1071 if (rs2SmsScreenIdMap_.find(rsScreenId) != rs2SmsScreenIdMap_.end()) {
1072 WLOGFW("SCB: ScreenSessionManager::CreateAndGetNewScreenId rsScreenId: %{public}" PRIu64" exit", rsScreenId);
1073 }
1074 rs2SmsScreenIdMap_[rsScreenId] = smsScreenId;
1075 return smsScreenId;
1076 }
1077
UpdateScreenId(ScreenId rsScreenId,ScreenId smsScreenId)1078 void ScreenSessionManager::ScreenIdManager::UpdateScreenId(ScreenId rsScreenId, ScreenId smsScreenId)
1079 {
1080 std::unique_lock lock(screenIdMapMutex_);
1081 rs2SmsScreenIdMap_[rsScreenId] = smsScreenId;
1082 sms2RsScreenIdMap_[smsScreenId] = rsScreenId;
1083 }
1084
DeleteScreenId(ScreenId smsScreenId)1085 bool ScreenSessionManager::ScreenIdManager::DeleteScreenId(ScreenId smsScreenId)
1086 {
1087 std::unique_lock lock(screenIdMapMutex_);
1088 auto iter = sms2RsScreenIdMap_.find(smsScreenId);
1089 if (iter == sms2RsScreenIdMap_.end()) {
1090 return false;
1091 }
1092 ScreenId rsScreenId = iter->second;
1093 sms2RsScreenIdMap_.erase(smsScreenId);
1094 rs2SmsScreenIdMap_.erase(rsScreenId);
1095 return true;
1096 }
1097
HasRsScreenId(ScreenId smsScreenId) const1098 bool ScreenSessionManager::ScreenIdManager::HasRsScreenId(ScreenId smsScreenId) const
1099 {
1100 std::shared_lock lock(screenIdMapMutex_);
1101 return rs2SmsScreenIdMap_.find(smsScreenId) != rs2SmsScreenIdMap_.end();
1102 }
1103
GetDefaultAbstractScreenId()1104 ScreenId ScreenSessionManager::GetDefaultAbstractScreenId()
1105 {
1106 WLOGFI("SCB: ScreenSessionManager::GetDefaultAbstractScreenId ENTER");
1107 defaultRsScreenId_ = rsInterface_.GetDefaultScreenId();
1108 return screenIdManager_.ConvertToSmsScreenId(defaultRsScreenId_);
1109 }
1110
InitVirtualScreen(ScreenId smsScreenId,ScreenId rsId,VirtualScreenOption option)1111 sptr<ScreenSession> ScreenSessionManager::InitVirtualScreen(ScreenId smsScreenId, ScreenId rsId,
1112 VirtualScreenOption option)
1113 {
1114 WLOGFI("SCB: ScreenSessionManager::InitVirtualScreen: Enter");
1115 sptr<ScreenSession> screenSession =
1116 new(std::nothrow) ScreenSession(option.name_, smsScreenId, rsId, GetDefaultAbstractScreenId());
1117 sptr<SupportedScreenModes> info = new(std::nothrow) SupportedScreenModes();
1118 if (screenSession == nullptr || info == nullptr) {
1119 WLOGFI("SCB: ScreenSessionManager::InitVirtualScreen: new screenSession or info failed");
1120 screenIdManager_.DeleteScreenId(smsScreenId);
1121 rsInterface_.RemoveVirtualScreen(rsId);
1122 return nullptr;
1123 }
1124 info->width_ = option.width_;
1125 info->height_ = option.height_;
1126 auto defaultScreen = GetScreenSession(GetDefaultAbstractScreenId());
1127 if (defaultScreen != nullptr && defaultScreen->GetActiveScreenMode() != nullptr) {
1128 info->refreshRate_ = defaultScreen->GetActiveScreenMode()->refreshRate_;
1129 }
1130 screenSession->modes_.emplace_back(info);
1131 screenSession->activeIdx_ = 0;
1132 screenSession->SetScreenType(ScreenType::VIRTUAL);
1133 screenSession->SetVirtualPixelRatio(option.density_);
1134 return screenSession;
1135 }
1136
InitAbstractScreenModesInfo(sptr<ScreenSession> & screenSession)1137 bool ScreenSessionManager::InitAbstractScreenModesInfo(sptr<ScreenSession>& screenSession)
1138 {
1139 std::vector<RSScreenModeInfo> allModes = rsInterface_.GetScreenSupportedModes(
1140 screenIdManager_.ConvertToRsScreenId(screenSession->screenId_));
1141 if (allModes.size() == 0) {
1142 WLOGE("SCB: allModes.size() == 0, screenId=%{public}" PRIu64"", screenSession->rsId_);
1143 return false;
1144 }
1145 for (const RSScreenModeInfo& rsScreenModeInfo : allModes) {
1146 sptr<SupportedScreenModes> info = new(std::nothrow) SupportedScreenModes();
1147 if (info == nullptr) {
1148 WLOGFE("SCB: ScreenSessionManager::InitAbstractScreenModesInfo:create SupportedScreenModes failed");
1149 return false;
1150 }
1151 info->width_ = static_cast<uint32_t>(rsScreenModeInfo.GetScreenWidth());
1152 info->height_ = static_cast<uint32_t>(rsScreenModeInfo.GetScreenHeight());
1153 info->refreshRate_ = rsScreenModeInfo.GetScreenRefreshRate();
1154 screenSession->modes_.push_back(info);
1155 WLOGI("SCB: fill screen idx:%{public}d w/h:%{public}d/%{public}d",
1156 rsScreenModeInfo.GetScreenModeId(), info->width_, info->height_);
1157 }
1158 int32_t activeModeId = rsInterface_.GetScreenActiveMode(screenSession->rsId_).GetScreenModeId();
1159 WLOGI("SCB: ScreenSessionManager::InitAbstractScreenModesInfo: fill screen activeModeId:%{public}d", activeModeId);
1160 if (static_cast<std::size_t>(activeModeId) >= allModes.size()) {
1161 WLOGE("SCB: activeModeId exceed, screenId=%{public}" PRIu64", activeModeId:%{public}d/%{public}ud",
1162 screenSession->rsId_, activeModeId, static_cast<uint32_t>(allModes.size()));
1163 return false;
1164 }
1165 screenSession->activeIdx_ = activeModeId;
1166 return true;
1167 }
1168
InitAndGetScreen(ScreenId rsScreenId)1169 sptr<ScreenSession> ScreenSessionManager::InitAndGetScreen(ScreenId rsScreenId)
1170 {
1171 ScreenId smsScreenId = screenIdManager_.CreateAndGetNewScreenId(rsScreenId);
1172 RSScreenCapability screenCapability = rsInterface_.GetScreenCapability(rsScreenId);
1173 WLOGFD("SCB: Screen name is %{public}s, phyWidth is %{public}u, phyHeight is %{public}u",
1174 screenCapability.GetName().c_str(), screenCapability.GetPhyWidth(), screenCapability.GetPhyHeight());
1175 sptr<ScreenSession> screenSession =
1176 new(std::nothrow) ScreenSession(screenCapability.GetName(), smsScreenId, rsScreenId, GetDefaultAbstractScreenId());
1177 if (screenSession == nullptr) {
1178 WLOGFE("SCB: ScreenSessionManager::InitAndGetScreen: screenSession == nullptr.");
1179 screenIdManager_.DeleteScreenId(smsScreenId);
1180 return nullptr;
1181 }
1182 if (!InitAbstractScreenModesInfo(screenSession)) {
1183 screenIdManager_.DeleteScreenId(smsScreenId);
1184 WLOGFE("SCB: ScreenSessionManager::InitAndGetScreen: InitAndGetScreen failed.");
1185 return nullptr;
1186 }
1187 WLOGI("SCB: InitAndGetScreen: screenSessionMap_ add screenId=%{public}" PRIu64"", smsScreenId);
1188 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
1189 screenSessionMap_.insert(std::make_pair(smsScreenId, screenSession));
1190 return screenSession;
1191 }
1192
AddToGroupLocked(sptr<ScreenSession> newScreen)1193 sptr<ScreenSessionGroup> ScreenSessionManager::AddToGroupLocked(sptr<ScreenSession> newScreen)
1194 {
1195 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
1196 sptr<ScreenSessionGroup> res;
1197 if (smsScreenGroupMap_.empty()) {
1198 WLOGI("connect the first screen");
1199 res = AddAsFirstScreenLocked(newScreen);
1200 } else {
1201 res = AddAsSuccedentScreenLocked(newScreen);
1202 }
1203 return res;
1204 }
1205
AddAsFirstScreenLocked(sptr<ScreenSession> newScreen)1206 sptr<ScreenSessionGroup> ScreenSessionManager::AddAsFirstScreenLocked(sptr<ScreenSession> newScreen)
1207 {
1208 ScreenId smsGroupScreenId(1);
1209 std::ostringstream buffer;
1210 buffer<<"ScreenGroup_"<<smsGroupScreenId;
1211 std::string name = buffer.str();
1212 // default ScreenCombination is mirror
1213 isExpandCombination_ = system::GetParameter("persist.display.expand.enabled", "0") == "1";
1214 sptr<ScreenSessionGroup> screenGroup;
1215 if (isExpandCombination_) {
1216 screenGroup = new(std::nothrow) ScreenSessionGroup(smsGroupScreenId,
1217 SCREEN_ID_INVALID, name, ScreenCombination::SCREEN_EXPAND);
1218 newScreen->SetScreenCombination(ScreenCombination::SCREEN_EXPAND);
1219 } else {
1220 screenGroup = new(std::nothrow) ScreenSessionGroup(smsGroupScreenId,
1221 SCREEN_ID_INVALID, name, ScreenCombination::SCREEN_MIRROR);
1222 newScreen->SetScreenCombination(ScreenCombination::SCREEN_MIRROR);
1223 }
1224 if (screenGroup == nullptr) {
1225 WLOGE("new ScreenSessionGroup failed");
1226 screenIdManager_.DeleteScreenId(smsGroupScreenId);
1227 return nullptr;
1228 }
1229 screenGroup->groupSmsId_ = 1;
1230 Point point;
1231 if (!screenGroup->AddChild(newScreen, point, GetScreenSession(GetDefaultAbstractScreenId()))) {
1232 WLOGE("fail to add screen to group. screen=%{public}" PRIu64"", newScreen->screenId_);
1233 screenIdManager_.DeleteScreenId(smsGroupScreenId);
1234 return nullptr;
1235 }
1236 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
1237 auto iter = smsScreenGroupMap_.find(smsGroupScreenId);
1238 if (iter != smsScreenGroupMap_.end()) {
1239 WLOGE("group screen existed. id=%{public}" PRIu64"", smsGroupScreenId);
1240 smsScreenGroupMap_.erase(iter);
1241 }
1242 smsScreenGroupMap_.insert(std::make_pair(smsGroupScreenId, screenGroup));
1243 screenSessionMap_.insert(std::make_pair(smsGroupScreenId, screenGroup));
1244 screenGroup->mirrorScreenId_ = newScreen->screenId_;
1245 WLOGI("connect new group screen, screenId: %{public}" PRIu64", screenGroupId: %{public}" PRIu64", "
1246 "combination:%{public}u", newScreen->screenId_, smsGroupScreenId,
1247 newScreen->GetScreenProperty().GetScreenType());
1248 return screenGroup;
1249 }
1250
AddAsSuccedentScreenLocked(sptr<ScreenSession> newScreen)1251 sptr<ScreenSessionGroup> ScreenSessionManager::AddAsSuccedentScreenLocked(sptr<ScreenSession> newScreen)
1252 {
1253 ScreenId defaultScreenId = GetDefaultAbstractScreenId();
1254 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
1255 auto iter = screenSessionMap_.find(defaultScreenId);
1256 if (iter == screenSessionMap_.end()) {
1257 WLOGE("AddAsSuccedentScreenLocked. defaultScreenId:%{public}" PRIu64" is not in screenSessionMap_.",
1258 defaultScreenId);
1259 return nullptr;
1260 }
1261 auto screen = iter->second;
1262 auto screenGroupIter = smsScreenGroupMap_.find(screen->groupSmsId_);
1263 if (screenGroupIter == smsScreenGroupMap_.end()) {
1264 WLOGE("AddAsSuccedentScreenLocked. groupSmsId:%{public}" PRIu64" is not in smsScreenGroupMap_.",
1265 screen->groupSmsId_);
1266 return nullptr;
1267 }
1268 auto screenGroup = screenGroupIter->second;
1269 Point point;
1270 if (screenGroup->combination_ == ScreenCombination::SCREEN_EXPAND) {
1271 point = {screen->GetActiveScreenMode()->width_, 0};
1272 }
1273 screenGroup->AddChild(newScreen, point, screen);
1274 return screenGroup;
1275 }
1276
RemoveFromGroupLocked(sptr<ScreenSession> screen)1277 sptr<ScreenSessionGroup> ScreenSessionManager::RemoveFromGroupLocked(sptr<ScreenSession> screen)
1278 {
1279 WLOGI("RemoveFromGroupLocked.");
1280 auto groupSmsId = screen->groupSmsId_;
1281 sptr<ScreenSessionGroup> screenGroup = GetAbstractScreenGroup(groupSmsId);
1282 if (!screenGroup) {
1283 WLOGE("RemoveFromGroupLocked. groupSmsId:%{public}" PRIu64"is not in smsScreenGroupMap_.", groupSmsId);
1284 return nullptr;
1285 }
1286 if (!RemoveChildFromGroup(screen, screenGroup)) {
1287 return nullptr;
1288 }
1289 return screenGroup;
1290 }
1291
RemoveChildFromGroup(sptr<ScreenSession> screen,sptr<ScreenSessionGroup> screenGroup)1292 bool ScreenSessionManager::RemoveChildFromGroup(sptr<ScreenSession> screen, sptr<ScreenSessionGroup> screenGroup)
1293 {
1294 bool res = screenGroup->RemoveChild(screen);
1295 if (!res) {
1296 WLOGE("RemoveFromGroupLocked. remove screen:%{public}" PRIu64" failed from screenGroup:%{public}" PRIu64".",
1297 screen->screenId_, screen->groupSmsId_);
1298 return false;
1299 }
1300 if (screenGroup->GetChildCount() == 0) {
1301 // Group removed, need to do something.
1302 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
1303 smsScreenGroupMap_.erase(screenGroup->screenId_);
1304 screenSessionMap_.erase(screenGroup->screenId_);
1305 WLOGE("SCB: RemoveFromGroupLocked. screenSessionMap_ remove screen:%{public}" PRIu64"", screenGroup->screenId_);
1306 }
1307 return true;
1308 }
1309
SetMirror(ScreenId screenId,std::vector<ScreenId> screens)1310 DMError ScreenSessionManager::SetMirror(ScreenId screenId, std::vector<ScreenId> screens)
1311 {
1312 WLOGI("SetMirror, screenId:%{public}" PRIu64"", screenId);
1313 sptr<ScreenSession> screen = GetScreenSession(screenId);
1314 if (screen == nullptr || screen->GetScreenProperty().GetScreenType() != ScreenType::REAL) {
1315 WLOGFE("screen is nullptr, or screenType is not real.");
1316 return DMError::DM_ERROR_NULLPTR;
1317 }
1318 screen->groupSmsId_ = 1;
1319 auto group = GetAbstractScreenGroup(screen->groupSmsId_);
1320 if (group == nullptr) {
1321 group = AddToGroupLocked(screen);
1322 if (group == nullptr) {
1323 WLOGFE("group is nullptr");
1324 return DMError::DM_ERROR_NULLPTR;
1325 }
1326 NotifyScreenGroupChanged(screen->ConvertToScreenInfo(), ScreenGroupChangeEvent::ADD_TO_GROUP);
1327 }
1328 Point point;
1329 std::vector<Point> startPoints;
1330 startPoints.insert(startPoints.begin(), screens.size(), point);
1331 bool filterMirroredScreen =
1332 group->combination_ == ScreenCombination::SCREEN_MIRROR && group->mirrorScreenId_ == screen->screenId_;
1333 group->mirrorScreenId_ = screen->screenId_;
1334 ChangeScreenGroup(group, screens, startPoints, filterMirroredScreen, ScreenCombination::SCREEN_MIRROR);
1335 WLOGFI("SetMirror success");
1336 return DMError::DM_OK;
1337 }
1338
GetAbstractScreenGroup(ScreenId smsScreenId)1339 sptr<ScreenSessionGroup> ScreenSessionManager::GetAbstractScreenGroup(ScreenId smsScreenId)
1340 {
1341 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
1342 auto iter = smsScreenGroupMap_.find(smsScreenId);
1343 if (iter == smsScreenGroupMap_.end()) {
1344 WLOGE("did not find screen:%{public}" PRIu64"", smsScreenId);
1345 return nullptr;
1346 }
1347 return iter->second;
1348 }
1349
ChangeScreenGroup(sptr<ScreenSessionGroup> group,const std::vector<ScreenId> & screens,const std::vector<Point> & startPoints,bool filterScreen,ScreenCombination combination)1350 void ScreenSessionManager::ChangeScreenGroup(sptr<ScreenSessionGroup> group, const std::vector<ScreenId>& screens,
1351 const std::vector<Point>& startPoints, bool filterScreen, ScreenCombination combination)
1352 {
1353 std::map<ScreenId, bool> removeChildResMap;
1354 std::vector<ScreenId> addScreens;
1355 std::vector<Point> addChildPos;
1356 for (uint64_t i = 0; i != screens.size(); i++) {
1357 ScreenId screenId = screens[i];
1358 WLOGFI("ScreenId: %{public}" PRIu64"", screenId);
1359 auto screen = GetScreenSession(screenId);
1360 if (screen == nullptr) {
1361 WLOGFE("screen:%{public}" PRIu64" is nullptr", screenId);
1362 continue;
1363 }
1364 WLOGFI("Screen->groupSmsId_: %{public}" PRIu64"", screen->groupSmsId_);
1365 screen->groupSmsId_ = 1;
1366 if (filterScreen && screen->groupSmsId_ == group->screenId_ && group->HasChild(screen->screenId_)) {
1367 continue;
1368 }
1369 auto originGroup = RemoveFromGroupLocked(screen);
1370 addChildPos.emplace_back(startPoints[i]);
1371 removeChildResMap[screenId] = originGroup != nullptr;
1372 addScreens.emplace_back(screenId);
1373 }
1374 group->combination_ = combination;
1375 AddScreenToGroup(group, addScreens, addChildPos, removeChildResMap);
1376 }
1377
AddScreenToGroup(sptr<ScreenSessionGroup> group,const std::vector<ScreenId> & addScreens,const std::vector<Point> & addChildPos,std::map<ScreenId,bool> & removeChildResMap)1378 void ScreenSessionManager::AddScreenToGroup(sptr<ScreenSessionGroup> group,
1379 const std::vector<ScreenId>& addScreens, const std::vector<Point>& addChildPos,
1380 std::map<ScreenId, bool>& removeChildResMap)
1381 {
1382 std::vector<sptr<ScreenInfo>> addToGroup;
1383 std::vector<sptr<ScreenInfo>> removeFromGroup;
1384 std::vector<sptr<ScreenInfo>> changeGroup;
1385 for (uint64_t i = 0; i != addScreens.size(); i++) {
1386 ScreenId screenId = addScreens[i];
1387 sptr<ScreenSession> screen = GetScreenSession(screenId);
1388 if (screen == nullptr) {
1389 continue;
1390 }
1391 Point expandPoint = addChildPos[i];
1392 WLOGFI("screenId: %{public}" PRIu64", Point: %{public}d, %{public}d",
1393 screen->screenId_, expandPoint.posX_, expandPoint.posY_);
1394 bool addChildRes = group->AddChild(screen, expandPoint, GetScreenSession(GetDefaultAbstractScreenId()));
1395 if (removeChildResMap[screenId] && addChildRes) {
1396 changeGroup.emplace_back(screen->ConvertToScreenInfo());
1397 WLOGFD("changeGroup");
1398 } else if (removeChildResMap[screenId]) {
1399 WLOGFD("removeChild");
1400 removeFromGroup.emplace_back(screen->ConvertToScreenInfo());
1401 } else if (addChildRes) {
1402 WLOGFD("AddChild");
1403 addToGroup.emplace_back(screen->ConvertToScreenInfo());
1404 } else {
1405 WLOGFD("default, AddChild failed");
1406 }
1407 }
1408
1409 NotifyScreenGroupChanged(removeFromGroup, ScreenGroupChangeEvent::REMOVE_FROM_GROUP);
1410 NotifyScreenGroupChanged(changeGroup, ScreenGroupChangeEvent::CHANGE_GROUP);
1411 NotifyScreenGroupChanged(addToGroup, ScreenGroupChangeEvent::ADD_TO_GROUP);
1412 }
1413
RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)1414 void ScreenSessionManager::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
1415 {
1416 WLOGFE("SCB: ScreenSessionManager::RemoveVirtualScreenFromGroup enter!");
1417 if (screens.empty()) {
1418 return;
1419 }
1420 std::vector<sptr<ScreenInfo>> removeFromGroup;
1421 for (ScreenId screenId : screens) {
1422 auto screen = GetScreenSession(screenId);
1423 if (screen == nullptr || screen->GetScreenProperty().GetScreenType() != ScreenType::VIRTUAL) {
1424 continue;
1425 }
1426 auto originGroup = GetAbstractScreenGroup(screen->groupSmsId_);
1427 if (originGroup == nullptr) {
1428 continue;
1429 }
1430 if (!originGroup->HasChild(screenId)) {
1431 continue;
1432 }
1433 RemoveFromGroupLocked(screen);
1434 removeFromGroup.emplace_back(screen->ConvertToScreenInfo());
1435 }
1436 NotifyScreenGroupChanged(removeFromGroup, ScreenGroupChangeEvent::REMOVE_FROM_GROUP);
1437 }
1438
GetRSDisplayNodeByScreenId(ScreenId smsScreenId) const1439 const std::shared_ptr<RSDisplayNode> ScreenSessionManager::GetRSDisplayNodeByScreenId(ScreenId smsScreenId) const
1440 {
1441 static std::shared_ptr<RSDisplayNode> notFound = nullptr;
1442 sptr<ScreenSession> screen = GetScreenSession(smsScreenId);
1443 if (screen == nullptr) {
1444 WLOGFE("SCB: ScreenSessionManager::GetRSDisplayNodeByScreenId screen == nullptr!");
1445 return notFound;
1446 }
1447 if (screen->GetDisplayNode() == nullptr) {
1448 WLOGFE("SCB: ScreenSessionManager::GetRSDisplayNodeByScreenId displayNode_ == nullptr!");
1449 return notFound;
1450 }
1451 WLOGI("GetRSDisplayNodeByScreenId: screen: %{public}" PRIu64", nodeId: %{public}" PRIu64" ",
1452 screen->screenId_, screen->GetDisplayNode()->GetId());
1453 return screen->GetDisplayNode();
1454 }
1455
GetScreenSnapshot(DisplayId displayId)1456 std::shared_ptr<Media::PixelMap> ScreenSessionManager::GetScreenSnapshot(DisplayId displayId)
1457 {
1458 ScreenId screenId = SCREEN_ID_INVALID;
1459 std::shared_ptr<RSDisplayNode> displayNode = nullptr;
1460 {
1461 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
1462 for (auto sessionIt : screenSessionMap_) {
1463 auto screenSession = sessionIt.second;
1464 sptr<DisplayInfo> displayInfo = screenSession->ConvertToDisplayInfo();
1465 WLOGI("SCB: GetScreenSnapshot: displayId %{public}" PRIu64"", displayInfo->GetDisplayId());
1466 if (displayId == displayInfo->GetDisplayId()) {
1467 displayNode = screenSession->GetDisplayNode();
1468 screenId = sessionIt.first;
1469 break;
1470 }
1471 }
1472 }
1473 if (screenId == SCREEN_ID_INVALID) {
1474 WLOGFE("SCB: ScreenSessionManager::GetScreenSnapshot screenId == SCREEN_ID_INVALID!");
1475 return nullptr;
1476 }
1477 if (displayNode == nullptr) {
1478 WLOGFE("SCB: ScreenSessionManager::GetScreenSnapshot displayNode == nullptr!");
1479 return nullptr;
1480 }
1481
1482 std::shared_ptr<SurfaceCaptureFuture> callback = std::make_shared<SurfaceCaptureFuture>();
1483 bool ret = rsInterface_.TakeSurfaceCapture(displayNode, callback);
1484 if (!ret) {
1485 WLOGFE("SCB: ScreenSessionManager::GetScreenSnapshot TakeSurfaceCapture failed");
1486 return nullptr;
1487 }
1488 std::shared_ptr<Media::PixelMap> screenshot = callback->GetResult(2000); // wait for <= 2000ms
1489 if (screenshot == nullptr) {
1490 WLOGFE("SCB: Failed to get pixelmap from RS, return nullptr!");
1491 }
1492
1493 // notify dm listener
1494 sptr<ScreenshotInfo> snapshotInfo = new ScreenshotInfo();
1495 snapshotInfo->SetTrigger(SysCapUtil::GetClientName());
1496 snapshotInfo->SetDisplayId(displayId);
1497 OnScreenshot(snapshotInfo);
1498
1499 return screenshot;
1500 }
1501
GetDisplaySnapshot(DisplayId displayId,DmErrorCode * errorCode)1502 std::shared_ptr<Media::PixelMap> ScreenSessionManager::GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode)
1503 {
1504 WLOGFI("SCB: ScreenSessionManager::GetDisplaySnapshot ENTER!");
1505 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:GetDisplaySnapshot(%" PRIu64")", displayId);
1506 auto res = GetScreenSnapshot(displayId);
1507 if (res != nullptr) {
1508 NotifyScreenshot(displayId);
1509 }
1510 return res;
1511 }
1512
OnRemoteDied(const sptr<IRemoteObject> & agent)1513 bool ScreenSessionManager::OnRemoteDied(const sptr<IRemoteObject>& agent)
1514 {
1515 if (agent == nullptr) {
1516 return false;
1517 }
1518 auto agentIter = screenAgentMap_.find(agent);
1519 if (agentIter != screenAgentMap_.end()) {
1520 while (screenAgentMap_[agent].size() > 0) {
1521 auto diedId = screenAgentMap_[agent][0];
1522 WLOGI("destroy screenId in OnRemoteDied: %{public}" PRIu64"", diedId);
1523 DMError res = DestroyVirtualScreen(diedId);
1524 if (res != DMError::DM_OK) {
1525 WLOGE("destroy failed in OnRemoteDied: %{public}" PRIu64"", diedId);
1526 }
1527 }
1528 screenAgentMap_.erase(agent);
1529 }
1530 return true;
1531 }
1532
GetAllValidScreenIds(const std::vector<ScreenId> & screenIds) const1533 std::vector<ScreenId> ScreenSessionManager::GetAllValidScreenIds(const std::vector<ScreenId>& screenIds) const
1534 {
1535 std::vector<ScreenId> validScreenIds;
1536 for (ScreenId screenId : screenIds) {
1537 auto screenIdIter = std::find(validScreenIds.begin(), validScreenIds.end(), screenId);
1538 if (screenIdIter != validScreenIds.end()) {
1539 continue;
1540 }
1541 std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
1542 auto iter = screenSessionMap_.find(screenId);
1543 if (iter != screenSessionMap_.end() &&
1544 iter->second->GetScreenProperty().GetScreenType() != ScreenType::UNDEFINED) {
1545 validScreenIds.emplace_back(screenId);
1546 }
1547 }
1548 return validScreenIds;
1549 }
1550
GetScreenGroupInfoById(ScreenId screenId)1551 sptr<ScreenGroupInfo> ScreenSessionManager::GetScreenGroupInfoById(ScreenId screenId)
1552 {
1553 auto screenSessionGroup = GetAbstractScreenGroup(screenId);
1554 if (screenSessionGroup == nullptr) {
1555 WLOGE("SCB: GetScreenGroupInfoById cannot find screenGroupInfo: %{public}" PRIu64"", screenId);
1556 return nullptr;
1557 }
1558 return screenSessionGroup->ConvertToScreenGroupInfo();
1559 }
1560
NotifyScreenConnected(sptr<ScreenInfo> screenInfo)1561 void ScreenSessionManager::NotifyScreenConnected(sptr<ScreenInfo> screenInfo)
1562 {
1563 if (screenInfo == nullptr) {
1564 WLOGFE("SCB: NotifyScreenConnected error, screenInfo is nullptr.");
1565 return;
1566 }
1567 auto task = [=] {
1568 WLOGFI("SCB: NotifyScreenConnected, screenId:%{public}" PRIu64"", screenInfo->GetScreenId());
1569 OnScreenConnect(screenInfo);
1570 };
1571 taskScheduler_->PostAsyncTask(task);
1572 }
1573
NotifyScreenDisconnected(ScreenId screenId)1574 void ScreenSessionManager::NotifyScreenDisconnected(ScreenId screenId)
1575 {
1576 auto task = [=] {
1577 WLOGFI("NotifyScreenDisconnected, screenId:%{public}" PRIu64"", screenId);
1578 OnScreenDisconnect(screenId);
1579 };
1580 taskScheduler_->PostAsyncTask(task);
1581 }
1582
NotifyScreenGroupChanged(const sptr<ScreenInfo> & screenInfo,ScreenGroupChangeEvent event)1583 void ScreenSessionManager::NotifyScreenGroupChanged(
1584 const sptr<ScreenInfo>& screenInfo, ScreenGroupChangeEvent event)
1585 {
1586 if (screenInfo == nullptr) {
1587 WLOGFE("screenInfo is nullptr.");
1588 return;
1589 }
1590 std::string trigger = SysCapUtil::GetClientName();
1591 auto task = [=] {
1592 WLOGFI("SCB: screenId:%{public}" PRIu64", trigger:[%{public}s]", screenInfo->GetScreenId(), trigger.c_str());
1593 OnScreenGroupChange(trigger, screenInfo, event);
1594 };
1595 taskScheduler_->PostAsyncTask(task);
1596 }
1597
NotifyScreenGroupChanged(const std::vector<sptr<ScreenInfo>> & screenInfo,ScreenGroupChangeEvent event)1598 void ScreenSessionManager::NotifyScreenGroupChanged(
1599 const std::vector<sptr<ScreenInfo>>& screenInfo, ScreenGroupChangeEvent event)
1600 {
1601 if (screenInfo.empty()) {
1602 return;
1603 }
1604 std::string trigger = SysCapUtil::GetClientName();
1605 auto task = [=] {
1606 WLOGFI("SCB: trigger:[%{public}s]", trigger.c_str());
1607 OnScreenGroupChange(trigger, screenInfo, event);
1608 };
1609 taskScheduler_->PostAsyncTask(task);
1610 }
1611
NotifyPrivateSessionStateChanged(bool hasPrivate)1612 void ScreenSessionManager::NotifyPrivateSessionStateChanged(bool hasPrivate)
1613 {
1614 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::PRIVATE_WINDOW_LISTENER);
1615 if (agents.empty()) {
1616 return;
1617 }
1618 WLOGI("PrivateSession status : %{public}u", hasPrivate);
1619 for (auto& agent : agents) {
1620 agent->NotifyPrivateWindowStateChanged(hasPrivate);
1621 }
1622 }
1623
UpdatePrivateStateAndNotify(sptr<ScreenSession> & screenSession,bool isAddingPrivateSession)1624 void ScreenSessionManager::UpdatePrivateStateAndNotify(sptr<ScreenSession>& screenSession, bool isAddingPrivateSession)
1625 {
1626 int32_t prePrivateSessionCount = screenSession->GetPrivateSessionCount();
1627 WLOGFD("before update : privateWindow count: %{public}u", prePrivateSessionCount);
1628 screenSession->SetPrivateSessionCount(prePrivateSessionCount + (isAddingPrivateSession ? 1 : -1));
1629 if (prePrivateSessionCount == 0 && isAddingPrivateSession) {
1630 NotifyPrivateSessionStateChanged(true);
1631 return;
1632 }
1633 if (prePrivateSessionCount == 1 && !isAddingPrivateSession) {
1634 NotifyPrivateSessionStateChanged(false);
1635 return;
1636 }
1637 }
1638
HasPrivateWindow(DisplayId id,bool & hasPrivateWindow)1639 DMError ScreenSessionManager::HasPrivateWindow(DisplayId id, bool& hasPrivateWindow)
1640 {
1641 // delete permission
1642 std::vector<ScreenId> screenIds = GetAllScreenIds();
1643 auto iter = std::find(screenIds.begin(), screenIds.end(), id);
1644 if (iter == screenIds.end()) {
1645 WLOGFE("invalid displayId");
1646 return DMError::DM_ERROR_INVALID_PARAM;
1647 }
1648 auto screenSession = GetScreenSession(id);
1649 if (screenSession == nullptr) {
1650 return DMError::DM_ERROR_NULLPTR;
1651 }
1652 hasPrivateWindow = screenSession->HasPrivateSession();
1653 WLOGFD("id: %{public}" PRIu64" has private window: %{public}u", id, static_cast<uint32_t>(hasPrivateWindow));
1654 return DMError::DM_OK;
1655 }
1656
OnScreenGroupChange(const std::string & trigger,const sptr<ScreenInfo> & screenInfo,ScreenGroupChangeEvent groupEvent)1657 void ScreenSessionManager::OnScreenGroupChange(const std::string& trigger,
1658 const sptr<ScreenInfo>& screenInfo, ScreenGroupChangeEvent groupEvent)
1659 {
1660 if (screenInfo == nullptr) {
1661 return;
1662 }
1663 std::vector<sptr<ScreenInfo>> screenInfos;
1664 screenInfos.push_back(screenInfo);
1665 OnScreenGroupChange(trigger, screenInfos, groupEvent);
1666 }
1667
OnScreenGroupChange(const std::string & trigger,const std::vector<sptr<ScreenInfo>> & screenInfos,ScreenGroupChangeEvent groupEvent)1668 void ScreenSessionManager::OnScreenGroupChange(const std::string& trigger,
1669 const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent groupEvent)
1670 {
1671 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
1672 std::vector<sptr<ScreenInfo>> infos;
1673 for (auto& screenInfo : screenInfos) {
1674 if (screenInfo != nullptr) {
1675 infos.emplace_back(screenInfo);
1676 }
1677 }
1678 if (agents.empty() || infos.empty()) {
1679 return;
1680 }
1681 for (auto& agent : agents) {
1682 agent->OnScreenGroupChange(trigger, infos, groupEvent);
1683 }
1684 }
1685
OnScreenConnect(const sptr<ScreenInfo> screenInfo)1686 void ScreenSessionManager::OnScreenConnect(const sptr<ScreenInfo> screenInfo)
1687 {
1688 if (screenInfo == nullptr) {
1689 return;
1690 }
1691 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
1692 if (agents.empty()) {
1693 return;
1694 }
1695 WLOGFI("SCB: OnScreenConnect");
1696 for (auto& agent : agents) {
1697 agent->OnScreenConnect(screenInfo);
1698 }
1699 }
1700
OnScreenDisconnect(ScreenId screenId)1701 void ScreenSessionManager::OnScreenDisconnect(ScreenId screenId)
1702 {
1703 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
1704 if (agents.empty()) {
1705 return;
1706 }
1707 WLOGFI("SCB: OnScreenDisconnect");
1708 for (auto& agent : agents) {
1709 agent->OnScreenDisconnect(screenId);
1710 }
1711 }
1712
OnScreenshot(sptr<ScreenshotInfo> info)1713 void ScreenSessionManager::OnScreenshot(sptr<ScreenshotInfo> info)
1714 {
1715 if (info == nullptr) {
1716 return;
1717 }
1718 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREENSHOT_EVENT_LISTENER);
1719 if (agents.empty()) {
1720 return;
1721 }
1722 WLOGFI("SCB: onScreenshot");
1723 for (auto& agent : agents) {
1724 agent->OnScreenshot(info);
1725 }
1726 }
1727
GetCutoutInfo(DisplayId displayId)1728 sptr<CutoutInfo> ScreenSessionManager::GetCutoutInfo(DisplayId displayId)
1729 {
1730 return screenCutoutController_ ? screenCutoutController_->GetScreenCutoutInfo() : nullptr;
1731 }
1732
SetDisplayBoundary(const sptr<ScreenSession> screenSession)1733 void ScreenSessionManager::SetDisplayBoundary(const sptr<ScreenSession> screenSession)
1734 {
1735 if (screenSession && screenCutoutController_) {
1736 RectF rect =
1737 screenCutoutController_->CalculateCurvedCompression(screenSession->GetScreenProperty());
1738 if (!rect.IsEmpty()) {
1739 screenSession->SetDisplayBoundary(rect, screenCutoutController_->GetOffsetY());
1740 }
1741 } else {
1742 WLOGFW("screenSession or screenCutoutController_ is null");
1743 }
1744 }
1745
TransferTypeToString(ScreenType type) const1746 std::string ScreenSessionManager::TransferTypeToString(ScreenType type) const
1747 {
1748 std::string screenType;
1749 switch (type) {
1750 case ScreenType::REAL:
1751 screenType = "REAL";
1752 break;
1753 case ScreenType::VIRTUAL:
1754 screenType = "VIRTUAL";
1755 break;
1756 default:
1757 screenType = "UNDEFINED";
1758 break;
1759 }
1760 return screenType;
1761 }
1762
DumpAllScreensInfo(std::string & dumpInfo)1763 void ScreenSessionManager::DumpAllScreensInfo(std::string& dumpInfo)
1764 {
1765 std::ostringstream oss;
1766 oss << "--------------------------------------Free Screen"
1767 << "--------------------------------------"
1768 << std::endl;
1769 oss << "ScreenName Type IsGroup DmsId RsId ActiveIdx VPR Rotation Orientation "
1770 << "RequestOrientation NodeId "
1771 << std::endl;
1772 for (auto sessionIt : screenSessionMap_) {
1773 auto screenSession = sessionIt.second;
1774 if (screenSession == nullptr) {
1775 continue;
1776 }
1777 sptr<ScreenInfo> screenInfo = GetScreenInfoById(sessionIt.first);
1778 if (screenInfo == nullptr) {
1779 continue;
1780 }
1781 std::string screenType = TransferTypeToString(screenInfo->GetType());
1782 NodeId nodeId = (screenSession->GetDisplayNode() == nullptr) ?
1783 SCREEN_ID_INVALID : screenSession->GetDisplayNode()->GetId();
1784 oss << std::left << std::setw(21) << screenInfo->GetName()
1785 << std::left << std::setw(9) << screenType
1786 << std::left << std::setw(8) << (screenSession->isScreenGroup_ ? "true" : "false")
1787 << std::left << std::setw(6) << screenSession->screenId_
1788 << std::left << std::setw(21) << screenSession->rsId_
1789 << std::left << std::setw(10) << screenSession->activeIdx_
1790 << std::left << std::setw(4) << screenInfo->GetVirtualPixelRatio()
1791 << std::left << std::setw(9) << static_cast<uint32_t>(screenInfo->GetRotation())
1792 << std::left << std::setw(12) << static_cast<uint32_t>(screenInfo->GetOrientation())
1793 << std::left << std::setw(19) << static_cast<uint32_t>(screenSession->GetScreenRequestedOrientation())
1794 << std::left << std::setw(21) << nodeId
1795 << std::endl;
1796 }
1797 oss << "total screen num: " << screenSessionMap_.size() << std::endl;
1798 dumpInfo.append(oss.str());
1799 }
1800
DumpSpecialScreenInfo(ScreenId id,std::string & dumpInfo)1801 void ScreenSessionManager::DumpSpecialScreenInfo(ScreenId id, std::string& dumpInfo)
1802 {
1803 std::ostringstream oss;
1804 sptr<ScreenSession> session = GetScreenSession(id);
1805 if (!session) {
1806 WLOGFE("Get screen session failed.");
1807 oss << "This screen id is invalid.";
1808 dumpInfo.append(oss.str());
1809 return;
1810 }
1811 sptr<ScreenInfo> screenInfo = GetScreenInfoById(id);
1812 if (screenInfo == nullptr) {
1813 return;
1814 }
1815 std::string screenType = TransferTypeToString(screenInfo->GetType());
1816 NodeId nodeId = (session->GetDisplayNode() == nullptr) ?
1817 SCREEN_ID_INVALID : session->GetDisplayNode()->GetId();
1818 oss << "ScreenName: " << screenInfo->GetName() << std::endl;
1819 oss << "Type: " << screenType << std::endl;
1820 oss << "IsGroup: " << (session->isScreenGroup_ ? "true" : "false") << std::endl;
1821 oss << "DmsId: " << id << std::endl;
1822 oss << "RsId: " << session->rsId_ << std::endl;
1823 oss << "ActiveIdx: " << session->activeIdx_ << std::endl;
1824 oss << "VPR: " << screenInfo->GetVirtualPixelRatio() << std::endl;
1825 oss << "Rotation: " << static_cast<uint32_t>(screenInfo->GetRotation()) << std::endl;
1826 oss << "Orientation: " << static_cast<uint32_t>(screenInfo->GetOrientation()) << std::endl;
1827 oss << "RequestOrientation: " << static_cast<uint32_t>(session->GetScreenRequestedOrientation()) << std::endl;
1828 oss << "NodeId: " << nodeId << std::endl;
1829 dumpInfo.append(oss.str());
1830 }
1831
1832 // --- Fold Screen ---
SetFoldDisplayMode(const FoldDisplayMode displayMode)1833 void ScreenSessionManager::SetFoldDisplayMode(const FoldDisplayMode displayMode)
1834 {
1835 WLOGFI("ScreenSessionManager::SetFoldDisplayMode");
1836 }
1837
GetFoldDisplayMode()1838 FoldDisplayMode ScreenSessionManager::GetFoldDisplayMode()
1839 {
1840 return FoldDisplayMode::UNKNOWN;
1841 }
1842
IsFoldable()1843 bool ScreenSessionManager::IsFoldable()
1844 {
1845 return false;
1846 }
1847
GetFoldStatus()1848 FoldStatus ScreenSessionManager::GetFoldStatus()
1849 {
1850 return FoldStatus::UNKNOWN;
1851 }
1852
GetCurrentFoldCreaseRegion()1853 sptr<FoldCreaseRegion> ScreenSessionManager::GetCurrentFoldCreaseRegion()
1854 {
1855 return nullptr;
1856 }
1857
NotifyFoldStatusChanged(FoldStatus foldStatus)1858 void ScreenSessionManager::NotifyFoldStatusChanged(FoldStatus foldStatus)
1859 {
1860 WLOGI("NotifyFoldStatusChanged foldStatus:%{public}d", foldStatus);
1861 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::FOLD_STATUS_CHANGED_LISTENER);
1862 if (agents.empty()) {
1863 return;
1864 }
1865 for (auto& agent: agents) {
1866 agent->NotifyFoldStatusChanged(foldStatus);
1867 }
1868 }
1869
NotifyDisplayModeChanged(FoldDisplayMode displayMode)1870 void ScreenSessionManager::NotifyDisplayModeChanged(FoldDisplayMode displayMode)
1871 {
1872 WLOGI("NotifyDisplayModeChanged displayMode:%{public}d", displayMode);
1873 auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_MODE_CHANGED_LISTENER);
1874 if (agents.empty()) {
1875 return;
1876 }
1877 for (auto& agent: agents) {
1878 agent->NotifyDisplayModeChanged(displayMode);
1879 }
1880 }
1881 } // namespace OHOS::Rosen
1882