Commit 99687086 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Added a notification which is shown when the VPN permission is revoked

parent d790182a
......@@ -742,6 +742,17 @@ class DnsVpnService : VpnService(), Runnable {
Handler(Looper.getMainLooper()).postDelayed({
BackgroundVpnConfigureActivity.prepareVpn(this, userServerConfig)
}, 250)
} else {
NotificationCompat.Builder(this, Notifications.getHighPriorityChannelId(this)).apply {
setSmallIcon(R.drawable.ic_cloud_warn)
setContentTitle(getString(R.string.notification_service_revoked_title))
setContentText(getString(R.string.notification_service_revoked_message))
setContentIntent(PendingIntent.getActivity(this@DnsVpnService, RequestCodes.RESTART_AFTER_REVOKE, Intent(this@DnsVpnService, BackgroundVpnConfigureActivity::class.java), PendingIntent.FLAG_CANCEL_CURRENT))
setAutoCancel(true)
priority = NotificationCompat.PRIORITY_HIGH
}.build().also {
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(Notifications.ID_SERVICE_REVOKED, it)
}
}
}
......@@ -1054,6 +1065,7 @@ class DnsVpnService : VpnService(), Runnable {
log("VPN proxy started.")
currentTrafficStats = vpnProxy?.trafficStats
LocalBroadcastManager.getInstance(this).sendBroadcast(Intent(BROADCAST_VPN_ACTIVE))
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(Notifications.ID_SERVICE_REVOKED)
}
private fun createQueryLogger(): QueryListener? {
......
......@@ -36,6 +36,7 @@ class Notifications {
const val ID_DNSRULE_EXPORT_FINISHED = 7
const val ID_PIN = 8
const val ID_SERVICE_KILLED = 9
const val ID_SERVICE_REVOKED = 10
const val ID_VPN_RESTART = 999
......@@ -104,6 +105,23 @@ class Notifications {
}
return "pinchannel"
}
fun getHighPriorityChannelId(context: Context):String {
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
val channel = NotificationChannel(
"high_priority",
context.getString(R.string.notification_channel_high_priorty),
NotificationManager.IMPORTANCE_HIGH
)
channel.enableLights(true)
channel.enableVibration(true)
channel.description = context.getString(R.string.notification_channel_high_priorty)
channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
channel.setBypassDnd(true)
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(channel)
}
return "high_priority"
}
}
}
......@@ -120,4 +138,5 @@ object RequestCodes {
val RULE_EXPORT_ABORT = 8
val PIN_NOTIFICATION = 9
val REQUEST_CODE_IGNORE_SERVICE_KILLED = 10
val RESTART_AFTER_REVOKE = 11
}
\ No newline at end of file
......@@ -12,6 +12,9 @@
<string name="notification_channel_pin">Pin-related channel</string>
<string name="notification_channel_pin_description">Channel used for notifications related to the pin, i.e. when it has to be provided</string>
<string name="notification_channel_high_priorty">High priority</string>
<string name="notification_channel_high_priorty_description">Channel for high priority notifications for example when the app loses permission to the VPN</string>
<string name="notification_simple_text">Current server: %1$s</string>
<string name="notification_main_text">Queries are sent to %1$s\n\n%2$d Apps are excluded from DoH/DoT\n%3$d entries in the cache</string>
<string name="notification_main_text_with_secondary">Queries are sent to %1$s and %2$s\n\n%3$d Apps are excluded from DoH/DoT\n%4$d entries in the cache</string>
......@@ -51,4 +54,7 @@
<string name="notification_service_killed_title">Information about battery optimization</string>
<string name="notification_service_killed_message">It seems like the app was previously stopped by the system. Click here to learn more.</string>
<string name="notification_service_killed_ignore">Ignore</string>
<string name="notification_service_revoked_title">VPN permission revoked by system</string>
<string name="notification_service_revoked_message">Click here to restart</string>
</resources>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment