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 <hisysevent.h>
17 #include <hitrace_meter.h>
18 #include <transaction/rs_interfaces.h>
19 #include "fold_screen_controller/single_display_fold_policy.h"
20 #include "session/screen/include/screen_session.h"
21 #include "screen_session_manager.h"
22 #include "fold_screen_state_internel.h"
23
24 #include "window_manager_hilog.h"
25
26 #ifdef POWER_MANAGER_ENABLE
27 #include <power_mgr_client.h>
28 #endif
29
30 namespace OHOS::Rosen {
31 namespace {
32 const ScreenId SCREEN_ID_FULL = 0;
33 const ScreenId SCREEN_ID_MAIN = 5;
34 const int32_t CREASE_REGION_POS_Y = 994;
35 const int32_t CREASE_REGION_POS_WIDTH = 1320;
36 const int32_t CREASE_REGION_POS_HEIGHT = 132;
37 constexpr int32_t FOLD_CREASE_RECT_SIZE = 4; //numbers of parameter on the current device is 4
38 const std::string g_FoldScreenRect = system::GetParameter("const.display.foldscreen.crease_region", "");
39 const std::string FOLD_CREASE_DELIMITER = ",;";
40
41 #ifdef TP_FEATURE_ENABLE
42 const int32_t TP_TYPE = 12;
43 const int32_t TP_TYPE_POWER_CTRL = 18;
44 const std::string FULL_TP = "0";
45 const std::string MAIN_TP = "1";
46 const std::string MAIN_TP_OFF = "1,1";
47 const std::string FULL_TP_OFF = "0,1";
48 #endif
49 } // namespace
50
SingleDisplayFoldPolicy(std::recursive_mutex & displayInfoMutex,std::shared_ptr<TaskScheduler> screenPowerTaskScheduler)51 SingleDisplayFoldPolicy::SingleDisplayFoldPolicy(std::recursive_mutex& displayInfoMutex,
52 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler)
53 : displayInfoMutex_(displayInfoMutex), screenPowerTaskScheduler_(screenPowerTaskScheduler)
54 {
55 TLOGI(WmsLogTag::DMS, "SingleDisplayFoldPolicy created");
56
57 ScreenId screenIdFull = 0;
58 int32_t foldCreaseRegionPosX = 0;
59 int32_t foldCreaseRegionPosY = CREASE_REGION_POS_Y;
60 int32_t foldCreaseRegionPosWidth = CREASE_REGION_POS_WIDTH;
61 int32_t foldCreaseRegionPosHeight = CREASE_REGION_POS_HEIGHT;
62
63 std::vector<DMRect> rect = {
64 {
65 foldCreaseRegionPosX, foldCreaseRegionPosY,
66 foldCreaseRegionPosWidth, foldCreaseRegionPosHeight
67 }
68 };
69 currentFoldCreaseRegion_ = new FoldCreaseRegion(screenIdFull, rect);
70 }
71
GetFoldCreaseRegion(bool isVertical) const72 FoldCreaseRegion SingleDisplayFoldPolicy::GetFoldCreaseRegion(bool isVertical) const
73 {
74 std::vector<int32_t> foldRect = FoldScreenStateInternel::StringFoldRectSplitToInt(g_FoldScreenRect,
75 FOLD_CREASE_DELIMITER);
76 if (foldRect.size() != FOLD_CREASE_RECT_SIZE) {
77 TLOGE(WmsLogTag::DMS, "foldRect is invalid");
78 return FoldCreaseRegion(0, {});
79 }
80
81 ScreenId screenIdFull = 0;
82 std::vector<DMRect> foldCreaseRect;
83 GetFoldCreaseRect(isVertical, foldRect, foldCreaseRect);
84 return FoldCreaseRegion(screenIdFull, foldCreaseRect);
85 }
86
GetFoldCreaseRect(bool isVertical,const std::vector<int32_t> & foldRect,std::vector<DMRect> & foldCreaseRect) const87 void SingleDisplayFoldPolicy::GetFoldCreaseRect(bool isVertical,
88 const std::vector<int32_t>& foldRect, std::vector<DMRect>& foldCreaseRect) const
89 {
90 int32_t liveCreaseRegionPosX; // live Crease Region PosX
91 int32_t liveCreaseRegionPosY; // live Crease Region PosY
92 uint32_t liveCreaseRegionPosWidth; // live Crease Region PosWidth
93 uint32_t liveCreaseRegionPosHeight; // live Crease Region PosHeight
94 if (isVertical) {
95 TLOGI(WmsLogTag::DMS, "the current FoldCreaseRect is vertical");
96 liveCreaseRegionPosX = foldRect[0];
97 liveCreaseRegionPosY = foldRect[1];
98 liveCreaseRegionPosWidth = static_cast<uint32_t>(foldRect[2]);
99 liveCreaseRegionPosHeight = static_cast<uint32_t>(foldRect[3]);
100 } else {
101 TLOGI(WmsLogTag::DMS, "the current FoldCreaseRect is horizontal");
102 liveCreaseRegionPosX = foldRect[1];
103 liveCreaseRegionPosY = foldRect[0];
104 liveCreaseRegionPosWidth = static_cast<uint32_t>(foldRect[3]);
105 liveCreaseRegionPosHeight = static_cast<uint32_t>(foldRect[2]);
106 }
107 foldCreaseRect = {
108 {
109 liveCreaseRegionPosX, liveCreaseRegionPosY,
110 liveCreaseRegionPosWidth, liveCreaseRegionPosHeight
111 }
112 };
113 return;
114 }
115
SetdisplayModeChangeStatus(bool status,bool isOnBootAnimation)116 void SingleDisplayFoldPolicy::SetdisplayModeChangeStatus(bool status, bool isOnBootAnimation)
117 {
118 if (status) {
119 pengdingTask_ = isOnBootAnimation ? FOLD_TO_EXPAND_ONBOOTANIMATION_TASK_NUM : FOLD_TO_EXPAND_TASK_NUM;
120 startTimePoint_ = std::chrono::steady_clock::now();
121 displayModeChangeRunning_ = status;
122 } else {
123 pengdingTask_ --;
124 if (pengdingTask_ != 0) {
125 return;
126 }
127 displayModeChangeRunning_ = false;
128 endTimePoint_ = std::chrono::steady_clock::now();
129 if (lastCachedisplayMode_.load() != GetScreenDisplayMode()) {
130 ScreenSessionManager::GetInstance().TriggerDisplayModeUpdate(lastCachedisplayMode_.load());
131 }
132 }
133 }
134
ChangeScreenDisplayMode(FoldDisplayMode displayMode,DisplayModeChangeReason reason)135 void SingleDisplayFoldPolicy::ChangeScreenDisplayMode(FoldDisplayMode displayMode, DisplayModeChangeReason reason)
136 {
137 if (isClearingBootAnimation_) {
138 TLOGI(WmsLogTag::DMS, "clearing bootAnimation not change displayMode");
139 return;
140 }
141 SetLastCacheDisplayMode(displayMode);
142 if (GetModeChangeRunningStatus()) {
143 TLOGW(WmsLogTag::DMS, "last process not complete, skip mode: %{public}d", displayMode);
144 return;
145 }
146 TLOGI(WmsLogTag::DMS, "start change displaymode: %{public}d, lastElapsedMs: %{public}" PRId64 "ms",
147 displayMode, getFoldingElapsedMs());
148
149 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:ChangeScreenDisplayMode(displayMode = %" PRIu64")", displayMode);
150 {
151 std::lock_guard<std::recursive_mutex> lock_mode(displayModeMutex_);
152 if (currentDisplayMode_ == displayMode) {
153 TLOGW(WmsLogTag::DMS, "ChangeScreenDisplayMode already in displayMode %{public}d", displayMode);
154 return;
155 }
156 }
157 ChangeScreenDisplayModeInner(displayMode, reason);
158 ScreenSessionManager::GetInstance().NotifyDisplayModeChanged(displayMode);
159 ScreenSessionManager::GetInstance().SwitchScrollParam(displayMode);
160 }
161
ChangeScreenDisplayModeInner(FoldDisplayMode displayMode,DisplayModeChangeReason reason)162 void SingleDisplayFoldPolicy::ChangeScreenDisplayModeInner(FoldDisplayMode displayMode, DisplayModeChangeReason reason)
163 {
164 sptr<ScreenSession> screenSession = ScreenSessionManager::GetInstance().GetScreenSession(SCREEN_ID_FULL);
165 if (screenSession == nullptr) {
166 TLOGE(WmsLogTag::DMS, "default screenSession is null");
167 return;
168 }
169 SetdisplayModeChangeStatus(true);
170 {
171 std::lock_guard<std::recursive_mutex> lock_mode(displayModeMutex_);
172 lastDisplayMode_ = displayMode;
173 }
174 ReportFoldDisplayModeChange(displayMode);
175 switch (displayMode) {
176 case FoldDisplayMode::MAIN: {
177 ChangeScreenDisplayModeToMain(screenSession, reason);
178 break;
179 }
180 case FoldDisplayMode::FULL: {
181 ChangeScreenDisplayModeToFull(screenSession, reason);
182 break;
183 }
184 case FoldDisplayMode::UNKNOWN: {
185 TLOGI(WmsLogTag::DMS, "displayMode is unknown");
186 break;
187 }
188 default: {
189 TLOGI(WmsLogTag::DMS, "displayMode is invalid");
190 break;
191 }
192 }
193 {
194 std::lock_guard<std::recursive_mutex> lock_mode(displayModeMutex_);
195 currentDisplayMode_ = displayMode;
196 }
197 }
198
SendSensorResult(FoldStatus foldStatus)199 void SingleDisplayFoldPolicy::SendSensorResult(FoldStatus foldStatus)
200 {
201 TLOGI(WmsLogTag::DMS, "SendSensorResult FoldStatus: %{public}d", foldStatus);
202 FoldDisplayMode displayMode = GetModeMatchStatus();
203 ChangeScreenDisplayMode(displayMode);
204 }
205
GetCurrentFoldCreaseRegion()206 sptr<FoldCreaseRegion> SingleDisplayFoldPolicy::GetCurrentFoldCreaseRegion()
207 {
208 TLOGI(WmsLogTag::DMS, "GetCurrentFoldCreaseRegion");
209 return currentFoldCreaseRegion_;
210 }
211
GetLiveCreaseRegion()212 FoldCreaseRegion SingleDisplayFoldPolicy::GetLiveCreaseRegion()
213 {
214 TLOGI(WmsLogTag::DMS, "enter");
215 std::lock_guard<std::mutex> lock_mode(liveCreaseRegionMutex_);
216 FoldDisplayMode displayMode = GetScreenDisplayMode();
217 if (displayMode == FoldDisplayMode::UNKNOWN || displayMode == FoldDisplayMode::MAIN) {
218 return FoldCreaseRegion(0, {});
219 }
220 sptr<ScreenSession> screenSession = ScreenSessionManager::GetInstance().GetScreenSession(SCREEN_ID_FULL);
221 if (screenSession == nullptr) {
222 TLOGE(WmsLogTag::DMS, "default screenSession is null");
223 return FoldCreaseRegion(0, {});
224 }
225 DisplayOrientation displayOrientation = screenSession->GetScreenProperty().GetDisplayOrientation();
226 if (displayMode == FoldDisplayMode::FULL) {
227 switch (displayOrientation) {
228 case DisplayOrientation::PORTRAIT:
229 case DisplayOrientation::PORTRAIT_INVERTED: {
230 liveCreaseRegion_ = GetFoldCreaseRegion(true);
231 break;
232 }
233 case DisplayOrientation::LANDSCAPE:
234 case DisplayOrientation::LANDSCAPE_INVERTED: {
235 liveCreaseRegion_ = GetFoldCreaseRegion(false);
236 break;
237 }
238 default: {
239 TLOGE(WmsLogTag::DMS, "displayOrientation is invalid");
240 }
241 }
242 }
243 return liveCreaseRegion_;
244 }
245
GetAllCreaseRegion(std::vector<FoldCreaseRegionItem> & foldCreaseRegionItems) const246 void SingleDisplayFoldPolicy::GetAllCreaseRegion(std::vector<FoldCreaseRegionItem>& foldCreaseRegionItems) const
247 {
248 FoldCreaseRegionItem MCreaseItem{DisplayOrientation::LANDSCAPE, FoldDisplayMode::MAIN,
249 FoldCreaseRegion(0, {})};
250 FoldCreaseRegionItem FPorCreaseItem{DisplayOrientation::PORTRAIT, FoldDisplayMode::FULL,
251 GetFoldCreaseRegion(true)};
252 FoldCreaseRegionItem FLandCreaseItem{DisplayOrientation::LANDSCAPE, FoldDisplayMode::FULL,
253 GetFoldCreaseRegion(false)};
254 foldCreaseRegionItems.push_back(MCreaseItem);
255 foldCreaseRegionItems.push_back(FPorCreaseItem);
256 foldCreaseRegionItems.push_back(FLandCreaseItem);
257 }
258
LockDisplayStatus(bool locked)259 void SingleDisplayFoldPolicy::LockDisplayStatus(bool locked)
260 {
261 TLOGI(WmsLogTag::DMS, "LockDisplayStatus locked: %{public}d", locked);
262 lockDisplayStatus_ = locked;
263 }
264
SetOnBootAnimation(bool onBootAnimation)265 void SingleDisplayFoldPolicy::SetOnBootAnimation(bool onBootAnimation)
266 {
267 TLOGI(WmsLogTag::DMS, "onBootAnimation: %{public}d", onBootAnimation);
268 onBootAnimation_ = onBootAnimation;
269 if (!onBootAnimation_) {
270 TLOGI(WmsLogTag::DMS, "when boot animation finished, change display mode");
271 RecoverWhenBootAnimationExit();
272 }
273 }
274
RecoverWhenBootAnimationExit()275 void SingleDisplayFoldPolicy::RecoverWhenBootAnimationExit()
276 {
277 TLOGI(WmsLogTag::DMS, "CurrentScreen(%{public}" PRIu64 ")", screenId_);
278 FoldDisplayMode displayMode = GetModeMatchStatus();
279 if (currentDisplayMode_ != displayMode) {
280 ChangeScreenDisplayMode(displayMode);
281 }
282 }
283
UpdateForPhyScreenPropertyChange()284 void SingleDisplayFoldPolicy::UpdateForPhyScreenPropertyChange()
285 {
286 TLOGI(WmsLogTag::DMS, "CurrentScreen(%{public}" PRIu64 ")", screenId_);
287 FoldDisplayMode displayMode = GetModeMatchStatus();
288 if (currentDisplayMode_ != displayMode) {
289 ChangeScreenDisplayMode(displayMode);
290 }
291 }
292
GetModeMatchStatus()293 FoldDisplayMode SingleDisplayFoldPolicy::GetModeMatchStatus()
294 {
295 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
296 switch (currentFoldStatus_) {
297 case FoldStatus::EXPAND: {
298 displayMode = FoldDisplayMode::FULL;
299 break;
300 }
301 case FoldStatus::FOLDED: {
302 displayMode = FoldDisplayMode::MAIN;
303 break;
304 }
305 case FoldStatus::HALF_FOLD: {
306 displayMode = FoldDisplayMode::FULL;
307 break;
308 }
309 default: {
310 TLOGI(WmsLogTag::DMS, "GetModeMatchStatus FoldStatus is invalid");
311 }
312 }
313 return displayMode;
314 }
315
ReportFoldDisplayModeChange(FoldDisplayMode displayMode)316 void SingleDisplayFoldPolicy::ReportFoldDisplayModeChange(FoldDisplayMode displayMode)
317 {
318 int32_t mode = static_cast<int32_t>(displayMode);
319 TLOGI(WmsLogTag::DMS, "displayMode: %{public}d", mode);
320 int32_t ret = HiSysEventWrite(
321 OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER,
322 "DISPLAY_MODE",
323 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
324 "FOLD_DISPLAY_MODE", mode);
325 if (ret != 0) {
326 TLOGE(WmsLogTag::DMS, "Write HiSysEvent error, ret: %{public}d", ret);
327 }
328 }
329
ReportFoldStatusChangeBegin(int32_t offScreen,int32_t onScreen)330 void SingleDisplayFoldPolicy::ReportFoldStatusChangeBegin(int32_t offScreen, int32_t onScreen)
331 {
332 TLOGI(WmsLogTag::DMS, "offScreen: %{public}d, onScreen: %{public}d",
333 offScreen, onScreen);
334 int32_t ret = HiSysEventWrite(
335 OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER,
336 "FOLD_STATE_CHANGE_BEGIN",
337 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
338 "POWER_OFF_SCREEN", offScreen,
339 "POWER_ON_SCREEN", onScreen);
340 if (ret != 0) {
341 TLOGE(WmsLogTag::DMS, "Write HiSysEvent error, ret: %{public}d", ret);
342 }
343 }
344
ChangeScreenDisplayModeToMainWhenFoldScreenOn(sptr<ScreenSession> screenSession)345 void SingleDisplayFoldPolicy::ChangeScreenDisplayModeToMainWhenFoldScreenOn(sptr<ScreenSession> screenSession)
346 {
347 TLOGI(WmsLogTag::DMS, "IsFoldScreenOn is true, begin.");
348 ReportFoldStatusChangeBegin(static_cast<int32_t>(SCREEN_ID_FULL),
349 static_cast<int32_t>(SCREEN_ID_MAIN));
350 auto taskScreenOnMain = [=] {
351 // off full screen
352 TLOGNI(WmsLogTag::DMS, "ChangeScreenDisplayModeToMain: IsFoldScreenOn is true, screenIdFull OFF.");
353 screenId_ = SCREEN_ID_FULL;
354 ChangeScreenDisplayModePower(SCREEN_ID_FULL, ScreenPowerStatus::POWER_STATUS_OFF);
355 SetdisplayModeChangeStatus(false);
356
357 // on main screen
358 TLOGNI(WmsLogTag::DMS, "ChangeScreenDisplayModeToMain: IsFoldScreenOn is true, screenIdMain ON.");
359 screenId_ = SCREEN_ID_MAIN;
360 ChangeScreenDisplayModePower(SCREEN_ID_MAIN, ScreenPowerStatus::POWER_STATUS_ON);
361 SetdisplayModeChangeStatus(false);
362 };
363 screenPowerTaskScheduler_->PostAsyncTask(taskScreenOnMain, "screenOnMainTask");
364 SendPropertyChangeResult(screenSession, SCREEN_ID_MAIN, ScreenPropertyChangeReason::FOLD_SCREEN_FOLDING);
365 }
366
ChangeScreenDisplayModeToMainWhenFoldScreenOff(sptr<ScreenSession> screenSession)367 void SingleDisplayFoldPolicy::ChangeScreenDisplayModeToMainWhenFoldScreenOff(sptr<ScreenSession> screenSession)
368 {
369 TLOGI(WmsLogTag::DMS, "IsFoldScreenOn is false, begin.");
370 // off full screen
371 auto taskScreenOffMainOff = [=] {
372 TLOGNI(WmsLogTag::DMS, "ChangeScreenDisplayModeToMain: IsFoldScreenOn is false, screenIdFull OFF.");
373 screenId_ = SCREEN_ID_FULL;
374 ChangeScreenDisplayModePower(SCREEN_ID_FULL, ScreenPowerStatus::POWER_STATUS_OFF);
375 SetdisplayModeChangeStatus(false);
376 };
377 screenPowerTaskScheduler_->PostAsyncTask(taskScreenOffMainOff, "screenOffMainOffTask");
378 SendPropertyChangeResult(screenSession, SCREEN_ID_MAIN, ScreenPropertyChangeReason::FOLD_SCREEN_FOLDING);
379 auto taskScreenOnMainChangeScreenId = [=] {
380 TLOGNI(WmsLogTag::DMS, "ChangeScreenDisplayModeToMain: IsFoldScreenOn is false, Change ScreenId to Main.");
381 screenId_ = SCREEN_ID_MAIN;
382 #ifdef TP_FEATURE_ENABLE
383 RSInterfaces::GetInstance().SetTpFeatureConfig(TP_TYPE_POWER_CTRL, MAIN_TP_OFF.c_str());
384 #endif
385 SetdisplayModeChangeStatus(false);
386 };
387 screenPowerTaskScheduler_->PostAsyncTask(taskScreenOnMainChangeScreenId, "taskScreenOnMainChangeScreenId");
388 }
389
ChangeScreenDisplayModeToMain(sptr<ScreenSession> screenSession,DisplayModeChangeReason reason)390 void SingleDisplayFoldPolicy::ChangeScreenDisplayModeToMain(sptr<ScreenSession> screenSession,
391 DisplayModeChangeReason reason)
392 {
393 if (onBootAnimation_) {
394 SetdisplayModeChangeStatus(true, true);
395 ChangeScreenDisplayModeToMainOnBootAnimation(screenSession);
396 return;
397 }
398 RSInterfaces::GetInstance().NotifyScreenSwitched();
399 #ifdef TP_FEATURE_ENABLE
400 RSInterfaces::GetInstance().SetTpFeatureConfig(TP_TYPE, MAIN_TP.c_str());
401 #endif
402 if (PowerMgr::PowerMgrClient::GetInstance().IsFoldScreenOn() ||
403 ScreenSessionManager::GetInstance().GetCancelSuspendStatus()) {
404 ChangeScreenDisplayModeToMainWhenFoldScreenOn(screenSession);
405 } else { // When the screen is off and folded, it is not powered on
406 ScreenSessionManager::GetInstance().ForceSkipScreenOffAnimation();
407 ChangeScreenDisplayModeToMainWhenFoldScreenOff(screenSession);
408 }
409 }
410
ChangeScreenDisplayModeToFullWhenFoldScreenOn(sptr<ScreenSession> screenSession)411 void SingleDisplayFoldPolicy::ChangeScreenDisplayModeToFullWhenFoldScreenOn(sptr<ScreenSession> screenSession)
412 {
413 TLOGI(WmsLogTag::DMS, "IsFoldScreenOn is true, begin.");
414 auto taskScreenOnFull = [=] {
415 // off main screen
416 TLOGNI(WmsLogTag::DMS, "ChangeScreenDisplayModeToFull: IsFoldScreenOn is true, screenIdMain OFF.");
417 screenId_ = SCREEN_ID_MAIN;
418 ChangeScreenDisplayModePower(SCREEN_ID_MAIN, ScreenPowerStatus::POWER_STATUS_OFF);
419 SetdisplayModeChangeStatus(false);
420
421 // on full screen
422 TLOGNI(WmsLogTag::DMS, "ChangeScreenDisplayModeToFull: IsFoldScreenOn is true, screenIdFull ON.");
423 screenId_ = SCREEN_ID_FULL;
424 ChangeScreenDisplayModePower(SCREEN_ID_FULL, ScreenPowerStatus::POWER_STATUS_ON);
425 SetdisplayModeChangeStatus(false);
426 };
427 screenPowerTaskScheduler_->PostAsyncTask(taskScreenOnFull, "screenOnFullTask");
428 SendPropertyChangeResult(screenSession, SCREEN_ID_FULL, ScreenPropertyChangeReason::FOLD_SCREEN_EXPAND);
429 }
430
ChangeScreenDisplayModeToFullWhenFoldScreenOff(sptr<ScreenSession> screenSession,DisplayModeChangeReason reason)431 void SingleDisplayFoldPolicy::ChangeScreenDisplayModeToFullWhenFoldScreenOff(sptr<ScreenSession> screenSession,
432 DisplayModeChangeReason reason)
433 {
434 TLOGI(WmsLogTag::DMS, "IsFoldScreenOn is false, begin.");
435 // off main screen
436 auto taskScreenOffFullOff = [=] {
437 TLOGNI(WmsLogTag::DMS, "ChangeScreenDisplayModeToFull: IsFoldScreenOn is false, screenIdMain OFF.");
438 screenId_ = SCREEN_ID_MAIN;
439 ChangeScreenDisplayModePower(SCREEN_ID_MAIN, ScreenPowerStatus::POWER_STATUS_OFF);
440 SetdisplayModeChangeStatus(false);
441 };
442 screenPowerTaskScheduler_->PostAsyncTask(taskScreenOffFullOff, "screenOffFullOffTask");
443 SendPropertyChangeResult(screenSession, SCREEN_ID_FULL, ScreenPropertyChangeReason::FOLD_SCREEN_EXPAND);
444 // on full screen
445 auto taskScreenOnFullOn = [=] {
446 TLOGNI(WmsLogTag::DMS, "ChangeScreenDisplayModeToFull: IsFoldScreenOn is false, screenIdFull ON.");
447 screenId_ = SCREEN_ID_FULL;
448 if (reason == DisplayModeChangeReason::RECOVER) {
449 #ifdef TP_FEATURE_ENABLE
450 RSInterfaces::GetInstance().SetTpFeatureConfig(TP_TYPE_POWER_CTRL, FULL_TP_OFF.c_str());
451 #endif
452 } else {
453 PowerMgr::PowerMgrClient::GetInstance().WakeupDeviceAsync();
454 }
455 SetdisplayModeChangeStatus(false);
456 };
457 screenPowerTaskScheduler_->PostAsyncTask(taskScreenOnFullOn, "screenOnFullOnTask");
458 }
459
ChangeScreenDisplayModeToFull(sptr<ScreenSession> screenSession,DisplayModeChangeReason reason)460 void SingleDisplayFoldPolicy::ChangeScreenDisplayModeToFull(sptr<ScreenSession> screenSession,
461 DisplayModeChangeReason reason)
462 {
463 if (onBootAnimation_) {
464 SetdisplayModeChangeStatus(true, true);
465 ChangeScreenDisplayModeToFullOnBootAnimation(screenSession);
466 return;
467 }
468 RSInterfaces::GetInstance().NotifyScreenSwitched();
469 ReportFoldStatusChangeBegin((int32_t)SCREEN_ID_MAIN, (int32_t)SCREEN_ID_FULL);
470 #ifdef TP_FEATURE_ENABLE
471 RSInterfaces::GetInstance().SetTpFeatureConfig(TP_TYPE, FULL_TP.c_str());
472 #endif
473 if (PowerMgr::PowerMgrClient::GetInstance().IsFoldScreenOn()) {
474 ChangeScreenDisplayModeToFullWhenFoldScreenOn(screenSession);
475 } else { //AOD scene
476 if (ScreenSessionManager::GetInstance().TryToCancelScreenOff()) {
477 ChangeScreenDisplayModeToFullWhenFoldScreenOn(screenSession);
478 } else {
479 ChangeScreenDisplayModeToFullWhenFoldScreenOff(screenSession, reason);
480 }
481 }
482 }
483
ChangeScreenDisplayModePower(ScreenId screenId,ScreenPowerStatus screenPowerStatus)484 void SingleDisplayFoldPolicy::ChangeScreenDisplayModePower(ScreenId screenId, ScreenPowerStatus screenPowerStatus)
485 {
486 ScreenSessionManager::GetInstance().SetKeyguardDrawnDoneFlag(false);
487 ScreenSessionManager::GetInstance().SetScreenPowerForFold(screenId, screenPowerStatus);
488 }
489
SendPropertyChangeResult(sptr<ScreenSession> screenSession,ScreenId screenId,ScreenPropertyChangeReason reason)490 void SingleDisplayFoldPolicy::SendPropertyChangeResult(sptr<ScreenSession> screenSession, ScreenId screenId,
491 ScreenPropertyChangeReason reason)
492 {
493 std::lock_guard<std::recursive_mutex> lock_info(displayInfoMutex_);
494 screenProperty_ = ScreenSessionManager::GetInstance().GetPhyScreenProperty(screenId);
495 ScreenProperty property = screenSession->UpdatePropertyByFoldControl(screenProperty_);
496 screenSession->SetRotationAndScreenRotationOnly(Rotation::ROTATION_0);
497 screenSession->PropertyChange(property, reason);
498 TLOGI(WmsLogTag::DMS, "screenBounds : width_= %{public}f, height_= %{public}f",
499 screenSession->GetScreenProperty().GetBounds().rect_.width_,
500 screenSession->GetScreenProperty().GetBounds().rect_.height_);
501 ScreenSessionManager::GetInstance().NotifyDisplayChanged(screenSession->ConvertToDisplayInfo(),
502 DisplayChangeEvent::DISPLAY_SIZE_CHANGED);
503 }
504
ChangeScreenDisplayModeToMainOnBootAnimation(sptr<ScreenSession> screenSession)505 void SingleDisplayFoldPolicy::ChangeScreenDisplayModeToMainOnBootAnimation(sptr<ScreenSession> screenSession)
506 {
507 TLOGI(WmsLogTag::DMS, "enter!");
508 screenProperty_ = ScreenSessionManager::GetInstance().GetPhyScreenProperty(SCREEN_ID_MAIN);
509 screenSession->UpdatePropertyByFoldControl(screenProperty_);
510 screenSession->PropertyChange(screenSession->GetScreenProperty(),
511 ScreenPropertyChangeReason::FOLD_SCREEN_FOLDING);
512 TLOGI(WmsLogTag::DMS, "screenBounds : width_= %{public}f, height_= %{public}f",
513 screenSession->GetScreenProperty().GetBounds().rect_.width_,
514 screenSession->GetScreenProperty().GetBounds().rect_.height_);
515 screenId_ = SCREEN_ID_MAIN;
516 }
517
ChangeScreenDisplayModeToFullOnBootAnimation(sptr<ScreenSession> screenSession)518 void SingleDisplayFoldPolicy::ChangeScreenDisplayModeToFullOnBootAnimation(sptr<ScreenSession> screenSession)
519 {
520 TLOGI(WmsLogTag::DMS, "enter!");
521 screenProperty_ = ScreenSessionManager::GetInstance().GetPhyScreenProperty(SCREEN_ID_FULL);
522 screenSession->UpdatePropertyByFoldControl(screenProperty_);
523 screenSession->PropertyChange(screenSession->GetScreenProperty(),
524 ScreenPropertyChangeReason::FOLD_SCREEN_EXPAND);
525 TLOGI(WmsLogTag::DMS, "screenBounds : width_= %{public}f, height_= %{public}f",
526 screenSession->GetScreenProperty().GetBounds().rect_.width_,
527 screenSession->GetScreenProperty().GetBounds().rect_.height_);
528 screenId_ = SCREEN_ID_FULL;
529 }
530
SetIsClearingBootAnimation(bool isClearingBootAnimation)531 void SingleDisplayFoldPolicy::SetIsClearingBootAnimation(bool isClearingBootAnimation)
532 {
533 TLOGI(WmsLogTag::DMS, "isClearingBootAnimation: %{public}d", isClearingBootAnimation);
534 isClearingBootAnimation_ = isClearingBootAnimation;
535 }
536 } // namespace OHOS::Rosen