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