Skip to content

Commit 4b30b27

Browse files
authored
Merge pull request #348 from Countly/fix_multiple_types
Add mixed type of immutable lists to segmentation
2 parents 4329ba3 + c719d42 commit 4b30b27

File tree

7 files changed

+24
-20
lines changed

7 files changed

+24
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## XX.XX.XX
2+
* Added mixed type of immutable lists, arrays to client given segmentations
23
* Mitigated issues where:
34
* session was ending regardless of manual control after without merge, not anymore.
45
* session was not starting even if consent is not required and automatic sessions are enabled after without merge, not anymore.

sdk/src/androidTest/java/ly/count/android/sdk/ModuleCrashTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@ public void recordHandledException_validateSupportedLists() throws JSONException
13831383
"arrDO", new JSONArray(arrDO),
13841384
"arrBO", new JSONArray(arrBO),
13851385
"arrIO", new JSONArray(arrIO),
1386+
"arrObj", new JSONArray(arrObj),
13861387
"arrObjStr", new JSONArray(arrObjStr)
13871388
);
13881389

@@ -1434,7 +1435,8 @@ public void recordHandledException_validateSupportedJSONArrays() throws JSONExce
14341435
"arrL", arrL,
14351436
"arrD", arrD,
14361437
"arrBO", arrBO,
1437-
"arrIO", arrIO
1438+
"arrIO", arrIO,
1439+
"arrObj", arrObj
14381440
);
14391441

14401442
validateCrash(extractStackTrace(exception), "", false, false, expectedSegmentation, 0, new HashMap<>(), new ArrayList<>());

sdk/src/androidTest/java/ly/count/android/sdk/ModuleEventsTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,8 @@ public void recordEvent_validateSupportedLists() throws JSONException {
686686
"arrDO", new JSONArray(arrDO),
687687
"arrBO", new JSONArray(arrBO),
688688
"arrIO", new JSONArray(arrIO),
689-
"arrObjStr", new JSONArray(arrObjStr)
689+
"arrObjStr", new JSONArray(arrObjStr),
690+
"arrObj", new JSONArray(arrObj)
690691
);
691692

692693
// Validate the recorded event with expected segmentation
@@ -738,7 +739,8 @@ public void recordEvent_validateSupportedJSONArrays() throws JSONException {
738739
"arrL", arrL,
739740
"arrD", arrD,
740741
"arrBO", arrBO,
741-
"arrIO", arrIO
742+
"arrIO", arrIO,
743+
"arrObj", arrObj
742744
);
743745

744746
// Validate the recorded event with expected segmentation

sdk/src/androidTest/java/ly/count/android/sdk/ModuleFeedbackTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ public void reportFeedbackWidgetManually_validateSupportedLists() throws JSONExc
592592
"arrDO", new JSONArray(arrDO),
593593
"arrBO", new JSONArray(arrBO),
594594
"arrIO", new JSONArray(arrIO),
595+
"arrObj", new JSONArray(arrObj),
595596
"arrObjStr", new JSONArray(arrObjStr), "rating", 10, "comment", "huhu"
596597
);
597598

@@ -644,7 +645,8 @@ public void reportFeedbackWidgetManually_validateSupportedJSONArrays() throws JS
644645
"arrL", arrL,
645646
"arrD", arrD,
646647
"arrBO", arrBO,
647-
"arrIO", arrIO, "rating", 10, "comment", "huhu"
648+
"arrIO", arrIO, "rating", 10, "comment", "huhu",
649+
"arrObj", arrObj
648650
);
649651

650652
fillFeedbackWidgetSegmentationParams(expectedSegmentation, widgetInfo.widgetId);

sdk/src/androidTest/java/ly/count/android/sdk/ModuleViewsTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,8 @@ public void startView_validateSupportedLists() throws JSONException {
16521652
"arrDO", new JSONArray(arrDO),
16531653
"arrBO", new JSONArray(arrBO),
16541654
"arrIO", new JSONArray(arrIO),
1655-
"arrObjStr", new JSONArray(arrObjStr)
1655+
"arrObjStr", new JSONArray(arrObjStr),
1656+
"arrObj", new JSONArray(arrObj)
16561657
));
16571658

16581659
// Validate the recorded event with expected segmentation
@@ -1706,7 +1707,8 @@ public void startView_validateSupportedJSONArrays() throws JSONException {
17061707
"arrL", arrL,
17071708
"arrD", arrD,
17081709
"arrBO", arrBO,
1709-
"arrIO", arrIO
1710+
"arrIO", arrIO,
1711+
"arrObj", arrObj
17101712
));
17111713

17121714
// Validate the recorded event with expected segmentation

