Q:

Is there a way to disconnect USB device from ADB?

I have a lot of scripts that use ADB to debug Android applications via Wi-Fi with emulators. The problem appears when I charge my Android phone via USB from my computer: ADB sees it and sends commands to my phone instead of emulator.
Is there a way to disconnect ADB from phone that charges via USB? I know I can send commands to emulators only via -e switch, as well as send them to specific device via -s switch. However, it is not OK for me, because I have to rewrite a lot of scripts to add more arguments if I want to implement this device selection feature. I don't need workarounds, I just curious does Google force ADB to debug any phone connected via USB that has USB debugging enabled in settings, or it is possible to remove specific USB connected phone from devices list on ADB side?
When I run adb disconnect, USB device remains connected.

A:

ADB doesn't support disconnecting a USB connection now(version 1.0.39).
"adb disconnect" can only disconnect a TCP connection set up by "adb connect", it can not disconnect a USB connection.
You can "disconnect" a connection by using push and reconnect commands as a workaround:
1.push a file to phone
adb -s SERIAL push somefile /data/local/tmp

2.reconnect while push is still in progress
adb -s SERIAL reconnect

Repeat step 1 and 2, after a while, you can find this device is in offline state from output of "adb devices".
No adb command can operate this offline device until you kill-server and start-server.

A:

USB connection for internal storage and adb connection for debugging are two separate things.
To disable adb - you can use adb disconnect or simply turn off usb debugging under developer options.
For disconnecting usb connection for internal storage certain ROMS have the option. e.g. CM 13 that i have at the moment allows connecting USB just for charging. Generally on other ROMS and Stock ROM I've not seen this option but you can try this. -> If you connect your device via USB while locked the internal storage will not be available unless you unlock the device once.

