Skip to content

Commit

Permalink
Merge pull request #277 from adjust/v4114
Browse files Browse the repository at this point in the history
V4114
  • Loading branch information
nonelse authored May 5, 2017
2 parents a10881d + ac16f84 commit 0abfac3
Show file tree
Hide file tree
Showing 36 changed files with 588 additions and 221 deletions.
4 changes: 2 additions & 2 deletions Adjust/adjust/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'

def getVersionName() {
return "4.11.3"
return "4.11.4"
}

android {
Expand All @@ -25,7 +25,7 @@ task clearJar(type: Delete) {
}

task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
from('build/intermediates/bundles/default/')
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', "adjust-${getVersionName()}.jar")
Expand Down
55 changes: 49 additions & 6 deletions Adjust/adjust/src/main/java/com/adjust/sdk/ActivityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ public void finishedTrackingActivity(ResponseData responseData) {
attributionHandler.checkSessionResponse((SessionResponseData)responseData);
return;
}
// redirect sdk click responses to attribution handler to check for attribution information
if (responseData instanceof SdkClickResponseData) {
attributionHandler.checkSdkClickResponse((SdkClickResponseData)responseData);
return;
}
// check if it's an event response
if (responseData instanceof EventResponseData) {
launchEventResponseTasks((EventResponseData)responseData);
Expand Down Expand Up @@ -489,6 +494,16 @@ public void run() {
});
}

@Override
public void launchSdkClickResponseTasks(final SdkClickResponseData sdkClickResponseData) {
scheduledExecutor.submit(new Runnable() {
@Override
public void run() {
launchSdkClickResponseTasksI(sdkClickResponseData);
}
});
}

