Skip to content

Commit 6aa2be9

Browse files
authored
Remove all elements after a failed request (#390)
* rename isReadyForEvent -> isInitializedAndEnabled for clarity * remove unnecessary logging * remove all elements when we cannot perform a network request * checkstyle once again
1 parent 8f3140d commit 6aa2be9

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/MapboxTelemetry.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public void onLocationChanged(Location location) {
387387
LocalBroadcastManager.getInstance(context.getApplicationContext()).sendBroadcast(intent);
388388
}
389389

390-
private boolean isReadyForEvent() {
390+
private boolean isInitializedAndEnabled() {
391391
return initialized && isTelemetryEnabled();
392392
}
393393

@@ -410,7 +410,7 @@ private void putEventOnQueue(@NonNull Hashtable<String, Object> event) {
410410
*/
411411
protected void addLocationEvent(Location location) {
412412
// Only add events when we're properly initialized and the user has opted-in
413-
if (!isReadyForEvent()) {
413+
if (!isInitializedAndEnabled()) {
414414
return;
415415
}
416416

@@ -454,7 +454,7 @@ protected void addLocationEvent(Location location) {
454454
*/
455455
public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
456456
// Only add events when we're properly initialized and the user has opted-in
457-
if (!isReadyForEvent()) {
457+
if (!isInitializedAndEnabled()) {
458458
return;
459459
}
460460

@@ -510,13 +510,24 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
510510
* Immediately attempt to send all events data in the queue to the server.
511511
*/
512512
private void flushEventsQueueImmediately(boolean hasTurnstileEvent) {
513-
boolean doRequest = hasTurnstileEvent || isReadyForEvent();
514-
if (events.size() > 0 && ConnectivityReceiver.isConnected(context) && doRequest) {
515-
client.sendEvents(events, this);
516-
for (TelemetryListener listener : telemetryListeners) {
517-
listener.onSendEvents(events.size());
513+
if (initialized && events.size() > 0) {
514+
if (ConnectivityReceiver.isConnected(context)) {
515+
if (hasTurnstileEvent || isTelemetryEnabled()) {
516+
client.sendEvents(events, this);
517+
for (TelemetryListener listener : telemetryListeners) {
518+
listener.onSendEvents(events.size());
519+
}
520+
} else {
521+
// Not enabled or doesn't include turnstile event
522+
events.removeAllElements();
523+
}
524+
} else {
525+
// No network connection
526+
events.removeAllElements();
518527
}
519-
} else if (withShutDown) {
528+
}
529+
530+
if (withShutDown) {
520531
shutdownTelemetry();
521532
}
522533
}

mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/TelemetryLocationReceiver.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@
55
import android.content.Intent;
66
import android.location.Location;
77
import android.location.LocationManager;
8-
import android.util.Log;
98

109
/**
1110
* The TelemetryService will register for updates sent to this TelemetryLocationReceiver.
1211
* Messages are sent locally using a LocalBroadcastManager.
1312
*/
1413
public class TelemetryLocationReceiver extends BroadcastReceiver {
1514

16-
private static final String LOG_TAG = TelemetryLocationReceiver.class.getSimpleName();
17-
1815
public static final String INTENT_STRING =
1916
"com.mapbox.services.android.telemetry.location.TelemetryLocationReceiver";
2017

2118
@Override
2219
public void onReceive(Context context, Intent intent) {
23-
Log.v(LOG_TAG, "Event received.");
24-
2520
// See https://github.com/mapbox/mapbox-gl-native/issues/6934
2621
if (intent == null || intent.getExtras() == null) {
2722
return;

0 commit comments

Comments
 (0)