blob: fce545cca7cf6cd4188f4799d1532fca3172ea54 [file] [log] [blame]
Caleb Connollyae389bf2021-11-17 22:48:27 +00001#include <memory>
Caleb Connollyae389bf2021-11-17 22:48:27 +00002
3#include <health/utils.h>
4#include <health2impl/Health.h>
5#include <hidl/Status.h>
6#include <log/log.h>
Caleb Connollyc28a5e32021-11-26 14:13:35 +00007#include <android-base/strings.h>
8#include <string>
Caleb Connollyc0729812021-11-23 18:39:11 +00009
Caleb Connollyae389bf2021-11-17 22:48:27 +000010using ::android::sp;
11using ::android::hardware::Return;
12using ::android::hardware::Void;
13using ::android::hardware::health::InitHealthdConfig;
14using ::android::hardware::health::V2_1::IHealth;
15using ::android::hidl::base::V1_0::IBase;
16
17using namespace std::literals;
18
19namespace android {
20namespace hardware {
21namespace health {
22namespace V2_1 {
23namespace implementation {
24
25// android::hardware::health::V2_1::implementation::Health implements most
26// defaults. Uncomment functions that you need to override.
27class HealthImpl : public Health {
28 public:
29 HealthImpl(std::unique_ptr<healthd_config>&& config)
30 : Health(std::move(config)) {}
31
32 // A subclass can override this if these information should be retrieved
33 // differently.
34 // Return<void> getChargeCounter(getChargeCounter_cb _hidl_cb) override;
35 // Return<void> getCurrentNow(getCurrentNow_cb _hidl_cb) override;
36 // Return<void> getCurrentAverage(getCurrentAverage_cb _hidl_cb) override;
37 // Return<void> getCapacity(getCapacity_cb _hidl_cb) override;
38 // Return<void> getEnergyCounter(getEnergyCounter_cb _hidl_cb) override;
Caleb Connolly873a9f22021-11-19 16:58:56 +000039 // Return<void> getChargeStatus(getChargeStatus_cb _hidl_cb) override;
Caleb Connollyae389bf2021-11-17 22:48:27 +000040 // Return<void> getStorageInfo(getStorageInfo_cb _hidl_cb) override;
41 // Return<void> getDiskStats(getDiskStats_cb _hidl_cb) override;
42 // Return<void> getHealthInfo(getHealthInfo_cb _hidl_cb) override;
43
44 // Functions introduced in Health HAL 2.1.
45 // Return<void> getHealthConfig(getHealthConfig_cb _hidl_cb) override;
46 // Return<void> getHealthInfo_2_1(getHealthInfo_2_1_cb _hidl_cb) override;
47 // Return<void> shouldKeepScreenOn(shouldKeepScreenOn_cb _hidl_cb) override;
48
49 protected:
50 // A subclass can override this to modify any health info object before
51 // returning to clients. This is similar to healthd_board_battery_update().
52 // By default, it does nothing.
53 // void UpdateHealthInfo(HealthInfo* health_info) override;
54};
55
Caleb Connolly873a9f22021-11-19 16:58:56 +000056// Return<void> HealthImpl::getChargeStatus(getChargeStatus_cb _hidl_cb) {
57// std::string statusPath = "/sys/class/power_supply/usb"
58// getHealthInfo_2_1([&](auto res, const auto& health_info) {
59
60// _hidl_cb(res, health_info);
61
62// });
63
64// return Void();
65// }
66
Caleb Connollyae389bf2021-11-17 22:48:27 +000067} // namespace implementation
68} // namespace V2_1
69} // namespace health
70} // namespace hardware
71} // namespace android
72
Caleb Connollyae389bf2021-11-17 22:48:27 +000073extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) {
74 using ::android::hardware::health::V2_1::implementation::HealthImpl;
Caleb Connolly873a9f22021-11-19 16:58:56 +000075 ALOGI("Instance is %s", instance);
Caleb Connollyc0729812021-11-23 18:39:11 +000076 if (instance != "default"sv) {
Caleb Connollyc28a5e32021-11-26 14:13:35 +000077 ALOGE("Instance is not supported");
Caleb Connollyae389bf2021-11-17 22:48:27 +000078 return nullptr;
79 }
Caleb Connolly873a9f22021-11-19 16:58:56 +000080 ALOGI("Before InitHealthdConfig()");
Caleb Connollyae389bf2021-11-17 22:48:27 +000081 auto config = std::make_unique<healthd_config>();
82 InitHealthdConfig(config.get());
Caleb Connolly873a9f22021-11-19 16:58:56 +000083 config->batteryStatusPath = "/sys/class/power_supply/usb/status";
Caleb Connollyae389bf2021-11-17 22:48:27 +000084
Caleb Connolly873a9f22021-11-19 16:58:56 +000085 ALOGI("CA: HAL 2.1!!!! health, status path = %s", config->batteryStatusPath.c_str());
Caleb Connollyae389bf2021-11-17 22:48:27 +000086
87 return new HealthImpl(std::move(config));
88}