Skip to content

Commit

Permalink
Merge pull request #63 from adjust/deviceids
Browse files Browse the repository at this point in the history
Deviceids
  • Loading branch information
wellle committed Jul 25, 2014
2 parents 5c2673f + 46500a8 commit c9170bc
Show file tree
Hide file tree
Showing 17 changed files with 322 additions and 185 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
3 changes: 1 addition & 2 deletions Adjust/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ repositories {

dependencies {
compile 'com.android.support:support-v4:19.1.+'
compile files('libs/google-play-services.jar')
}

android {
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
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.
36 changes: 23 additions & 13 deletions Adjust/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,30 @@
<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>
<name>Adjust Android SDK</name>
<url>https://github.com/adjust/android_sdk</url>
<description>The Adjust SDK for Android</description>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>
<developers>
<developer>
<name>Pedro Silva</name>
<email>pedro@adjust.com</email>
<organization>adjust GmbH</organization>
<organizationUrl>http://www.adjust.com</organizationUrl>
</developer>
</developers>
<scm>
<connection>scm:git:git@github.com:adjust/android_sdk.git</connection>
<developerConnection>scm:git:git@github.com:adjust/android_sdk.git</developerConnection>
<url>git@github.com:adjust/android_sdk.git</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<android.version>4.1.1.4</android.version>
Expand All @@ -19,18 +41,6 @@
<groupId>com.google.android</groupId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>4.3.23</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>4.3.23</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down
11 changes: 6 additions & 5 deletions Adjust/src/com/adjust/sdk/ActivityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +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 +283,12 @@ 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);
}

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 c9170bc

Please sign in to comment.