wireguard-android icon indicating copy to clipboard operation
wireguard-android copied to clipboard

Fix solution for launching the service on pre-8.0 devices.

Open w3rkzeug opened this issue 3 years ago • 9 comments

Fix for the following error that occurs when launching the service from background (onBoot f.e.): E/WireGuard/TunnelManager: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.tun.android.debug/com.wireguard.android.backend.GoBackend$VpnService }: app is in background

w3rkzeug avatar Jun 18 '21 13:06 w3rkzeug

When are you encountering this? We already ship a trampoline activity that is launched by the QS tile to bring the app to the foreground before the GoBackend code path is hit.

msfjarvis avatar Jun 18 '21 13:06 msfjarvis

Oh , I embedded the library implementation 'com.wireguard.android:tunnel:1.0.20210211' version, applied the fix & it worked tho.

w3rkzeug avatar Jun 18 '21 13:06 w3rkzeug

btw this may occur when calling from BootShutdownReceiver -> tunnelManager.restoreState(true),followed by this https://github.com/WireGuard/wireguard-android/blob/master/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt

w3rkzeug avatar Jun 18 '21 13:06 w3rkzeug

Oh , I embedded the library implementation 'com.wireguard.android:tunnel:$wireguardTunnelVersion' version, applied the fix & it worked tho.

Ah, I see. The problem with launching a foreground service is that it requires a persistent notification as well as an additional permission. My personal recommendation would be to replicate the trampoline workaround that we use in the WireGuard app for user-initiated triggers and relying on the Android platform's always-on VPN option for starting up right after boot.

msfjarvis avatar Jun 18 '21 13:06 msfjarvis

btw this may occur when calling from BootShutdownReceiver -> tunnelManager.restoreState(true),followed by this https://github.com/WireGuard/wireguard-android/blob/master/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt

Yeah I guessed as much. I will look into fixing this separately. In the meantime can you please force push your commit with your real name as author and a Signed-off-by line? That'll make my life easier in case I end up merging your patch.

msfjarvis avatar Jun 18 '21 13:06 msfjarvis

Oh , I embedded the library implementation 'com.wireguard.android:tunnel:$wireguardTunnelVersion' version, applied the fix & it worked tho.

Ah, I see. The problem with launching a foreground service is that it requires a persistent notification as well as an additional permission. My personal recommendation would be to replicate the trampoline workaround that we use in the WireGuard app for user-initiated triggers and relying on the Android platform's always-on VPN option for starting up right after boot.

Well at this point the best option (tested) would be to create a trampoline foreground service to trigger from BootShutdownReceiver on ACTION_BOOT_COMPLETED :) Anyway Thanks

w3rkzeug avatar Jun 19 '21 09:06 w3rkzeug

implementation 'com.wireguard.android:tunnel:1.0.20220516' not on mavent 有没有谁知道,解决方案是什么

zzb-zzb avatar Dec 06 '22 06:12 zzb-zzb

Failed to resolve: com.wireguard.android:tunnel:1.0.20220516

zzb-zzb avatar Dec 06 '22 09:12 zzb-zzb

btw this may occur when calling from BootShutdownReceiver -> tunnelManager.restoreState(true),followed by this https://github.com/WireGuard/wireguard-android/blob/master/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt

Yeah I guessed as much. I will look into fixing this separately. In the meantime can you please force push your commit with your real name as author and a Signed-off-by line? That'll make my life easier in case I end up merging your patch.

Failed to resolve: com.wireguard.android:tunnel:1.0.20220516

zzb-zzb avatar Dec 06 '22 09:12 zzb-zzb