Skip to content

Commit c9170bc

Browse files
committed
Merge pull request #63 from adjust/deviceids
Deviceids
2 parents 5c2673f + 46500a8 commit c9170bc

17 files changed

+322
-185
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,4 @@ build/
6464
.jira-url
6565
atlassian-ide-plugin.xml
6666

67-
# add exception of google play services jar
68-
!google-play-services.jar
67+
# add exception for private libraries

Adjust/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ repositories {
1717

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

2322
android {
2423
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
2524
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
2625
defaultConfig {
2726
versionCode 11
28-
versionName '3.4.0'
27+
versionName '3.5.0'
2928
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
3029
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
3130
}

Adjust/libs/google-play-services.jar

-1.79 MB
Binary file not shown.

Adjust/pom.xml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,30 @@
55
<modelVersion>4.0.0</modelVersion>
66
<artifactId>adjust-android</artifactId>
77
<groupId>com.adjust.sdk</groupId>
8-
<version>3.3.4</version>
8+
<version>3.5.0</version>
99
<packaging>jar</packaging>
10+
<name>Adjust Android SDK</name>
11+
<url>https://github.com/adjust/android_sdk</url>
12+
<description>The Adjust SDK for Android</description>
13+
<licenses>
14+
<license>
15+
<name>MIT License</name>
16+
<url>http://www.opensource.org/licenses/mit-license.php</url>
17+
</license>
18+
</licenses>
19+
<developers>
20+
<developer>
21+
<name>Pedro Silva</name>
22+
<email>[email protected]</email>
23+
<organization>adjust GmbH</organization>
24+
<organizationUrl>http://www.adjust.com</organizationUrl>
25+
</developer>
26+
</developers>
27+
<scm>
28+
<connection>scm:git:[email protected]:adjust/android_sdk.git</connection>
29+
<developerConnection>scm:git:[email protected]:adjust/android_sdk.git</developerConnection>
30+
<url>[email protected]:adjust/android_sdk.git</url>
31+
</scm>
1032
<properties>
1133
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1234
<android.version>4.1.1.4</android.version>
@@ -19,18 +41,6 @@
1941
<groupId>com.google.android</groupId>
2042
<scope>provided</scope>
2143
</dependency>
22-
<dependency>
23-
<groupId>com.google.android.gms</groupId>
24-
<artifactId>google-play-services</artifactId>
25-
<version>4.3.23</version>
26-
<type>apklib</type>
27-
</dependency>
28-
<dependency>
29-
<groupId>com.google.android.gms</groupId>
30-
<artifactId>google-play-services</artifactId>
31-
<version>4.3.23</version>
32-
<type>jar</type>
33-
</dependency>
3444
</dependencies>
3545
<build>
3646
<sourceDirectory>src</sourceDirectory>

Adjust/src/com/adjust/sdk/ActivityHandler.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,7 @@ private void initInternal(boolean fromBundle, String appToken) {
273273
return;
274274
}
275275

276-
String macAddress = Util.getMacAddress(context);
277-
String macShort = macAddress.replaceAll(":", "");
278-
279276
this.appToken = appToken;
280-
macSha1 = Util.sha1(macAddress);
281-
macShortMd5 = Util.md5(macShort);
282277
androidId = Util.getAndroidId(context);
283278
fbAttributionId = Util.getAttributionId(context);
284279
userAgent = Util.getUserAgent(context);
@@ -288,6 +283,12 @@ private void initInternal(boolean fromBundle, String appToken) {
288283
logger.info("Unable to get Google Play Services Advertising ID at start time");
289284
}
290285

286+
if (!Util.isGooglePlayServicesAvailable(context)) {
287+
String macAddress = Util.getMacAddress(context);
288+
macSha1 = Util.getMacSha1(macAddress);
289+
macShortMd5 = Util.getMacShortMd5(macAddress);
290+
}
291+
291292
packageHandler = AdjustFactory.getPackageHandler(this, context, dropOfflineActivities);
292293

293294
readActivityState();

Adjust/src/com/adjust/sdk/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface Constants {
1919
int THIRTY_MINUTES = 30 * ONE_MINUTE;
2020

2121
String BASE_URL = "https://app.adjust.io";
22-
String CLIENT_SDK = "android3.4.0";
22+
String CLIENT_SDK = "android3.5.0";
2323
String LOGTAG = "Adjust";
2424

2525
String SESSION_STATE_FILENAME = "AdjustIoActivityState";

Adjust/src/com/adjust/sdk/LogCatLogger.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ public void error(String message, Object ...parameters) {
7676

7777
@Override
7878
public void Assert(String message, Object ...parameters) {
79+
Log.println(Log.ASSERT, LOGTAG, String.format(message, parameters));
7980
}
8081
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package com.adjust.sdk;
2+
3+
import java.lang.reflect.Field;
4+
import java.lang.reflect.Method;
5+
6+
import android.content.Context;
7+
8+
public class Reflection {
9+
10+
public static String getPlayAdId(Context context) {
11+
try {
12+
Object AdvertisingInfoObject = getAdvertisingInfoObject(context);
13+
14+
String playAdid = (String) invokeInstanceMethod(AdvertisingInfoObject, "getId", null);
15+
16+
return playAdid;
17+
}
18+
catch (Throwable t) {
19+
return null;
20+
}
21+
}
22+
23+
public static boolean isPlayTrackingEnabled(Context context) {
24+
try {
25+
Object AdvertisingInfoObject = getAdvertisingInfoObject(context);
26+
27+
Boolean isLimitedTrackingEnabled = (Boolean) invokeInstanceMethod(AdvertisingInfoObject, "isLimitAdTrackingEnabled", null);
28+
29+
return !isLimitedTrackingEnabled;
30+
}
31+
catch (Throwable t) {
32+
return false;
33+
}
34+
}
35+
36+
public static boolean isGooglePlayServicesAvailable(Context context) {
37+
try {
38+
Integer isGooglePlayServicesAvailableStatusCode = (Integer) invokeStaticMethod(
39+
"com.google.android.gms.common.GooglePlayServicesUtil",
40+
"isGooglePlayServicesAvailable",
41+
new Class[] {Context.class}, context
42+
);
43+
44+
boolean isGooglePlayServicesAvailable = (Boolean) isConnectionResultSuccess(isGooglePlayServicesAvailableStatusCode);
45+
46+
return isGooglePlayServicesAvailable;
47+
}
48+
catch (Throwable t) {
49+
return false;
50+
}
51+
}
52+
53+
public static String getMacAddress(Context context) {
54+
try {
55+
String macSha1 = (String) invokeStaticMethod(
56+
"com.adjust.sdk.deviceIds.MacAddressUtil",
57+
"getMacAddress",
58+
new Class[] {Context.class}, context
59+
);
60+
61+
return macSha1;
62+
}
63+
catch (Throwable t) {
64+
return null;
65+
}
66+
}
67+
68+
public static String getAndroidId(Context context) {
69+
try {
70+
String androidId = (String) invokeStaticMethod("com.adjust.sdk.deviceIds.AndroidIdUtil", "getAndroidId"
71+
,new Class[] {Context.class}, context);
72+
73+
return androidId;
74+
}
75+
catch (Throwable t) {
76+
return null;
77+
}
78+
}
79+
80+
private static Object getAdvertisingInfoObject(Context context)
81+
throws Exception {
82+
return invokeStaticMethod("com.google.android.gms.ads.identifier.AdvertisingIdClient",
83+
"getAdvertisingIdInfo",
84+
new Class[] {Context.class} , context
85+
);
86+
}
87+
88+
private static boolean isConnectionResultSuccess(Integer statusCode) {
89+
if (statusCode == null) {
90+
return false;
91+
}
92+
93+
try {
94+
Class ConnectionResultClass = Class.forName("com.google.android.gms.common.ConnectionResult");
95+
96+
Field SuccessField = ConnectionResultClass.getField("SUCCESS");
97+
98+
int successStatusCode = SuccessField.getInt(null);
99+
100+
return successStatusCode == statusCode;
101+
}
102+
catch (Throwable t) {
103+
return false;
104+
}
105+
}
106+
107+
private static Object invokeStaticMethod(String className, String methodName, Class[] cArgs, Object... args)
108+
throws Exception {
109+
Class classObject = Class.forName(className);
110+
111+
return invokeMethod(classObject, methodName, null, cArgs, args);
112+
}
113+
114+
private static Object invokeInstanceMethod(Object instance, String methodName, Class[] cArgs, Object... args)
115+
throws Exception {
116+
Class classObject = instance.getClass();
117+
118+
return invokeMethod(classObject, methodName, instance, cArgs, args);
119+
}
120+
121+
private static Object invokeMethod(Class classObject, String methodName, Object instance, Class[] cArgs, Object... args)
122+
throws Exception {
123+
Method methodObject = classObject.getMethod(methodName, cArgs);
124+
125+
Object resultObject = methodObject.invoke(instance, args);
126+
127+
return resultObject;
128+
}
129+
}

0 commit comments

Comments
 (0)