summaryrefslogtreecommitdiff
path: root/src/se/leap/openvpn/OpenVpnService.java
diff options
context:
space:
mode:
authorSean Leonard <meanderingcode@aetherislands.net>2013-07-10 11:10:10 -0600
committerSean Leonard <meanderingcode@aetherislands.net>2013-07-19 15:09:14 -0600
commitc3a9d580a8428809aa001129ce78c93ed3ee72a8 (patch)
treee2e670b343448ba45b88eedafd5c0df98a6b1382 /src/se/leap/openvpn/OpenVpnService.java
parentc7f73c9ef8f64351d4e462106a2ab5d216810684 (diff)
Show notification while VPN connection in progress and when VPN connection lost
Diffstat (limited to 'src/se/leap/openvpn/OpenVpnService.java')
-rw-r--r--src/se/leap/openvpn/OpenVpnService.java28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/se/leap/openvpn/OpenVpnService.java b/src/se/leap/openvpn/OpenVpnService.java
index 08a5d62e..b5653d4d 100644
--- a/src/se/leap/openvpn/OpenVpnService.java
+++ b/src/se/leap/openvpn/OpenVpnService.java
@@ -67,6 +67,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
private int mMtu;
private String mLocalIPv6=null;
private NetworkSateReceiver mNetworkStateReceiver;
+ private NotificationManager mNotificationManager;
private boolean mDisplayBytecount=false;
@@ -118,9 +119,9 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
}
}
- private void showNotification(String msg, String tickerText, boolean lowpriority, long when) {
+ private void showNotification(String msg, String tickerText, boolean lowpriority, long when, boolean persistant) {
String ns = Context.NOTIFICATION_SERVICE;
- NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
+ mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_stat_vpn;
@@ -129,7 +130,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
nbuilder.setContentTitle(getString(R.string.notifcation_title,mProfile.mName));
nbuilder.setContentText(msg);
nbuilder.setOnlyAlertOnce(true);
- nbuilder.setOngoing(true);
+ nbuilder.setOngoing(persistant);
nbuilder.setContentIntent(getLogPendingIntent());
nbuilder.setSmallIcon(icon);
if(when !=0)
@@ -146,7 +147,6 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
mNotificationManager.notify(OPENVPN_STATUS, notification);
- startForeground(OPENVPN_STATUS, notification);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@@ -483,26 +483,16 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
if(mProcessThread==null)
return;
- // Display byte count only after being connected
-
- if("BYTECOUNT".equals(state)) {
- if(mDisplayBytecount) {
- //showNotification(logmessage,null,true,mConnecttime);
- }
- } else {
- if("CONNECTED".equals(state)) {
- mDisplayBytecount = true;
- mConnecttime = System.currentTimeMillis();
- } else {
- mDisplayBytecount = false;
- }
+ if("CONNECTED".equals(state)) {
+ mNotificationManager.cancel(OPENVPN_STATUS);
+ } else if(!"BYTECOUNT".equals(state)) {
// Other notifications are shown,
// This also mean we are no longer connected, ignore bytecount messages until next
// CONNECTED
String ticker = getString(resid);
- //showNotification(getString(resid) +" " + logmessage,ticker,false,0);
-
+ boolean persist = ("NOPROCESS".equals(state)) ? false : true;
+ showNotification(getString(resid) +" " + logmessage,ticker,false,0,persist);
}
}