adb_shell icon indicating copy to clipboard operation
adb_shell copied to clipboard

No ability to list attached devices?

Open thethiny opened this issue 1 year ago • 1 comments

Description

running adb devices is how I get the names of my devices. If I don't have a device name I cannot connect to it. Is there an option to list all connected devices?

thethiny avatar Jun 06 '24 17:06 thethiny

You can use UsbTransport.find_all_adb_devices() to get a list of UsbTransport objects that correlate to devices. On each entry returned by the generator, you can get the serial_number attribute to get the serial number. Then you can use AdbDeviceUsb to connect to them.

Note: in some cases you can run into usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3] either while creating the AdbDeviceUsb instance or when you call connect() on it. This is caused by the standard ADB daemon running in the background and locking the device accessors, so just make sure you kill the ADB server before creating the device object and connecting to it:

def connect(self, serial: str):
    subprocess.Popen(["adb", "kill-server"]).communicate()
    device = AdbDeviceUsb(serial)
    device.connect()

I do concur however that a @classmethod device lister on both AdbDeviceUsb and AdbDeviceTcp (latter using mDNS) would be preferred.

fonix232 avatar Dec 17 '24 10:12 fonix232