diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index f5e2d8f97f..554e1a53da 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -35,6 +35,7 @@ import android.net.LinkProperties; import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkRequest; +import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; import android.os.OperationCanceledException; @@ -206,6 +207,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences registerReceiver(suspendChanged, suspend); } + registerReceiver(batteryChanged, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); DB db = DB.getInstance(this); @@ -866,6 +869,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.unregisterOnSharedPreferenceChangeListener(this); + unregisterReceiver(batteryChanged); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) unregisterReceiver(suspendChanged); @@ -2652,6 +2657,20 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences } }; + private final BroadcastReceiver batteryChanged = new BroadcastReceiver() { + private Integer lastLevel = null; + + @Override + public void onReceive(Context context, Intent intent) { + int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); + if (!Objects.equals(level, lastLevel)) { + lastLevel = level; + EntityLog.log(context, intent.getAction() + " " + + TextUtils.join(", ", Log.getExtras(intent.getExtras()))); + } + } + }; + private void updateNetworkState(final Network network, final String reason) { getMainHandler().post(new Runnable() { @Override