Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb88d64c authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Clean up toStatsDimensionsValueParcel" into rvc-dev am: f5550861

Change-Id: I5946f299f2efcb8e91a92d83ac4eeb19d6667734
parents 3eea5e81 f5550861
Loading
Loading
Loading
Loading
+47 −34
Original line number Original line Diff line number Diff line
@@ -40,53 +40,62 @@ const static int STATS_DIMENSIONS_VALUE_TUPLE_TYPE = 7;
 * Recursive helper function that populates a parent StatsDimensionsValueParcel
 * Recursive helper function that populates a parent StatsDimensionsValueParcel
 * with children StatsDimensionsValueParcels.
 * with children StatsDimensionsValueParcels.
 *
 *
 * \param parent parcel that will be populated with children
 * \param childDepth depth of children FieldValues
 * \param childPrefix expected FieldValue prefix of children
 * \param dims vector of FieldValues stored by HashableDimensionKey
 * \param dims vector of FieldValues stored by HashableDimensionKey
 * \param index positions in dims vector to start reading children from
 * \param index position in dims to start reading children from
 * \param depth level of parent parcel in the full StatsDimensionsValueParcel
 * tree
 */
 */
static void populateStatsDimensionsValueParcelChildren(StatsDimensionsValueParcel &parentParcel,
static void populateStatsDimensionsValueParcelChildren(StatsDimensionsValueParcel& parent,
                                                const vector<FieldValue>& dims, size_t& index,
                                                       int childDepth, int childPrefix,
                                                int depth, int prefix) {
                                                       const vector<FieldValue>& dims,
    while (index < dims.size()) {
                                                       size_t& index) {
        const FieldValue& dim = dims[index];
    if (childDepth > 2) {
        int fieldDepth = dim.mField.getDepth();
        int fieldPrefix = dim.mField.getPrefix(depth);
        StatsDimensionsValueParcel childParcel;
        childParcel.field = dim.mField.getPosAtDepth(depth);
        if (depth > 2) {
        ALOGE("Depth > 2 not supported by StatsDimensionsValueParcel.");
        ALOGE("Depth > 2 not supported by StatsDimensionsValueParcel.");
        return;
        return;
    }
    }
        if (depth == fieldDepth && prefix == fieldPrefix) {

    while (index < dims.size()) {
        const FieldValue& dim = dims[index];
        int fieldDepth = dim.mField.getDepth();
        int fieldPrefix = dim.mField.getPrefix(childDepth);

        StatsDimensionsValueParcel child;
        child.field = dim.mField.getPosAtDepth(childDepth);

        if (fieldDepth == childDepth && fieldPrefix == childPrefix) {
            switch (dim.mValue.getType()) {
            switch (dim.mValue.getType()) {
                case INT:
                case INT:
                    childParcel.valueType = STATS_DIMENSIONS_VALUE_INT_TYPE;
                    child.valueType = STATS_DIMENSIONS_VALUE_INT_TYPE;
                    childParcel.intValue = dim.mValue.int_value;
                    child.intValue = dim.mValue.int_value;
                    break;
                    break;
                case LONG:
                case LONG:
                    childParcel.valueType = STATS_DIMENSIONS_VALUE_LONG_TYPE;
                    child.valueType = STATS_DIMENSIONS_VALUE_LONG_TYPE;
                    childParcel.longValue = dim.mValue.long_value;
                    child.longValue = dim.mValue.long_value;
                    break;
                    break;
                case FLOAT:
                case FLOAT:
                    childParcel.valueType = STATS_DIMENSIONS_VALUE_FLOAT_TYPE;
                    child.valueType = STATS_DIMENSIONS_VALUE_FLOAT_TYPE;
                    childParcel.floatValue = dim.mValue.float_value;
                    child.floatValue = dim.mValue.float_value;
                    break;
                    break;
                case STRING:
                case STRING:
                    childParcel.valueType = STATS_DIMENSIONS_VALUE_STRING_TYPE;
                    child.valueType = STATS_DIMENSIONS_VALUE_STRING_TYPE;
                    childParcel.stringValue = dim.mValue.str_value;
                    child.stringValue = dim.mValue.str_value;
                    break;
                    break;
                default:
                default:
                    ALOGE("Encountered FieldValue with unsupported value type.");
                    ALOGE("Encountered FieldValue with unsupported value type.");
                    break;
                    break;
            }
            }
            index++;
            index++;
            parentParcel.tupleValue.push_back(childParcel);
            parent.tupleValue.push_back(child);
        } else if (fieldDepth > depth && fieldPrefix == prefix) {
        } else if (fieldDepth > childDepth && fieldPrefix == childPrefix) {
            childParcel.valueType = STATS_DIMENSIONS_VALUE_TUPLE_TYPE;
            // This FieldValue is not a child of the current parent, but it is
            populateStatsDimensionsValueParcelChildren(childParcel, dims, index, depth + 1,
            // an indirect descendant. Thus, create a direct child of TUPLE_TYPE
                                                       dim.mField.getPrefix(depth + 1));
            // and recurse to parcel the indirect descendants.
            parentParcel.tupleValue.push_back(childParcel);
            child.valueType = STATS_DIMENSIONS_VALUE_TUPLE_TYPE;
            populateStatsDimensionsValueParcelChildren(child, childDepth + 1,
                                                       dim.mField.getPrefix(childDepth + 1), dims,
                                                       index);
            parent.tupleValue.push_back(child);
        } else {
        } else {
            return;
            return;
        }
        }
@@ -94,17 +103,21 @@ static void populateStatsDimensionsValueParcelChildren(StatsDimensionsValueParce
}
}


StatsDimensionsValueParcel HashableDimensionKey::toStatsDimensionsValueParcel() const {
StatsDimensionsValueParcel HashableDimensionKey::toStatsDimensionsValueParcel() const {
    StatsDimensionsValueParcel parcel;
    StatsDimensionsValueParcel root;
    if (mValues.size() == 0) {
    if (mValues.size() == 0) {
        return parcel;
        return root;
    }
    }


    parcel.field = mValues[0].mField.getTag();
    root.field = mValues[0].mField.getTag();
    parcel.valueType = STATS_DIMENSIONS_VALUE_TUPLE_TYPE;
    root.valueType = STATS_DIMENSIONS_VALUE_TUPLE_TYPE;


    // Children of the root correspond to top-level (depth = 0) FieldValues.
    int childDepth = 0;
    int childPrefix = 0;
    size_t index = 0;
    size_t index = 0;
    populateStatsDimensionsValueParcelChildren(parcel, mValues, index, /*depth=*/0, /*prefix=*/0);
    populateStatsDimensionsValueParcelChildren(root, childDepth, childPrefix, mValues, index);
    return parcel;

    return root;
}
}


android::hash_t hashDimension(const HashableDimensionKey& value) {
android::hash_t hashDimension(const HashableDimensionKey& value) {