Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 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 | |
Hridya Valsaraju | 2b52083 | 2017-12-20 13:25:29 -0800 | [diff] [blame] | 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 | |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 18 | namespace android { |
| 19 | namespace hardware { |
| 20 | namespace health { |
| 21 | namespace V2_0 { |
| 22 | namespace implementation { |
| 23 | |
| 24 | using V1_0::BatteryStatus; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 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. |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 34 | static sp<Health> getImplementation(); |
| 35 | |
| 36 | Health(struct healthd_config* c); |
| 37 | |
Hridya Valsaraju | d31932a | 2018-01-17 23:09:24 -0800 | [diff] [blame] | 38 | void notifyListeners(HealthInfo* info); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 39 | |
| 40 | // Methods from IHealth follow. |
| 41 | Return<Result> registerCallback(const sp<IHealthInfoCallback>& callback) override; |
| 42 | Return<Result> unregisterCallback(const sp<IHealthInfoCallback>& callback) override; |
| 43 | Return<Result> update() override; |
| 44 | Return<void> getChargeCounter(getChargeCounter_cb _hidl_cb) override; |
| 45 | Return<void> getCurrentNow(getCurrentNow_cb _hidl_cb) override; |
| 46 | Return<void> getCurrentAverage(getCurrentAverage_cb _hidl_cb) override; |
| 47 | Return<void> getCapacity(getCapacity_cb _hidl_cb) override; |
| 48 | Return<void> getEnergyCounter(getEnergyCounter_cb _hidl_cb) override; |
| 49 | Return<void> getChargeStatus(getChargeStatus_cb _hidl_cb) override; |
Hridya Valsaraju | 2b52083 | 2017-12-20 13:25:29 -0800 | [diff] [blame] | 50 | Return<void> getStorageInfo(getStorageInfo_cb _hidl_cb) override; |
| 51 | Return<void> getDiskStats(getDiskStats_cb _hidl_cb) override; |
Hridya Valsaraju | 1bd3772 | 2018-01-12 10:25:59 -0800 | [diff] [blame] | 52 | Return<void> getHealthInfo(getHealthInfo_cb _hidl_cb) override; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 53 | |
| 54 | // Methods from ::android::hidl::base::V1_0::IBase follow. |
| 55 | Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override; |
| 56 | |
| 57 | void serviceDied(uint64_t cookie, const wp<IBase>& /* who */) override; |
| 58 | |
| 59 | private: |
| 60 | static sp<Health> instance_; |
| 61 | |
Yifan Hong | a46c0da | 2018-10-02 14:06:51 -0700 | [diff] [blame] | 62 | std::recursive_mutex callbacks_lock_; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 63 | std::vector<sp<IHealthInfoCallback>> callbacks_; |
| 64 | std::unique_ptr<BatteryMonitor> battery_monitor_; |
| 65 | |
| 66 | bool unregisterCallbackInternal(const sp<IBase>& cb); |
Yifan Hong | e9fc235 | 2018-10-02 14:11:35 -0700 | [diff] [blame] | 67 | |
| 68 | // update() and only notify the given callback, but none of the other callbacks. |
| 69 | // If cb is null, do not notify any callback at all. |
| 70 | Return<Result> updateAndNotify(const sp<IHealthInfoCallback>& cb); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace implementation |
| 74 | } // namespace V2_0 |
| 75 | } // namespace health |
| 76 | } // namespace hardware |
| 77 | } // namespace android |
| 78 | |
| 79 | #endif // ANDROID_HARDWARE_HEALTH_V2_0_HEALTH_H |