summaryrefslogtreecommitdiff
path: root/app/src/main/java/de
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-10-02 13:31:36 +0200
committercyBerta <cyberta@riseup.net>2021-10-02 13:32:30 +0200
commit80bf751141c85316c22a0d16c1e4d6fa0f473f44 (patch)
tree08802373b1a0c24f5f83fe3f9a295141df3ae8b1 /app/src/main/java/de
parent9e131a6ae3456c6b8daa99dbd5b38dc5ef5d8592 (diff)
* refactor startTorProxy()
* fix setting http proxy port correctly * snowflake+tor does currently only work when being connected to a wifi, not a cellular network. For now, we check if the device is connected to a wifi, before attempting to start tor
Diffstat (limited to 'app/src/main/java/de')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java b/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java
index 78799a3a..cbb58f0f 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java
@@ -9,6 +9,9 @@ import android.content.Context;
import android.net.*;
import android.os.Build;
import android.text.TextUtils;
+import android.util.Log;
+
+import androidx.core.net.ConnectivityManagerCompat;
import java.net.Inet4Address;
import java.net.Inet6Address;
@@ -16,6 +19,8 @@ import java.util.Vector;
public class NetworkUtils {
+ private static final String TAG = NetworkUtils.class.getSimpleName();
+
public static Vector<String> getLocalNetworks(Context c, boolean ipv6) {
Vector<String> nets = new Vector<>();
ConnectivityManager conn = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -76,4 +81,29 @@ public class NetworkUtils {
return nets;
}
+ public static boolean isConnectedToWifi(Context context) {
+ ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
+ NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ Log.d(TAG, "isConnectedToWifi (<=LOLLIPOP_MR1): " + wifi.isConnected());
+ return wifi.isConnected();
+ } else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
+ NetworkInfo[] netInfos = connManager.getAllNetworkInfo();
+ for (NetworkInfo netInfo : netInfos) {
+ if (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
+ Log.d(TAG, "isConnectedToWifi (<= Build.VERSION_CODES.O_MR1): " + netInfo.isConnected());
+ return netInfo.isConnected();
+ }
+ }
+ } else {
+ NetworkInfo netInfo = connManager.getActiveNetworkInfo();
+ if(netInfo != null) {
+ NetworkCapabilities networkCapabilities = connManager.getNetworkCapabilities(connManager.getActiveNetwork());
+ Log.d(TAG, "isConnectedToWifi (> Build.VERSION_CODES.O_MR1): " + networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI));
+ return networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
+ }
+ }
+
+ return false;
+ }
} \ No newline at end of file