summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-05-29 19:52:41 +0200
committerArne Schwabe <arne@rfc2549.org>2013-05-29 19:52:41 +0200
commit9288f9cdcb85f00918614595a1b81775a8d9e607 (patch)
tree89adff4ca252e7d660aa88ac88383e002ea97335
parentd7f6bea080270060f6b76729704ffa978c25d5af (diff)
Allow pausing the VPN also without persistent-tun.
I don't like the concept but I don't to educate people ….
-rwxr-xr-xres/values/strings.xml4
-rw-r--r--src/de/blinkt/openvpn/core/DeviceStateReceiver.java45
2 files changed, 25 insertions, 24 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index db6305e3..b7589271 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -278,9 +278,9 @@
<string name="no_external_app_allowed">No app allowed to use external API</string>
<string name="allowed_apps">Allowed apps: %s</string>
<string name="clearappsdialog">Clear list of allowed external apps?\nCurrent list of allowed apps:\n\n%s</string>
- <string name="screenoff_summary">"Pause VPN when screen is off and less than 64 kB transferred data in 60s. Pausing the VPN the is only enabled if the \"Persistent Tun\" option is enabled on a VPN. When the VPN is paused your device has NO network connectivity."</string>
+ <string name="screenoff_summary">"Pause VPN when screen is off and less than 64 kB transferred data in 60s. When the \"Persistent Tun\" option is enabled pausing the VPN will leave your device with NO network connectivity. Without the \"Persistent Tun\" option the device will have no VPN connection/protection.</string>
<string name="screenoff_title">Pause VPN connection after screen off</string>
<string name="screenoff_pause">Pausing connection in screen off state: less than %1$s in %2$ss</string>
- <string name="screen_nopersistenttun">ERROR: Persistent tun not enabled for this VPN. Ignoring option to pause VPN when screen is off</string>
+ <string name="screen_nopersistenttun">Warning: Persistent tun not enabled for this VPN. Traffic will use the normal Internet connection when the screen is off.</string>
</resources> \ No newline at end of file
diff --git a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java
index 11096f48..479860bc 100644
--- a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java
+++ b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java
@@ -68,12 +68,12 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
if(windowtraffic < TRAFFIC_LIMIT) {
screen = connectState.DISCONNECTED;
- OpenVPN.logInfo(R.string.screenoff_pause,
+ OpenVPN.logInfo(R.string.screenoff_pause,
OpenVpnService.humanReadableByteCount(TRAFFIC_LIMIT, false), TRAFFIC_WINDOW);
mManangement.pause();
}
Log.i("OpenVPN", String.format("State: %s %s total %d last %d time %d",network.name(), screen.name(),windowtraffic/1024,
- total,
+ total,
System.currentTimeMillis()/1024));
}
@@ -88,25 +88,26 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
@Override
public void onReceive(Context context, Intent intent) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
-
-
- if(ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
- networkStateChange(context);
- } else if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
- boolean screenoff = prefs.getBoolean("screenoff", false);
-
- if(screenoff && ! ProfileManager.getLastConnectedVpn().mPersistTun) {
- OpenVPN.logError(R.string.screen_nopersistenttun);
- } else if(screenoff) {
- screen = connectState.PENDINGDISCONNECT;
- fillTrafficData();
- if (network == connectState.DISCONNECTED)
- screen = connectState.DISCONNECTED;
- }
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+
+
+ if(ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
+ networkStateChange(context);
+ } else if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
+ boolean screenoff = prefs.getBoolean("screenoff", false);
+
+ if(screenoff)
+ if(!ProfileManager.getLastConnectedVpn().mPersistTun)
+ OpenVPN.logError(R.string.screen_nopersistenttun);
+
+ screen = connectState.PENDINGDISCONNECT;
+ fillTrafficData();
+ if (network == connectState.DISCONNECTED)
+ screen = connectState.DISCONNECTED;
+ }
} else if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())) {
- // Network was disabled because screen off
+ // Network was disabled because screen off
if (screen == connectState.DISCONNECTED && network == connectState.SHOULDBECONNECTED) {
mManangement.resume();
@@ -123,7 +124,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
public void networkStateChange(Context context) {
NetworkInfo networkInfo = getCurrentNetworkInfo(context);
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean sendusr1 = prefs.getBoolean("netchangereconnect", true);
@@ -132,7 +133,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
netstatestring = "not connected";
else {
String subtype = networkInfo.getSubtypeName();
- if(subtype==null)
+ if(subtype==null)
subtype = "";
String extrainfo = networkInfo.getExtraInfo();
if(extrainfo==null)
@@ -140,7 +141,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
/*
if(networkInfo.getType()==android.net.ConnectivityManager.TYPE_WIFI) {
- WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+ WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiinfo = wifiMgr.getConnectionInfo();
extrainfo+=wifiinfo.getBSSID();