Search code examples
androidflutterpermissionsgpsusb

Bypass or prevent USB read permission each time after device reboot or usb ejection


I am making a GPS tracker for android tv and I am reading gps data from a serial port using U-box 7 GPS receiver. the device is set to turn off on the schedule time and after each restart, my app asks for USB read permission of GPS receiver when connected. is there any way to bypass it

I am using flutter and usb_serial package for it

My manifest looks like :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.geolocator">
    <uses-feature android:name="android.hardware.usb.host" />
    <uses-permission android:name="android.permission.INTERNET" />
   

   <application
        android:label="geolocator"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize"
            android:directBootAware="true">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
             
              android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
            android:resource="@xml/device_filter"
              />
            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"/>
                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
                <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>


Solution

  • First you need to find vender_id and product_id of device and specify it in device.xml and mention in manifest

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <!-- 0x0403 / 0x6001: FTDI FT232R UART -->
        <usb-device vendor-id="1027" product-id="24577" />
    
        <usb-device vendor-id="5446" product-id="423" />
        <usb-device vendor-id="3690" product-id="290" />
        
        <!-- 0x0403 / 0x6015: FTDI FT231X -->
      
    </resources>