change check for wifi connection to metered connection

This commit is contained in:
Domingos Lopes 2016-07-21 23:14:08 -04:00
parent ef31878a10
commit 6f2bfed3a6
2 changed files with 12 additions and 10 deletions

View File

@ -76,7 +76,7 @@ import de.danoeh.antennapod.core.util.InvalidFeedException;
import de.greenrobot.event.EventBus;
/**
* Manages the download of feedfiles in the app. Downloads can be enqueued viathe startService intent.
* Manages the download of feedfiles in the app. Downloads can be enqueued via the startService intent.
* The argument of the intent is an instance of DownloadRequest in the EXTRA_REQUEST field of
* the intent.
* After the downloads have finished, the downloaded object will be passed on to a specific handler, depending on the
@ -199,10 +199,10 @@ public class DownloadService extends Service {
if(type == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
long id = status.getFeedfileId();
FeedMedia media = DBReader.getFeedMedia(id);
if(media == null || media.getItem() == null) {
FeedItem item;
if(media == null || (item = media.getItem()) == null) {
return;
}
FeedItem item = media.getItem();
boolean httpNotFound = status.getReason() == DownloadError.ERROR_HTTP_DATA_ERROR
&& String.valueOf(HttpURLConnection.HTTP_NOT_FOUND).equals(status.getReasonDetailed());
boolean forbidden = status.getReason() == DownloadError.ERROR_FORBIDDEN
@ -221,7 +221,11 @@ public class DownloadService extends Service {
// so that lists reload that it
if(status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
EventBus.getDefault().post(FeedItemEvent.updated(media.getItem()));
FeedItem item;
if(media == null || (item = media.getItem()) == null) {
return;
}
EventBus.getDefault().post(FeedItemEvent.updated(item));
}
}
queryDownloadsAsync();

View File

@ -5,6 +5,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.support.v4.net.ConnectivityManagerCompat;
import android.text.TextUtils;
import android.util.Log;
@ -80,16 +81,13 @@ public class NetworkUtils {
}
public static boolean isDownloadAllowed() {
return UserPreferences.isAllowMobileUpdate() || NetworkUtils.connectedToWifi();
return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered();
}
public static boolean connectedToWifi() {
public static boolean isNetworkMetered() {
ConnectivityManager connManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return mWifi.isConnected();
return ConnectivityManagerCompat.isActiveNetworkMetered(connManager);
}
/**