I want to use android in industry,
I can connect to Profilic and Ftdi USB to Serial chips with slickdevlabs.com library without any problem.
The application has a service and it starts on boot,connect to the usb serial port and do the other things.
my problem is that the host device does not have any interaction with user,
so when the android asks
Allow the app "MyAPP" to access the USB device ?
[checkmark]Use by default for this USB device
Cancel OK
there is no person to click on ok.
even when I check the use by default... checkbox,If I reinsert the USB ,or reboot the host device, it asks again on next boot.
I ran the service and app with SuperUser mode,but no difference,it asks again.
I added intent filter but no difference,it asks me every time.
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
android:resource="@xml/device_filter" />
Any opinion how to bypass or disable it ?
I have root and SU access.
I know it's a bit late, but still...
I had the same kind of problem and I think I've managed to solve it. There's a service that Android uses internally that allows to manage USB devices and accessories. This service is hidden from thrid party developers and is not documented. If you check the source code for UsbPermissionActivity you'll be able to figure out how that service is called. In order to call the service IUsbManager interface and ServiceManager class are employed. These are both hidden too, so you can't use them directly. But what you can do is to create their stubs with exactly the same names and in corresponding namespaces (packages). Then you'll be able to compile that code, while the runtime environment will use the real things.
The only requirement is that your application has to be a system one - that is it has to be located in /system/app/ directory. Since your device is rooted that shouldn't be a problem.
So you will have to add a package to your project: "android.hardware.usb" and put a file in it named "IUsbManager.java" with the following content:
Then another package: "android.os" with "ServiceManager.java":
Note that interfaces of these classes may change depending on the version of Android. In my case the version is 4.0.3. So if you have another version of Android and this code doesn't work you will have to check the source code for your particular version of OS.
Here's an example of using the service to grant permissions to all FTDI devices:
One more thing - you will have to add the following permission to your manifest (Lint might not like it but you can always change severity level in your project's properties):
If you have access to the Android source code, here is the code you need to disable the permission dialog
https://gitlab.tubit.tu-berlin.de/justus.beyer/streamagame_platform_frameworks_base/commit/e97b62ed0d4050acacbf54781435686ea28edd73
The code update above creates a config option you can use, or instead you can hardcode it using the value true in-place of
mDisablePermissionDialogs
to disable the permission dialog.In
services/usb/java/com/android/server/usb/UsbSettingsManager.java
@d_d_t aswer is great, but it dosen't work on Android > 4.2.2. Use this interface:
And modify the code adding user id:
I had the same problem, the permission popup appear everytime i plug the USB cable, to solve it i just added the filter in the manifest and the xml file for VID and PID, just make sure you've setup USB device filtering as suggested in the SO link above or as documented here, and you put the good VID and PID. It was my problem, i didn't put the VID and PID that match to my device
i had the same problem with the popup window and nobody to click on it. But i found a different solution (for rooted devices). The popup gets generated by android in the class UsbPermissionActivity (and that UsbPermissionActivity is started by the UsbSettingsManager). Look at the Android Sourcecode to see whats going on. The good thing here is, we can manipulate the bytecode of the UsbPermissionActivity to accept all UsbDevices. You need the tool Smali/Baksmali to do so. https://code.google.com/p/smali/
adb pull path/to/SystemUI.apk
java -jar baksmali.jar classes.dex
Find the file UsbPermissionActivity and inside of it find the line that says
invoke-virtual {p0}, Lcom/android/systemui/usb/UsbPermissionActivity;->setupAlert()V
Change this by commenting it out and adding two new lines
#invoke-virtual {p0}, Lcom/android/systemui/usb/UsbPermissionActivity;->setupAlert()V const/4 v0, 0x1 iput-boolean v0, p0, Lcom/android/systemui/usb/UsbPermissionActivity;->mPermissionGranted:Z invoke-virtual {p0}, Lcom/android/systemui/usb/UsbPermissionActivity;->finish()V
java -jar smali.jar -o classes.dex out
adb push services.jar path/to/SystemUI.apk
or if that doesnt work with a filemanager apAndroid is really not designed to support this kind of usage out of the box. Personally, for non-interactive usage, I'd be tempted to consider using the USB serial driver in the linux kernel and skipping the android USB apis. But you'd have to be in a position to seriously modify the android installation - change the kernel configuration and/or load a module, create device files and set their permissions or owners, possibly add a unix group and android permission for apps allowed to access it.
Or you can look through the android source and disable the user confirmation; but if you do not have a from-source android build for the device, this may be trickier than the linux-level idea, since adapting open source android to run on a vendor device can be non-trivial (unless someone already offers a from-source build that is sufficiently functional for the device in question)
Indicentally, root/su access does not apply to applications themselves - it only means that an application which knowns how to run whatever tool your root hack left behind, can start up a helper program that runs as root, but the application itself does not and cannot. Using root to install the app on the system partition might get you some atypical android permissions, but you'd have to check if there are any which would help you with the usb.