Skip to content

Commit

Permalink
Avoid HIGH_ACCURACY request from stationary throttling
Browse files Browse the repository at this point in the history
Bug: 319054085

Test: atest StationThrottlingLocationProviderTest
Change-Id: I33e945b62c660db7e0ecce45ca6959213cd64bf4

Tracked-On: OAM-122224
Signed-off-by: Yu-Han Yang <[email protected]>
  • Loading branch information
Yu-Han Yang authored and sysopenci committed Jul 12, 2024
1 parent 13ed7cb commit 326baed
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
From a44c43c7251f66ab82302f52a7b416485f6358b7 Mon Sep 17 00:00:00 2001
From: Yu-Han Yang <[email protected]>
Date: Thu, 11 Jul 2024 12:03:35 +0530
Subject: [PATCH] Avoid HIGH_ACCURACY request from stationary throttling

Bug: 319054085
Test: atest StationThrottlingLocationProviderTest
Change-Id: I33e945b62c660db7e0ecce45ca6959213cd64bf4
---
.../StationaryThrottlingLocationProvider.java | 2 ++
...tionaryThrottlingLocationProviderTest.java | 19 +++++++++++++++++++
2 files changed, 21 insertions(+)

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..da7c65ab2611 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));
+ }
}
--
2.25.1

0 comments on commit 326baed

Please sign in to comment.