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

Commit 5c0e77d8 authored by Max Loh's avatar Max Loh
Browse files

Rollforward aslgen tests and more fields, fixing tests.

Changes: Added required version number in source xml, and changed purpose from set to list to remove chance of flakiness in verification.
Verified tests failed before change and were fixed after the change.

Bug: 329902686
Test: Unit tests.
Change-Id: I21c6247689fe6ca5577bf12ec971e992a9ace3aa
parent 6175aa77
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import com.android.asllib.util.MalformedXmlException;

import org.w3c.dom.Element;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@@ -28,7 +28,7 @@ public class DataCategoryFactory implements AslMarshallableFactory<DataCategory>
    @Override
    public DataCategory createFromHrElements(List<Element> elements) throws MalformedXmlException {
        String categoryName = null;
        Map<String, DataType> dataTypeMap = new HashMap<String, DataType>();
        Map<String, DataType> dataTypeMap = new LinkedHashMap<String, DataType>();
        for (Element ele : elements) {
            categoryName = ele.getAttribute(XmlUtils.HR_ATTR_DATA_CATEGORY);
            String dataTypeName = ele.getAttribute(XmlUtils.HR_ATTR_DATA_TYPE);
+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ import com.android.asllib.util.MalformedXmlException;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -93,7 +93,7 @@ public class DataLabelsFactory implements AslMarshallableFactory<DataLabels> {
    private static Map<String, DataCategory> getDataCategoriesWithTag(
            Element dataLabelsEle, String dataCategoryUsageTypeTag) throws MalformedXmlException {
        NodeList dataUsedNodeList = dataLabelsEle.getElementsByTagName(dataCategoryUsageTypeTag);
        Map<String, DataCategory> dataCategoryMap = new HashMap<String, DataCategory>();
        Map<String, DataCategory> dataCategoryMap = new LinkedHashMap<String, DataCategory>();

        Set<String> dataCategoryNames = new HashSet<String>();
        for (int i = 0; i < dataUsedNodeList.getLength(); i++) {
+7 −7
Original line number Diff line number Diff line
@@ -76,19 +76,19 @@ public class DataType implements AslMarshallable {

    private final String mDataTypeName;

    private final Set<Purpose> mPurposeSet;
    private final List<Purpose> mPurposes;
    private final Boolean mIsCollectionOptional;
    private final Boolean mIsSharingOptional;
    private final Boolean mEphemeral;

    public DataType(
            String dataTypeName,
            Set<Purpose> purposeSet,
            List<Purpose> purposes,
            Boolean isCollectionOptional,
            Boolean isSharingOptional,
            Boolean ephemeral) {
        this.mDataTypeName = dataTypeName;
        this.mPurposeSet = purposeSet;
        this.mPurposes = purposes;
        this.mIsCollectionOptional = isCollectionOptional;
        this.mIsSharingOptional = isSharingOptional;
        this.mEphemeral = ephemeral;
@@ -102,8 +102,8 @@ public class DataType implements AslMarshallable {
     * Returns {@link Set} of valid {@link Integer} purposes for using the associated data category
     * and type
     */
    public Set<Purpose> getPurposeSet() {
        return mPurposeSet;
    public List<Purpose> getPurposes() {
        return mPurposes;
    }

    /**
@@ -133,13 +133,13 @@ public class DataType implements AslMarshallable {
    @Override
    public List<Element> toOdDomElements(Document doc) {
        Element dataTypeEle = XmlUtils.createPbundleEleWithName(doc, this.getDataTypeName());
        if (!this.getPurposeSet().isEmpty()) {
        if (!this.getPurposes().isEmpty()) {
            dataTypeEle.appendChild(
                    XmlUtils.createOdArray(
                            doc,
                            XmlUtils.OD_TAG_INT_ARRAY,
                            XmlUtils.OD_NAME_PURPOSES,
                            this.getPurposeSet().stream()
                            this.getPurposes().stream()
                                    .map(p -> String.valueOf(p.getValue()))
                                    .toList()));
        }
+3 −3
Original line number Diff line number Diff line
@@ -29,16 +29,16 @@ public class DataTypeFactory implements AslMarshallableFactory<DataType> {
    public DataType createFromHrElements(List<Element> elements) {
        Element hrDataTypeEle = XmlUtils.getSingleElement(elements);
        String dataTypeName = hrDataTypeEle.getAttribute(XmlUtils.HR_ATTR_DATA_TYPE);
        Set<DataType.Purpose> purposeSet =
        List<DataType.Purpose> purposes =
                Arrays.stream(hrDataTypeEle.getAttribute(XmlUtils.HR_ATTR_PURPOSES).split("\\|"))
                        .map(DataType.Purpose::forString)
                        .collect(Collectors.toUnmodifiableSet());
                        .collect(Collectors.toList());
        Boolean isCollectionOptional =
                XmlUtils.getBoolAttr(hrDataTypeEle, XmlUtils.HR_ATTR_IS_COLLECTION_OPTIONAL);
        Boolean isSharingOptional =
                XmlUtils.getBoolAttr(hrDataTypeEle, XmlUtils.HR_ATTR_IS_SHARING_OPTIONAL);
        Boolean ephemeral = XmlUtils.getBoolAttr(hrDataTypeEle, XmlUtils.HR_ATTR_EPHEMERAL);
        return new DataType(
                dataTypeName, purposeSet, isCollectionOptional, isSharingOptional, ephemeral);
                dataTypeName, purposes, isCollectionOptional, isSharingOptional, ephemeral);
    }
}
+1 −1
Original line number Diff line number Diff line
<app-metadata-bundles>
<app-metadata-bundles version="123">
    <safety-labels version="12345">
        <data-labels>
            <data-shared dataCategory="contacts"
Loading