22
33import androidx .annotation .NonNull ;
44import androidx .annotation .Nullable ;
5+ import java .util .HashSet ;
56import java .util .Iterator ;
7+ import java .util .Map ;
8+ import java .util .Set ;
9+ import java .util .concurrent .ConcurrentHashMap ;
10+ import org .json .JSONArray ;
611import org .json .JSONException ;
712import org .json .JSONObject ;
813
@@ -47,6 +52,12 @@ class ModuleConfiguration extends ModuleBase implements ConfigurationProvider {
4752 final static String keyRBOMRQPercentage = "bom_rqp" ;
4853 final static String keyRBOMRequestAge = "bom_ra" ;
4954 final static String keyRBOMDuration = "bom_d" ;
55+ final static String keyRUserPropertyCacheLimit = "upcl" ;
56+ final static String keyRFilterPreset = "filter_preset" ;
57+ final static String keyREventFilterList = "eb" ;
58+ final static String keyRUserPropertyFilterList = "upb" ;
59+ final static String keyRSegmentationFilterList = "sb" ;
60+ final static String keyREventSegmentationFilterList = "esb" ; // json
5061 // FLAGS
5162 boolean currentVTracking = true ;
5263 boolean currentVNetworking = true ;
@@ -64,6 +75,14 @@ class ModuleConfiguration extends ModuleBase implements ConfigurationProvider {
6475 double currentVBOMRQPercentage = 0.5 ;
6576 int currentVBOMRequestAge = 24 ; // in hours
6677 int currentVBOMDuration = 60 ; // in seconds
78+ int currentVUserPropertyCacheLimit = 100 ;
79+
80+ // FILTERS
81+ String currentVFilterPreset = "Blacklisting" ;
82+ Set <String > currentVEventFilterList = new HashSet <>();
83+ Set <String > currentVUserPropertyFilterList = new HashSet <>();
84+ Set <String > currentVSegmentationFilterList = new HashSet <>();
85+ Map <String , Set <String >> currentVEventSegmentationFilterList = new ConcurrentHashMap <>();
6786
6887 // SERVER CONFIGURATION PARAMS
6988 Integer serverConfigUpdateInterval ; // in hours
@@ -207,6 +226,8 @@ private void updateConfigVariables(@NonNull final CountlyConfig clyConfig) {
207226 currentVBOMRQPercentage = extractValue (keyRBOMRQPercentage , sb , currentVBOMRQPercentage , currentVBOMRQPercentage , Double .class , (Double value ) -> value > 0.0 && value < 1.0 );
208227 currentVBOMRequestAge = extractValue (keyRBOMRequestAge , sb , currentVBOMRequestAge , currentVBOMRequestAge , Integer .class , (Integer value ) -> value > 0 );
209228 currentVBOMDuration = extractValue (keyRBOMDuration , sb , currentVBOMDuration , currentVBOMDuration , Integer .class , (Integer value ) -> value > 0 );
229+ currentVUserPropertyCacheLimit = extractValue (keyRUserPropertyCacheLimit , sb , currentVUserPropertyCacheLimit , currentVUserPropertyCacheLimit , Integer .class , (Integer value ) -> value > 0 );
230+ currentVFilterPreset = extractValue (keyRFilterPreset , sb , currentVFilterPreset , currentVFilterPreset , String .class , (String value ) -> value .equals ("Blacklisting" ) || value .equals ("Whitelisting" ));
210231
211232 clyConfig .setMaxRequestQueueSize (extractValue (keyRReqQueueSize , sb , clyConfig .maxRequestQueueSize , clyConfig .maxRequestQueueSize , Integer .class , (Integer value ) -> value > 0 ));
212233 clyConfig .setEventQueueSizeToSend (extractValue (keyREventQueueSize , sb , clyConfig .eventQueueSizeThreshold , Countly .sharedInstance ().EVENT_QUEUE_SIZE_THRESHOLD , Integer .class , (Integer value ) -> value > 0 ));
@@ -222,13 +243,52 @@ private void updateConfigVariables(@NonNull final CountlyConfig clyConfig) {
222243 clyConfig .setRequiresConsent (extractValue (keyRConsentRequired , sb , clyConfig .shouldRequireConsent , clyConfig .shouldRequireConsent ));
223244 clyConfig .setRequestDropAgeHours (extractValue (keyRDropOldRequestTime , sb , clyConfig .dropAgeHours , clyConfig .dropAgeHours , Integer .class , (Integer value ) -> value >= 0 ));
224245
246+ updateListingFilters ();
247+
225248 String updatedValues = sb .toString ();
226249 if (!updatedValues .isEmpty ()) {
227250 L .i ("[ModuleConfiguration] updateConfigVariables, SDK configuration has changed, notifying the SDK, new values: [" + updatedValues + "]" );
228251 _cly .onSdkConfigurationChanged (clyConfig );
229252 }
230253 }
231254
255+ private void updateListingFilters () {
256+ JSONArray eventFilterListJSARR = latestRetrievedConfiguration .optJSONArray (keyREventFilterList );
257+ JSONArray userPropertyFilterListJSARR = latestRetrievedConfiguration .optJSONArray (keyRUserPropertyFilterList );
258+ JSONArray segmentationFilterListJSARR = latestRetrievedConfiguration .optJSONArray (keyRSegmentationFilterList );
259+ JSONObject eventSegmentationFilterListJSOBJ = latestRetrievedConfiguration .optJSONObject (keyREventSegmentationFilterList );
260+
261+ extractFilterSetFromJSONArray (eventFilterListJSARR , currentVEventFilterList );
262+ extractFilterSetFromJSONArray (userPropertyFilterListJSARR , currentVUserPropertyFilterList );
263+ extractFilterSetFromJSONArray (segmentationFilterListJSARR , currentVSegmentationFilterList );
264+ if (eventSegmentationFilterListJSOBJ != null ) {
265+ currentVEventSegmentationFilterList .clear ();
266+ Iterator <String > keys = eventSegmentationFilterListJSOBJ .keys ();
267+ while (keys .hasNext ()) {
268+ String key = keys .next ();
269+ JSONArray jsonArray = eventSegmentationFilterListJSOBJ .optJSONArray (key );
270+ if (jsonArray != null ) {
271+ Set <String > filterSet = new HashSet <>();
272+ extractFilterSetFromJSONArray (jsonArray , filterSet );
273+ currentVEventSegmentationFilterList .put (key , filterSet );
274+ }
275+ }
276+ }
277+ }
278+
279+ private void extractFilterSetFromJSONArray (@ Nullable JSONArray jsonArray , @ NonNull Set <String > targetSet ) {
280+ if (jsonArray == null ) {
281+ return ;
282+ }
283+ targetSet .clear ();
284+ for (int i = 0 ; i < jsonArray .length (); i ++) {
285+ String item = jsonArray .optString (i , null );
286+ if (item != null ) {
287+ targetSet .add (item );
288+ }
289+ }
290+ }
291+
232292 boolean validateServerConfig (@ NonNull JSONObject config ) {
233293 JSONObject newInner = config .optJSONObject (keyRConfig );
234294
@@ -293,6 +353,7 @@ private void removeUnsupportedKeys(@NonNull JSONObject newInner) {
293353 case keyRLimitBreadcrumb :
294354 case keyRLimitTraceLine :
295355 case keyRLimitTraceLength :
356+ case keyRUserPropertyCacheLimit :
296357 isValid = value instanceof Integer && ((Integer ) value ) > 0 ;
297358 break ;
298359
@@ -310,6 +371,19 @@ private void removeUnsupportedKeys(@NonNull JSONObject newInner) {
310371 case keyRBOMRQPercentage :
311372 isValid = value instanceof Double && ((Double ) value > 0.0 && (Double ) value < 1.0 );
312373 break ;
374+
375+ // --- Filtering keys ---
376+ case keyRFilterPreset :
377+ isValid = value instanceof String && (value .equals ("Blacklisting" ) || value .equals ("Whitelisting" ));
378+ break ;
379+ case keyREventFilterList :
380+ case keyRUserPropertyFilterList :
381+ case keyRSegmentationFilterList :
382+ isValid = value instanceof JSONArray ;
383+ break ;
384+ case keyREventSegmentationFilterList :
385+ isValid = value instanceof JSONObject ;
386+ break ;
313387 // --- Unknown keys ---
314388 default :
315389 L .w ("[ModuleConfiguration] removeUnsupportedKeys, Unknown key: [" + key + "], removing it. value: [" + value + "]" );
@@ -498,4 +572,28 @@ public boolean getTrackingEnabled() {
498572 @ Override public int getRequestTimeoutDurationMillis () {
499573 return _cly .config_ .requestTimeoutDuration * 1000 ;
500574 }
575+
576+ @ Override public int getUserPropertyCacheLimit () {
577+ return currentVUserPropertyCacheLimit ;
578+ }
579+
580+ @ Override public boolean getFilterIsWhitelist () {
581+ return currentVFilterPreset .equals ("Whitelisting" );
582+ }
583+
584+ @ Override public Set <String > getEventFilterSet () {
585+ return currentVEventFilterList ;
586+ }
587+
588+ @ Override public Set <String > getUserPropertyFilterSet () {
589+ return currentVUserPropertyFilterList ;
590+ }
591+
592+ @ Override public Set <String > getSegmentationFilterSet () {
593+ return currentVSegmentationFilterList ;
594+ }
595+
596+ @ Override public Map <String , Set <String >> getEventSegmentationFilterMap () {
597+ return currentVEventSegmentationFilterList ;
598+ }
501599}
0 commit comments