• 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 "session_display_power_controller.h"
17 #include "screen_session_manager.h"
18 #include "window_manager_hilog.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace {
23     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SessionDisplayPowerController"};
24 }
25 
SuspendBegin(PowerStateChangeReason reason)26 bool SessionDisplayPowerController::SuspendBegin(PowerStateChangeReason reason)
27 {
28     WLOGFI("reason:%{public}u", reason);
29     std::map<DisplayId, sptr<DisplayInfo>> emptyMap;
30     displayStateChangeListener_(DISPLAY_ID_INVALID, nullptr, emptyMap, DisplayStateChangeType::BEFORE_SUSPEND);
31     return true;
32 }
33 
SetDisplayState(DisplayState state)34 bool SessionDisplayPowerController::SetDisplayState(DisplayState state)
35 {
36     WLOGFI("state:%{public}u", state);
37     {
38         if (displayState_ == state) {
39             WLOGFE("state is already set");
40             return false;
41         }
42     }
43     switch (state) {
44         case DisplayState::ON: {
45             {
46                 displayState_ = state;
47             }
48             break;
49         }
50         case DisplayState::OFF: {
51             {
52                 displayState_ = state;
53             }
54             ScreenSessionManager::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_OFF,
55                 EventStatus::BEGIN);
56             break;
57         }
58         default: {
59             WLOGFW("unknown DisplayState!");
60             return false;
61         }
62     }
63     ScreenSessionManager::GetInstance().NotifyDisplayStateChanged(DISPLAY_ID_INVALID, state);
64     return true;
65 }
66 
GetDisplayState(DisplayId displayId)67 DisplayState SessionDisplayPowerController::GetDisplayState(DisplayId displayId)
68 {
69     return displayState_;
70 }
71 
NotifyDisplayEvent(DisplayEvent event)72 void SessionDisplayPowerController::NotifyDisplayEvent(DisplayEvent event)
73 {
74     WLOGFI("DisplayEvent:%{public}u", event);
75     if (event == DisplayEvent::UNLOCK) {
76         std::map<DisplayId, sptr<DisplayInfo>> emptyMap;
77         displayStateChangeListener_(DISPLAY_ID_INVALID, nullptr, emptyMap, DisplayStateChangeType::BEFORE_UNLOCK);
78         ScreenSessionManager::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DESKTOP_READY,
79             EventStatus::BEGIN);
80         return;
81     }
82     if (event == DisplayEvent::KEYGUARD_DRAWN) {
83         ScreenSessionManager::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_ON,
84             EventStatus::BEGIN);
85     }
86 }
87 }
88 }