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

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

BatteryController: Use stable reference for handler callback

Since Java method references are not stable, we cannot use a method
reference to remove a callback that was posted before.

Bug: 349932775
Change-Id: Iea18f45708360c24715b7d0a8de6a19d9fea3ac3
Test: Presubmit
Flag: NONE bug fix
parent 929f8cad
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ final class BatteryController {
    private final Handler mHandler;
    private final UEventManager mUEventManager;
    private final BluetoothBatteryManager mBluetoothBatteryManager;
    private final Runnable mHandlePollEventCallback = this::handlePollEvent;

    // Maps a pid to the registered listener record for that process. There can only be one battery
    // listener per process.
@@ -206,7 +207,7 @@ final class BatteryController {
        if (!mIsInteractive || !anyOf(mDeviceMonitors, DeviceMonitor::requiresPolling)) {
            // Stop polling.
            mIsPolling = false;
            mHandler.removeCallbacks(this::handlePollEvent);
            mHandler.removeCallbacks(mHandlePollEventCallback);
            return;
        }

@@ -215,7 +216,7 @@ final class BatteryController {
        }
        // Start polling.
        mIsPolling = true;
        mHandler.postDelayed(this::handlePollEvent, delayStart ? POLLING_PERIOD_MILLIS : 0);
        mHandler.postDelayed(mHandlePollEventCallback, delayStart ? POLLING_PERIOD_MILLIS : 0);
    }

    private <R> R processInputDevice(int deviceId, R defaultValue, Function<InputDevice, R> func) {
@@ -366,7 +367,7 @@ final class BatteryController {
            }
            final long eventTime = SystemClock.uptimeMillis();
            mDeviceMonitors.forEach((deviceId, monitor) -> monitor.onPoll(eventTime));
            mHandler.postDelayed(this::handlePollEvent, POLLING_PERIOD_MILLIS);
            mHandler.postDelayed(mHandlePollEventCallback, POLLING_PERIOD_MILLIS);
        }
    }