Fix passive+coarse location bug
Passive requests require the min update interval to be set, so we should not be clearing the min update interval altogether when adjusting passive requests. Bug: 171949953 Test: Added new CTS/unit tests Change-Id: If50bee91aa18d8c3817d342b82d35478075a64cb
This commit is contained in:
@@ -491,7 +491,7 @@ class LocationProviderManager extends
|
||||
builder.setIntervalMillis(MIN_COARSE_INTERVAL_MS);
|
||||
}
|
||||
if (baseRequest.getMinUpdateIntervalMillis() < MIN_COARSE_INTERVAL_MS) {
|
||||
builder.clearMinUpdateIntervalMillis();
|
||||
builder.setMinUpdateIntervalMillis(MIN_COARSE_INTERVAL_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import static android.app.AppOpsManager.OP_MONITOR_LOCATION;
|
||||
import static android.location.Criteria.ACCURACY_COARSE;
|
||||
import static android.location.Criteria.ACCURACY_FINE;
|
||||
import static android.location.Criteria.POWER_HIGH;
|
||||
import static android.location.LocationRequest.PASSIVE_INTERVAL;
|
||||
import static android.os.PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF;
|
||||
|
||||
import static androidx.test.ext.truth.location.LocationSubject.assertThat;
|
||||
@@ -597,6 +598,38 @@ public class LocationProviderManagerTest {
|
||||
verify(mWakeLock, timeout(TIMEOUT_MS)).release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterListener_Coarse() throws Exception {
|
||||
ILocationListener listener = createMockLocationListener();
|
||||
mManager.registerLocationRequest(
|
||||
new LocationRequest.Builder(0).setWorkSource(WORK_SOURCE).build(),
|
||||
IDENTITY,
|
||||
PERMISSION_COARSE,
|
||||
listener);
|
||||
|
||||
mProvider.setProviderLocation(createLocation(NAME, mRandom));
|
||||
mProvider.setProviderLocation(createLocation(NAME, mRandom));
|
||||
verify(listener, times(1))
|
||||
.onLocationChanged(any(Location.class), nullable(IRemoteCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterListener_Coarse_Passive() throws Exception {
|
||||
ILocationListener listener = createMockLocationListener();
|
||||
mManager.registerLocationRequest(
|
||||
new LocationRequest.Builder(PASSIVE_INTERVAL)
|
||||
.setMinUpdateIntervalMillis(0)
|
||||
.setWorkSource(WORK_SOURCE).build(),
|
||||
IDENTITY,
|
||||
PERMISSION_COARSE,
|
||||
listener);
|
||||
|
||||
mProvider.setProviderLocation(createLocation(NAME, mRandom));
|
||||
mProvider.setProviderLocation(createLocation(NAME, mRandom));
|
||||
verify(listener, times(1))
|
||||
.onLocationChanged(any(Location.class), nullable(IRemoteCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurrentLocation() throws Exception {
|
||||
ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);
|
||||
|
||||
Reference in New Issue
Block a user