blob: d5b004c3ad9f253fb96d6913813292cd5574aabe [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;
Caleb Connolly873a9f22021-11-19 16:58:56 +000038 // Return<void> getChargeStatus(getChargeStatus_cb _hidl_cb) override;
Caleb Connollyae389bf2021-11-17 22:48:27 +000039 // 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
Caleb Connolly873a9f22021-11-19 16:58:56 +000055// Return<void> HealthImpl::getChargeStatus(getChargeStatus_cb _hidl_cb) {
56// std::string statusPath = "/sys/class/power_supply/usb"
57// getHealthInfo_2_1([&](auto res, const auto& health_info) {
58
59// _hidl_cb(res, health_info);
60
61// });
62
63// return Void();
64// }
65
Caleb Connollyae389bf2021-11-17 22:48:27 +000066} // namespace implementation
67} // namespace V2_1
68} // namespace health
69} // namespace hardware
70} // namespace android
71
Caleb Connollyae389bf2021-11-17 22:48:27 +000072extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) {
73 using ::android::hardware::health::V2_1::implementation::HealthImpl;
Caleb Connolly873a9f22021-11-19 16:58:56 +000074 ALOGI("Instance is %s", instance);
Caleb Connollyae389bf2021-11-17 22:48:27 +000075 if (instance != "default") {
76 return nullptr;
77 }
Caleb Connolly873a9f22021-11-19 16:58:56 +000078 ALOGI("Before InitHealthdConfig()");
Caleb Connollyae389bf2021-11-17 22:48:27 +000079 auto config = std::make_unique<healthd_config>();
80 InitHealthdConfig(config.get());
Caleb Connolly873a9f22021-11-19 16:58:56 +000081 config->batteryStatusPath = "/sys/class/power_supply/usb/status";
Caleb Connollyae389bf2021-11-17 22:48:27 +000082
Caleb Connolly873a9f22021-11-19 16:58:56 +000083 ALOGI("CA: HAL 2.1!!!! health, status path = %s", config->batteryStatusPath.c_str());
Caleb Connollyae389bf2021-11-17 22:48:27 +000084
85 return new HealthImpl(std::move(config));
86}