diff options
Diffstat (limited to 'main/src/main')
6 files changed, 84 insertions, 12 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java b/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java index fbd693b9..4f9d6f91 100644 --- a/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java +++ b/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java @@ -8,6 +8,9 @@ package de.blinkt.openvpn; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + import de.blinkt.openvpn.core.ProfileManager; @@ -18,9 +21,14 @@ public class OnBootReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + boolean useStartOnBoot = prefs.getBoolean("restartvpnonboot", false); + if (!useStartOnBoot) + return; if(Intent.ACTION_BOOT_COMPLETED.equals(action) || Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) { - VpnProfile bootProfile = ProfileManager.getLastConnectedProfile(context, true); + VpnProfile bootProfile = ProfileManager.getAlwaysOnVPN(context); if(bootProfile != null) { launchVPN(bootProfile, context); } diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index ef397fa8..3ab39a84 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -363,12 +363,14 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac mProfile = ProfileManager.get(this, profileUUID); } else { /* The intent is null when we are set as always-on or the service has been restarted. */ - mProfile = ProfileManager.getLastConnectedProfile(this, false); + mProfile = ProfileManager.getLastConnectedProfile(this); VpnStatus.logInfo(R.string.service_restarted); /* Got no profile, just stop */ if (mProfile == null) { - Log.d("OpenVPN", "Got no last connected profile on null intent. Stopping"); + Log.d("OpenVPN", "Got no last connected profile on null intent. Assuming always on."); + mProfile = ProfileManager.getAlwaysOnVPN(this); + stopSelf(startId); return START_NOT_STICKY; } diff --git a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java index 4f9c219b..165bd647 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java @@ -76,13 +76,10 @@ public class ProfileManager { } - public static VpnProfile getLastConnectedProfile(Context c, boolean onBoot) { + public static VpnProfile getLastConnectedProfile(Context c) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); - boolean useStartOnBoot = prefs.getBoolean("restartvpnonboot", false); - if (onBoot && !useStartOnBoot) - return null; String lastConnectedProfile = prefs.getString(LAST_CONNECTED_PROFILE, null); if (lastConnectedProfile != null) @@ -195,4 +192,12 @@ public class ProfileManager { return mLastConnectedVpn; } + public static VpnProfile getAlwaysOnVPN(Context context) { + checkInstance(context); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + String uuid = prefs.getString("alwaysOnVpn", null); + return get(uuid); + + } } diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java b/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java index 013369b9..529ae944 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java @@ -5,6 +5,7 @@ package de.blinkt.openvpn.fragments; import java.io.File; +import java.util.Collection; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -17,18 +18,24 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.os.Build; import android.os.Bundle; import android.preference.CheckBoxPreference; +import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; import de.blinkt.openvpn.BuildConfig; import de.blinkt.openvpn.R; +import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.api.ExternalAppDatabase; +import de.blinkt.openvpn.core.ProfileManager; -public class GeneralSettings extends PreferenceFragment implements OnPreferenceClickListener, OnClickListener { + +public class GeneralSettings extends PreferenceFragment implements OnPreferenceClickListener, OnClickListener, Preference.OnPreferenceChangeListener { private ExternalAppDatabase mExtapp; + private ListPreference mAlwaysOnVPN; @Override public void onCreate(Bundle savedInstanceState) { @@ -40,6 +47,8 @@ public class GeneralSettings extends PreferenceFragment implements OnPreferenceC PreferenceCategory devHacks = (PreferenceCategory) findPreference("device_hacks"); + mAlwaysOnVPN = (ListPreference) findPreference("alwaysOnVpn"); + mAlwaysOnVPN.setOnPreferenceChangeListener(this); Preference loadtun = findPreference("loadTunModule"); @@ -70,7 +79,45 @@ public class GeneralSettings extends PreferenceFragment implements OnPreferenceC setClearApiSummary(); } - private void setClearApiSummary() { + @Override + public void onResume() { + super.onResume(); + + ProfileManager pm = ProfileManager.getInstance(getActivity()); + Collection<VpnProfile> profiles = pm.getProfiles(); + CharSequence[] entries = new CharSequence[profiles.size()]; + CharSequence[] entryValues = new CharSequence[profiles.size()];; + + int i=0; + for (VpnProfile p: profiles) + { + entries[i]=p.getName(); + entryValues[i]=p.getUUIDString(); + i++; + } + + mAlwaysOnVPN.setEntries(entries); + mAlwaysOnVPN.setEntryValues(entryValues); + + + VpnProfile vpn = ProfileManager.getAlwaysOnVPN(getActivity()); + if (vpn== null) + mAlwaysOnVPN.setSummary(R.string.novpn_selected); + else + mAlwaysOnVPN.setSummary(vpn.getName()); + + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (preference== mAlwaysOnVPN) { + VpnProfile vpn = ProfileManager.get(getActivity(), (String) newValue); + mAlwaysOnVPN.setSummary(vpn.getName()); + } + return true; + } + + private void setClearApiSummary() { Preference clearapi = findPreference("clearapi"); if(mExtapp.getExtAppList().isEmpty()) { diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml index ad905367..f68832e9 100755 --- a/main/src/main/res/values/strings.xml +++ b/main/src/main/res/values/strings.xml @@ -202,8 +202,8 @@ <string name="use_system_proxy">Use system proxy</string> <string name="use_system_proxy_summary">Use the system wide configuration for HTTP/HTTPS proxies to connect.</string> <string name="donatewithpaypal">You can <a href=\"https://www.paypal.com/cgi-bin/webscr?hosted_button_id=R2M6ZP9AF25LS&amp;cmd=_s-xclick\">donate with PayPal</a> </string> - <string name="onbootrestartsummary">OpenVPN will reconnect a VPN if it was active on system reboot/shutdown. Please read the Connection warning FAQ before using this option.</string> - <string name="onbootrestart">Reconnect on reboot</string> + <string name="onbootrestartsummary">OpenVPN will connect the specified VPN if it was active on system boot. Please read the connection warning FAQ before using this option on Android < 5.0.</string> + <string name="onbootrestart">Connect on boot</string> <string name="ignore">Ignore</string> <string name="restart">Restart</string> <string name="restart_vpn_after_change">Configuration changes are applied after restarting the VPN. (Re)start the VPN now?</string> @@ -407,4 +407,6 @@ <string name="reread_log">Reread (%d) log items from log cache file</string> <string name="samsung_broken">Even though Samsung phones are among the most selling Android phones, Samsung\'s firmware are also among the most buggy Android firmwares. The bugs are not limited to the VPN operation on these devices but many of them can be workarounded. In the following some of these bugs are described.\n\nDNS does not work unless the DNS server in the VPN range.\n\nOn many Samsung 5.x devices the allowed/disallowed apps feature does not work.\nOn Samsung 6.x VPN is reported not to work unless the VPN app is exempted from Powersave features.</string> <string name="samsung_broken_title">Samsung phones</string> + <string name="novpn_selected">No VPN selected.</string> + <string name="alwaysonvpn">VPN used on boot and for Always-On</string> </resources> diff --git a/main/src/main/res/xml/general_settings.xml b/main/src/main/res/xml/general_settings.xml index 1e18b19c..bed282b0 100644 --- a/main/src/main/res/xml/general_settings.xml +++ b/main/src/main/res/xml/general_settings.xml @@ -4,7 +4,8 @@ ~ Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt --> -<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools"> <PreferenceCategory android:title="@string/appbehaviour" android:key="app_behaviour"> <CheckBoxPreference android:defaultValue="true" @@ -12,6 +13,7 @@ android:summary="@string/show_log_summary" android:title="@string/show_log_window"/> + <CheckBoxPreference android:defaultValue="false" android:key="ovpn3" @@ -20,6 +22,12 @@ android:title="OpenVPN 3 Core"/> + <ListPreference + android:key="alwaysOnVpn" + android:title="@string/alwaysonvpn" + tools:summary="foo bar baz VPN" + /> + <CheckBoxPreference android:defaultValue="false" android:key="restartvpnonboot" |