mirror of https://github.com/BOINC/boinc.git
client: Basic detection of how much capacity a host's battery has on Android and Windows.
This commit is contained in:
parent
3453ed7814
commit
759b3b8078
|
@ -444,6 +444,37 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the percent of which the battery is charged
|
||||||
|
//
|
||||||
|
int HOST_INFO::host_battery_charge() {
|
||||||
|
#if defined(ANDROID)
|
||||||
|
// using /sys/class/power_supply/battery/capacity
|
||||||
|
char capacitypath[256];
|
||||||
|
int capacity = 0;
|
||||||
|
|
||||||
|
snprintf(capacitypath, sizeof(capacitypath), "/sys/class/power_supply/battery/capacity");
|
||||||
|
|
||||||
|
FILE *battery_capacity_file = fopen(acpath, "r");
|
||||||
|
if(battery_capacity_file) {
|
||||||
|
fscanf(battery_capacity_file, "%d", &capacity);
|
||||||
|
fclose(battery_capacity_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (capacity) {
|
||||||
|
char msg[1024];
|
||||||
|
snprintf(msg, sizeof(msg),
|
||||||
|
"battery capacity at: %d%% charge",
|
||||||
|
capacity
|
||||||
|
);
|
||||||
|
LOGD(msg);
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if LINUX_LIKE_SYSTEM
|
#if LINUX_LIKE_SYSTEM
|
||||||
static void parse_meminfo_linux(HOST_INFO& host) {
|
static void parse_meminfo_linux(HOST_INFO& host) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
|
@ -1279,9 +1279,9 @@ int HOST_INFO::get_host_info() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HOST_INFO::host_is_running_on_batteries() {
|
bool HOST_INFO::host_is_running_on_batteries() {
|
||||||
SYSTEM_POWER_STATUS pStatus;
|
SYSTEM_POWER_STATUS Status;
|
||||||
ZeroMemory(&pStatus, sizeof(SYSTEM_POWER_STATUS));
|
ZeroMemory(&Status, sizeof(SYSTEM_POWER_STATUS));
|
||||||
if (!GetSystemPowerStatus(&pStatus)) {
|
if (!GetSystemPowerStatus(&Status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1289,13 +1289,24 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
||||||
// undocumented value, so lets check to see if the
|
// undocumented value, so lets check to see if the
|
||||||
// battery is charging or missing and make that part
|
// battery is charging or missing and make that part
|
||||||
// of the decision.
|
// of the decision.
|
||||||
bool bIsOnBatteryPower = (pStatus.ACLineStatus != 1);
|
bool bIsOnBatteryPower = (Status.ACLineStatus != 1);
|
||||||
bool bIsBatteryCharging = ((pStatus.BatteryFlag & 8) == 8);
|
bool bIsBatteryCharging = ((Status.BatteryFlag & 8) == 8);
|
||||||
bool bIsBatteryMissing = ((pStatus.BatteryFlag & 128) == 128);
|
bool bIsBatteryMissing = ((Status.BatteryFlag & 128) == 128);
|
||||||
|
|
||||||
return (bIsOnBatteryPower && !bIsBatteryCharging && !bIsBatteryMissing);
|
return (bIsOnBatteryPower && !bIsBatteryCharging && !bIsBatteryMissing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int HOST_INFO::host_battery_charge() {
|
||||||
|
SYSTEM_POWER_STATUS Status;
|
||||||
|
ZeroMemory(&Status, sizeof(SYSTEM_POWER_STATUS));
|
||||||
|
if (!GetSystemPowerStatus(&Status)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((int)Status.BatteryLifePercent) == 255) return 0;
|
||||||
|
return ((int)Status.BatteryLifePercent);
|
||||||
|
}
|
||||||
|
|
||||||
bool HOST_INFO::users_idle(bool /*check_all_logins*/, double idle_time_to_run) {
|
bool HOST_INFO::users_idle(bool /*check_all_logins*/, double idle_time_to_run) {
|
||||||
double seconds_idle = get_idle_tick_count() / 1000;
|
double seconds_idle = get_idle_tick_count() / 1000;
|
||||||
double seconds_time_to_run = 60 * idle_time_to_run;
|
double seconds_time_to_run = 60 * idle_time_to_run;
|
||||||
|
|
|
@ -75,6 +75,7 @@ public:
|
||||||
void print();
|
void print();
|
||||||
|
|
||||||
bool host_is_running_on_batteries();
|
bool host_is_running_on_batteries();
|
||||||
|
int host_battery_charge();
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
bool users_idle(bool check_all_logins, double idle_time_to_run, double *actual_idle_time=NULL);
|
bool users_idle(bool check_all_logins, double idle_time_to_run, double *actual_idle_time=NULL);
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue