Issue
I'd like to cut off emulator's internet while keeping wifi and mobile data enabled so I can run some automated tests covering this case without having to turn off the internet manually.
While running an emulator on the PC it gets its internet access through the host PC, I'm interested in whether there's an adb
command that would let me disable (and re-enable mid-test, potentially multiple times) the internet access the emulator is getting from the host PC while keeping wifi and mobile data enabled?
I've been using svc wifi/data enable/disable
to enable and disable wifi and mobile data repectively.
This could be a duplicate of Can I truly enable and disable network access mid-test? but taking into account that it's almost 10 years old something might have changed in the meantime.
Solution
Diego's answer pushed me in the right direction.
Using: add shell settings put global http_proxy <ip>:<port>
and add shell settings put global http_proxy :0
to set and reset emulator's global proxy along with using the same proxy in the code (if it's set, to check so I'm using System.getProperty("http.proxyHost")
and System.getProperty("http.proxyPort")
), because it's not used automatically, I was able to achieve what I wanted.
Thanks Diego.
Edit:
In fact the APIs such as HttpURLConnection
do use the proxy automatically (if set, so no checking and manually setting needed on my side). Well HttpURLConnection
comes with its own problems such as not always honouring timeouts, so back to using other APIs and manually checking for proxy and if set using it.
Answered By - J.Grbo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.