androidusbandroid-open-accessory

Detecting on AOA accessory that app has been closed and reopened


I have the following use case:

  1. User connects accessory to phone.
  2. App is automatically started on phone (this is part of AOA functionality).
  3. Communication between app and accessory proceeds.
  4. User closes app (by swiping it off the recent apps menu).
  5. User starts app again.
  6. Accessory tries to send data to app.

At step 6, I get USB error 7: Transfer error on bulk endpoint: Operation timed out on the accessory - the same as when the app is not running at all! This happens, even though the app is notified that an UsbAccessory is available.

What is the correct way to handle this situation?


Solution

  • Currently if the app is closed, there is no way to reopen the port for receiving from the android side. It is caused by a bug in the lower layer driver implementation.

    One way to handle this is to have a protocol running to check if the app is alive. If it's not alive, one of the possible ways to recover is to power cycle the usb port from the accessory side.

    The best way to trigger the lower layer driver to re-enumerate is to power cycle the usb port as of now.

    If you where to close the port before the app is closed, it would work fine. But that is not the case here since the app is being killed.