0

Problem: By default, Android has only one active Network, so when you have your other device connected to your phone over Wi-Fi (IoT, Dashcam, whatever, obviously with no internet), your Android Cellular got unavailable for the App. If you switch to Cellular (eg ConnectivityManager.bindProcessToNetwork), Wifi is not available anymore for any http://10.XX.XX.XX requests to device.

Adding more complexity: You technically can ping second network, but simply doing Network.openConnection(...) to WiFi network is not enough, cause I have FFMPEG running on low level, that needs a constant access to WiFi device, with no control over when it will happen and how, it's a low level process.

What I really need is STABLE RE-ROUTING OF ALL THE TRAFFIC COMING TO HTTP://10.XX.XX.XX TO WIFI DEVICE. Am I asking a lot? Task seems trivial on the paper, so once all the traffic to this particular IP gets re-routed to WiFi, I'm ok to send everything else to Cellular.

What I did so far:

  • Bound all the traffic to Cellular by default
  • Created VPNService to catch all the traffic to 10.XX.XX.XX port via VPNService.Builder().addAddress(...).establish() so I got ParcelFileDescriptor to work with. How can I send all this catched traffic to WiFi network now, and get the entire flow back to client? Special notes to anyone who will advice creating TCP Socket for this IP address or using Network.getSocketFactory().createSocket(...) to get specific socket bound to WiFi: I need it STABLE and ALIVE. Deprecated requestRouteToHost is not working anymore, please don't advice those old & outdated stuff, I killed a LOT of my time to test it out. I don't need to close my connection and open it over and over again, I don't need to work for 4 seconds straight and then drop, and then re-run it again. I'm looking for solution which is:
  • stable
  • alive for the entire session of the App
  • simply flows the data from VpnService to Wifi and sends it back to requesters
  • or maybe you know another, simple and modern way to use the latest Android SDK and perform it in a short and elegant way. Huge thanks to any of you in advance for the time you spent reading that post.
punov
  • 798
  • 7
  • 16
  • Can you just file two network requests? One for Cellular and one for Wi-Fi? Then they'll always stay up if they are available. You can reference this answer here: https://stackoverflow.com/questions/8718434/can-i-have-both-wi-fi-and-cellular-network-interfaces-open-at-the-same-time-on-a/67081087#67081087 – Always Learning Dec 23 '21 at 01:23
  • @AlwaysLearning thanks for your answer. Unfortunately, that's not how it works. When you file two network requests, they're telling you they're available, and they're technically available for being directly connected (via openConnection or bindSocket operations), but there's only one active network that Android treats as a main one (you can see it by logging ConnectivityManager.getActiveNetwork() ), and all the traffic from all of your libraries / tools (Map, ffmpeg, Auth, WebViews) flows using this active network. – punov Dec 23 '21 at 07:12
  • Yeah, but it looks like you are using Wi-Fi for internal networks? 10.x.x.x? Can't those apps be updated to request only Wi-Fi networks? Then they would use Wi-Fi by requesting it directly (as opposed to relying on the default/active network) and everything else can use the default network. – Always Learning Dec 23 '21 at 17:50

0 Answers0