Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 1 | #include <memory> |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 2 | |
| 3 | #include <health/utils.h> |
| 4 | #include <health2impl/Health.h> |
| 5 | #include <hidl/Status.h> |
| 6 | #include <log/log.h> |
Caleb Connolly | c28a5e3 | 2021-11-26 14:13:35 +0000 | [diff] [blame] | 7 | #include <android-base/strings.h> |
| 8 | #include <string> |
Caleb Connolly | c072981 | 2021-11-23 18:39:11 +0000 | [diff] [blame] | 9 | |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 10 | using ::android::sp; |
| 11 | using ::android::hardware::Return; |
| 12 | using ::android::hardware::Void; |
| 13 | using ::android::hardware::health::InitHealthdConfig; |
| 14 | using ::android::hardware::health::V2_1::IHealth; |
| 15 | using ::android::hidl::base::V1_0::IBase; |
| 16 | |
| 17 | using namespace std::literals; |
| 18 | |
| 19 | namespace android { |
| 20 | namespace hardware { |
| 21 | namespace health { |
| 22 | namespace V2_1 { |
| 23 | namespace implementation { |
| 24 | |
| 25 | // android::hardware::health::V2_1::implementation::Health implements most |
| 26 | // defaults. Uncomment functions that you need to override. |
| 27 | class 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 Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 39 | // Return<void> getChargeStatus(getChargeStatus_cb _hidl_cb) override; |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 40 | // 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 Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 62 | extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) { |
| 63 | using ::android::hardware::health::V2_1::implementation::HealthImpl; |
Caleb Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 64 | ALOGI("Instance is %s", instance); |
Caleb Connolly | c072981 | 2021-11-23 18:39:11 +0000 | [diff] [blame] | 65 | if (instance != "default"sv) { |
Caleb Connolly | c28a5e3 | 2021-11-26 14:13:35 +0000 | [diff] [blame] | 66 | ALOGE("Instance is not supported"); |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 67 | return nullptr; |
| 68 | } |
Caleb Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 69 | ALOGI("Before InitHealthdConfig()"); |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 70 | auto config = std::make_unique<healthd_config>(); |
| 71 | InitHealthdConfig(config.get()); |
Caleb Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 72 | config->batteryStatusPath = "/sys/class/power_supply/usb/status"; |
Caleb Connolly | ae389bf | 2021-11-17 22:48:27 +0000 | [diff] [blame] | 73 | |
Caleb Connolly | 873a9f2 | 2021-11-19 16:58:56 +0000 | [diff] [blame] | 74 | 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] | 75 | |
| 76 | return new HealthImpl(std::move(config)); |
| 77 | } |