diff options
-rw-r--r-- | gradle/libs.versions.toml | 1 | ||||
-rw-r--r-- | tunnel/build.gradle.kts | 1 | ||||
-rw-r--r-- | tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java | 34 | ||||
-rw-r--r-- | ui/src/main/AndroidManifest.xml | 1 |
4 files changed, 37 insertions, 0 deletions
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8a3a53e6..605e53a2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,7 @@ androidx-biometric = "androidx.biometric:biometric:1.1.0" androidx-collection = "androidx.collection:collection:1.3.0" androidx-constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.4" androidx-coordinatorlayout = "androidx.coordinatorlayout:coordinatorlayout:1.2.0" +androidx-core = "androidx.core:core:1.12.0" androidx-core-ktx = "androidx.core:core-ktx:1.12.0" androidx-datastore-preferences = "androidx.datastore:datastore-preferences:1.0.0" androidx-fragment-ktx = "androidx.fragment:fragment-ktx:1.6.1" 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/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 diff --git a/ui/src/main/AndroidManifest.xml b/ui/src/main/AndroidManifest.xml index e49efd8e..cf70f494 100644 --- a/ui/src/main/AndroidManifest.xml +++ b/ui/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> + <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED" android:minSdkVersion="34" /> |