-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathCountlyConfig.java
More file actions
599 lines (485 loc) · 17.5 KB
/
CountlyConfig.java
File metadata and controls
599 lines (485 loc) · 17.5 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
package ly.count.android.sdk;
import android.app.Application;
import android.content.Context;
import java.util.Map;
public class CountlyConfig {
/**
* Internal fields and fields for testing
*/
protected CountlyStore countlyStore = null;
protected boolean checkForNativeCrashDumps = true;
//used to deliver this object to connection queue
protected DeviceId deviceIdInstance = null;
/**
* Android context.
* Mandatory field.
*/
protected Context context = null;
/**
* URL of the Countly server to submit data to.
* Mandatory field.
*/
protected String serverURL = null;
/**
* app key for the application being tracked; find in the Countly Dashboard under Management > Applications.
* Mandatory field.
*/
protected String appKey = null;
/**
* unique ID for the device the app is running on; note that null in deviceID means that Countly will fall back to OpenUDID, then, if it's not available, to Google Advertising ID.
*/
protected String deviceID = null;
/**
* enum value specifying which device ID generation strategy Countly should use: OpenUDID or Google Advertising ID.
*/
protected DeviceId.Type idMode = null;
/**
* sets the limit after how many sessions, for each apps version, the automatic star rating dialog is shown.
*/
protected int starRatingSessionLimit = 5;
/**
* the callback function that will be called from the automatic star rating dialog.
*/
protected StarRatingCallback starRatingCallback = null;
/**
* the shown title text for the star rating dialogs.
*/
protected String starRatingTextTitle = null;
/**
* the shown message text for the star rating dialogs.
*/
protected String starRatingTextMessage = null;
/**
* the shown dismiss button text for the shown star rating dialogs.
*/
protected String starRatingTextDismiss = null;
protected boolean loggingEnabled = false;
protected boolean enableUnhandledCrashReporting = false;
protected boolean enableViewTracking = false;
protected boolean autoTrackingUseShortName = false;
protected Class[] autoTrackingExceptions = null;
protected Map<String, Object> automaticViewSegmentation = null;
protected Map<String, String> customNetworkRequestHeaders = null;
protected boolean pushIntentAddMetadata = false;
protected boolean enableRemoteConfigAutomaticDownload = false;
protected RemoteConfig.RemoteConfigCallback remoteConfigCallback = null;
protected boolean shouldRequireConsent = false;
protected String[] enabledFeatureNames = null;
protected boolean httpPostForced = false;
protected boolean temporaryDeviceIdEnabled = false;
protected String tamperingProtectionSalt = null;
protected Integer eventQueueSizeThreshold = null;
protected boolean trackOrientationChange = false;
protected boolean manualSessionControlEnabled = false;
protected boolean recordAllThreadsWithCrash = false;
protected boolean disableUpdateSessionRequests = false;
protected boolean shouldIgnoreAppCrawlers = false;
protected String[] appCrawlerNames = null;
protected String[] publicKeyPinningCertificates = null;
protected String[] certificatePinningCertificates = null;
protected Boolean enableAttribution = null;
protected Map<String, Object> customCrashSegment = null;
protected Integer sessionUpdateTimerDelay = null;
protected CrashFilterCallback crashFilterCallback;
protected boolean starRatingDialogIsCancellable = false;
protected boolean starRatingShownAutomatically = false;
protected boolean starRatingDisableAskingForEachAppVersion = false;
protected Application application = null;
protected boolean recordAppStartTime = false;
protected ConnectionInterceptor interceptor = null;
boolean disableLocation = false;
String locationCountyCode = null;
String locationCity = null;
String locationLocation = null;
String locationIpAddress = null;
Map<String, String> metricOverride = null;
Long appStartTimestampOverride = null;
boolean appLoadedManualTrigger = false;
boolean manualForegroundBackgroundTrigger = false;
ModuleLog.LogCallback providedLogCallback;
public CountlyConfig() {
}
/**
* @param context
* @param appKey
* @param serverURL
* @deprecated Please use the constructor that takes the application class
*/
public CountlyConfig(Context context, String appKey, String serverURL) {
setContext(context);
setAppKey(appKey);
setServerURL(serverURL);
}
public CountlyConfig(Application application, String appKey, String serverURL) {
setContext(application.getApplicationContext());
setAppKey(appKey);
setServerURL(serverURL);
setApplication(application);
}
/**
* Android context.
* Mandatory field.
*/
public CountlyConfig setContext(Context context) {
this.context = context;
return this;
}
/**
* URL of the Countly server to submit data to.
* Mandatory field.
*/
public CountlyConfig setServerURL(String serverURL) {
this.serverURL = serverURL;
return this;
}
/**
* app key for the application being tracked; find in the Countly Dashboard under Management > Applications.
* Mandatory field.
*/
public CountlyConfig setAppKey(String appKey) {
this.appKey = appKey;
return this;
}
/**
* unique ID for the device the app is running on; note that null in deviceID means that Countly will fall back to OpenUDID, then, if it's not available, to Google Advertising ID.
*/
public CountlyConfig setDeviceId(String deviceID) {
this.deviceID = deviceID;
return this;
}
/**
* enum value specifying which device ID generation strategy Countly should use: OpenUDID or Google Advertising ID.
*/
public CountlyConfig setIdMode(DeviceId.Type idMode) {
this.idMode = idMode;
return this;
}
/**
* sets the limit after how many sessions, for each apps version, the automatic star rating dialog is shown.
*/
public CountlyConfig setStarRatingSessionLimit(int starRatingLimit) {
this.starRatingSessionLimit = starRatingLimit;
return this;
}
/**
* the callback function that will be called from the automatic star rating dialog.
*/
public CountlyConfig setStarRatingCallback(StarRatingCallback starRatingCallback) {
this.starRatingCallback = starRatingCallback;
return this;
}
/**
* the shown title text for the star rating dialogs.
*/
public CountlyConfig setStarRatingTextTitle(String starRatingTextTitle) {
this.starRatingTextTitle = starRatingTextTitle;
return this;
}
/**
* the shown message text for the star rating dialogs.
*/
public CountlyConfig setStarRatingTextMessage(String starRatingTextMessage) {
this.starRatingTextMessage = starRatingTextMessage;
return this;
}
/**
* the shown dismiss button text for the shown star rating dialogs.
*/
public CountlyConfig setStarRatingTextDismiss(String starRatingTextDismiss) {
this.starRatingTextDismiss = starRatingTextDismiss;
return this;
}
/**
* Set to true of you want to enable countly internal debugging logs
* Those logs will be printed to the console
*
* @param enabled
*/
public CountlyConfig setLoggingEnabled(boolean enabled) {
this.loggingEnabled = enabled;
return this;
}
/**
* Call to enable uncaught crash reporting
* @return
*/
public CountlyConfig enableCrashReporting() {
this.enableUnhandledCrashReporting = true;
return this;
}
/**
* Set if automatic view tracking should be enabled
* @param enable
* @return
*/
public CountlyConfig setViewTracking(boolean enable) {
this.enableViewTracking = enable;
return this;
}
public CountlyConfig setAutoTrackingUseShortName(boolean enable) {
this.autoTrackingUseShortName = enable;
return this;
}
public CountlyConfig setAutomaticViewSegmentation(Map<String, Object> segmentation) {
automaticViewSegmentation = segmentation;
return this;
}
/**
* Set which activities should be excluded from automatic view tracking
*
* @param exceptions activities which should be ignored
* @return
*/
public CountlyConfig setAutoTrackingExceptions(Class[] exceptions) {
if (exceptions != null) {
for (int a = 0; a < exceptions.length; a++) {
if (exceptions[a] == null) {
throw new IllegalArgumentException("setAutoTrackingExceptions() does not accept 'null' activities");
}
}
}
autoTrackingExceptions = exceptions;
return this;
}
public CountlyConfig addCustomNetworkRequestHeaders(Map<String, String> customHeaderValues) {
this.customNetworkRequestHeaders = customHeaderValues;
return this;
}
public CountlyConfig setPushIntentAddMetadata(boolean enable) {
pushIntentAddMetadata = enable;
return this;
}
public CountlyConfig setRemoteConfigAutomaticDownload(boolean enabled, RemoteConfig.RemoteConfigCallback callback) {
enableRemoteConfigAutomaticDownload = enabled;
remoteConfigCallback = callback;
return this;
}
/**
* Set if consent should be required
*
* @param shouldRequireConsent
* @return
*/
public CountlyConfig setRequiresConsent(boolean shouldRequireConsent) {
this.shouldRequireConsent = shouldRequireConsent;
return this;
}
/**
* Sets which features are enabled in case consent is required
*
* @param featureNames
* @return
*/
public CountlyConfig setConsentEnabled(String[] featureNames) {
enabledFeatureNames = featureNames;
return this;
}
public CountlyConfig setHttpPostForced(boolean isForced) {
httpPostForced = isForced;
return this;
}
public CountlyConfig enableTemporaryDeviceIdMode() {
temporaryDeviceIdEnabled = true;
return this;
}
public CountlyConfig setCrashFilterCallback(CrashFilterCallback callback) {
crashFilterCallback = callback;
return this;
}
public CountlyConfig setParameterTamperingProtectionSalt(String salt) {
tamperingProtectionSalt = salt;
return this;
}
public CountlyConfig setTrackOrientationChanges(boolean shouldTrackOrientation) {
trackOrientationChange = shouldTrackOrientation;
return this;
}
public CountlyConfig setRecordAllThreadsWithCrash() {
recordAllThreadsWithCrash = true;
return this;
}
public CountlyConfig setEnableAttribution(boolean enableAttribution) {
this.enableAttribution = enableAttribution;
return this;
}
public CountlyConfig enablePublicKeyPinning(String[] certificates) {
publicKeyPinningCertificates = certificates;
return this;
}
public CountlyConfig enableCertificatePinning(String[] certificates) {
certificatePinningCertificates = certificates;
return this;
}
public CountlyConfig setShouldIgnoreAppCrawlers(boolean shouldIgnore) {
shouldIgnoreAppCrawlers = shouldIgnore;
return this;
}
public CountlyConfig setAppCrawlerNames(String[] appCrawlerNames) {
this.appCrawlerNames = appCrawlerNames;
return this;
}
/**
* Set the threshold for event grouping. Event count that is bellow the
* threshold will be send on update ticks.
* @param threshold
* @return
*/
public CountlyConfig setEventQueueSizeToSend(int threshold) {
eventQueueSizeThreshold = threshold;
return this;
}
public CountlyConfig enableManualSessionControl() {
manualSessionControlEnabled = true;
return this;
}
public CountlyConfig setCustomCrashSegment(Map<String, Object> crashSegment) {
customCrashSegment = crashSegment;
return this;
}
protected CountlyConfig checkForNativeCrashDumps(boolean checkForDumps) {
checkForNativeCrashDumps = checkForDumps;
return this;
}
/**
* Sets the interval for the automatic session update calls
* min value 1 (1 second),
* max value 600 (10 minutes)
*
* @param delay in seconds
* @return
*/
public CountlyConfig setUpdateSessionTimerDelay(int delay) {
sessionUpdateTimerDelay = delay;
return this;
}
protected CountlyConfig setCountlyStore(CountlyStore store) {
countlyStore = store;
return this;
}
protected CountlyConfig setDisableUpdateSessionRequests(boolean disable) {
disableUpdateSessionRequests = disable;
return this;
}
/**
* Set if the star rating dialog is cancellable
*
* @param isCancellable set this true if it should be cancellable
*/
public synchronized CountlyConfig setIfStarRatingDialogIsCancellable(boolean isCancellable) {
starRatingDialogIsCancellable = isCancellable;
return this;
}
/**
* Set if the star rating should be shown automatically
*
* @param isShownAutomatically set it true if you want to show the app star rating dialog automatically for each new version after the specified session amount
*/
public synchronized CountlyConfig setIfStarRatingShownAutomatically(boolean isShownAutomatically) {
starRatingShownAutomatically = isShownAutomatically;
return this;
}
/**
* Set if the star rating is shown only once per app lifetime
*
* @param disableAsking set true if you want to disable asking the app rating for each new app version (show it only once per apps lifetime)
*/
public synchronized CountlyConfig setStarRatingDisableAskingForEachAppVersion(boolean disableAsking) {
starRatingDisableAskingForEachAppVersion = disableAsking;
return this;
}
/**
* Set the link to the application class
* @param application
* @return
*/
public synchronized CountlyConfig setApplication(Application application) {
this.application = application;
return this;
}
/**
* Enable the recording of the app start time
* @param recordAppStartTime
* @return
*/
public synchronized CountlyConfig setRecordAppStartTime(boolean recordAppStartTime) {
this.recordAppStartTime = recordAppStartTime;
return this;
}
/**
* Disable location tracking
* @return
*/
public synchronized CountlyConfig setDisableLocation() {
disableLocation = true;
return this;
}
/**
* Set location parameters.
* This will be ignored if set together with `setDisableLocation`
*
* @param country_code ISO Country code for the user's country
* @param city Name of the user's city
* @param gpsCoordinates comma separate lat and lng values. For example, "56.42345,123.45325"
*/
public synchronized CountlyConfig setLocation(String country_code, String city, String gpsCoordinates, String ipAddress) {
locationCountyCode = country_code;
locationCity = city;
locationLocation = gpsCoordinates;
locationIpAddress = ipAddress;
return this;
}
/**
* Set the metrics you want to override or additional custom metrics you want to provide
* @param providedMetricOverride
* @return
*/
public synchronized CountlyConfig setMetricOverride(Map<String, String> providedMetricOverride) {
metricOverride = providedMetricOverride;
return this;
}
/**
* Override the app start timestamp in case you have a more precise way to measure it
* @param appStartTimestampOverride
* @return
*/
public synchronized CountlyConfig setAppStartTimestampOverride(long appStartTimestampOverride) {
this.appStartTimestampOverride = appStartTimestampOverride;
return this;
}
/**
* Set to manually trigger the moment when the app has finished loading
* @return
*/
public synchronized CountlyConfig enableManualAppLoadedTrigger() {
appLoadedManualTrigger = true;
return this;
}
/**
* Set this in case you want to control these triggers manually
* @return
*/
public synchronized CountlyConfig enableManualForegroundBackgroundTriggerAPM() {
manualForegroundBackgroundTrigger = true;
return this;
}
/**
* Add a log callback that will duplicate all logs done by the SDK.
* For each message you will receive the message string and it's targeted log level.
* @param logCallback
* @return
*/
public synchronized CountlyConfig setLogListener(ModuleLog.LogCallback logCallback) {
providedLogCallback = logCallback;
return this;
}
/**
* Sets an interceptor which can be used to run custom connection processing for each network requests.
* This is useful to add dynamic headers for each request.
*
* @param interceptor Gets an HttpURLConnection and returns a new HttpURLConnection
*/
public synchronized CountlyConfig setConnectionInterceptor(ConnectionInterceptor interceptor) {
this.interceptor = interceptor;
return this;
}
}