Mastering USB Permissions
The "Always Allow" Checkbox
One of the most frustrating aspects of using Android with custom hardware is the relentless permission popup:
Allow MAVLink GPS to access [Device Name]?
Even if you check "Always open MAVLink GPS when ... is connected", the popup often returns the next day. Why?
The Anatomy of a Match (DeviceFilter)
When you check that box, Android creates a "Filter" based on the connected device's unique signature and saves it to a system XML file. To bypass the popup next time, the new connection must match every field in that saved filter.
The comparison logic is strict (AOSP DeviceFilter.java):
- Vendor ID (VID): Must match.
- Product ID (PID): Must match.
- Serial Number: Must match exactly (if stored).
The Serial Number Trap
This is where cheap Flight Controllers fail.
Scenario 1: The "Randomizer" (Bad)
Some bootloaders generate a random USB Serial Number on every boot to avoid conflicts.
- Day 1: You connect. Serial=
ABC-123. You check "Always Allow". Android saves[VID:1234, PID:5678, Serial:ABC-123]. - Day 2: You reboot the drone. Serial=
DEF-456. - The Check: Android compares
DEF-456vs storedABC-123. Mismatch. - Result: The permission is denied, and the popup appears again.
Scenario 2: The "Clone" (Good?)
Cheap clones often have no serial number or a generic one (00000000).
- If the device reports no serial, Android saves
[VID:1234, PID:5678, Serial:null]. - Any subsequent device with that VID/PID will match. This actually makes the "Always Allow" feature work reliably, albeit less securely.
Hardware Recommendations
To ensure a true "Plug and Fly" experience, use flight controllers from reputable manufacturers (Hex Cube, Holybro, mRo) that burn a unique, static UUID into the STM32 USB descriptor.
Source Code Reference
- Matching Logic:
frameworks/base/core/java/android/hardware/usb/DeviceFilter.java- See thematches(UsbDevice device)method.