blob: 4cd3f1e0d7f63c546c4e997155b19d8d9cc18092 [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
Caleb Connollyc0729812021-11-23 18:39:11 +00009#include <string_view>
10
Caleb Connollyae389bf2021-11-17 22:48:27 +000011using ::android::sp;
12using ::android::hardware::Return;
13using ::android::hardware::Void;
14using ::android::hardware::health::InitHealthdConfig;
15using ::android::hardware::health::V2_1::IHealth;
16using ::android::hidl::base::V1_0::IBase;
17
18using namespace std::literals;
19
20namespace android {
21namespace hardware {
22namespace health {
23namespace V2_1 {
24namespace implementation {
25
26// android::hardware::health::V2_1::implementation::Health implements most
27// defaults. Uncomment functions that you need to override.
28class HealthImpl : public Health {
29 public:
30 HealthImpl(std::unique_ptr<healthd_config>&& config)
31 : Health(std::move(config)) {}
32
33 // A subclass can override this if these information should be retrieved
34 // differently.
35 // Return<void> getChargeCounter(getChargeCounter_cb _hidl_cb) override;
36 // Return<void> getCurrentNow(getCurrentNow_cb _hidl_cb) override;
37 // Return<void> getCurrentAverage(getCurrentAverage_cb _hidl_cb) override;
38 // Return<void> getCapacity(getCapacity_cb _hidl_cb) override;
39 // Return<void> getEnergyCounter(getEnergyCounter_cb _hidl_cb) override;
Caleb Connolly873a9f22021-11-19 16:58:56 +000040 // Return<void> getChargeStatus(getChargeStatus_cb _hidl_cb) override;
Caleb Connollyae389bf2021-11-17 22:48:27 +000041 // Return<void> getStorageInfo(getStorageInfo_cb _hidl_cb) override;
42 // Return<void> getDiskStats(getDiskStats_cb _hidl_cb) override;
43 // Return<void> getHealthInfo(getHealthInfo_cb _hidl_cb) override;
44
45 // Functions introduced in Health HAL 2.1.
46 // Return<void> getHealthConfig(getHealthConfig_cb _hidl_cb) override;
47 // Return<void> getHealthInfo_2_1(getHealthInfo_2_1_cb _hidl_cb) override;
48 // Return<void> shouldKeepScreenOn(shouldKeepScreenOn_cb _hidl_cb) override;
49
50 protected:
51 // A subclass can override this to modify any health info object before
52 // returning to clients. This is similar to healthd_board_battery_update().
53 // By default, it does nothing.
54 // void UpdateHealthInfo(HealthInfo* health_info) override;
55};
56
Caleb Connolly873a9f22021-11-19 16:58:56 +000057// Return<void> HealthImpl::getChargeStatus(getChargeStatus_cb _hidl_cb) {
58// std::string statusPath = "/sys/class/power_supply/usb"
59// getHealthInfo_2_1([&](auto res, const auto& health_info) {
60
61// _hidl_cb(res, health_info);
62
63// });
64
65// return Void();
66// }
67
Caleb Connollyae389bf2021-11-17 22:48:27 +000068} // namespace implementation
69} // namespace V2_1
70} // namespace health
71} // namespace hardware
72} // namespace android
73
Caleb Connollyae389bf2021-11-17 22:48:27 +000074extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) {
75 using ::android::hardware::health::V2_1::implementation::HealthImpl;
Caleb Connolly873a9f22021-11-19 16:58:56 +000076 ALOGI("Instance is %s", instance);
Caleb Connollyc0729812021-11-23 18:39:11 +000077 if (instance != "default"sv) {
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}