meh / rust-tun

TUN device creation and handling.
343 stars 136 forks source link

feat: add Android support #30

Closed black-binary closed 3 years ago

black-binary commented 3 years ago

I added a module android by simply copying the code and renaming the structs from the ios module, and it works well on my Android 10 device.

VpnService.builder in Android works like iOS (#21). The tunnel device's file descriptor can be created in Java code and then be passed to the native Rust code.

black-binary commented 3 years ago

The way Android creates the tun device is different from Linux. The app developer needs to pop up a window (VpnService.prepare()) asking users for permissions. And then invoke VpnService.Builder.establish() to request ART to create a tun device and obtain the fd.

The process of creating tun in Android needs to be written in Java instead of native code. Creating a tun device directly, like what linux::new does, will result in an error. So I prefer to implement a new module for Android. :)

meh commented 3 years ago

Makes sense! Just need to verify the note I left then.

raintean commented 3 years ago

AsyncDevice supported?