summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorBrad Leege <bleege@gmail.com>2016-02-26 15:26:47 -0600
committerBrad Leege <bleege@gmail.com>2016-02-26 15:26:47 -0600
commitb3adb96e4a34123a337027f5d3ecc377e33397c3 (patch)
tree1911dc8cf1d2c23a82986e9e6934e13b47b2926a /platform/android
parent3ed9f4336ca81b213afb3c132b3fed5a30c76521 (diff)
downloadqtlocation-mapboxgl-b3adb96e4a34123a337027f5d3ecc377e33397c3.tar.gz
[android] #4066 - Implementing flush events when app terminates functionality
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java19
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java11
2 files changed, 28 insertions, 2 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java
index c1f956f5f5..1d8b75f6dc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java
@@ -233,6 +233,16 @@ public class MapboxEventManager {
}
/**
+ * Immediately attempt to send all events data in the queue to the server.
+ *
+ * NOTE: Permission set to package private to enable only telemetry code to use this.
+ */
+ void flushEventsQueueImmediately() {
+ Log.i(TAG, "flushEventsQueueImmediately() called...");
+ new FlushTheEventsTask().execute();
+ }
+
+ /**
* Adds a Location Event to the system for processing
* @param location Location event
*/
@@ -328,7 +338,7 @@ public class MapboxEventManager {
events.add(event);
// Send to Server Immediately
- new FlushTheEventsTask().execute();
+ flushEventsQueueImmediately();
Log.d(TAG, "turnstile event pushed.");
}
@@ -540,7 +550,6 @@ public class MapboxEventManager {
jsonObject.putOpt(MapboxEvent.KEY_ALTITUDE, evt.get(MapboxEvent.KEY_ALTITUDE));
jsonObject.putOpt(MapboxEvent.KEY_ZOOM, evt.get(MapboxEvent.KEY_ZOOM));
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM, evt.get(MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM));
- jsonObject.putOpt(MapboxEvent.ATTRIBUTE_APPLICATION_STATE, evt.get(MapboxEvent.ATTRIBUTE_APPLICATION_STATE));
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_USERID, evt.get(MapboxEvent.ATTRIBUTE_USERID));
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_MODEL, evt.get(MapboxEvent.ATTRIBUTE_MODEL));
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_RESOLUTION, evt.get(MapboxEvent.ATTRIBUTE_RESOLUTION));
@@ -563,6 +572,12 @@ public class MapboxEventManager {
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_CARRIER, carrier);
}
}
+ if (evt.containsKey(MapboxEvent.ATTRIBUTE_APPLICATION_STATE)) {
+ String appState = (String)evt.get(MapboxEvent.ATTRIBUTE_APPLICATION_STATE);
+ if (!TextUtils.isEmpty(appState)) {
+ jsonObject.putOpt(MapboxEvent.ATTRIBUTE_APPLICATION_STATE, evt.get(MapboxEvent.ATTRIBUTE_APPLICATION_STATE));
+ }
+ }
// Special Cases where null has to be passed if no value exists
// Requires using put() instead of putOpt()
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java
index 56006dadf6..0640620814 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java
@@ -139,6 +139,17 @@ public class TelemetryService extends Service {
}
private void shutdownTelemetry() {
+
+ // Send Any Remaining events to the server
+ MapboxEventManager.getMapboxEventManager().flushEventsQueueImmediately();
+
+ // Undesired, but needed trick to keep app alive long enough for data to get to server
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+ Log.e(TAG, "Error while trying to sleep for 1 second: " + e);
+ }
+
unregisterReceiver(telemetryLocationReceiver);
telemetryWakeLock.release();
}