Skip to content

Commit

Permalink
Merge pull request #236 from adjust/v4110
Browse files Browse the repository at this point in the history
V4110
  • Loading branch information
nonelse authored Dec 14, 2016
2 parents c7225b8 + 468b742 commit 91107f1
Show file tree
Hide file tree
Showing 37 changed files with 847 additions and 361 deletions.
4 changes: 2 additions & 2 deletions Adjust/adjust/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

def getVersionName() {
return "4.10.4"
return "4.11.0"
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 9
Expand Down
82 changes: 74 additions & 8 deletions Adjust/adjust/src/main/java/com/adjust/sdk/ActivityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import android.net.Uri;
import android.os.Handler;

import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import static com.adjust.sdk.Constants.ACTIVITY_STATE_FILENAME;
import static com.adjust.sdk.Constants.ATTRIBUTION_FILENAME;
Expand Down Expand Up @@ -286,7 +288,7 @@ public void finishedTrackingActivity(ResponseData responseData) {
}
// check if it's an event response
if (responseData instanceof EventResponseData) {
launchEventResponseTasksI((EventResponseData)responseData);
launchEventResponseTasks((EventResponseData)responseData);
return;
}
}
Expand Down Expand Up @@ -412,6 +414,20 @@ public void run() {
});
}

private void updateAdidI(final String adid) {
if (adid == null) {
return;
}

if (adid.equals(activityState.adid)) {
return;
}

activityState.adid = adid;
writeActivityStateI();
return;
}

@Override
public boolean updateAttributionI(AdjustAttribution attribution) {
if (attribution == null) {
Expand Down Expand Up @@ -562,6 +578,17 @@ public void run() {
});
}

public String getAdid() {
if (activityState == null) {
return null;
}
return activityState.adid;
}

public AdjustAttribution getAttribution() {
return attribution;
}

