Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignorenetworkstate restriction, to allow tunnel over USB #1746

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

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;
Expand Down Expand Up @@ -147,6 +146,13 @@ private static void setMiscSettings(Context c, Bundle restrictions) {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
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;

Expand All @@ -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;
Expand Down Expand Up @@ -179,12 +175,16 @@ public static boolean equalsObj(Object a, Object b) {
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) {
Expand Down
1 change: 1 addition & 0 deletions main/src/main/res/values/untranslatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
4 changes: 4 additions & 0 deletions main/src/main/res/xml/app_restrictions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down