aospa: Fix race condition for LineageHealth.
If the HAL accidentally selects these nodes, the charging control capability declared by the dev might not hold. So force a default capability for each charging control node. If the charging control node has different capability than the default capability, the dev can override it by declaring the `HEALTH_CHARGING_CONTROL_CHARGING_PATH` and related variables in the device tree. Change-Id: I3d9226375ab3563cba5b970244cc4040c3cc6479 health: Don't use other nodes when a custom node is set Change-Id: Iebdb9722f101ef4e52c5d88173a5e43df1896b46 Signed-off-by: Fazil Sheik <fazil.sheik96@gmail.com>
This commit is contained in:
parent
aea31c195f
commit
1e56e9b996
|
@ -22,23 +22,38 @@ namespace health {
|
|||
|
||||
#ifdef HEALTH_CHARGING_CONTROL_SUPPORTS_TOGGLE
|
||||
static const std::vector<ChargingEnabledNode> kChargingEnabledNodes = {
|
||||
{HEALTH_CHARGING_CONTROL_CHARGING_PATH, HEALTH_CHARGING_CONTROL_CHARGING_ENABLED,
|
||||
HEALTH_CHARGING_CONTROL_CHARGING_DISABLED},
|
||||
{"/sys/class/power_supply/battery/battery_charging_enabled", "1", "0"},
|
||||
{"/sys/class/power_supply/battery/charging_enabled", "1", "0"},
|
||||
{"/sys/class/power_supply/battery/input_suspend", "0", "1"},
|
||||
{"/sys/class/qcom-battery/input_suspend", "0", "1"},
|
||||
#ifdef HEALTH_CHARGING_CONTROL_CHARGING_PATH
|
||||
{HEALTH_CHARGING_CONTROL_CHARGING_PATH,
|
||||
HEALTH_CHARGING_CONTROL_CHARGING_ENABLED,
|
||||
HEALTH_CHARGING_CONTROL_CHARGING_DISABLED,
|
||||
{}},
|
||||
#else
|
||||
{"/sys/class/power_supply/battery/battery_charging_enabled", "1", "0",
|
||||
static_cast<int>(ChargingControlSupportedMode::TOGGLE) |
|
||||
static_cast<int>(ChargingControlSupportedMode::BYPASS)},
|
||||
{"/sys/class/power_supply/battery/charging_enabled", "1", "0",
|
||||
static_cast<int>(ChargingControlSupportedMode::TOGGLE) |
|
||||
static_cast<int>(ChargingControlSupportedMode::BYPASS)},
|
||||
{"/sys/class/power_supply/battery/input_suspend", "0", "1",
|
||||
static_cast<int>(ChargingControlSupportedMode::TOGGLE)},
|
||||
{"/sys/class/qcom-battery/input_suspend", "0", "1",
|
||||
static_cast<int>(ChargingControlSupportedMode::TOGGLE)},
|
||||
#endif
|
||||
};
|
||||
|
||||
#define OPEN_RETRY_COUNT 10
|
||||
|
||||
ChargingControl::ChargingControl() : mChargingEnabledNode(nullptr) {
|
||||
while (!mChargingEnabledNode) {
|
||||
for (const auto& node : kChargingEnabledNodes) {
|
||||
if (access(node.path.c_str(), R_OK | W_OK) == 0) {
|
||||
mChargingEnabledNode = &node;
|
||||
break;
|
||||
for (int retries = 0; retries < OPEN_RETRY_COUNT; retries++) {
|
||||
if (access(node.path.c_str(), R_OK | W_OK) == 0) {
|
||||
mChargingEnabledNode = &node;
|
||||
return;
|
||||
}
|
||||
PLOG(WARNING) << "Failed to access() file " << node.path;
|
||||
usleep(10000);
|
||||
}
|
||||
PLOG(WARNING) << "Failed to access() file " << node.path;
|
||||
usleep(100000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +148,11 @@ ndk::ScopedAStatus ChargingControl::getSupportedMode(int* _aidl_return) {
|
|||
mode |= static_cast<int>(ChargingControlSupportedMode::DEADLINE);
|
||||
#endif
|
||||
|
||||
#ifdef HEALTH_CHARGING_CONTROL_SUPPORTS_TOGGLE
|
||||
*_aidl_return = mChargingEnabledNode->supported_mode.value_or(mode);
|
||||
#else
|
||||
*_aidl_return = mode;
|
||||
#endif
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ struct ChargingEnabledNode {
|
|||
const std::string path;
|
||||
const std::string value_true;
|
||||
const std::string value_false;
|
||||
const std::optional<int> supported_mode;
|
||||
};
|
||||
|
||||
struct ChargingControl : public BnChargingControl {
|
||||
|
|
Loading…
Reference in New Issue