diff options
author | Brad Leege <bleege@gmail.com> | 2016-02-08 17:21:25 -0800 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2016-02-10 19:05:23 -0800 |
commit | d88a350732509bea4bfa74ee5e99784eddcc8ed2 (patch) | |
tree | 445f881c539141157d60f284a2cc305d5899a40e /platform | |
parent | 167cbecdd6e388f9bd03d7ba52dc1dc303b83162 (diff) | |
download | qtlocation-mapboxgl-d88a350732509bea4bfa74ee5e99784eddcc8ed2.tar.gz |
[android] #2421 - Setting vendor id and session id to be encrypted
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java | 30 |
1 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 c452dab8c0..b239721ded 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 @@ -27,6 +27,8 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.utils.ApiAccess; import org.json.JSONArray; import org.json.JSONObject; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Hashtable; @@ -67,9 +69,11 @@ public class MapboxEventManager { private String mapboxSessionId = null; private static long hourInMillis = 1000 * 60 * 60; - private static long flushDelayInMillis = 1000 * 60 * 2; + private static long flushDelayInMillis = 1000 * 60 * 2; // 2 Minutes private static final int SESSION_ID_ROTATION_HOURS = 24; + private static MessageDigest messageDigest = null; + private Timer timer = null; private MapboxEventManager(@NonNull Context context) { @@ -77,6 +81,13 @@ public class MapboxEventManager { this.accessToken = ApiAccess.getToken(context); this.context = context; + // Setup Message Digest + try { + messageDigest = MessageDigest.getInstance("SHA-1"); + } catch (NoSuchAlgorithmException e) { + Log.w(TAG, "Error getting Encryption Algorithm: " + e); + } + // Load / Create Vendor Id SharedPreferences prefs = context.getSharedPreferences(MapboxConstants.MAPBOX_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE); if (prefs.contains(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_VENDORID)) { @@ -84,6 +95,7 @@ public class MapboxEventManager { Log.i(TAG, "Found Vendor Id = " + mapboxVendorId); } else { String vendorId = UUID.randomUUID().toString(); + vendorId = encodeString(vendorId); SharedPreferences.Editor editor = prefs.edit(); editor.putString(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_VENDORID, vendorId); editor.apply(); @@ -158,6 +170,20 @@ public class MapboxEventManager { rotateSessionId(); } + private String encodeString(String string) { + try { + if (messageDigest != null) { + messageDigest.reset(); + messageDigest.update(string.getBytes("UTF-8")); + byte[] bytes = messageDigest.digest(); + return new String(bytes); + } + } catch (Exception e) { + Log.w(TAG, "Error encoding string, will return in original form." + e); + } + return string; + } + private void rotateSessionId() { if (mapboxSessionId == null) { mapboxSessionId = generateNewSessionId(); @@ -321,7 +347,7 @@ public class MapboxEventManager { // Basic Event Meta Data jsonObject.put(MapboxEvent.ATTRIBUTE_EVENT, evt.get("event")); - jsonObject.put(MapboxEvent.ATTRIBUTE_SESSION_ID, mapboxSessionId); + jsonObject.put(MapboxEvent.ATTRIBUTE_SESSION_ID, encodeString(mapboxSessionId)); jsonObject.put(MapboxEvent.ATTRIBUTE_VERSION, MapboxEvent.VERSION_NUMBER); jsonObject.put(MapboxEvent.ATTRIBUTE_CREATED, evt.get("created")); jsonObject.put(MapboxEvent.ATTRIBUTE_VENDOR_ID, mapboxVendorId); |