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
ChangeOnTentMode(FoldStatus currentState)75 void FoldScreenPolicy::ChangeOnTentMode(FoldStatus currentState) {}
76
ChangeOffTentMode()77 void FoldScreenPolicy::ChangeOffTentMode() {}
78
GetModeChangeRunningStatus()79 bool FoldScreenPolicy::GetModeChangeRunningStatus()
80 {
81 auto currentTime = std::chrono::steady_clock::now();
82 auto intervalMs = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - startTimePoint_).count();
83 if (intervalMs > MODE_CHANGE_TIMEOUT_MS) {
84 TLOGE(WmsLogTag::DMS, "mode change timeout.");
85 return false;
86 }
87 return GetdisplayModeRunningStatus();
88 }
89
GetdisplayModeRunningStatus()90 bool FoldScreenPolicy::GetdisplayModeRunningStatus()
91 {
92 return displayModeChangeRunning_.load();
93 }
94
GetLastCacheDisplayMode()95 FoldDisplayMode FoldScreenPolicy::GetLastCacheDisplayMode()
96 {
97 return lastCachedisplayMode_.load();
98 }
99
SetLastCacheDisplayMode(FoldDisplayMode mode)100 void FoldScreenPolicy::SetLastCacheDisplayMode(FoldDisplayMode mode)
101 {
102 lastCachedisplayMode_ = mode;
103 }
104
getFoldingElapsedMs()105 int64_t FoldScreenPolicy::getFoldingElapsedMs()
106 {
107 if (endTimePoint_ < startTimePoint_) {
108 TLOGE(WmsLogTag::DMS, "invalid timepoint. endTimePoint less startTimePoint");
109 return 0;
110 }
111 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(endTimePoint_ - startTimePoint_).count();
112 return static_cast<int64_t>(elapsed);
113 }
114
AddOrRemoveDisplayNodeToTree(ScreenId screenId,int32_t command)115 void FoldScreenPolicy::AddOrRemoveDisplayNodeToTree(ScreenId screenId, int32_t command) {};
116
SetScreenSnapshotRect(RSSurfaceCaptureConfig & config)117 void FoldScreenPolicy::SetScreenSnapshotRect(RSSurfaceCaptureConfig& config) {}
118
SetMainScreenRegion(DMRect & mainScreenRegion)119 void FoldScreenPolicy::SetMainScreenRegion(DMRect& mainScreenRegion) {}
120 } // namespace OHOS::Rosen