1 /*
2  * Copyright (c) 2024 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 #ifndef HIVIEWDFX_HIVIEW_POWER_STATUS_MANAGER_H
16 #define HIVIEWDFX_HIVIEW_POWER_STATUS_MANAGER_H
17 
18 #include "common_event_data.h"
19 #include "common_event_subscriber.h"
20 #include "singleton.h"
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 namespace UCollectUtil {
25 using namespace EventFwk;
26 
27 enum PowerState {
28     SCREEN_ON = 0,
29     SCREEN_OFF = 10,
30 };
31 
32 class PowerStateSubscriber : public CommonEventSubscriber {
33 public:
PowerStateSubscriber(const CommonEventSubscribeInfo & subscribeInfo)34     PowerStateSubscriber(const CommonEventSubscribeInfo &subscribeInfo) : CommonEventSubscriber(subscribeInfo) {}
35     void OnReceiveEvent(const CommonEventData &data) override;
36 };
37 
38 class PowerStatusManager : public OHOS::DelayedRefSingleton<PowerStatusManager> {
39 public:
40     PowerStatusManager();
41     ~PowerStatusManager();
42     void SetPowerState(PowerState powerState);
43     int32_t GetPowerState();
44 private:
45     std::mutex mutex_;
46     int32_t powerState_;
47     std::shared_ptr<EventFwk::CommonEventSubscriber> powerStateSubscriber_ = nullptr;
48 };
49 }
50 }
51 }
52 #endif //HIVIEWDFX_HIVIEW_POWER_STATUS_MANAGER_H
53