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