]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Add notification channel for API level 26+
authorTobias Brunner <tobias@strongswan.org>
Wed, 6 Jun 2018 16:55:45 +0000 (18:55 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 Jul 2018 09:31:33 +0000 (11:31 +0200)
Unfortunately, setLockscreenVisibility() doesn't seem to have any
effect. So the full notification is shown unless the user manually
configures the notification settings.

src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java
src/frontends/android/app/src/main/res/values-de/strings.xml
src/frontends/android/app/src/main/res/values-pl/strings.xml
src/frontends/android/app/src/main/res/values-ru/strings.xml
src/frontends/android/app/src/main/res/values-ua/strings.xml
src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml
src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml
src/frontends/android/app/src/main/res/values/strings.xml

index b6e7e2d644dff3a897c2ce54ee482b5125ae3b24..d573d882d131abc0acb55221cd2a0bafa7b1d373 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2017 Tobias Brunner
+ * Copyright (C) 2012-2018 Tobias Brunner
  * Copyright (C) 2012 Giuliano Grassi
  * Copyright (C) 2012 Ralf Sager
  * HSR Hochschule fuer Technik Rapperswil
@@ -19,6 +19,7 @@ package org.strongswan.android.logic;
 
 import android.annotation.TargetApi;
 import android.app.Notification;
+import android.app.NotificationChannel;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.Service;
@@ -70,6 +71,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
 {
        private static final String TAG = CharonVpnService.class.getSimpleName();
        public static final String DISCONNECT_ACTION = "org.strongswan.android.CharonVpnService.DISCONNECT";
+       private static final String NOTIFICATION_CHANNEL = "org.strongswan.android.CharonVpnService.VPN_STATE_NOTIFICATION";
        public static final String LOG_FILE = "charon.log";
        public static final int VPN_STATE_NOTIFICATION_ID = 1;
 
@@ -162,6 +164,8 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
                /* the thread is started when the service is bound */
                bindService(new Intent(this, VpnStateService.class),
                                        mServiceConnection, Service.BIND_AUTO_CREATE);
+
+               createNotificationChannel();
        }
 
        @Override
@@ -321,6 +325,25 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
                stopForeground(true);
        }
 
+       /**
+        * Create a notification channel for Android 8+
+        */
+       private void createNotificationChannel()
+       {
+               if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+               {
+                       NotificationChannel channel;
+                       channel = new NotificationChannel(NOTIFICATION_CHANNEL, getString(R.string.permanent_notification_name),
+                                                                                         NotificationManager.IMPORTANCE_LOW);
+                       channel.setDescription(getString(R.string.permanent_notification_description));
+                       channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
+                       channel.setShowBadge(false);
+                       NotificationManager notificationManager = getSystemService(NotificationManager.class);
+                       notificationManager.createNotificationChannel(channel);
+               }
+       }
+
+
        /**
         * Build a notification matching the current state
         */
@@ -336,7 +359,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
                {
                        name = profile.getName();
                }
-               android.support.v4.app.NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
+               NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL)
                                .setSmallIcon(R.drawable.ic_notification)
                                .setCategory(NotificationCompat.CATEGORY_SERVICE)
                                .setVisibility(publicVersion ? NotificationCompat.VISIBILITY_PUBLIC
index 896e53608ff4f70504a1d36607a7b7b8cfd52e26..975686e563e70ba77a7e7aeffc49e315e75269a4 100644 (file)
@@ -29,6 +29,8 @@
     <string name="loading">Laden&#8230;</string>
     <string name="profile_not_found">Profil nicht gefunden</string>
     <string name="strongswan_shortcut">strongSwan-Verknüpfung</string>
+    <string name="permanent_notification_name">VPN Verbindungsstatus</string>
+    <string name="permanent_notification_description">Zeigt Informationen zum Verbindungsstatus der VPN Verbindung und dient als permanente Notification dazu, den VPN Dienst im Hintergrund am Laufen zu halten.</string>
 
     <!-- Log view -->
     <string name="log_title">Log</string>
index ce1dc6741b199b8e0f08d09467ee188841cbdf16..835efd531a1f04f555e94514d80e212e6adf5413 100644 (file)
@@ -29,6 +29,8 @@
     <string name="loading">Wczytywanie&#8230;</string>
     <string name="profile_not_found">Nie znaleziono profilu</string>
     <string name="strongswan_shortcut">Skrót strongSwan</string>
+    <string name="permanent_notification_name">VPN connection state</string>
+    <string name="permanent_notification_description">Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background.</string>
 
     <!-- Log view -->
     <string name="log_title">Log</string>
index 756473b5649d94feee402c7f0f6667ab9d0e86b3..53e83757307d669a40911389320cc701bb46a57a 100644 (file)
@@ -26,6 +26,8 @@
     <string name="loading">Загрузка&#8230;</string>
     <string name="profile_not_found">Профиль не найден</string>
     <string name="strongswan_shortcut">Ссылка на strongSwan</string>
+    <string name="permanent_notification_name">VPN connection state</string>
+    <string name="permanent_notification_description">Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background.</string>
 
     <!-- Log view -->
     <string name="log_title">Журнал</string>
index 8c165734a383ce86fe8cc5ccdfe8b7a1ce8acb42..8e41daf91423f527272c14ae1b4ccc7b1daf3629 100644 (file)
@@ -27,6 +27,8 @@
     <string name="loading">Завантаження&#8230;</string>
     <string name="profile_not_found">Профіль не знайдено</string>
     <string name="strongswan_shortcut">strongSwan посилання</string>
+    <string name="permanent_notification_name">VPN connection state</string>
+    <string name="permanent_notification_description">Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background.</string>
 
     <!-- Log view -->
     <string name="log_title">Журнал</string>
index 2d195f638402555f781370f3f684c6dd565c0979..0cb6bd087a7ea3c30d65827a31e89a75aac33c20 100644 (file)
@@ -26,6 +26,8 @@
     <string name="loading">载入中&#8230;</string>
     <string name="profile_not_found">未找到配置</string>
     <string name="strongswan_shortcut">strongSwan快捷方式</string>
+    <string name="permanent_notification_name">VPN connection state</string>
+    <string name="permanent_notification_description">Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background.</string>
 
     <!-- Log view -->
     <string name="log_title">日志</string>
index 650cd6940d01467a54586ea86a26eaeb2cba079b..168fdd7dd39347732b88547a61ecb35a6e2c8e88 100644 (file)
@@ -26,6 +26,8 @@
     <string name="loading">載入中&#8230;</string>
     <string name="profile_not_found">沒有找到設定檔</string>
     <string name="strongswan_shortcut">strongSwan快速選單</string>
+    <string name="permanent_notification_name">VPN connection state</string>
+    <string name="permanent_notification_description">Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background.</string>
 
     <!-- Log view -->
     <string name="log_title">日誌</string>
index e6cb9dc4cdfb42dcdd93386e4053bed3d0922e91..13d718733353db3157472c7e3f11869aff083f5e 100644 (file)
@@ -29,6 +29,8 @@
     <string name="loading">Loading&#8230;</string>
     <string name="profile_not_found">Profile not found</string>
     <string name="strongswan_shortcut">strongSwan shortcut</string>
+    <string name="permanent_notification_name">VPN connection state</string>
+    <string name="permanent_notification_description">Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background.</string>
 
     <!-- Log view -->
     <string name="log_title">Log</string>