bypass android usb host permission confirmation di

2020-01-24 10:51发布

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.

12条回答
霸刀☆藐视天下
2楼-- · 2020-01-24 11:09

I think we can do this by making some modifications in /etc/udev. We could add the vendor id and device id into the 51-android.rules file.

查看更多
何必那么认真
3楼-- · 2020-01-24 11:10

At the first time, when it needs confirm, you can select "always", then even if the Android device is powered down, and powered up, your app still has permission to access the USB2Serial. Just to say, only one time confirm!

查看更多
Evening l夕情丶
4楼-- · 2020-01-24 11:12

If you have the option to compile the android system, then there's nothing you cannot do.

You can add

public void onStart() {
    super.onStart();
    mPermissionGranted = true;

    finish();
}

to frameworks/base/packages/SystemUI/src/com/android/systemui/usb/UsbPermissionActivity.java

to bypass the the permission confirmation popup.

查看更多
SAY GOODBYE
5楼-- · 2020-01-24 11:13

I think white-listing the accessory you are using in advance will be the best solution. To do this you need to add the file usb_device_manager.xml at this location /data/system/users/0
// Note that 0 is user ID, it will probably be 0 if you didn't add more users in Android but if you did change this ID accordingly

This is how file should look:

<settings>
<preference package="<PACKAGE NAME OF APP YOU WANT TO START ON CONNECTIONCTION>">
    <usb-accessory manufacturer="<NAME OF MANUFECTURER LIKE ONE REGISTERED IN meta-data in the manifest>" model="<MODEL NAME LIKE ONE REGISTERED IN meta-data in the manifest>" version="<VERSION LIKE ONE REGISTERED IN meta-data in the manifest>" />
</preference>

For a board like this http://www.embeddedartists.com/products/app/aoa_kit.php it is:

 <?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<settings>
<preference package="com.embeddedartists.aoa">
    <usb-accessory manufacturer="Embedded Artists AB" model="AOA Board - Basic" version="1.0" />
</preference>

查看更多
我命由我不由天
6楼-- · 2020-01-24 11:13

One way to achieve this, note that this does not actually get rid of the confirmation, would be to pinpoint the location of the checkbox and use the Android equivalent of the Robot class to select it and then select OK. You could write a application that runs in the background, it could even be called by that startup service that you mentioned, specifically for this purpose.

查看更多
够拽才男人
7楼-- · 2020-01-24 11:20

According to the documentation on Android Developers you already have permission to the attached USB device when your app gets started trough your manifest intent filter. Perhaps you should try this approach and write a filter to exact match the device you want to use, to prevent that other apps also want to communicate with the device.

See the "Note" on http://developer.android.com/guide/topics/connectivity/usb/host.html#permission-d

查看更多
登录 后发表回答