Repository navigation
Expand file tree
/
Copy pathInternalConfig.java
More file actions
305 lines (260 loc) · 8.61 KB
/
Copy pathInternalConfig.java
File metadata and controls
305 lines (260 loc) · 8.61 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package ly.count.sdk.java.internal;
import java.io.File;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import ly.count.sdk.java.Config;
/**
* Internal to Countly SDK configuration class. Can and should contain options hidden from outside.
* Only members of {@link InternalConfig} can be changed, members of {@link Config} are non-modifiable.
*/
public class InternalConfig extends Config {
/**
* Whether to use default networking, meaning networking in the same process with SDK
*/
private boolean defaultNetworking = true;
/**
* {@link DID} instances generated from Countly SDK (currently maximum 2: Countly device id + FCM).
* Stored to be able to refresh them.
*/
private final List<DID> dids = new ArrayList<>();
ImmediateRequestGenerator immediateRequestGenerator = null;
public SDKCore sdk;
public StorageProvider storageProvider;
protected IdGenerator viewIdGenerator;
protected IdGenerator eventIdGenerator;
protected ViewIdProvider viewIdProvider;
/**
* The SDK behavior settings of the running SDK, registered by {@link ModuleConfiguration} when it
* initializes. Read it through {@link #getConfigurationProvider()}.
*/
volatile ConfigurationProvider configProvider;
/**
* Shouldn't be used!
*/
public InternalConfig(String url, String appKey) throws IllegalArgumentException {
super(url, appKey);
throw new IllegalStateException("InternalConfig(url, appKey) should not be used");
}
public InternalConfig() throws IllegalArgumentException {
super("http://count.ly", "not a key");
}
public InternalConfig(final Config config) throws IllegalArgumentException {
super(config.getServerURL().toString(), config.getServerAppKey());
setFrom(config);
}
public void setFrom(Config config) {
List<Field> priva = Utils.reflectiveGetDeclaredFields(getClass(), false);
List<Field> local = Utils.reflectiveGetDeclaredFields(getClass(), true);
List<Field> remot = Utils.reflectiveGetDeclaredFields(config.getClass(), true);
for (Field r : remot) {
if (priva.contains(r)) {
continue;
}
for (Field l : local) {
if (r.getName().equals(l.getName())) {
try {
r.setAccessible(true);
if (l.isAccessible()) {
l.set(this, r.get(config));
} else {
l.setAccessible(true);
l.set(this, r.get(config));
l.setAccessible(false);
}
} catch (IllegalAccessException | IllegalArgumentException iae) {
if (configLog != null) {
configLog.e("[InternalConfig] Cannot access field " + r.getName() + " " + iae);
}
}
}
}
}
}
protected String getSDKNameInternal() {
return sdkName;
}
public static String getStoragePrefix() {
return "config";
}
public static Long storageId() {
return 0L;
}
public DID getDeviceId() {
if (!dids.isEmpty()) {
return dids.get(0);
} else {
return null;
}
}
public DID setDeviceId(DID id) {
if (id == null) {
if (configLog != null) {
configLog.e("DID cannot be null");
}
}
DID old = getDeviceId();
if (old != null) {
dids.remove(old);
}
dids.add(id);
return old;
}
public boolean removeDeviceId(DID did) {
return this.dids.remove(did);
}
public boolean removeDeviceId(String id) {
for (DID did : dids) {
if (did.id.equals(id)) {
return this.dids.remove(did);
}
}
return false;
}
public int getFeatures1() {
return features;
}
public Set<Integer> getModuleOverrides() {
return moduleOverrides == null ? new HashSet<Integer>() : moduleOverrides.keySet();
}
public boolean isDefaultNetworking() {
return defaultNetworking;
}
public void setDefaultNetworking(boolean defaultNetworking) {
this.defaultNetworking = defaultNetworking;
}
/**
* The SDK behavior settings in effect. While no {@link ModuleConfiguration} is registered on
* this configuration, as for a module built on its own in a test, the settings come from this
* configuration alone.
*
* @return the settings, never {@code null}
*/
@Nonnull
ConfigurationProvider getConfigurationProvider() {
ConfigurationProvider provider = configProvider;
if (provider != null) {
return provider;
}
return ModuleConfiguration.developerDefaults(this);
}
/**
* Whether the SDK is currently allowed to perform network requests, the {@code networking}
* switch of the SDK behavior settings.
*
* @return {@code true} if networking is allowed
*/
public boolean getNetworkingEnabled() {
return getConfigurationProvider().getNetworkingEnabled();
}
public String getSdkBehaviorSettings() {
return sdkBehaviorSettings;
}
public boolean isSdkBehaviorSettingsRequestsDisabled() {
return sdkBehaviorSettingsRequestsDisabled;
}
/**
* Whether the developer turned request compression on, see {@link Config#enableRequestCompression()}.
*
* @return {@code true} after {@link Config#enableRequestCompression()}
*/
boolean isRequestCompressionEnabled() {
return requestCompressionEnabled;
}
/**
* Whether the SDK sends its health check, see {@link Config#disableHealthCheck()}.
*
* @return {@code true} unless the health check was disabled
*/
boolean isHealthCheckEnabled() {
return healthCheckEnabled;
}
/**
* Whether the developer left the backoff mechanism on, the value the {@code bom} setting of the
* SDK behavior settings starts from.
*
* @return {@code false} after {@link Config#disableBackoffMechanism()}
*/
boolean isBackoffMechanismEnabled() {
return backoffMechanismEnabled;
}
/**
* This feature is not yet implemented
* If someday we decide to support temporary device ID mode
*
* @return false
*/
public boolean isTemporaryIdEnabled() {
return false;
}
//region remote config
public boolean isRemoteConfigAutomaticDownloadTriggersEnabled() {
return enableRemoteConfigAutomaticDownloadTriggers;
}
public boolean isRemoteConfigValueCachingEnabled() {
return enableRemoteConfigValueCaching;
}
public boolean isAutoEnrollFlagEnabled() {
return enableAutoEnrollFlag;
}
public List<RCDownloadCallback> getRemoteConfigGlobalCallbackList() {
return remoteConfigGlobalCallbacks;
}
//endregion
public Map<String, String> getMetricOverride() {
return metricOverride;
}
public void setLogger(Log logger) {
this.configLog = logger;
}
/**
* Replaces the server URL every later request is sent to, in this configuration only.
*
* @param serverURL the new server URL
*/
void setServerURL(@Nonnull URL serverURL) {
this.serverURL = serverURL;
}
/**
* Replaces the app key every later request carries, in this configuration only.
*
* @param serverAppKey the new app key
*/
void setServerAppKey(@Nonnull String serverAppKey) {
this.serverAppKey = serverAppKey;
}
File getSdkStorageRootDirectory() {
return sdkStorageRootDirectory;
}
Log getLogger() {
return configLog;
}
boolean isUnhandledCrashReportingEnabled() {
return unhandledCrashReportingEnabled;
}
int getMaxBreadcrumbCount() {
return maxBreadcrumbCount;
}
/**
* The key length limit the developer set.
*
* @return the limit, {@link Integer#MAX_VALUE} when none is set
*/
int getMaxKeyLength() {
return maxKeyLength;
}
String[] getLocationParams() {
return new String[] { country, city, location, ip };
}
boolean isLocationDisabled() {
return !locationEnabled;
}
boolean isAutoSendUserProperties() {
return autoSendUserProperties;
}
}