In the Android API reference, UsbDevice objects have a function, getDeviceId()
, that returns a unique integer ID. The API reference notes that IDs are not persistent across disconnects.
However, the manual is not clear about an important point. If a device has some ID number, and then it is disconnected, is that ID number likely to be reused?
Say the ID number for a connected device is 3 - if the user disconnects it and plugs it in again, or plugs in a different device to that USB port, is there a chance for the newly connected device to get the number 3 again? Or is the ID likely to be different from IDs from prior device connections?
After checking the Android source as per Robert's suggestion, it looks like the ID is derived from the device name, which is derived from the device's place on the USB bus (specifically, bus number * 1000 + device number
).
Some light googling suggests that this renders the ID assignment behavior dependent on the device kernel's bus/device# assignment behavior when a USB device is attached.
So I'd definitely have to assume that IDs might be reused at any time.