Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill VpnService instance and notification

I know that VpnService is-a Service and that stopSelf() works to stop the service itself (at least it seems to since onDestroy() is called).

The issue is that the notification at the top (which appears once VpnService.Builder.establish() is called ) does not clear itself when I call stopSelf() in my service instance.

Also, I've noticed that the VPN settings (connection, routes, nameservers) stay in tact while that notification remains, thus there is a disconnect between Android and the VpnService.

Can anyone help me programmatically cancel the VPN ?

like image 549
Dulax Avatar asked Mar 03 '26 12:03

Dulax


1 Answers

After a bunch of testing, it appears that if the FD in the ParcelFileDescriptor returned by VpnService.Builder.establish() is closed, then the notification is cleared.

Therefore, on the native side, if you close all references to the FD, the notification will clear. Be sure to ACTUALLY call close() on the FD.

like image 167
Dulax Avatar answered Mar 06 '26 01:03

Dulax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!