Merge pull request #5311 from BOINC/dpa_android_battery

This commit is contained in:
Vitalii Koshura 2023-07-20 06:55:58 +02:00 committed by GitHub
commit e72eae2cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -685,6 +685,10 @@ extern THREAD throttle_thread;
// Android: if don't get a report_device_status() RPC from the GUI
// in this interval, exit.
// We rely on the GUI to report battery status.
#define ANDROID_BATTERY_BACKOFF 300
// Android: if battery is overheated or undercharged,
// suspend for at least this long
// (avoid rapid start/stop)
#ifndef ANDROID
#define USE_NET_PREFS

View File

@ -265,17 +265,28 @@ int CLIENT_STATE::check_suspend_processing() {
}
#ifdef ANDROID
// suspend if we haven't heard from the GUI in 30 sec
// (we rely on it for battery info)
//
if (now > device_status_time + ANDROID_KEEPALIVE_TIMEOUT) {
requested_exit = true;
return SUSPEND_REASON_NO_GUI_KEEPALIVE;
}
// check for hot battery
// If suspend because of hot battery, don't resume for at least 5 min
// (crude hysteresis)
//
static double battery_heat_resume_time=0;
if (now < battery_heat_resume_time) {
return SUSPEND_REASON_BATTERY_OVERHEATED;
}
if (device_status.battery_state == BATTERY_STATE_OVERHEATED) {
battery_heat_resume_time = now + ANDROID_BATTERY_BACKOFF;
return SUSPEND_REASON_BATTERY_OVERHEATED;
}
if (device_status.battery_temperature_celsius > global_prefs.battery_max_temperature) {
battery_heat_resume_time = now + ANDROID_BATTERY_BACKOFF;
return SUSPEND_REASON_BATTERY_OVERHEATED;
}
@ -283,9 +294,14 @@ int CLIENT_STATE::check_suspend_processing() {
// while it's recharging.
// So compute only if 95% charged or more.
//
static double battery_charge_resume_time=0;
if (now < battery_charge_resume_time) {
return SUSPEND_REASON_BATTERY_CHARGING;
}
int cp = device_status.battery_charge_pct;
if (cp >= 0) {
if (cp < global_prefs.battery_charge_min_pct) {
battery_charge_resume_time = now + ANDROID_BATTERY_BACKOFF;
return SUSPEND_REASON_BATTERY_CHARGING;
}
}