From 3ed5460fd7e8e3fd84fd5c40740e2a1e2e0309c8 Mon Sep 17 00:00:00 2001 From: Brandon T Date: Thu, 22 May 2025 20:35:26 -0400 Subject: [PATCH] Add isAlwaysOn and isLockdownEnabled Signed-off-by: Brandon T --- .../wireguard/android/backend/Backend.java | 22 +++++++++++++++++++ .../wireguard/android/backend/GoBackend.java | 18 +++++++++++++++ 2 files changed, 40 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..e29b1d9a 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. + * + * @returns 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. + * + * @returns 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..4dc7ba05 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 String getVersion() { 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() { + 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() { + return vpnService.get(0, TimeUnit.NANOSECONDS).isLockdownEnabled(); + } + /** * Change the state of a given {@link Tunnel}, optionally applying a given {@link Config}. *