From ca55caa111173a786c4494462feaf7d9cfd64792 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 11:20:58 +0100 Subject: [PATCH 01/25] Activity Package constructor with activity kind --- .../java/com/adjust/sdk/ActivityPackage.java | 22 +++++-------------- .../java/com/adjust/sdk/PackageBuilder.java | 16 +++++--------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java index 27ab969fd..23c419864 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java @@ -52,10 +52,6 @@ public ActivityKind getActivityKind() { return activityKind; } - public void setActivityKind(ActivityKind activityKind) { - this.activityKind = activityKind; - } - public String getSuffix() { return suffix; } @@ -64,6 +60,10 @@ public void setSuffix(String suffix) { this.suffix = suffix; } + public ActivityPackage(ActivityKind activityKind) { + this.activityKind = activityKind; + } + public String toString() { return String.format("%s%s", activityKind.toString(), suffix); } @@ -82,19 +82,7 @@ public String getExtendedString() { return builder.toString(); } - protected String getSuccessMessage() { - try { - return String.format("Tracked %s%s", activityKind.toString(), suffix); - } catch (NullPointerException e) { - return "Tracked ???"; - } - } - protected String getFailureMessage() { - try { - return String.format("Failed to track %s%s", activityKind.toString(), suffix); - } catch (NullPointerException e) { - return "Failed to track ???"; - } + return String.format("Failed to track %s%s", activityKind.toString(), suffix); } } diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/PackageBuilder.java b/Adjust/adjust/src/main/java/com/adjust/sdk/PackageBuilder.java index 3a43045fd..5e892f0a0 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/PackageBuilder.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/PackageBuilder.java @@ -45,9 +45,8 @@ public ActivityPackage buildSessionPackage() { addDuration(parameters, "last_interval", activityState.lastInterval); addString(parameters, "default_tracker", adjustConfig.defaultTracker); - ActivityPackage sessionPackage = getDefaultActivityPackage(); + ActivityPackage sessionPackage = getDefaultActivityPackage(ActivityKind.SESSION); sessionPackage.setPath("/session"); - sessionPackage.setActivityKind(ActivityKind.SESSION); sessionPackage.setSuffix(""); sessionPackage.setParameters(parameters); @@ -63,9 +62,8 @@ public ActivityPackage buildEventPackage(AdjustEvent event) { addMapJson(parameters, "callback_params", event.callbackParameters); addMapJson(parameters, "partner_params", event.partnerParameters); - ActivityPackage eventPackage = getDefaultActivityPackage(); + ActivityPackage eventPackage = getDefaultActivityPackage(ActivityKind.EVENT); eventPackage.setPath("/event"); - eventPackage.setActivityKind(ActivityKind.EVENT); eventPackage.setSuffix(getEventSuffix(event)); eventPackage.setParameters(parameters); @@ -81,9 +79,8 @@ public ActivityPackage buildClickPackage(String source, long clickTime) { addMapJson(parameters, "params", extraParameters); injectAttribution(parameters); - ActivityPackage clickPackage = getDefaultActivityPackage(); + ActivityPackage clickPackage = getDefaultActivityPackage(ActivityKind.CLICK); clickPackage.setPath("/sdk_click"); - clickPackage.setActivityKind(ActivityKind.CLICK); clickPackage.setSuffix(""); clickPackage.setParameters(parameters); @@ -93,17 +90,16 @@ public ActivityPackage buildClickPackage(String source, long clickTime) { public ActivityPackage buildAttributionPackage() { Map parameters = getIdsParameters(); - ActivityPackage attributionPackage = getDefaultActivityPackage(); + ActivityPackage attributionPackage = getDefaultActivityPackage(ActivityKind.ATTRIBUTION); attributionPackage.setPath("attribution"); // does not contain '/' because of Uri.Builder.appendPath - attributionPackage.setActivityKind(ActivityKind.ATTRIBUTION); attributionPackage.setSuffix(""); attributionPackage.setParameters(parameters); return attributionPackage; } - private ActivityPackage getDefaultActivityPackage() { - ActivityPackage activityPackage = new ActivityPackage(); + private ActivityPackage getDefaultActivityPackage(ActivityKind activityKind) { + ActivityPackage activityPackage = new ActivityPackage(activityKind); activityPackage.setClientSdk(deviceInfo.clientSdk); return activityPackage; } From 846deb4f532a05743b98c3f822faf01909d0d6cf Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 11:22:13 +0100 Subject: [PATCH 02/25] Parameter log ordered --- .../src/main/java/com/adjust/sdk/ActivityPackage.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java index 23c419864..f927caac2 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java @@ -11,6 +11,8 @@ import java.io.Serializable; import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; public class ActivityPackage implements Serializable { private static final long serialVersionUID = -35935556512024097L; @@ -75,8 +77,9 @@ public String getExtendedString() { if (parameters != null) { builder.append("Parameters:"); - for (Map.Entry entry : parameters.entrySet()) { - builder.append(String.format("\n\t%-16s %s", entry.getKey(), entry.getValue())); + SortedMap sortedParameters = new TreeMap(parameters); + for (Map.Entry entry : sortedParameters.entrySet() ) { + builder.append(String.format("\n\t%-16s %s", entry.getKey(), entry.getValue())); } } return builder.toString(); From 44ebdb8a81cd4989283c22fc934fa4472191e598 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 11:39:24 +0100 Subject: [PATCH 03/25] Util static logger --- .../src/main/java/com/adjust/sdk/AttributionHandler.java | 2 +- .../adjust/src/main/java/com/adjust/sdk/RequestHandler.java | 2 +- Adjust/adjust/src/main/java/com/adjust/sdk/Util.java | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/AttributionHandler.java b/Adjust/adjust/src/main/java/com/adjust/sdk/AttributionHandler.java index 2a2bef03d..23cad8b96 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/AttributionHandler.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/AttributionHandler.java @@ -124,7 +124,7 @@ private void getAttributionInternal() { return; } - JSONObject jsonResponse = Util.parseJsonResponse(httpResponse, logger); + JSONObject jsonResponse = Util.parseJsonResponse(httpResponse); checkAttributionInternal(jsonResponse); } diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/RequestHandler.java b/Adjust/adjust/src/main/java/com/adjust/sdk/RequestHandler.java index 49a46c8de..1bef0084e 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/RequestHandler.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/RequestHandler.java @@ -136,7 +136,7 @@ private void sendInternal(ActivityPackage activityPackage, boolean sendToPackage } private void requestFinished(HttpResponse response, boolean sendToPackageHandler) { - JSONObject jsonResponse = Util.parseJsonResponse(response, logger); + JSONObject jsonResponse = Util.parseJsonResponse(response); if (jsonResponse == null) { if (sendToPackageHandler) { diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java index a893d09f9..2bb275cc8 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java @@ -45,6 +45,7 @@ public class Util { private static SimpleDateFormat dateFormat; private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'Z"; + private static final ILogger logger = AdjustFactory.getLogger(); protected static String createUuid() { return UUID.randomUUID().toString(); @@ -80,7 +81,6 @@ public static Boolean isPlayTrackingEnabled(Context context) { } public static T readObject(Context context, String filename, String objectName) { - ILogger logger = AdjustFactory.getLogger(); try { FileInputStream inputStream = context.openFileInput(filename); BufferedInputStream bufferedStream = new BufferedInputStream(inputStream); @@ -113,7 +113,6 @@ public static T readObject(Context context, String filename, String objectNa } public static void writeObject(T object, Context context, String filename, String objectName) { - ILogger logger = AdjustFactory.getLogger(); try { FileOutputStream outputStream = context.openFileOutput(filename, Context.MODE_PRIVATE); BufferedOutputStream bufferedStream = new BufferedOutputStream(outputStream); @@ -147,7 +146,7 @@ public static String parseResponse(HttpResponse httpResponse, ILogger logger) { } } - public static JSONObject parseJsonResponse(HttpResponse httpResponse, ILogger logger) { + public static JSONObject parseJsonResponse(HttpResponse httpResponse) { if (httpResponse == null) { return null; } From cfea6890d66553caf96494df3f9d28ae99a9f7ef Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 11:53:39 +0100 Subject: [PATCH 04/25] Move read fields to Util --- .../java/com/adjust/sdk/ActivityState.java | 56 ++++--------------- .../src/main/java/com/adjust/sdk/Util.java | 37 ++++++++++++ 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java index 41ad2ca3b..1b2b59294 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java @@ -18,7 +18,6 @@ public class ActivityState implements Serializable, Cloneable { private static final long serialVersionUID = 9039439291143138148L; - private transient String readErrorMessage = "Unable to read '%s' field in migration device with message (%s)"; private transient ILogger logger; // persistent data @@ -84,18 +83,18 @@ public ActivityState clone() { private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); - eventCount = readIntField(fields, "eventCount", 0); - sessionCount = readIntField(fields, "sessionCount", 0); - subsessionCount = readIntField(fields, "subsessionCount", -1); - sessionLength = readLongField(fields, "sessionLength", -1l); - timeSpent = readLongField(fields, "timeSpent", -1l); - lastActivity = readLongField(fields, "lastActivity", -1l); - lastInterval = readLongField(fields, "lastInterval", -1l); + eventCount = Util.readIntField(fields, "eventCount", 0); + sessionCount = Util.readIntField(fields, "sessionCount", 0); + subsessionCount = Util.readIntField(fields, "subsessionCount", -1); + sessionLength = Util.readLongField(fields, "sessionLength", -1l); + timeSpent = Util.readLongField(fields, "timeSpent", -1l); + lastActivity = Util.readLongField(fields, "lastActivity", -1l); + lastInterval = Util.readLongField(fields, "lastInterval", -1l); // new fields - uuid = readStringField(fields, "uuid", null); - enabled = readBooleanField(fields, "enabled", true); - askingAttribution = readBooleanField(fields, "askingAttribution", false); + uuid = Util.readStringField(fields, "uuid", null); + enabled = Util.readBooleanField(fields, "enabled", true); + askingAttribution = Util.readBooleanField(fields, "askingAttribution", false); // create UUID for migrating devices if (uuid == null) { @@ -103,41 +102,6 @@ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFo } } - private String readStringField(GetField fields, String name, String defaultValue) { - try { - return (String) fields.get(name, defaultValue); - } catch (Exception e) { - logger.debug(readErrorMessage, name, e.getMessage()); - return defaultValue; - } - } - - private boolean readBooleanField(GetField fields, String name, boolean defaultValue) { - try { - return fields.get(name, defaultValue); - } catch (Exception e) { - logger.debug(readErrorMessage, name, e.getMessage()); - return defaultValue; - } - } - - private int readIntField(GetField fields, String name, int defaultValue) { - try { - return fields.get(name, defaultValue); - } catch (Exception e) { - logger.debug(readErrorMessage, name, e.getMessage()); - return defaultValue; - } - } - - private long readLongField(GetField fields, String name, long defaultValue) { - try { - return fields.get(name, defaultValue); - } catch (Exception e) { - logger.debug(readErrorMessage, name, e.getMessage()); - return defaultValue; - } - } private static String stamp(long dateMillis) { Calendar calendar = Calendar.getInstance(); diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java index 2bb275cc8..442eacbe0 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java @@ -45,6 +45,7 @@ public class Util { private static SimpleDateFormat dateFormat; private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'Z"; + private static final String fieldReadErrorMessage = "Unable to read '%s' field in migration device with message (%s)"; private static final ILogger logger = AdjustFactory.getLogger(); protected static String createUuid() { @@ -198,4 +199,40 @@ public static boolean checkPermission(Context context, String permission) { int result = context.checkCallingOrSelfPermission(permission); return result == PackageManager.PERMISSION_GRANTED; } + + public static String readStringField(ObjectInputStream.GetField fields, String name, String defaultValue) { + try { + return (String) fields.get(name, defaultValue); + } catch (Exception e) { + logger.debug(fieldReadErrorMessage, name, e.getMessage()); + return defaultValue; + } + } + + public static boolean readBooleanField(ObjectInputStream.GetField fields, String name, boolean defaultValue) { + try { + return fields.get(name, defaultValue); + } catch (Exception e) { + logger.debug(fieldReadErrorMessage, name, e.getMessage()); + return defaultValue; + } + } + + public static int readIntField(ObjectInputStream.GetField fields, String name, int defaultValue) { + try { + return fields.get(name, defaultValue); + } catch (Exception e) { + logger.debug(fieldReadErrorMessage, name, e.getMessage()); + return defaultValue; + } + } + + public static long readLongField(ObjectInputStream.GetField fields, String name, long defaultValue) { + try { + return fields.get(name, defaultValue); + } catch (Exception e) { + logger.debug(fieldReadErrorMessage, name, e.getMessage()); + return defaultValue; + } + } } From 3b89115d9688a69f642c843036df505ce760ca70 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 12:04:52 +0100 Subject: [PATCH 05/25] Remove unused parse response --- .../adjust/src/main/java/com/adjust/sdk/Util.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java index 442eacbe0..86822fce0 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java @@ -133,20 +133,6 @@ public static void writeObject(T object, Context context, String filename, S } } - public static String parseResponse(HttpResponse httpResponse, ILogger logger) { - try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - httpResponse.getEntity().writeTo(out); - out.close(); - String response = out.toString().trim(); - logger.verbose("Response: %s", response); - return response; - } catch (Exception e) { - logger.error("Failed to parse response (%s)", e); - return null; - } - } - public static JSONObject parseJsonResponse(HttpResponse httpResponse) { if (httpResponse == null) { return null; From 162aa4bda513ed40546c423a0421c458439f5b6a Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 12:07:15 +0100 Subject: [PATCH 06/25] Read and write package handler in util --- .../java/com/adjust/sdk/PackageHandler.java | 71 +++---------------- 1 file changed, 11 insertions(+), 60 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/PackageHandler.java b/Adjust/adjust/src/main/java/com/adjust/sdk/PackageHandler.java index d0a84ccd1..4497e4b1d 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/PackageHandler.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/PackageHandler.java @@ -17,16 +17,6 @@ import org.json.JSONObject; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.NotSerializableException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OptionalDataException; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -35,6 +25,7 @@ // persistent public class PackageHandler extends HandlerThread implements IPackageHandler { private static final String PACKAGE_QUEUE_FILENAME = "AdjustIoPackageQueue"; + private static final String PACKAGE_QUEUE_NAME = "Package queue"; private final InternalHandler internalHandler; private IRequestHandler requestHandler; @@ -214,61 +205,21 @@ private void sendNextInternal() { } private void readPackageQueue() { - try { - FileInputStream inputStream = context.openFileInput(PACKAGE_QUEUE_FILENAME); - BufferedInputStream bufferedStream = new BufferedInputStream(inputStream); - ObjectInputStream objectStream = new ObjectInputStream(bufferedStream); - - try { - Object object = objectStream.readObject(); - @SuppressWarnings("unchecked") - List packageQueue = (List) object; - logger.debug("Package handler read %d packages", packageQueue.size()); - this.packageQueue = packageQueue; - return; - } catch (ClassNotFoundException e) { - logger.error("Failed to find package queue class"); - } catch (OptionalDataException e) { - /* no-op */ - } catch (IOException e) { - logger.error("Failed to read package queue object"); - } catch (ClassCastException e) { - logger.error("Failed to cast package queue object"); - } finally { - objectStream.close(); - } - } catch (FileNotFoundException e) { - logger.verbose("Package queue file not found"); - } catch (Exception e) { - logger.error("Failed to read package queue file"); + packageQueue = Util.readObject(context, PACKAGE_QUEUE_FILENAME, PACKAGE_QUEUE_NAME); + + if (packageQueue != null) { + logger.debug("Package handler read %d packages", packageQueue.size()); + } else { + packageQueue = new ArrayList<>(); } + } - // start with a fresh package queue in case of any exception - packageQueue = new ArrayList(); + private void writePackageQueue() { + Util.writeObject(packageQueue, context, PACKAGE_QUEUE_FILENAME, PACKAGE_QUEUE_NAME); + logger.debug("Package handler wrote %d packages", packageQueue.size()); } public static Boolean deletePackageQueue(Context context) { return context.deleteFile(PACKAGE_QUEUE_FILENAME); } - - - private void writePackageQueue() { - try { - FileOutputStream outputStream = context.openFileOutput(PACKAGE_QUEUE_FILENAME, Context.MODE_PRIVATE); - BufferedOutputStream bufferedStream = new BufferedOutputStream(outputStream); - ObjectOutputStream objectStream = new ObjectOutputStream(bufferedStream); - - try { - objectStream.writeObject(packageQueue); - logger.debug("Package handler wrote %d packages", packageQueue.size()); - } catch (NotSerializableException e) { - logger.error("Failed to serialize packages"); - } finally { - objectStream.close(); - } - } catch (Exception e) { - logger.error("Failed to write packages (%s)", e.getLocalizedMessage()); - e.printStackTrace(); - } - } } From 5855614487423791ef76fc4c36851015aea23174 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 12:08:07 +0100 Subject: [PATCH 07/25] Close file streams one at a time --- .../src/main/java/com/adjust/sdk/Util.java | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java index 86822fce0..0db359908 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java @@ -24,6 +24,7 @@ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; +import java.io.Closeable; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -82,16 +83,22 @@ public static Boolean isPlayTrackingEnabled(Context context) { } public static T readObject(Context context, String filename, String objectName) { + Closeable closable = null; + @SuppressWarnings("unchecked") + T object = null; try { FileInputStream inputStream = context.openFileInput(filename); + closable = inputStream; + BufferedInputStream bufferedStream = new BufferedInputStream(inputStream); + closable = bufferedStream; + ObjectInputStream objectStream = new ObjectInputStream(bufferedStream); + closable = objectStream; try { - @SuppressWarnings("unchecked") - T t = (T) objectStream.readObject(); - logger.debug("Read %s: %s", objectName, t); - return t; + object = (T) objectStream.readObject(); + logger.debug("Read %s: %s", objectName, object); } catch (ClassNotFoundException e) { logger.error("Failed to find %s class", objectName); } catch (OptionalDataException e) { @@ -100,37 +107,51 @@ public static T readObject(Context context, String filename, String objectNa logger.error("Failed to read %s object", objectName); } catch (ClassCastException e) { logger.error("Failed to cast %s object", objectName); - } finally { - objectStream.close(); } - } catch (FileNotFoundException e) { logger.verbose("%s file not found", objectName); } catch (Exception e) { logger.error("Failed to open %s file for reading (%s)", objectName, e); } + try { + if (closable != null) { + closable.close(); + } + } catch (Exception e) { + logger.error("Failed to close %s file for reading (%s)", objectName, e); + } - return null; + return object; } public static void writeObject(T object, Context context, String filename, String objectName) { + Closeable closable = null; try { FileOutputStream outputStream = context.openFileOutput(filename, Context.MODE_PRIVATE); + closable = outputStream; + BufferedOutputStream bufferedStream = new BufferedOutputStream(outputStream); + closable = bufferedStream; + ObjectOutputStream objectStream = new ObjectOutputStream(bufferedStream); + closable = objectStream; try { objectStream.writeObject(object); logger.debug("Wrote %s: %s", objectName, object); } catch (NotSerializableException e) { logger.error("Failed to serialize %s", objectName); - } finally { - objectStream.close(); } - } catch (Exception e) { logger.error("Failed to open %s for writing (%s)", objectName, e); } + try { + if (closable != null) { + closable.close(); + } + } catch (Exception e) { + logger.error("Failed to close %s file for writing (%s)", objectName, e); + } } public static JSONObject parseJsonResponse(HttpResponse httpResponse) { From 97c692cc9273d1e8005be37f90620ae01bd62216 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 12:10:05 +0100 Subject: [PATCH 08/25] Remove unused email sha1 --- .../src/main/java/com/adjust/sdk/Reflection.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Reflection.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Reflection.java index d9d9a9dbc..7454690a6 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Reflection.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Reflection.java @@ -81,17 +81,6 @@ public static String getAndroidId(Context context) { } } - public static String getSha1EmailAddress(Context context, String key) { - try { - String sha1EmailAddress = (String) invokeStaticMethod("com.adjust.sdk.plugin.EmailUtil", "getSha1EmailAddress" - , new Class[]{Context.class, String.class}, context, key); - - return sha1EmailAddress; - } catch (Throwable t) { - return null; - } - } - private static Object getAdvertisingInfoObject(Context context) throws Exception { return invokeStaticMethod("com.google.android.gms.ads.identifier.AdvertisingIdClient", From a44a7341a29ea637efc96db8ed1eb91e330e0862 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 12:12:02 +0100 Subject: [PATCH 09/25] Add serialPersistentFields --- .../main/java/com/adjust/sdk/ActivityPackage.java | 8 ++++++++ .../src/main/java/com/adjust/sdk/ActivityState.java | 13 +++++++++++++ .../main/java/com/adjust/sdk/AdjustAttribution.java | 9 +++++++++ 3 files changed, 30 insertions(+) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java index f927caac2..08184488a 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java @@ -9,6 +9,7 @@ package com.adjust.sdk; +import java.io.ObjectStreamField; import java.io.Serializable; import java.util.Map; import java.util.SortedMap; @@ -16,6 +17,13 @@ public class ActivityPackage implements Serializable { private static final long serialVersionUID = -35935556512024097L; + private static final ObjectStreamField[] serialPersistentFields = { + new ObjectStreamField("path", String.class), + new ObjectStreamField("clientSdk", String.class), + new ObjectStreamField("parameters", (Class>)((Class)Map.class)), + new ObjectStreamField("activityKind", ActivityKind.class), + new ObjectStreamField("suffix", String.class) + }; // data private String path; diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java index 1b2b59294..b121ae4ba 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectInputStream.GetField; +import java.io.ObjectStreamField; import java.io.Serializable; import java.util.Calendar; import java.util.Locale; @@ -19,6 +20,18 @@ public class ActivityState implements Serializable, Cloneable { private static final long serialVersionUID = 9039439291143138148L; private transient ILogger logger; + private static final ObjectStreamField[] serialPersistentFields = { + new ObjectStreamField("uuid", String.class), + new ObjectStreamField("enabled", boolean.class), + new ObjectStreamField("askingAttribution", boolean.class), + new ObjectStreamField("eventCount", int.class), + new ObjectStreamField("sessionCount", int.class), + new ObjectStreamField("subsessionCount", int.class), + new ObjectStreamField("sessionLength", long.class), + new ObjectStreamField("timeSpent", long.class), + new ObjectStreamField("lastActivity", long.class), + new ObjectStreamField("lastInterval", long.class) + }; // persistent data protected String uuid; diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java b/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java index 4e3abb017..0609caebd 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java @@ -2,6 +2,7 @@ import org.json.JSONObject; +import java.io.ObjectStreamField; import java.io.Serializable; /** @@ -9,6 +10,14 @@ */ public class AdjustAttribution implements Serializable { private static final long serialVersionUID = 1L; + private static final ObjectStreamField[] serialPersistentFields = { + new ObjectStreamField("trackerToken", String.class), + new ObjectStreamField("trackerName", String.class), + new ObjectStreamField("network", String.class), + new ObjectStreamField("campaign", String.class), + new ObjectStreamField("adgroup", String.class), + new ObjectStreamField("creative", String.class) + }; public String trackerToken; public String trackerName; From f5b7fbe2487334d5b443b2635db9548fe2bc4ed0 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 15:38:10 +0100 Subject: [PATCH 10/25] Read and write serializable objects --- .../main/java/com/adjust/sdk/ActivityPackage.java | 11 +++++++++++ .../src/main/java/com/adjust/sdk/ActivityState.java | 4 ++++ .../main/java/com/adjust/sdk/AdjustAttribution.java | 12 ++++++++++++ 3 files changed, 27 insertions(+) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java index 08184488a..3b77fcc8b 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java @@ -9,6 +9,9 @@ package com.adjust.sdk; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.ObjectStreamField; import java.io.Serializable; import java.util.Map; @@ -96,4 +99,12 @@ public String getExtendedString() { protected String getFailureMessage() { return String.format("Failed to track %s%s", activityKind.toString(), suffix); } + + private void writeObject(ObjectOutputStream stream) throws IOException { + stream.defaultWriteObject(); + } + + private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException { + stream.defaultReadObject(); + } } diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java index b121ae4ba..aeb93e8b7 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectInputStream.GetField; +import java.io.ObjectOutputStream; import java.io.ObjectStreamField; import java.io.Serializable; import java.util.Calendar; @@ -115,6 +116,9 @@ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFo } } + private void writeObject(ObjectOutputStream stream) throws IOException { + stream.defaultWriteObject(); + } private static String stamp(long dateMillis) { Calendar calendar = Calendar.getInstance(); diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java b/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java index 0609caebd..0b181dc01 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java @@ -2,6 +2,9 @@ import org.json.JSONObject; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.ObjectStreamField; import java.io.Serializable; @@ -68,4 +71,13 @@ public String toString() { return String.format("tt:%s tn:%s net:%s cam:%s adg:%s cre:%s", trackerToken, trackerName, network, campaign, adgroup, creative); } + + private void writeObject(ObjectOutputStream stream) throws IOException { + stream.defaultWriteObject(); + } + + private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException { + stream.defaultReadObject(); + } + } From 31a2ce303f52d0795cb81f35f40f9693d390eb11 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 15:45:38 +0100 Subject: [PATCH 11/25] Move equalString to Util --- .../com/adjust/sdk/AdjustAttribution.java | 19 +++++++------------ .../src/main/java/com/adjust/sdk/Util.java | 5 +++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java b/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java index 0b181dc01..d4b1676c0 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java @@ -44,27 +44,22 @@ public static AdjustAttribution fromJson(JSONObject jsonObject) { return attribution; } + @Override public boolean equals(Object other) { if (other == this) return true; if (other == null) return false; if (getClass() != other.getClass()) return false; AdjustAttribution otherAttribution = (AdjustAttribution) other; - if (!equalString(trackerToken, otherAttribution.trackerToken)) return false; - if (!equalString(trackerName, otherAttribution.trackerName)) return false; - if (!equalString(network, otherAttribution.network)) return false; - if (!equalString(campaign, otherAttribution.campaign)) return false; - if (!equalString(adgroup, otherAttribution.adgroup)) return false; - if (!equalString(creative, otherAttribution.creative)) return false; + if (!Util.equalString(trackerToken, otherAttribution.trackerToken)) return false; + if (!Util.equalString(trackerName, otherAttribution.trackerName)) return false; + if (!Util.equalString(network, otherAttribution.network)) return false; + if (!Util.equalString(campaign, otherAttribution.campaign)) return false; + if (!Util.equalString(adgroup, otherAttribution.adgroup)) return false; + if (!Util.equalString(creative, otherAttribution.creative)) return false; return true; } - private boolean equalString(String first, String second) { - if (first == null || second == null) { - return first == null && second == null; - } - return first.equals(second); - } @Override public String toString() { diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java index 0db359908..b92945597 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java @@ -35,6 +35,7 @@ import java.io.OptionalDataException; import java.text.SimpleDateFormat; import java.util.Locale; +import java.util.Map; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -242,4 +243,8 @@ public static long readLongField(ObjectInputStream.GetField fields, String name, return defaultValue; } } + + public static boolean equalString(String first, String second) { + return equalObject(first, second); + } } From 9bcd22255edf3e514c79f929b8a7d25a51891eeb Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 15:46:56 +0100 Subject: [PATCH 12/25] Equals and hash code for serializable --- .../java/com/adjust/sdk/ActivityPackage.java | 29 ++++++++ .../java/com/adjust/sdk/ActivityState.java | 34 +++++++++ .../com/adjust/sdk/AdjustAttribution.java | 12 ++++ .../src/main/java/com/adjust/sdk/Util.java | 72 +++++++++++++++++++ 4 files changed, 147 insertions(+) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java index 3b77fcc8b..c90f6700e 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java @@ -27,6 +27,7 @@ public class ActivityPackage implements Serializable { new ObjectStreamField("activityKind", ActivityKind.class), new ObjectStreamField("suffix", String.class) }; + private transient int hashCode; // data private String path; @@ -107,4 +108,32 @@ private void writeObject(ObjectOutputStream stream) throws IOException { private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException { stream.defaultReadObject(); } + + @Override + public boolean equals(Object other) { + if (other == this) return true; + if (other == null) return false; + if (getClass() != other.getClass()) return false; + ActivityPackage otherActivityPackage = (ActivityPackage) other; + + if (!Util.equalString( path, otherActivityPackage.path)) return false; + if (!Util.equalString( clientSdk, otherActivityPackage.clientSdk)) return false; + if (!Util.equalsMap( parameters, otherActivityPackage.parameters)) return false; + if (!Util.equalEnum( activityKind, otherActivityPackage.activityKind)) return false; + if (!Util.equalString( suffix, otherActivityPackage.suffix)) return false; + return true; + } + + @Override + public int hashCode() { + if (hashCode == 0) { + hashCode = 17; + hashCode = 37 * hashCode + Util.hashString(path); + hashCode = 37 * hashCode + Util.hashString(clientSdk); + hashCode = 37 * hashCode + Util.hashMap(parameters); + hashCode = 37 * hashCode + Util.hashEnum(activityKind); + hashCode = 37 * hashCode + Util.hashString(suffix); + } + return hashCode; + } } diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java index aeb93e8b7..bd777cbbb 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java @@ -93,6 +93,40 @@ public ActivityState clone() { } } + @Override + public boolean equals(Object other) { + if (other == this) return true; + if (other == null) return false; + if (getClass() != other.getClass()) return false; + ActivityState otherActivityState = (ActivityState) other; + + if (!Util.equalString( uuid, otherActivityState.uuid)) return false; + if (!Util.equalBoolean( enabled, otherActivityState.enabled)) return false; + if (!Util.equalBoolean( askingAttribution, otherActivityState.askingAttribution)) return false; + if (!Util.equalInt( eventCount, otherActivityState.eventCount)) return false; + if (!Util.equalInt( sessionCount, otherActivityState.sessionCount)) return false; + if (!Util.equalInt( subsessionCount, otherActivityState.subsessionCount)) return false; + if (!Util.equalLong( sessionLength, otherActivityState.sessionLength)) return false; + if (!Util.equalLong( timeSpent, otherActivityState.timeSpent)) return false; + if (!Util.equalLong( lastInterval, otherActivityState.lastInterval)) return false; + return true; + } + + @Override + public int hashCode() { + int hashCode = 17; + hashCode = 37 * hashCode + Util.hashString(uuid); + hashCode = 37 * hashCode + Util.hashBoolean(enabled); + hashCode = 37 * hashCode + Util.hashBoolean(askingAttribution); + hashCode = 37 * hashCode + eventCount; + hashCode = 37 * hashCode + sessionCount; + hashCode = 37 * hashCode + subsessionCount; + hashCode = 37 * hashCode + Util.hashLong(sessionLength); + hashCode = 37 * hashCode + Util.hashLong(timeSpent); + hashCode = 37 * hashCode + Util.hashLong(lastInterval); + return hashCode; + } + private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { GetField fields = stream.readFields(); diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java b/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java index d4b1676c0..0c814a21f 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java @@ -60,6 +60,18 @@ public boolean equals(Object other) { return true; } + @Override + public int hashCode() { + int hashCode = 17; + hashCode = 37 * hashCode + Util.hashString(trackerToken); + hashCode = 37 * hashCode + Util.hashString(trackerName); + hashCode = 37 * hashCode + Util.hashString(network); + hashCode = 37 * hashCode + Util.hashString(campaign); + hashCode = 37 * hashCode + Util.hashString(adgroup); + hashCode = 37 * hashCode + Util.hashString(creative); + return hashCode; + } + @Override public String toString() { diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java index b92945597..8eaf4b2eb 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java @@ -244,7 +244,79 @@ public static long readLongField(ObjectInputStream.GetField fields, String name, } } + public static boolean equalObject(Object first, Object second) { + if (first == null || second == null) { + return first == null && second == null; + } + return first.equals(second); + } + + public static boolean equalsMap(Map first, Map second) { + if (first == null || second == null) { + return first == null && second == null; + } + return first.entrySet().equals(second.entrySet()); + } + + public static boolean equalsDouble(Double first, Double second) { + if (first == null || second == null) { + return first == null && second == null; + } + return Double.doubleToLongBits(first) == Double.doubleToLongBits(second); + } + public static boolean equalString(String first, String second) { return equalObject(first, second); } + + public static boolean equalEnum(Enum first, Enum second) { + return equalObject(first, second); + } + + public static boolean equalLong(Long first, Long second) { + return equalObject(first, second); + } + + public static boolean equalInt(Integer first, Integer second) { + return equalObject(first, second); + } + + public static boolean equalBoolean(Boolean first, Boolean second) { + return equalObject(first, second); + } + + public static int hashBoolean(Boolean value) { + if (value == null) { + return 0; + } + return value.hashCode(); + } + + public static int hashLong(Long value) { + if (value == null) { + return 0; + } + return value.hashCode(); + } + + public static int hashString(String value) { + if (value == null) { + return 0; + } + return value.hashCode(); + } + + public static int hashEnum(Enum value) { + if (value == null) { + return 0; + } + return value.hashCode(); + } + + public static int hashMap(Map value) { + if (value == null) { + return 0; + } + return value.entrySet().hashCode(); + } } From eef444be42f333769ff9340f02fa5de5210dbe90 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 15:50:57 +0100 Subject: [PATCH 13/25] New proguard rules --- Adjust/example/build.gradle | 2 +- Adjust/example/proguard-rules.pro | 21 +++++++++++++++++++++ Adjust/example/src/main/AndroidManifest.xml | 4 ---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Adjust/example/build.gradle b/Adjust/example/build.gradle index e59d6f944..bf6f5a26b 100644 --- a/Adjust/example/build.gradle +++ b/Adjust/example/build.gradle @@ -13,7 +13,7 @@ android { } buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } diff --git a/Adjust/example/proguard-rules.pro b/Adjust/example/proguard-rules.pro index b88e5ae52..2dbc5763e 100644 --- a/Adjust/example/proguard-rules.pro +++ b/Adjust/example/proguard-rules.pro @@ -15,3 +15,24 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} + +-keep class com.adjust.sdk.plugin.MacAddressUtil { ; } +-keep class com.adjust.sdk.plugin.AndroidIdUtil { ; } +#-keep class com.adjust.sdk.plugin.MacAddressUtil { String getMacAddress(android.content.Context); } +#-keep class com.adjust.sdk.plugin.AndroidIdUtil { String getAndroidId(android.content.Context); } + +-keep class com.google.android.gms.common.GooglePlayServicesUtil { + int isGooglePlayServicesAvailable (android.content.Context); +} +-keep class com.google.android.gms.common.ConnectionResult { + int SUCCESS; +} +-keep class com.google.android.gms.ads.identifier.** { *; } + +#-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient { +# com.google.android.gms.ads.identifier.AdvertisingIdClient.Info getAdvertisingIdInfo (android.content.Contextxt); +#} +#-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient.Info { +# String getId (); +# boolean isLimitAdTrackingEnabled(); +#} \ No newline at end of file diff --git a/Adjust/example/src/main/AndroidManifest.xml b/Adjust/example/src/main/AndroidManifest.xml index 9b12f001c..3d44386e3 100644 --- a/Adjust/example/src/main/AndroidManifest.xml +++ b/Adjust/example/src/main/AndroidManifest.xml @@ -25,7 +25,6 @@ android:label="@string/app_name"> - @@ -35,10 +34,7 @@ - - - From 477cb427545f8fdf6c16c9ce3f35fcfcb701c2ba Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 15:56:12 +0100 Subject: [PATCH 14/25] New version 4.0.1 --- Adjust/adjust/build.gradle | 2 +- Adjust/adjust/src/main/java/com/adjust/sdk/Constants.java | 2 +- Adjust/example/build.gradle | 2 +- Adjust/pom.xml | 2 +- .../java/com/adjust/sdk/test/TestActivityPackage.java | 2 +- README.md | 2 +- VERSION | 2 +- doc/migrate.md | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Adjust/adjust/build.gradle b/Adjust/adjust/build.gradle index 92255c2ab..7baf28baf 100644 --- a/Adjust/adjust/build.gradle +++ b/Adjust/adjust/build.gradle @@ -8,7 +8,7 @@ android { minSdkVersion 9 targetSdkVersion 21 versionCode 1 - versionName "4.0.0" + versionName "4.0.1" } } diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Constants.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Constants.java index 7a97cb2f4..d835c2a82 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Constants.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Constants.java @@ -27,7 +27,7 @@ public interface Constants { String BASE_URL = "https://app.adjust.com"; String SCHEME = "https"; String AUTHORITY = "app.adjust.com"; - String CLIENT_SDK = "android4.0.0"; + String CLIENT_SDK = "android4.0.1"; String LOGTAG = "Adjust"; String ACTIVITY_STATE_FILENAME = "AdjustIoActivityState"; diff --git a/Adjust/example/build.gradle b/Adjust/example/build.gradle index bf6f5a26b..9106fd275 100644 --- a/Adjust/example/build.gradle +++ b/Adjust/example/build.gradle @@ -28,5 +28,5 @@ dependencies { // running mvn package //compile fileTree(dir: '../target', include: ['*.jar']) // using maven repository - //compile 'com.adjust.sdk:adjust-android:4.0.0' + //compile 'com.adjust.sdk:adjust-android:4.0.1' } diff --git a/Adjust/pom.xml b/Adjust/pom.xml index 1638485f4..845c0ef66 100644 --- a/Adjust/pom.xml +++ b/Adjust/pom.xml @@ -5,7 +5,7 @@ 4.0.0 adjust-android com.adjust.sdk - 4.0.0 + 4.0.1 jar Adjust Android SDK https://github.com/adjust/android_sdk diff --git a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestActivityPackage.java b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestActivityPackage.java index a0310c949..54f5ce5f3 100644 --- a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestActivityPackage.java +++ b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestActivityPackage.java @@ -45,7 +45,7 @@ public TestActivityPackage(ActivityPackage activityPackage) { // default values appToken = "123456789012"; environment = "sandbox"; - clientSdk = "android4.0.0"; + clientSdk = "android4.0.1"; suffix = ""; attribution = new AdjustAttribution(); } diff --git a/README.md b/README.md index 71988e8fd..b274d61fd 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ compile project(":adjust") If you are using Maven, add this line instead: ``` -compile 'com.adjust.sdk:adjust-android:4.0.0' +compile 'com.adjust.sdk:adjust-android:4.0.1' ``` ### 4. Add Google Play Services diff --git a/VERSION b/VERSION index fcdb2e109..1454f6ed4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.0 +4.0.1 diff --git a/doc/migrate.md b/doc/migrate.md index 8c2ae9add..9eb0b6532 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -1,4 +1,4 @@ -## Migrate your adjust SDK for Android to 4.0.0 from 3.6.2 +## Migrate your adjust SDK for Android to 4.0.1 from 3.6.2 ### The Application class From 82ad99dde4d6747a1e629023e32365651e26e4eb Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 19:54:43 +0100 Subject: [PATCH 15/25] Lazy static logger in Util --- .../src/main/java/com/adjust/sdk/Util.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java index 8eaf4b2eb..750ecd409 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java @@ -48,7 +48,10 @@ public class Util { private static SimpleDateFormat dateFormat; private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'Z"; private static final String fieldReadErrorMessage = "Unable to read '%s' field in migration device with message (%s)"; - private static final ILogger logger = AdjustFactory.getLogger(); + + private static ILogger getLogger() { + return AdjustFactory.getLogger(); + } protected static String createUuid() { return UUID.randomUUID().toString(); @@ -99,27 +102,27 @@ public static T readObject(Context context, String filename, String objectNa try { object = (T) objectStream.readObject(); - logger.debug("Read %s: %s", objectName, object); + getLogger().debug("Read %s: %s", objectName, object); } catch (ClassNotFoundException e) { - logger.error("Failed to find %s class", objectName); + getLogger().error("Failed to find %s class", objectName); } catch (OptionalDataException e) { /* no-op */ } catch (IOException e) { - logger.error("Failed to read %s object", objectName); + getLogger().error("Failed to read %s object", objectName); } catch (ClassCastException e) { - logger.error("Failed to cast %s object", objectName); + getLogger().error("Failed to cast %s object", objectName); } } catch (FileNotFoundException e) { - logger.verbose("%s file not found", objectName); + getLogger().verbose("%s file not found", objectName); } catch (Exception e) { - logger.error("Failed to open %s file for reading (%s)", objectName, e); + getLogger().error("Failed to open %s file for reading (%s)", objectName, e); } try { if (closable != null) { closable.close(); } } catch (Exception e) { - logger.error("Failed to close %s file for reading (%s)", objectName, e); + getLogger().error("Failed to close %s file for reading (%s)", objectName, e); } return object; @@ -139,19 +142,19 @@ public static void writeObject(T object, Context context, String filename, S try { objectStream.writeObject(object); - logger.debug("Wrote %s: %s", objectName, object); + getLogger().debug("Wrote %s: %s", objectName, object); } catch (NotSerializableException e) { - logger.error("Failed to serialize %s", objectName); + getLogger().error("Failed to serialize %s", objectName); } } catch (Exception e) { - logger.error("Failed to open %s for writing (%s)", objectName, e); + getLogger().error("Failed to open %s for writing (%s)", objectName, e); } try { if (closable != null) { closable.close(); } } catch (Exception e) { - logger.error("Failed to close %s file for writing (%s)", objectName, e); + getLogger().error("Failed to close %s file for writing (%s)", objectName, e); } } @@ -166,17 +169,17 @@ public static JSONObject parseJsonResponse(HttpResponse httpResponse) { out.close(); stringResponse = out.toString().trim(); } catch (Exception e) { - logger.error("Failed to parse response (%s)", e.getMessage()); + getLogger().error("Failed to parse response (%s)", e.getMessage()); } - logger.verbose("Response: %s", stringResponse); + getLogger().verbose("Response: %s", stringResponse); if (stringResponse == null) return null; JSONObject jsonResponse = null; try { jsonResponse = new JSONObject(stringResponse); } catch (JSONException e) { - logger.error("Failed to parse json response: %s (%s)", stringResponse, e.getMessage()); + getLogger().error("Failed to parse json response: %s (%s)", stringResponse, e.getMessage()); } if (jsonResponse == null) return null; @@ -188,9 +191,9 @@ public static JSONObject parseJsonResponse(HttpResponse httpResponse) { } if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - logger.info("%s", message); + getLogger().info("%s", message); } else { - logger.error("%s", message); + getLogger().error("%s", message); } return jsonResponse; @@ -212,7 +215,7 @@ public static String readStringField(ObjectInputStream.GetField fields, String n try { return (String) fields.get(name, defaultValue); } catch (Exception e) { - logger.debug(fieldReadErrorMessage, name, e.getMessage()); + getLogger().debug(fieldReadErrorMessage, name, e.getMessage()); return defaultValue; } } @@ -221,7 +224,7 @@ public static boolean readBooleanField(ObjectInputStream.GetField fields, String try { return fields.get(name, defaultValue); } catch (Exception e) { - logger.debug(fieldReadErrorMessage, name, e.getMessage()); + getLogger().debug(fieldReadErrorMessage, name, e.getMessage()); return defaultValue; } } @@ -230,7 +233,7 @@ public static int readIntField(ObjectInputStream.GetField fields, String name, i try { return fields.get(name, defaultValue); } catch (Exception e) { - logger.debug(fieldReadErrorMessage, name, e.getMessage()); + getLogger().debug(fieldReadErrorMessage, name, e.getMessage()); return defaultValue; } } @@ -239,7 +242,7 @@ public static long readLongField(ObjectInputStream.GetField fields, String name, try { return fields.get(name, defaultValue); } catch (Exception e) { - logger.debug(fieldReadErrorMessage, name, e.getMessage()); + getLogger().debug(fieldReadErrorMessage, name, e.getMessage()); return defaultValue; } } From 832278f329a082efdd11b4c6570c15b06655c352 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 19 Mar 2015 20:00:44 +0100 Subject: [PATCH 16/25] Update tests --- .../adjust/sdk/test/TestActivityHandler.java | 112 +----------------- .../sdk/test/TestAttributionHandler.java | 4 +- .../adjust/sdk/test/TestPackageHandler.java | 3 +- .../adjust/sdk/test/TestRequestHandler.java | 6 +- 4 files changed, 11 insertions(+), 114 deletions(-) diff --git a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestActivityHandler.java b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestActivityHandler.java index df6a1d3d0..8ff10d0e3 100644 --- a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestActivityHandler.java +++ b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestActivityHandler.java @@ -1122,8 +1122,6 @@ public void testOfflineMode() { assertUtil.test("PackageHandler pauseSending"); - assertUtil.test("AttributionHandler init, startPaused: true"); - assertUtil.test("AttributionHandler pauseSending"); // disable the SDK @@ -1315,26 +1313,8 @@ public void testGetAttribution() { AdjustFactory.setTimerStart(500); /*** * if (attribution == null || activityState.askingAttribution) { - * if (shouldGetAttribution) { * getAttributionHandler().getAttribution(); - * } * } - * - * 9 possible states with variables - * attribution = null -> attrNul - * askingAttribution = true -> askAttr - * shouldGetAttribution = true -> shldGet - * getAttribution is called -> getAttr - * - * State Number attrNul | askAttr | shldGet -> getAttr - * 000->0 0 False | False | False -> False - * 001->0 1 False | False | True -> False - * 010->0 2 False | True | False -> False - * 011->1 3 False | True | True -> True - * 100->0 4 True | False | False -> False - * 101->1 5 True | False | True -> True - * 110->0 6 True | True | False -> False - * 111->1 7 True | True | True -> True */ // create the config to start the session @@ -1355,26 +1335,22 @@ public void onAttributionChanged(AdjustAttribution attribution) { // test init values initTests(AdjustConfig.ENVIRONMENT_SANDBOX, "INFO", false); - // state 100->0 number 4 // attribution is null, // askingAttribution is false by default, - // shouldGetAttribution is false after a session // test first session start firstSessionStartWithoutTimerTests(false, false); - timerFiredTest(); + // there should be a getAttribution + assertUtil.test("AttributionHandler getAttribution"); - // there shouldn't be a getAttribution - assertUtil.notInTest("AttributionHandler getAttribution"); + timerFiredTest(); // save activity state assertUtil.debug("Wrote Activity state: ec:0 sc:1 ssc:1"); - // state 110->0 number 6 // attribution is null, // askingAttribution is set to true, - // shouldGetAttribution is false after a session // set asking attribution activityHandler.setAskingAttribution(true); @@ -1384,12 +1360,10 @@ public void onAttributionChanged(AdjustAttribution attribution) { activityHandler.trackSubsessionStart(); SystemClock.sleep(2000); - subsessionGetAttributionTest(2, false); + subsessionGetAttributionTest(2, true); - // state 010->0 number 2 // attribution is set, // askingAttribution is set to true, - // shouldGetAttribution is false after a session JSONObject jsonAttribution = null; @@ -1416,12 +1390,10 @@ public void onAttributionChanged(AdjustAttribution attribution) { activityHandler.trackSubsessionStart(); SystemClock.sleep(2000); - subsessionGetAttributionTest(3, false); + subsessionGetAttributionTest(3, true); - // state 000->0 number 0 // attribution is set, // askingAttribution is set to false - // shouldGetAttribution is false after a session activityHandler.setAskingAttribution(false); assertUtil.debug("Wrote Activity state: ec:0 sc:1 ssc:3"); @@ -1431,80 +1403,6 @@ public void onAttributionChanged(AdjustAttribution attribution) { SystemClock.sleep(2000); subsessionGetAttributionTest(4, false); - - // state 101->1 number 5 - // attribution is null, - // askingAttribution is set to false from the previous activity handler - // shouldGetAttribution is true after restarting with no new session - - // delete attribution to start as null - ActivityHandler.deleteAttribution(context); - - // deleting the attribution file to simulate a first session - mockLogger.test("Was Attribution deleted? " + true); - - // reset activity handler with previous saved activity state - config = new AdjustConfig(context, "123456789012", AdjustConfig.ENVIRONMENT_SANDBOX); - - config.setOnAttributionChangedListener(new OnAttributionChangedListener() { - @Override - public void onAttributionChanged(AdjustAttribution attribution) { - mockLogger.test("onAttributionChanged " + attribution); - } - }); - activityHandler = ActivityHandler.getInstance(config); - - SystemClock.sleep(3000); - - // test init values - initTests(AdjustConfig.ENVIRONMENT_SANDBOX, "INFO", false); - - subsessionGetAttributionTest(5, true); - - // state 111->1 number 7 - // attribution is null, - // askingAttribution is set to true, - // shouldGetAttribution is still true - - activityHandler.setAskingAttribution(true); - assertUtil.debug("Wrote Activity state: ec:0 sc:1 ssc:5"); - - // trigger a new sub session - activityHandler.trackSubsessionStart(); - SystemClock.sleep(2000); - - subsessionGetAttributionTest(6, true); - - // state 011->1 number 3 - // attribution is set, - // askingAttribution is set to true, - // shouldGetAttribution is still true - - // update the attribution - activityHandler.tryUpdateAttribution(attribution); - - // attribution was updated - assertUtil.debug("Wrote Attribution: tt:ttValue tn:tnValue net:nValue cam:cpValue adg:aValue cre:ctValue"); - - // trigger a new sub session - activityHandler.trackSubsessionStart(); - SystemClock.sleep(2000); - - subsessionGetAttributionTest(7, true); - - // state 001->0 number 1 - // attribution is set, - // askingAttribution is set to false, - // shouldGetAttribution is still true - - activityHandler.setAskingAttribution(false); - assertUtil.debug("Wrote Activity state: ec:0 sc:1 ssc:7"); - - // trigger a new sub session - activityHandler.trackSubsessionStart(); - SystemClock.sleep(2000); - - subsessionGetAttributionTest(8, false); } private void firstSessionSubsessionsTest(int subsessionCount) { diff --git a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestAttributionHandler.java b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestAttributionHandler.java index b56429538..3101561ed 100644 --- a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestAttributionHandler.java +++ b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestAttributionHandler.java @@ -216,7 +216,7 @@ private void emptyJsonResponseTest(AttributionHandler attributionHandler) { assertUtil.verbose("Response: { }"); - assertUtil.debug("No message found"); + assertUtil.info("No message found"); // check attribution was called without ask_in assertUtil.test("ActivityHandler tryUpdateAttribution, null"); @@ -254,7 +254,7 @@ private void okMessageTestLogs() { assertUtil.verbose("Response: { \"message\" : \"response OK\"}"); // the message in the response - assertUtil.debug("response OK"); + assertUtil.info("response OK"); // check attribution was called without ask_in assertUtil.test("ActivityHandler tryUpdateAttribution, null"); diff --git a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestPackageHandler.java b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestPackageHandler.java index da75ea4ac..2642acf30 100644 --- a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestPackageHandler.java +++ b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestPackageHandler.java @@ -277,8 +277,7 @@ private void deletePackageQueue() { } private ActivityPackage createUnknowPackage(String suffix) { - ActivityPackage activityPackage = new ActivityPackage(); - activityPackage.setActivityKind(ActivityKind.UNKNOWN); + ActivityPackage activityPackage = new ActivityPackage(ActivityKind.UNKNOWN); activityPackage.setSuffix(suffix); return activityPackage; diff --git a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestRequestHandler.java b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestRequestHandler.java index 19077a036..fab7f948d 100644 --- a/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestRequestHandler.java +++ b/Adjust/test/src/androidTest/java/com/adjust/sdk/test/TestRequestHandler.java @@ -170,7 +170,7 @@ private void emptyJsonTest(boolean sendClick) { assertUtil.verbose("Response: { }"); - assertUtil.debug("No message found"); + assertUtil.info("No message found"); assertUtil.test("PackageHandler finishedTrackingActivity, {}"); @@ -186,7 +186,7 @@ private void messageTest(boolean sendClick) { assertUtil.verbose("Response: { \"message\" : \"response OK\"}"); - assertUtil.debug("response OK"); + assertUtil.info("response OK"); assertUtil.test("PackageHandler finishedTrackingActivity, {\"message\":\"response OK\"}"); @@ -202,7 +202,7 @@ private void attributionTest(boolean sendClick) { assertUtil.verbose("Response: { \"attribution\" : {\"tracker_token\" : \"ttValue\" , \"tracker_name\" : \"tnValue\" , \"network\" : \"nValue\" , \"campaign\" : \"cpValue\" , \"adgroup\" : \"aValue\" , \"creative\" : \"ctValue\" } }"); - assertUtil.debug("No message found"); + assertUtil.info("No message found"); assertUtil.test("PackageHandler finishedTrackingActivity, {\"attribution\":{\"tracker_token\":\"ttValue\",\"tracker_name\":\"tnValue\",\"network\":\"nValue\",\"campaign\":\"cpValue\",\"adgroup\":\"aValue\",\"creative\":\"ctValue\"}}"); From 2633e0b9a62ddb85967209556f6c477316ee084c Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 23 Mar 2015 14:10:10 +0100 Subject: [PATCH 17/25] Update Criteo view listing --- Adjust/plugin/AdjustCriteo.java | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Adjust/plugin/AdjustCriteo.java b/Adjust/plugin/AdjustCriteo.java index 4fdb00130..c18dd10f5 100644 --- a/Adjust/plugin/AdjustCriteo.java +++ b/Adjust/plugin/AdjustCriteo.java @@ -20,8 +20,8 @@ public static void injectViewSearchIntoEvent(AdjustEvent event, String checkInDa event.addPartnerParameter("dout", checkOutDate); } - public static void injectViewListingIntoEvent(AdjustEvent event, List products, String customerId) { - String jsonProducts = createCriteoVLFromProducts(products); + public static void injectViewListingIntoEvent(AdjustEvent event, List productIds, String customerId) { + String jsonProducts = createCriteoVLFromProducts(productIds); if (jsonProducts == null) { logger.error("Missing products from Criteo View Listing"); @@ -59,35 +59,35 @@ public static void injectTransactionConfirmedIntoEvent(AdjustEvent event, List products) { - if (products == null) { + private static String createCriteoVLFromProducts(List productIds) { + if (productIds == null) { return null; } - StringBuffer criteoVBValue = new StringBuffer("["); - int productsSize = products.size(); + StringBuffer criteoVLValue = new StringBuffer("["); + int productIdsSize = productIds.size(); - if (productsSize > MAX_VIEW_LISTING_PRODUCTS) { - logger.warn("View Listing events should only have at most 3 objects, discarding the rest"); + if (productIdsSize > MAX_VIEW_LISTING_PRODUCTS) { + logger.warn("Criteo View Listing should only have at most 3 product ids. The rest will be discarded."); } - for (int i = 0; i < productsSize; ) { - CriteoProduct criteoProduct = products.get(i); - String productString = String.format("\"%s\"", criteoProduct.productID); - criteoVBValue.append(productString); + for (int i = 0; i < productIdsSize; ) { + String productID = productIds.get(i); + String productString = String.format("\"%s\"", productID); + criteoVLValue.append(productString); i++; - if (i == productsSize || i >= MAX_VIEW_LISTING_PRODUCTS) { + if (i == productIdsSize || i >= MAX_VIEW_LISTING_PRODUCTS) { break; } - criteoVBValue.append(","); + criteoVLValue.append(","); } - criteoVBValue.append("]"); + criteoVLValue.append("]"); String result = null; try { - result = URLEncoder.encode(criteoVBValue.toString(),"UTF-8"); + result = URLEncoder.encode(criteoVLValue.toString(),"UTF-8"); } catch (UnsupportedEncodingException e) { - logger.error("error converting criteo products (%s)", e.getMessage()); + logger.error("error converting criteo product ids (%s)", e.getMessage()); } return result; } From 086f5537ae55b4591222b53add9e5c0c5f8add7f Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 23 Mar 2015 14:19:20 +0100 Subject: [PATCH 18/25] New criteo events --- Adjust/plugin/AdjustCriteo.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Adjust/plugin/AdjustCriteo.java b/Adjust/plugin/AdjustCriteo.java index c18dd10f5..03efc12dd 100644 --- a/Adjust/plugin/AdjustCriteo.java +++ b/Adjust/plugin/AdjustCriteo.java @@ -59,6 +59,32 @@ public static void injectTransactionConfirmedIntoEvent(AdjustEvent event, List productIds) { if (productIds == null) { return null; From 700fb55ab6db3ffc698e3fc8da98feca7d3659c1 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 23 Mar 2015 14:26:43 +0100 Subject: [PATCH 19/25] Criteo inject hash email --- Adjust/plugin/AdjustCriteo.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Adjust/plugin/AdjustCriteo.java b/Adjust/plugin/AdjustCriteo.java index 03efc12dd..f79252b9d 100644 --- a/Adjust/plugin/AdjustCriteo.java +++ b/Adjust/plugin/AdjustCriteo.java @@ -14,10 +14,12 @@ public class AdjustCriteo { private static ILogger logger = AdjustFactory.getLogger(); private static int MAX_VIEW_LISTING_PRODUCTS = 3; + private static String hashEmailInternal; public static void injectViewSearchIntoEvent(AdjustEvent event, String checkInDate, String checkOutDate) { event.addPartnerParameter("din", checkInDate); event.addPartnerParameter("dout", checkOutDate); + injectHashEmail(event); } public static void injectViewListingIntoEvent(AdjustEvent event, List productIds, String customerId) { @@ -30,11 +32,13 @@ public static void injectViewListingIntoEvent(AdjustEvent event, List pr event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("criteo_p", jsonProducts); + injectHashEmail(event); } public static void injectViewProductIntoEvent(AdjustEvent event, String productId, String customerId) { event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("criteo_p", productId); + injectHashEmail(event); } public static void injectCartIntoEvent(AdjustEvent event, List products, String customerId) { @@ -46,6 +50,7 @@ public static void injectCartIntoEvent(AdjustEvent event, List pr event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("criteo_p", jsonProducts); + injectHashEmail(event); } public static void injectTransactionConfirmedIntoEvent(AdjustEvent event, List products, String customerId) { @@ -57,32 +62,50 @@ public static void injectTransactionConfirmedIntoEvent(AdjustEvent event, List productIds) { From 8306cdeff8bce9a33b04687952fb166ad59e1786 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 23 Mar 2015 15:01:46 +0100 Subject: [PATCH 20/25] Criteo messages equal of iOs --- Adjust/plugin/AdjustCriteo.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Adjust/plugin/AdjustCriteo.java b/Adjust/plugin/AdjustCriteo.java index f79252b9d..040c40166 100644 --- a/Adjust/plugin/AdjustCriteo.java +++ b/Adjust/plugin/AdjustCriteo.java @@ -26,7 +26,7 @@ public static void injectViewListingIntoEvent(AdjustEvent event, List pr String jsonProducts = createCriteoVLFromProducts(productIds); if (jsonProducts == null) { - logger.error("Missing products from Criteo View Listing"); + logger.error("Criteo View Listing must contain a product id list."); return; } @@ -44,7 +44,7 @@ public static void injectViewProductIntoEvent(AdjustEvent event, String productI public static void injectCartIntoEvent(AdjustEvent event, List products, String customerId) { String jsonProducts = createCriteoVBFromProducts(products); if (jsonProducts == null) { - logger.error("Missing products from Criteo Cart"); + logger.error("Criteo Cart must contain a list of CriteoProduct."); return; } @@ -56,7 +56,7 @@ public static void injectCartIntoEvent(AdjustEvent event, List pr public static void injectTransactionConfirmedIntoEvent(AdjustEvent event, List products, String customerId) { String jsonProducts = createCriteoVBFromProducts(products); if (jsonProducts == null) { - logger.error("Missing products from Criteo Transaction Confirmed"); + logger.error("Criteo Transaction Confirmed must contain a list of products."); return; } From d1f874a938d72814532ecf18fdfc98d4664a47ad Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 23 Mar 2015 16:47:42 +0100 Subject: [PATCH 21/25] Criteo accept null as empty --- Adjust/plugin/AdjustCriteo.java | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/Adjust/plugin/AdjustCriteo.java b/Adjust/plugin/AdjustCriteo.java index 040c40166..4466c7db3 100644 --- a/Adjust/plugin/AdjustCriteo.java +++ b/Adjust/plugin/AdjustCriteo.java @@ -6,6 +6,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.ArrayList; import java.util.List; /** @@ -19,73 +20,68 @@ public class AdjustCriteo { public static void injectViewSearchIntoEvent(AdjustEvent event, String checkInDate, String checkOutDate) { event.addPartnerParameter("din", checkInDate); event.addPartnerParameter("dout", checkOutDate); + injectHashEmail(event); } public static void injectViewListingIntoEvent(AdjustEvent event, List productIds, String customerId) { String jsonProducts = createCriteoVLFromProducts(productIds); - - if (jsonProducts == null) { - logger.error("Criteo View Listing must contain a product id list."); - return; - } - event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("criteo_p", jsonProducts); + injectHashEmail(event); } public static void injectViewProductIntoEvent(AdjustEvent event, String productId, String customerId) { event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("criteo_p", productId); + injectHashEmail(event); } public static void injectCartIntoEvent(AdjustEvent event, List products, String customerId) { String jsonProducts = createCriteoVBFromProducts(products); - if (jsonProducts == null) { - logger.error("Criteo Cart must contain a list of CriteoProduct."); - return; - } event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("criteo_p", jsonProducts); + injectHashEmail(event); } public static void injectTransactionConfirmedIntoEvent(AdjustEvent event, List products, String customerId) { String jsonProducts = createCriteoVBFromProducts(products); - if (jsonProducts == null) { - logger.error("Criteo Transaction Confirmed must contain a list of products."); - return; - } event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("criteo_p", jsonProducts); + injectHashEmail(event); } public static void injectUserLevelIntoEvent(AdjustEvent event, long uiLevel, String customerId) { event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("ui_level", String.valueOf(uiLevel)); + injectHashEmail(event); } public static void injectUserStatusIntoEvent(AdjustEvent event, String uiStatus, String customerId) { event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("ui_status", uiStatus); + injectHashEmail(event); } public static void injectAchievementUnlockedIntoEvent(AdjustEvent event, String uiAchievement, String customerId) { event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("ui_achievmnt", uiAchievement); + injectHashEmail(event); } public static void injectCustomEventIntoEvent(AdjustEvent event, String uiData, String customerId) { event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("ui_data", uiData); + injectHashEmail(event); } @@ -93,6 +89,7 @@ public static void injectCustomEvent2IntoEvent(AdjustEvent event, String uiData2 event.addPartnerParameter("customer_id", customerId); event.addPartnerParameter("ui_data2", uiData2); event.addPartnerParameter("ui_data3", String.valueOf(uiData3)); + injectHashEmail(event); } @@ -110,7 +107,8 @@ private static void injectHashEmail(AdjustEvent event) { private static String createCriteoVLFromProducts(List productIds) { if (productIds == null) { - return null; + logger.warn("Criteo View Listing product ids list is null. It will sent as empty."); + productIds = new ArrayList(); } StringBuffer criteoVLValue = new StringBuffer("["); int productIdsSize = productIds.size(); @@ -142,8 +140,9 @@ private static String createCriteoVLFromProducts(List productIds) { } private static String createCriteoVBFromProducts(List products) { - if (logger == null) { - return null; + if (products == null) { + logger.warn("Criteo Event product list is empty. It will sent as empty."); + products = new ArrayList(); } StringBuffer criteoVBValue = new StringBuffer("["); int productsSize = products.size(); From 71d0e493e802b46dd7e82335dbc9dd0b99fb48f9 Mon Sep 17 00:00:00 2001 From: Pedro Filipe Date: Mon, 23 Mar 2015 16:50:27 +0100 Subject: [PATCH 22/25] Criteo doc correct view listing --- doc/criteo_plugin.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/criteo_plugin.md b/doc/criteo_plugin.md index eb2d25a4e..3aab427e5 100644 --- a/doc/criteo_plugin.md +++ b/doc/criteo_plugin.md @@ -40,13 +40,9 @@ import com.adjust.sdk.plugin.AdjustCriteo; AdjustEvent event = new AdjustEvent("{viewListingEventToken}"); -CriteoProduct product1 = new CriteoProduct(100, 1, "productId1"); -CriteoProduct product2 = new CriteoProduct(77.7f, 3, "productId2"); -CriteoProduct product3 = new CriteoProduct(50, 2, "productId3"); - -List products = Arrays.asList(product1, product2, product3); +List productIds = Arrays.asList("productId1", "productId2", "productId3"); -AdjustCriteo.injectViewListingIntoEvent(event, products, "customerId1"); +AdjustCriteo.injectViewListingIntoEvent(event, productIds, "customerId1"); Adjust.trackEvent(event); ``` From f91faf4e1ebcb1ebb34a5370b660e84f325dd3de Mon Sep 17 00:00:00 2001 From: Pedro Filipe Date: Mon, 23 Mar 2015 16:56:01 +0100 Subject: [PATCH 23/25] Creteo doc added new events --- doc/criteo_plugin.md | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/doc/criteo_plugin.md b/doc/criteo_plugin.md index 3aab427e5..37ccbd86c 100644 --- a/doc/criteo_plugin.md +++ b/doc/criteo_plugin.md @@ -94,3 +94,76 @@ AdjustCriteo.injectTransactionConfirmedIntoEvent(event, products, "customerId1") Adjust.trackEvent(event); ``` + +### User Level + +```java +import com.adjust.sdk.plugin.AdjustCriteo; + +AdjustEvent event = new AdjustEvent("{userLevelEventToken}"); + +AdjustCriteo.injectUserLevelIntoEvent(event, 1, "customerId1"); + +Adjust.trackEvent(event); +``` + +### User Status + +```java +import com.adjust.sdk.plugin.AdjustCriteo; + +AdjustEvent event = new AdjustEvent("{userStatusEventToken}"); + +AdjustCriteo.injectUserStatusIntoEvent(event, "uiStatusValue", "customerId1"); + +Adjust.trackEvent(event); +``` + +### Achievement Unlocked + +```java +import com.adjust.sdk.plugin.AdjustCriteo; + +AdjustEvent event = new AdjustEvent("{achievementUnlockedEventToken}"); + +AdjustCriteo.injectAchievementUnlockedIntoEvent(event, "AchievementUnlocked", "customerId1"); + +Adjust.trackEvent(event); +``` + +### Custom Event + +```java +import com.adjust.sdk.plugin.AdjustCriteo; + +AdjustEvent event = new AdjustEvent("{customEventEventToken}"); + +AdjustCriteo.injectCustomEventIntoEvent(event, "uiDataValue", "customerId1"); + +Adjust.trackEvent(event); +``` + +### Custom Event 2 + +```java +import com.adjust.sdk.plugin.AdjustCriteo; + +AdjustEvent event = new AdjustEvent("{customEvent2EventToken}"); + +AdjustCriteo.injectCustomEvent2IntoEvent(event, "uiData2Value", 3, "customerId1"); + +Adjust.trackEvent(event); +``` + +### Hashed Email + +It's possible to attach an hashed email in every Criteo event with the `injectHashedEmailIntoCriteoEvents` method. +The hashed email will be sent with every Criteo event for the duration of the application lifecycle, +so it must be set again when the app is re-lauched. +The hashed email can be removed by setting the `injectHashedEmailIntoCriteoEvents` method with `null`. + +```java +import com.adjust.sdk.plugin.AdjustCriteo; + +AdjustCriteo.injectHashedEmailIntoCriteoEvents("8455938a1db5c475a87d76edacb6284e"); +``` From 6e9248783d48bb4c799b15e6a48278cb0b060b30 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 23 Mar 2015 18:09:33 +0100 Subject: [PATCH 24/25] Fix migrate Activity kind --- .../java/com/adjust/sdk/ActivityKind.java | 2 +- .../java/com/adjust/sdk/ActivityPackage.java | 20 +++++++++++++------ .../java/com/adjust/sdk/ActivityState.java | 18 ++++++++--------- .../src/main/java/com/adjust/sdk/Util.java | 18 ++++++++--------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityKind.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityKind.java index a255b83a9..01c526ffc 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityKind.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityKind.java @@ -1,7 +1,7 @@ package com.adjust.sdk; public enum ActivityKind { - UNKNOWN, SESSION, EVENT, CLICK, ATTRIBUTION; + UNKNOWN, SESSION, EVENT, CLICK, ATTRIBUTION, REVENUE, REATTRIBUTION; public static ActivityKind fromString(String string) { if ("session".equals(string)) { diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java index c90f6700e..967c0a7b0 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java @@ -20,6 +20,7 @@ public class ActivityPackage implements Serializable { private static final long serialVersionUID = -35935556512024097L; + private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField("path", String.class), new ObjectStreamField("clientSdk", String.class), @@ -27,6 +28,7 @@ public class ActivityPackage implements Serializable { new ObjectStreamField("activityKind", ActivityKind.class), new ObjectStreamField("suffix", String.class) }; + private transient int hashCode; // data @@ -106,7 +108,13 @@ private void writeObject(ObjectOutputStream stream) throws IOException { } private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException { - stream.defaultReadObject(); + ObjectInputStream.GetField fields = stream.readFields(); + + path = Util.readStringField(fields, "path", null); + clientSdk = Util.readStringField(fields, "clientSdk", null); + parameters = Util.readObjectField(fields, "parameters", null); + activityKind = Util.readObjectField(fields, "activityKind", ActivityKind.UNKNOWN); + suffix = Util.readStringField(fields, "suffix", null); } @Override @@ -116,11 +124,11 @@ public boolean equals(Object other) { if (getClass() != other.getClass()) return false; ActivityPackage otherActivityPackage = (ActivityPackage) other; - if (!Util.equalString( path, otherActivityPackage.path)) return false; - if (!Util.equalString( clientSdk, otherActivityPackage.clientSdk)) return false; - if (!Util.equalsMap( parameters, otherActivityPackage.parameters)) return false; - if (!Util.equalEnum( activityKind, otherActivityPackage.activityKind)) return false; - if (!Util.equalString( suffix, otherActivityPackage.suffix)) return false; + if (!Util.equalString(path, otherActivityPackage.path)) return false; + if (!Util.equalString(clientSdk, otherActivityPackage.clientSdk)) return false; + if (!Util.equalsMap(parameters, otherActivityPackage.parameters)) return false; + if (!Util.equalEnum(activityKind, otherActivityPackage.activityKind)) return false; + if (!Util.equalString(suffix, otherActivityPackage.suffix)) return false; return true; } diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java index bd777cbbb..bd18e8447 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java @@ -100,15 +100,15 @@ public boolean equals(Object other) { if (getClass() != other.getClass()) return false; ActivityState otherActivityState = (ActivityState) other; - if (!Util.equalString( uuid, otherActivityState.uuid)) return false; - if (!Util.equalBoolean( enabled, otherActivityState.enabled)) return false; - if (!Util.equalBoolean( askingAttribution, otherActivityState.askingAttribution)) return false; - if (!Util.equalInt( eventCount, otherActivityState.eventCount)) return false; - if (!Util.equalInt( sessionCount, otherActivityState.sessionCount)) return false; - if (!Util.equalInt( subsessionCount, otherActivityState.subsessionCount)) return false; - if (!Util.equalLong( sessionLength, otherActivityState.sessionLength)) return false; - if (!Util.equalLong( timeSpent, otherActivityState.timeSpent)) return false; - if (!Util.equalLong( lastInterval, otherActivityState.lastInterval)) return false; + if (!Util.equalString(uuid, otherActivityState.uuid)) return false; + if (!Util.equalBoolean(enabled, otherActivityState.enabled)) return false; + if (!Util.equalBoolean(askingAttribution, otherActivityState.askingAttribution)) return false; + if (!Util.equalInt(eventCount, otherActivityState.eventCount)) return false; + if (!Util.equalInt(sessionCount, otherActivityState.sessionCount)) return false; + if (!Util.equalInt(subsessionCount, otherActivityState.subsessionCount)) return false; + if (!Util.equalLong(sessionLength, otherActivityState.sessionLength)) return false; + if (!Util.equalLong(timeSpent, otherActivityState.timeSpent)) return false; + if (!Util.equalLong(lastInterval, otherActivityState.lastInterval)) return false; return true; } diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java index 750ecd409..c498755dd 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/Util.java @@ -28,11 +28,9 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.IOException; import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.io.OptionalDataException; import java.text.SimpleDateFormat; import java.util.Locale; import java.util.Map; @@ -104,13 +102,11 @@ public static T readObject(Context context, String filename, String objectNa object = (T) objectStream.readObject(); getLogger().debug("Read %s: %s", objectName, object); } catch (ClassNotFoundException e) { - getLogger().error("Failed to find %s class", objectName); - } catch (OptionalDataException e) { - /* no-op */ - } catch (IOException e) { - getLogger().error("Failed to read %s object", objectName); + getLogger().error("Failed to find %s class (%s)", objectName, e.getMessage()); } catch (ClassCastException e) { - getLogger().error("Failed to cast %s object", objectName); + getLogger().error("Failed to cast %s object (%s)", objectName, e.getMessage()); + } catch (Exception e) { + getLogger().error("Failed to read %s object (%s)", objectName, e.getMessage()); } } catch (FileNotFoundException e) { getLogger().verbose("%s file not found", objectName); @@ -212,8 +208,12 @@ public static boolean checkPermission(Context context, String permission) { } public static String readStringField(ObjectInputStream.GetField fields, String name, String defaultValue) { + return readObjectField(fields, name, defaultValue); + } + + public static T readObjectField(ObjectInputStream.GetField fields, String name, T defaultValue) { try { - return (String) fields.get(name, defaultValue); + return (T) fields.get(name, defaultValue); } catch (Exception e) { getLogger().debug(fieldReadErrorMessage, name, e.getMessage()); return defaultValue; From 1d97c50ce4d69ef9b29400bd561aeab0b20efb11 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 23 Mar 2015 18:12:22 +0100 Subject: [PATCH 25/25] Prevent activity kind null pointer --- Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java index 967c0a7b0..f2cb8b9b0 100644 --- a/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java +++ b/Adjust/adjust/src/main/java/com/adjust/sdk/ActivityPackage.java @@ -100,7 +100,7 @@ public String getExtendedString() { } protected String getFailureMessage() { - return String.format("Failed to track %s%s", activityKind.toString(), suffix); + return String.format("Failed to track %s%s", (activityKind == null? "unknown":activityKind.toString()), suffix); } private void writeObject(ObjectOutputStream stream) throws IOException {