|
5 | 5 | import com.mapbox.services.android.telemetry.constants.TelemetryConstants; |
6 | 6 | import com.mapbox.services.android.telemetry.utils.TelemetryUtils; |
7 | 7 |
|
| 8 | +import org.json.JSONObject; |
| 9 | + |
8 | 10 | import java.util.Date; |
9 | 11 | import java.util.Hashtable; |
10 | 12 |
|
@@ -226,7 +228,8 @@ public static Hashtable<String, Object> buildCancelEvent( |
226 | 228 | event.put(KEY_DISTANCE_COMPLETED, distanceCompleted); |
227 | 229 | event.put(KEY_DISTANCE_REMAINING, distanceRemaining); |
228 | 230 | event.put(KEY_DURATION_REMAINING, durationRemaining); |
229 | | - event.put(KEY_ARRIVAL_TIMESTAMP, arrivalTimestamp); |
| 231 | + // arrivalTimestamp may be null |
| 232 | + addArrivalTimestamp(event, arrivalTimestamp); |
230 | 233 | return event; |
231 | 234 | } |
232 | 235 |
|
@@ -258,15 +261,33 @@ private static Hashtable<String, Object> getMetadata( |
258 | 261 | event.put(KEY_ORIGINAL_STEP_COUNT, originalStepCount); |
259 | 262 | event.put(KEY_REROUTE_COUNT, rerouteCount); |
260 | 263 | event.put(KEY_SIMULATION, isSimulation); |
261 | | - event.put(KEY_ORIGINAL_REQUEST_IDENTIFIER, originalRequestIdentifier); |
262 | | - event.put(KEY_REQUEST_IDENTIFIER, requestIdentifier); |
| 264 | + // originalRequestIdentifier may be "null" |
| 265 | + addPairIntoEventIfNeeded(event, KEY_ORIGINAL_REQUEST_IDENTIFIER, originalRequestIdentifier); |
| 266 | + // requestIdentifier may be "null" |
| 267 | + addPairIntoEventIfNeeded(event, KEY_REQUEST_IDENTIFIER, requestIdentifier); |
263 | 268 | event.put(KEY_ORIGINAL_GEOMETRY, originalGeometry); |
264 | 269 | event.put(KEY_ORIGINAL_ESTIMATED_DISTANCE, originalEstimatedDistance); |
265 | 270 | event.put(KEY_ORIGINAL_ESTIMATED_DURATION, originalEstimatedDuration); |
266 | | - event.put(KEY_AUDIO_TYPE, audioType); |
| 271 | + // audioType may be "null" |
| 272 | + addPairIntoEventIfNeeded(event, KEY_AUDIO_TYPE, audioType); |
267 | 273 | return event; |
268 | 274 | } |
269 | 275 |
|
| 276 | + private static void addArrivalTimestamp(Hashtable<String, Object> event, Date arrivalTimestamp) { |
| 277 | + if (arrivalTimestamp == null) { |
| 278 | + event.put(KEY_ARRIVAL_TIMESTAMP, JSONObject.NULL); |
| 279 | + } else { |
| 280 | + event.put(KEY_ARRIVAL_TIMESTAMP, TelemetryUtils.generateCreateDateFormatted(arrivalTimestamp)); |
| 281 | + } |
| 282 | + } |
| 283 | + |
| 284 | + private static void addPairIntoEventIfNeeded(Hashtable<String, Object> event, String key, String value) { |
| 285 | + // See NavigationMetricsWrapper.java in https://github.com/mapbox/mapbox-navigation-android |
| 286 | + if (value == null || value.equalsIgnoreCase("null")) { |
| 287 | + event.put(key, JSONObject.NULL); |
| 288 | + } |
| 289 | + } |
| 290 | + |
270 | 291 | private static Hashtable<String, Object> getStepMetadata( |
271 | 292 | String upcomingInstruction, String upcomingType, String upcomingModifier, String upcomingName, |
272 | 293 | String previousInstruction, String previousType, String previousModifier, String previousName, |
|
0 commit comments