<commit_before>package me.devsaki.hentoid.util.network;

import android.app.ActivityManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.TrafficStats;
import android.os.Build;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

import static android.content.Context.ACTIVITY_SERVICE;

public class NetworkHelper {

    private NetworkHelper() {
        throw new IllegalStateException("Utility class");
    }

    @IntDef({Connectivity.NO_INTERNET, Connectivity.WIFI, Connectivity.OTHER})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Connectivity {
        int NO_INTERNET = -1;
        int WIFI = 0;
        int OTHER = 1;
    }


    @SuppressWarnings({"squid:CallToDeprecatedMethod"})
    public static @Connectivity
    int getConnectivity(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (null == connectivityManager) return Connectivity.NO_INTERNET;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Network networkCapabilities = connectivityManager.getActiveNetwork();
            if (null == networkCapabilities) return Connectivity.NO_INTERNET;
            NetworkCapabilities actNw = connectivityManager.getNetworkCapabilities(networkCapabilities);
            if (null == actNw) return Connectivity.NO_INTERNET;

            if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) return Connectivity.WIFI;
            else if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR))
                return Connectivity.OTHER;
            else if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET))
                return Connectivity.OTHER;
            else return Connectivity.NO_INTERNET; // Bluetooth, LoWPAN
        } else {
            NetworkInfo info = connectivityManager.getActiveNetworkInfo();
            if (null == info) return Connectivity.NO_INTERNET;

            switch (info.getType()) {
                case (ConnectivityManager.TYPE_WIFI):
                    return Connectivity.WIFI;
                case (ConnectivityManager.TYPE_MOBILE):
                case (ConnectivityManager.TYPE_ETHERNET):
                    return Connectivity.OTHER;
                default:
                    return Connectivity.NO_INTERNET; // Others (e.g. TYPE_MOBILE_MMS)
            }
        }
    }

    public static long getIncomingNetworkUsage(@NonNull final Context context) {
        // Get running processes
        ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
        if (null == manager) return -1;

        long totalReceived = 0;

        List<ActivityManager.RunningAppProcessInfo> runningApps = manager.getRunningAppProcesses();
        if (runningApps != null)
            for (ActivityManager.RunningAppProcessInfo runningApp : runningApps) {
                long received = TrafficStats.getUidRxBytes(runningApp.uid);
                totalReceived += received;
            }
        return totalReceived;
    }
}
<commit_msg>Attempt at fixing VPN over cellular not detected as a valid connection<commit_after>package me.devsaki.hentoid.util.network;

import android.app.ActivityManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.TrafficStats;
import android.os.Build;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

import static android.content.Context.ACTIVITY_SERVICE;

public class NetworkHelper {

    private NetworkHelper() {
        throw new IllegalStateException("Utility class");
    }

    @IntDef({Connectivity.NO_INTERNET, Connectivity.WIFI, Connectivity.OTHER})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Connectivity {
        int NO_INTERNET = -1;
        int WIFI = 0;
        int OTHER = 1;
    }


    @SuppressWarnings({"squid:CallToDeprecatedMethod"})
    public static @Connectivity
    int getConnectivity(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (null == connectivityManager) return Connectivity.NO_INTERNET;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Network activeNetwork = connectivityManager.getActiveNetwork();
            if (null == activeNetwork) return Connectivity.NO_INTERNET;
            NetworkCapabilities actNw = connectivityManager.getNetworkCapabilities(activeNetwork);
            if (null == actNw) return Connectivity.NO_INTERNET;

            if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) return Connectivity.WIFI;
            else return Connectivity.OTHER;
        } else {
            NetworkInfo info = connectivityManager.getActiveNetworkInfo();
            if (null == info) return Connectivity.NO_INTERNET;

            switch (info.getType()) {
                case (ConnectivityManager.TYPE_WIFI):
                    return Connectivity.WIFI;
                case (ConnectivityManager.TYPE_MOBILE_MMS):
                    return Connectivity.NO_INTERNET;
                default:
                    return Connectivity.OTHER; // Others (e.g. TYPE_MOBILE_MMS)
            }
        }
    }

    public static long getIncomingNetworkUsage(@NonNull final Context context) {
        // Get running processes
        ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
        if (null == manager) return -1;

        long totalReceived = 0;

        List<ActivityManager.RunningAppProcessInfo> runningApps = manager.getRunningAppProcesses();
        if (runningApps != null)
            for (ActivityManager.RunningAppProcessInfo runningApp : runningApps) {
                long received = TrafficStats.getUidRxBytes(runningApp.uid);
                totalReceived += received;
            }
        return totalReceived;
    }
}

{'fraction_non_alphanumeric': 0.08104309806371018, 'fraction_numerical': 0.001561524047470331, 'mean_word_length': 2.9684014869888475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '829687', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1662, 'n_words': 349}