From b89a3e9935b326786017939bd43736fe46c5a889 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 4 Nov 2020 15:15:08 +0100 Subject: [PATCH] Log battery level --- app/src/main/java/eu/faircode/email/Helper.java | 10 ++++++++++ .../java/eu/faircode/email/ServiceSynchronize.java | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 57df424d8b..bbed2a7256 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -424,6 +424,16 @@ public class Helper { return null; } + static Integer getBatteryLevel(Context context) { + try { + BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE); + return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); + } catch (Throwable ex) { + Log.e(ex); + return null; + } + } + static boolean isCharging(Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false; diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 4abd85bb8f..50cc6f8ad1 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1479,7 +1479,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences new Exception(state.getUnrecoverable())); // Sends store NOOP - EntityLog.log(this, account.name + " checking store"); + EntityLog.log(this, account.name + " checking store" + + " battery=" + Helper.getBatteryLevel(this)); if (!iservice.getStore().isConnected()) throw new StoreClosedException(iservice.getStore(), "NOOP");