| 758 | }; |
| 759 | |
| 760 | iOSBatteryInfo queryiOSBattery(const QString &udid) { |
| 761 | QProcess proc; |
| 762 | proc.start("ideviceinfo", {"-u", udid, "-q", "com.apple.mobile.battery"}); |
| 763 | iOSBatteryInfo info; |
| 764 | if (!proc.waitForFinished(4000) || proc.exitCode() != 0) |
| 765 | return info; |
| 766 | for (const QString &line : |
| 767 | QString::fromUtf8(proc.readAllStandardOutput()).split('\n')) { |
| 768 | if (line.startsWith("BatteryCurrentCapacity:")) { |
| 769 | bool ok; |
| 770 | int v = line.section(':', 1).trimmed().toInt(&ok); |
| 771 | if (ok) info.capacity = v; |
| 772 | } else if (line.startsWith("BatteryIsCharging:")) { |
| 773 | info.charging = line.section(':', 1).trimmed().toLower() == "true"; |
| 774 | } |
| 775 | } |
| 776 | return info; |
| 777 | } |
| 778 | |
| 779 | // Returns a map keyed by UDID (with and without dashes) → battery info. |
| 780 | // The sysfs /serial file contains the UDID without dashes; idevice_id -l may |