Skip to content

Improve FIDO USB detection with HID descriptor parsing + fixes#285

Open
AdamVe wants to merge 4 commits intomainfrom
adamve/improve-android-fido-hid-detection
Open

Improve FIDO USB detection with HID descriptor parsing + fixes#285
AdamVe wants to merge 4 commits intomainfrom
adamve/improve-android-fido-hid-detection

Conversation

@AdamVe
Copy link
Member

@AdamVe AdamVe commented Feb 17, 2026

Summary

Improves FIDO USB device detection by parsing HID report descriptors to identify devices by their FIDO Alliance usage page (0xF1D0), replacing the previous interface subclass check. This ensures more reliable detection when USB devices have multiple HID interfaces.

Changes

🔧 Main Refactoring

  • FIDO USB Detection Enhancement
    • Parse HID report descriptors to verify FIDO Alliance usage page (0xF1D0)
    • Iterate through all HID interfaces with proper resource cleanup
    • Add fallback mechanism for descriptor length detection failures
    • Extract testable static methods with debug logging
    • Add comprehensive test suite (775 LOC, 92%+ branch coverage)

🐛 Bug Fixes

  • Thread Safety: Fix inconsistent synchronization in UsbDeviceManager using volatile keyword
  • API Visibility: Make DeviceFilter methods public to allow proper extension
  • Build Warnings: Suppress deprecation warnings for backward-compatible API usage

Why These Changes?

Problem

The previous implementation relied on interface subclass checks, which could fail to identify FIDO devices when:

  • USB devices have multiple HID interfaces (e.g., keyboard + FIDO authenticator)
  • Devices don't follow strict subclass conventions

Solution

By parsing the HID report descriptor and checking for the FIDO usage page (0xF1D0), we accurately identify FIDO-capable interfaces regardless of subclass value or other interfaces present.

Testing

  • ✅ New comprehensive unit test suite with JUnit @RunWith(Enclosed.class) pattern
  • ✅ 92%+ branch coverage including edge cases and error paths
  • ✅ All tests use mocked USB stack for fast, isolated testing
  • ✅ Existing integration tests pass

Breaking Changes

None. The changes are backward compatible.

Commits

  1. refactor: FIDO USB detection with HID parsing - Main improvement
  2. fix: resolve inconsistent synchronization - SpotBugs IS2 warning fix
  3. fix: make DeviceFilter methods public - API visibility correction
  4. fix: suppress deprecation warnings for backward compatibility - Build warning cleanup

- Replace subclass check with HID usage page (0xF1D0) detection
- Iterate all HID interfaces with proper resource cleanup
- Add fallback for descriptor length read failures
- Add comprehensive test suite

Fixes reliability issues when USB devices have multiple HID interfaces.
Replace synchronized access with volatile keyword to fix inconsistent
synchronization warning. Volatile is sufficient for this replace-only
field pattern.

Fixes SpotBugs IS2 warning
Change checkVendorProductIds() and checkUsbDevice() from package-private
to public visibility. These methods are intended to be overridden by
custom DeviceFilter implementations and require public access.

Also update YubicoVendorFilter override to maintain consistency.
Add suppressions for getParcelableExtra() backward compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments