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.
This commit is contained in:
+25
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2012-2017 Tobias Brunner
|
* Copyright (C) 2012-2018 Tobias Brunner
|
||||||
* Copyright (C) 2012 Giuliano Grassi
|
* Copyright (C) 2012 Giuliano Grassi
|
||||||
* Copyright (C) 2012 Ralf Sager
|
* Copyright (C) 2012 Ralf Sager
|
||||||
* HSR Hochschule fuer Technik Rapperswil
|
* HSR Hochschule fuer Technik Rapperswil
|
||||||
@@ -19,6 +19,7 @@ package org.strongswan.android.logic;
|
|||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
@@ -70,6 +71,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
|
|||||||
{
|
{
|
||||||
private static final String TAG = CharonVpnService.class.getSimpleName();
|
private static final String TAG = CharonVpnService.class.getSimpleName();
|
||||||
public static final String DISCONNECT_ACTION = "org.strongswan.android.CharonVpnService.DISCONNECT";
|
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 String LOG_FILE = "charon.log";
|
||||||
public static final int VPN_STATE_NOTIFICATION_ID = 1;
|
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 */
|
/* the thread is started when the service is bound */
|
||||||
bindService(new Intent(this, VpnStateService.class),
|
bindService(new Intent(this, VpnStateService.class),
|
||||||
mServiceConnection, Service.BIND_AUTO_CREATE);
|
mServiceConnection, Service.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
|
createNotificationChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -321,6 +325,25 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
|
|||||||
stopForeground(true);
|
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
|
* Build a notification matching the current state
|
||||||
*/
|
*/
|
||||||
@@ -336,7 +359,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
|
|||||||
{
|
{
|
||||||
name = profile.getName();
|
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)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||||
.setVisibility(publicVersion ? NotificationCompat.VISIBILITY_PUBLIC
|
.setVisibility(publicVersion ? NotificationCompat.VISIBILITY_PUBLIC
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
<string name="loading">Laden…</string>
|
<string name="loading">Laden…</string>
|
||||||
<string name="profile_not_found">Profil nicht gefunden</string>
|
<string name="profile_not_found">Profil nicht gefunden</string>
|
||||||
<string name="strongswan_shortcut">strongSwan-Verknüpfung</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 -->
|
<!-- Log view -->
|
||||||
<string name="log_title">Log</string>
|
<string name="log_title">Log</string>
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
<string name="loading">Wczytywanie…</string>
|
<string name="loading">Wczytywanie…</string>
|
||||||
<string name="profile_not_found">Nie znaleziono profilu</string>
|
<string name="profile_not_found">Nie znaleziono profilu</string>
|
||||||
<string name="strongswan_shortcut">Skrót strongSwan</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 -->
|
<!-- Log view -->
|
||||||
<string name="log_title">Log</string>
|
<string name="log_title">Log</string>
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
<string name="loading">Загрузка…</string>
|
<string name="loading">Загрузка…</string>
|
||||||
<string name="profile_not_found">Профиль не найден</string>
|
<string name="profile_not_found">Профиль не найден</string>
|
||||||
<string name="strongswan_shortcut">Ссылка на strongSwan</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 -->
|
<!-- Log view -->
|
||||||
<string name="log_title">Журнал</string>
|
<string name="log_title">Журнал</string>
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
<string name="loading">Завантаження…</string>
|
<string name="loading">Завантаження…</string>
|
||||||
<string name="profile_not_found">Профіль не знайдено</string>
|
<string name="profile_not_found">Профіль не знайдено</string>
|
||||||
<string name="strongswan_shortcut">strongSwan посилання</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 -->
|
<!-- Log view -->
|
||||||
<string name="log_title">Журнал</string>
|
<string name="log_title">Журнал</string>
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
<string name="loading">载入中…</string>
|
<string name="loading">载入中…</string>
|
||||||
<string name="profile_not_found">未找到配置</string>
|
<string name="profile_not_found">未找到配置</string>
|
||||||
<string name="strongswan_shortcut">strongSwan快捷方式</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 -->
|
<!-- Log view -->
|
||||||
<string name="log_title">日志</string>
|
<string name="log_title">日志</string>
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
<string name="loading">載入中…</string>
|
<string name="loading">載入中…</string>
|
||||||
<string name="profile_not_found">沒有找到設定檔</string>
|
<string name="profile_not_found">沒有找到設定檔</string>
|
||||||
<string name="strongswan_shortcut">strongSwan快速選單</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 -->
|
<!-- Log view -->
|
||||||
<string name="log_title">日誌</string>
|
<string name="log_title">日誌</string>
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
<string name="loading">Loading…</string>
|
<string name="loading">Loading…</string>
|
||||||
<string name="profile_not_found">Profile not found</string>
|
<string name="profile_not_found">Profile not found</string>
|
||||||
<string name="strongswan_shortcut">strongSwan shortcut</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 -->
|
<!-- Log view -->
|
||||||
<string name="log_title">Log</string>
|
<string name="log_title">Log</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user