Change condition init to return current condition
To allow initialization of conditions to work for both config creation
and update, have init always fill the conditionCache with the current
condition.
For sliced dimensions, it should compute an OR over all dimensions,
returning true if any of the dimensions are true.
We can use this for setting the initial value of new combination
conditions that depend on existing initial conditions, or for new
metrics that depend on existing conditions.
Test: atest statsd_test. Existing tests pass, will add more for the
update path in the update for condition cl.
Bug: 162322841
Change-Id: Ib48479269828f2e071c5c46aba1129d52d4725de
diff --git a/cmds/statsd/src/condition/SimpleConditionTracker.cpp b/cmds/statsd/src/condition/SimpleConditionTracker.cpp
index efb4d49..f45759b 100644
--- a/cmds/statsd/src/condition/SimpleConditionTracker.cpp
+++ b/cmds/statsd/src/condition/SimpleConditionTracker.cpp
@@ -95,11 +95,14 @@
 bool SimpleConditionTracker::init(const vector<Predicate>& allConditionConfig,
                                   const vector<sp<ConditionTracker>>& allConditionTrackers,
                                   const unordered_map<int64_t, int>& conditionIdIndexMap,
-                                  vector<bool>& stack,
-                                  vector<ConditionState>& initialConditionCache) {
+                                  vector<bool>& stack, vector<ConditionState>& conditionCache) {
     // SimpleConditionTracker does not have dependency on other conditions, thus we just return
     // if the initialization was successful.
-    initialConditionCache[mIndex] = mInitialValue;
+    ConditionKey conditionKey;
+    if (mSliced) {
+        conditionKey[mConditionId] = DEFAULT_DIMENSION_KEY;
+    }
+    isConditionMet(conditionKey, allConditionTrackers, mSliced, conditionCache);
     return mInitialized;
 }