• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "display_power_controller.h"
17 #include "display_manager_service.h"
18 #include "display_manager_agent_controller.h"
19 #include "window_manager_hilog.h"
20 
21 namespace OHOS {
22 namespace Rosen {
23 
SuspendBegin(PowerStateChangeReason reason)24 bool DisplayPowerController::SuspendBegin(PowerStateChangeReason reason)
25 {
26     TLOGI(WmsLogTag::DMS, "reason:%{public}u", reason);
27     std::map<DisplayId, sptr<DisplayInfo>> emptyMap;
28     displayStateChangeListener_(DISPLAY_ID_INVALID, nullptr, emptyMap, DisplayStateChangeType::BEFORE_SUSPEND);
29     return true;
30 }
31 
SetDisplayState(DisplayState state)32 bool DisplayPowerController::SetDisplayState(DisplayState state)
33 {
34     TLOGI(WmsLogTag::DMS, "state:%{public}u", state);
35     {
36         std::lock_guard<std::recursive_mutex> lock(mutex_);
37         if (displayState_ == state) {
38             TLOGE(WmsLogTag::DMS, "state is already set");
39             return false;
40         }
41     }
42     switch (state) {
43         case DisplayState::ON: {
44             {
45                 std::lock_guard<std::recursive_mutex> lock(mutex_);
46                 displayState_ = state;
47             }
48             DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_ON,
49                 EventStatus::BEGIN);
50             break;
51         }
52         case DisplayState::OFF: {
53             {
54                 std::lock_guard<std::recursive_mutex> lock(mutex_);
55                 displayState_ = state;
56             }
57             DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_OFF,
58                 EventStatus::BEGIN);
59             break;
60         }
61         default: {
62             TLOGW(WmsLogTag::DMS, "unknown DisplayState!");
63             return false;
64         }
65     }
66     DisplayManagerAgentController::GetInstance().NotifyDisplayStateChanged(DISPLAY_ID_INVALID, state);
67     return true;
68 }
69 
GetDisplayState(DisplayId displayId)70 DisplayState DisplayPowerController::GetDisplayState(DisplayId displayId)
71 {
72     return displayState_;
73 }
74 
NotifyDisplayEvent(DisplayEvent event)75 void DisplayPowerController::NotifyDisplayEvent(DisplayEvent event)
76 {
77     TLOGI(WmsLogTag::DMS, "DisplayEvent:%{public}u", event);
78     if (event == DisplayEvent::UNLOCK) {
79         std::map<DisplayId, sptr<DisplayInfo>> emptyMap;
80         displayStateChangeListener_(DISPLAY_ID_INVALID, nullptr, emptyMap, DisplayStateChangeType::BEFORE_UNLOCK);
81         DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DESKTOP_READY,
82             EventStatus::BEGIN);
83         std::lock_guard<std::recursive_mutex> lock(mutex_);
84         isKeyguardDrawn_ = false;
85         return;
86     }
87     if (event == DisplayEvent::KEYGUARD_DRAWN) {
88         std::lock_guard<std::recursive_mutex> lock(mutex_);
89         isKeyguardDrawn_ = true;
90     }
91 }
92 }
93 }