summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-06-08 17:32:17 +0200
committerArne Schwabe <arne@rfc2549.org>2013-06-08 17:32:17 +0200
commit692875b3b3afa7408714ccb31ef73099757dc1ee (patch)
tree9ec2f522b58109d8793a9f8ad1ec1bf5420e094a
parent00d4add3e1ff720c33183d6f575d44a655a5bea8 (diff)
Fix icon displayed in the notification bar. Using a Leveldrawable does not work as expected.
-rw-r--r--res/drawable/ic_notification_icon.xml14
-rwxr-xr-xres/values-fr/strings.xml2
-rw-r--r--src/de/blinkt/openvpn/core/OpenVPN.java24
-rw-r--r--src/de/blinkt/openvpn/core/OpenVpnService.java40
4 files changed, 45 insertions, 35 deletions
diff --git a/res/drawable/ic_notification_icon.xml b/res/drawable/ic_notification_icon.xml
deleted file mode 100644
index 0bdb5f57..00000000
--- a/res/drawable/ic_notification_icon.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<level-list xmlns:android="http://schemas.android.com/apk/res/android">
- <!-- connected -->
- <item android:maxLevel="0" android:drawable="@drawable/ic_stat_vpn" />
- <!-- connecting, server reply -->
- <item android:maxLevel="1" android:drawable="@drawable/ic_stat_vpn_empty_halo" />
- <!-- connecting, no server rply yet -->
- <item android:maxLevel="2" android:drawable="@drawable/ic_stat_vpn_outline" />
- <!-- 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_empty_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/values-fr/strings.xml b/res/values-fr/strings.xml
index 1dd4cfb9..4f81351f 100755
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -148,7 +148,7 @@
<string name="converted_profile">"profil importé"</string>
<string name="converted_profile_i">"profil importé: %d"</string>
<string name="broken_images">"Images corrompues "</string>
- <string name="broken_images_faq">&lt;&gt;Les ROMs officielles HTC sont connues pour avoir des problèmes de routage entraînant que le trafic ne passe pas par le tunnel VPN. (C.f.: &lt;a href=\"http://code.google.com/p/ics-openvpn/issues/detail?id=18\"&gt;Issue 18&lt;/a&gt; dans le \"bug tacker\")&lt;/p&gt;&lt;p&&gt;Les ROMs officielles de SONY pour le Xperia Arc S et le Xperia Ray ont été signalé comme ne possédant pas le service VPN. Toute autre ROM SONY peut avoir le même problème. (C.f.: &lt;a href=\"http://code.google.com/p/ics-openvpn/issues/detail?id=29\"&gt;Issue 29&lt;/a&gt; dans le \"bug tacker\")&lt;/p&gt;&lt;p&gt;Sur les ROM personnalisées le module TUN peut être manquant ou les droits de /dev/tun peuvent être incorrects. Certaines ROM CM9 peuvent nécessiter d\'utiliser l\'option de correction des droits de /dev/tun accessible depuis les \"Options générales\"/&lt;/p&gt;&lt;p&gt;Important: Si votre ROM a un problème, contactez le vendeur, il se peut que qu\'il vous fournisse un patch.&lt;/p&gt;</string>
+ <string name="broken_images_faq">&lt;&gt;Les ROMs officielles HTC sont connues pour avoir des problèmes de routage entraînant que le trafic ne passe pas par le tunnel VPN. (C.f.: &lt;a href=\"http://code.google.com/p/ics-openvpn/issues/detail?id=18\"&gt;Issue 18&lt;/a&gt; dans le \"bug tacker\")&lt;/p&gt;&lt;p&gt;Les ROMs officielles de SONY pour le Xperia Arc S et le Xperia Ray ont été signalé comme ne possédant pas le service VPN. Toute autre ROM SONY peut avoir le même problème. (C.f.: &lt;a href=\"http://code.google.com/p/ics-openvpn/issues/detail?id=29\"&gt;Issue 29&lt;/a&gt; dans le \"bug tacker\")&lt;/p&gt;&lt;p&gt;Sur les ROM personnalisées le module TUN peut être manquant ou les droits de /dev/tun peuvent être incorrects. Certaines ROM CM9 peuvent nécessiter d\'utiliser l\'option de correction des droits de /dev/tun accessible depuis les \"Options générales\"/&lt;/p&gt;&lt;p&gt;Important: Si votre ROM a un problème, contactez le vendeur, il se peut que qu\'il vous fournisse un patch.&lt;/p&gt;</string>
<string name="pkcs12_file_encryption_key">"Fichier de clé de cryptage PKCS12"</string>
<string name="private_key_password">"Mot de passe de clé privée"</string>
<string name="password">"Mot de passe"</string>
diff --git a/src/de/blinkt/openvpn/core/OpenVPN.java b/src/de/blinkt/openvpn/core/OpenVPN.java
index 982a1e62..450a13ea 100644
--- a/src/de/blinkt/openvpn/core/OpenVPN.java
+++ b/src/de/blinkt/openvpn/core/OpenVPN.java
@@ -1,16 +1,5 @@
package de.blinkt.openvpn.core;
-import java.io.ByteArrayInputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.Locale;
-import java.util.Vector;
-
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
@@ -22,6 +11,17 @@ import android.os.Parcel;
import android.os.Parcelable;
import de.blinkt.openvpn.R;
+import java.io.ByteArrayInputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.Locale;
+import java.util.Vector;
+
public class OpenVPN {
@@ -50,7 +50,7 @@ public class OpenVPN {
LEVEL_CONNECTING_NO_SERVER_REPLY_YET (2),
LEVEL_CONNECTED (0), UNKNOWN_LEVEL(-1);
- public final int level;
+ private final int level;
ConnectionStatus(int level){
this.level = level;
diff --git a/src/de/blinkt/openvpn/core/OpenVpnService.java b/src/de/blinkt/openvpn/core/OpenVpnService.java
index 6563fa0f..853389fd 100644
--- a/src/de/blinkt/openvpn/core/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/core/OpenVpnService.java
@@ -27,6 +27,8 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Vector;
+import static de.blinkt.openvpn.core.OpenVPN.ConnectionStatus.*;
+
public class OpenVpnService extends VpnService implements StateListener, Callback, ByteCountListener {
public static final String START_SERVICE = "de.blinkt.openvpn.START_SERVICE";
public static final String START_SERVICE_STICKY = "de.blinkt.openvpn.START_SERVICE_STICKY";
@@ -115,7 +117,8 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
- int icon = R.drawable.ic_notification_icon;
+ int icon = getIconByLevel(level);
+
android.app.Notification.Builder nbuilder = new Notification.Builder(this);
if(mProfile!=null)
@@ -127,7 +130,8 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
nbuilder.setOnlyAlertOnce(true);
nbuilder.setOngoing(true);
nbuilder.setContentIntent(getLogPendingIntent());
- nbuilder.setSmallIcon(icon,level.level);
+ nbuilder.setSmallIcon(icon);
+
if(when !=0)
nbuilder.setWhen(when);
@@ -145,8 +149,28 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
startForeground(OPENVPN_STATUS, notification);
}
-
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+ private int getIconByLevel(ConnectionStatus level) {
+ switch (level) {
+ case LEVEL_CONNECTED:
+ case UNKNOWN_LEVEL:
+ return R.drawable.ic_stat_vpn;
+ case LEVEL_AUTH_FAILED:
+ case LEVEL_NONETWORK:
+ case LEVEL_NOTCONNECTED:
+ return R.drawable.ic_stat_vpn_offline;
+ case LEVEL_CONNECTING_NO_SERVER_REPLY_YET:
+ case LEVEL_WAITING_FOR_USER_INPUT:
+ return R.drawable.ic_stat_vpn_outline;
+ case LEVEL_CONNECTING_SERVER_REPLIED:
+ return R.drawable.ic_stat_vpn_empty_halo;
+ default:
+ return R.drawable.ic_stat_vpn;
+
+ }
+ }
+
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void jbNotificationExtras(boolean lowpriority,
android.app.Notification.Builder nbuilder) {
try {
@@ -268,7 +292,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
String startTitle = getString(R.string.start_vpn_title, mProfile.mName);
String startTicker = getString(R.string.start_vpn_ticker, mProfile.mName);
showNotification(startTitle, startTicker,
- false,0,ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET);
+ false,0, LEVEL_CONNECTING_NO_SERVER_REPLY_YET);
// Set a flag that we are starting a new VPN
mStarting=true;
@@ -542,11 +566,11 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
// Display byte count only after being connected
{
- if (level == ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT) {
+ if (level == LEVEL_WAITING_FOR_USER_INPUT) {
// The user is presented a dialog of some kind, no need to inform the user
// with a notifcation
return;
- } else if(level == ConnectionStatus.LEVEL_CONNECTED) {
+ } else if(level == LEVEL_CONNECTED) {
mDisplayBytecount = true;
mConnecttime = System.currentTimeMillis();
} else {
@@ -580,7 +604,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
humanReadableByteCount(diffout/OpenVPNMangement.mBytecountinterval, true));
boolean lowpriority = !mNotificationalwaysVisible;
- showNotification(netstat,null,lowpriority,mConnecttime, ConnectionStatus.LEVEL_CONNECTED);
+ showNotification(netstat,null,lowpriority,mConnecttime, LEVEL_CONNECTED);
}
}