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

Commit fe62154c authored by Soonil Nagarkar's avatar Soonil Nagarkar Committed by Automerger Merge Worker
Browse files

DO NOT MERGE: Revert "DO NOT MERGE: Revert "DO NOT MERGE: Lower bound...

DO NOT MERGE: Revert "DO NOT MERGE: Revert "DO NOT MERGE: Lower bound throttling interval"" am: 186d929e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16507258

Change-Id: Iee952b6738dfc181fd382a30c65ec9fdc9a50f20
parents ec6d4db3 186d929e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import static com.android.server.location.LocationManagerService.D;
import static com.android.server.location.LocationManagerService.TAG;
import static com.android.server.location.eventlog.LocationEventLog.EVENT_LOG;

import static java.lang.Math.max;

import android.annotation.Nullable;
import android.location.Location;
import android.location.LocationResult;
@@ -53,6 +55,7 @@ public final class StationaryThrottlingLocationProvider extends DelegateLocation
        implements DeviceIdleHelper.DeviceIdleListener, DeviceIdleInternal.StationaryListener {

    private static final long MAX_STATIONARY_LOCATION_AGE_MS = 30000;
    private static final long MIN_INTERVAL_MS = 1000;

    final Object mLock = new Object();

@@ -179,7 +182,7 @@ public final class StationaryThrottlingLocationProvider extends DelegateLocation
                && mLastLocation != null
                && mLastLocation.getElapsedRealtimeAgeMillis(mDeviceStationaryRealtimeMs)
                <= MAX_STATIONARY_LOCATION_AGE_MS) {
            throttlingIntervalMs = mIncomingRequest.getIntervalMillis();
            throttlingIntervalMs = max(mIncomingRequest.getIntervalMillis(), MIN_INTERVAL_MS);
        }

        ProviderRequest newRequest;
+21 −10
Original line number Diff line number Diff line
@@ -89,6 +89,19 @@ public class StationaryThrottlingLocationProviderTest {
        mProvider.getController().stop();
    }

    @Test
    public void testThrottle_lowInterval() {
        ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(0).build();

        mProvider.getController().setRequest(request);
        mDelegateProvider.reportLocation(createLocationResult("test_provider", mRandom));
        verify(mListener, times(1)).onReportLocation(any(LocationResult.class));

        mInjector.getDeviceStationaryHelper().setStationary(true);
        mInjector.getDeviceIdleHelper().setIdle(true);
        verify(mListener, after(1500).times(2)).onReportLocation(any(LocationResult.class));
    }

    @Test
    public void testThrottle_stationaryExit() {
        ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(50).build();
@@ -104,17 +117,16 @@ public class StationaryThrottlingLocationProviderTest {

        mInjector.getDeviceIdleHelper().setIdle(true);
        verify(mDelegate).onSetRequest(ProviderRequest.EMPTY_REQUEST);
        verify(mListener, timeout(75).times(2)).onReportLocation(any(LocationResult.class));
        verify(mListener, timeout(75).times(3)).onReportLocation(any(LocationResult.class));
        verify(mListener, timeout(1100).times(2)).onReportLocation(any(LocationResult.class));

        mInjector.getDeviceStationaryHelper().setStationary(false);
        verify(mDelegate, times(2)).onSetRequest(request);
        verify(mListener, after(75).times(3)).onReportLocation(any(LocationResult.class));
        verify(mListener, after(1000).times(2)).onReportLocation(any(LocationResult.class));
    }

    @Test
    public void testThrottle_idleExit() {
        ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(50).build();
        ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(1000).build();

        mProvider.getController().setRequest(request);
        verify(mDelegate).onSetRequest(request);
@@ -127,17 +139,16 @@ public class StationaryThrottlingLocationProviderTest {

        mInjector.getDeviceStationaryHelper().setStationary(true);
        verify(mDelegate).onSetRequest(ProviderRequest.EMPTY_REQUEST);
        verify(mListener, timeout(75).times(2)).onReportLocation(any(LocationResult.class));
        verify(mListener, timeout(75).times(3)).onReportLocation(any(LocationResult.class));
        verify(mListener, timeout(1100).times(2)).onReportLocation(any(LocationResult.class));

        mInjector.getDeviceIdleHelper().setIdle(false);
        verify(mDelegate, times(2)).onSetRequest(request);
        verify(mListener, after(75).times(3)).onReportLocation(any(LocationResult.class));
        verify(mListener, after(1000).times(2)).onReportLocation(any(LocationResult.class));
    }

    @Test
    public void testThrottle_NoInitialLocation() {
        ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(50).build();
        ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(1000).build();

        mProvider.getController().setRequest(request);
        verify(mDelegate).onSetRequest(request);
@@ -149,11 +160,11 @@ public class StationaryThrottlingLocationProviderTest {
        mDelegateProvider.reportLocation(createLocationResult("test_provider", mRandom));
        verify(mListener, times(1)).onReportLocation(any(LocationResult.class));
        verify(mDelegate, times(1)).onSetRequest(ProviderRequest.EMPTY_REQUEST);
        verify(mListener, timeout(75).times(2)).onReportLocation(any(LocationResult.class));
        verify(mListener, timeout(1100).times(2)).onReportLocation(any(LocationResult.class));

        mInjector.getDeviceStationaryHelper().setStationary(false);
        verify(mDelegate, times(2)).onSetRequest(request);
        verify(mListener, after(75).times(2)).onReportLocation(any(LocationResult.class));
        verify(mListener, after(1000).times(2)).onReportLocation(any(LocationResult.class));
    }

    @Test