Skip to content
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 @@ -13,6 +13,7 @@
import android.os.BatteryManager;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
Expand Down Expand Up @@ -72,6 +73,7 @@ public class MapboxTelemetry implements Callback, LocationEngineListener {
private Boolean telemetryEnabled = null;
protected CopyOnWriteArrayList<TelemetryListener> telemetryListeners;
private Hashtable<String, Object> customTurnstileEvent = null;
private int sessionIdRotationTime = TelemetryConstants.DEFAULT_SESSION_ID_ROTATION_HOURS;

/**
* Private constructor for configuring the single instance per app.
Expand Down Expand Up @@ -157,6 +159,14 @@ public void setCustomTurnstileEvent(Hashtable<String, Object> customTurnstileEve
this.customTurnstileEvent = customTurnstileEvent;
}

// For internal use only
// This is an experimental API. Experimental APIs are quickly evolving and
// might change or be removed in minor versions.
@Experimental
public void setSessionIdRotationTime(@IntRange(from = 1, to = 24) int sessionIdRotationTime) {
this.sessionIdRotationTime = sessionIdRotationTime; // in hours
}

/**
* Checks that TelemetryService has been configured by developer
*/
Expand Down Expand Up @@ -219,7 +229,7 @@ private void checkStagingServerInformation() {
// Set new client information (if needed)
if (!TextUtils.isEmpty(stagingURL) && !TextUtils.isEmpty(stagingAccessToken)) {
Log.w(LOG_TAG, String.format("Using staging server '%s' with access token '%s'.",
stagingURL, stagingAccessToken));
stagingURL, stagingAccessToken));
client.setEventsEndpoint(stagingURL);
client.setAccessToken(stagingAccessToken);
client.setStagingEnvironment(true);
Expand All @@ -234,7 +244,7 @@ private void setUserAgent() {
// Append app identifier to user agent if present
String appIdentifier = TelemetryUtils.getApplicationIdentifier(context);
String fullUserAgent = TextUtils.isEmpty(appIdentifier) ? userAgent : Util.toHumanReadableAscii(
String.format(TelemetryConstants.DEFAULT_LOCALE, "%s %s", appIdentifier, userAgent));
String.format(TelemetryConstants.DEFAULT_LOCALE, "%s %s", appIdentifier, userAgent));
client.setUserAgent(fullUserAgent);
}

Expand All @@ -244,7 +254,7 @@ private void setUserAgent() {
private void rotateSessionId() {
long timeSinceLastSet = System.currentTimeMillis() - mapboxSessionIdLastSet;
if ((TextUtils.isEmpty(mapboxSessionId))
|| (timeSinceLastSet > TelemetryConstants.SESSION_ID_ROTATION_MS)) {
|| (timeSinceLastSet > sessionIdRotationTime * TelemetryConstants.ONE_HOUR_IN_MS)) {
mapboxSessionId = TelemetryUtils.buildUUID();
mapboxSessionIdLastSet = System.currentTimeMillis();
}
Expand Down Expand Up @@ -660,7 +670,7 @@ private void shutdownTelemetry() {
context.stopService(new Intent(context, TelemetryService.class));
if (locationEngine == null) {
Log.e(LOG_TAG, String.format(
"Shutdown error: Location Engine instance wasn't set up (initialized: %b).", initialized));
"Shutdown error: Location Engine instance wasn't set up (initialized: %b).", initialized));
} else {
locationEngine.removeLocationEngineListener(this);
locationEngine.removeLocationUpdates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class TelemetryConstants {
public static final long FLUSH_PERIOD_MS = 3 * 60 * 1_000; // 3 minutes
public static final int FLUSH_EVENTS_CAP = 180; // 180 seconds or 180 events

public static final int SESSION_ID_ROTATION_MS = 24 * 60 * 60 * 1_000; // 24 hours
public static final int ONE_HOUR_IN_MS = 60 * 60 * 1_000;
public static final int DEFAULT_SESSION_ID_ROTATION_HOURS = 24;

/**
* Key used to store CN endpoint settings in AndroidManifest.xml
Expand Down