Programmatically resetting USB completely without root access

I have been working on a project in which I communicate with a device for reprogramming via USB Host. The device I am reprogramming requires me to unplug the USB cable and plug it back in to communicate with the Boot Block for reprogramming. I am looking for a solution to completely reset USB so the users do not have to mess with disconnecting cables. The other wrinkle in this is the Android devices will not be rooted, but the application will be privately distributed so if the process would violate the terms of Google Play but would still work I am open to the options.

I have tested on a rooted phone and it looks like I can do something like:

Process p = Runtime.getRuntime().exec(String[] { "su", "-c", "echo 0 > /sys/bus/usb/drivers/usb/usb1/bConfigurationValue", });

to disconnect USB and :

p = Runtime.getRuntime().exec(String[] { "su", "-c", "echo 1 > /sys/bus/usb/drivers/usb/usb1/bConfigurationValue", });

to reconnect.

Also, I can do:

Process p = Runtime.getRuntime().exec(String[] { "su", "-c", "echo 0 > /sys/bus/usb/drivers/usb/usb1/authorized"", });

p = Runtime.getRuntime().exec(String[] { "su", "-c", "echo 1 > /sys/bus/usb/drivers/usb/usb1/authorized"", });

The issue with these methods is that they require root access. And short of causing my reprogramming app to secretly root the user's device to call these commands this will not work as part of my solution.

I looked in init.usb.rc, and it seems to set another flag: write /sys/class/android_usb/android0/enable 0

This does not seem to do what I am looking for. My guess is it only works at initializing. It seems that it is ran conditionally on sys.usb.config=adb or accessory or none... I am not seeing any place to update that value, especially without root access.

Another option I have investigated is using /system/bin/usbhub and /system/bin/usbhub_init. They do not seem to do anything even as root and when I look at the file what I can make out of the compiled code is the syntax looks like usbhub --off and usbhub --on. It looks like it only works if a specific gpio device or folder is present. I believe it was gpio56, /sys/class/gpio/gpio56/, which doesn't exist on any of my cache of phones or tablets.

I have also looked at the basic commands that are part of Android USBManager and UsbDeviceConnection.close() and UsbDeviceConnection.releaseInterface(). The application has been using a target of Android 4.4.2 (19?) but I have also looked at Lollipop and Marshmallow for updates to the API for USB. The only thing I saw was the ability to get and set a configuration and I attempted to modify that to cause the OS to believe the device had disconnected, which didn't work.

Really it is not that I need to trick my app or even the OS for that matter to think the device disconnected I need to have the device I am connecting to recognizing the disconnect.

I have chased many leads and went down far too many rabbit holes to count. If anyone has any other ideas I would welcome any advice or insight.

Thanks for reading my rant...



Category: usb on the go Time: 2016-07-29 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.163 (s). 12 q(s)