Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #2421 - Changing sessionId to UUID and adding flag to chang…
Browse files Browse the repository at this point in the history
…e it after 24 hours
  • Loading branch information
bleege committed Feb 11, 2016
1 parent 5751302 commit 285cb33
Showing 1 changed file with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class MapboxEventManager {
private String mapboxVendorId = null;

private String mapboxSessionId = null;
private long mapboxSessionIdLastSet = 0;
private static long hourInMillis = 1000 * 60 * 60;
private static long flushDelayInMillis = 1000 * 60 * 2; // 2 Minutes
private static final int SESSION_ID_ROTATION_HOURS = 24;
Expand Down Expand Up @@ -185,26 +186,13 @@ private String encodeString(String string) {
}

private void rotateSessionId() {
if (mapboxSessionId == null) {
mapboxSessionId = generateNewSessionId();
return;
}

// Rotate if it's been SESSION_ID_ROTATION_HOURS hours
int start = mapboxSessionId.indexOf("-") + 1;
int end = mapboxSessionId.indexOf("-", start);
long time = Long.valueOf(mapboxSessionId.substring(start, end));

long now = System.currentTimeMillis();
if (now - time > (SESSION_ID_ROTATION_HOURS * hourInMillis)) {
mapboxSessionId = generateNewSessionId();
if (now - mapboxSessionIdLastSet > (SESSION_ID_ROTATION_HOURS * hourInMillis)) {
mapboxSessionId = UUID.randomUUID().toString();
mapboxSessionIdLastSet = System.currentTimeMillis();
}
}

private String generateNewSessionId() {
return context.getPackageName() + "-" + System.currentTimeMillis() + "-" + UUID.randomUUID().toString();
}

private String getOrientation() {
switch (context.getResources().getConfiguration().orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
Expand Down

0 comments on commit 285cb33

Please sign in to comment.