diff options
Diffstat (limited to 'tunnel')
-rw-r--r-- | tunnel/build.gradle.kts | 1 | ||||
-rw-r--r-- | tunnel/src/main/AndroidManifest.xml | 3 | ||||
-rw-r--r-- | tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java | 34 |
3 files changed, 37 insertions, 1 deletions
diff --git a/tunnel/build.gradle.kts b/tunnel/build.gradle.kts index 44a10696..625959e6 100644 --- a/tunnel/build.gradle.kts +++ b/tunnel/build.gradle.kts @@ -70,6 +70,7 @@ dependencies { implementation(project(":bgp-java")) implementation(libs.androidx.annotation) implementation(libs.androidx.collection) + implementation(libs.androidx.core) implementation(libs.grpc.android) implementation(libs.grpc.okhttp) implementation(libs.grpc.protobuf.lite) diff --git a/tunnel/src/main/AndroidManifest.xml b/tunnel/src/main/AndroidManifest.xml index 99509a20..bbefdb1c 100644 --- a/tunnel/src/main/AndroidManifest.xml +++ b/tunnel/src/main/AndroidManifest.xml @@ -9,7 +9,8 @@ <service android:name="com.wireguard.android.backend.GoBackend$VpnService" android:permission="android.permission.BIND_VPN_SERVICE" - android:exported="false"> + android:exported="false" + android:foregroundServiceType="systemExempted"> <intent-filter> <action android:name="android.net.VpnService" /> </intent-filter> diff --git a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java index 0e9668d0..dec3021c 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -6,9 +6,12 @@ package com.wireguard.android.backend; import android.app.AlarmManager; +import android.app.Notification; +import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.pm.ServiceInfo; import android.net.ConnectivityManager; import android.net.LinkProperties; import android.net.LocalSocketAddress; @@ -101,6 +104,10 @@ import javax.net.SocketFactory; import androidx.annotation.Nullable; import androidx.collection.ArraySet; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationChannelCompat; +import androidx.core.app.NotificationManagerCompat; +import androidx.core.app.ServiceCompat; /** * Implementation of {@link Backend} that uses the wireguard-go userspace implementation to provide @@ -113,6 +120,7 @@ public final class GoBackend implements Backend { private static final int STATS_TAG = 2; private static final int MSG_DHCP_EXPIRE = 1; private static final int MSG_CAPABILITIES_CHANGED = 2; + private static final String NOTIFICATION_CHANNEL_ID = "WireGuardVPN"; @Nullable private static AlwaysOnCallback alwaysOnCallback; private static GhettoCompletableFuture<VpnService> vpnService = new GhettoCompletableFuture<>(); private final Context context; @@ -143,6 +151,18 @@ public final class GoBackend implements Backend { String socketName = socketFile.getAbsolutePath(); Log.i(TAG, "wgStartGrpc: " + wgStartGrpc(socketName)); channel = UdsChannelBuilder.forPath(socketName, LocalSocketAddress.Namespace.FILESYSTEM).build(); + + NotificationManagerCompat notificationManager = + NotificationManagerCompat.from(context); + + NotificationChannelCompat channel = + new NotificationChannelCompat + .Builder(NOTIFICATION_CHANNEL_ID, + NotificationManager.IMPORTANCE_DEFAULT) + .setName(NOTIFICATION_CHANNEL_ID) + .build(); + + notificationManager.createNotificationChannel(channel); } /** @@ -911,6 +931,20 @@ public final class GoBackend implements Backend { public void onCreate() { vpnService.complete(this); super.onCreate(); + + Notification notification = + new NotificationCompat.Builder(this, + GoBackend.NOTIFICATION_CHANNEL_ID) + .build(); + + int foregroundServiceType = + Build.VERSION.SDK_INT >= Build.VERSION_CODES.R + ? ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED : 0; + + ServiceCompat.startForeground(this, + 100, + notification, + foregroundServiceType); } @Override |