diff --git a/services/core/java/com/android/server/input/BatteryController.java b/services/core/java/com/android/server/input/BatteryController.java index 696b6047137a6..44c031da81dd3 100644 --- a/services/core/java/com/android/server/input/BatteryController.java +++ b/services/core/java/com/android/server/input/BatteryController.java @@ -479,7 +479,12 @@ final class BatteryController { handleUEventNotification(deviceId, eventTime); } }; - mUEventManager.addListener(mUEventListener, "DEVPATH=" + batteryPath); + mUEventManager.addListener(mUEventListener, "DEVPATH=" + formatDevPath(batteryPath)); + } + + private String formatDevPath(String path) { + // Remove the "/sys" prefix if it has one. + return path.startsWith("/sys") ? path.substring(4) : path; } // This must be called when the device is no longer being monitored. diff --git a/services/tests/servicestests/src/com/android/server/input/BatteryControllerTests.kt b/services/tests/servicestests/src/com/android/server/input/BatteryControllerTests.kt index 5f3f3d7714ef7..5a3148e2b6969 100644 --- a/services/tests/servicestests/src/com/android/server/input/BatteryControllerTests.kt +++ b/services/tests/servicestests/src/com/android/server/input/BatteryControllerTests.kt @@ -260,13 +260,16 @@ class BatteryControllerTests { @Test fun testListenersNotifiedOnUEventNotification() { - `when`(native.getBatteryDevicePath(DEVICE_ID)).thenReturn("/test/device1") + `when`(native.getBatteryDevicePath(DEVICE_ID)).thenReturn("/sys/dev/test/device1") `when`(native.getBatteryStatus(DEVICE_ID)).thenReturn(STATUS_CHARGING) `when`(native.getBatteryCapacity(DEVICE_ID)).thenReturn(78) val listener = createMockListener() val uEventListener = ArgumentCaptor.forClass(UEventManager.UEventListener::class.java) batteryController.registerBatteryListener(DEVICE_ID, listener, PID) - verify(uEventManager).addListener(uEventListener.capture(), eq("DEVPATH=/test/device1")) + // The device paths for UEvent notifications do not include the "/sys" prefix, so verify + // that the added listener is configured to match the path without that prefix. + verify(uEventManager) + .addListener(uEventListener.capture(), eq("DEVPATH=/dev/test/device1")) listener.verifyNotified(DEVICE_ID, status = STATUS_CHARGING, capacity = 0.78f) // If the battery state has changed when an UEvent is sent, the listeners are notified.