diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/build.gradle | 7 | ||||
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java | 42 | ||||
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java | 15 | ||||
-rwxr-xr-x | main/src/main/res/values/strings.xml | 4 |
4 files changed, 60 insertions, 8 deletions
diff --git a/main/build.gradle b/main/build.gradle index 8bdd763c..7237eac4 100644 --- a/main/build.gradle +++ b/main/build.gradle @@ -15,12 +15,13 @@ apply plugin: 'checkstyle' repositories { jcenter() maven { url "https://jitpack.io" } + maven { url 'https://maven.google.com' } } dependencies { - compile 'com.android.support:support-annotations:25.3.1' - compile 'com.android.support:cardview-v7:25.3.1' - compile 'com.android.support:recyclerview-v7:25.3.1' + compile 'com.android.support:support-annotations:25.4.0' + compile 'com.android.support:cardview-v7:25.4.0' + compile 'com.android.support:recyclerview-v7:25.4.0' // compile 'ch.acra:acra:4.5.0' compile 'com.github.PhilJay:MPAndroidChart:v3.0.2' diff --git a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java index 4220b2be..919c7d3e 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java @@ -4,7 +4,14 @@ */ package de.blinkt.openvpn.core; + +import android.annotation.TargetApi; import android.app.Application; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.graphics.Color; +import android.os.Build; /* import org.acra.ACRA; @@ -12,9 +19,7 @@ import org.acra.ReportingInteractionMode; import org.acra.annotation.ReportsCrashes; */ -import de.blinkt.openvpn.BuildConfig; import de.blinkt.openvpn.R; -import de.blinkt.openvpn.core.PRNGFixes; public class ICSOpenVPNApplication extends Application { private StatusListener mStatus; @@ -24,7 +29,40 @@ public class ICSOpenVPNApplication extends Application { super.onCreate(); PRNGFixes.apply(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + + createNotificationChannels(); mStatus = new StatusListener(); mStatus.init(getApplicationContext()); + + } + + @TargetApi(Build.VERSION_CODES.O) + private void createNotificationChannels() { + NotificationManager mNotificationManager = + (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + // Background message + CharSequence name = getString(R.string.channel_name_background); + NotificationChannel mChannel = new NotificationChannel(OpenVPNService.NOTIFICATION_CHANNEL_BG_ID, + name, NotificationManager.IMPORTANCE_MIN); + + mChannel.setDescription(getString(R.string.channel_description_background)); + mChannel.enableLights(false); + + mChannel.setLightColor(Color.DKGRAY); + mNotificationManager.createNotificationChannel(mChannel); + + // Connection status change messages + + name = getString(R.string.channel_name_status); + mChannel = new NotificationChannel(OpenVPNService.NOTIFICATION_CHANNEL_NEWSTATUS_ID, + name, NotificationManager.IMPORTANCE_DEFAULT); + + mChannel.setDescription(getString(R.string.channel_description_status)); + mChannel.enableLights(true); + + mChannel.setLightColor(Color.BLUE); + mNotificationManager.createNotificationChannel(mChannel); } } diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index 9042ddba..5b90bcc8 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -68,7 +68,9 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac private static final String PAUSE_VPN = "de.blinkt.openvpn.PAUSE_VPN"; private static final String RESUME_VPN = "de.blinkt.openvpn.RESUME_VPN"; private static final int OPENVPN_STATUS = 1; - private static final String NOTIFICATION_CHANNEL_ID="openvpn"; + public static final String NOTIFICATION_CHANNEL_BG_ID="openvpn_bg"; + public static final String NOTIFICATION_CHANNEL_NEWSTATUS_ID="openvpn_newstat"; + private static boolean mNotificationAlwaysVisible = false; private final Vector<String> mDnslist = new Vector<>(); private final NetworkSpace mRoutes = new NetworkSpace(); @@ -229,8 +231,15 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) lpNotificationExtras(nbuilder); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - nbuilder.setChannelId(NOTIFICATION_CHANNEL_ID); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (priority ==0 ) + nbuilder.setChannelId(NOTIFICATION_CHANNEL_BG_ID); + else + nbuilder.setChannelId(NOTIFICATION_CHANNEL_NEWSTATUS_ID); + if (mProfile != null) + nbuilder.setShortcutId(mProfile.getUUIDString()); + + } if (tickerText != null && !tickerText.equals("")) nbuilder.setTicker(tickerText); diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml index c20d1fe4..cbd9c06b 100755 --- a/main/src/main/res/values/strings.xml +++ b/main/src/main/res/values/strings.xml @@ -441,5 +441,9 @@ <string name="volume_kbyte">%.1f kB</string> <string name="volume_mbyte">%.1f MB</string> <string name="volume_gbyte">%.1f GB</string> + <string name="channel_name_background">Connection statistics</string> + <string name="channel_description_background">Ongoing statistics of the established OpenVPN connection</string> + <string name="channel_name_status">Connection status change</string> + <string name="channel_description_status">Status changes of the OpenVPN connection (Connecting, authenticating,…)</string> </resources> |