Skip to content

Commit cb29d80

Browse files
nonelseshashanksu
authored andcommitted
Refac: Align reflection call with style and utils of project
1 parent 26a906f commit cb29d80

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

Adjust/sdk-core/src/main/java/com/adjust/sdk/DeviceInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class DeviceInfo {
114114
appUpdateTime = getAppUpdateTime(context);
115115
uiMode = getDeviceUiMode(configuration);
116116
if (Util.canReadPlayIds(adjustConfig)) {
117-
appSetId = Reflection.getAppSetId(context, AdjustFactory.getLogger());
117+
appSetId = Reflection.getAppSetId(context);
118118
}
119119
}
120120

Adjust/sdk-core/src/main/java/com/adjust/sdk/Reflection.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,28 @@ public static ReferrerDetails getVivoReferrer(Context context, ILogger logger) {
9797
return referrerDetails;
9898
}
9999

100-
public static String getAppSetId(Context context, ILogger logger) {
100+
public static String getAppSetId(Context context) {
101101
try {
102-
Class appSetClass = Class.forName("com.google.android.gms.appset.AppSet");
103-
Method getClientMethod = appSetClass.getMethod("getClient", Context.class);
104-
Object appSetIdClientObject = getClientMethod.invoke(null, context);
105-
Method getAppSetIdInfoMethod = appSetIdClientObject.getClass().getMethod("getAppSetIdInfo");
106-
Object taskWithAppSetInfoObject = getAppSetIdInfoMethod.invoke(appSetIdClientObject);
107-
Class tasksClass = Class.forName("com.google.android.gms.tasks.Tasks");
108-
Method awaitMethod = tasksClass.getMethod("await", Class.forName("com.google.android.gms.tasks.Task"));
109-
Object appSetInfoObject = awaitMethod.invoke(null, taskWithAppSetInfoObject);
110-
Method getIdMethod = appSetInfoObject.getClass().getMethod("getId");
111-
112-
return (String) getIdMethod.invoke(appSetInfoObject);
113-
} catch (ClassNotFoundException e) {
114-
logger.error("ClassNotFoundException while retrieving app set id with error: %s", e.getMessage());
115-
} catch (NoSuchMethodException e) {
116-
logger.error("NoSuchMethodException while retrieving app set id with error: %s", e.getMessage());
117-
} catch (InvocationTargetException e) {
118-
logger.error("InvocationTargetException while retrieving app set id with error: %s", e.getMessage());
119-
} catch (Exception e) {
120-
logger.error("Exception while retrieving app set id with error: %s", e.getMessage());
102+
Object appSetIdClientObject =
103+
invokeStaticMethod("com.google.android.gms.appset.AppSet",
104+
"getClient",
105+
new Class[]{Context.class}, context);
106+
107+
Object taskWithAppSetInfoObject =
108+
invokeInstanceMethod(appSetIdClientObject,
109+
"getAppSetIdInfo", null);
110+
111+
Object appSetInfoObject =
112+
invokeStaticMethod("com.google.android.gms.tasks.Tasks",
113+
"await",
114+
new Class[]{forName("com.google.android.gms.tasks.Task")},
115+
taskWithAppSetInfoObject);
116+
117+
return (String) invokeInstanceMethod(appSetInfoObject,
118+
"getId", null);
119+
} catch (Throwable t) {
120+
return null;
121121
}
122-
123-
return null;
124122
}
125123

126124
public static Class forName(String className) {

0 commit comments

Comments
 (0)