-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConfig.java
More file actions
1494 lines (1336 loc) · 46.8 KB
/
Config.java
File metadata and controls
1494 lines (1336 loc) · 46.8 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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package ly.count.sdk.java;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import ly.count.sdk.java.internal.ConfigViews;
import ly.count.sdk.java.internal.CoreFeature;
import ly.count.sdk.java.internal.Log;
import ly.count.sdk.java.internal.LogCallback;
import ly.count.sdk.java.internal.ModuleBase;
import ly.count.sdk.java.internal.RCDownloadCallback;
import ly.count.sdk.java.internal.Utils;
/**
* Countly configuration object.
*/
public class Config {
protected Log configLog;
/**
* URL of Countly server
*/
protected URL serverURL;
/**
* Application key of Countly server
*/
protected String serverAppKey;
/**
* Set of Countly SDK features enabled
*/
protected int features = 0;
/**
* Device id generation strategy, UUID by default
*/
protected int deviceIdStrategy = 0;
/**
* Developer specified device id
*/
protected String customDeviceId;
/**
* Logging level
*/
protected LoggingLevel loggingLevel = LoggingLevel.OFF;
/**
* Log listener
*/
protected LogCallback logListener = null;
/**
* Countly SDK name to be sent in HTTP requests
*/
protected String sdkName = "java-native";
/**
* Countly SDK version to be sent in HTTP requests
*/
protected String sdkVersion = "24.1.3";
/**
* Countly SDK version to be sent in HTTP requests
*/
protected String applicationVersion;
/**
* Force usage of POST method for all requests
*/
protected boolean forceHTTPPost = false;
/**
* This would be a special state where the majority of the SDK calls don't work anymore and only a few special calls work.
*/
protected boolean enableBackendMode = false;
protected final Map<String, String> metricOverride = new ConcurrentHashMap<>();
/**
* Salt string for parameter tampering protection
*/
protected String salt = null;
/**
* Connection timeout in seconds for HTTP requests SDK sends to Countly server. Defaults to 30.
*/
protected int networkConnectionTimeout = 30;
/**
* Read timeout in seconds for HTTP requests SDK sends to Countly server. Defaults to 30.
*/
protected int networkReadTimeout = 30;
/**
* How long to wait between requests in milliseconds. Used to decrease CPU & I/O load on the device.
*/
protected int networkRequestCooldown = 1000;
/**
* How long to wait between Device ID change & push token requests, in milliseconds.
* Required by Countly server, don't change unless you know what you're doing!
*/
protected int networkImportantRequestCooldown = 5000;
/**
* Enable SSL public key pinning. Improves HTTPS security by not allowing MiM attacks
* based on SSL certificate replacing somewhere between Android device and Countly server.
* Here you can set one or more PEM-encoded public keys which Countly SDK verifies against
* public keys provided by Countly's web server for each HTTPS connection. At least one match
* results in connection being established, no matches result in request not being sent stored for next try.
*
* NOTE: Public key pinning is preferred over certificate pinning due to the fact
* that public keys are usually not changed when certificate expires and you generate new one.
* This ensures pinning continues to work after certificate prolongation.
* Certificates ({@link #certificatePins}) on the other hand have specific expiry date.
* In case you chose this way of pinning, you MUST ensure that ALL installs of your app
* have both certificates (old & new) until expiry date.
*/
protected Set<String> publicKeyPins = null;
/**
* Enable SSL certificate pinning. Improves HTTPS security by not allowing MiM attacks
* based on SSL certificate replacing somewhere between Android device and Countly server.
* Here you can set one or more PEM-encoded certificates which Countly SDK verifies against
* certificates provided by Countly's web server for each HTTPS connection. At least one match
* results in connection being established, no matches result in request not being sent stored for next try.
*
* NOTE: Public key pinning ({@link #publicKeyPins}) is preferred over certificate pinning due to the fact
* that public keys are usually not changed when certificate expires and you generate new one.
* This ensures pinning continues to work after certificate prolongation.
* Certificates on the other hand have specific expiry date.
* In case you chose this way of pinning, you MUST ensure that ALL installs of your app
* have both certificates (old & new) until expiry date.
*/
protected Set<String> certificatePins = null;
/**
* Maximum amount of time in seconds between two update requests to the server
* reporting session duration and other parameters if any added between update requests.
*
* Update request is also sent when number of unsent events reached {@link #eventQueueThreshold}.
*
* Set to 0 to disable update requests based on time.
*/
protected int sendUpdateEachSeconds = 60;
/**
* Maximum number of events to hold until request is to be sent to the server
*
* Events are also sent along with session update each {@link #sendUpdateEachSeconds}.
*
* Set to 0 to disable buffering.
*/
protected int eventQueueThreshold = 10;
/**
* {@link CrashProcessor}-implementing class which is instantiated when application
* crashes or crash is reported programmatically using {@link Session#addCrashReport(Throwable, boolean, String, Map, String...)}.
* Crash processor helps you to add custom data in event of a crash: custom crash segments & crash logs.
*/
protected String crashProcessorClass = null;
/**
* Feature-Class map which sets ModuleBase overrides.
*/
protected Map<Integer, Class<? extends ModuleBase>> moduleOverrides = null;
/**
* Requires GDPR-compliance calls.
* If {@code true}, SDK waits for corresponding consent calls before recording any data.
*/
protected boolean requiresConsent = false;
//endregion
//Begin Remote Config Module Fields
/**
* If remote config automatic fetching should be enabled
*/
protected boolean enableRemoteConfigAutomaticDownloadTriggers = false;
/**
* If remote config value caching should be enabled
*/
protected boolean enableRemoteConfigValueCaching = false;
/**
* If automatic remote config enrollment should be enabled
*/
protected boolean enableAutoEnrollFlag = false;
protected List<RCDownloadCallback> remoteConfigGlobalCallbacks = new ArrayList<>();
//End Remote Config Module Fields
/**
* Maximum in memory request queue size.
*/
protected int requestQueueMaxSize = 1000;
/**
* Storage path for storing requests and events queues
*/
protected File sdkStorageRootDirectory = null;
/**
* If sdk used across multiple platforms
*/
protected String sdkPlatform = System.getProperty("os.name");
/**
* Set the maximum amount of breadcrumbs.
*/
protected int maxBreadcrumbCount = 100;
/**
* Enable automatic crash reporting for unhandled exceptions.
*/
protected boolean unhandledCrashReportingEnabled = true;
/**
* Custom network request headers to be sent with each request.
* If you want to add a header, use {@link #addCustomNetworkRequestHeaders(Map)}.
*/
protected Map<String, String> customNetworkRequestHeaders = null;
public ConfigViews views = new ConfigViews(this);
protected String location = null;
protected String ip = null;
protected String city = null;
protected String country = null;
protected boolean locationEnabled = true;
protected boolean autoSendUserPropertiesOnSessions = true;
// TODO: storage limits & configuration
// protected int maxRequestsStored = 0;
// protected int storageDirectory = "";
// protected int storagePrefix = "[CLY]_";
/**
* The only Config constructor.
*
* @param serverURL valid {@link URL} of Countly server
* @param serverAppKey App Key from Management -> Applications section of your Countly Dashboard
* @deprecated use {@link #Config(String, String, File)} instead
*/
public Config(String serverURL, String serverAppKey) {
this(serverURL, serverAppKey, null);
}
/**
* The only Config constructor.
*
* @param serverURL valid {@link URL} of Countly server
* @param serverAppKey App Key from Management -> Applications section of your Countly Dashboard
* @param sdkStorageRootDirectory root directory for SDK files
*/
public Config(String serverURL, String serverAppKey, File sdkStorageRootDirectory) {
//the last '/' should be deleted
if (serverURL != null && serverURL.length() > 0 && serverURL.charAt(serverURL.length() - 1) == '/') {
serverURL = serverURL.substring(0, serverURL.length() - 1);
}
try {
this.serverURL = new URL(serverURL);
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
this.serverAppKey = serverAppKey;
this.sdkStorageRootDirectory = sdkStorageRootDirectory;
}
/**
* Get the maximum amount of breadcrumbs. Default is 100.
*
* @param maxBreadcrumbCount the maximum amount of breadcrumbs
* @return {@code this} instance for method chaining
*/
public Config setMaxBreadcrumbCount(int maxBreadcrumbCount) {
this.maxBreadcrumbCount = maxBreadcrumbCount;
return this;
}
/**
* Disable automatic crash reporting for unhandled exceptions.
*
* @return {@code this} instance for method chaining
*/
public Config disableUnhandledCrashReporting() {
this.unhandledCrashReportingEnabled = false;
return this;
}
/**
* Whether to allow fallback from unavailable device id strategy to Countly OpenUDID derivative.
*
* @param deviceIdFallbackAllowed true if fallback is allowed
* @return {@code this} instance for method chaining
* @deprecated this will do nothing
*/
public Config setDeviceIdFallbackAllowed(boolean deviceIdFallbackAllowed) {
return this;
}
/**
* Enable one or many features of Countly SDK instead of {@link #setFeatures(Config.Feature...)}.
*
* @param features features to enable
* @return {@code this} instance for method chaining
*/
public Config enableFeatures(Config.Feature... features) {
if (features == null) {
if (configLog != null) {
configLog.e("[Config] Features array cannot be null");
}
} else {
for (Config.Feature f : features) {
if (f == null) {
if (configLog != null) {
configLog.e("[Config] Feature cannot be null");
}
} else {
this.features = this.features | f.getIndex();
}
}
}
return this;
}
/**
* Disable one or many features of Countly SDK instead of {@link #setFeatures(Config.Feature...)}.
*
* @param features features to disable
* @return {@code this} instance for method chaining
*/
public Config disableFeatures(Config.Feature... features) {
if (features == null) {
if (configLog != null) {
configLog.e("[Config] Features array cannot be null");
}
} else {
for (Config.Feature f : features) {
if (f == null) {
if (configLog != null) {
configLog.e("[Config] Feature cannot be null");
}
} else {
this.features = this.features & ~f.getIndex();
}
}
}
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 Returns the same config object for convenient linking
*/
public Config setLogListener(LogCallback logCallback) {
this.logListener = logCallback;
return this;
}
/**
* Set enabled features all at once instead of {@link #setFeatures(Config.Feature...)}.
*
* @param features variable args of features to enable
* @return {@code this} instance for method chaining
*/
public Config setFeatures(Config.Feature... features) {
this.features = 0;
if (features != null && features.length > 0) {
for (int i = 0; i < features.length; i++) {
if (features[i] == null) {
if (configLog != null) {
configLog.e("[Config] " + i + "-th feature is null in setFeatures");
}
} else {
this.features = this.features | features[i].index;
}
}
}
return this;
}
/**
* Set device id generation strategy:
* - {@link DeviceIdStrategy#UUID} to use standard java random UUID. Default.
* - {@link DeviceIdStrategy#CUSTOM_ID} to use your own device id for Countly.
*
* @param strategy strategy to use instead of default OpenUDID
* @param customDeviceId device id for use with {@link DeviceIdStrategy#CUSTOM_ID}
* @return {@code this} instance for method chaining
*/
public Config setDeviceIdStrategy(DeviceIdStrategy strategy, String customDeviceId) {
if (strategy == null) {
if (configLog != null) {
configLog.e("[Config] DeviceIdStrategy cannot be null");
}
} else {
if (strategy == DeviceIdStrategy.CUSTOM_ID) {
return setCustomDeviceId(customDeviceId);
}
this.deviceIdStrategy = strategy.index;
}
return this;
}
/**
* Shorthand method for {@link #setDeviceIdStrategy(DeviceIdStrategy, String)}
*
* @param strategy strategy to use instead of default OpenUDID
* @return {@code this} instance for method chaining
*/
public Config setDeviceIdStrategy(DeviceIdStrategy strategy) {
return setDeviceIdStrategy(strategy, null);
}
/**
* Set device id to specific string and set generation strategy to {@link DeviceIdStrategy#CUSTOM_ID}.
*
* @param customDeviceId device id for use with {@link DeviceIdStrategy#CUSTOM_ID}
* @return {@code this} instance for method chaining
*/
public Config setCustomDeviceId(String customDeviceId) {
if (Utils.isEmptyOrNull(customDeviceId)) {
if (configLog != null) {
configLog.e("[Config] DeviceIdStrategy.CUSTOM_ID strategy cannot be used without device id specified");
}
this.customDeviceId = null;
this.deviceIdStrategy = 0;
} else {
this.customDeviceId = customDeviceId;
this.deviceIdStrategy = DeviceIdStrategy.CUSTOM_ID.index;
}
return this;
}
/**
* Getter for {@link #deviceIdStrategy}
*
* @return {@link #deviceIdStrategy} value as enum
*/
public DeviceIdStrategy getDeviceIdStrategyEnum() {
return DeviceIdStrategy.fromIndex(deviceIdStrategy);
}
/**
* Force usage of POST method for all requests
*
* @return {@code this} instance for method chaining
* @deprecated use {@link #enableForcedHTTPPost()} instead
*/
public Config enableUsePOST() {
return enableForcedHTTPPost();
}
/**
* Force usage of POST method for all requests
*
* @return {@code this} instance for method chaining
*/
public Config enableForcedHTTPPost() {
this.forceHTTPPost = true;
return this;
}
/**
* Force usage of POST method for all requests.
*
* @param forcePost whether to force using POST method for all requests or not
* @return {@code this} instance for method chaining
* @deprecated please use {@link #enableForcedHTTPPost()} instead
*/
public Config setUsePOST(boolean forcePost) {
this.forceHTTPPost = forcePost;
return this;
}
/**
* Enable SDK's backend mode.
*
* @return {@code this} instance for method chaining
*/
public Config enableBackendMode() {
this.enableBackendMode = true;
return this;
}
public int getRequestQueueMaxSize() {
return requestQueueMaxSize;
}
/**
* In backend mode set the in memory request queue size.
*
* @param requestQueueMaxSize int to set request queue maximum size for backend mode
* @return {@code this} instance for method chaining
*/
public Config setRequestQueueMaxSize(int requestQueueMaxSize) {
this.requestQueueMaxSize = requestQueueMaxSize;
return this;
}
/**
* Enable parameter tampering protection
*
* @param salt String to add to each request before calculating checksum
* @return {@code this} instance for method chaining
*/
public Config enableParameterTamperingProtection(String salt) {
if (Utils.isEmptyOrNull(salt)) {
if (configLog != null) {
configLog.e("[Config] Salt cannot be empty in enableParameterTamperingProtection");
}
} else {
this.salt = salt;
}
return this;
}
/**
* Tag used for logging
*
* @param loggingTag tag string to use
* @return {@code this} instance for method chaining
* @deprecated Calling this function will do nothing
*/
public Config setLoggingTag(String loggingTag) {
return this;
}
/**
* Logging level for Countly SDK
*
* @param loggingLevel log level to use
* @return {@code this} instance for method chaining
*/
public Config setLoggingLevel(LoggingLevel loggingLevel) {
if (loggingLevel == null) {
if (configLog != null) {
configLog.e("[Config] Logging level cannot be null");
}
} else {
this.loggingLevel = loggingLevel;
}
return this;
}
/**
* Enable test mode:
* <ul>
* <li>Raise exceptions when SDK is in inconsistent state as opposed to silently
* trying to ignore them when testMode is off</li>
* <li>Put Firebase token under {@code test} devices if {@code Feature.Push} is enabled.</li>
* </ul>
* Note: this method automatically sets {@link #loggingLevel} to {@link LoggingLevel#INFO} in
* case it was {@link LoggingLevel#OFF} (default).
*
* @return {@code this} instance for method chaining
* @deprecated Calling this function will do nothing
*/
public Config enableTestMode() {
return this;
}
/**
* Disable test mode, so SDK will silently avoid raising exceptions whenever possible.
* Test mode is disabled by default.
*
* @return {@code this} instance for method chaining
* @deprecated Calling this function will do nothing
*/
public Config disableTestMode() {
return this;
}
/**
* Set maximum amount of time in seconds between two update requests to the server
* reporting session duration and other parameters if any added between update requests.
*
* Update request is also sent when number of unsent events reached {@link #setEventsBufferSize(int)}.
*
* @param sendUpdateEachSeconds max time interval between two update requests, set to 0 to disable update requests based on time.
* @return {@code this} instance for method chaining
* @deprecated this will be removed, please use {@link #setUpdateSessionTimerDelay(int)}
*/
public Config setSendUpdateEachSeconds(int sendUpdateEachSeconds) {
return setUpdateSessionTimerDelay(sendUpdateEachSeconds);
}
/**
* Changes the maximum amount of time in seconds between two update requests to the server reporting
* session duration and other parameters, if any, added between update requests.
*
* An update request is also sent when the number of unsent events reaches {@link #setEventQueueSizeToSend(int)}.
*
* @param delay max time interval between two update requests, set to 0 to disable update requests based on time.
* @return {@code this} instance for method chaining
*/
public Config setUpdateSessionTimerDelay(int delay) {
if (delay < 0) {
if (configLog != null) {
configLog.e("[Config] delay cannot be negative");
}
} else {
this.sendUpdateEachSeconds = delay;
}
return this;
}
/**
* Sets maximum number of events to hold until forcing update request to be sent to the server
*
* Update request is also sent when last update request was sent more than {@link #setSendUpdateEachSeconds(int)} seconds ago.
*
* @param eventQueueThreshold max number of events between two update requests, set to 0 to disable update requests based on events.
* @return {@code this} instance for method chaining
* @deprecated this will be removed, please use {@link #setEventQueueSizeToSend(int)}
*/
public Config setEventsBufferSize(int eventQueueThreshold) {
return setEventQueueSizeToSend(eventQueueThreshold);
}
/**
* Changes the maximum number of events to hold until an update request is sent to the server
*
* An update request is also sent when the last update request was sent more than {@link #setUpdateSessionTimerDelay(int)} seconds ago.
*
* @param eventsQueueSize max number of events between two update requests, set to 0 to disable update requests based on events.
* @return {@code this} instance for method chaining
*/
public Config setEventQueueSizeToSend(int eventsQueueSize) {
if (eventsQueueSize < 0) {
if (configLog != null) {
configLog.e("[Config] eventsQueueSize cannot be negative");
}
} else {
this.eventQueueThreshold = eventsQueueSize;
}
return this;
}
/**
* Disable update requests completely. Only begin & end requests will be sent + some special
* cases if applicable like User Profile change or Push token updated.
*
* @return {@code this} instance for method chaining
* @see #setUpdateSessionTimerDelay(int)
* @see #setEventQueueSizeToSend(int)
*/
public Config disableUpdateRequests() {
this.sendUpdateEachSeconds = 0;
return this;
}
/**
* Change name of SDK used in HTTP requests
*
* @param sdkName new name of SDK
* @return {@code this} instance for method chaining
* @deprecated Calling this function will do nothing
*/
public Config setSdkName(String sdkName) {
return this;
}
/**
* Change version of SDK used in HTTP requests
*
* @param sdkVersion new version of SDK
* @return {@code this} instance for method chaining
* @deprecated Calling this function will do nothing
*/
public Config setSdkVersion(String sdkVersion) {
return this;
}
/**
* Change application name reported to Countly server
*
* @param name new name
* @return {@code this} instance for method chaining
* @deprecated this will do nothing
*/
public Config setApplicationName(String name) {
return this;
}
/**
* Change application version reported to Countly server
*
* @param version new version
* @return {@code this} instance for method chaining
*/
public Config setApplicationVersion(String version) {
if (Utils.isEmptyOrNull(version)) {
if (configLog != null) {
configLog.e("[Config] version cannot be empty");
}
} else {
this.applicationVersion = version;
}
return this;
}
/**
* Set connection timeout in seconds for HTTP requests SDK sends to Countly server. Defaults to 30.
*
* @param seconds network timeout in seconds
* @return {@code this} instance for method chaining
*/
public Config setNetworkConnectTimeout(int seconds) {
if (seconds <= 0 || seconds > 300) {
if (configLog != null) {
configLog.e("[Config] Connection timeout must be between 0 and 300");
}
} else {
networkConnectionTimeout = seconds;
}
return this;
}
/**
* Set read timeout in seconds for HTTP requests SDK sends to Countly server. Defaults to 30.
*
* @param seconds read timeout in seconds
* @return {@code this} instance for method chaining
*/
public Config setNetworkReadTimeout(int seconds) {
if (seconds <= 0 || seconds > 300) {
if (configLog != null) {
configLog.e("[Config] Read timeout must be between 0 and 300");
}
} else {
networkReadTimeout = seconds;
}
return this;
}
/**
* How long to wait between requests in seconds.
* Used to decrease CPU & I/O load on the device in case of batch requests.
*
* @param milliseconds cooldown period in seconds
* @return {@code this} instance for method chaining
*/
public Config setNetworkRequestCooldown(int milliseconds) {
if (milliseconds < 0 || milliseconds > 30000) {
if (configLog != null) {
configLog.e("[Config] Request cooldown must be between 0 and 30000");
}
} else {
networkRequestCooldown = milliseconds;
}
return this;
}
/**
* Set read timeout in seconds for HTTP requests SDK sends to Countly server. Defaults to 30.
* Used to decrease CPU & I/O load on the device in case of batch requests.
*
* @param milliseconds read timeout in milliseconds
* @return {@code this} instance for method chaining
*/
public Config setNetworkImportantRequestCooldown(int milliseconds) {
if (milliseconds < 0 || milliseconds > 30) {
if (configLog != null) {
configLog.e("[Config] Important request cooldown must be between 0 and 30");
}
} else {
networkImportantRequestCooldown = milliseconds;
}
return this;
}
/**
* Enable SSL public key pinning. Improves HTTPS security by not allowing MiM attacks
* based on SSL certificate replacing somewhere between Android device and Countly server.
* Here you can set one or more PEM-encoded public keys which Countly SDK verifies against
* public keys provided by Countly's web server for each HTTPS connection. At least one match
* results in connection being established, no matches result in request not being sent stored for next try.
*
* NOTE: Public key pinning is preferred over certificate pinning due to the fact
* that public keys are usually not changed when certificate expires and you generate new one.
* This ensures pinning continues to work after certificate prolongation.
* Certificates ({@link #certificatePins}) on the other hand have specific expiry date.
* In case you chose this way of pinning, you MUST ensure that ALL installs of your app
* have both certificates (old & new) until expiry date.
*
* NOTE: when {@link #serverURL} doesn't have {@code "https://"} public key pinning doesn't work
*
* @param pemEncodedPublicKey PEM-encoded SSL public key string to add
* @return {@code this} instance for method chaining
*/
public Config addPublicKeyPin(String pemEncodedPublicKey) {
if (Utils.isEmptyOrNull(pemEncodedPublicKey)) {
if (configLog != null) {
configLog.e("[Config] pemEncodedPublicKey cannot be empty");
}
} else {
if (publicKeyPins == null) {
publicKeyPins = new HashSet<>();
}
publicKeyPins.add(pemEncodedPublicKey);
}
return this;
}
/**
* Enable SSL certificate pinning. Improves HTTPS security by not allowing MiM attacks
* based on SSL certificate replacing somewhere between Android device and Countly server.
* Here you can set one or more PEM-encoded certificates which Countly SDK verifies against
* certificates provided by Countly's web server for each HTTPS connection. At least one match
* results in connection being established, no matches result in request not being sent stored for next try.
*
* NOTE: Public key pinning ({@link #publicKeyPins}) is preferred over certificate pinning due to the fact
* that public keys are usually not changed when certificate expires and you generate new one.
* This ensures pinning continues to work after certificate prolongation.
* Certificates on the other hand have specific expiry date.
* In case you chose this way of pinning, you MUST ensure that ALL installs of your app
* have both certificates (old & new) until expiry date.
*
* NOTE: when {@link #serverURL} doesn't have {@code "https://"} certificate pinning doesn't work
*
* @param pemEncodedCertificate PEM-encoded SSL certificate string to add
* @return {@code this} instance for method chaining
*/
public Config addCertificatePin(String pemEncodedCertificate) {
if (Utils.isEmptyOrNull(pemEncodedCertificate)) {
if (configLog != null) {
configLog.e("[Config] pemEncodedCertificate cannot be empty");
}
} else {
if (certificatePins == null) {
certificatePins = new HashSet<>();
}
certificatePins.add(pemEncodedCertificate);
}
return this;
}
/**
* Change period when a check for ANR is made. ANR reporting is enabled by default once you enable {@code Feature.CrashReporting}.
* Default period is 5 seconds. This is *NOT* a timeout for any possible time frame within app running time, it's a checking period.
* Meaning *some* ANRs are to be recorded if main thread is blocked for slightly more than #crashReportingANRCheckingPeriod.
* Statistically it should be good enough as you don't really need all ANRs on the server.
* *More* ANRs will be recorded in case main thread is blocked for {@code 1.5 * crashReportingANRCheckingPeriod}. Almost all ANRs
* are going to be recorded once main thread is blocked for {@code 2 * crashReportingANRCheckingPeriod} or more seconds.
*
* To disable ANR reporting, use {@link #disableANRCrashReporting()}.
*
* @param periodInSeconds how much time the SDK waits between individual ANR checks
* @return {@code this} instance for method chaining
* @deprecated will do nothing
*/
public Config setCrashReportingANRCheckingPeriod(int periodInSeconds) {
return this;
}
/**
* Disable ANR detection and thus reporting to Countly server.
*
* @return {@code this} instance for method chaining
* @deprecated will do nothing
*/
public Config disableANRCrashReporting() {
return this;
}
/**
* Set crash processor class responsible .
* Defaults automatically to main activity class.
*
* @param crashProcessorClass {@link CrashProcessor}-implementing class
* @return {@code this} instance for method chaining
*/
public Config setCrashProcessorClass(Class<? extends CrashProcessor> crashProcessorClass) {
if (crashProcessorClass == null) {
if (configLog != null) {
configLog.e("[Config] crashProcessorClass cannot be null");
}
} else {
this.crashProcessorClass = crashProcessorClass.getName();
}
return this;
}
/**
* Override some {@link ModuleBase} functionality with your own class.
*
* @param feature feature index to override
* @param cls {@link Class} to use instead of Countly SDK standard class
* @return {@code this} instance for method chaining
* @deprecated this will do nothing
*/
protected Config overrideModule(Integer feature, Class<? extends ModuleBase> cls) {
return this;
}
/**
* Getter for {@link #features}
*
* @return {@link #features} value
*/
public Set<Config.Feature> getFeatures() {
Set<Config.Feature> ftrs = new HashSet<>();
for (Config.Feature f : Config.Feature.values()) {
if ((f.index & features) > 0) {
ftrs.add(f);
}
}
return ftrs;
}
public int getFeaturesMap() {
return features;
}
/**
* Whether a feature is enabled in this config, that is exists in {@link #features}
*
* @return {@code true} if {@link #features} contains supplied argument, {@code false} otherwise
*/
public boolean isFeatureEnabled(Config.Feature feature) {
return (features & feature.index) > 0;
}
/**
* Getter for {@link #moduleOverrides}
*
* @return {@link #moduleOverrides} value for {@code Feature} specified
* @deprecated this will do nothing
*/
public Class<? extends ModuleBase> getModuleOverride(Config.Feature feature) {
return null;
}
/**
* Enable GDPR compliance by disallowing SDK to record any data until corresponding consent
* calls are made.
*
* @param requiresConsent {@code true} to enable GDPR compliance
* @return {@code this} instance for method chaining
*/
public Config setRequiresConsent(boolean requiresConsent) {
this.requiresConsent = requiresConsent;
return this;
}
/**
* Getter for {@link #serverURL}
*
* @return {@link #serverURL} value
*/
public URL getServerURL() {
return serverURL;
}
/**
* Getter for {@link #serverAppKey}
*
* @return {@link #serverAppKey} value
*/
public String getServerAppKey() {
return serverAppKey;
}
/**
* Getter for {@link #deviceIdStrategy}
*
* @return {@link #deviceIdStrategy} value
*/
public int getDeviceIdStrategy() {
return deviceIdStrategy;
}
/**
* Whether to allow fallback from unavailable device id strategy to any other available.
*