From d5aa4f15c221b065cbde0b9c535fb5bc6427b498 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Mon, 31 Mar 2025 12:09:13 +0200 Subject: Allow disabling VPN confirmation This is not recommended but people keep annoying for their broken Samsung automation nonsense that abuses Android APIs for their own ****** instead of providing proper APIs or trying to improve overall ecosystem. So app programmers are bugged to make questionable implementation choices like this to cater to that mess that Samsung created. Github: closes schwabe/ics-openvpn#1808 --- .../blinkt/openvpn/activities/DisconnectVPN.java | 19 ++++- main/src/main/res/values/strings.xml | 2 + main/src/ui/res/xml/general_settings.xml | 83 ++++++++++++---------- 3 files changed, 65 insertions(+), 39 deletions(-) (limited to 'main/src') diff --git a/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java b/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java index 4ccf5bd3..544dc413 100644 --- a/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java +++ b/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java @@ -12,6 +12,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; +import android.content.SharedPreferences; import android.os.IBinder; import android.os.RemoteException; @@ -19,6 +20,7 @@ import de.blinkt.openvpn.LaunchVPN; import de.blinkt.openvpn.R; import de.blinkt.openvpn.core.IOpenVPNServiceInternal; import de.blinkt.openvpn.core.OpenVPNService; +import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; @@ -27,6 +29,7 @@ import de.blinkt.openvpn.core.VpnStatus; */ public class DisconnectVPN extends Activity implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener { private IOpenVPNServiceInternal mService; + private boolean disconnectPending = false; private final ServiceConnection mConnection = new ServiceConnection() { @@ -36,6 +39,14 @@ public class DisconnectVPN extends Activity implements DialogInterface.OnClickLi IBinder service) { mService = IOpenVPNServiceInternal.Stub.asInterface(service); + if (disconnectPending) { + try { + mService.stopVPN(false); + } catch (RemoteException e) { + VpnStatus.logException(e); + } + finish(); + } } @Override @@ -50,8 +61,14 @@ public class DisconnectVPN extends Activity implements DialogInterface.OnClickLi super.onResume(); Intent intent = new Intent(this, OpenVPNService.class); intent.setAction(OpenVPNService.START_SERVICE); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(this); + if (prefs.getBoolean("disableconfirmation", false)) { + disconnectPending = true; + } + else { + showDisconnectDialog(); + } bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - showDisconnectDialog(); } @Override diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml index 45d3755f..2d4b7587 100755 --- a/main/src/main/res/values/strings.xml +++ b/main/src/main/res/values/strings.xml @@ -518,5 +518,7 @@ Skipping address %1$s:%2$d for DNS server entry %1$d as uses a non-default port: %2$s No valid DNS server left. Terminating connection. Profile has changed outside the editor. Closing configuration editor. + Disable VPN connection confirmations + (Not recommended) Disables confirmations when connecting/disconnecting VPN. This disables the safeguard to accidientially disconnect VPN connections diff --git a/main/src/ui/res/xml/general_settings.xml b/main/src/ui/res/xml/general_settings.xml index a1920aaf..15a635fb 100644 --- a/main/src/ui/res/xml/general_settings.xml +++ b/main/src/ui/res/xml/general_settings.xml @@ -1,102 +1,109 @@ - - - + xmlns:tools="http://schemas.android.com/tools"> + + android:title="@string/show_log_window" /> + android:defaultValue="@bool/allowTranslationDefault" + android:key="allow_translation" + android:summary="@string/allow_translations_summary" + android:title="@string/allow_translations_title" /> + android:defaultValue="false" + android:disableDependentsState="true" + android:key="ovpn3" + android:summaryOff="Use OpenVPN 2.x" + android:summaryOn="Use the C++ O4penVPN library (experimental)" + android:title="OpenVPN 3 Core" /> + android:key="alwaysOnVpn" + android:title="@string/defaultvpn" + tools:summary="@string/defaultvpnsummary" /> + android:title="@string/keep_vpn_connected" /> + android:title="@string/encrypt_profiles" /> + android:title="@string/clear_external_apps" /> + android:title="@string/use_system_proxy" /> + android:title="@string/netchange" /> + android:title="@string/screenoff_title" /> + + \ + android:key="osslspeed" + android:persistent="false" + android:title="@string/osslspeedtest" /> + - + + android:title="@string/owner_fix" /> + android:title="@string/setting_loadtun" /> - + android:defaultValue="false" + android:key="useInternalFileSelector" + android:summary="Always use the very basic file browser instead of the Android file browser. Use this option if you have problems selecting files." + android:title="Use internal file browser" /> \ No newline at end of file -- cgit v1.2.3