Skip to content

Commit

Permalink
add missing device attribute to navigation events
Browse files Browse the repository at this point in the history
  • Loading branch information
Guardiola31337 committed Sep 19, 2017
1 parent 31a2e90 commit f5733f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class MapboxEvent implements Serializable {
public static final String KEY_USER_ID = "userId";
public static final String KEY_ENABLED_TELEMETRY = "enabled.telemetry";
public static final String KEY_MODEL = "model";
public static final String KEY_DEVICE = "device";
public static final String KEY_OPERATING_SYSTEM = "operatingSystem";
public static final String KEY_RESOLUTION = "resolution";
public static final String KEY_ACCESSIBILITY_FONT_SCALE = "accessibilityFontScale";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,47 +550,35 @@ 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));
} else if (isANavigationEvent(eventType)) {
addGeneralNavigationMetadataTo(eventWithAttributes);
putEventOnQueue(eventWithAttributes);
} else {
Log.w(LOG_TAG, String.format("Unknown event type provided: %s.", eventType));
}
}

private boolean isANavigationEvent(String eventType) {
boolean isDepart = eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_DEPART);
boolean isFeedback = eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_FEEDBACK);
boolean isArrived = eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_ARRIVE);
boolean isCanceled = eventType.equalsIgnoreCase(MapboxNavigationEvent.TYPE_CANCEL);

boolean isANavigationEvent = isDepart || isFeedback || isArrived || isCanceled;

return isANavigationEvent;
}

private void addGeneralNavigationMetadataTo(Hashtable<String, Object> eventWithAttributes) {
eventWithAttributes.put(MapboxEvent.KEY_DEVICE, Build.MODEL);
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));
}

/**
* Immediately attempt to send all events data in the queue to the server.
*/
Expand Down

0 comments on commit f5733f3

Please sign in to comment.