EventHub: Reimplement sysfsNodeChanged
There were several bugs in the old implementation of sysfsNodeChanged.
There are unfortunately no existing unit tests for EventHub, so the old
code and the new code are not tested exhaustively.
Issues addressed:
- The old code would concurrently modify mOpeningDevices while iterating
through it, making the code difficult to reason about, particularly
since calling openDeviceLocked() from the iteration would add an
additional opening device.
- The old code was improperly erasing items from mOpeningDevices.
vector::erase() returns the next iterator position after the removal,
and when progressing to the next for loop iteration, the iterator is
incremented again, leading to a missed element.
- Each call to isChanged() involves several syscalls, and the old code
would perform the check multiple times on the same AssociatedDevice
object. Note that for each changed sysfs node, the sysfs node is
reloaded yet again for each openDeviceLocked() call, which this CL
does not address.
Bug: 245989146
Test: atest SonyDualshock4BluetoothTest --iterations
Test: Presubmit
Flag: EXEMPT refactor/bug fix
Change-Id: Iaec9079d8c888310f6d8e496b9dd9df231aff228
2 files changed