Bug 1269924 - Move telemetry upload to NetworkUtils.isConnected. r=grisha

The concept of "background data" (as it exists in the Android options menu)
doesn't exist in the Android APIs - I think it should be covered under
isConnected. Thus, I removed our `isBackgroundDataEnabled` method.

One other network consideration, however: we may want to consider stopping
uploads on roaming.

In the previous implementation, we did not queue the ping for upload if
the network was not connected (in order to conserve disk space). However,
this doesn't allow us to see all of the days the user interacted with
the device (e.g. for engagement) so in this implementation, we always
queue the ping and stop in the UploadService if we're not connected.

MozReview-Commit-ID: 1mjnHq3l7Jj

--HG--
extra : rebase_source : 4640aad21783f8e8edc568ea341a6e910a066d01
This commit is contained in:
Michael Comella 2016-05-19 11:54:54 -07:00
parent 690d2128a5
commit fc9ec09c75
2 changed files with 9 additions and 21 deletions

View File

@ -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) {

View File

@ -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.
*/