• 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 "actions/idevice_state_action.h"
20 #include "display_power_callback_stub.h"
21 
22 namespace OHOS {
23 namespace PowerMgr {
24 class DeviceStateAction : public IDeviceStateAction {
25 public:
26     DeviceStateAction();
27     ~DeviceStateAction();
28     void Suspend(int64_t callTimeMs, SuspendDeviceType type, uint32_t flags) override;
29     void ForceSuspend() override;
30     void Wakeup(int64_t callTimeMs, WakeupDeviceType type, const std::string& details,
31         const std::string& pkgName) override;
RefreshActivity(const int64_t callTimeMs,UserActivityType type,const uint32_t flags)32     void RefreshActivity(const int64_t callTimeMs, UserActivityType type,
33         const uint32_t flags) override {}
34     DisplayState GetDisplayState() override;
35     uint32_t SetDisplayState(const DisplayState state,
36         StateChangeReason reason = StateChangeReason::STATE_CHANGE_REASON_UNKNOWN) override;
37     uint32_t GoToSleep(std::function<void()> onSuspend, std::function<void()> onWakeup, bool force) override;
38     void RegisterCallback(std::function<void(uint32_t)>& callback) override;
39 
40 private:
41     static constexpr const char * const LOCK_TAG_DISPLAY_POWER = "display_power_lock";
42     class DisplayPowerCallback : public DisplayPowerMgr::DisplayPowerCallbackStub {
43         friend DeviceStateAction;
44     public:
45         void OnDisplayStateChanged(uint32_t displayId, DisplayPowerMgr::DisplayState state, uint32_t reason) override;
46     private:
47         void NotifyDisplayActionDone(uint32_t event);
48         std::function<void(uint32_t)> notify_ {nullptr};
49         std::mutex notifyMutex_;
50     };
51     bool isRegister_ {false};
52     sptr<DisplayPowerCallback> dispCallback_ {nullptr};
53     std::function<void(uint32_t)> actionCallback_ {nullptr};
54 };
55 } // namespace PowerMgr
56 } // namespace OHOS
57 #endif // POWERMGR_DEVICE_STATE_ACTION_H
58