Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f840dd48 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

BatteryController: Remove the /sys prefix when adding UEvent listener

UEvent DEVPATHs don't contain the /sys prefix.

Bug: 243005009
Test: atest FrameworkServicesTests
Test: manual with USI 2.0 device
Change-Id: Iec6192f1e2afaee2736e5d442937be234da1d5e4
parent 00f72644
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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.
+5 −2
Original line number Diff line number Diff line
@@ -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.