Skip to content

Consolidate Windows UsbDevice twin and simplify getUsbDevices() OS-wide - #3447

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-usbdevice
Jul 11, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-usbdevice

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

Third subsystem in the cross-OS consistency/dedup audit. No user-facing change — the public HardwareAbstractionLayer.getUsbDevices(tree) is unchanged; this is internal consolidation.

Three coordinated changes:

1. Merge the Windows JNA↔FFM twin

WindowsUsbDeviceJNA and WindowsUsbDeviceFFM were fully-duplicated value + tree-building classes (Windows was the only USB platform without a shared class). The WinAPI device tree is already abstracted behind the DeviceTree/DeviceTreeFFM drivers, so they differed only in which driver they call + the GUID type. Merged into one WindowsUsbDevice (oshi-common) that takes the device-tree query as a Supplier — the same "pass the query in" pattern AixUsbDevice already uses. Each Windows HAL passes its JNA/FFM driver + GUID. −2 classes.

2. Simplify getUsbDevices() OS-wide

PR #3443 moved the tree→flat derivation into AbstractHardwareAbstractionLayer.getUsbDevices(tree) (which always calls the platform method with tree=true and flattens itself). That made the boolean tree parameter + the identical if(!tree){ flatten } branch in every platform static method dead code. Dropped them — each platform now returns the controller tree; the HAL derives flat. Updated all ~17 HAL createUsbDevices() callers (getUsbDevices(true) → getUsbDevices(), AIX keeps its lscfg).

3. Dedup the flatten helper

AbstractHardwareAbstractionLayer had a private addDevicesToList identical to AbstractUsbDevice.addDevicesToList. Collapsed to the latter (same package).

Scope / deferred

  • Linux + Mac JNA/FFM twins keep their classes. Unlike Windows, their udev/IORegistry enumeration is inline (no pre-existing driver) with different native APIs and different resource lifecycles (JNA try/finally + unref vs FFM NativeHandle/arena). That's a real native abstraction (a UdevProvider-style hook), not a mechanical merge — split to a focused follow-up (#3b). Mac IORegistry after that.

31 files, large net reduction. Gate + clean full build green. Part of the subsystem-by-subsystem audit; follows #3445 (FileSystem) and #3446 (OSThread).

Summary by CodeRabbit

  • New Features

    • USB enumeration now consistently returns controller-based device trees across supported platforms.
    • USB device listings are flattened by the hardware abstraction layer when needed, providing consistent results to applications.
    • Windows USB discovery now uses a shared device-tree approach.
  • Bug Fixes

    • Improved consistency and reliability of USB device discovery across native backends and operating systems.

Third subsystem in the cross-OS consistency audit. Three coordinated changes:

- Merge WindowsUsbDeviceJNA/FFM into a single WindowsUsbDevice (oshi-common).
  The WinAPI device tree is already abstracted in the DeviceTree/DeviceTreeFFM
  drivers, so the merged class takes the query as a Supplier passed by the HAL
  (the AixUsbDevice pattern); each Windows HAL passes its JNA/FFM driver + GUID.

- Simplify getUsbDevices() across every platform. Since #3443 moved the
  tree/flat derivation into AbstractHardwareAbstractionLayer (which always calls
  the platform method with tree=true and flattens itself), the boolean tree
  parameter and the identical flatten branch in each platform static method were
  dead. Drop them: each returns the controller tree; the HAL derives flat.
  Updated all HAL createUsbDevices() callers.

- Dedup the flatten helper: AbstractHardwareAbstractionLayer's private
  addDevicesToList duplicated AbstractUsbDevice.addDevicesToList; reuse the
  latter (same package).

No user-facing change: the public HardwareAbstractionLayer.getUsbDevices(tree)
is unchanged. Linux/Mac JNA/FFM twins keep their classes; their udev/IORegistry
native abstraction is a careful follow-up.
@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bc6be97f-b6fb-4a85-bf97-5b09edf7e0e5

📥 Commits

Reviewing files that changed from the base of the PR and between 131f2cd and b7e2384.

