Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ ext {

version = [
mapboxMapSdk : '5.1.4',
mapboxServices : '2.2.6',
// TODO Fix mapboxServices version when PR https://github.com/mapbox/mapbox-java/pull/605 lands
mapboxServices : '2.3.0-SNAPSHOT',
locationLayerPlugin: '0.1.0',
autoValue : '1.4.1',
autoValueParcel : '0.2.5',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import android.location.Location;
import android.preference.PreferenceManager;

import com.mapbox.mapboxsdk.location.LocationSource;
import com.mapbox.services.android.location.MockLocationEngine;
import com.mapbox.services.android.navigation.v5.navigation.NavigationConstants;
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
import com.mapbox.services.android.telemetry.location.LostLocationEngine;
import com.mapbox.services.api.directions.v5.models.DirectionsRoute;

public class LocationViewModel extends AndroidViewModel implements LifecycleObserver, LocationEngineListener {
Expand Down Expand Up @@ -91,7 +91,7 @@ void updateRoute(DirectionsRoute route) {
@SuppressWarnings( {"MissingPermission"})
private void initLocation(Application application) {
if (!shouldSimulateRoute()) {
modelLocationEngine = new LocationSource(application.getApplicationContext());
modelLocationEngine = new LostLocationEngine(application.getApplicationContext());
modelLocationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
modelLocationEngine.setFastestInterval(1000);
modelLocationEngine.setInterval(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class MapboxNavigation implements ServiceConnection, ProgressChangeListen
private DirectionsRoute directionsRoute;
private MapboxNavigationOptions options;
private LocationEngine locationEngine;
private String locationEngineName;
private List<Milestone> milestones;
private SessionState sessionState;
private final String accessToken;
Expand Down Expand Up @@ -182,6 +183,7 @@ private void initializeDefaultLocationEngine() {
locationEngine.setFastestInterval(1000);
locationEngine.setInterval(0);
locationEngine.activate();
locationEngineName = obtainLocationEngineName();
}

/**
Expand Down Expand Up @@ -306,6 +308,7 @@ public void removeMilestone(int milestoneIdentifier) {
*/
public void setLocationEngine(@NonNull LocationEngine locationEngine) {
this.locationEngine = locationEngine;
locationEngineName = obtainLocationEngineName();
// Notify service to get new location engine.
if (isServiceAvailable()) {
navigationService.acquireLocationEngine();
Expand Down Expand Up @@ -628,7 +631,7 @@ public OffRoute getOffRouteEngine() {
public void onProgressChange(Location location, RouteProgress routeProgress) {
Timber.v("Arrived event occurred");
sessionState = sessionState.toBuilder().arrivalTimestamp(new Date()).build();
NavigationMetricsWrapper.arriveEvent(sessionState, routeProgress, location);
NavigationMetricsWrapper.arriveEvent(sessionState, routeProgress, location, locationEngineName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cammace would it make sense to move the arrive event to NavigationService like the rest of the events? That way most of the current changes to this class could be self contained within NavigationService. @Guardiola31337

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't immediately see any issue with moving the entire onProgressChange into NavigationService` to keep all the events in the same class. Though I think whichever path we take, we should only have 1 internal onProgressChange to keep things simple. Let's do this in a different PR and go ahead and merge this one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cammace @ericrwolfe
Follow up ticket 👉 #402

// Remove all listeners except the onProgressChange by passing in null.
navigationEventDispatcher.removeOffRouteListener(null);
// Remove this listener so that the arrival event only occurs once.
Expand Down Expand Up @@ -682,4 +685,8 @@ public void onServiceDisconnected(ComponentName name) {
navigationService = null;
isBound = false;
}

private String obtainLocationEngineName() {
return locationEngine.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.mapbox.services.android.telemetry.navigation.MapboxNavigationEvent;
import com.mapbox.services.android.telemetry.utils.TelemetryUtils;

import java.util.Hashtable;
import java.util.List;

class NavigationMetricsWrapper {
Expand All @@ -18,8 +19,9 @@ private NavigationMetricsWrapper() {
// Empty private constructor for preventing initialization of this class.
}

static void arriveEvent(SessionState sessionState, RouteProgress routeProgress, Location location) {
MapboxTelemetry.getInstance().pushEvent(MapboxNavigationEvent.buildArriveEvent(
static void arriveEvent(SessionState sessionState, RouteProgress routeProgress, Location location,
String locationEngineName) {
Hashtable<String, Object> arriveEvent = MapboxNavigationEvent.buildArriveEvent(
sdkIdentifier, BuildConfig.MAPBOX_NAVIGATION_VERSION_NAME,
sessionState.sessionIdentifier(), location.getLatitude(), location.getLongitude(),
sessionState.currentGeometry(), "unknown",
Expand All @@ -32,11 +34,14 @@ static void arriveEvent(SessionState sessionState, RouteProgress routeProgress,
sessionState.originalGeometry(), sessionState.originalDistance(),
sessionState.originalDuration(), null, sessionState.currentStepCount(),
sessionState.originalStepCount()
));
);
MapboxTelemetry.getInstance().addLocationEngineName(locationEngineName, arriveEvent);
MapboxTelemetry.getInstance().pushEvent(arriveEvent);
}

static void cancelEvent(SessionState sessionState, RouteProgress routeProgress, Location location) {
MapboxTelemetry.getInstance().pushEvent(MapboxNavigationEvent.buildCancelEvent(
static void cancelEvent(SessionState sessionState, RouteProgress routeProgress, Location location,
String locationEngineName) {
Hashtable<String, Object> cancelEvent = MapboxNavigationEvent.buildCancelEvent(
sdkIdentifier, BuildConfig.MAPBOX_NAVIGATION_VERSION_NAME,
sessionState.sessionIdentifier(),
location.getLatitude(), location.getLongitude(),
Expand All @@ -50,11 +55,14 @@ static void cancelEvent(SessionState sessionState, RouteProgress routeProgress,
null, null, sessionState.originalGeometry(),
sessionState.originalDistance(), sessionState.originalDuration(), null,
sessionState.arrivalTimestamp(), sessionState.currentStepCount(), sessionState.originalStepCount()
));
);
MapboxTelemetry.getInstance().addLocationEngineName(locationEngineName, cancelEvent);
MapboxTelemetry.getInstance().pushEvent(cancelEvent);
}

static void departEvent(SessionState sessionState, RouteProgress routeProgress, Location location) {
MapboxTelemetry.getInstance().pushEvent(MapboxNavigationEvent.buildDepartEvent(
static void departEvent(SessionState sessionState, RouteProgress routeProgress, Location location,
String locationEngineName) {
Hashtable<String, Object> departEvent = MapboxNavigationEvent.buildDepartEvent(
sdkIdentifier, BuildConfig.MAPBOX_NAVIGATION_VERSION_NAME,
sessionState.sessionIdentifier(), location.getLatitude(), location.getLongitude(),
sessionState.currentGeometry(), "unknown",
Expand All @@ -65,10 +73,13 @@ static void departEvent(SessionState sessionState, RouteProgress routeProgress,
null, sessionState.currentStepCount(), sessionState.originalStepCount(),
(int) routeProgress.distanceTraveled(), (int) routeProgress.distanceRemaining(),
(int) routeProgress.durationRemaining(), sessionState.startTimestamp()
));
);
MapboxTelemetry.getInstance().addLocationEngineName(locationEngineName, departEvent);
MapboxTelemetry.getInstance().pushEvent(departEvent);
}

static void rerouteEvent(SessionState sessionState, RouteProgress routeProgress, Location location) {
static void rerouteEvent(SessionState sessionState, RouteProgress routeProgress, Location location,
String locationEngineName) {
String upcomingInstruction = null;
String previousInstruction = null;
String upcomingModifier = null;
Expand Down Expand Up @@ -98,7 +109,7 @@ static void rerouteEvent(SessionState sessionState, RouteProgress routeProgress,

String previousName = routeProgress.currentLegProgress().currentStep().getName();

MapboxTelemetry.getInstance().pushEvent(MapboxNavigationEvent.buildRerouteEvent(
Hashtable<String, Object> rerouteEvent = MapboxNavigationEvent.buildRerouteEvent(
sdkIdentifier, BuildConfig.MAPBOX_NAVIGATION_VERSION_NAME, sessionState.sessionIdentifier(),
location.getLatitude(), location.getLongitude(),
sessionState.currentGeometry(), "unknown",
Expand All @@ -121,7 +132,9 @@ static void rerouteEvent(SessionState sessionState, RouteProgress routeProgress,
(int) routeProgress.currentLegProgress().currentStepProgress().distanceRemaining(),
(int) routeProgress.currentLegProgress().currentStepProgress().durationRemaining(),
sessionState.currentStepCount(), sessionState.originalStepCount()
));
);
MapboxTelemetry.getInstance().addLocationEngineName(locationEngineName, rerouteEvent);
MapboxTelemetry.getInstance().pushEvent(rerouteEvent);
}

static void turnstileEvent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class NavigationService extends Service implements LocationEngineListener
private long timeIntervalSinceLastOffRoute;
private MapboxNavigation mapboxNavigation;
private LocationEngine locationEngine;
private String locationEngineName;
private RouteProgress routeProgress;
private boolean firstProgressUpdate = true;
private boolean queuedRerouteEvent;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void onDestroy() {
// User canceled navigation session
if (routeProgress != null && rawLocation != null) {
NavigationMetricsWrapper.cancelEvent(mapboxNavigation.getSessionState(), routeProgress,
rawLocation);
rawLocation, locationEngineName);
}
endNavigation();
super.onDestroy();
Expand Down Expand Up @@ -162,6 +163,7 @@ void endNavigation() {
void acquireLocationEngine() {
locationEngine = mapboxNavigation.getLocationEngine();
locationEngine.addLocationEngineListener(this);
locationEngineName = obtainLocationEngineName();
}

/**
Expand Down Expand Up @@ -225,7 +227,7 @@ public void onNewRouteProgress(Location location, RouteProgress routeProgress) {

if (firstProgressUpdate) {
NavigationMetricsWrapper.departEvent(mapboxNavigation.getSessionState(), routeProgress,
rawLocation);
rawLocation, locationEngineName);
firstProgressUpdate = false;
}
if (mapboxNavigation.options().enableNotification()) {
Expand Down Expand Up @@ -305,7 +307,7 @@ public void run() {
locationBuffer.clear();

NavigationMetricsWrapper.rerouteEvent(mapboxNavigation.getSessionState(), routeProgress,
rawLocation);
rawLocation, locationEngineName);
queuedRerouteEvent = false;
}
};
Expand All @@ -318,4 +320,8 @@ NavigationService getService() {
return NavigationService.this;
}
}

private String obtainLocationEngineName() {
return locationEngine.getClass().getSimpleName();
}
}