blob: 1f7a9d1f53a5ed81ef39686e3f3d4e2c994ea8f1 [file] [log] [blame]
Caleb Connollyae389bf2021-11-17 22:48:27 +00001#include <memory>
2#include <string_view>
3
4#include <health/utils.h>
5#include <health2impl/Health.h>
6#include <hidl/Status.h>
7#include <log/log.h>
8
9using ::android::sp;
10using ::android::hardware::Return;
11using ::android::hardware::Void;
12using ::android::hardware::health::InitHealthdConfig;
13using ::android::hardware::health::V2_1::IHealth;
14using ::android::hidl::base::V1_0::IBase;
15
16using namespace std::literals;
17
18namespace android {
19namespace hardware {
20namespace health {
21namespace V2_1 {
22namespace implementation {
23
24// android::hardware::health::V2_1::implementation::Health implements most
25// defaults. Uncomment functions that you need to override.
26class HealthImpl : public Health {
27 public:
28 HealthImpl(std::unique_ptr<healthd_config>&& config)
29 : Health(std::move(config)) {}
30
31 // A subclass can override this if these information should be retrieved
32 // differently.
33 // Return<void> getChargeCounter(getChargeCounter_cb _hidl_cb) override;
34 // Return<void> getCurrentNow(getCurrentNow_cb _hidl_cb) override;
35 // Return<void> getCurrentAverage(getCurrentAverage_cb _hidl_cb) override;
36 // Return<void> getCapacity(getCapacity_cb _hidl_cb) override;
37 // Return<void> getEnergyCounter(getEnergyCounter_cb _hidl_cb) override;
38 //Return<void> getChargeStatus(getChargeStatus_cb _hidl_cb) override;
39 // Return<void> getStorageInfo(getStorageInfo_cb _hidl_cb) override;
40 // Return<void> getDiskStats(getDiskStats_cb _hidl_cb) override;
41 // Return<void> getHealthInfo(getHealthInfo_cb _hidl_cb) override;
42
43 // Functions introduced in Health HAL 2.1.
44 // Return<void> getHealthConfig(getHealthConfig_cb _hidl_cb) override;
45 // Return<void> getHealthInfo_2_1(getHealthInfo_2_1_cb _hidl_cb) override;
46 // Return<void> shouldKeepScreenOn(shouldKeepScreenOn_cb _hidl_cb) override;
47
48 protected:
49 // A subclass can override this to modify any health info object before
50 // returning to clients. This is similar to healthd_board_battery_update().
51 // By default, it does nothing.
52 // void UpdateHealthInfo(HealthInfo* health_info) override;
53};
54
55} // namespace implementation
56} // namespace V2_1
57} // namespace health
58} // namespace hardware
59} // namespace android
60
61void healthd_board_init(healthd_config *config) {
62 // The battery doesn't expose it's status, only the charger does.
63 config->batteryStatusPath = "/sys/class/power_supply/usb/status";
64}
65
66extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) {
67 using ::android::hardware::health::V2_1::implementation::HealthImpl;
68 if (instance != "default") {
69 return nullptr;
70 }
71 auto config = std::make_unique<healthd_config>();
72 InitHealthdConfig(config.get());
73
74 healthd_board_init(config.get());
75
76 ALOGI("CA: Creating Health HAL 2.1, status path = %s", config->batteryStatusPath.c_str());
77
78 return new HealthImpl(std::move(config));
79}