Skip to content

Commit 7e1a87b

Browse files
zugaldiaCameron Mace
authored andcommitted
Navigation events (#489)
* enable custom turnstile event and new events * separate platform and os constants * make date formatting a bit more flexible * include static generators for all new nav types * move UUID logic to utils * document buildUUID in the context of navigation * add javadoc to events * sdkName is now sdKIdentifier * schemaVersion is now eventVersion * sessionUUID is now sessionIdentifier * add lat and lng keys * add a method to compute screen brightness * add method to detect volume level * add keys for volumeLevel, screenBrightness, applicationState, batteryPluggedIn, batteryLevel, and connectivity * remove completedDuration * completedDistance is now distanceCompleted * add distanceRemaining and durationRemaining * changes to feedback event * normalize getVolumeLevel * only set newDistanceRemaining, newDurationRemaining, and secondsSinceLastReroute for a reroute type * remove platform key * add reroute event * fix checkstyle * added some missing metadata * added step metadata to reroute * seperated step key to make seperate json object * added step metadata to feedback * fixed a few missing metadata
1 parent f507f84 commit 7e1a87b

5 files changed

Lines changed: 388 additions & 50 deletions

File tree

mapbox/libandroid-telemetry/src/androidTest/java/com/mapbox/services/android/telemetry/ExampleInstrumentedTest.java

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

mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/MapboxTelemetry.java

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.mapbox.services.android.telemetry.location.AndroidLocationEngine;
2828
import com.mapbox.services.android.telemetry.location.LocationEngine;
2929
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
30+
import com.mapbox.services.android.telemetry.navigation.MapboxNavigationEvent;
3031
import com.mapbox.services.android.telemetry.permissions.PermissionsManager;
3132
import com.mapbox.services.android.telemetry.service.TelemetryService;
3233
import com.mapbox.services.android.telemetry.utils.TelemetryUtils;
@@ -36,7 +37,6 @@
3637
import java.util.Hashtable;
3738
import java.util.Timer;
3839
import java.util.TimerTask;
39-
import java.util.UUID;
4040
import java.util.Vector;
4141
import java.util.concurrent.CopyOnWriteArrayList;
4242

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

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

151+
public Hashtable<String, Object> getCustomTurnstileEvent() {
152+
return customTurnstileEvent;
153+
}
154+
155+
public void setCustomTurnstileEvent(Hashtable<String, Object> customTurnstileEvent) {
156+
this.customTurnstileEvent = customTurnstileEvent;
157+
}
158+
150159
/**
151160
* Checks that TelemetryService has been configured by developer
152161
*/
@@ -226,7 +235,7 @@ private void rotateSessionId() {
226235
long timeSinceLastSet = System.currentTimeMillis() - mapboxSessionIdLastSet;
227236
if ((TextUtils.isEmpty(mapboxSessionId))
228237
|| (timeSinceLastSet > TelemetryConstants.SESSION_ID_ROTATION_MS)) {
229-
mapboxSessionId = UUID.randomUUID().toString();
238+
mapboxSessionId = TelemetryUtils.buildUUID();
230239
mapboxSessionIdLastSet = System.currentTimeMillis();
231240
}
232241
}
@@ -277,7 +286,7 @@ private void loadUserPreferences() {
277286

278287
// Create vendor ID (if needed)
279288
if (TextUtils.isEmpty(mapboxVendorId)) {
280-
mapboxVendorId = UUID.randomUUID().toString();
289+
mapboxVendorId = TelemetryUtils.buildUUID();
281290
SharedPreferences.Editor editor = prefs.edit();
282291
editor.putString(TelemetryConstants.MAPBOX_SHARED_PREFERENCE_KEY_VENDOR_ID, mapboxVendorId);
283292
editor.apply();
@@ -501,6 +510,42 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
501510
eventWithAttributes.put(MapboxEvent.KEY_CELLULAR_NETWORK_TYPE, TelemetryUtils.getCellularNetworkType(context));
502511
eventWithAttributes.put(MapboxEvent.KEY_WIFI, TelemetryUtils.getConnectedToWifi(context));
503512
putEventOnQueue(eventWithAttributes);
513+
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_DEPART)) {
514+
// User started a route
515+
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
516+
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
517+
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
518+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
519+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
520+
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
521+
putEventOnQueue(eventWithAttributes);
522+
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_FEEDBACK)) {
523+
// User feedback/reroute event
524+
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
525+
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
526+
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
527+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
528+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
529+
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
530+
putEventOnQueue(eventWithAttributes);
531+
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_ARRIVE)) {
532+
// User arrived
533+
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
534+
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
535+
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
536+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
537+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
538+
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
539+
putEventOnQueue(eventWithAttributes);
540+
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_CANCEL)) {
541+
// User canceled navigation
542+
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
543+
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
544+
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
545+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
546+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
547+
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
548+
putEventOnQueue(eventWithAttributes);
504549
} else {
505550
Log.w(LOG_TAG, String.format("Unknown event type provided: %s.", eventType));
506551
}
@@ -536,11 +581,16 @@ private void flushEventsQueueImmediately(boolean hasTurnstileEvent) {
536581
* Pushes turnstile event for internal billing purposes.
537582
*/
538583
private void pushTurnstileEvent() {
539-
Hashtable<String, Object> event = new Hashtable<>();
540-
event.put(MapboxEvent.KEY_EVENT, MapboxEvent.TYPE_TURNSTILE);
584+
Hashtable<String, Object> event = getCustomTurnstileEvent();
585+
if (event == null) {
586+
event = new Hashtable<>();
587+
event.put(MapboxEvent.KEY_EVENT, MapboxEvent.TYPE_TURNSTILE);
588+
}
589+
541590
event.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(null));
542591
event.put(MapboxEvent.KEY_USER_ID, mapboxVendorId);
543592
event.put(MapboxEvent.KEY_ENABLED_TELEMETRY, isTelemetryEnabled());
593+
544594
events.add(event);
545595
flushEventsQueueImmediately(true);
546596
}

0 commit comments

Comments
 (0)