blob: fa0fd3d422d295066913bee94d5ab5a91b50464f [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
56} // namespace implementation
57} // namespace V2_1
58} // namespace health
59} // namespace hardware
60} // namespace android
61
Caleb Connollyae389bf2021-11-17 22:48:27 +000062extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) {
63 using ::android::hardware::health::V2_1::implementation::HealthImpl;
Caleb Connolly873a9f22021-11-19 16:58:56 +000064 ALOGI("Instance is %s", instance);
Caleb Connollyc0729812021-11-23 18:39:11 +000065 if (instance != "default"sv) {
Caleb Connollyc28a5e32021-11-26 14:13:35 +000066 ALOGE("Instance is not supported");
Caleb Connollyae389bf2021-11-17 22:48:27 +000067 return nullptr;
68 }
Caleb Connolly873a9f22021-11-19 16:58:56 +000069 ALOGI("Before InitHealthdConfig()");
Caleb Connollyae389bf2021-11-17 22:48:27 +000070 auto config = std::make_unique<healthd_config>();
71 InitHealthdConfig(config.get());
Caleb Connolly873a9f22021-11-19 16:58:56 +000072 config->batteryStatusPath = "/sys/class/power_supply/usb/status";
Caleb Connollyae389bf2021-11-17 22:48:27 +000073
Caleb Connolly873a9f22021-11-19 16:58:56 +000074 ALOGI("CA: HAL 2.1!!!! health, status path = %s", config->batteryStatusPath.c_str());
Caleb Connollyae389bf2021-11-17 22:48:27 +000075
76 return new HealthImpl(std::move(config));
77}