Skip to content

Commit a17ce25

Browse files
authored
Remove LocationValidator and force last Location if found (#1498)
1 parent f5d976f commit a17ce25

File tree

7 files changed

+43
-128
lines changed

7 files changed

+43
-128
lines changed

libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/location/LocationValidator.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/MapboxNavigationOptions.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public abstract class MapboxNavigationOptions {
3232
@NavigationTimeFormat.Type
3333
public abstract int timeFormatType();
3434

35-
public abstract int locationAcceptableAccuracyInMetersThreshold();
36-
3735
public abstract int navigationLocationEngineIntervalLagInMilliseconds();
3836

3937
public abstract Builder toBuilder();
@@ -55,8 +53,6 @@ public abstract static class Builder {
5553

5654
public abstract Builder timeFormatType(@NavigationTimeFormat.Type int type);
5755

58-
public abstract Builder locationAcceptableAccuracyInMetersThreshold(int accuracyInMetersThreshold);
59-
6056
public abstract Builder navigationLocationEngineIntervalLagInMilliseconds(int lagInMilliseconds);
6157

6258
public abstract MapboxNavigationOptions build();
@@ -70,7 +66,6 @@ public static Builder builder() {
7066
.isDebugLoggingEnabled(false)
7167
.roundingIncrement(ROUNDING_INCREMENT_FIFTY)
7268
.timeFormatType(NavigationTimeFormat.NONE_SPECIFIED)
73-
.locationAcceptableAccuracyInMetersThreshold(NavigationConstants.ONE_HUNDRED_METER_ACCEPTABLE_ACCURACY_THRESHOLD)
7469
.navigationLocationEngineIntervalLagInMilliseconds(NAVIGATION_LOCATION_ENGINE_INTERVAL_LAG);
7570
}
7671
}

libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationConstants.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,6 @@ private NavigationConstants() {
112112
*/
113113
public static final int NAVIGATION_HIGH_ALERT_DURATION = 15;
114114

115-
/**
116-
* Default location acceptable accuracy threshold
117-
* used in {@link com.mapbox.services.android.navigation.v5.location.LocationValidator}.
118-
* <p>
119-
* If a new {@link android.location.Location} update is received from the LocationEngine that has
120-
* an accuracy less than this threshold, the update will be considered valid and all other validation
121-
* is not considered.
122-
*
123-
* @since 0.17.0
124-
*/
125-
static final int ONE_HUNDRED_METER_ACCEPTABLE_ACCURACY_THRESHOLD = 100;
126-
127115
/**
128116
* Default approximate location engine interval lag in milliseconds
129117
* <p>
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
package com.mapbox.services.android.navigation.v5.navigation;
22

3+
import android.annotation.SuppressLint;
34
import android.location.Location;
45

56
import com.mapbox.android.core.location.LocationEngine;
67
import com.mapbox.android.core.location.LocationEngineListener;
7-
import com.mapbox.services.android.navigation.v5.location.LocationValidator;
88

99
class NavigationLocationEngineListener implements LocationEngineListener {
1010

1111
private final RouteProcessorBackgroundThread thread;
1212
private final LocationEngine locationEngine;
13-
private final LocationValidator validator;
1413

15-
NavigationLocationEngineListener(RouteProcessorBackgroundThread thread, LocationEngine locationEngine,
16-
LocationValidator validator) {
14+
NavigationLocationEngineListener(RouteProcessorBackgroundThread thread, LocationEngine locationEngine) {
1715
this.thread = thread;
1816
this.locationEngine = locationEngine;
19-
this.validator = validator;
2017
}
2118

2219
@Override
2320
@SuppressWarnings("MissingPermission")
2421
public void onConnected() {
2522
locationEngine.requestLocationUpdates();
23+
sendLastKnownLocation();
2624
}
2725

2826
@Override
@@ -32,7 +30,11 @@ public void onLocationChanged(Location location) {
3230
}
3331
}
3432

35-
boolean isValidLocationUpdate(Location location) {
36-
return location != null && validator.isValidUpdate(location);
33+
@SuppressLint("MissingPermission")
34+
private void sendLastKnownLocation() {
35+
Location lastLocation = locationEngine.getLastLocation();
36+
if (lastLocation != null) {
37+
onLocationChanged(lastLocation);
38+
}
3739
}
3840
}

libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationService.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import com.mapbox.android.core.location.LocationEngine;
1212
import com.mapbox.api.directions.v5.models.DirectionsRoute;
13-
import com.mapbox.services.android.navigation.v5.location.LocationValidator;
1413
import com.mapbox.services.android.navigation.v5.navigation.notification.NavigationNotification;
1514
import com.mapbox.services.android.navigation.v5.route.FasterRoute;
1615
import com.mapbox.services.android.navigation.v5.route.RouteFetcher;
@@ -120,11 +119,7 @@ private void initializeRouteProcessorThread(MapboxNavigation mapboxNavigation,
120119

121120
private void initializeLocationProvider(MapboxNavigation mapboxNavigation) {
122121
LocationEngine locationEngine = mapboxNavigation.getLocationEngine();
123-
int accuracyThreshold = mapboxNavigation.options().locationAcceptableAccuracyInMetersThreshold();
124-
LocationValidator validator = new LocationValidator(accuracyThreshold);
125-
NavigationLocationEngineListener listener = new NavigationLocationEngineListener(
126-
thread, locationEngine, validator
127-
);
122+
NavigationLocationEngineListener listener = new NavigationLocationEngineListener(thread, locationEngine);
128123
locationUpdater = new NavigationLocationEngineUpdater(locationEngine, listener);
129124
}
130125

libandroid-navigation/src/test/java/com/mapbox/services/android/navigation/v5/location/LocationValidatorTest.java

Lines changed: 0 additions & 58 deletions
This file was deleted.

libandroid-navigation/src/test/java/com/mapbox/services/android/navigation/v5/navigation/NavigationLocationEngineListenerTest.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import android.location.Location;
44

55
import com.mapbox.android.core.location.LocationEngine;
6-
import com.mapbox.services.android.navigation.v5.location.LocationValidator;
76

87
import org.junit.Test;
98

109
import static org.mockito.Mockito.mock;
1110
import static org.mockito.Mockito.verify;
11+
import static org.mockito.Mockito.verifyZeroInteractions;
12+
import static org.mockito.Mockito.when;
1213

1314
public class NavigationLocationEngineListenerTest {
1415

@@ -22,6 +23,35 @@ public void onConnected_engineRequestsUpdates() {
2223
verify(locationEngine).requestLocationUpdates();
2324
}
2425

26+
@Test
27+
public void onConnected_nonNullLastLocationIsSent() {
28+
LocationEngine locationEngine = mock(LocationEngine.class);
29+
Location location = mock(Location.class);
30+
when(locationEngine.getLastLocation()).thenReturn(location);
31+
RouteProcessorBackgroundThread thread = mock(RouteProcessorBackgroundThread.class);
32+
NavigationLocationEngineListener listener = new NavigationLocationEngineListener(
33+
thread, locationEngine
34+
);
35+
36+
listener.onConnected();
37+
38+
verify(thread).updateRawLocation(location);
39+
}
40+
41+
@Test
42+
public void onConnected_nullLastLocationIsIgnored() {
43+
LocationEngine locationEngine = mock(LocationEngine.class);
44+
when(locationEngine.getLastLocation()).thenReturn(null);
45+
RouteProcessorBackgroundThread thread = mock(RouteProcessorBackgroundThread.class);
46+
NavigationLocationEngineListener listener = new NavigationLocationEngineListener(
47+
thread, locationEngine
48+
);
49+
50+
listener.onConnected();
51+
52+
verifyZeroInteractions(thread);
53+
}
54+
2555
@Test
2656
public void queueValidLocationUpdate_threadReceivesUpdate() {
2757
RouteProcessorBackgroundThread thread = mock(RouteProcessorBackgroundThread.class);
@@ -34,12 +64,10 @@ public void queueValidLocationUpdate_threadReceivesUpdate() {
3464
}
3565

3666
private NavigationLocationEngineListener buildListener(RouteProcessorBackgroundThread thread) {
37-
return new NavigationLocationEngineListener(thread, mock(LocationEngine.class),
38-
mock(LocationValidator.class));
67+
return new NavigationLocationEngineListener(thread, mock(LocationEngine.class));
3968
}
4069

4170
private NavigationLocationEngineListener buildListener(LocationEngine locationEngine) {
42-
return new NavigationLocationEngineListener(mock(RouteProcessorBackgroundThread.class),
43-
locationEngine, mock(LocationValidator.class));
71+
return new NavigationLocationEngineListener(mock(RouteProcessorBackgroundThread.class), locationEngine);
4472
}
4573
}

0 commit comments

Comments
 (0)