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

Commit 0e54327f authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "BatteryMonitor: support Dock charging"

parents 7f4da54b 06b90417
Loading
Loading
Loading
Loading
+34 −8
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ BatteryMonitor::BatteryMonitor()
      mBatteryDevicePresent(false),
      mBatteryFixedCapacity(0),
      mBatteryFixedTemperature(0),
      mChargerDockOnline(false),
      mHealthInfo(std::make_unique<HealthInfo_2_1>()) {
    initHealthInfo(mHealthInfo.get());
}
@@ -196,6 +197,7 @@ BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String
            {"USB_PD", ANDROID_POWER_SUPPLY_TYPE_AC},
            {"USB_PD_DRP", ANDROID_POWER_SUPPLY_TYPE_USB},
            {"Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS},
            {"Dock", ANDROID_POWER_SUPPLY_TYPE_DOCK},
            {NULL, 0},
    };
    std::string buf;
@@ -319,10 +321,22 @@ void BatteryMonitor::updateValues(void) {
            case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
                props.chargerWirelessOnline = true;
                break;
            case ANDROID_POWER_SUPPLY_TYPE_DOCK:
                mChargerDockOnline = true;
                break;
            default:
                path.clear();
                path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH,
                                  mChargerNames[i].string());
                if (access(path.string(), R_OK) == 0) {
                    mChargerDockOnline = true;
                    KLOG_INFO(LOG_TAG, "%s: online\n",
                              mChargerNames[i].string());
                } else {
                    KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
                                 mChargerNames[i].string());
                }
            }
            path.clear();
            path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH,
                              mChargerNames[i].string());
@@ -391,8 +405,8 @@ void BatteryMonitor::logValues(const android::hardware::health::V2_1::HealthInfo

bool BatteryMonitor::isChargerOnline() {
    const HealthInfo_1_0& props = mHealthInfo->legacy.legacy;
    return props.chargerAcOnline | props.chargerUsbOnline |
            props.chargerWirelessOnline;
    return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline |
           mChargerDockOnline;
}

int BatteryMonitor::getChargeStatus() {
@@ -477,10 +491,10 @@ void BatteryMonitor::dumpState(int fd) {
    char vs[128];
    const HealthInfo_1_0& props = mHealthInfo->legacy.legacy;

    snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d current_max: %d voltage_max: %d\n",
             props.chargerAcOnline, props.chargerUsbOnline,
             props.chargerWirelessOnline, props.maxChargingCurrent,
             props.maxChargingVoltage);
    snprintf(vs, sizeof(vs),
             "ac: %d usb: %d wireless: %d dock: %d current_max: %d voltage_max: %d\n",
             props.chargerAcOnline, props.chargerUsbOnline, props.chargerWirelessOnline,
             mChargerDockOnline, props.maxChargingCurrent, props.maxChargingVoltage);
    write(fd, vs, strlen(vs));
    snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n",
             props.batteryStatus, props.batteryHealth, props.batteryPresent);
@@ -554,6 +568,7 @@ void BatteryMonitor::init(struct healthd_config *hc) {
            case ANDROID_POWER_SUPPLY_TYPE_AC:
            case ANDROID_POWER_SUPPLY_TYPE_USB:
            case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
            case ANDROID_POWER_SUPPLY_TYPE_DOCK:
                path.clear();
                path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
                if (access(path.string(), R_OK) == 0)
@@ -691,6 +706,17 @@ void BatteryMonitor::init(struct healthd_config *hc) {
            case ANDROID_POWER_SUPPLY_TYPE_UNKNOWN:
                break;
            }

            // Look for "is_dock" file
            path.clear();
            path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH, name);
            if (access(path.string(), R_OK) == 0) {
                path.clear();
                path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
                if (access(path.string(), R_OK) == 0)
                    mChargerNames.add(String8(name));

            }
        }
    }

+4 −1
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@ class BatteryMonitor {
        ANDROID_POWER_SUPPLY_TYPE_AC,
        ANDROID_POWER_SUPPLY_TYPE_USB,
        ANDROID_POWER_SUPPLY_TYPE_WIRELESS,
        ANDROID_POWER_SUPPLY_TYPE_BATTERY
        ANDROID_POWER_SUPPLY_TYPE_BATTERY,
        ANDROID_POWER_SUPPLY_TYPE_DOCK
    };

    BatteryMonitor();
@@ -75,6 +76,8 @@ class BatteryMonitor {
    bool mBatteryDevicePresent;
    int mBatteryFixedCapacity;
    int mBatteryFixedTemperature;
    // TODO(b/214126090): to migrate to AIDL HealthInfo
    bool mChargerDockOnline;
    std::unique_ptr<android::hardware::health::V2_1::HealthInfo> mHealthInfo;

    int readFromFile(const String8& path, std::string* buf);