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

Add missing device attribute to Navigation events #565

Merged
merged 1 commit into from
Sep 19, 2017
Merged
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
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 @@ -583,47 +583,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