Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 891893ba authored by Kazuhiro Inaba's avatar Kazuhiro Inaba
Browse files

healthd: Don't take device-scoped battery as the main system battery.

Some devices expose the battery state of stylus etc in sysfs,
in addition to the whole system's main battery. Android only
recognizes the first battery enumerated here. We need to
filter out such HID-specific battery to let Android correctly
monitor the main battery status.

Bug: 136111013
Test: CtsBatterySavingTestCases on arcada
Change-Id: I4cbf6e3bf883fb3d107bedd2849d8ad525538629
parent 5bcf6498
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -233,6 +233,15 @@ int BatteryMonitor::getIntField(const String8& path) {
    return value;
    return value;
}
}


bool BatteryMonitor::isScopedPowerSupply(const char* name) {
    constexpr char kScopeDevice[] = "Device";

    String8 path;
    path.appendFormat("%s/%s/scope", POWER_SUPPLY_SYSFS_PATH, name);
    std::string scope;
    return (readFromFile(path, &scope) > 0 && scope == kScopeDevice);
}

void BatteryMonitor::updateValues(void) {
void BatteryMonitor::updateValues(void) {
    initHealthInfo(mHealthInfo.get());
    initHealthInfo(mHealthInfo.get());


@@ -547,6 +556,11 @@ void BatteryMonitor::init(struct healthd_config *hc) {
                break;
                break;


            case ANDROID_POWER_SUPPLY_TYPE_BATTERY:
            case ANDROID_POWER_SUPPLY_TYPE_BATTERY:
                // Some devices expose the battery status of sub-component like
                // stylus. Such a device-scoped battery info needs to be skipped
                // in BatteryMonitor, which is intended to report the status of
                // the battery supplying the power to the whole system.
                if (isScopedPowerSupply(name)) continue;
                mBatteryDevicePresent = true;
                mBatteryDevicePresent = true;


                if (mHealthdConfig->batteryStatusPath.isEmpty()) {
                if (mHealthdConfig->batteryStatusPath.isEmpty()) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,7 @@ class BatteryMonitor {
    PowerSupplyType readPowerSupplyType(const String8& path);
    PowerSupplyType readPowerSupplyType(const String8& path);
    bool getBooleanField(const String8& path);
    bool getBooleanField(const String8& path);
    int getIntField(const String8& path);
    int getIntField(const String8& path);
    bool isScopedPowerSupply(const char* name);
};
};


}; // namespace android
}; // namespace android