-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix solution for launching the service on pre-8.0 devices. #29
base: master
Are you sure you want to change the base?
Conversation
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 |
Oh , I embedded the library |
btw this may occur when calling from |
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. |
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 |
Well at this point the best option (tested) would be to create a trampoline foreground service to trigger from |
|
Failed to resolve: com.wireguard.android:tunnel:1.0.20220516 |
Failed to resolve: com.wireguard.android:tunnel:1.0.20220516 |
@@ -219,7 +219,11 @@ private void setStateInternal(final Tunnel tunnel, @Nullable final Config config | |||
final VpnService service; | |||
if (!vpnService.isDone()) { | |||
Log.d(TAG, "Requesting to start VpnService"); | |||
context.startService(new Intent(context, VpnService.class)); | |||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |||
context.startForegroundService(new Intent(context, VpnService.class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are starting the service as a foreground service, you should accompany it with a notification.
Also, according to the guidelines, it is okay to start the VPN service as a background service, but you must promote it to foreground by showing the notification using the Service#setForeground method.
https://developer.android.com/guide/topics/connectivity/vpn#starting_a_service
Thoughts?
581ab92
to
ec126a9
Compare
b2568c4
to
b1324e2
Compare
ab02c51
to
44a2603
Compare
a1670c8
to
dc1860c
Compare
baa1257
to
79b8c34
Compare
c046706
to
40eaa54
Compare
In my opinion, it would be better to start a VPN Service as a foreground one, but I've seen(WireGuard#29) that you don't want additional permissions that come with it.
In my opinion, it would be better to start a VPN Service as a foreground one, but I've seen(WireGuard#29) that you don't want additional permissions that come with it. Signed-off-by: Alexander Perfilyev <[email protected]>
827495b
to
4ba8794
Compare
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