Skip to content

Commit

Permalink
Merge pull request #62 from adjust/deviceids
Browse files Browse the repository at this point in the history
Deviceids
  • Loading branch information
nonelse committed Jul 23, 2014
2 parents 5c2673f + 4974497 commit d679bce
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 152 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,4 @@ build/
.jira-url
atlassian-ide-plugin.xml

# add exception of google play services jar
!google-play-services.jar
# add exception for private libraries
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.4.0'
versionName '3.5.0'
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
Expand Down
Binary file removed Adjust/libs/google-play-services.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion Adjust/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>adjust-android</artifactId>
<groupId>com.adjust.sdk</groupId>
<version>3.3.4</version>
<version>3.5.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
13 changes: 7 additions & 6 deletions Adjust/src/com/adjust/sdk/ActivityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,7 @@ private void initInternal(boolean fromBundle, String appToken) {
return;
}

String macAddress = Util.getMacAddress(context);
String macShort = macAddress.replaceAll(":", "");

this.appToken = appToken;
macSha1 = Util.sha1(macAddress);
macShortMd5 = Util.md5(macShort);
androidId = Util.getAndroidId(context);
fbAttributionId = Util.getAttributionId(context);
userAgent = Util.getUserAgent(context);

Expand All @@ -288,6 +282,13 @@ private void initInternal(boolean fromBundle, String appToken) {
logger.info("Unable to get Google Play Services Advertising ID at start time");
}

if (!Util.isGooglePlayServicesAvailable(context)) {
String macAddress = Util.getMacAddress(context);
macSha1 = Util.getMacSha1(macAddress);
macShortMd5 = Util.getMacShortMd5(macAddress);
androidId = Util.getAndroidId(context);
}

packageHandler = AdjustFactory.getPackageHandler(this, context, dropOfflineActivities);

readActivityState();
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.4.0";
String CLIENT_SDK = "android3.5.0";
String LOGTAG = "Adjust";

String SESSION_STATE_FILENAME = "AdjustIoActivityState";
Expand Down
1 change: 1 addition & 0 deletions Adjust/src/com/adjust/sdk/LogCatLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ public void error(String message, Object ...parameters) {

@Override
public void Assert(String message, Object ...parameters) {
Log.println(Log.ASSERT, LOGTAG, String.format(message, parameters));
}
}
129 changes: 129 additions & 0 deletions Adjust/src/com/adjust/sdk/Reflection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.adjust.sdk;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import android.content.Context;

public class Reflection {

public static String getPlayAdId(Context context) {
try {
Object AdvertisingInfoObject = getAdvertisingInfoObject(context);

String playAdid = (String) invokeInstanceMethod(AdvertisingInfoObject, "getId", null);

return playAdid;
}
catch (Throwable t) {
return null;
}
}

public static boolean isPlayTrackingEnabled(Context context) {
try {
Object AdvertisingInfoObject = getAdvertisingInfoObject(context);

Boolean isLimitedTrackingEnabled = (Boolean) invokeInstanceMethod(AdvertisingInfoObject, "isLimitAdTrackingEnabled", null);

return !isLimitedTrackingEnabled;
}
catch (Throwable t) {
return false;
}
}

public static boolean isGooglePlayServicesAvailable(Context context) {
try {
Integer isGooglePlayServicesAvailableStatusCode = (Integer) invokeStaticMethod(
"com.google.android.gms.common.GooglePlayServicesUtil",
"isGooglePlayServicesAvailable",
new Class[] {Context.class}, context
);

boolean isGooglePlayServicesAvailable = (Boolean) isConnectionResultSuccess(isGooglePlayServicesAvailableStatusCode);

return isGooglePlayServicesAvailable;
}
catch (Throwable t) {
return false;
}
}

public static String getMacAddress(Context context) {
try {
String macSha1 = (String) invokeStaticMethod(
"com.adjust.sdk.deviceIds.MacAddressUtil",
"getMacAddress",
new Class[] {Context.class}, context
);

return macSha1;
}
catch (Throwable t) {
return null;
}
}

public static String getAndroidId(Context context) {
try {
String androidId = (String) invokeStaticMethod("com.adjust.sdk.deviceIds.AndroidIdUtil", "getAndroidId"
,new Class[] {Context.class}, context);

return androidId;
}
catch (Throwable t) {
return null;
}
}

private static Object getAdvertisingInfoObject(Context context)
throws Exception {
return invokeStaticMethod("com.google.android.gms.ads.identifier.AdvertisingIdClient",
"getAdvertisingIdInfo",
new Class[] {Context.class} , context
);
}

private static boolean isConnectionResultSuccess(Integer statusCode) {
if (statusCode == null) {
return false;
}

try {
Class ConnectionResultClass = Class.forName("com.google.android.gms.common.ConnectionResult");

Field SuccessField = ConnectionResultClass.getField("SUCCESS");

int successStatusCode = SuccessField.getInt(null);

return successStatusCode == statusCode;
}
catch (Throwable t) {
return false;
}
}

private static Object invokeStaticMethod(String className, String methodName, Class[] cArgs, Object... args)
throws Exception {
Class classObject = Class.forName(className);

return invokeMethod(classObject, methodName, null, cArgs, args);
}

private static Object invokeInstanceMethod(Object instance, String methodName, Class[] cArgs, Object... args)
throws Exception {
Class classObject = instance.getClass();

return invokeMethod(classObject, methodName, instance, cArgs, args);
}

private static Object invokeMethod(Class classObject, String methodName, Object instance, Class[] cArgs, Object... args)
throws Exception {
Method methodObject = classObject.getMethod(methodName, cArgs);

Object resultObject = methodObject.invoke(instance, args);

return resultObject;
}
}
Loading

0 comments on commit d679bce

Please sign in to comment.