diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 1d20b48086..03ff37a107 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -1671,7 +1671,7 @@ public class FragmentMessages extends FragmentEx { if (download == 0) download = Long.MAX_VALUE; - Boolean isMetered = Helper.isMetered(getContext()); + Boolean isMetered = Helper.isMetered(getContext(), false); boolean metered = (isMetered == null || isMetered); int count = 0; diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 2d16974bed..e6f23aa99d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -389,7 +389,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS @Override public void onPrepareOptionsMenu(Menu menu) { - Boolean metered = Helper.isMetered(getContext()); + Boolean metered = Helper.isMetered(getContext(), false); menu.findItem(R.id.menu_metered).setVisible(metered != null); if (metered != null) menu.findItem(R.id.menu_metered).setIcon( diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 8a5e14bfe5..c0ff273a50 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -305,7 +305,7 @@ public class Helper { return filename.substring(index + 1); } - static Boolean isMetered(Context context) { + static Boolean isMetered(Context context, boolean log) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) @@ -313,26 +313,38 @@ public class Helper { Network active = cm.getActiveNetwork(); if (active == null) { - Log.i(Helper.TAG, "isMetered: no active network"); + if (log) + EntityLog.log(context, "isMetered: no active network"); + else + Log.i(Helper.TAG, "isMetered: no active network"); return null; } NetworkInfo ni = cm.getNetworkInfo(active); if (ni == null) { - Log.i(Helper.TAG, "isMetered: active no info"); + if (log) + EntityLog.log(context, "isMetered: active no info"); + else + Log.i(Helper.TAG, "isMetered: active no info"); return null; } Log.i(Helper.TAG, "isMetered: active info=" + ni); if (!ni.isConnected()) { - Log.i(Helper.TAG, "isMetered: active not connected"); + if (log) + EntityLog.log(context, "isMetered: active not connected"); + else + Log.i(Helper.TAG, "isMetered: active not connected"); return null; } NetworkCapabilities caps = cm.getNetworkCapabilities(active); if (caps == null) { - Log.i(Helper.TAG, "isMetered: active no caps"); + if (log) + EntityLog.log(context, "isMetered: active no caps"); + else + Log.i(Helper.TAG, "isMetered: active no caps"); return null; } @@ -340,7 +352,10 @@ public class Helper { if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) { boolean unmetered = caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED); - Log.i(Helper.TAG, "isMetered: active not VPN unmetered=" + unmetered); + if (log) + EntityLog.log(context, "isMetered: active not VPN unmetered=" + unmetered); + else + Log.i(Helper.TAG, "isMetered: active not VPN unmetered=" + unmetered); return !unmetered; } @@ -348,7 +363,10 @@ public class Helper { Network[] networks = cm.getAllNetworks(); if (networks == null) { - Log.i(Helper.TAG, "isMetered: no underlying networks"); + if (log) + EntityLog.log(context, "isMetered: no underlying networks"); + else + Log.i(Helper.TAG, "isMetered: no underlying networks"); return null; } @@ -356,7 +374,10 @@ public class Helper { for (Network network : networks) { ni = cm.getNetworkInfo(network); if (ni == null) { - Log.i(Helper.TAG, "isMetered: no underlying info"); + if (log) + EntityLog.log(context, "isMetered: no underlying info"); + else + Log.i(Helper.TAG, "isMetered: no underlying info"); return null; } @@ -364,7 +385,10 @@ public class Helper { caps = cm.getNetworkCapabilities(network); if (caps == null) { - Log.i(Helper.TAG, "isMetered: no underlying caps"); + if (log) + EntityLog.log(context, "isMetered: no underlying caps"); + else + Log.i(Helper.TAG, "isMetered: no underlying caps"); return null; } @@ -376,7 +400,10 @@ public class Helper { Log.i(Helper.TAG, "isMetered: underlying is connected"); if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)) { - Log.i(Helper.TAG, "isMetered: underlying is unmetered"); + if (log) + EntityLog.log(context, "isMetered: underlying is unmetered"); + else + Log.i(Helper.TAG, "isMetered: underlying is unmetered"); return false; } } else @@ -386,11 +413,17 @@ public class Helper { } if (!connected) { - Log.i(Helper.TAG, "isMetered: underlying disconnected"); + if (log) + EntityLog.log(context, "isMetered: underlying disconnected"); + else + Log.i(Helper.TAG, "isMetered: underlying disconnected"); return null; } - Log.i(Helper.TAG, "isMetered: underlying is metered"); + if (log) + EntityLog.log(context, "isMetered: underlying is metered"); + else + Log.i(Helper.TAG, "isMetered: underlying is metered"); return true; } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index f47e9cf7f3..5f42d6690f 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -2396,7 +2396,7 @@ public class ServiceSynchronize extends LifecycleService { List attachments = db.attachment().getAttachments(message.id); MessageHelper helper = new MessageHelper(imessage); - Boolean isMetered = Helper.isMetered(context); + Boolean isMetered = Helper.isMetered(context, false); boolean metered = (isMetered == null || isMetered); boolean fetch = false; @@ -2505,7 +2505,7 @@ public class ServiceSynchronize extends LifecycleService { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this); boolean metered = prefs.getBoolean("metered", true); - Boolean isMetered = Helper.isMetered(ServiceSynchronize.this); + Boolean isMetered = Helper.isMetered(ServiceSynchronize.this, true); boolean suitable = (isMetered != null && (metered || !isMetered)); EntityLog.log(ServiceSynchronize.this,