From 0d18e478ca732395bee839a40c1288c3a5ddf271 Mon Sep 17 00:00:00 2001 From: Brandon T Date: Thu, 22 May 2025 20:35:26 -0400 Subject: [PATCH] tunnel: add isAlwaysOn and isLockdownEnabled Signed-off-by: Brandon T [Harsh: fix build and Javadoc errors] Signed-off-by: Harsh Shandilya Signed-off-by: Jason A. Donenfeld --- .../wireguard/android/backend/Backend.java | 22 +++++++++++++++++++ .../wireguard/android/backend/GoBackend.java | 18 +++++++++++++++ .../android/backend/WgQuickBackend.java | 10 +++++++++ 3 files changed, 50 insertions(+) diff --git a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java index 224d5849..ff2fb818 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java @@ -52,6 +52,28 @@ public interface Backend { */ String getVersion() throws Exception; + /** + * Determines whether the service is running in always-on VPN mode. + * In this mode the system ensures that the service is always running by restarting it when necessary, + * e.g. after reboot. + * + * @return A boolean indicating whether the service is running in always-on VPN mode. + * @throws Exception Exception raised while retrieving the always-on status. + */ + + boolean isAlwaysOn() throws Exception; + + /** + * Determines whether the service is running in always-on VPN lockdown mode. + * In this mode the system ensures that the service is always running and that the apps + * aren't allowed to bypass the VPN. + * + * @return A boolean indicating whether the service is running in always-on VPN lockdown mode. + * @throws Exception Exception raised while retrieving the lockdown status. + */ + + boolean isLockdownEnabled() throws Exception; + /** * Set the state of a tunnel, updating it's configuration. If the tunnel is already up, config * may update the running configuration; config may be null when setting the tunnel down. 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 6b66f2c5..46f68b4b 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -188,6 +188,24 @@ public final class GoBackend implements Backend { return wgVersion(); } + /** + * Determines if the service is running in always-on VPN mode. + * @return {@link boolean} whether the service is running in always-on VPN mode. + */ + @Override + public boolean isAlwaysOn() throws ExecutionException, InterruptedException, TimeoutException { + return vpnService.get(0, TimeUnit.NANOSECONDS).isAlwaysOn(); + } + + /** + * Determines if the service is running in always-on VPN lockdown mode. + * @return {@link boolean} whether the service is running in always-on VPN lockdown mode. + */ + @Override + public boolean isLockdownEnabled() throws ExecutionException, InterruptedException, TimeoutException { + return vpnService.get(0, TimeUnit.NANOSECONDS).isLockdownEnabled(); + } + /** * Change the state of a given {@link Tunnel}, optionally applying a given {@link Config}. * diff --git a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java index 87fdf6e5..af96ddae 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java @@ -109,6 +109,16 @@ public final class WgQuickBackend implements Backend { return output.get(0); } + @Override + public boolean isAlwaysOn() { + return false; + } + + @Override + public boolean isLockdownEnabled() { + return false; + } + public void setMultipleTunnels(final boolean on) { multipleTunnels = on; }