Skip to content

Commit

Permalink
Merge pull request #57 from adjust/development
Browse files Browse the repository at this point in the history
Send "tracking enabled"
  • Loading branch information
nonelse committed Jul 1, 2014
2 parents 204765a + 8d98ac0 commit 83fc959
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Adjust/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
defaultConfig {
versionCode 11
versionName '3.3.4'
versionName '3.3.5'
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
Expand Down
4 changes: 2 additions & 2 deletions Adjust/src/com/adjust/sdk/ActivityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ private void initInternal(boolean fromBundle) {
fbAttributionId = Util.getAttributionId(context);
userAgent = Util.getUserAgent(context);

String gpsAdid = Util.getGpsAdid(context);
if (gpsAdid == null) {
String playAdId = Util.getPlayAdId(context);
if (playAdId == null) {
logger.info("Unable to get Google Play Services Advertising ID at start time");
}

Expand Down
2 changes: 1 addition & 1 deletion Adjust/src/com/adjust/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface Constants {
int THIRTY_MINUTES = 30 * ONE_MINUTE;

String BASE_URL = "https://app.adjust.io";
String CLIENT_SDK = "android3.3.4";
String CLIENT_SDK = "android3.3.5";
String LOGTAG = "Adjust";

String SESSION_STATE_FILENAME = "AdjustIoActivityState";
Expand Down
16 changes: 14 additions & 2 deletions Adjust/src/com/adjust/sdk/PackageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ private Map<String, String> getDefaultParameters() {
addString(parameters, "android_uuid", uuid);
addString(parameters, "fb_id", fbAttributionId);
addString(parameters, "environment", environment);
String gpsAdid = Util.getGpsAdid(context);
addString(parameters, "gps_adid", gpsAdid);
String playAdId = Util.getPlayAdId(context);
addString(parameters, "gps_adid", playAdId);
Boolean isTrackingEnabled = Util.isPlayTrackingEnabled(context);
addBoolean(parameters, "tracking_enabled", isTrackingEnabled);

// session related (used for events as well)
addInt(parameters, "session_count", sessionCount);
Expand Down Expand Up @@ -351,4 +353,14 @@ private void addMapJson(Map<String, String> parameters, String key, Map<String,

addString(parameters, key, jsonString);
}

private void addBoolean(Map<String, String> parameters, String key, Boolean value) {
if (value == null) {
return;
}

int intValue = value? 1 : 0;

addInt(parameters, key, intValue);
}
}
54 changes: 36 additions & 18 deletions Adjust/src/com/adjust/sdk/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,41 +349,59 @@ public static String dateFormat(long date) {
return dateFormat.format(date);
}

public static String getGpsAdid(Context context) {
public static String getPlayAdId(Context context) {
try {
Class AdvertisingIdClientClass = Class.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient");
Object AdvertisingInfoObject = getPlayAdvertisingInfoObject(context);

Class[] cArg = new Class[1];
cArg[0] = Context.class;
Method getAdvertisingInfoMethod = AdvertisingIdClientClass.getMethod("getAdvertisingIdInfo", cArg);
Class AdvertisingInfoClass = AdvertisingInfoObject.getClass();

Object AdvertisingInfoObject = getAdvertisingInfoMethod.invoke(null, context);
Method getIdMethod = AdvertisingInfoClass.getMethod("getId");

Class AdvertisingInfoClass = AdvertisingInfoObject.getClass();
Object getIdObject = getIdMethod.invoke(AdvertisingInfoObject);

Method isLimitedTrackingEnabledMethod = AdvertisingInfoClass.getMethod("isLimitAdTrackingEnabled");
String playAdid = (String) getIdObject;

Object isLimitedTrackingEnabledObject = isLimitedTrackingEnabledMethod.invoke(AdvertisingInfoObject);
return playAdid;
}
catch (Exception e) {
}
catch (NoClassDefFoundError ncdffe) {
}

Boolean isLimitedTrackingEnabled = (Boolean) isLimitedTrackingEnabledObject;
return null;
}

if (isLimitedTrackingEnabled) {
return null;
}
public static boolean isPlayTrackingEnabled(Context context) {
try {
Object AdvertisingInfoObject = getPlayAdvertisingInfoObject(context);

Method getIdMethod = AdvertisingInfoClass.getMethod("getId");
Class AdvertisingInfoClass = AdvertisingInfoObject.getClass();

Object getIdObject = getIdMethod.invoke(AdvertisingInfoObject);
Method isLimitedTrackingEnabledMethod = AdvertisingInfoClass.getMethod("isLimitAdTrackingEnabled");

String gpsAdid = (String) getIdObject;
Object isLimitedTrackingEnabledObject = isLimitedTrackingEnabledMethod.invoke(AdvertisingInfoObject);

return gpsAdid;
Boolean isLimitedTrackingEnabled = (Boolean) isLimitedTrackingEnabledObject;

return !isLimitedTrackingEnabled;
}
catch (Exception e) {
}
catch (NoClassDefFoundError ncdffe) {
}

return null;
return false;
}

private static Object getPlayAdvertisingInfoObject(Context context) throws Exception {
Class AdvertisingIdClientClass = Class.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient");

Class[] cArg = new Class[1];
cArg[0] = Context.class;
Method getAdvertisingInfoMethod = AdvertisingIdClientClass.getMethod("getAdvertisingIdInfo", cArg);

Object AdvertisingInfoObject = getAdvertisingInfoMethod.invoke(null, context);

return AdvertisingInfoObject;
}
}
7 changes: 6 additions & 1 deletion Adjust/test/src/com/adjust/sdk/test/TestActivityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void testFirstSession() {

// check the Sdk version is being tested
assertEquals(activityPackage.getExtendedString(),
"android3.3.4", activityPackage.getClientSdk());
"android3.3.5", activityPackage.getClientSdk());

// check the server url
assertEquals(Constants.BASE_URL, "https://app.adjust.io");
Expand Down Expand Up @@ -335,6 +335,11 @@ public void testEventsNotBuffered() {
ActivityPackage activityPackage = mockPackageHandler.queue.get(1);
Map<String, String> packageParameters = activityPackage.getParameters();

// check that it contains the information of the tracking being enabled
assertNotNull(activityPackage.getExtendedString(),
packageParameters.get("tracking_enabled"));


// check the event count in the package parameters
assertEquals(activityPackage.getExtendedString(),
1, Integer.parseInt(packageParameters.get("event_count")));
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4
3.3.5
6 changes: 3 additions & 3 deletions doc/migrate.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Migrate your adjust SDK for Android to 3.3.4 from v2.1.x
## Migrate your adjust SDK for Android to 3.3.5 from v2.1.x

We renamed the main class `com.adeven.adjustio.AdjustIo` to
`com.adjust.sdk.Adjust`. Follow these steps to update all adjust SDK calls.
Expand All @@ -24,7 +24,7 @@ We renamed the main class `com.adeven.adjustio.AdjustIo` to
4. In the same fashion, replace `adeven.adjustio` with `adjust.sdk` in all
manifest files to update the package name of the `ReferrerReceiver`.

5. Download version v3.3.4 and create a new Android project from the `Adjust` folder.
5. Download version v3.3.5 and create a new Android project from the `Adjust` folder.

![][import]

Expand All @@ -36,7 +36,7 @@ We renamed the main class `com.adeven.adjustio.AdjustIo` to

8. Build your project to confirm that everything is properly connected again.

The adjust SDK v3.3.4 added delegate notifications. Check out the [README] for
The adjust SDK v3.3.5 added delegate notifications. Check out the [README] for
details.


Expand Down

0 comments on commit 83fc959

Please sign in to comment.