Skip to content

Commit 140013c

Browse files
refactor: internal limits checks
1 parent 401354c commit 140013c

File tree

2 files changed

+12
-82
lines changed

2 files changed

+12
-82
lines changed

sdk/src/main/java/ly/count/android/sdk/ConfigSdkInternalLimits.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
public class ConfigSdkInternalLimits {
44
//SDK internal limits
5-
protected Integer maxKeyLength;
6-
protected Integer maxValueSize;
5+
protected Integer maxKeyLength = 128;
6+
protected Integer maxValueSize = 256;
77
protected int maxValueSizePicture = 4096;
8-
protected Integer maxSegmentationValues;
9-
protected Integer maxBreadcrumbCount;
10-
protected Integer maxStackTraceLinesPerThread;
11-
protected Integer maxStackTraceLineLength;
8+
protected Integer maxSegmentationValues = 100;
9+
protected Integer maxBreadcrumbCount = 100;
10+
protected Integer maxStackTraceLinesPerThread = 30;
11+
protected Integer maxStackTraceLineLength = 200;
1212
protected int maxStackTraceThreadCount = 50;
1313

1414
/**
@@ -19,7 +19,7 @@ public class ConfigSdkInternalLimits {
1919
* @return Returns the same config object for convenient linking
2020
*/
2121
public synchronized ConfigSdkInternalLimits setMaxSegmentationValues(int maxSegmentationValues) {
22-
this.maxSegmentationValues = maxSegmentationValues;
22+
this.maxSegmentationValues = Math.max(maxSegmentationValues, 1);
2323
return this;
2424
}
2525

@@ -32,7 +32,7 @@ public synchronized ConfigSdkInternalLimits setMaxSegmentationValues(int maxSegm
3232
* @return Returns the same config object for convenient linking
3333
*/
3434
public synchronized ConfigSdkInternalLimits setMaxBreadcrumbCount(int maxBreadcrumbCount) {
35-
this.maxBreadcrumbCount = maxBreadcrumbCount;
35+
this.maxBreadcrumbCount = Math.max(maxBreadcrumbCount, 1);
3636
return this;
3737
}
3838

@@ -46,7 +46,7 @@ public synchronized ConfigSdkInternalLimits setMaxBreadcrumbCount(int maxBreadcr
4646
* @return Returns the same config object for convenient linking
4747
*/
4848
public synchronized ConfigSdkInternalLimits setMaxKeyLength(int maxKeyLength) {
49-
this.maxKeyLength = maxKeyLength;
49+
this.maxKeyLength = Math.max(maxKeyLength, 1);
5050
return this;
5151
}
5252

@@ -66,7 +66,7 @@ public synchronized ConfigSdkInternalLimits setMaxKeyLength(int maxKeyLength) {
6666
* @return Returns the same config object for convenient linking
6767
*/
6868
public synchronized ConfigSdkInternalLimits setMaxValueSize(int maxValueSize) {
69-
this.maxValueSize = maxValueSize;
69+
this.maxValueSize = Math.max(maxValueSize, 1);
7070
return this;
7171
}
7272

@@ -78,7 +78,7 @@ public synchronized ConfigSdkInternalLimits setMaxValueSize(int maxValueSize) {
7878
* @return Returns the same config object for convenient linking
7979
*/
8080
public synchronized ConfigSdkInternalLimits setMaxStackTraceLinesPerThread(int maxStackTraceLinesPerThread) {
81-
this.maxStackTraceLinesPerThread = maxStackTraceLinesPerThread;
81+
this.maxStackTraceLinesPerThread = Math.max(maxStackTraceLinesPerThread, 1);
8282
return this;
8383
}
8484

@@ -90,7 +90,7 @@ public synchronized ConfigSdkInternalLimits setMaxStackTraceLinesPerThread(int m
9090
* @return Returns the same config object for convenient linking
9191
*/
9292
public synchronized ConfigSdkInternalLimits setMaxStackTraceLineLength(int maxStackTraceLineLength) {
93-
this.maxStackTraceLineLength = maxStackTraceLineLength;
93+
this.maxStackTraceLineLength = Math.max(maxStackTraceLineLength, 1);
9494
return this;
9595
}
9696
}

sdk/src/main/java/ly/count/android/sdk/Countly.java

-70
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,6 @@ public enum CountlyMessagingProvider {
126126
HMS, // Huawei
127127
}
128128

129-
//SDK limit defaults
130-
final int maxKeyLengthDefault = 128;
131-
final int maxValueSizeDefault = 256;
132-
final int maxSegmentationValuesDefault = 100;
133-
final int maxBreadcrumbCountDefault = 100;
134-
final int maxStackTraceLinesPerThreadDefault = 30;
135-
final int maxStackTraceLineLengthDefault = 200;
136-
final int maxStackTraceThreadCountDefault = 50;
137-
138129
// see http://stackoverflow.com/questions/7048198/thread-safe-singletons-in-java
139130
private static class SingletonHolder {
140131
@SuppressLint("StaticFieldLeak")
@@ -358,67 +349,6 @@ public synchronized Countly init(CountlyConfig config) {
358349

359350
config_ = config;
360351

361-
// Have a look at the SDK limit values
362-
if (config.sdkInternalLimits.maxKeyLength != null) {
363-
if (config.sdkInternalLimits.maxKeyLength < 1) {
364-
config.sdkInternalLimits.maxKeyLength = 1;
365-
L.w("[Init] provided 'maxKeyLength' is less than '1'. Setting it to '1'.");
366-
}
367-
L.i("[Init] provided 'maxKeyLength' override:[" + config.sdkInternalLimits.maxKeyLength + "]");
368-
} else {
369-
config.sdkInternalLimits.maxKeyLength = maxKeyLengthDefault;
370-
}
371-
372-
if (config.sdkInternalLimits.maxValueSize != null) {
373-
if (config.sdkInternalLimits.maxValueSize < 1) {
374-
config.sdkInternalLimits.maxValueSize = 1;
375-
L.w("[Init] provided 'maxValueSize' is less than '1'. Setting it to '1'.");
376-
}
377-
L.i("[Init] provided 'maxValueSize' override:[" + config.sdkInternalLimits.maxValueSize + "]");
378-
} else {
379-
config.sdkInternalLimits.maxValueSize = maxValueSizeDefault;
380-
}
381-
382-
if (config.sdkInternalLimits.maxSegmentationValues != null) {
383-
if (config.sdkInternalLimits.maxSegmentationValues < 1) {
384-
config.sdkInternalLimits.maxSegmentationValues = 1;
385-
L.w("[Init] provided 'maxSegmentationValues' is less than '1'. Setting it to '1'.");
386-
}
387-
L.i("[Init] provided 'maxSegmentationValues' override:[" + config.sdkInternalLimits.maxSegmentationValues + "]");
388-
} else {
389-
config.sdkInternalLimits.maxSegmentationValues = maxSegmentationValuesDefault;
390-
}
391-
392-
if (config.sdkInternalLimits.maxBreadcrumbCount != null) {
393-
if (config.sdkInternalLimits.maxBreadcrumbCount < 1) {
394-
config.sdkInternalLimits.maxBreadcrumbCount = 1;
395-
L.w("[Init] provided 'maxBreadcrumbCount' is less than '1'. Setting it to '1'.");
396-
}
397-
L.i("[Init] provided 'maxBreadcrumbCount' override:[" + config.sdkInternalLimits.maxBreadcrumbCount + "]");
398-
} else {
399-
config.sdkInternalLimits.maxBreadcrumbCount = maxBreadcrumbCountDefault;
400-
}
401-
402-
if (config.sdkInternalLimits.maxStackTraceLinesPerThread != null) {
403-
if (config.sdkInternalLimits.maxStackTraceLinesPerThread < 1) {
404-
config.sdkInternalLimits.maxStackTraceLinesPerThread = 1;
405-
L.w("[Init] provided 'maxStackTraceLinesPerThread' is less than '1'. Setting it to '1'.");
406-
}
407-
L.i("[Init] provided 'maxStackTraceLinesPerThread' override:[" + config.sdkInternalLimits.maxStackTraceLinesPerThread + "]");
408-
} else {
409-
config.sdkInternalLimits.maxStackTraceLinesPerThread = maxStackTraceLinesPerThreadDefault;
410-
}
411-
412-
if (config.sdkInternalLimits.maxStackTraceLineLength != null) {
413-
if (config.sdkInternalLimits.maxStackTraceLineLength < 1) {
414-
config.sdkInternalLimits.maxStackTraceLineLength = 1;
415-
L.w("[Init] provided 'maxStackTraceLineLength' is less than '1'. Setting it to '1'.");
416-
}
417-
L.i("[Init] provided 'maxStackTraceLineLength' override:[" + config.sdkInternalLimits.maxStackTraceLineLength + "]");
418-
} else {
419-
config.sdkInternalLimits.maxStackTraceLineLength = maxStackTraceLineLengthDefault;
420-
}
421-
422352
long timerDelay = TIMER_DELAY_IN_SECONDS;
423353
if (config.sessionUpdateTimerDelay != null) {
424354
//if we need to change the timer delay, do that first

0 commit comments

Comments
 (0)