• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_controller.h"
17 #include "fold_screen_controller/dual_display_device_policy.h"
18 #include "fold_screen_controller/fold_screen_sensor_manager.h"
19 
20 #include "window_manager_hilog.h"
21 
22 namespace OHOS::Rosen {
23 namespace {
24     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "FoldScreenController"};
25 } // namespace
26 
FoldScreenController(std::recursive_mutex & displayInfoMutex,std::shared_ptr<TaskScheduler> screenPowerTaskScheduler)27 FoldScreenController::FoldScreenController(std::recursive_mutex& displayInfoMutex,
28     std::shared_ptr<TaskScheduler> screenPowerTaskScheduler)
29     : displayInfoMutex_(displayInfoMutex), screenPowerTaskScheduler_(screenPowerTaskScheduler)
30 {
31     foldScreenPolicy_ = GetFoldScreenPolicy(DisplayDeviceType::DOUBLE_DISPLAY_DEVICE);
32     if (foldScreenPolicy_ == nullptr) {
33         WLOGE("FoldScreenPolicy is null");
34         return;
35     }
36 #ifdef SENSOR_ENABLE
37     FoldScreenSensorManager::GetInstance().SetFoldScreenPolicy(foldScreenPolicy_);
38 #endif
39 }
40 
~FoldScreenController()41 FoldScreenController::~FoldScreenController()
42 {
43     WLOGFI("FoldScreenController is destructed");
44 }
45 
GetFoldScreenPolicy(DisplayDeviceType productType)46 sptr<FoldScreenPolicy> FoldScreenController::GetFoldScreenPolicy(DisplayDeviceType productType)
47 {
48     sptr<FoldScreenPolicy> tempPolicy = nullptr;
49     switch (productType) {
50         case DisplayDeviceType::DOUBLE_DISPLAY_DEVICE: {
51             tempPolicy = new DualDisplayDevicePolicy(displayInfoMutex_, screenPowerTaskScheduler_);
52             break;
53         }
54         default: {
55             WLOGE("GetFoldScreenPolicy DisplayDeviceType is invalid");
56             break;
57         }
58     }
59 
60     return tempPolicy;
61 }
62 
SetDisplayMode(const FoldDisplayMode displayMode)63 void FoldScreenController::SetDisplayMode(const FoldDisplayMode displayMode)
64 {
65     if (foldScreenPolicy_ == nullptr) {
66         WLOGW("SetDisplayMode: foldScreenPolicy_ is null");
67         return;
68     }
69     foldScreenPolicy_->ChangeScreenDisplayMode(displayMode);
70 }
71 
LockDisplayStatus(bool locked)72 void FoldScreenController::LockDisplayStatus(bool locked)
73 {
74     if (foldScreenPolicy_ == nullptr) {
75         WLOGW("LockDisplayStatus: foldScreenPolicy_ is null");
76         return;
77     }
78     foldScreenPolicy_->LockDisplayStatus(locked);
79 }
80 
GetDisplayMode()81 FoldDisplayMode FoldScreenController::GetDisplayMode()
82 {
83     if (foldScreenPolicy_ == nullptr) {
84         WLOGW("GetDisplayMode: foldScreenPolicy_ is null");
85         return FoldDisplayMode::UNKNOWN;
86     }
87     return foldScreenPolicy_->GetScreenDisplayMode();
88 }
89 
IsFoldable()90 bool FoldScreenController::IsFoldable()
91 {
92     return true;
93 }
94 
GetFoldStatus()95 FoldStatus FoldScreenController::GetFoldStatus()
96 {
97     if (foldScreenPolicy_ == nullptr) {
98         WLOGW("GetFoldStatus: foldScreenPolicy_ is null");
99         return FoldStatus::UNKNOWN;
100     }
101     return foldScreenPolicy_->GetFoldStatus();
102 }
103 
SetFoldStatus(FoldStatus foldStatus)104 void FoldScreenController::SetFoldStatus(FoldStatus foldStatus)
105 {
106     if (foldScreenPolicy_ == nullptr) {
107         WLOGW("SetFoldStatus: foldScreenPolicy_ is null");
108         return;
109     }
110     foldScreenPolicy_->SetFoldStatus(foldStatus);
111 }
112 
GetCurrentFoldCreaseRegion()113 sptr<FoldCreaseRegion> FoldScreenController::GetCurrentFoldCreaseRegion()
114 {
115     if (foldScreenPolicy_ == nullptr) {
116         WLOGW("GetFoldStatus: foldScreenPolicy_ is null");
117         return nullptr;
118     }
119     return foldScreenPolicy_->GetCurrentFoldCreaseRegion();
120 }
121 
GetCurrentScreenId()122 ScreenId FoldScreenController::GetCurrentScreenId()
123 {
124     if (foldScreenPolicy_ == nullptr) {
125         WLOGW("GetCurrentScreenId: foldScreenPolicy_ is null");
126         return 0;
127     }
128     return foldScreenPolicy_->GetCurrentScreenId();
129 }
130 
SetOnBootAnimation(bool onBootAnimation)131 void FoldScreenController::SetOnBootAnimation(bool onBootAnimation)
132 {
133     if (foldScreenPolicy_ == nullptr) {
134         WLOGW("SetOnBootAnimation: foldScreenPolicy_ is null");
135         return;
136     }
137     foldScreenPolicy_->SetOnBootAnimation(onBootAnimation);
138 }
139 
UpdateForPhyScreenPropertyChange()140 void FoldScreenController::UpdateForPhyScreenPropertyChange()
141 {
142     if (foldScreenPolicy_ == nullptr) {
143         WLOGW("UpdateForPhyScreenPropertyChange: foldScreenPolicy_ is null");
144         return;
145     }
146     foldScreenPolicy_->UpdateForPhyScreenPropertyChange();
147 }
148 } // namespace OHOS::Rosen