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 "fold_screen_controller/fold_screen_policy.h"
17 #include "window_manager_hilog.h"
18
19 namespace OHOS::Rosen {
20 namespace {
21 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "FoldScreenPolicy"};
22 const uint32_t MODE_CHANGE_TIMEOUT_MS = 2000;
23 } // namespace
24 FoldScreenPolicy::FoldScreenPolicy() = default;
25 FoldScreenPolicy::~FoldScreenPolicy() = default;
26
ChangeScreenDisplayMode(FoldDisplayMode displayMode,DisplayModeChangeReason reason)27 void FoldScreenPolicy::ChangeScreenDisplayMode(FoldDisplayMode displayMode, DisplayModeChangeReason reason) {}
28
GetScreenDisplayMode()29 FoldDisplayMode FoldScreenPolicy::GetScreenDisplayMode()
30 {
31 std::lock_guard<std::recursive_mutex> lock_mode(displayModeMutex_);
32 return lastDisplayMode_;
33 }
34
LockDisplayStatus(bool locked)35 void FoldScreenPolicy::LockDisplayStatus(bool locked)
36 {
37 lockDisplayStatus_ = locked;
38 }
39
GetFoldStatus()40 FoldStatus FoldScreenPolicy::GetFoldStatus()
41 {
42 return lastFoldStatus_;
43 }
44
SetFoldStatus(FoldStatus foldStatus)45 void FoldScreenPolicy::SetFoldStatus(FoldStatus foldStatus)
46 {
47 WLOGI("SetFoldStatus FoldStatus: %{public}d", foldStatus);
48 currentFoldStatus_ = foldStatus;
49 lastFoldStatus_ = foldStatus;
50 }
51
SendSensorResult(FoldStatus foldStatus)52 void FoldScreenPolicy::SendSensorResult(FoldStatus foldStatus) {}
GetCurrentScreenId()53 ScreenId FoldScreenPolicy::GetCurrentScreenId() { return screenId_; }
54
GetCurrentFoldCreaseRegion()55 sptr<FoldCreaseRegion> FoldScreenPolicy::GetCurrentFoldCreaseRegion()
56 {
57 return currentFoldCreaseRegion_;
58 }
59
SetOnBootAnimation(bool onBootAnimation)60 void FoldScreenPolicy::SetOnBootAnimation(bool onBootAnimation)
61 {
62 onBootAnimation_ = onBootAnimation;
63 }
64
UpdateForPhyScreenPropertyChange()65 void FoldScreenPolicy::UpdateForPhyScreenPropertyChange() {}
66
ClearState()67 void FoldScreenPolicy::ClearState()
68 {
69 currentDisplayMode_ = FoldDisplayMode::UNKNOWN;
70 currentFoldStatus_ = FoldStatus::UNKNOWN;
71 }
72
ExitCoordination()73 void FoldScreenPolicy::ExitCoordination() {};
74
AddOrRemoveDisplayNodeToTree(ScreenId screenId,int32_t command)75 void FoldScreenPolicy::AddOrRemoveDisplayNodeToTree(ScreenId screenId, int32_t command) {};
76
ChangeOnTentMode(FoldStatus currentState)77 void FoldScreenPolicy::ChangeOnTentMode(FoldStatus currentState) {}
78
ChangeOffTentMode()79 void FoldScreenPolicy::ChangeOffTentMode() {}
80
GetModeChangeRunningStatus()81 bool FoldScreenPolicy::GetModeChangeRunningStatus()
82 {
83 auto currentTime = std::chrono::steady_clock::now();
84 auto intervalMs = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - startTimePoint_).count();
85 if (intervalMs > MODE_CHANGE_TIMEOUT_MS) {
86 TLOGE(WmsLogTag::DMS, "mode change timeout.");
87 return false;
88 }
89 return GetdisplayModeRunningStatus();
90 }
91
GetdisplayModeRunningStatus()92 bool FoldScreenPolicy::GetdisplayModeRunningStatus()
93 {
94 return displayModeChangeRunning_.load();
95 }
96
GetLastCacheDisplayMode()97 FoldDisplayMode FoldScreenPolicy::GetLastCacheDisplayMode()
98 {
99 return lastCachedisplayMode_.load();
100 }
101
SetLastCacheDisplayMode(FoldDisplayMode mode)102 void FoldScreenPolicy::SetLastCacheDisplayMode(FoldDisplayMode mode)
103 {
104 lastCachedisplayMode_ = mode;
105 }
106
getFoldingElapsedMs()107 int64_t FoldScreenPolicy::getFoldingElapsedMs()
108 {
109 if (endTimePoint_ < startTimePoint_) {
110 TLOGE(WmsLogTag::DMS, "invalid timepoint. endTimePoint less startTimePoint");
111 return 0;
112 }
113 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(endTimePoint_ - startTimePoint_).count();
114 return static_cast<int64_t>(elapsed);
115 }
116 } // namespace OHOS::Rosen