Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation events #489

Merged
merged 28 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
beafa41
enable custom turnstile event and new events
zugaldia Jun 21, 2017
3cef4e2
separate platform and os constants
zugaldia Jun 21, 2017
2ccf558
make date formatting a bit more flexible
zugaldia Jun 21, 2017
2d05850
include static generators for all new nav types
zugaldia Jun 21, 2017
f235364
move UUID logic to utils
zugaldia Jun 22, 2017
88fa260
document buildUUID in the context of navigation
zugaldia Jun 22, 2017
8d7af05
add javadoc to events
zugaldia Jun 22, 2017
5149cca
sdkName is now sdKIdentifier
zugaldia Jun 22, 2017
11c01c2
schemaVersion is now eventVersion
zugaldia Jun 22, 2017
c8e80b9
sessionUUID is now sessionIdentifier
zugaldia Jun 22, 2017
e9dd7ca
add lat and lng keys
zugaldia Jun 22, 2017
7ee0c5c
add a method to compute screen brightness
zugaldia Jun 22, 2017
d81fa2a
add method to detect volume level
zugaldia Jun 22, 2017
153c5b3
add keys for volumeLevel, screenBrightness, applicationState, battery…
zugaldia Jun 22, 2017
e2b5486
remove completedDuration
zugaldia Jun 22, 2017
2f6de48
completedDistance is now distanceCompleted
zugaldia Jun 22, 2017
4d98058
add distanceRemaining and durationRemaining
zugaldia Jun 22, 2017
9b3b162
changes to feedback event
zugaldia Jun 22, 2017
a4a584b
normalize getVolumeLevel
zugaldia Jul 14, 2017
6394031
only set newDistanceRemaining, newDurationRemaining, and secondsSince…
zugaldia Jul 14, 2017
43cd1ca
remove platform key
zugaldia Jul 14, 2017
1e4a9ff
add reroute event
zugaldia Jul 14, 2017
06d19c7
fix checkstyle
zugaldia Jul 27, 2017
b55499e
added some missing metadata
Aug 1, 2017
f20a258
added step metadata to reroute
Aug 1, 2017
4dd4fb0
seperated step key to make seperate json object
Aug 1, 2017
2145616
added step metadata to feedback
Aug 1, 2017
28d798f
fixed a few missing metadata
Aug 1, 2017
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.mapbox.services.android.telemetry.location.AndroidLocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
import com.mapbox.services.android.telemetry.navigation.MapboxNavigationEvent;
import com.mapbox.services.android.telemetry.permissions.PermissionsManager;
import com.mapbox.services.android.telemetry.service.TelemetryService;
import com.mapbox.services.android.telemetry.utils.TelemetryUtils;
Expand All @@ -36,7 +37,6 @@
import java.util.Hashtable;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

Expand Down Expand Up @@ -71,6 +71,7 @@ public class MapboxTelemetry implements Callback, LocationEngineListener {
private boolean withShutDown = false;
private Boolean telemetryEnabled = null;
protected CopyOnWriteArrayList<TelemetryListener> telemetryListeners;
private Hashtable<String, Object> customTurnstileEvent = null;

/**
* Private constructor for configuring the single instance per app.
Expand Down Expand Up @@ -147,6 +148,14 @@ public boolean removeTelemetryListener(TelemetryListener listener) {
return this.telemetryListeners.remove(listener);
}

public Hashtable<String, Object> getCustomTurnstileEvent() {
return customTurnstileEvent;
}

public void setCustomTurnstileEvent(Hashtable<String, Object> customTurnstileEvent) {
this.customTurnstileEvent = customTurnstileEvent;
}

/**
* Checks that TelemetryService has been configured by developer
*/
Expand Down Expand Up @@ -226,7 +235,7 @@ private void rotateSessionId() {
long timeSinceLastSet = System.currentTimeMillis() - mapboxSessionIdLastSet;
if ((TextUtils.isEmpty(mapboxSessionId))
|| (timeSinceLastSet > TelemetryConstants.SESSION_ID_ROTATION_MS)) {
mapboxSessionId = UUID.randomUUID().toString();
mapboxSessionId = TelemetryUtils.buildUUID();
mapboxSessionIdLastSet = System.currentTimeMillis();
}
}
Expand Down Expand Up @@ -277,7 +286,7 @@ private void loadUserPreferences() {

// Create vendor ID (if needed)
if (TextUtils.isEmpty(mapboxVendorId)) {
mapboxVendorId = UUID.randomUUID().toString();
mapboxVendorId = TelemetryUtils.buildUUID();
SharedPreferences.Editor editor = prefs.edit();
editor.putString(TelemetryConstants.MAPBOX_SHARED_PREFERENCE_KEY_VENDOR_ID, mapboxVendorId);
editor.apply();
Expand Down Expand Up @@ -501,6 +510,42 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
eventWithAttributes.put(MapboxEvent.KEY_CELLULAR_NETWORK_TYPE, TelemetryUtils.getCellularNetworkType(context));
eventWithAttributes.put(MapboxEvent.KEY_WIFI, TelemetryUtils.getConnectedToWifi(context));
putEventOnQueue(eventWithAttributes);
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_DEPART)) {
// User started a route
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
putEventOnQueue(eventWithAttributes);
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_FEEDBACK)) {
// User feedback/reroute event
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
putEventOnQueue(eventWithAttributes);
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_ARRIVE)) {
// User arrived
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
putEventOnQueue(eventWithAttributes);
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_CANCEL)) {
// User canceled navigation
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
putEventOnQueue(eventWithAttributes);
} else {
Log.w(LOG_TAG, String.format("Unknown event type provided: %s.", eventType));
}
Expand Down Expand Up @@ -536,11 +581,16 @@ private void flushEventsQueueImmediately(boolean hasTurnstileEvent) {
* Pushes turnstile event for internal billing purposes.
*/
private void pushTurnstileEvent() {
Hashtable<String, Object> event = new Hashtable<>();
event.put(MapboxEvent.KEY_EVENT, MapboxEvent.TYPE_TURNSTILE);
Hashtable<String, Object> event = getCustomTurnstileEvent();
if (event == null) {
event = new Hashtable<>();
event.put(MapboxEvent.KEY_EVENT, MapboxEvent.TYPE_TURNSTILE);
}

event.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(null));
event.put(MapboxEvent.KEY_USER_ID, mapboxVendorId);
event.put(MapboxEvent.KEY_ENABLED_TELEMETRY, isTelemetryEnabled());

events.add(event);
flushEventsQueueImmediately(true);
}
Expand Down
Loading