📒 Files selected for processing (30)
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsUsbDevice.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDeviceJNA.java
💤 Files with no reviewable changes (1)
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDeviceJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (12)
  • GitHub Check: CodeRabbit
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHardwareAbstractionLayer.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdUsbDevice.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixUsbDevice.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixUsbDevice.java
📚 Learning: 2026-04-06T21:48:09.616Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:85-111
Timestamp: 2026-04-06T21:48:09.616Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java` and `MacUsbDeviceFFM.java`, treat `id = 0L` as an intentional sentinel when `device.getParentEntry(IOSERVICE)` returns null. This catch-all value groups devices whose controller cannot be identified (even though that edge case is expected not to occur). Do not review it as a bug, do not suggest skipping those devices, and do not propose moving them to the top level without controller context—this design explicitly avoids silently dropping orphaned devices and preserves controller-grouping behavior.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: For OSHI Linux USB device implementations, the behavior of `getUsbDevices(boolean tree)` with `tree=false` is intentional: the returned flat list includes controller nodes (it is not meant to exclude them). In code review, do not flag the implementation for including controllers in flat mode; instead, only flag/update documentation/JavaDoc that incorrectly claims controllers are excluded (e.g., Javadoc text like "returns a flat list excluding controllers" should be corrected).

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
🔇 Additional comments (32)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsUsbDevice.java (2)

44-63: LGTM!


65-104: LGTM!

oshi-common/src/main/java/oshi/hardware/common/AbstractHardwareAbstractionLayer.java (1)

144-148: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.java (1)

28-35: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.java (1)

34-39: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisUsbDevice.java (1)

34-39: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java (1)

79-79: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerJNA.java (1)

91-91: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdUsbDevice.java (1)

31-35: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixUsbDevice.java (1)

31-36: LGTM!

Also applies to: 48-48

oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java (1)

45-50: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java (1)

58-58: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java (1)

45-50: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java (1)

72-72: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerJNA.java (1)

79-79: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java (1)

56-56: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java (1)

73-73: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerFFM.java (1)

73-73: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java (1)

46-51: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerFFM.java (1)

90-90: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java (1)

83-83: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java (1)

82-85: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerFFM.java (1)

77-80: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerFFM.java (1)

75-78: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerFFM.java (1)

74-77: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java (1)

40-47: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.java (1)

76-79: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerJNA.java (1)

78-81: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java (2)

10-10: LGTM!

Also applies to: 26-26


80-87: LGTM!

GUID byte array correctly encodes {3ABF6F2D-71C4-462A-8A92-1E6861E6AF27} in Windows mixed-endian format (Data1–Data3 little-endian, Data4 big-endian), with appropriate byte casts for values > 0x7F. The supplier pattern cleanly delegates device-tree querying to the shared WindowsUsbDevice builder.

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerJNA.java (2)

9-12: LGTM!

Also applies to: 28-28


81-86: LGTM!

JNA GUID string constructor cleanly handles the mixed-endian encoding. The supplier pattern mirrors the FFM backend, ensuring contract consistency across both Windows implementations.


📝 Walkthrough

Walkthrough

USB enumeration now consistently exposes controller-rooted trees, with flat-list derivation centralized in the HAL. Linux, macOS, BSD, AIX, Solaris, and Windows callers use simplified APIs, while Windows shares tree construction across FFM and JNA backends.

Changes

USB enumeration refactor

Layer / File(s) Summary
Shared USB contracts and flattening
oshi-common/src/main/java/oshi/hardware/common/...
Platform USB helpers expose controller trees, and AbstractHardwareAbstractionLayer delegates flattening to AbstractUsbDevice.
Platform USB API and HAL wiring
oshi-common/src/main/java/oshi/hardware/common/platform/..., oshi-core/src/main/java/oshi/hardware/platform/..., oshi-core-ffm/src/main/java/oshi/hardware/platform/...
Linux, macOS, AIX, BSD, and Solaris enumeration methods and HAL callers remove the tree flag and use parameterless controller-tree retrieval.
Shared Windows USB tree builder
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsUsbDevice.java
WindowsUsbDevice accepts backend-supplied device-tree data and recursively constructs controller and child devices.
Windows backend integration
oshi-core/src/main/java/oshi/hardware/platform/windows/..., oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/...
Windows FFM and JNA HALs query host-controller device trees and pass them to the shared builder.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WindowsHAL
  participant DeviceTree
  participant WindowsUsbDevice
  WindowsHAL->>DeviceTree: query host-controller device tree
  DeviceTree-->>WindowsHAL: controller IDs and lookup maps
  WindowsHAL->>WindowsUsbDevice: supply device-tree data
  WindowsUsbDevice-->>WindowsHAL: recursively assembled USB tree
Loading

Possibly related PRs

  • oshi/oshi#3122: Introduced shared recursive USB flattening used by this change.
  • oshi/oshi#3443: Moved USB controller-tree caching and flat-list derivation into the HAL.

Poem

A bunny sees controllers bloom,
With child nodes hopping through the room.
Trees grow tall, flags fade away,
Shared builders guide the way.
Windows, Linux, BSD unite—
USB paths now feel just right! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main Windows USB consolidation and the broader getUsbDevices simplification across platforms.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.44%. Comparing base (131f2cd) to head (b7e2384).

Files with missing lines Patch % Lines
...ware/common/platform/windows/WindowsUsbDevice.java 40.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3447      +/-   ##
============================================
- Coverage     74.53%   74.44%   -0.09%     
  Complexity       76       76              
============================================
  Files           581      582       +1     
  Lines         21903    21913      +10     
  Branches       3669     3669              
============================================
- Hits          16325    16313      -12     
- Misses         3543     3562      +19     
- Partials       2035     2038       +3     
Flag Coverage Δ
freebsd 26.88% <13.04%> (-0.03%) ⬇️
linux 31.42% <21.73%> (-0.02%) ⬇️
macos 31.83% <13.04%> (-0.06%) ⬇️
openbsd 26.37% <13.04%> (-0.02%) ⬇️
solaris 28.40% <13.04%> (-0.04%) ⬇️
windows 39.86% <34.78%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant