• 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 #ifndef POWERMGR_DEVICE_STATE_ACTION_H
17 #define POWERMGR_DEVICE_STATE_ACTION_H
18 
19 #include "display_manager_lite.h"
20 #include "dm_common.h"
21 
22 #include "actions/idevice_state_action.h"
23 #include "display_power_callback_stub.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 class DeviceStateAction : public IDeviceStateAction {
28 public:
29     DeviceStateAction();
30     ~DeviceStateAction();
31     void Suspend(int64_t callTimeMs, SuspendDeviceType type, uint32_t flags) override;
32     void ForceSuspend() override;
33     void Wakeup(int64_t callTimeMs, WakeupDeviceType type, const std::string& details,
34         const std::string& pkgName) override;
RefreshActivity(const int64_t callTimeMs,UserActivityType type,const uint32_t flags)35     void RefreshActivity(const int64_t callTimeMs, UserActivityType type,
36         const uint32_t flags) override {}
37     DisplayState GetDisplayState() override;
38     uint32_t SetDisplayState(DisplayState state,
39         StateChangeReason reason = StateChangeReason::STATE_CHANGE_REASON_UNKNOWN) override;
40     void SetInternalScreenDisplayPower(DisplayState state, StateChangeReason reason) override;
41     void SetInternalScreenBrightness() override;
42     bool TryToCancelScreenOff() override;
43     void BeginPowerkeyScreenOff() override;
44     void EndPowerkeyScreenOff() override;
45     void SetCoordinated(bool coordinated) override;
46     uint32_t GoToSleep(std::function<void()> onSuspend, std::function<void()> onWakeup, bool force) override;
47     void RegisterCallback(std::function<void(uint32_t)>& callback) override;
48 
49 private:
50     static constexpr const char * const LOCK_TAG_DISPLAY_POWER = "display_power_lock";
51     class DisplayPowerCallback : public DisplayPowerMgr::DisplayPowerCallbackStub {
52         friend DeviceStateAction;
53     public:
54         void OnDisplayStateChanged(uint32_t displayId, DisplayPowerMgr::DisplayState state, uint32_t reason) override;
55     private:
56         void NotifyDisplayActionDone(uint32_t event);
57         std::function<void(uint32_t)> notify_ {nullptr};
58         std::mutex notifyMutex_;
59     };
60     DisplayPowerMgr::DisplayState GetDisplayPowerMgrDisplayState(DisplayState state);
61     bool IsInterruptingScreenOff(Rosen::PowerStateChangeReason dispReason);
62     bool IsOnState(DisplayState state);
63     std::mutex cancelScreenOffMutex_;
64     std::condition_variable cancelScreenOffCv_;
65     bool cancelScreenOffCvUnblocked_ {false};
66     bool interruptingScreenOff_ {false};
67     bool screenOffInterrupted_ {false};
68     bool screenOffStarted_ {false};
69     bool isRegister_ {false};
70     sptr<DisplayPowerCallback> dispCallback_ {nullptr};
71     std::function<void(uint32_t)> actionCallback_ {nullptr};
72     bool coordinated_ {false};
73 };
74 } // namespace PowerMgr
75 } // namespace OHOS
76 #endif // POWERMGR_DEVICE_STATE_ACTION_H
77