• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <mutex>
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     bool PublishCustomEvent(const BatteryInfo& info, const std::string& commonEventName) const;
33     bool HandleNotification(const std::string& ueventName) const;
34 
35 private:
36     void HandleUevent(BatteryInfo& info);
37     bool PublishChangedEvent(const BatteryInfo& info);
38     bool PublishChangedEventInner(const BatteryInfo& info) const;
39     bool PublishLowEvent(const BatteryInfo& info) const;
40     bool PublishOkayEvent(const BatteryInfo& info) const;
41     void StartVibrator() const;
42     bool PublishPowerConnectedEvent(const BatteryInfo& info) const;
43     bool PublishPowerDisconnectedEvent(const BatteryInfo& info) const;
44     bool PublishChargingEvent(const BatteryInfo& info) const;
45     bool PublishDischargingEvent(const BatteryInfo& info) const;
46     bool PublishChargeTypeChangedEvent(const BatteryInfo& info);
47     bool IsCommonEventServiceAbilityExist() const;
48     void WirelessPluggedConnected(const BatteryInfo& info) const;
49     void WirelessPluggedDisconnected(const BatteryInfo& info) const;
50     void RotationMotionSubscriber() const;
51     void RotationMotionUnsubscriber() const;
52 
53     int32_t lowCapacity_ = -1;
54     ChargeType batteryInfoChargeType_ = ChargeType::NONE;
55     int32_t lastCapacity_ = -1;
56     int32_t lastPluggedType_ = -1;
57     int32_t lastTemperature_ = -1;
58     int32_t lastHealthState_ = -1;
59     BatteryPluggedType lastPowerPluggedType_ = BatteryPluggedType::PLUGGED_TYPE_BUTT;
60     std::mutex mutex_;
61 };
62 } // namespace PowerMgr
63 } // namespace OHOS
64 #endif // BATTERY_SERVICE_SUBSCRIBER_H
65