Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 1 | #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 Connolly | c072981 | 2021-11-23 18:39:11 +0000 | [diff] [blame] | 9 | #include <string_view> |
| 10 | |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 11 | using ::android::sp; |
| 12 | using ::android::hardware::Return; |
| 13 | using ::android::hardware::Void; |
| 14 | using ::android::hardware::health::InitHealthdConfig; |
| 15 | using ::android::hardware::health::V2_1::IHealth; |
| 16 | using ::android::hidl::base::V1_0::IBase; |
| 17 | |
| 18 | using namespace std::literals; |
| 19 | |
| 20 | namespace android { |
| 21 | namespace hardware { |
| 22 | namespace health { |
| 23 | namespace V2_1 { |
| 24 | namespace implementation { |
| 25 | |
| 26 | // android::hardware::health::V2_1::implementation::Health implements most |
| 27 | // defaults. Uncomment functions that you need to override. |
| 28 | class 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 Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 40 | // Return<void> getChargeStatus(getChargeStatus_cb _hidl_cb) override; |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 41 | // 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 Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 57 | // 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 Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 68 | } // namespace implementation |
| 69 | } // namespace V2_1 |
| 70 | } // namespace health |
| 71 | } // namespace hardware |
| 72 | } // namespace android |
| 73 | |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 74 | extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) { |
| 75 | using ::android::hardware::health::V2_1::implementation::HealthImpl; |
Caleb Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 76 | ALOGI("Instance is %s", instance); |
Caleb Connolly | c072981 | 2021-11-23 18:39:11 +0000 | [diff] [blame] | 77 | if (instance != "default"sv) { |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 78 | return nullptr; |
| 79 | } |
Caleb Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 80 | ALOGI("Before InitHealthdConfig()"); |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 81 | auto config = std::make_unique<healthd_config>(); |
| 82 | InitHealthdConfig(config.get()); |
Caleb Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 83 | config->batteryStatusPath = "/sys/class/power_supply/usb/status"; |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 84 | |
Caleb Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 85 | ALOGI("CA: HAL 2.1!!!! health, status path = %s", config->batteryStatusPath.c_str()); |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 86 | |
| 87 | return new HealthImpl(std::move(config)); |
| 88 | } |