From: Tobias Brunner Date: Wed, 6 Jun 2018 16:55:45 +0000 (+0200) Subject: android: Add notification channel for API level 26+ X-Git-Tag: 5.7.0dr5~20^2~59 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6ca0b46c20d83266a9b93e60ef54a7c91e54008a;p=thirdparty%2Fstrongswan.git android: Add notification channel for API level 26+ Unfortunately, setLockscreenVisibility() doesn't seem to have any effect. So the full notification is shown unless the user manually configures the notification settings. --- diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java index b6e7e2d644..d573d882d1 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java @@ -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 diff --git a/src/frontends/android/app/src/main/res/values-de/strings.xml b/src/frontends/android/app/src/main/res/values-de/strings.xml index 896e53608f..975686e563 100644 --- a/src/frontends/android/app/src/main/res/values-de/strings.xml +++ b/src/frontends/android/app/src/main/res/values-de/strings.xml @@ -29,6 +29,8 @@ Laden… Profil nicht gefunden strongSwan-Verknüpfung + VPN Verbindungsstatus + Zeigt Informationen zum Verbindungsstatus der VPN Verbindung und dient als permanente Notification dazu, den VPN Dienst im Hintergrund am Laufen zu halten. Log diff --git a/src/frontends/android/app/src/main/res/values-pl/strings.xml b/src/frontends/android/app/src/main/res/values-pl/strings.xml index ce1dc6741b..835efd531a 100644 --- a/src/frontends/android/app/src/main/res/values-pl/strings.xml +++ b/src/frontends/android/app/src/main/res/values-pl/strings.xml @@ -29,6 +29,8 @@ Wczytywanie… Nie znaleziono profilu Skrót strongSwan + VPN connection state + Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background. Log diff --git a/src/frontends/android/app/src/main/res/values-ru/strings.xml b/src/frontends/android/app/src/main/res/values-ru/strings.xml index 756473b564..53e8375730 100644 --- a/src/frontends/android/app/src/main/res/values-ru/strings.xml +++ b/src/frontends/android/app/src/main/res/values-ru/strings.xml @@ -26,6 +26,8 @@ Загрузка… Профиль не найден Ссылка на strongSwan + VPN connection state + Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background. Журнал diff --git a/src/frontends/android/app/src/main/res/values-ua/strings.xml b/src/frontends/android/app/src/main/res/values-ua/strings.xml index 8c165734a3..8e41daf914 100644 --- a/src/frontends/android/app/src/main/res/values-ua/strings.xml +++ b/src/frontends/android/app/src/main/res/values-ua/strings.xml @@ -27,6 +27,8 @@ Завантаження… Профіль не знайдено strongSwan посилання + VPN connection state + Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background. Журнал diff --git a/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml b/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml index 2d195f6384..0cb6bd087a 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml @@ -26,6 +26,8 @@ 载入中… 未找到配置 strongSwan快捷方式 + VPN connection state + Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background. 日志 diff --git a/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml b/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml index 650cd6940d..168fdd7dd3 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml @@ -26,6 +26,8 @@ 載入中… 沒有找到設定檔 strongSwan快速選單 + VPN connection state + Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background. 日誌 diff --git a/src/frontends/android/app/src/main/res/values/strings.xml b/src/frontends/android/app/src/main/res/values/strings.xml index e6cb9dc4cd..13d7187333 100644 --- a/src/frontends/android/app/src/main/res/values/strings.xml +++ b/src/frontends/android/app/src/main/res/values/strings.xml @@ -29,6 +29,8 @@ Loading… Profile not found strongSwan shortcut + VPN connection state + Provides information about the VPN connection state and serves as permanent notification to keep the VPN service running in the background. Log