Loading fastboot/constants.h +1 −0 Original line number Diff line number Diff line Loading @@ -63,3 +63,4 @@ #define FB_VAR_VARIANT "variant" #define FB_VAR_OFF_MODE_CHARGE_STATE "off-mode-charge" #define FB_VAR_BATTERY_VOLTAGE "battery-voltage" #define FB_VAR_BATTERY_SOC_OK "battery-soc-ok" fastboot/device/commands.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args) {FB_VAR_IS_USERSPACE, {GetIsUserspace, nullptr}}, {FB_VAR_OFF_MODE_CHARGE_STATE, {GetOffModeChargeState, nullptr}}, {FB_VAR_BATTERY_VOLTAGE, {GetBatteryVoltage, nullptr}}, {FB_VAR_BATTERY_SOC_OK, {GetBatterySoCOk, nullptr}}, {FB_VAR_HW_REVISION, {GetHardwareRevision, nullptr}}}; if (args.size() < 2) { Loading fastboot/device/variables.cpp +56 −19 Original line number Diff line number Diff line Loading @@ -96,8 +96,35 @@ bool GetVariant(FastbootDevice* device, const std::vector<std::string>& /* args return true; } bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string>& /* args */, bool GetBatteryVoltageHelper(FastbootDevice* device, int32_t* battery_voltage) { using android::hardware::health::V2_0::HealthInfo; using android::hardware::health::V2_0::Result; auto health_hal = device->health_hal(); if (!health_hal) { return false; } Result ret; auto ret_val = health_hal->getHealthInfo([&](Result result, HealthInfo info) { *battery_voltage = info.legacy.batteryVoltage; ret = result; }); if (!ret_val.isOk() || (ret != Result::SUCCESS)) { return false; } return true; } bool GetBatterySoCOk(FastbootDevice* device, const std::vector<std::string>& /* args */, std::string* message) { int32_t battery_voltage = 0; if (!GetBatteryVoltageHelper(device, &battery_voltage)) { *message = "Unable to read battery voltage"; return false; } auto fastboot_hal = device->fastboot_hal(); if (!fastboot_hal) { *message = "Fastboot HAL not found"; Loading @@ -105,43 +132,53 @@ bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string } Result ret; auto ret_val = fastboot_hal->getOffModeChargeState([&](bool off_mode_charging_state, Result result) { *message = off_mode_charging_state ? "1" : "0"; auto ret_val = fastboot_hal->getBatteryVoltageFlashingThreshold( [&](int32_t voltage_threshold, Result result) { *message = battery_voltage >= voltage_threshold ? "yes" : "no"; ret = result; }); if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) { *message = "Unable to get off mode charge state"; if (!ret_val.isOk() || ret.status != Status::SUCCESS) { *message = "Unable to get battery voltage flashing threshold"; return false; } return true; } bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& /* args */, bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string>& /* args */, std::string* message) { using android::hardware::health::V2_0::HealthInfo; using android::hardware::health::V2_0::Result; auto health_hal = device->health_hal(); if (!health_hal) { *message = "Health HAL not found"; auto fastboot_hal = device->fastboot_hal(); if (!fastboot_hal) { *message = "Fastboot HAL not found"; return false; } Result ret; auto ret_val = health_hal->getHealthInfo([&](Result result, HealthInfo info) { *message = std::to_string(info.legacy.batteryVoltage); auto ret_val = fastboot_hal->getOffModeChargeState([&](bool off_mode_charging_state, Result result) { *message = off_mode_charging_state ? "1" : "0"; ret = result; }); if (!ret_val.isOk() || (ret != Result::SUCCESS)) { *message = "Unable to get battery voltage"; if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) { *message = "Unable to get off mode charge state"; return false; } return true; } bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& /* args */, std::string* message) { int32_t battery_voltage = 0; if (GetBatteryVoltageHelper(device, &battery_voltage)) { *message = std::to_string(battery_voltage); return true; } *message = "Unable to get battery voltage"; return false; } bool GetCurrentSlot(FastbootDevice* device, const std::vector<std::string>& /* args */, std::string* message) { std::string suffix = device->GetCurrentSlot(); Loading fastboot/device/variables.h +3 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string std::string* message); bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& args, std::string* message); bool GetBatterySoCOk(FastbootDevice* device, const std::vector<std::string>& args, std::string* message); // Helpers for getvar all. std::vector<std::vector<std::string>> GetAllPartitionArgsWithSlot(FastbootDevice* device); std::vector<std::vector<std::string>> GetAllPartitionArgsNoSlot(FastbootDevice* device); Loading
fastboot/constants.h +1 −0 Original line number Diff line number Diff line Loading @@ -63,3 +63,4 @@ #define FB_VAR_VARIANT "variant" #define FB_VAR_OFF_MODE_CHARGE_STATE "off-mode-charge" #define FB_VAR_BATTERY_VOLTAGE "battery-voltage" #define FB_VAR_BATTERY_SOC_OK "battery-soc-ok"
fastboot/device/commands.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args) {FB_VAR_IS_USERSPACE, {GetIsUserspace, nullptr}}, {FB_VAR_OFF_MODE_CHARGE_STATE, {GetOffModeChargeState, nullptr}}, {FB_VAR_BATTERY_VOLTAGE, {GetBatteryVoltage, nullptr}}, {FB_VAR_BATTERY_SOC_OK, {GetBatterySoCOk, nullptr}}, {FB_VAR_HW_REVISION, {GetHardwareRevision, nullptr}}}; if (args.size() < 2) { Loading
fastboot/device/variables.cpp +56 −19 Original line number Diff line number Diff line Loading @@ -96,8 +96,35 @@ bool GetVariant(FastbootDevice* device, const std::vector<std::string>& /* args return true; } bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string>& /* args */, bool GetBatteryVoltageHelper(FastbootDevice* device, int32_t* battery_voltage) { using android::hardware::health::V2_0::HealthInfo; using android::hardware::health::V2_0::Result; auto health_hal = device->health_hal(); if (!health_hal) { return false; } Result ret; auto ret_val = health_hal->getHealthInfo([&](Result result, HealthInfo info) { *battery_voltage = info.legacy.batteryVoltage; ret = result; }); if (!ret_val.isOk() || (ret != Result::SUCCESS)) { return false; } return true; } bool GetBatterySoCOk(FastbootDevice* device, const std::vector<std::string>& /* args */, std::string* message) { int32_t battery_voltage = 0; if (!GetBatteryVoltageHelper(device, &battery_voltage)) { *message = "Unable to read battery voltage"; return false; } auto fastboot_hal = device->fastboot_hal(); if (!fastboot_hal) { *message = "Fastboot HAL not found"; Loading @@ -105,43 +132,53 @@ bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string } Result ret; auto ret_val = fastboot_hal->getOffModeChargeState([&](bool off_mode_charging_state, Result result) { *message = off_mode_charging_state ? "1" : "0"; auto ret_val = fastboot_hal->getBatteryVoltageFlashingThreshold( [&](int32_t voltage_threshold, Result result) { *message = battery_voltage >= voltage_threshold ? "yes" : "no"; ret = result; }); if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) { *message = "Unable to get off mode charge state"; if (!ret_val.isOk() || ret.status != Status::SUCCESS) { *message = "Unable to get battery voltage flashing threshold"; return false; } return true; } bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& /* args */, bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string>& /* args */, std::string* message) { using android::hardware::health::V2_0::HealthInfo; using android::hardware::health::V2_0::Result; auto health_hal = device->health_hal(); if (!health_hal) { *message = "Health HAL not found"; auto fastboot_hal = device->fastboot_hal(); if (!fastboot_hal) { *message = "Fastboot HAL not found"; return false; } Result ret; auto ret_val = health_hal->getHealthInfo([&](Result result, HealthInfo info) { *message = std::to_string(info.legacy.batteryVoltage); auto ret_val = fastboot_hal->getOffModeChargeState([&](bool off_mode_charging_state, Result result) { *message = off_mode_charging_state ? "1" : "0"; ret = result; }); if (!ret_val.isOk() || (ret != Result::SUCCESS)) { *message = "Unable to get battery voltage"; if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) { *message = "Unable to get off mode charge state"; return false; } return true; } bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& /* args */, std::string* message) { int32_t battery_voltage = 0; if (GetBatteryVoltageHelper(device, &battery_voltage)) { *message = std::to_string(battery_voltage); return true; } *message = "Unable to get battery voltage"; return false; } bool GetCurrentSlot(FastbootDevice* device, const std::vector<std::string>& /* args */, std::string* message) { std::string suffix = device->GetCurrentSlot(); Loading
fastboot/device/variables.h +3 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string std::string* message); bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& args, std::string* message); bool GetBatterySoCOk(FastbootDevice* device, const std::vector<std::string>& args, std::string* message); // Helpers for getvar all. std::vector<std::vector<std::string>> GetAllPartitionArgsWithSlot(FastbootDevice* device); std::vector<std::vector<std::string>> GetAllPartitionArgsNoSlot(FastbootDevice* device);