1 /*
2  * Copyright (c) 2021-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 #ifndef BATTERY_SERVICE_SUBSCRIBER_H
17 #define BATTERY_SERVICE_SUBSCRIBER_H
18 
19 #include <cstdint>
20 
21 #include "want.h"
22 
23 #include "battery_info.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 class BatteryNotify {
28 public:
29     BatteryNotify();
30     ~BatteryNotify() = default;
31     int32_t PublishEvents(BatteryInfo& info);
32 
33 private:
34     void HandleUevent(BatteryInfo& info);
35     bool PublishChangedEvent(const BatteryInfo& info);
36     bool PublishChangedEventInner(const BatteryInfo& info) const;
37     bool PublishLowEvent(const BatteryInfo& info) const;
38     bool PublishOkayEvent(const BatteryInfo& info) const;
39     void StartVibrator() const;
40     bool PublishPowerConnectedEvent(const BatteryInfo& info) const;
41     bool PublishPowerDisconnectedEvent(const BatteryInfo& info) const;
42     bool PublishChargingEvent(const BatteryInfo& info) const;
43     bool PublishDischargingEvent(const BatteryInfo& info) const;
44     bool PublishChargeTypeChangedEvent(const BatteryInfo& info);
45     bool IsCommonEventServiceAbilityExist() const;
46     bool PublishCustomEvent(const BatteryInfo& info, const std::string& commonEventName) const;
47 
48     int32_t lowCapacity_ = -1;
49     ChargeType batteryInfoChargeType_ = ChargeType::NONE;
50     int32_t lastCapacity_ = -1;
51     int32_t lastPluggedType_ = -1;
52     int32_t lastTemperature_ = -1;
53     int32_t lastHealthState_ = -1;
54 };
55 } // namespace PowerMgr
56 } // namespace OHOS
57 #endif // BATTERY_SERVICE_SUBSCRIBER_H
58