Skip to content

Commit 4af1718

Browse files
add missing device attribute to navigation events (#565)
1 parent d089d50 commit 4af1718

2 files changed

Lines changed: 24 additions & 35 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class MapboxEvent implements Serializable {
3131
public static final String KEY_USER_ID = "userId";
3232
public static final String KEY_ENABLED_TELEMETRY = "enabled.telemetry";
3333
public static final String KEY_MODEL = "model";
34+
public static final String KEY_DEVICE = "device";
3435
public static final String KEY_OPERATING_SYSTEM = "operatingSystem";
3536
public static final String KEY_RESOLUTION = "resolution";
3637
public static final String KEY_ACCESSIBILITY_FONT_SCALE = "accessibilityFontScale";

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

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -583,47 +583,35 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
583583
eventWithAttributes.put(MapboxEvent.KEY_CELLULAR_NETWORK_TYPE, TelemetryUtils.getCellularNetworkType(context));
584584
eventWithAttributes.put(MapboxEvent.KEY_WIFI, TelemetryUtils.getConnectedToWifi(context));
585585
putEventOnQueue(eventWithAttributes);
586-
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_DEPART)) {
587-
// User started a route
588-
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
589-
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
590-
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
591-
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
592-
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
593-
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
594-
putEventOnQueue(eventWithAttributes);
595-
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_FEEDBACK)) {
596-
// User feedback/reroute event
597-
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
598-
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
599-
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
600-
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
601-
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
602-
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
603-
putEventOnQueue(eventWithAttributes);
604-
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_ARRIVE)) {
605-
// User arrived
606-
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
607-
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
608-
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
609-
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
610-
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
611-
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
612-
putEventOnQueue(eventWithAttributes);
613-
} else if (eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_CANCEL)) {
614-
// User canceled navigation
615-
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
616-
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
617-
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
618-
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
619-
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
620-
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
586+
} else if (isANavigationEvent(eventType)) {
587+
addGeneralNavigationMetadataTo(eventWithAttributes);
621588
putEventOnQueue(eventWithAttributes);
622589
} else {
623590
Log.w(LOG_TAG, String.format("Unknown event type provided: %s.", eventType));
624591
}
625592
}
626593

594+
private boolean isANavigationEvent(String eventType) {
595+
boolean isDepart = eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_DEPART);
596+
boolean isFeedback = eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_FEEDBACK);
597+
boolean isArrived = eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_ARRIVE);
598+
boolean isCanceled = eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_CANCEL);
599+
600+
boolean isANavigationEvent = isDepart || isFeedback || isArrived || isCanceled;
601+
602+
return isANavigationEvent;
603+
}
604+
605+
private void addGeneralNavigationMetadataTo(Hashtable<String, Object> eventWithAttributes) {
606+
eventWithAttributes.put(MapboxEvent.KEY_DEVICE, Build.MODEL);
607+
eventWithAttributes.put(MapboxNavigationEvent.KEY_VOLUME_LEVEL, TelemetryUtils.getVolumeLevel(context));
608+
eventWithAttributes.put(MapboxNavigationEvent.KEY_SCREEN_BRIGHTNESS, TelemetryUtils.getScreenBrightness(context));
609+
eventWithAttributes.put(MapboxNavigationEvent.KEY_APPLICATION_STATE, TelemetryUtils.getApplicationState(context));
610+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_PLUGGED_IN, isPluggedIn());
611+
eventWithAttributes.put(MapboxNavigationEvent.KEY_BATTERY_LEVEL, getBatteryLevel());
612+
eventWithAttributes.put(MapboxNavigationEvent.KEY_CONNECTIVITY, TelemetryUtils.getCellularNetworkType(context));
613+
}
614+
627615
/**
628616
* Immediately attempt to send all events data in the queue to the server.
629617
*/

0 commit comments

Comments
 (0)