You've already forked FIDO2_Bridge
mirror of
https://github.com/token2/FIDO2_Bridge.git
synced 2026-03-13 11:12:26 -07:00
Detect already-connected USB device in main activity
This commit is contained in:
@@ -185,6 +185,9 @@ class MainActivity : AppCompatActivity() {
|
||||
registerReceiver(usbAttachReceiver, usbAttachFilter)
|
||||
}
|
||||
|
||||
// Auto-connect to already-plugged USB FIDO devices
|
||||
checkForUsbDevice()
|
||||
|
||||
// Check if started by USB device attachment
|
||||
if (intent.action == UsbManager.ACTION_USB_DEVICE_ATTACHED) {
|
||||
val device = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
@@ -310,6 +313,30 @@ class MainActivity : AppCompatActivity() {
|
||||
showDeviceSelectionDialog(devices)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for already-plugged USB FIDO devices and connect if found.
|
||||
* Only connects if there's exactly one device and we're not already connected.
|
||||
*/
|
||||
private fun checkForUsbDevice() {
|
||||
// Skip if already connected
|
||||
if (currentTransport?.isConnected == true) {
|
||||
return
|
||||
}
|
||||
|
||||
val devices = usbManager.deviceList.values
|
||||
.filter { UsbTransport.isFidoDevice(it) }
|
||||
|
||||
// Only auto-connect if exactly one FIDO device is found
|
||||
if (devices.size == 1) {
|
||||
val device = devices.first()
|
||||
if (usbManager.hasPermission(device)) {
|
||||
connectToUsbDevice(device)
|
||||
} else {
|
||||
requestUsbPermission(device)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showDeviceSelectionDialog(devices: Collection<UsbDevice>) {
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_usb_devices, null)
|
||||
val recyclerView = dialogView.findViewById<RecyclerView>(R.id.deviceList)
|
||||
|
||||
Reference in New Issue
Block a user