Skip to content

Commit

Permalink
Merge pull request #271 from adjust/v4112
Browse files Browse the repository at this point in the history
Version 4.11.2
  • Loading branch information
nonelse authored Mar 22, 2017
2 parents eb7f762 + 977e31f commit cf1f4ee
Show file tree
Hide file tree
Showing 24 changed files with 239 additions and 67 deletions.
2 changes: 1 addition & 1 deletion 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.1"
return "4.11.2"
}

android {
Expand Down
105 changes: 75 additions & 30 deletions Adjust/adjust/src/main/java/com/adjust/sdk/ActivityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.net.UrlQuerySanitizer;
import android.os.Handler;
import android.util.*;

Expand Down Expand Up @@ -119,6 +120,8 @@ public class InternalState {
boolean background;
boolean delayStart;
boolean updatePackages;
boolean firstLaunch;
boolean sessionResponseProcessed;

public boolean isEnabled() {
return enabled;
Expand Down Expand Up @@ -155,6 +158,14 @@ public boolean isToStartNow() {
public boolean isToUpdatePackages() {
return updatePackages;
}

public boolean isFirstLaunch() {
return firstLaunch;
}

public boolean isSessionResponseProcessed() {
return sessionResponseProcessed;
}
}

private ActivityHandler(AdjustConfig adjustConfig) {
Expand All @@ -178,6 +189,8 @@ private ActivityHandler(AdjustConfig adjustConfig) {
internalState.delayStart = false;
// does not need to update packages by default
internalState.updatePackages = false;
// does not have the session response by default
internalState.sessionResponseProcessed = false;

scheduledExecutor.submit(new Runnable() {
@Override
Expand Down Expand Up @@ -579,6 +592,24 @@ public void run() {
});
}

public void foregroundTimerFired() {
scheduledExecutor.submit(new Runnable() {
@Override
public void run() {
foregroundTimerFiredI();
}
});
}

public void backgroundTimerFired() {
scheduledExecutor.submit(new Runnable() {
@Override
public void run() {
backgroundTimerFiredI();
}
});
}

public String getAdid() {
if (activityState == null) {
return null;
Expand Down Expand Up @@ -631,6 +662,9 @@ private void initI() {
if (activityState != null) {
internalState.enabled = activityState.enabled;
internalState.updatePackages = activityState.updatePackages;
internalState.firstLaunch = false;
} else {
internalState.firstLaunch = true; // first launch if activity state is null
}

readConfigFile(adjustConfig.context);
Expand Down Expand Up @@ -669,18 +703,18 @@ private void initI() {
new Runnable() {
@Override
public void run() {
foregroundTimerFiredI();
foregroundTimerFired();
}
}, FOREGROUND_TIMER_START, FOREGROUND_TIMER_INTERVAL, FOREGROUND_TIMER_NAME);

// create background timer
if (adjustConfig.sendInBackground) {
logger.info("Send in background configured");

backgroundTimer = new TimerOnce(scheduledExecutor, new Runnable() {
backgroundTimer = new TimerOnce(new Runnable() {
@Override
public void run() {
backgroundTimerFiredI();
backgroundTimerFired();
}
}, BACKGROUND_TIMER_NAME);
}
Expand All @@ -692,10 +726,10 @@ public void run() {
{
logger.info("Delay start configured");
internalState.delayStart = true;
delayStartTimer = new TimerOnce(scheduledExecutor, new Runnable() {
delayStartTimer = new TimerOnce(new Runnable() {
@Override
public void run() {
sendFirstPackagesI();
sendFirstPackages();
}
}, DELAY_START_TIMER_NAME);
}
Expand Down Expand Up @@ -823,9 +857,12 @@ private void processSessionI() {
private void checkAttributionStateI() {
if (!checkActivityStateI(activityState)) { return; }

// if it's a new session
if (activityState.subsessionCount <= 1) {
return;
// if it's the first launch
if (internalState.isFirstLaunch()) {
// and it hasn't received the session response
if (!internalState.isSessionResponseProcessed()) {
return;
}
}

// if there is already an attribution saved and there was no attribution being asked
Expand Down Expand Up @@ -929,6 +966,9 @@ private void launchSessionResponseTasksI(SessionResponseData sessionResponseData

// launch Session tracking listener if available
launchSessionResponseListenerI(sessionResponseData, handler);

// mark session response has proccessed
internalState.sessionResponseProcessed = true;
}

private void launchSessionResponseListenerI(final SessionResponseData sessionResponseData, Handler handler) {
Expand Down Expand Up @@ -1053,7 +1093,15 @@ private void sendReferrerI(String referrer, long clickTime) {
if (referrer == null || referrer.length() == 0 ) {
return;
}
PackageBuilder clickPackageBuilder = queryStringClickPackageBuilderI(referrer);

logger.verbose("Referrer to parse (%s)", referrer);

UrlQuerySanitizer querySanitizer = new UrlQuerySanitizer();
querySanitizer.setUnregisteredParameterValueSanitizer(UrlQuerySanitizer.getAllButNulLegal());
querySanitizer.setAllowUnregisteredParamaters(true);
querySanitizer.parseQuery(referrer);

PackageBuilder clickPackageBuilder = queryStringClickPackageBuilderI(querySanitizer.getParameterList());

if (clickPackageBuilder == null) {
return;
Expand All @@ -1071,13 +1119,15 @@ private void readOpenUrlI(Uri url, long clickTime) {
return;
}

String queryString = url.getQuery();
String urlString = url.toString();
logger.verbose("Url to parse (%s)", url);

if (queryString == null && url.toString().length() > 0) {
queryString = "";
}
UrlQuerySanitizer querySanitizer = new UrlQuerySanitizer();
querySanitizer.setUnregisteredParameterValueSanitizer(UrlQuerySanitizer.getAllButNulLegal());
querySanitizer.setAllowUnregisteredParamaters(true);
querySanitizer.parseUrl(urlString);

PackageBuilder clickPackageBuilder = queryStringClickPackageBuilderI(queryString);
PackageBuilder clickPackageBuilder = queryStringClickPackageBuilderI(querySanitizer.getParameterList());
if (clickPackageBuilder == null) {
return;
}
Expand All @@ -1089,20 +1139,19 @@ private void readOpenUrlI(Uri url, long clickTime) {
sdkClickHandler.sendSdkClick(clickPackage);
}

private PackageBuilder queryStringClickPackageBuilderI(String queryString) {
if (queryString == null) {
private PackageBuilder queryStringClickPackageBuilderI(
List<UrlQuerySanitizer.ParameterValuePair> queryList) {
if (queryList == null) {
return null;
}

Map<String, String> queryStringParameters = new LinkedHashMap<String, String>();
AdjustAttribution queryStringAttribution = new AdjustAttribution();

logger.verbose("Reading query string (%s)", queryString);

String[] queryPairs = queryString.split("&");

for (String pair : queryPairs) {
readQueryStringI(pair, queryStringParameters, queryStringAttribution);
for (UrlQuerySanitizer.ParameterValuePair parameterValuePair : queryList) {
readQueryStringI(parameterValuePair.mParameter,
parameterValuePair.mValue,
queryStringParameters, queryStringAttribution);
}

String reftag = queryStringParameters.remove(Constants.REFTAG);
Expand All @@ -1116,17 +1165,13 @@ private PackageBuilder queryStringClickPackageBuilderI(String queryString) {
return builder;
}

private boolean readQueryStringI(String queryString,
private boolean readQueryStringI(String key, String value,
Map<String, String> extraParameters,
AdjustAttribution queryStringAttribution) {
String[] pairComponents = queryString.split("=");
if (pairComponents.length != 2) return false;

String key = pairComponents[0];
if (!key.startsWith(ADJUST_PREFIX)) return false;
if (key == null || value == null) { return false; }

String value = pairComponents[1];
if (value.length() == 0) return false;
// parameter key does not start with "adjust_"
if (!key.startsWith(ADJUST_PREFIX)) { return false; }

String keyWOutPrefix = key.substring(ADJUST_PREFIX.length());
if (keyWOutPrefix.length() == 0) return false;
Expand Down
13 changes: 11 additions & 2 deletions Adjust/adjust/src/main/java/com/adjust/sdk/AttributionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public AttributionHandler(IActivityHandler activityHandler,
scheduledExecutor = new CustomScheduledExecutor("AttributionHandler", false);
logger = AdjustFactory.getLogger();

timer = new TimerOnce(scheduledExecutor, new Runnable() {
timer = new TimerOnce(new Runnable() {
@Override
public void run() {
sendAttributionRequestI();
sendAttributionRequest();
}
}, ATTRIBUTION_TIMER_NAME);

Expand Down Expand Up @@ -117,6 +117,15 @@ public void resumeSending() {
paused = false;
}

public void sendAttributionRequest() {
scheduledExecutor.submit(new Runnable() {
@Override
public void run() {
sendAttributionRequestI();
}
});
}

private void getAttributionI(long delayInMilliseconds) {
// don't reset if new time is shorter than last one
if (timer.getFireIn() > delayInMilliseconds) {
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.1";
String CLIENT_SDK = "android4.11.2";
String LOGTAG = "Adjust";
String REFTAG = "reftag";
String DEEPLINK = "deeplink";
Expand Down
31 changes: 31 additions & 0 deletions Adjust/adjust/src/main/java/com/adjust/sdk/DeviceInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Build;
import android.util.DisplayMetrics;

import java.util.Date;
import java.util.Locale;
import java.util.Map;

Expand Down Expand Up @@ -51,6 +52,8 @@ class DeviceInfo {
String abi;
String buildName;
String vmInstructionSet;
String appInstallTime;
String appUpdateTime;
Map<String, String> pluginKeys;

DeviceInfo(Context context, String sdkPrefix) {
Expand Down Expand Up @@ -88,6 +91,8 @@ class DeviceInfo {
abi = getABI();
buildName = getBuildName();
vmInstructionSet = getVmInstructionSet();
appInstallTime = getAppInstallTime(context);
appUpdateTime = getAppUpdateTime(context);
}

private String getMacAddress(Context context, boolean isGooglePlayServicesAvailable) {
Expand Down Expand Up @@ -294,4 +299,30 @@ private String getVmInstructionSet() {
String instructionSet = Util.getVmInstructionSet();
return instructionSet;
}

private String getAppInstallTime(Context context) {
try {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);

String appInstallTime = Util.dateFormatter.format(new Date(packageInfo.firstInstallTime));

return appInstallTime;
} catch (Exception ex) {
return null;
}
}

private String getAppUpdateTime(Context context) {
try {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);

String appInstallTime = Util.dateFormatter.format(new Date(packageInfo.lastUpdateTime));

return appInstallTime;
} catch (Exception ex) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public ActivityPackage buildSessionPackage(SessionParameters sessionParameters,
Map<String, String> parameters = getDefaultParameters();
PackageBuilder.addDuration(parameters, "last_interval", activityStateCopy.lastInterval);
PackageBuilder.addString(parameters, "default_tracker", adjustConfig.defaultTracker);
PackageBuilder.addString(parameters, "installed_at", deviceInfo.appInstallTime);
PackageBuilder.addString(parameters, "updated_at", deviceInfo.appUpdateTime);

if (!isInDelay) {
PackageBuilder.addMapJson(parameters, CALLBACK_PARAMETERS, sessionParameters.callbackParameters);
Expand Down Expand Up @@ -141,7 +143,6 @@ public ActivityPackage buildInfoPackage(String source) {
Map<String, String> parameters = getIdsParameters();

PackageBuilder.addString(parameters, "source", source);
injectAttribution(parameters);

ActivityPackage clickPackage = getDefaultActivityPackage(ActivityKind.INFO);
clickPackage.setPath("/sdk_info");
Expand Down
20 changes: 7 additions & 13 deletions Adjust/adjust/src/main/java/com/adjust/sdk/TimerOnce.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
* Created by pfms on 08/05/15.
*/
public class TimerOnce {
private WeakReference<CustomScheduledExecutor> scheduledExecutorWeakRef;
private CustomScheduledExecutor executor;

private ScheduledFuture waitingTask;
private String name;
private Runnable command;
private ILogger logger;

public TimerOnce(CustomScheduledExecutor scheduler, Runnable command, String name) {
public TimerOnce(Runnable command, String name) {
this.name = name;
this.scheduledExecutorWeakRef = new WeakReference<CustomScheduledExecutor>(scheduler);
this.executor = new CustomScheduledExecutor(name, true);
this.command = command;
this.logger = AdjustFactory.getLogger();
}
Expand All @@ -25,16 +26,11 @@ public void startIn(long fireIn) {
// cancel previous
cancel(false);

CustomScheduledExecutor scheduledExecutor = scheduledExecutorWeakRef.get();
if (scheduledExecutor == null) {
return;
}

String fireInSeconds = Util.SecondsDisplayFormat.format(fireIn / 1000.0);

logger.verbose("%s starting. Launching in %s seconds", name, fireInSeconds);

waitingTask = scheduledExecutor.schedule(new Runnable() {
waitingTask = executor.schedule(new Runnable() {
@Override
public void run() {
logger.verbose("%s fired", name);
Expand Down Expand Up @@ -66,9 +62,7 @@ public void cancel() {

public void teardown() {
cancel(true);
if (scheduledExecutorWeakRef != null) {
scheduledExecutorWeakRef.clear();
}
scheduledExecutorWeakRef = null;

executor = null;
}
}
Loading

0 comments on commit cf1f4ee

Please sign in to comment.