|
27 | 27 | import com.mapbox.services.android.telemetry.location.AndroidLocationEngine; |
28 | 28 | import com.mapbox.services.android.telemetry.location.LocationEngine; |
29 | 29 | import com.mapbox.services.android.telemetry.location.LocationEngineListener; |
| 30 | +import com.mapbox.services.android.telemetry.navigation.MapboxNavigationEvent; |
30 | 31 | import com.mapbox.services.android.telemetry.permissions.PermissionsManager; |
31 | 32 | import com.mapbox.services.android.telemetry.service.TelemetryService; |
32 | 33 | import com.mapbox.services.android.telemetry.utils.TelemetryUtils; |
|
36 | 37 | import java.util.Hashtable; |
37 | 38 | import java.util.Timer; |
38 | 39 | import java.util.TimerTask; |
39 | | -import java.util.UUID; |
40 | 40 | import java.util.Vector; |
41 | 41 | import java.util.concurrent.CopyOnWriteArrayList; |
42 | 42 |
|
@@ -71,6 +71,7 @@ public class MapboxTelemetry implements Callback, LocationEngineListener { |
71 | 71 | private boolean withShutDown = false; |
72 | 72 | private Boolean telemetryEnabled = null; |
73 | 73 | protected CopyOnWriteArrayList<TelemetryListener> telemetryListeners; |
| 74 | + private Hashtable<String, Object> customTurnstileEvent = null; |
74 | 75 |
|
75 | 76 | /** |
76 | 77 | * Private constructor for configuring the single instance per app. |
@@ -147,6 +148,14 @@ public boolean removeTelemetryListener(TelemetryListener listener) { |
147 | 148 | return this.telemetryListeners.remove(listener); |
148 | 149 | } |
149 | 150 |
|
| 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 | + |
150 | 159 | /** |
151 | 160 | * Checks that TelemetryService has been configured by developer |
152 | 161 | */ |
@@ -226,7 +235,7 @@ private void rotateSessionId() { |
226 | 235 | long timeSinceLastSet = System.currentTimeMillis() - mapboxSessionIdLastSet; |
227 | 236 | if ((TextUtils.isEmpty(mapboxSessionId)) |
228 | 237 | || (timeSinceLastSet > TelemetryConstants.SESSION_ID_ROTATION_MS)) { |
229 | | - mapboxSessionId = UUID.randomUUID().toString(); |
| 238 | + mapboxSessionId = TelemetryUtils.buildUUID(); |
230 | 239 | mapboxSessionIdLastSet = System.currentTimeMillis(); |
231 | 240 | } |
232 | 241 | } |
@@ -277,7 +286,7 @@ private void loadUserPreferences() { |
277 | 286 |
|
278 | 287 | // Create vendor ID (if needed) |
279 | 288 | if (TextUtils.isEmpty(mapboxVendorId)) { |
280 | | - mapboxVendorId = UUID.randomUUID().toString(); |
| 289 | + mapboxVendorId = TelemetryUtils.buildUUID(); |
281 | 290 | SharedPreferences.Editor editor = prefs.edit(); |
282 | 291 | editor.putString(TelemetryConstants.MAPBOX_SHARED_PREFERENCE_KEY_VENDOR_ID, mapboxVendorId); |
283 | 292 | editor.apply(); |
@@ -501,6 +510,42 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) { |
501 | 510 | eventWithAttributes.put(MapboxEvent.KEY_CELLULAR_NETWORK_TYPE, TelemetryUtils.getCellularNetworkType(context)); |
502 | 511 | eventWithAttributes.put(MapboxEvent.KEY_WIFI, TelemetryUtils.getConnectedToWifi(context)); |
503 | 512 | 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); |
504 | 549 | } else { |
505 | 550 | Log.w(LOG_TAG, String.format("Unknown event type provided: %s.", eventType)); |
506 | 551 | } |
@@ -536,11 +581,16 @@ private void flushEventsQueueImmediately(boolean hasTurnstileEvent) { |
536 | 581 | * Pushes turnstile event for internal billing purposes. |
537 | 582 | */ |
538 | 583 | 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 | + |
541 | 590 | event.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(null)); |
542 | 591 | event.put(MapboxEvent.KEY_USER_ID, mapboxVendorId); |
543 | 592 | event.put(MapboxEvent.KEY_ENABLED_TELEMETRY, isTelemetryEnabled()); |
| 593 | + |
544 | 594 | events.add(event); |
545 | 595 | flushEventsQueueImmediately(true); |
546 | 596 | } |
|
0 commit comments