diff options
author | Parménides GV <parmegv@sdf.org> | 2014-08-05 19:43:48 +0200 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2014-08-05 19:43:48 +0200 |
commit | acf580fe5b5173beced3a06c6644a453899aea62 (patch) | |
tree | aa3a394f4d71e633c977f3fd77f4f90c43c1dce6 /app | |
parent | 092fa788ca1a6cde091feb24828e3bd28e147bfc (diff) |
Restored notification only when it's alone.
Diffstat (limited to 'app')
-rw-r--r-- | app/jni/Android.mk | 4 | ||||
-rw-r--r-- | app/src/main/java/de/blinkt/openvpn/core/OpenVpnService.java | 53 | ||||
-rw-r--r-- | app/src/main/res/values/untranslatable.xml | 76 |
3 files changed, 130 insertions, 3 deletions
diff --git a/app/jni/Android.mk b/app/jni/Android.mk index 0c906f97..33d0bc76 100644 --- a/app/jni/Android.mk +++ b/app/jni/Android.mk @@ -5,7 +5,7 @@ JNI_DIR := $(call my-dir) #WITH_POLAR=1 #WITH_OPENVPN3=1 # Build openvpn with polar (OpenVPN3 core is always build with polar) -WITH_BREAKPAD=0 +#WITH_BREAKPAD=0 include lzo/Android.mk @@ -13,7 +13,7 @@ include snappy/Android.mk include openssl/Android.mk -ifneq ($(WITH_BREAKPAD),0) +ifneq ($(USE_BREAKPAD),0) ifneq ($(TARGET_ARCH),mips) WITH_BREAKPAD=1 include google-breakpad/android/google_breakpad/Android.mk diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVpnService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVpnService.java index 9d61247a..c9fe3739 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/OpenVpnService.java +++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVpnService.java @@ -127,6 +127,46 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac } } + private void showNotification(String msg, String tickerText, boolean lowpriority, long when, ConnectionStatus status) { + String ns = Context.NOTIFICATION_SERVICE; + NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); + + + int icon = getIconByConnectionStatus(status); + + android.app.Notification.Builder nbuilder = new Notification.Builder(this); + + if (mProfile != null) + nbuilder.setContentTitle(getString(R.string.notifcation_title, mProfile.mName)); + else + nbuilder.setContentTitle(getString(R.string.notifcation_title_notconnect)); + + nbuilder.setContentText(msg); + nbuilder.setOnlyAlertOnce(true); + nbuilder.setOngoing(true); + nbuilder.setContentIntent(getLogPendingIntent()); + nbuilder.setSmallIcon(icon); + + + if (when != 0) + nbuilder.setWhen(when); + + + // Try to set the priority available since API 16 (Jellybean) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) + jbNotificationExtras(lowpriority, nbuilder); + + if (tickerText != null && !tickerText.equals("")) + nbuilder.setTicker(tickerText); + + @SuppressWarnings("deprecation") + Notification notification = nbuilder.getNotification(); + + + mNotificationManager.notify(OPENVPN_STATUS, notification); + // startForeground(OPENVPN_STATUS, notification); + } + private int getIconByConnectionStatus(ConnectionStatus level) { switch (level) { case LEVEL_CONNECTED: @@ -277,6 +317,12 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac mProfile = ProfileManager.get(this, profileUUID); + + 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, LEVEL_CONNECTING_NO_SERVER_REPLY_YET); + // Set a flag that we are starting a new VPN mStarting = true; // Stop the previous session by interrupting the thread. @@ -653,9 +699,14 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac } else if (level == LEVEL_CONNECTED) { mDisplayBytecount = true; mConnecttime = System.currentTimeMillis(); - lowpriority = true; + lowpriority = true; + NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.cancel(OPENVPN_STATUS); } else { mDisplayBytecount = false; + String msg = getString(resid); + String ticker = msg; + showNotification(msg + " " + logmessage, ticker, lowpriority , 0, level); } } diff --git a/app/src/main/res/values/untranslatable.xml b/app/src/main/res/values/untranslatable.xml index e667a808..1a3aa112 100644 --- a/app/src/main/res/values/untranslatable.xml +++ b/app/src/main/res/values/untranslatable.xml @@ -969,4 +969,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + </resources>
\ No newline at end of file |