blob: 148a5f670b92987c4ad9178dc42721864a2894b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
package com.adjust.sdk;
import android.content.Context;
/**
* Created by pfms on 06/11/14.
*/
public class AdjustConfig {
Context context;
String appToken;
String environment;
LogLevel logLevel;
String sdkPrefix;
Boolean eventBufferingEnabled;
String defaultTracker;
OnAttributionChangedListener onAttributionChangedListener;
String referrer;
long referrerClickTime;
Boolean knownDevice;
public static final String ENVIRONMENT_SANDBOX = "sandbox";
public static final String ENVIRONMENT_PRODUCTION = "production";
public AdjustConfig(Context context, String appToken, String environment) {
if (!isValid(context, appToken, environment)) {
return;
}
this.context = context.getApplicationContext();
this.appToken = appToken;
this.environment = environment;
// default values
this.logLevel = LogLevel.INFO;
this.eventBufferingEnabled = false;
}
public void setEventBufferingEnabled(Boolean eventBufferingEnabled) {
this.eventBufferingEnabled = eventBufferingEnabled;
}
public void setLogLevel(LogLevel logLevel) {
this.logLevel = logLevel;
}
public void setSdkPrefix(String sdkPrefix) {
this.sdkPrefix = sdkPrefix;
}
public void setDefaultTracker(String defaultTracker) {
this.defaultTracker = defaultTracker;
}
public void setOnAttributionChangedListener(OnAttributionChangedListener onAttributionChangedListener) {
this.onAttributionChangedListener = onAttributionChangedListener;
}
public boolean hasListener() {
return onAttributionChangedListener != null;
}
public boolean isValid() {
return appToken != null;
}
private boolean isValid(Context context, String appToken, String environment) {
if (!checkAppToken(appToken)) return false;
if (!checkEnvironment(environment)) return false;
if (!checkContext(context)) return false;
return true;
}
private static boolean checkContext(Context context) {
ILogger logger = AdjustFactory.getLogger();
if (context == null) {
logger.error("Missing context");
return false;
}
if (!Util.checkPermission(context, android.Manifest.permission.INTERNET)) {
logger.error("Missing permission: INTERNET");
return false;
}
return true;
}
private static boolean checkAppToken(String appToken) {
ILogger logger = AdjustFactory.getLogger();
if (appToken == null) {
logger.error("Missing App Token.");
return false;
}
if (appToken.length() != 12) {
logger.error("Malformed App Token '%s'", appToken);
return false;
}
return true;
}
private static boolean checkEnvironment(String environment) {
ILogger logger = AdjustFactory.getLogger();
if (environment == null) {
logger.error("Missing environment");
return false;
}
if (environment == AdjustConfig.ENVIRONMENT_SANDBOX) {
logger.Assert("SANDBOX: Adjust is running in Sandbox mode. " +
"Use this setting for testing. " +
"Don't forget to set the environment to `production` before publishing!");
return true;
}
if (environment == AdjustConfig.ENVIRONMENT_PRODUCTION) {
logger.Assert(
"PRODUCTION: Adjust is running in Production mode. " +
"Use this setting only for the build that you want to publish. " +
"Set the environment to `sandbox` if you want to test your app!");
return true;
}
logger.error("Unknown environment '%s'", environment);
return false;
}
}
|