diff --git a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java index d969f465c70f..67afcb413442 100644 --- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java +++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java @@ -149,6 +149,11 @@ public class TelemetryUploadService extends IntentService { return false; } + if (!NetworkUtils.isConnected(context)) { + Log.w(LOGTAG, "Network is not connected; returning"); + return false; + } + if (!isIntentValid(intent)) { Log.w(LOGTAG, "Received invalid Intent; returning"); return false; @@ -167,6 +172,8 @@ public class TelemetryUploadService extends IntentService { * {@link #isUploadEnabledByProfileConfig(Context, GeckoProfile)} if the profile is available as it takes into * account more information. * + * You may wish to also check if the network is connected when calling this method. + * * Note that this method logs debug statements when upload is disabled. */ public static boolean isUploadEnabledByAppConfig(final Context context) { @@ -180,11 +187,6 @@ public class TelemetryUploadService extends IntentService { return false; } - if (!NetworkUtils.isBackgroundDataEnabled(context)) { - Log.d(LOGTAG, "Background data is disabled"); - return false; - } - return true; } @@ -192,6 +194,8 @@ public class TelemetryUploadService extends IntentService { * Determines if the telemetry upload feature is enabled via profile & application level configurations. This is the * preferred method. * + * You may wish to also check if the network is connected when calling this method. + * * Note that this method logs debug statements when upload is disabled. */ public static boolean isUploadEnabledByProfileConfig(final Context context, final GeckoProfile profile) { diff --git a/mobile/android/base/java/org/mozilla/gecko/util/NetworkUtils.java b/mobile/android/base/java/org/mozilla/gecko/util/NetworkUtils.java index ebc79752f7c2..2210e43edfaf 100644 --- a/mobile/android/base/java/org/mozilla/gecko/util/NetworkUtils.java +++ b/mobile/android/base/java/org/mozilla/gecko/util/NetworkUtils.java @@ -66,22 +66,6 @@ public class NetworkUtils { } } - public static boolean isBackgroundDataEnabled(final Context context) { - final NetworkInfo networkInfo = getActiveNetworkInfo(context); - return networkInfo != null && - networkInfo.isAvailable() && - networkInfo.isConnectedOrConnecting(); - } - - @Nullable - private static NetworkInfo getActiveNetworkInfo(final Context context) { - final ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - if (connectivity == null) { - return null; - } - return connectivity.getActiveNetworkInfo(); // can return null. - } - /** * Indicates whether network connectivity exists and it is possible to establish connections and pass data. */