Added support for standalone VPNs

Like https://github.com/Genymobile/gnirehtet
This commit is contained in:
M66B 2021-01-03 19:43:01 +01:00
parent 7760d9064a
commit b1e8b450ba
5 changed files with 32 additions and 5 deletions

View File

@ -265,7 +265,10 @@ public class ConnectionHelper {
return null;
}
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean standalone_vpn = prefs.getBoolean("standalone_vpn", false);
if (standalone_vpn ||
caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
// NET_CAPABILITY_NOT_METERED is unreliable on older Android versions
boolean metered = cm.isActiveNetworkMetered();
Log.i("isMetered: active not VPN metered=" + metered);

View File

@ -61,6 +61,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
private SwitchCompat swRlah;
private EditText etTimeout;
private SwitchCompat swPreferIp4;
private SwitchCompat swStandaloneVpn;
private SwitchCompat swTcpKeepAlive;
private TextView tvTcpKeepAliveHint;
private SwitchCompat swSslHarden;
@ -70,7 +71,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
private TextView tvNetworkInfo;
private final static String[] RESET_OPTIONS = new String[]{
"metered", "download", "roaming", "rlah", "timeout", "prefer_ip4", "tcp_keep_alive", "ssl_harden"
"metered", "download", "roaming", "rlah", "timeout", "prefer_ip4", "standalone_vpn", "tcp_keep_alive", "ssl_harden"
};
@Override
@ -89,6 +90,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swRlah = view.findViewById(R.id.swRlah);
etTimeout = view.findViewById(R.id.etTimeout);
swPreferIp4 = view.findViewById(R.id.swPreferIp4);
swStandaloneVpn = view.findViewById(R.id.swStandaloneVpn);
swTcpKeepAlive = view.findViewById(R.id.swTcpKeepAlive);
tvTcpKeepAliveHint = view.findViewById(R.id.tvTcpKeepAliveHint);
swSslHarden = view.findViewById(R.id.swSslHarden);
@ -103,6 +105,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
// Wire controls
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean debug = prefs.getBoolean("debug", false);
swMetered.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
@ -170,7 +173,15 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
}
});
boolean debug = prefs.getBoolean("debug", false);
swStandaloneVpn.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
swStandaloneVpn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("standalone_vpn", checked).apply();
}
});
swTcpKeepAlive.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
tvTcpKeepAliveHint.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
@ -303,6 +314,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
etTimeout.setHint(Integer.toString(EmailService.DEFAULT_CONNECT_TIMEOUT));
swPreferIp4.setChecked(prefs.getBoolean("prefer_ip4", true));
swStandaloneVpn.setChecked(prefs.getBoolean("standalone_vpn", false));
swTcpKeepAlive.setChecked(prefs.getBoolean("tcp_keep_alive", false));
swSslHarden.setChecked(prefs.getBoolean("ssl_harden", false));
}

View File

@ -146,7 +146,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
"sync_kept",
"sync_folders",
"sync_shared_folders",
"prefer_ip4", "tcp_keep_alive", "ssl_harden", // force reconnect
"prefer_ip4", "standalone_vpn", "tcp_keep_alive", "ssl_harden", // force reconnect
"badge", "unseen_ignored", // force update badge/widget
"experiments", "debug", "protocol", // force reconnect
"auth_plain",

View File

@ -196,6 +196,17 @@
app:layout_constraintTop_toBottomOf="@id/etTimeout"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swStandaloneVpn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_standalone_vpn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swPreferIp4"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swTcpKeepAlive"
android:layout_width="0dp"
@ -204,7 +215,7 @@
android:text="@string/title_advanced_tcp_keep_alive"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swPreferIp4"
app:layout_constraintTop_toBottomOf="@id/swStandaloneVpn"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

View File

@ -337,6 +337,7 @@
<string name="title_advanced_rlah">Roam like at home</string>
<string name="title_advanced_timeout">Connection timeout (seconds)</string>
<string name="title_advanced_prefer_ip4">Prefer IPv4 over IPv6</string>
<string name="title_advanced_standalone_vpn" translatable="false">Standalone VPN</string>
<string name="title_advanced_tcp_keep_alive" translatable="false">TCP keep alive</string>
<string name="title_advanced_ssl_harden">Harden SSL connections</string>
<string name="title_advanced_manage_connectivity">Manage connectivity</string>