@Override
public void launchSessionResponseTasks(final SessionResponseData sessionResponseData) {
scheduledExecutor.submit(new Runnable() {
Expand Down Expand Up @@ -744,14 +759,14 @@ public void run() {
attributionPackage,
toSendI(false));

sdkClickHandler = AdjustFactory.getSdkClickHandler(toSendI(true));
sdkClickHandler = AdjustFactory.getSdkClickHandler(this, toSendI(true));

if (isToUpdatePackagesI()) {
updatePackagesI();
}

if (adjustConfig.referrer != null) {
sendReferrerI(adjustConfig.referrer, adjustConfig.referrerClickTime); // send to background queue to make sure that activityState is valid
sendReferrerI(adjustConfig.referrer, adjustConfig.referrerClickTime);
}

sessionParametersActionsI(adjustConfig.sessionParametersActionsArray);
Expand Down Expand Up @@ -949,6 +964,22 @@ public void run() {
}
}

private void launchSdkClickResponseTasksI(SdkClickResponseData sdkClickResponseData) {
// try to update adid from response
updateAdidI(sdkClickResponseData.adid);

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

// try to update the attribution
boolean attributionUpdated = updateAttributionI(sdkClickResponseData.attribution);

// if attribution changed, launch attribution changed delegate
if (attributionUpdated) {
launchAttributionListenerI(handler);
}
}

private void launchSessionResponseTasksI(SessionResponseData sessionResponseData) {
// try to update adid from response
updateAdidI(sessionResponseData.adid);
Expand Down Expand Up @@ -1109,7 +1140,7 @@ private void sendReferrerI(String referrer, long clickTime) {

clickPackageBuilder.referrer = referrer;
clickPackageBuilder.clickTime = clickTime;
ActivityPackage clickPackage = clickPackageBuilder.buildClickPackage(Constants.REFTAG);
ActivityPackage clickPackage = clickPackageBuilder.buildClickPackage(Constants.REFTAG, sessionParameters);

sdkClickHandler.sendSdkClick(clickPackage);
}
Expand All @@ -1120,6 +1151,9 @@ private void readOpenUrlI(Uri url, long clickTime) {
}

String urlString = url.toString();
if (urlString == null || urlString.length() == 0) {
return;
}
logger.verbose("Url to parse (%s)", url);

UrlQuerySanitizer querySanitizer = new UrlQuerySanitizer();
Expand All @@ -1134,13 +1168,14 @@ private void readOpenUrlI(Uri url, long clickTime) {

clickPackageBuilder.deeplink = url.toString();
clickPackageBuilder.clickTime = clickTime;
ActivityPackage clickPackage = clickPackageBuilder.buildClickPackage(Constants.DEEPLINK);
ActivityPackage clickPackage = clickPackageBuilder.buildClickPackage(Constants.DEEPLINK, sessionParameters);

sdkClickHandler.sendSdkClick(clickPackage);
}

private PackageBuilder queryStringClickPackageBuilderI(
List<UrlQuerySanitizer.ParameterValuePair> queryList) {
List<UrlQuerySanitizer.ParameterValuePair> queryList)
{
if (queryList == null) {
return null;
}
Expand All @@ -1157,6 +1192,12 @@ private PackageBuilder queryStringClickPackageBuilderI(
String reftag = queryStringParameters.remove(Constants.REFTAG);

long now = System.currentTimeMillis();
// check of activity state != null
// because referrer can be called before onResume
if (activityState != null) {
long lastInterval = now - activityState.lastActivity;
activityState.lastInterval = lastInterval;
}
PackageBuilder builder = new PackageBuilder(adjustConfig, deviceInfo, activityState, now);
builder.extraParameters = queryStringParameters;
builder.attribution = queryStringAttribution;
Expand All @@ -1174,7 +1215,9 @@ private boolean readQueryStringI(String key, String value,
if (!key.startsWith(ADJUST_PREFIX)) { return false; }

String keyWOutPrefix = key.substring(ADJUST_PREFIX.length());
if (keyWOutPrefix.length() == 0) return false;
if (keyWOutPrefix.length() == 0) { return false; }

if (value.length() == 0) { return false;}

if (!trySetAttributionI(queryStringAttribution, keyWOutPrefix, value)) {
extraParameters.put(keyWOutPrefix, value);
Expand Down
32 changes: 8 additions & 24 deletions Adjust/adjust/src/main/java/com/adjust/sdk/AdjustConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class AdjustConfig {
boolean sendInBackground;
Double delayStart;
List<IRunActivityHandler> sessionParametersActionsArray;
boolean allowSuppressLogLevel;
ILogger logger;
String userAgent;
String pushToken;
Expand All @@ -45,10 +44,13 @@ public AdjustConfig(Context context, String appToken, String environment, boolea
}

private void init(Context context, String appToken, String environment, boolean allowSuppressLogLevel) {
this.allowSuppressLogLevel = allowSuppressLogLevel;
logger = AdjustFactory.getLogger();
// default values
setLogLevel(LogLevel.INFO, environment);
if (allowSuppressLogLevel && AdjustConfig.ENVIRONMENT_PRODUCTION.equals(environment)) {
setLogLevel(LogLevel.SUPRESS, environment);
} else {
setLogLevel(LogLevel.INFO, environment);
}

if (!isValid(context, appToken, environment)) {
return;
Expand Down Expand Up @@ -142,25 +144,7 @@ private boolean isValid(Context context, String appToken, String environment) {
}

private void setLogLevel(LogLevel logLevel, String environment) {
LogLevel newLogLevel = null;
if (ENVIRONMENT_PRODUCTION.equals(environment)) {
// production && allows supress -> Supress
if (allowSuppressLogLevel) {
newLogLevel = LogLevel.SUPRESS;
} else {
// production && not allow supress -> Assert
newLogLevel = LogLevel.ASSERT;
}
} else {
// not allow supress && try supress -> Assert
if (!allowSuppressLogLevel &&
logLevel == LogLevel.SUPRESS) {
newLogLevel = LogLevel.ASSERT;
} else {
newLogLevel = logLevel;
}
}
logger.setLogLevel(newLogLevel);
logger.setLogLevel(logLevel, AdjustConfig.ENVIRONMENT_PRODUCTION.equals(environment));
}

private boolean checkContext(Context context) {
Expand Down Expand Up @@ -198,13 +182,13 @@ private boolean checkEnvironment(String environment) {
}

if (environment.equals(AdjustConfig.ENVIRONMENT_SANDBOX)) {
logger.Assert("SANDBOX: Adjust is running in Sandbox mode. " +
logger.warnInProduction("SANDBOX: Adjust is running in Sandbox mode. " +
"Use this setting for testing. " +
"Don't forget to set the environment to `production` before publishing!");
return true;
}
if (environment.equals(AdjustConfig.ENVIRONMENT_PRODUCTION)) {
logger.Assert(
logger.warnInProduction(
"PRODUCTION: Adjust is running in Production mode. " +
"Use this setting only for the build that you want to publish. " +
"Set the environment to `sandbox` if you want to test your app!");
Expand Down
6 changes: 3 additions & 3 deletions Adjust/adjust/src/main/java/com/adjust/sdk/AdjustFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ public static HttpsURLConnection getHttpsURLConnection(URL url) throws IOExcepti
return AdjustFactory.httpsURLConnection;
}

public static ISdkClickHandler getSdkClickHandler(boolean startsSending) {
public static ISdkClickHandler getSdkClickHandler(IActivityHandler activityHandler, boolean startsSending) {
if (sdkClickHandler == null) {
return new SdkClickHandler(startsSending);
return new SdkClickHandler(activityHandler, startsSending);
}

sdkClickHandler.init(startsSending);
sdkClickHandler.init(activityHandler, startsSending);
return sdkClickHandler;
}

Expand Down
21 changes: 21 additions & 0 deletions Adjust/adjust/src/main/java/com/adjust/sdk/AttributionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ public void run() {
});
}

@Override
public void checkSdkClickResponse(final SdkClickResponseData sdkClickResponseData) {
scheduledExecutor.submit(new Runnable() {
@Override
public void run() {
IActivityHandler activityHandler = activityHandlerWeakRef.get();
if (activityHandler == null) {
return;
}

checkSdkClickResponseI(activityHandler, sdkClickResponseData);
}
});
}

public void checkAttributionResponse(final AttributionResponseData attributionResponseData) {
scheduledExecutor.submit(new Runnable() {
@Override
Expand Down Expand Up @@ -167,6 +182,12 @@ private void checkSessionResponseI(IActivityHandler activityHandler, SessionResp
activityHandler.launchSessionResponseTasks(sessionResponseData);
}

private void checkSdkClickResponseI(IActivityHandler activityHandler, SdkClickResponseData sdkClickResponseData) {
checkAttributionI(activityHandler, sdkClickResponseData);

activityHandler.launchSdkClickResponseTasks(sdkClickResponseData);
}

private void checkAttributionResponseI(IActivityHandler activityHandler, AttributionResponseData attributionResponseData) {
checkAttributionI(activityHandler, attributionResponseData);

Expand Down
2 changes: 1 addition & 1 deletion Adjust/adjust/src/main/java/com/adjust/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface Constants {
String BASE_URL = "https://app.adjust.com";
String SCHEME = "https";
String AUTHORITY = "app.adjust.com";
String CLIENT_SDK = "android4.11.3";
String CLIENT_SDK = "android4.11.4";
String LOGTAG = "Adjust";
String REFTAG = "reftag";
String DEEPLINK = "deeplink";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface IActivityHandler {

void launchSessionResponseTasks(SessionResponseData sessionResponseData);

void launchSdkClickResponseTasks(SdkClickResponseData sdkClickResponseData);

void launchAttributionResponseTasks(AttributionResponseData attributionResponseData);

void sendReferrer(String referrer, long clickTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ void init(IActivityHandler activityHandler,

void getAttribution();

void checkSessionResponse(SessionResponseData responseData);
void checkSessionResponse(SessionResponseData sessionResponseData);

void checkSdkClickResponse(SdkClickResponseData sdkClickResponseData);

void pauseSending();

Expand Down
5 changes: 3 additions & 2 deletions Adjust/adjust/src/main/java/com/adjust/sdk/ILogger.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.adjust.sdk;

public interface ILogger {
void setLogLevel(LogLevel logLevel);
void setLogLevel(LogLevel logLevel, boolean isProductionEnvironment);

void setLogLevelString(String logLevelString);
void setLogLevelString(String logLevelString, boolean isProductionEnvironment);

void verbose(String message, Object... parameters);

Expand All @@ -12,6 +12,7 @@ public interface ILogger {
void info(String message, Object... parameters);

void warn(String message, Object... parameters);
void warnInProduction(String message, Object... parameters);

void error(String message, Object... parameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created by pfms on 31/03/16.
*/
public interface ISdkClickHandler {
void init(boolean startsSending);
void init(IActivityHandler activityHandler, boolean startsSending);
void pauseSending();
void resumeSending();
void sendSdkClick(ActivityPackage sdkClick);
Expand Down
Loading

0 comments on commit 0abfac3

Please sign in to comment.