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

Commit ba7eba9c authored by Max Loh's avatar Max Loh Committed by Android (Google) Code Review
Browse files

Merge "aslgen implement security labels and third party verification" into main

parents 159d436b 58f7d34b
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -28,10 +28,18 @@ public class SafetyLabels implements AslMarshallable {

    private final Long mVersion;
    private final DataLabels mDataLabels;
    private final SecurityLabels mSecurityLabels;
    private final ThirdPartyVerification mThirdPartyVerification;

    public SafetyLabels(Long version, DataLabels dataLabels) {
    public SafetyLabels(
            Long version,
            DataLabels dataLabels,
            SecurityLabels securityLabels,
            ThirdPartyVerification thirdPartyVerification) {
        this.mVersion = version;
        this.mDataLabels = dataLabels;
        this.mSecurityLabels = securityLabels;
        this.mThirdPartyVerification = thirdPartyVerification;
    }

    /** Returns the data label for the safety label */
@@ -54,6 +62,12 @@ public class SafetyLabels implements AslMarshallable {
        if (mDataLabels != null) {
            XmlUtils.appendChildren(safetyLabelsEle, mDataLabels.toOdDomElements(doc));
        }
        if (mSecurityLabels != null) {
            XmlUtils.appendChildren(safetyLabelsEle, mSecurityLabels.toOdDomElements(doc));
        }
        if (mThirdPartyVerification != null) {
            XmlUtils.appendChildren(safetyLabelsEle, mThirdPartyVerification.toOdDomElements(doc));
        }
        return XmlUtils.listOf(safetyLabelsEle);
    }
}
+17 −1
Original line number Diff line number Diff line
@@ -44,6 +44,22 @@ public class SafetyLabelsFactory implements AslMarshallableFactory<SafetyLabels>
                                                safetyLabelsEle,
                                                XmlUtils.HR_TAG_DATA_LABELS,
                                                false)));
        return new SafetyLabels(version, dataLabels);
        SecurityLabels securityLabels =
                new SecurityLabelsFactory()
                        .createFromHrElements(
                                XmlUtils.listOf(
                                        XmlUtils.getSingleChildElement(
                                                safetyLabelsEle,
                                                XmlUtils.HR_TAG_SECURITY_LABELS,
                                                false)));
        ThirdPartyVerification thirdPartyVerification =
                new ThirdPartyVerificationFactory()
                        .createFromHrElements(
                                XmlUtils.listOf(
                                        XmlUtils.getSingleChildElement(
                                                safetyLabelsEle,
                                                XmlUtils.HR_TAG_THIRD_PARTY_VERIFICATION,
                                                false)));
        return new SafetyLabels(version, dataLabels, securityLabels, thirdPartyVerification);
    }
}
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.asllib.marshallable;

import com.android.asllib.util.XmlUtils;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import java.util.List;

/** Security Labels representation */
public class SecurityLabels implements AslMarshallable {

    private final Boolean mIsDataDeletable;
    private final Boolean mIsDataEncrypted;

    public SecurityLabels(Boolean isDataDeletable, Boolean isDataEncrypted) {
        this.mIsDataDeletable = isDataDeletable;
        this.mIsDataEncrypted = isDataEncrypted;
    }

    /** Creates an on-device DOM element from the {@link SecurityLabels}. */
    @Override
    public List<Element> toOdDomElements(Document doc) {
        Element ele = XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_SECURITY_LABELS);
        if (mIsDataDeletable != null) {
            ele.appendChild(
                    XmlUtils.createOdBooleanEle(
                            doc, XmlUtils.OD_NAME_IS_DATA_DELETABLE, mIsDataDeletable));
        }
        if (mIsDataEncrypted != null) {
            ele.appendChild(
                    XmlUtils.createOdBooleanEle(
                            doc, XmlUtils.OD_NAME_IS_DATA_ENCRYPTED, mIsDataEncrypted));
        }
        return XmlUtils.listOf(ele);
    }
}
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.asllib.marshallable;

import com.android.asllib.util.AslgenUtil;
import com.android.asllib.util.MalformedXmlException;
import com.android.asllib.util.XmlUtils;

import org.w3c.dom.Element;

import java.util.List;

public class SecurityLabelsFactory implements AslMarshallableFactory<SecurityLabels> {

    /** Creates a {@link SecurityLabels} from the human-readable DOM element. */
    @Override
    public SecurityLabels createFromHrElements(List<Element> elements)
            throws MalformedXmlException {
        Element ele = XmlUtils.getSingleElement(elements);
        if (ele == null) {
            AslgenUtil.logI("No SecurityLabels found in hr format.");
            return null;
        }
        Boolean isDataDeletable =
                XmlUtils.getBoolAttr(ele, XmlUtils.HR_ATTR_IS_DATA_DELETABLE, false);
        Boolean isDataEncrypted =
                XmlUtils.getBoolAttr(ele, XmlUtils.HR_ATTR_IS_DATA_ENCRYPTED, false);
        return new SecurityLabels(isDataDeletable, isDataEncrypted);
    }
}
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.asllib.marshallable;

import com.android.asllib.util.XmlUtils;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import java.util.List;

/** ThirdPartyVerification representation. */
public class ThirdPartyVerification implements AslMarshallable {

    private final String mUrl;

    public ThirdPartyVerification(String url) {
        this.mUrl = url;
    }

    /** Creates an on-device DOM element from the {@link ThirdPartyVerification}. */
    @Override
    public List<Element> toOdDomElements(Document doc) {
        Element ele =
                XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_THIRD_PARTY_VERIFICATION);
        ele.appendChild(XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_URL, mUrl));
        return XmlUtils.listOf(ele);
    }
}
Loading