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

Commit 29482e71 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

CP StationaryThrottling bugfixes from SC QPR1

Somehow these fixes were never merged into main (although the test
changes were? Very strange). Merge this fix which eliminates wasted
power from registering the SMD when not necessary.

Bug: 279879297
Test: atest StationaryThrottlingLocationProviderTest
Change-Id: I923573cd5e4735c74d896c4f16210ce62013e2fe
parent 4201d560
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -109,20 +109,15 @@ public final class StationaryThrottlingLocationProvider extends DelegateLocation

        synchronized (mLock) {
            mDeviceIdleHelper.addListener(this);
            mDeviceIdle = mDeviceIdleHelper.isDeviceIdle();
            mDeviceStationaryHelper.addListener(this);
            mDeviceStationary = false;
            mDeviceStationaryRealtimeMs = Long.MIN_VALUE;

            onThrottlingChangedLocked(false);
            onDeviceIdleChanged(mDeviceIdleHelper.isDeviceIdle());
        }
    }

    @Override
    protected void onStop() {
        synchronized (mLock) {
            mDeviceStationaryHelper.removeListener(this);
            mDeviceIdleHelper.removeListener(this);
            onDeviceIdleChanged(false);

            mIncomingRequest = ProviderRequest.EMPTY_REQUEST;
            mOutgoingRequest = ProviderRequest.EMPTY_REQUEST;
@@ -155,13 +150,26 @@ public final class StationaryThrottlingLocationProvider extends DelegateLocation
            }

            mDeviceIdle = deviceIdle;
            if (deviceIdle) {
                // device stationary helper will deliver an immediate listener update
                mDeviceStationaryHelper.addListener(this);
            } else {
                mDeviceStationaryHelper.removeListener(this);
                mDeviceStationary = false;
                mDeviceStationaryRealtimeMs = Long.MIN_VALUE;
                onThrottlingChangedLocked(false);
            }
        }
    }

    @Override
    public void onDeviceStationaryChanged(boolean deviceStationary) {
        synchronized (mLock) {
            if (!mDeviceIdle) {
                // stationary detection is only registered while idle - ignore late notifications
                return;
            }

            if (mDeviceStationary == deviceStationary) {
                return;
            }