sdk/src/androidTest/java/ly/count/android/sdk/UtilsInternalLimitsTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,20 +417,23 @@ public void removeUnsupportedDataTypes_jsonArray() {
417417
JSONArray arrBool = new JSONArray(Arrays.asList(true, false, true, false));
418418
JSONArray arrFloat = new JSONArray(Arrays.asList(1.1f, 2.2f, 3.3f, 4.4f, 5.5f));
419419
JSONArray arrLong = new JSONArray(Arrays.asList(1L, 2L, 3L, 4L, 5L));
420-
JSONArray arrObj = new JSONArray(Arrays.asList(1, 2, "ABC", true, 3.3d, 4.4f, 5L, new Object()));
421-
Map<String, Object> segmentation = TestUtils.map("empty", empty, "arrInt", arrInt, "arrStr", arrStr, "arrDouble", arrDouble, "arrBool", arrBool, "arrFloat", arrFloat, "arrLong", arrLong, "arrObj", arrObj);
420+
JSONArray arrObj = new JSONArray(Arrays.asList(1, 2, "ABC", true, 3.3d, 4.4f, 5L));
421+
JSONArray arrObjUltra = new JSONArray(Arrays.asList(new HashMap<>(), new ArrayList<>(), empty));
422422

423-
Assert.assertEquals(8, segmentation.size());
423+
Map<String, Object> segmentation = TestUtils.map("empty", empty, "arrInt", arrInt, "arrStr", arrStr, "arrDouble", arrDouble, "arrBool", arrBool, "arrFloat", arrFloat, "arrLong", arrLong, "arrObj", arrObj, "arrObjUltra", arrObjUltra);
424+
425+
Assert.assertEquals(9, segmentation.size());
424426

425427
Assert.assertTrue(UtilsInternalLimits.removeUnsupportedDataTypes(segmentation, Mockito.mock(ModuleLog.class)));
426-
Assert.assertEquals(7, segmentation.size());
428+
Assert.assertEquals(8, segmentation.size());
427429
Assert.assertEquals(empty, segmentation.get("empty"));
428430
Assert.assertEquals(arrInt, segmentation.get("arrInt"));
429431
Assert.assertEquals(arrStr, segmentation.get("arrStr"));
430432
Assert.assertEquals(arrDouble, segmentation.get("arrDouble"));
431433
Assert.assertEquals(arrBool, segmentation.get("arrBool"));
432434
Assert.assertEquals(arrFloat, segmentation.get("arrFloat"));
433435
Assert.assertEquals(arrLong, segmentation.get("arrLong"));
436+
Assert.assertEquals(arrObj, segmentation.get("arrObj"));
434437
}
435438

436439
@Test

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import androidx.annotation.NonNull;
44
import androidx.annotation.Nullable;
55
import java.util.ArrayList;
6-
import java.util.HashSet;
76
import java.util.Iterator;
87
import java.util.List;
98
import java.util.Map;
10-
import java.util.Set;
119
import java.util.concurrent.ConcurrentHashMap;
1210
import org.json.JSONArray;
1311

@@ -358,31 +356,25 @@ static boolean isSupportedDataType(@Nullable Object value) {
358356
return true;
359357
} else if (value instanceof List) {
360358
List<?> list = (List<?>) value;
361-
Set<String> classNames = new HashSet<>();
362-
// checking for multiple classes because we cannot access generic type of the list
363359
for (Object element : list) {
364360
if (!isSupportedDataTypeBasic(element)) {
365361
return false;
366362
}
367-
classNames.add(element.getClass().getName());
368363
}
369-
// if it had multiple classes, it's not supported
370-
return classNames.size() <= 1;
364+
return true;
371365
} else if (value != null && value.getClass().isArray()) {
372366
Class<?> componentType = value.getClass().getComponentType();
373367
return componentType == String.class || componentType == Integer.class || componentType == Double.class || componentType == Boolean.class || componentType == Float.class || componentType == Long.class
374368
|| componentType == int.class || componentType == double.class || componentType == boolean.class || componentType == float.class || componentType == long.class;
375369
} else if (value instanceof JSONArray) {
376370
JSONArray jsonArray = (JSONArray) value;
377-
Set<String> classNames = new HashSet<>();
378371
for (int i = 0; i < jsonArray.length(); i++) {
379372
Object element = jsonArray.opt(i);
380373
if (!isSupportedDataTypeBasic(element)) {
381374
return false;
382375
}
383-
classNames.add(element.getClass().getName());
384376
}
385-
return classNames.size() <= 1;
377+
return true;
386378
}
387379
return false;
388380
}

0 commit comments

Comments
 (0)