Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disconnect network in Android emulator while keeping ADB alive

I have made a mistake somewhere in my code that my Android app crashes when I switch off the network in the emulator while the app's HTTPClient is making some request.

But I cannot debug it, because when I switched off the network, I also lost the ADB connection. Thus I cannot see what exception is causing the crash.

I have tried switching off the network by:

  • F8
  • Set 'Data' to 'Unregistered' or 'Denied' in DDMS Emulator Control

I can put my Mac offline and ADB will stay up, but unfortunately I cannot reproduce the crash that way.

Is there a way to turn off network in the emulator, while keeping ADB alive? I basically need access to the LogCat entries.

Thanks!

like image 508
edwinbs Avatar asked Nov 09 '12 05:11

edwinbs


People also ask

How do I disable Internet on emulator?

You can disable the Internet connection by pressing F8 in any Android emulator. It is a toggle button, so if it doesn't have Internet connection then it will start the Internet connection and if it already has an Internet connection then it will dis-connect it.

How do you check if your emulator has the permission to access Internet and also is connected to?

Click Advanced -> Click on Tab DNS -> Click on Add. Write 8.8. 8.8 & Click Add, It will look like. Check your emulator, you should access internet.


2 Answers

You can run logcat from the device instead of from ADB and redirect it to a file for offline reading.

adb shell logcat [-v threadtime] > /sdcard/mylogs/logcat.log

Instead of

adb logcat [-v threadtime]

Then you can get the file when you reconnect to the device.

like image 76
Ofir Luzon Avatar answered Oct 02 '22 16:10

Ofir Luzon


On linux this is pretty simple with iptables firewall. I suppose you trying to debug api calls so just block api host:

iptables -I OUTPUT -d api.example.com -j DROP

Sure you can do the same thing with Mac or Windows firewall.

like image 37
Oleg Kr Avatar answered Oct 02 '22 16:10

Oleg Kr