2

I'm building an Android embedded system which requires direct use of USB devices. The app will start when the device boot up. However, when accessing USB device normally, I have to request permission first. I don't want that permission popup comes up. I know there is a way to use intent-filter to directly get permission after user authorize it the first time but I don't know if this is the most ideal way. My device is a rooted android development board so basically I can change anything in the system. I know all the permission data is stored in /data/system/packages.xml but the USB permission is not real user-permission. I want to know if there is a place like /data/system/packages.xml that stores all the usb permissions like this:

For app: com.aaa.app, vendorId="1111" and productId="1111", permission="true". 

I think there should be such a place to store this info cus the intent filter needs this. Anyone knows which file I should look at in the system? Thanks

Community
  • 1
  • 1
York Yang
  • 527
  • 7
  • 13

1 Answers1

3

After some investigation, finally found the place where this file is stored by myself. If you look at Android source code and locate com.android.server.usb.UsbSettingsManager (https://github.com/android/platform_frameworks_base/blob/4b1a8f46d6ec55796bf77fd8921a5a242a219278/services/usb/java/com/android/server/usb/UsbSettingsManager.java), all the USB related permission functions are here. And then you can search for mSettingsFile, you will find some code lines:

mSettingsFile = new AtomicFile(new File(
            Environment.getUserSystemDirectory(user.getIdentifier()),
            "usb_device_manager.xml"));

Then dig into the Environment class getUserSystemDirectory method, you will find the usb_device_manager.xml file is usually (system and ENV variable dependent if you look at the source code of Environment) located at

/data/system/users/0/usb_device_manager.xml

where 0 is the userId. This may very in your case. If I give the app the USB permit, then inside the file, it will show like this:

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<settings>
    <preference package="com.xxxx.testusb">
        <usb-device vendor-id="1003" product-id="9220" class="0" subclass="0" protocol="0" manufacturer-name="Unknown" product-name="BlendMicro 8MHz" serial-number="" />
    </preference>
</settings>

If you uninstall this app, then this entry will be removed automatically.

Here is a more detailed explanation I found just now. https://groups.google.com/forum/#!topic/android-platform/3duEI8rFERo

York Yang
  • 527
  • 7
  • 13
  • and how can it help to bypass permission dialog (pop-up)? – user924 Aug 23 '19 at 07:09
  • even when your app doesn't have permission for the device you still have this device info in usb_device_manager.xml for your app – user924 Aug 23 '19 at 07:10
  • @user924 I pushed the permission after change "usb_device_manager.xml" and restart device. And that worked, no dialog popup – Jamebes Nov 14 '22 at 02:53