Skip to content

Commit 6cbe492

Browse files
committed
feat: add support for store type
1 parent e630d99 commit 6cbe492

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class AdjustConfig {
4747
Integer eventDeduplicationIdsMaxSize;
4848
ArrayList<OnAttributionReadListener> cachedAttributionReadCallbacks = new ArrayList<>();
4949
boolean isFirstSessionDelayEnabled;
50+
AdjustStoreInfo adjustStoreInfo;
5051

5152
public static final String ENVIRONMENT_SANDBOX = "sandbox";
5253
public static final String ENVIRONMENT_PRODUCTION = "production";
@@ -161,6 +162,10 @@ public void enableFirstSessionDelay() {
161162
this.isFirstSessionDelayEnabled = true;
162163
}
163164

165+
public void setAdjustStoreInfo(AdjustStoreInfo adjustStoreInfo) {
166+
this.adjustStoreInfo = adjustStoreInfo;
167+
}
168+
164169
public void setOnAttributionChangedListener(OnAttributionChangedListener onAttributionChangedListener) {
165170
this.onAttributionChangedListener = onAttributionChangedListener;
166171
}
@@ -253,6 +258,10 @@ public boolean isDeviceIdsReadingOnceEnabled() {
253258
return isDeviceIdsReadingOnceEnabled;
254259
}
255260

261+
public AdjustStoreInfo getAdjustStoreInfo() {
262+
return adjustStoreInfo;
263+
}
264+
256265
public OnAttributionChangedListener getOnAttributionChangedListener() {
257266
return onAttributionChangedListener;
258267
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.adjust.sdk;
2+
3+
public class AdjustStoreInfo {
4+
String storeType;
5+
String appId;
6+
7+
public AdjustStoreInfo(String storeType, String appId) {
8+
this.storeType = storeType;
9+
this.appId = appId;
10+
}
11+
12+
public String getStoreType() {
13+
return storeType;
14+
}
15+
16+
public String getAppId() {
17+
return appId;
18+
}
19+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ class DeviceInfo {
100100
int connectivityType;
101101
String mcc;
102102
String mnc;
103+
AdjustStoreInfo storeInfoApi;
104+
AdjustStoreInfo storeInfoMetadata;
105+
String storeIdSystem;
103106

104107
DeviceInfo(AdjustConfig adjustConfig) {
105108
Context context = adjustConfig.context;
@@ -137,6 +140,9 @@ class DeviceInfo {
137140
if (Util.canReadPlayIds(adjustConfig)) {
138141
appSetId = Reflection.getAppSetId(context);
139142
}
143+
storeInfoApi = StoreInfoUtil.getStoreInfoFromApi(adjustConfig);
144+
storeInfoMetadata = StoreInfoUtil.getStoreInfoFromMetadata(context);
145+
storeIdSystem = StoreInfoUtil.getStoreIdFromSystem(context);
140146
}
141147

142148
void reloadPlayIds(final AdjustConfig adjustConfig) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,17 @@ private Map<String, String> getSessionParameters() {
306306
JSONObject controlParams = SharedPreferencesManager.getDefaultInstance(adjustConfig.context).getControlParamsJson();
307307
PackageBuilder.addJsonObject(parameters, "control_params", controlParams);
308308

309+
// store info
310+
if (deviceInfo.storeInfoApi != null) {
311+
PackageBuilder.addString(parameters, "store_a", deviceInfo.storeInfoApi.storeType);
312+
PackageBuilder.addString(parameters, "app_id_a", deviceInfo.storeInfoApi.appId);
313+
}
314+
if (deviceInfo.storeInfoMetadata != null) {
315+
PackageBuilder.addString(parameters, "store_m", deviceInfo.storeInfoMetadata.storeType);
316+
PackageBuilder.addString(parameters, "app_id_m", deviceInfo.storeInfoMetadata.appId);
317+
}
318+
PackageBuilder.addString(parameters, "store_s", deviceInfo.storeIdSystem);
319+
309320
injectFeatureFlagsWithParameters(parameters);
310321

311322
checkDeviceIds(parameters);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.adjust.sdk;
2+
3+
import android.content.Context;
4+
import android.content.pm.ApplicationInfo;
5+
import android.content.pm.InstallSourceInfo;
6+
import android.content.pm.PackageManager;
7+
import android.os.Build;
8+
import android.os.Bundle;
9+
10+
public class StoreInfoUtil {
11+
public static String getStoreIdFromSystem(final Context context) {
12+
try {
13+
PackageManager packageManager = context.getPackageManager();
14+
String packageName = context.getPackageName();
15+
16+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
17+
InstallSourceInfo installSourceInfo = packageManager.getInstallSourceInfo(packageName);
18+
return installSourceInfo.getInstallingPackageName();
19+
} else {
20+
return packageManager.getInstallerPackageName(packageName);
21+
}
22+
} catch (Exception e) {
23+
return null;
24+
}
25+
}
26+
27+
public static AdjustStoreInfo getStoreInfoFromMetadata(final Context context) {
28+
try {
29+
ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
30+
Bundle metaData = applicationInfo.metaData;
31+
if (metaData == null) {
32+
return null;
33+
}
34+
35+
String storeType = metaData.getString("ADJUST_STORE_TYPE");
36+
String storeAppId = metaData.getString("ADJUST_STORE_APP_ID");
37+
38+
if (storeType == null || storeAppId == null) {
39+
return null;
40+
}
41+
42+
return new AdjustStoreInfo(storeType, storeAppId);
43+
} catch (Exception e) {
44+
return null;
45+
}
46+
}
47+
48+
public static AdjustStoreInfo getStoreInfoFromApi(final AdjustConfig adjustConfig) {
49+
return adjustConfig.adjustStoreInfo;
50+
}
51+
}

0 commit comments

Comments
 (0)