From 82e244ef4970fc4781fd7484233443ae5b78cf94 Mon Sep 17 00:00:00 2001 From: Jamil Date: Mon, 24 Jun 2024 15:37:51 -0700 Subject: [PATCH] fix(android): Handle onRevoke to stop connlib when VPN profile is revoked (#5495) If the Firezone VPN profile is removed while Firezone is signed in, we fail to shut down connlib and upon the next `buildVpnService()` call, we get a NullPointerException because the app isn't "ready". It needs a call to `prepare()` to register the profile again. Fixes #5466 https://developer.android.com/reference/android/net/VpnService#onRevoke() --- .../main/java/dev/firezone/android/tunnel/TunnelService.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kotlin/android/app/src/main/java/dev/firezone/android/tunnel/TunnelService.kt b/kotlin/android/app/src/main/java/dev/firezone/android/tunnel/TunnelService.kt index 29d34d7be..3db3e1db2 100644 --- a/kotlin/android/app/src/main/java/dev/firezone/android/tunnel/TunnelService.kt +++ b/kotlin/android/app/src/main/java/dev/firezone/android/tunnel/TunnelService.kt @@ -199,6 +199,12 @@ class TunnelService : VpnService() { super.onDestroy() } + override fun onRevoke() { + Log.d(TAG, "onRevoke") + disconnect() + super.onRevoke() + } + // Call this to stop the tunnel and shutdown the service, leaving the token intact. fun disconnect() { Log.d(TAG, "disconnect")