diff options
| author | 2024-01-25 18:18:48 +0000 | |
|---|---|---|
| committer | 2024-01-25 23:21:58 +0000 | |
| commit | ba2c426e36593b2bb6071987b903b7038b4cc91c (patch) | |
| tree | aae9e7f2c83a96d13c444da7359f7a3f92c5f807 | |
| parent | 55e27576181f3a252c8e54a5a777ad52f2b64f99 (diff) | |
Avoid HIGH_ACCURACY request from stationary throttling
Bug: 319054085
Test: atest StationThrottlingLocationProviderTest
Change-Id: I33e945b62c660db7e0ecce45ca6959213cd64bf4
2 files changed, 21 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/location/provider/StationaryThrottlingLocationProvider.java b/services/core/java/com/android/server/location/provider/StationaryThrottlingLocationProvider.java index 5e38bca78a7c..2522f7b82353 100644 --- a/services/core/java/com/android/server/location/provider/StationaryThrottlingLocationProvider.java +++ b/services/core/java/com/android/server/location/provider/StationaryThrottlingLocationProvider.java @@ -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) { diff --git a/services/tests/mockingservicestests/src/com/android/server/location/provider/StationaryThrottlingLocationProviderTest.java b/services/tests/mockingservicestests/src/com/android/server/location/provider/StationaryThrottlingLocationProviderTest.java index 4eba21934a4e..efab19cc9663 100644 --- a/services/tests/mockingservicestests/src/com/android/server/location/provider/StationaryThrottlingLocationProviderTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/location/provider/StationaryThrottlingLocationProviderTest.java @@ -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)); + } } |