• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef ANDROID_HARDWARE_HEALTH_V2_0_HEALTH_H
2 #define ANDROID_HARDWARE_HEALTH_V2_0_HEALTH_H
3 
4 #include <memory>
5 #include <vector>
6 
7 #include <android/hardware/health/1.0/types.h>
8 #include <android/hardware/health/2.0/IHealth.h>
9 #include <healthd/BatteryMonitor.h>
10 #include <hidl/Status.h>
11 
12 using android::hardware::health::V2_0::StorageInfo;
13 using android::hardware::health::V2_0::DiskStats;
14 
15 void get_storage_info(std::vector<struct StorageInfo>& info);
16 void get_disk_stats(std::vector<struct DiskStats>& stats);
17 
18 namespace android {
19 namespace hardware {
20 namespace health {
21 namespace V2_0 {
22 namespace implementation {
23 
24 using V1_0::BatteryStatus;
25 
26 using ::android::hidl::base::V1_0::IBase;
27 
28 struct Health : public IHealth, hidl_death_recipient {
29    public:
30     static sp<IHealth> initInstance(struct healthd_config* c);
31     // Should only be called by implementation itself (-impl, -service).
32     // Clients should not call this function. Instead, initInstance() initializes and returns the
33     // global instance that has fewer functions.
34     // TODO(b/62229583): clean up and hide these functions after update() logic is simplified.
35     static sp<Health> getImplementation();
36 
37     Health(struct healthd_config* c);
38 
39     // TODO(b/62229583): clean up and hide these functions after update() logic is simplified.
40     void notifyListeners(HealthInfo* info);
41 
42     // Methods from IHealth follow.
43     Return<Result> registerCallback(const sp<IHealthInfoCallback>& callback) override;
44     Return<Result> unregisterCallback(const sp<IHealthInfoCallback>& callback) override;
45     Return<Result> update() override;
46     Return<void> getChargeCounter(getChargeCounter_cb _hidl_cb) override;
47     Return<void> getCurrentNow(getCurrentNow_cb _hidl_cb) override;
48     Return<void> getCurrentAverage(getCurrentAverage_cb _hidl_cb) override;
49     Return<void> getCapacity(getCapacity_cb _hidl_cb) override;
50     Return<void> getEnergyCounter(getEnergyCounter_cb _hidl_cb) override;
51     Return<void> getChargeStatus(getChargeStatus_cb _hidl_cb) override;
52     Return<void> getStorageInfo(getStorageInfo_cb _hidl_cb) override;
53     Return<void> getDiskStats(getDiskStats_cb _hidl_cb) override;
54     Return<void> getHealthInfo(getHealthInfo_cb _hidl_cb) override;
55 
56     // Methods from ::android::hidl::base::V1_0::IBase follow.
57     Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override;
58 
59     void serviceDied(uint64_t cookie, const wp<IBase>& /* who */) override;
60 
61    private:
62     static sp<Health> instance_;
63 
64     std::mutex callbacks_lock_;
65     std::vector<sp<IHealthInfoCallback>> callbacks_;
66     std::unique_ptr<BatteryMonitor> battery_monitor_;
67 
68     bool unregisterCallbackInternal(const sp<IBase>& cb);
69 };
70 
71 }  // namespace implementation
72 }  // namespace V2_0
73 }  // namespace health
74 }  // namespace hardware
75 }  // namespace android
76 
77 #endif  // ANDROID_HARDWARE_HEALTH_V2_0_HEALTH_H
78