From 835e11c0a09c417a3b31cf63456ce685b13128a0 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 16 May 2021 08:28:33 +0200 Subject: [PATCH] Bugsnag: honor metered setting --- app/src/main/java/com/bugsnag/android/Client.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/com/bugsnag/android/Client.java b/app/src/main/java/com/bugsnag/android/Client.java index 9723eb0f03..c444d8fab5 100644 --- a/app/src/main/java/com/bugsnag/android/Client.java +++ b/app/src/main/java/com/bugsnag/android/Client.java @@ -8,13 +8,16 @@ import android.app.Application; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.content.res.Resources; +import android.net.ConnectivityManager; import android.os.Environment; import android.os.storage.StorageManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; +import androidx.preference.PreferenceManager; import kotlin.Unit; import kotlin.jvm.functions.Function2; @@ -121,6 +124,18 @@ public class Client implements MetadataAware, CallbackAware, UserAware { connectivity = new ConnectivityCompat(appContext, new Function2() { @Override public Unit invoke(Boolean hasConnection, String networkState) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext); + boolean metered = prefs.getBoolean("metered", true); + if (!metered) + try { + ConnectivityManager cm = + (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm != null && cm.isActiveNetworkMetered()) + hasConnection = false; + } catch (Throwable ex) { + android.util.Log.e("fairemail", ex + "\n" + android.util.Log.getStackTraceString(ex)); + } + Map data = new HashMap<>(); data.put("hasConnection", hasConnection); data.put("networkState", networkState);