summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliyahuSternDAI <108889726+EliyahuSternDAI@users.noreply.github.com>2024-08-09 18:09:37 +0300
committerGitHub <noreply@github.com>2024-08-09 17:09:37 +0200
commitace1b6faa9e9dd3b6bb6c4a60317d5db7048c0ea (patch)
treee9a2c7f7b41218f131555120bb969ab468e9a3a7
parentad7dfd597299f6cdf339ca924621733d3edecb0d (diff)
Add ignorenetworkstate restriction, to allow tunnel over USB (#1746)
* Add ignorenetworkstate restriction, to allow tunnel over USB * Add to app_restrictions.xml * Parse restriction value into SharedPreferences Co-authored-by: Eliyahu Stern <estern@digital.ai>
-rw-r--r--main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java8
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java14
-rw-r--r--main/src/main/res/values/untranslatable.xml1
-rw-r--r--main/src/main/res/xml/app_restrictions.xml4
4 files changed, 19 insertions, 8 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java
index 48fbb2da..9e3764e3 100644
--- a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java
+++ b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java
@@ -14,7 +14,6 @@ import android.text.TextUtils;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ConfigParser;
-import de.blinkt.openvpn.core.OpenVPNService;
import de.blinkt.openvpn.core.Preferences;
import de.blinkt.openvpn.core.ProfileManager;
import de.blinkt.openvpn.core.VpnStatus;
@@ -147,6 +146,13 @@ public class AppRestrictions {
editor.putBoolean("screenoff", pauseVPN);
editor.apply();
}
+ if(restrictions.containsKey("ignorenetworkstate"))
+ {
+ boolean ignoreNetworkState = restrictions.getBoolean("ignorenetworkstate");
+ SharedPreferences.Editor editor = defaultPrefs.edit();
+ editor.putBoolean("ignorenetstate", ignoreNetworkState);
+ editor.apply();
+ }
if (restrictions.containsKey("restartvpnonboot"))
{
boolean restartVPNonBoot = restrictions.getBoolean("restartvpnonboot");
diff --git a/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java b/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
index 8c5772a8..51a84875 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
@@ -14,14 +14,11 @@ import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.os.Handler;
import android.os.Looper;
-import android.preference.PreferenceManager;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.core.VpnStatus.ByteCountListener;
import java.util.LinkedList;
-import java.util.Objects;
-import java.util.StringTokenizer;
import static de.blinkt.openvpn.core.OpenVPNManagement.pauseReason;
@@ -38,7 +35,6 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
// Time to wait after network disconnect to pause the VPN
private final int DISCONNECT_WAIT = 20;
-
connectState network = connectState.DISCONNECTED;
connectState screen = connectState.SHOULDBECONNECTED;
connectState userpause = connectState.SHOULDBECONNECTED;
@@ -179,12 +175,16 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
return (a == null) ? (b == null) : a.equals(b);
}
-
public void networkStateChange(Context context) {
- NetworkInfo networkInfo = getCurrentNetworkInfo(context);
SharedPreferences prefs = Preferences.getDefaultSharedPreferences(context);
- boolean sendusr1 = prefs.getBoolean("netchangereconnect", true);
+ boolean ignoreNetworkState = prefs.getBoolean("ignorenetstate", false);
+ if (ignoreNetworkState) {
+ network = connectState.SHOULDBECONNECTED;
+ return;
+ }
+ NetworkInfo networkInfo = getCurrentNetworkInfo(context);
+ boolean sendusr1 = prefs.getBoolean("netchangereconnect", true);
String netstatestring;
if (networkInfo == null) {
diff --git a/main/src/main/res/values/untranslatable.xml b/main/src/main/res/values/untranslatable.xml
index edafd76e..5caa853d 100644
--- a/main/src/main/res/values/untranslatable.xml
+++ b/main/src/main/res/values/untranslatable.xml
@@ -86,6 +86,7 @@
<string name="import_from_URL">URL</string>
<string name="restriction_pausevpn">Pause VPN when screen is off and less than 64 kB transferred data in 60s</string>
<string name="restriction_restartvpnonboot">Enable the workaround to use an on boot receiver to start the VPN if the Always On VPN functionality is not available</string>
+ <string name="restriction_ignorenetworkstate">Keep the VPN connected even when no network is detected, e.g. when reverse tethering over USB using adb</string>
<string name="apprest_aidl_list">List of apps that are allowed to use the remote AIDL. If this list is in the restrictions, the app will not allowed any changes to the list by the user. Package names of allowed apps separated by comma, space or newlines</string>
<string name="apprest_remoteaidl">Remote API access</string>
diff --git a/main/src/main/res/xml/app_restrictions.xml b/main/src/main/res/xml/app_restrictions.xml
index 81171d6f..9843fada 100644
--- a/main/src/main/res/xml/app_restrictions.xml
+++ b/main/src/main/res/xml/app_restrictions.xml
@@ -76,6 +76,10 @@
android:key="restartvpnonboot"
android:restrictionType="bool"
android:title="@string/restriction_restartvpnonboot" />
+ <restriction
+ android:key="ignorenetworkstate"
+ android:restrictionType="bool"
+ android:title="@string/restriction_ignorenetworkstate" />
<restriction
android:description="@string/apprest_aidl_list"