blob: fc867893d7dfea1325df25ef9c5efaaf037a6243 [file] [log] [blame]
Hridya Valsarajud3e3d722017-12-11 17:31:00 -08001#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
Hridya Valsaraju2b520832017-12-20 13:25:29 -080012using android::hardware::health::V2_0::StorageInfo;
13using android::hardware::health::V2_0::DiskStats;
14
15void get_storage_info(std::vector<struct StorageInfo>& info);
16void get_disk_stats(std::vector<struct DiskStats>& stats);
17
Hridya Valsarajud3e3d722017-12-11 17:31:00 -080018namespace android {
19namespace hardware {
20namespace health {
21namespace V2_0 {
22namespace implementation {
23
24using V1_0::BatteryStatus;
25using V1_0::HealthInfo;
26
27using ::android::hidl::base::V1_0::IBase;
28
29struct Health : public IHealth, hidl_death_recipient {
30 public:
31 static sp<IHealth> initInstance(struct healthd_config* c);
32 // Should only be called by implementation itself (-impl, -service).
33 // Clients should not call this function. Instead, initInstance() initializes and returns the
34 // global instance that has fewer functions.
35 // TODO(b/62229583): clean up and hide these functions after update() logic is simplified.
36 static sp<Health> getImplementation();
37
38 Health(struct healthd_config* c);
39
40 // TODO(b/62229583): clean up and hide these functions after update() logic is simplified.
41 void notifyListeners(const HealthInfo& info);
42
43 // Methods from IHealth follow.
44 Return<Result> registerCallback(const sp<IHealthInfoCallback>& callback) override;
45 Return<Result> unregisterCallback(const sp<IHealthInfoCallback>& callback) override;
46 Return<Result> update() override;
47 Return<void> getChargeCounter(getChargeCounter_cb _hidl_cb) override;
48 Return<void> getCurrentNow(getCurrentNow_cb _hidl_cb) override;
49 Return<void> getCurrentAverage(getCurrentAverage_cb _hidl_cb) override;
50 Return<void> getCapacity(getCapacity_cb _hidl_cb) override;
51 Return<void> getEnergyCounter(getEnergyCounter_cb _hidl_cb) override;
52 Return<void> getChargeStatus(getChargeStatus_cb _hidl_cb) override;
Hridya Valsaraju2b520832017-12-20 13:25:29 -080053 Return<void> getStorageInfo(getStorageInfo_cb _hidl_cb) override;
54 Return<void> getDiskStats(getDiskStats_cb _hidl_cb) override;
Hridya Valsaraju1bd37722018-01-12 10:25:59 -080055 Return<void> getHealthInfo(getHealthInfo_cb _hidl_cb) override;
Hridya Valsarajud3e3d722017-12-11 17:31:00 -080056
57 // Methods from ::android::hidl::base::V1_0::IBase follow.
58 Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override;
59
60 void serviceDied(uint64_t cookie, const wp<IBase>& /* who */) override;
61
62 private:
63 static sp<Health> instance_;
64
65 std::mutex callbacks_lock_;
66 std::vector<sp<IHealthInfoCallback>> callbacks_;
67 std::unique_ptr<BatteryMonitor> battery_monitor_;
68
69 bool unregisterCallbackInternal(const sp<IBase>& cb);
70};
71
72} // namespace implementation
73} // namespace V2_0
74} // namespace health
75} // namespace hardware
76} // namespace android
77
78#endif // ANDROID_HARDWARE_HEALTH_V2_0_HEALTH_H