<commit_before>package info.nightscout.androidaps.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.support.annotation.Nullable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventNetworkChange;

public class NetworkChangeReceiver extends BroadcastReceiver {

    private static Logger log = LoggerFactory.getLogger(NetworkChangeReceiver.class);

    @Override
    public void onReceive(final Context context, final Intent intent) {
        EventNetworkChange event = grabNetworkStatus(context);
        if (event != null)
            MainApp.bus().post(event);
    }

    @Nullable
    public EventNetworkChange grabNetworkStatus(final Context context) {
        EventNetworkChange event = new EventNetworkChange();

        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm == null) return null;
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();

        if (activeNetwork != null) {
            if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
                event.wifiConnected = true;
                WifiManager wifiManager = (WifiManager) MainApp.instance().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
                if (wifiManager != null) {
                    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                    if (wifiInfo.getSupplicantState() == SupplicantState.COMPLETED) {
                        event.ssid = wifiInfo.getSSID();
                    }
                    log.debug("NETCHANGE: Wifi connected. SSID: " + event.ssid);
                }
            }

            if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
                event.mobileConnected = true;
                event.roaming = activeNetwork.isRoaming();
                log.debug("NETCHANGE: Mobile connected. Roaming: " + event.roaming);
            }<commit_msg>Add isConnected, enable NSClient only, if really connected to internet<commit_after>package info.nightscout.androidaps.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.support.annotation.Nullable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventNetworkChange;

public class NetworkChangeReceiver extends BroadcastReceiver {

    private static Logger log = LoggerFactory.getLogger(NetworkChangeReceiver.class);

    @Override
    public void onReceive(final Context context, final Intent intent) {
        EventNetworkChange event = grabNetworkStatus(context);
        if (event != null)
            MainApp.bus().post(event);
    }

    @Nullable
    public EventNetworkChange grabNetworkStatus(final Context context) {
        EventNetworkChange event = new EventNetworkChange();

        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm == null) return null;
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();

        if (activeNetwork != null) {
            if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI && activeNetwork.isConnected()) {
                event.wifiConnected = true;
                WifiManager wifiManager = (WifiManager) MainApp.instance().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
                if (wifiManager != null) {
                    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                    if (wifiInfo.getSupplicantState() == SupplicantState.COMPLETED) {
                        event.ssid = wifiInfo.getSSID();
                    }
                    log.debug("NETCHANGE: Wifi connected. SSID: " + event.ssid);
                }
            }

            if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
                event.mobileConnected = true;
                event.roaming = activeNetwork.isRoaming();
                log.debug("NETCHANGE: Mobile connected. Roaming: " + event.roaming);
            }
{'fraction_non_alphanumeric': 0.09069366652305041, 'fraction_numerical': 0.0008616975441619991, 'mean_word_length': 2.9447748513169074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6037988', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1206, 'n_words': 242}