<commit_before>package de.danoeh.antennapod.core.util;

import android.content.Context;
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;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
import de.danoeh.antennapod.core.storage.DBWriter;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class NetworkUtils {

	private static final String TAG = NetworkUtils.class.getSimpleName();

	private static Context context;

	public static void init(Context context) {
		NetworkUtils.context = context;
	}

	/**
	 * Returns true if the device is connected to Wi-Fi and the Wi-Fi filter for
	 * automatic downloads is disabled or the device is connected to a Wi-Fi
	 * network that is on the 'selected networks' list of the Wi-Fi filter for
	 * automatic downloads and false otherwise.
	 * */
	public static boolean autodownloadNetworkAvailable() {
		ConnectivityManager cm = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = cm.getActiveNetworkInfo();
		if (networkInfo != null) {
			if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
				Log.d(TAG, "Device is connected to Wi-Fi");
				if (networkInfo.isConnected()) {
					if (!UserPreferences.isEnableAutodownloadWifiFilter()) {
						Log.d(TAG, "Auto-dl filter is disabled");
						return true;
					} else {
						WifiManager wm = (WifiManager) context
								.getSystemService(Context.WIFI_SERVICE);
						WifiInfo wifiInfo = wm.getConnectionInfo();
						List<String> selectedNetworks = Arrays
								.asList(UserPreferences
										.getAutodownloadSelectedNetworks());
						if (selectedNetworks.contains(Integer.toString(wifiInfo
								.getNetworkId()))) {
							Log.d(TAG, "Current network is on the selected networks list");
							return true;
						}
					}
				}
			} else {
				if (!UserPreferences.isEnableAutodownloadOnMobile())
				{
					Log.d(TAG, "Auto Download not enabled on Mobile");
					return false;
				}
				if (networkInfo.isRoaming())
				{
					Log.d(TAG, "Roaming on foreign network");
					return false;
				}
				return true;
			}
		}
		Log.d(TAG, "Network for auto-dl is not available");
		return false;
	}

    public static boolean networkAvailable() {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        return info != null && info.isConnected();
    }

	public static boolean isDownloadAllowed() {
		return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered();
	}

	public static boolean isNetworkMetered() {
		ConnectivityManager connManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
        return ConnectivityManagerCompat.isActiveNetworkMetered(connManager);
	}
<commit_msg>Fix code style<commit_after>package de.danoeh.antennapod.core.util;

import android.content.Context;
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;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
import de.danoeh.antennapod.core.storage.DBWriter;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class NetworkUtils {

	private static final String TAG = NetworkUtils.class.getSimpleName();

	private static Context context;

	public static void init(Context context) {
		NetworkUtils.context = context;
	}

	/**
	 * Returns true if the device is connected to Wi-Fi and the Wi-Fi filter for
	 * automatic downloads is disabled or the device is connected to a Wi-Fi
	 * network that is on the 'selected networks' list of the Wi-Fi filter for
	 * automatic downloads and false otherwise.
	 * */
	public static boolean autodownloadNetworkAvailable() {
		ConnectivityManager cm = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = cm.getActiveNetworkInfo();
		if (networkInfo != null) {
			if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
				Log.d(TAG, "Device is connected to Wi-Fi");
				if (networkInfo.isConnected()) {
					if (!UserPreferences.isEnableAutodownloadWifiFilter()) {
						Log.d(TAG, "Auto-dl filter is disabled");
						return true;
					} else {
						WifiManager wm = (WifiManager) context
								.getSystemService(Context.WIFI_SERVICE);
						WifiInfo wifiInfo = wm.getConnectionInfo();
						List<String> selectedNetworks = Arrays
								.asList(UserPreferences
										.getAutodownloadSelectedNetworks());
						if (selectedNetworks.contains(Integer.toString(wifiInfo
								.getNetworkId()))) {
							Log.d(TAG, "Current network is on the selected networks list");
							return true;
						}
					}
				}
			} else {
				if (!UserPreferences.isEnableAutodownloadOnMobile()) {
					Log.d(TAG, "Auto Download not enabled on Mobile");
					return false;
				}
				if (networkInfo.isRoaming()) {
					Log.d(TAG, "Roaming on foreign network");
					return false;
				}
				return true;
			}
		}
		Log.d(TAG, "Network for auto-dl is not available");
		return false;
	}

    public static boolean networkAvailable() {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        return info != null && info.isConnected();
    }

	public static boolean isDownloadAllowed() {
		return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered();
	}

	public static boolean isNetworkMetered() {
		ConnectivityManager connManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
        return ConnectivityManagerCompat.isActiveNetworkMetered(connManager);
	}

{'fraction_non_alphanumeric': 0.09682609331578178, 'fraction_numerical': 0.001170103846716396, 'mean_word_length': 4.122097378277154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2276820', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2008, 'n_words': 482}