1313import android .os .BatteryManager ;
1414import android .os .Build ;
1515import android .os .Handler ;
16+ import android .support .annotation .IntRange ;
1617import android .support .annotation .NonNull ;
1718import android .support .v4 .content .LocalBroadcastManager ;
1819import android .text .TextUtils ;
@@ -72,6 +73,7 @@ public class MapboxTelemetry implements Callback, LocationEngineListener {
7273 private Boolean telemetryEnabled = null ;
7374 protected CopyOnWriteArrayList <TelemetryListener > telemetryListeners ;
7475 private Hashtable <String , Object > customTurnstileEvent = null ;
76+ private int sessionIdRotationTime = TelemetryConstants .DEFAULT_SESSION_ID_ROTATION_HOURS ;
7577
7678 /**
7779 * Private constructor for configuring the single instance per app.
@@ -157,6 +159,14 @@ public void setCustomTurnstileEvent(Hashtable<String, Object> customTurnstileEve
157159 this .customTurnstileEvent = customTurnstileEvent ;
158160 }
159161
162+ // For internal use only
163+ // This is an experimental API. Experimental APIs are quickly evolving and
164+ // might change or be removed in minor versions.
165+ @ Experimental
166+ public void setSessionIdRotationTime (@ IntRange (from = 1 , to = 24 ) int sessionIdRotationTime ) {
167+ this .sessionIdRotationTime = sessionIdRotationTime ; // in hours
168+ }
169+
160170 /**
161171 * Checks that TelemetryService has been configured by developer
162172 */
@@ -219,7 +229,7 @@ private void checkStagingServerInformation() {
219229 // Set new client information (if needed)
220230 if (!TextUtils .isEmpty (stagingURL ) && !TextUtils .isEmpty (stagingAccessToken )) {
221231 Log .w (LOG_TAG , String .format ("Using staging server '%s' with access token '%s'." ,
222- stagingURL , stagingAccessToken ));
232+ stagingURL , stagingAccessToken ));
223233 client .setEventsEndpoint (stagingURL );
224234 client .setAccessToken (stagingAccessToken );
225235 client .setStagingEnvironment (true );
@@ -234,7 +244,7 @@ private void setUserAgent() {
234244 // Append app identifier to user agent if present
235245 String appIdentifier = TelemetryUtils .getApplicationIdentifier (context );
236246 String fullUserAgent = TextUtils .isEmpty (appIdentifier ) ? userAgent : Util .toHumanReadableAscii (
237- String .format (TelemetryConstants .DEFAULT_LOCALE , "%s %s" , appIdentifier , userAgent ));
247+ String .format (TelemetryConstants .DEFAULT_LOCALE , "%s %s" , appIdentifier , userAgent ));
238248 client .setUserAgent (fullUserAgent );
239249 }
240250
@@ -244,7 +254,7 @@ private void setUserAgent() {
244254 private void rotateSessionId () {
245255 long timeSinceLastSet = System .currentTimeMillis () - mapboxSessionIdLastSet ;
246256 if ((TextUtils .isEmpty (mapboxSessionId ))
247- || (timeSinceLastSet > TelemetryConstants .SESSION_ID_ROTATION_MS )) {
257+ || (timeSinceLastSet > sessionIdRotationTime * TelemetryConstants .ONE_HOUR_IN_MS )) {
248258 mapboxSessionId = TelemetryUtils .buildUUID ();
249259 mapboxSessionIdLastSet = System .currentTimeMillis ();
250260 }
@@ -660,7 +670,7 @@ private void shutdownTelemetry() {
660670 context .stopService (new Intent (context , TelemetryService .class ));
661671 if (locationEngine == null ) {
662672 Log .e (LOG_TAG , String .format (
663- "Shutdown error: Location Engine instance wasn't set up (initialized: %b)." , initialized ));
673+ "Shutdown error: Location Engine instance wasn't set up (initialized: %b)." , initialized ));
664674 } else {
665675 locationEngine .removeLocationEngineListener (this );
666676 locationEngine .removeLocationUpdates ();
0 commit comments