0

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?

3
  • 1
    Have you checked the sources of AOSP for the implementation of getDeviceId ? Commented Feb 28 at 21:08
  • No, I figured I would ask here first and see if anyone else knew the answer. Commented Mar 2 at 21:59
  • The main problem I see here is if Google hasn't specified the behavior there is most likely not test in the AOSP compatibility test suite. Thus the behavior of different manufacturer may not be consistent, dependent on the modifications those manufacturer apply to AOSP. This means you can not rely on it. Better assume the worst case. Commented Mar 2 at 22:11

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.