summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-08-28 01:14:05 +0200
committerArne Schwabe <arne@rfc2549.org>2012-08-28 01:14:05 +0200
commit4483c357fee4688a1604dd1cbf5b6262bbbf4e75 (patch)
tree4e915eba8ca868e148f062690e72d9b413e20c1d /src/de/blinkt/openvpn
parentc6526d53d31c7520c7c6ad575e0f61a40663ab4f (diff)
- Add status message when waiting for network.
- Using a priority higher than PRIORITY_MIN stop the flickering of the notification but make the icon visible again :/
Diffstat (limited to 'src/de/blinkt/openvpn')
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java2
-rw-r--r--src/de/blinkt/openvpn/OpenVPN.java11
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java21
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java28
4 files changed, 37 insertions, 25 deletions
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index 94425fa8..ecadd85c 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -251,7 +251,7 @@ public class LogWindow extends ListActivity implements StateListener {
@Override
protected void onResume() {
super.onResume();
- OpenVPN.addSpeedListener(this);
+ OpenVPN.addStateListener(this);
}
@Override
diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java
index db980200..6b65c22e 100644
--- a/src/de/blinkt/openvpn/OpenVPN.java
+++ b/src/de/blinkt/openvpn/OpenVPN.java
@@ -14,6 +14,10 @@ public class OpenVPN {
private static Vector<LogListener> logListener;
private static Vector<StateListener> stateListener;
private static String[] mBconfig;
+
+ private static String mLaststatemsg;
+
+ private static String mLaststate;
static {
logbuffer = new LinkedList<LogItem>();
@@ -117,8 +121,10 @@ public class OpenVPN {
}
- synchronized static void addSpeedListener(StateListener sl){
+ synchronized static void addStateListener(StateListener sl){
stateListener.add(sl);
+ if(mLaststate!=null)
+ sl.updateState(mLaststate, mLaststatemsg);
}
synchronized static void removeSpeedListener(StateListener sl) {
@@ -148,6 +154,9 @@ public class OpenVPN {
}
public synchronized static void updateStateString(String state, String msg) {
+ mLaststate= state;
+ mLaststatemsg = msg;
+
for (StateListener sl : stateListener) {
sl.updateState(state,msg);
}
diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
index d593832a..22da0241 100644
--- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
@@ -37,7 +37,6 @@ public class OpenVpnManagementThread implements Runnable {
private int mBytecountinterval=2;
private long mLastIn=0;
private long mLastOut=0;
- private String mCurrentstate;
private LocalServerSocket mServerSocket;
private boolean mReleaseHold=true;
private boolean mWaitingForRelease=false;
@@ -185,10 +184,7 @@ public class OpenVpnManagementThread implements Runnable {
}else if (cmd.equals("PASSWORD")) {
processPWCommand(argument);
} else if (cmd.equals("HOLD")) {
- if(mReleaseHold)
- releaseHoldCmd();
- else
- mWaitingForRelease=true;
+ handleHold();
} else if (cmd.equals("NEED-OK")) {
processNeedCommand(argument);
} else if (cmd.equals("BYTECOUNT")){
@@ -216,6 +212,14 @@ public class OpenVpnManagementThread implements Runnable {
OpenVPN.logMessage(0, "MGMT:", "Got unrecognized line from management:" + command);
}
}
+ private void handleHold() {
+ if(mReleaseHold) {
+ releaseHoldCmd();
+ } else {
+ mWaitingForRelease=true;
+ OpenVPN.updateStateString("NONETWORK", "Waiting for usable network");
+ }
+ }
private void releaseHoldCmd() {
mWaitingForRelease=false;
managmentCommand("hold release\n");
@@ -256,8 +260,11 @@ public class OpenVpnManagementThread implements Runnable {
}
private void processState(String argument) {
String[] args = argument.split(",",3);
- mCurrentstate = args[1];
- OpenVPN.updateStateString(mCurrentstate,args[2]);
+ String currentstate = args[1];
+ if(args[2].equals(",,"))
+ OpenVPN.updateStateString(currentstate,"");
+ else
+ OpenVPN.updateStateString(currentstate,args[2]);
}
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index 41d5b1ee..c1fd1710 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -83,7 +83,7 @@ public class OpenVpnService extends VpnService implements StateListener {
}
}
- private Notification showNotification(String msg, String tickerText, boolean lowpriority) {
+ private void showNotification(String msg, String tickerText, boolean lowpriority) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
@@ -98,12 +98,13 @@ public class OpenVpnService extends VpnService implements StateListener {
nbuilder.setContentIntent(getLogPendingIntent());
nbuilder.setSmallIcon(icon);
+
// Try to set the priority available since API 16 (Jellybean)
- if(lowpriority) {
+ if( lowpriority) {
try {
Method setpriority = nbuilder.getClass().getMethod("setPriority", int.class);
// PRIORITY_MIN == -2
- setpriority.invoke(nbuilder, -2 );
+ setpriority.invoke(nbuilder, -1 );
//ignore exception
} catch (NoSuchMethodException nsm) {
@@ -118,13 +119,8 @@ public class OpenVpnService extends VpnService implements StateListener {
Notification notification = nbuilder.getNotification();
-
-
-
mNotificationManager.notify(OPENVPN_STATUS, notification);
startForeground(OPENVPN_STATUS, notification);
- return notification;
-
}
PendingIntent getLogPendingIntent() {
@@ -189,7 +185,7 @@ public class OpenVpnService extends VpnService implements StateListener {
showNotification("Starting VPN " + mProfile.mName,"Starting VPN " + mProfile.mName, false);
- OpenVPN.addSpeedListener(this);
+ OpenVPN.addStateListener(this);
// Set a flag that we are starting a new VPN
mStarting=true;
@@ -425,22 +421,22 @@ public class OpenVpnService extends VpnService implements StateListener {
// Display byte count only after being connected
- if("CONNECTED".equals(state)) {
- mDisplayBytecount = true;
- } else if("BYTECOUNT".equals(state)) {
+ if("BYTECOUNT".equals(state)) {
if(mDisplayBytecount) {
showNotification(logmessage,null,true);
}
} else {
+ if("CONNECTED".equals(state))
+ mDisplayBytecount = true;
+ else
+ mDisplayBytecount = false;
+
// Other notifications are shown,
// This also mean we are no longer connected, ignore bytecount messages until next
// CONNECTED
String ticker = state.toLowerCase();
showNotification(state +" " + logmessage,ticker,false);
- mDisplayBytecount=false;
+
}
}
-
-
-
}