summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-02-10 21:55:46 +0100
committerArne Schwabe <arne@rfc2549.org>2013-02-10 21:55:46 +0100
commit2a9f7fcdb1ddf8c2ee39ed87334bf0bc58955808 (patch)
treef39f5812032d316e6530a1b143758088a39e7fbd
parentdad578cff15e77be2f7e1ce6ff2b8dad4753da4d (diff)
Use different icons in the status bar depending on status.
-rw-r--r--res/drawable/ic_notification_icon.xml13
-rw-r--r--res/drawable/notification_icon.xml20
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java2
-rw-r--r--src/de/blinkt/openvpn/OpenVPN.java53
-rw-r--r--src/de/blinkt/openvpn/OpenVPNThread.java2
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java4
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java31
7 files changed, 73 insertions, 52 deletions
diff --git a/res/drawable/ic_notification_icon.xml b/res/drawable/ic_notification_icon.xml
index db5e6e0f..852da869 100644
--- a/res/drawable/ic_notification_icon.xml
+++ b/res/drawable/ic_notification_icon.xml
@@ -1,5 +1,14 @@
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- connected -->
<item android:maxLevel="0" android:drawable="@drawable/ic_stat_vpn" />
- <item android:maxLevel="1" android:drawable="@drawable/ic_stat_vpn" />
- <item android:maxLevel="2" android:drawable="@drawable/ic_stat_vpn" />
+ <!-- connecting, server reply -->
+ <item android:maxLevel="1" android:drawable="@drawable/ic_stat_vpn_more_halo" />
+ <!-- connecting, no server rply yet -->
+ <item android:maxLevel="2" android:drawable="@drawable/ic_stat_vpn_minimal_halo" />
+ <!-- no useable network -->
+ <item android:maxLevel="3" android:drawable="@drawable/ic_stat_vpn_offline" />
+ <!-- Authentication failed -->
+ <item android:maxLevel="4" android:drawable="@drawable/ic_stat_vpn_more_halo" />
+ <!-- client not running, not used -->
+ <item android:maxLevel="5" android:drawable="@drawable/ic_stat_vpn_offline" />
</level-list> \ No newline at end of file
diff --git a/res/drawable/notification_icon.xml b/res/drawable/notification_icon.xml
deleted file mode 100644
index 6968e806..00000000
--- a/res/drawable/notification_icon.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<!--
- <string name="state_auth">Authenticating</string>
- <string name="state_get_config">Getting client configuration</string>
- <string name="state_assign_ip">Assigning IP addresses</string>
- <string name="state_add_routes">Adding routes</string>
- <string name="state_connected">Connected</string>
- <string name="state_reconnecting">Reconnecting</string>
- <string name="state_exiting">Exiting</string>
- <string name="state_noprocess">Not running</string>
- <string name="state_resolve">Resolving host names</string>
- <string name="state_tcp_connect">Connecting (TCP)</string>
- <string name="state_auth_failed">Authentication failed</string>
- <string name="state_nonetwork">Waiting for usable network</string>
- -->
-
- <level-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:maxLevel="0" android:drawable="@drawable/ic_stat_vpn" />
- <item android:maxLevel="1" android:drawable="@drawable/ic_stat_vpn" />
- <item android:maxLevel="2" android:drawable="@drawable/ic_stat_vpn" />
- </level-list> \ No newline at end of file
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index ef29ad5e..4e153357 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -392,7 +392,7 @@ public class LogWindow extends ListActivity implements StateListener {
}
@Override
- public void updateState(final String status,final String logmessage, final int resid) {
+ public void updateState(final String status,final String logmessage, final int resid, final int level) {
runOnUiThread(new Runnable() {
@Override
diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java
index 03db7677..607f87e3 100644
--- a/src/de/blinkt/openvpn/OpenVPN.java
+++ b/src/de/blinkt/openvpn/OpenVPN.java
@@ -28,6 +28,18 @@ public class OpenVPN {
private static long mlastByteCount[]={0,0,0,0};
+
+
+
+ static final int LEVEL_NONETWORK = 3;
+ static final int LEVEL_NOTCONNECTED = 4;
+ public static final int LEVEL_AUTH_FAILED = 5;
+ static final int LEVEL_CONNECTING_SERVER_REPLIED = 1;
+ static final int LEVEL_CONNECTING_NO_SERVER_REPLY_YET = 2;
+ static final int LEVEL_CONNECTED = 0;
+
+ private static int mLastLevel=LEVEL_NOTCONNECTED;
+
static {
logbuffer = new LinkedList<LogItem>();
logListener = new Vector<OpenVPN.LogListener>();
@@ -145,7 +157,7 @@ public class OpenVPN {
}
public interface StateListener {
- void updateState(String state, String logmessage, int localizedResId);
+ void updateState(String state, String logmessage, int localizedResId, int level);
}
public interface ByteCountListener {
@@ -190,7 +202,7 @@ public class OpenVPN {
if(!stateListener.contains(sl)){
stateListener.add(sl);
if(mLaststate!=null)
- sl.updateState(mLaststate, mLaststatemsg, mLastStateresid);
+ sl.updateState(mLaststate, mLaststatemsg, mLastStateresid, mLastLevel);
}
}
@@ -224,6 +236,35 @@ public class OpenVPN {
}
+ private static int getLevel(String state){
+ String[] noreplyet = {"CONNECTING","WAIT", "RECONNECTING", "RESOLVE", "TCP_CONNECT"};
+ String[] reply = {"AUTH","GETCONFIG","ASSIGN_IP","ADD_ROUTES"};
+ String[] connected = {"CONNECTED"};
+ String[] notconnected = {"DISCONNECTED", "EXITING"};
+
+ for(String x:noreplyet)
+ if(state.equals(x))
+ return LEVEL_CONNECTING_NO_SERVER_REPLY_YET;
+
+ for(String x:reply)
+ if(state.equals(x))
+ return LEVEL_CONNECTING_SERVER_REPLIED;
+
+ for(String x:connected)
+ if(state.equals(x))
+ return LEVEL_CONNECTED;
+
+ for(String x:notconnected)
+ if(state.equals(x))
+ return LEVEL_NOTCONNECTED;
+
+ return -1;
+
+ }
+
+
+
+
public synchronized static void removeStateListener(StateListener sl) {
stateListener.remove(sl);
}
@@ -252,16 +293,18 @@ public class OpenVPN {
public static void updateStateString (String state, String msg) {
int rid = getLocalizedState(state);
- updateStateString(state, msg,rid);
+ int level = getLevel(state);
+ updateStateString(state, msg, rid, level);
}
- public synchronized static void updateStateString(String state, String msg, int resid) {
+ public synchronized static void updateStateString(String state, String msg, int resid, int level) {
mLaststate= state;
mLaststatemsg = msg;
mLastStateresid = resid;
+ mLastLevel = level;
for (StateListener sl : stateListener) {
- sl.updateState(state,msg,resid);
+ sl.updateState(state,msg,resid,level);
}
}
diff --git a/src/de/blinkt/openvpn/OpenVPNThread.java b/src/de/blinkt/openvpn/OpenVPNThread.java
index 1ef04f70..67878eb7 100644
--- a/src/de/blinkt/openvpn/OpenVPNThread.java
+++ b/src/de/blinkt/openvpn/OpenVPNThread.java
@@ -54,7 +54,7 @@ public class OpenVPNThread implements Runnable {
if( exitvalue != 0)
OpenVPN.logError("Process exited with exit value " + exitvalue);
- OpenVPN.updateStateString("NOPROCESS","No process running.", R.string.state_noprocess);
+ OpenVPN.updateStateString("NOPROCESS","No process running.", R.string.state_noprocess,OpenVPN.LEVEL_NOTCONNECTED);
if(mDumpPath!=null) {
try {
BufferedWriter logout = new BufferedWriter(new FileWriter(mDumpPath + ".log"));
diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
index e4528132..5cd70987 100644
--- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
@@ -208,7 +208,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNMangement {
releaseHoldCmd();
} else {
mWaitingForRelease=true;
- OpenVPN.updateStateString("NONETWORK", "",R.string.state_nonetwork);
+ OpenVPN.updateStateString("NONETWORK", "",R.string.state_nonetwork,OpenVPN.LEVEL_NONETWORK);
}
}
private void releaseHoldCmd() {
@@ -423,7 +423,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNMangement {
private void proccessPWFailed(String needed, String args) {
- OpenVPN.updateStateString("AUTH_FAILED", needed + args,R.string.state_auth_failed);
+ OpenVPN.updateStateString("AUTH_FAILED", needed + args,R.string.state_auth_failed,OpenVPN.LEVEL_AUTH_FAILED);
}
private void logStatusMessage(String command) {
OpenVPN.logMessage(0,"MGMT:", command);
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index 881eda9d..7e1eebd3 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -77,11 +77,6 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
public static final int PROTECT_FD = 0;
-
- private static final int LEVEL_OFFLINE = 0;
- private static final int LEVEL_NOTCONNECTED = 1;
- private static final int LEVEL_CONNECTED = 2;
-
private static boolean mNotificationalwaysVisible=false;
private final IBinder mBinder = new LocalBinder();
@@ -136,7 +131,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
- int icon = R.drawable.notification_icon;
+ int icon = R.drawable.ic_notification_icon;
android.app.Notification.Builder nbuilder = new Notification.Builder(this);
if(mProfile!=null)
@@ -248,8 +243,8 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
this.unregisterReceiver(mNetworkStateReceiver);
mNetworkStateReceiver=null;
}
-
-
+
+
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
@@ -274,7 +269,8 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
mProfile = ProfileManager.get(profileUUID);
- showNotification("Starting VPN " + mProfile.mName,"Starting VPN " + mProfile.mName, false,0,LEVEL_NOTCONNECTED);
+ showNotification("Starting VPN " + mProfile.mName,"Starting VPN " + mProfile.mName,
+ false,0,OpenVPN.LEVEL_CONNECTING_NO_SERVER_REPLY_YET);
// Set a flag that we are starting a new VPN
mStarting=true;
@@ -320,11 +316,11 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
Runnable processThread;
if(mOvpn3) {
-
+
OpenVPNMangement mOpenVPN3 = instantiateOpenVPN3Core();
processThread = (Runnable) mOpenVPN3;
mManagement = mOpenVPN3;
-
+
} else {
processThread = new OpenVPNThread(this, argv,nativelibdir);
@@ -556,7 +552,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
}
@Override
- public void updateState(String state,String logmessage, int resid) {
+ public void updateState(String state,String logmessage, int resid, int level) {
// If the process is not running, ignore any state,
// Notification should be invisible in this state
if(mProcessThread==null && !mNotificationalwaysVisible)
@@ -565,17 +561,10 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
// Display byte count only after being connected
{
- int level;
- if("CONNECTED".equals(state)) {
+ if(level == OpenVPN.LEVEL_CONNECTED) {
mDisplayBytecount = true;
mConnecttime = System.currentTimeMillis();
- level = LEVEL_CONNECTED;
} else {
- if ("NONETWORK".equals(state)) {
- level = LEVEL_OFFLINE;
- } else {
- level = LEVEL_NOTCONNECTED;
- }
mDisplayBytecount = false;
}
@@ -598,7 +587,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
humanReadableByteCount(diffout, false));
boolean lowpriority = !mNotificationalwaysVisible;
- showNotification(netstat,null,lowpriority,mConnecttime, LEVEL_CONNECTED);
+ showNotification(netstat,null,lowpriority,mConnecttime, OpenVPN.LEVEL_CONNECTED);
}
}