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

Commit 69821f9a authored by Yu-Han Yang's avatar Yu-Han Yang Committed by Android (Google) Code Review
Browse files

Merge "Avoid HIGH_ACCURACY request from stationary throttling" into main

parents eea95000 ba2c426e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static java.lang.Math.max;

import android.annotation.Nullable;
import android.location.Location;
import android.location.LocationRequest;
import android.location.LocationResult;
import android.location.provider.ProviderRequest;
import android.os.SystemClock;
@@ -179,6 +180,7 @@ public final class StationaryThrottlingLocationProvider extends DelegateLocation
    private void onThrottlingChangedLocked(boolean deliverImmediate) {
        long throttlingIntervalMs = INTERVAL_DISABLED;
        if (mDeviceStationary && mDeviceIdle && !mIncomingRequest.isLocationSettingsIgnored()
                && mIncomingRequest.getQuality() != LocationRequest.QUALITY_HIGH_ACCURACY
                && mLastLocation != null
                && mLastLocation.getElapsedRealtimeAgeMillis(mDeviceStationaryRealtimeMs)
                <= MAX_STATIONARY_LOCATION_AGE_MS) {
+19 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static org.mockito.MockitoAnnotations.initMocks;

import android.content.Context;
import android.location.Location;
import android.location.LocationRequest;
import android.location.LocationResult;
import android.location.provider.ProviderRequest;
import android.platform.test.annotations.Presubmit;
@@ -218,4 +219,22 @@ public class StationaryThrottlingLocationProviderTest {
        verify(mDelegate, never()).onSetRequest(ProviderRequest.EMPTY_REQUEST);
        verify(mListener, after(75).times(1)).onReportLocation(any(LocationResult.class));
    }

    @Test
    public void testNoThrottle_highAccuracy() {
        ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(
                50).setQuality(LocationRequest.QUALITY_HIGH_ACCURACY).build();

        mProvider.getController().setRequest(request);
        verify(mDelegate).onSetRequest(request);

        LocationResult loc = createLocationResult("test_provider", mRandom);
        mDelegateProvider.reportLocation(loc);
        verify(mListener, times(1)).onReportLocation(loc);

        mInjector.getDeviceStationaryHelper().setStationary(true);
        mInjector.getDeviceIdleHelper().setIdle(true);
        verify(mDelegate, never()).onSetRequest(ProviderRequest.EMPTY_REQUEST);
        verify(mListener, after(75).times(1)).onReportLocation(any(LocationResult.class));
    }
}