public ActivityPackage getAttributionPackageI() {
long now = System.currentTimeMillis();
PackageBuilder attributionBuilder = new PackageBuilder(adjustConfig,
Expand Down Expand Up @@ -605,6 +632,8 @@ private void initI() {
internalState.updatePackages = activityState.updatePackages;
}

readConfigFile(adjustConfig.context);

deviceInfo = new DeviceInfo(adjustConfig.context, adjustConfig.sdkPrefix);

if (adjustConfig.eventBufferingEnabled) {
Expand All @@ -628,6 +657,13 @@ private void initI() {
logger.info("Default tracker: '%s'", adjustConfig.defaultTracker);
}

if (adjustConfig.pushToken != null) {
logger.info("Push token: '%s'", adjustConfig.pushToken);
if (activityState != null) {
setPushToken(adjustConfig.pushToken);
}
}

foregroundTimer = new TimerCycle(scheduledExecutor,
new Runnable() {
@Override
Expand Down Expand Up @@ -686,6 +722,27 @@ public void run() {
sessionParametersActionsI(adjustConfig.sessionParametersActionsArray);
}

private void readConfigFile(Context context) {
Properties properties;

try {
InputStream inputStream = context.getAssets().open("adjust_config.properties");
properties = new Properties();
properties.load(inputStream);
} catch (Exception e) {
logger.debug("%s file not found in this app", e.getMessage());
return;
}

logger.verbose("adjust_config.properties file read and loaded");

String defaultTracker = properties.getProperty("defaultTracker");

if (defaultTracker != null) {
adjustConfig.defaultTracker = defaultTracker;
}
}

private void sessionParametersActionsI(List<IRunActivityHandler> sessionParametersActionsArray) {
if (sessionParametersActionsArray == null) {
return;
Expand Down Expand Up @@ -717,12 +774,12 @@ private void processSessionI() {
if (activityState == null) {
activityState = new ActivityState();
activityState.sessionCount = 1; // this is the first session
activityState.pushToken = adjustConfig.pushToken;

transferSessionPackageI(now);
activityState.resetSessionAttributes(now);
activityState.enabled = internalState.isEnabled();
activityState.updatePackages = internalState.isToUpdatePackages();
activityState.pushToken = adjustConfig.pushToken;
writeActivityStateI();
return;
}
Expand Down Expand Up @@ -819,6 +876,9 @@ private void trackEventI(AdjustEvent event) {
}

private void launchEventResponseTasksI(final EventResponseData eventResponseData) {
// try to update adid from response
updateAdidI(eventResponseData.adid);

Handler handler = new Handler(adjustConfig.context.getMainLooper());

// success callback
Expand Down Expand Up @@ -852,6 +912,9 @@ public void run() {
}

private void launchSessionResponseTasksI(SessionResponseData sessionResponseData) {
// try to update adid from response
updateAdidI(sessionResponseData.adid);

// use the same handler to ensure that all tasks are executed sequentially
Handler handler = new Handler(adjustConfig.context.getMainLooper());

Expand Down Expand Up @@ -899,6 +962,9 @@ public void run() {
}

private void launchAttributionResponseTasksI(AttributionResponseData attributionResponseData) {
// try to update adid from response
updateAdidI(attributionResponseData.adid);

Handler handler = new Handler(adjustConfig.context.getMainLooper());

// try to update the attribution
Expand Down Expand Up @@ -1427,16 +1493,16 @@ private void setPushTokenI(String token) {
return;
}

// save new push token
activityState.pushToken = token;
writeActivityStateI();

long now = System.currentTimeMillis();
PackageBuilder infoPackageBuilder = new PackageBuilder(adjustConfig, deviceInfo, activityState, now);
infoPackageBuilder.pushToken = token;

ActivityPackage infoPackage = infoPackageBuilder.buildInfoPackage(Constants.PUSH);
sdkClickHandler.sendSdkClick(infoPackage);

// save new push token
activityState.pushToken = token;
writeActivityStateI();
packageHandler.addPackage(infoPackage);
packageHandler.sendFirstPackage();
}

private void readActivityStateI(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class ActivityState implements Serializable, Cloneable {
new ObjectStreamField("lastInterval", long.class),
new ObjectStreamField("updatePackages", boolean.class),
new ObjectStreamField("orderIds", (Class<LinkedList<String>>)(Class) LinkedList.class),
new ObjectStreamField("pushToken", String.class)
new ObjectStreamField("pushToken", String.class),
new ObjectStreamField("adid", String.class),
};

// persistent data
Expand All @@ -62,6 +63,7 @@ public class ActivityState implements Serializable, Cloneable {
protected LinkedList<String> orderIds;

protected String pushToken;
protected String adid;

protected ActivityState() {
logger = AdjustFactory.getLogger();
Expand All @@ -80,6 +82,7 @@ protected ActivityState() {
updatePackages = false;
orderIds = null;
pushToken = null;
adid = null;
}

protected void resetSessionAttributes(long now) {
Expand Down Expand Up @@ -136,6 +139,7 @@ public boolean equals(Object other) {
if (!Util.equalBoolean(updatePackages, otherActivityState.updatePackages)) return false;
if (!Util.equalObject(orderIds, otherActivityState.orderIds)) return false;
if (!Util.equalString(pushToken, otherActivityState.pushToken)) return false;
if (!Util.equalString(adid, otherActivityState.adid)) return false;
return true;
}

Expand All @@ -154,6 +158,7 @@ public int hashCode() {
hashCode = 37 * hashCode + Util.hashBoolean(updatePackages);
hashCode = 37 * hashCode + Util.hashObject(orderIds);
hashCode = 37 * hashCode + Util.hashString(pushToken);
hashCode = 37 * hashCode + Util.hashString(adid);
return hashCode;
}

Expand All @@ -179,6 +184,8 @@ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFo

pushToken = Util.readStringField(fields, "pushToken", null);

adid = Util.readStringField(fields, "adid", null);

// create UUID for migrating devices
if (uuid == null) {
uuid = Util.createUuid();
Expand Down
10 changes: 10 additions & 0 deletions Adjust/adjust/src/main/java/com/adjust/sdk/Adjust.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,14 @@ public static void setPushToken(String token) {
public static void getGoogleAdId(Context context, OnDeviceIdsRead onDeviceIdRead) {
Util.getGoogleAdId(context, onDeviceIdRead);
}

public static String getAdid() {
AdjustInstance adjustInstance = Adjust.getDefaultInstance();
return adjustInstance.getAdid();
}

public static AdjustAttribution getAttribution() {
AdjustInstance adjustInstance = Adjust.getDefaultInstance();
return adjustInstance.getAttribution();
}
}
17 changes: 11 additions & 6 deletions Adjust/adjust/src/main/java/com/adjust/sdk/AdjustAttribution.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class AdjustAttribution implements Serializable {
new ObjectStreamField("campaign", String.class),
new ObjectStreamField("adgroup", String.class),
new ObjectStreamField("creative", String.class),
new ObjectStreamField("clickLabel", String.class)
new ObjectStreamField("clickLabel", String.class),
new ObjectStreamField("adid", String.class),
};

public String trackerToken;
Expand All @@ -31,8 +32,9 @@ public class AdjustAttribution implements Serializable {
public String adgroup;
public String creative;
public String clickLabel;
public String adid;

public static AdjustAttribution fromJson(JSONObject jsonObject) {
public static AdjustAttribution fromJson(JSONObject jsonObject, String adid) {
if (jsonObject == null) return null;

AdjustAttribution attribution = new AdjustAttribution();
Expand All @@ -44,6 +46,7 @@ public static AdjustAttribution fromJson(JSONObject jsonObject) {
attribution.adgroup = jsonObject.optString("adgroup", null);
attribution.creative = jsonObject.optString("creative", null);
attribution.clickLabel = jsonObject.optString("click_label", null);
attribution.adid = adid;

return attribution;
}
Expand All @@ -62,6 +65,8 @@ public boolean equals(Object other) {
if (!Util.equalString(adgroup, otherAttribution.adgroup)) return false;
if (!Util.equalString(creative, otherAttribution.creative)) return false;
if (!Util.equalString(clickLabel, otherAttribution.clickLabel)) return false;
if (!Util.equalString(adid, otherAttribution.adid)) return false;

return true;
}

Expand All @@ -75,14 +80,15 @@ public int hashCode() {
hashCode = 37 * hashCode + Util.hashString(adgroup);
hashCode = 37 * hashCode + Util.hashString(creative);
hashCode = 37 * hashCode + Util.hashString(clickLabel);
hashCode = 37 * hashCode + Util.hashString(adid);

return hashCode;
}


@Override
public String toString() {
return String.format(Locale.US, "tt:%s tn:%s net:%s cam:%s adg:%s cre:%s cl:%s",
trackerToken, trackerName, network, campaign, adgroup, creative, clickLabel);
return String.format(Locale.US, "tt:%s tn:%s net:%s cam:%s adg:%s cre:%s cl:%s adid:%s",
trackerToken, trackerName, network, campaign, adgroup, creative, clickLabel, adid);
}

private void writeObject(ObjectOutputStream stream) throws IOException {
Expand All @@ -92,5 +98,4 @@ private void writeObject(ObjectOutputStream stream) throws IOException {
private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException {
stream.defaultReadObject();
}

}
8 changes: 0 additions & 8 deletions Adjust/adjust/src/main/java/com/adjust/sdk/AdjustConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,6 @@ public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}

public boolean hasListener() {
return onAttributionChangedListener != null
|| onEventTrackingSucceededListener != null
|| onEventTrackingFailedListener != null
|| onSessionTrackingSucceededListener != null
|| onSessionTrackingFailedListener != null;
}

public boolean isValid() {
return appToken != null;
}
Expand Down
10 changes: 10 additions & 0 deletions Adjust/adjust/src/main/java/com/adjust/sdk/AdjustInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ public void setPushToken(String token) {
}
}

public String getAdid() {
if (!checkActivityHandler()) return null;
return activityHandler.getAdid();
}

public AdjustAttribution getAttribution() {
if (!checkActivityHandler()) return null;
return activityHandler.getAttribution();
}

private boolean checkActivityHandler() {
if (activityHandler == null) {
getLogger().error("Adjust not initialized correctly");
Expand Down
Loading

0 comments on commit 91107f1

Please sign in to comment.