mirror of https://github.com/M66B/FairEmail.git
Always short backoff on charging
This commit is contained in:
parent
82200c8acb
commit
d5baa93a48
|
@ -37,6 +37,7 @@ import android.content.res.Resources;
|
|||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
@ -423,6 +424,18 @@ public class Helper {
|
|||
return null;
|
||||
}
|
||||
|
||||
static boolean isCharging(Context context) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||
return false;
|
||||
try {
|
||||
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
||||
return bm.isCharging();
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isPlayStoreInstall() {
|
||||
return BuildConfig.PLAY_STORE_RELEASE;
|
||||
}
|
||||
|
|
|
@ -1292,6 +1292,7 @@ public class Log {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
ignoring = pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID);
|
||||
sb.append(String.format("Battery optimizations: %b\r\n", !ignoring));
|
||||
sb.append(String.format("Charging: %b\r\n", Helper.isCharging(context)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
|
||||
|
|
|
@ -1711,7 +1711,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
long fail_threshold = account.poll_interval * 60 * 1000L * 2 / 3;
|
||||
if (account.last_connected == null ||
|
||||
now - account.last_connected < fail_threshold) {
|
||||
if (state.getBackoff() == CONNECT_BACKOFF_START) {
|
||||
if (state.getBackoff() == CONNECT_BACKOFF_START &&
|
||||
!Helper.isCharging(this)) {
|
||||
fast_fails++;
|
||||
if (fast_fails == 1)
|
||||
first_fail = now;
|
||||
|
@ -1838,9 +1839,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
|
||||
if (backoff < max)
|
||||
state.setBackoff(backoff * 2);
|
||||
else if (backoff == max)
|
||||
state.setBackoff(CONNECT_BACKOFF_ALARM_START * 60);
|
||||
else if (backoff < CONNECT_BACKOFF_ALARM_MAX * 60)
|
||||
else if (backoff == max) {
|
||||
if (!Helper.isCharging(this))
|
||||
state.setBackoff(CONNECT_BACKOFF_ALARM_START * 60);
|
||||
} else if (backoff < CONNECT_BACKOFF_ALARM_MAX * 60)
|
||||
state.setBackoff(backoff * 2);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue