Loading tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslConverter.java +8 −4 Original line number Diff line number Diff line Loading @@ -65,8 +65,10 @@ public class AslConverter { return new AndroidSafetyLabelFactory() .createFromHrElements(XmlUtils.listOf(appMetadataBundles)); case ON_DEVICE: throw new IllegalArgumentException( "Parsing from on-device format is not supported at this time."); Element bundleEle = XmlUtils.getSingleChildElement(document, XmlUtils.OD_TAG_BUNDLE, true); return new AndroidSafetyLabelFactory() .createFromOdElements(XmlUtils.listOf(bundleEle)); default: throw new IllegalStateException("Unrecognized input format."); } Loading @@ -89,8 +91,10 @@ public class AslConverter { switch (format) { case HUMAN_READABLE: throw new IllegalArgumentException( "Outputting human-readable format is not supported at this time."); for (var child : asl.toHrDomElements(document)) { document.appendChild(child); } break; case ON_DEVICE: for (var child : asl.toOdDomElements(document)) { document.appendChild(child); Loading tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabel.java +12 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,17 @@ public class AndroidSafetyLabel implements AslMarshallable { /** Creates the human-readable DOM elements from the AslMarshallable Java Object. */ @Override public List<Element> toHrDomElements(Document doc) { return List.of(); Element aslEle = doc.createElement(XmlUtils.HR_TAG_APP_METADATA_BUNDLES); aslEle.setAttribute(XmlUtils.HR_ATTR_VERSION, String.valueOf(mVersion)); if (mSafetyLabels != null) { XmlUtils.appendChildren(aslEle, mSafetyLabels.toHrDomElements(doc)); } if (mSystemAppSafetyLabel != null) { XmlUtils.appendChildren(aslEle, mSystemAppSafetyLabel.toHrDomElements(doc)); } if (mTransparencyInfo != null) { XmlUtils.appendChildren(aslEle, mTransparencyInfo.toHrDomElements(doc)); } return XmlUtils.listOf(aslEle); } } tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabelFactory.java +24 −2 Original line number Diff line number Diff line Loading @@ -56,10 +56,32 @@ public class AndroidSafetyLabelFactory implements AslMarshallableFactory<Android version, systemAppSafetyLabel, safetyLabels, transparencyInfo); } /** Creates an {@link AslMarshallableFactory} from on-device DOM elements */ /** Creates an {@link AndroidSafetyLabel} from on-device DOM elements */ @Override public AndroidSafetyLabel createFromOdElements(List<Element> elements) throws MalformedXmlException { return null; Element bundleEle = XmlUtils.getSingleElement(elements); Long version = XmlUtils.getOdLongEle(bundleEle, XmlUtils.OD_NAME_VERSION, true); Element safetyLabelsEle = XmlUtils.getOdPbundleWithName(bundleEle, XmlUtils.OD_NAME_SAFETY_LABELS, false); SafetyLabels safetyLabels = new SafetyLabelsFactory().createFromOdElements(XmlUtils.listOf(safetyLabelsEle)); Element systemAppSafetyLabelEle = XmlUtils.getOdPbundleWithName( bundleEle, XmlUtils.OD_NAME_SYSTEM_APP_SAFETY_LABEL, false); SystemAppSafetyLabel systemAppSafetyLabel = new SystemAppSafetyLabelFactory() .createFromOdElements(XmlUtils.listOf(systemAppSafetyLabelEle)); Element transparencyInfoEle = XmlUtils.getOdPbundleWithName(bundleEle, XmlUtils.OD_NAME_TRANSPARENCY_INFO, false); TransparencyInfo transparencyInfo = new TransparencyInfoFactory() .createFromOdElements(XmlUtils.listOf(transparencyInfoEle)); return new AndroidSafetyLabel( version, systemAppSafetyLabel, safetyLabels, transparencyInfo); } } tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfo.java +50 −1 Original line number Diff line number Diff line Loading @@ -146,6 +146,55 @@ public class AppInfo implements AslMarshallable { /** Creates the human-readable DOM elements from the AslMarshallable Java Object. */ @Override public List<Element> toHrDomElements(Document doc) { return List.of(); Element appInfoEle = doc.createElement(XmlUtils.HR_TAG_APP_INFO); if (this.mTitle != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_TITLE, this.mTitle); } if (this.mDescription != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_DESCRIPTION, this.mDescription); } if (this.mContainsAds != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_CONTAINS_ADS, String.valueOf(this.mContainsAds)); } if (this.mObeyAps != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_OBEY_APS, String.valueOf(this.mObeyAps)); } if (this.mAdsFingerprinting != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_ADS_FINGERPRINTING, String.valueOf(this.mAdsFingerprinting)); } if (this.mSecurityFingerprinting != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_SECURITY_FINGERPRINTING, String.valueOf(this.mSecurityFingerprinting)); } if (this.mPrivacyPolicy != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_PRIVACY_POLICY, this.mPrivacyPolicy); } if (this.mSecurityEndpoints != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_SECURITY_ENDPOINTS, String.join("|", this.mSecurityEndpoints)); } if (this.mFirstPartyEndpoints != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_FIRST_PARTY_ENDPOINTS, String.join("|", this.mFirstPartyEndpoints)); } if (this.mServiceProviderEndpoints != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_SERVICE_PROVIDER_ENDPOINTS, String.join("|", this.mServiceProviderEndpoints)); } if (this.mCategory != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_CATEGORY, this.mCategory); } if (this.mEmail != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_EMAIL, this.mEmail); } if (this.mWebsite != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_WEBSITE, this.mWebsite); } return XmlUtils.listOf(appInfoEle); } } tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfoFactory.java +49 −6 Original line number Diff line number Diff line Loading @@ -35,15 +35,16 @@ public class AppInfoFactory implements AslMarshallableFactory<AppInfo> { return null; } String title = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_TITLE); String description = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_DESCRIPTION); String title = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_TITLE, true); String description = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_DESCRIPTION, true); Boolean containsAds = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_CONTAINS_ADS, true); Boolean obeyAps = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_OBEY_APS, true); Boolean adsFingerprinting = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_ADS_FINGERPRINTING, true); Boolean securityFingerprinting = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_SECURITY_FINGERPRINTING, true); String privacyPolicy = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_PRIVACY_POLICY); String privacyPolicy = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_PRIVACY_POLICY, true); List<String> securityEndpoints = XmlUtils.getPipelineSplitAttr( appInfoEle, XmlUtils.HR_ATTR_SECURITY_ENDPOINTS, true); Loading @@ -53,8 +54,8 @@ public class AppInfoFactory implements AslMarshallableFactory<AppInfo> { List<String> serviceProviderEndpoints = XmlUtils.getPipelineSplitAttr( appInfoEle, XmlUtils.HR_ATTR_SERVICE_PROVIDER_ENDPOINTS, true); String category = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_CATEGORY); String email = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_EMAIL); String category = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_CATEGORY, true); String email = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_EMAIL, true); String website = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_WEBSITE, false); return new AppInfo( Loading @@ -76,6 +77,48 @@ public class AppInfoFactory implements AslMarshallableFactory<AppInfo> { /** Creates an {@link AslMarshallableFactory} from on-device DOM elements */ @Override public AppInfo createFromOdElements(List<Element> elements) throws MalformedXmlException { Element appInfoEle = XmlUtils.getSingleElement(elements); if (appInfoEle == null) { AslgenUtil.logI("No AppInfo found in od format."); return null; } String title = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_TITLE, true); String description = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_DESCRIPTION, true); Boolean containsAds = XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_CONTAINS_ADS, true); Boolean obeyAps = XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_OBEY_APS, true); Boolean adsFingerprinting = XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_ADS_FINGERPRINTING, true); Boolean securityFingerprinting = XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_SECURITY_FINGERPRINTING, true); String privacyPolicy = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_PRIVACY_POLICY, true); List<String> securityEndpoints = XmlUtils.getOdStringArray(appInfoEle, XmlUtils.OD_NAME_SECURITY_ENDPOINT, true); List<String> firstPartyEndpoints = XmlUtils.getOdStringArray(appInfoEle, XmlUtils.OD_NAME_FIRST_PARTY_ENDPOINT, true); List<String> serviceProviderEndpoints = XmlUtils.getOdStringArray( appInfoEle, XmlUtils.OD_NAME_SERVICE_PROVIDER_ENDPOINT, true); String category = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_CATEGORY, true); String email = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_EMAIL, true); String website = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_WEBSITE, false); return new AppInfo( title, description, containsAds, obeyAps, adsFingerprinting, securityFingerprinting, privacyPolicy, securityEndpoints, firstPartyEndpoints, serviceProviderEndpoints, category, email, website); } } Loading
tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslConverter.java +8 −4 Original line number Diff line number Diff line Loading @@ -65,8 +65,10 @@ public class AslConverter { return new AndroidSafetyLabelFactory() .createFromHrElements(XmlUtils.listOf(appMetadataBundles)); case ON_DEVICE: throw new IllegalArgumentException( "Parsing from on-device format is not supported at this time."); Element bundleEle = XmlUtils.getSingleChildElement(document, XmlUtils.OD_TAG_BUNDLE, true); return new AndroidSafetyLabelFactory() .createFromOdElements(XmlUtils.listOf(bundleEle)); default: throw new IllegalStateException("Unrecognized input format."); } Loading @@ -89,8 +91,10 @@ public class AslConverter { switch (format) { case HUMAN_READABLE: throw new IllegalArgumentException( "Outputting human-readable format is not supported at this time."); for (var child : asl.toHrDomElements(document)) { document.appendChild(child); } break; case ON_DEVICE: for (var child : asl.toOdDomElements(document)) { document.appendChild(child); Loading
tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabel.java +12 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,17 @@ public class AndroidSafetyLabel implements AslMarshallable { /** Creates the human-readable DOM elements from the AslMarshallable Java Object. */ @Override public List<Element> toHrDomElements(Document doc) { return List.of(); Element aslEle = doc.createElement(XmlUtils.HR_TAG_APP_METADATA_BUNDLES); aslEle.setAttribute(XmlUtils.HR_ATTR_VERSION, String.valueOf(mVersion)); if (mSafetyLabels != null) { XmlUtils.appendChildren(aslEle, mSafetyLabels.toHrDomElements(doc)); } if (mSystemAppSafetyLabel != null) { XmlUtils.appendChildren(aslEle, mSystemAppSafetyLabel.toHrDomElements(doc)); } if (mTransparencyInfo != null) { XmlUtils.appendChildren(aslEle, mTransparencyInfo.toHrDomElements(doc)); } return XmlUtils.listOf(aslEle); } }
tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabelFactory.java +24 −2 Original line number Diff line number Diff line Loading @@ -56,10 +56,32 @@ public class AndroidSafetyLabelFactory implements AslMarshallableFactory<Android version, systemAppSafetyLabel, safetyLabels, transparencyInfo); } /** Creates an {@link AslMarshallableFactory} from on-device DOM elements */ /** Creates an {@link AndroidSafetyLabel} from on-device DOM elements */ @Override public AndroidSafetyLabel createFromOdElements(List<Element> elements) throws MalformedXmlException { return null; Element bundleEle = XmlUtils.getSingleElement(elements); Long version = XmlUtils.getOdLongEle(bundleEle, XmlUtils.OD_NAME_VERSION, true); Element safetyLabelsEle = XmlUtils.getOdPbundleWithName(bundleEle, XmlUtils.OD_NAME_SAFETY_LABELS, false); SafetyLabels safetyLabels = new SafetyLabelsFactory().createFromOdElements(XmlUtils.listOf(safetyLabelsEle)); Element systemAppSafetyLabelEle = XmlUtils.getOdPbundleWithName( bundleEle, XmlUtils.OD_NAME_SYSTEM_APP_SAFETY_LABEL, false); SystemAppSafetyLabel systemAppSafetyLabel = new SystemAppSafetyLabelFactory() .createFromOdElements(XmlUtils.listOf(systemAppSafetyLabelEle)); Element transparencyInfoEle = XmlUtils.getOdPbundleWithName(bundleEle, XmlUtils.OD_NAME_TRANSPARENCY_INFO, false); TransparencyInfo transparencyInfo = new TransparencyInfoFactory() .createFromOdElements(XmlUtils.listOf(transparencyInfoEle)); return new AndroidSafetyLabel( version, systemAppSafetyLabel, safetyLabels, transparencyInfo); } }
tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfo.java +50 −1 Original line number Diff line number Diff line Loading @@ -146,6 +146,55 @@ public class AppInfo implements AslMarshallable { /** Creates the human-readable DOM elements from the AslMarshallable Java Object. */ @Override public List<Element> toHrDomElements(Document doc) { return List.of(); Element appInfoEle = doc.createElement(XmlUtils.HR_TAG_APP_INFO); if (this.mTitle != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_TITLE, this.mTitle); } if (this.mDescription != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_DESCRIPTION, this.mDescription); } if (this.mContainsAds != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_CONTAINS_ADS, String.valueOf(this.mContainsAds)); } if (this.mObeyAps != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_OBEY_APS, String.valueOf(this.mObeyAps)); } if (this.mAdsFingerprinting != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_ADS_FINGERPRINTING, String.valueOf(this.mAdsFingerprinting)); } if (this.mSecurityFingerprinting != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_SECURITY_FINGERPRINTING, String.valueOf(this.mSecurityFingerprinting)); } if (this.mPrivacyPolicy != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_PRIVACY_POLICY, this.mPrivacyPolicy); } if (this.mSecurityEndpoints != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_SECURITY_ENDPOINTS, String.join("|", this.mSecurityEndpoints)); } if (this.mFirstPartyEndpoints != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_FIRST_PARTY_ENDPOINTS, String.join("|", this.mFirstPartyEndpoints)); } if (this.mServiceProviderEndpoints != null) { appInfoEle.setAttribute( XmlUtils.HR_ATTR_SERVICE_PROVIDER_ENDPOINTS, String.join("|", this.mServiceProviderEndpoints)); } if (this.mCategory != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_CATEGORY, this.mCategory); } if (this.mEmail != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_EMAIL, this.mEmail); } if (this.mWebsite != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_WEBSITE, this.mWebsite); } return XmlUtils.listOf(appInfoEle); } }
tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfoFactory.java +49 −6 Original line number Diff line number Diff line Loading @@ -35,15 +35,16 @@ public class AppInfoFactory implements AslMarshallableFactory<AppInfo> { return null; } String title = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_TITLE); String description = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_DESCRIPTION); String title = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_TITLE, true); String description = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_DESCRIPTION, true); Boolean containsAds = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_CONTAINS_ADS, true); Boolean obeyAps = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_OBEY_APS, true); Boolean adsFingerprinting = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_ADS_FINGERPRINTING, true); Boolean securityFingerprinting = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_SECURITY_FINGERPRINTING, true); String privacyPolicy = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_PRIVACY_POLICY); String privacyPolicy = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_PRIVACY_POLICY, true); List<String> securityEndpoints = XmlUtils.getPipelineSplitAttr( appInfoEle, XmlUtils.HR_ATTR_SECURITY_ENDPOINTS, true); Loading @@ -53,8 +54,8 @@ public class AppInfoFactory implements AslMarshallableFactory<AppInfo> { List<String> serviceProviderEndpoints = XmlUtils.getPipelineSplitAttr( appInfoEle, XmlUtils.HR_ATTR_SERVICE_PROVIDER_ENDPOINTS, true); String category = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_CATEGORY); String email = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_EMAIL); String category = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_CATEGORY, true); String email = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_EMAIL, true); String website = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_WEBSITE, false); return new AppInfo( Loading @@ -76,6 +77,48 @@ public class AppInfoFactory implements AslMarshallableFactory<AppInfo> { /** Creates an {@link AslMarshallableFactory} from on-device DOM elements */ @Override public AppInfo createFromOdElements(List<Element> elements) throws MalformedXmlException { Element appInfoEle = XmlUtils.getSingleElement(elements); if (appInfoEle == null) { AslgenUtil.logI("No AppInfo found in od format."); return null; } String title = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_TITLE, true); String description = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_DESCRIPTION, true); Boolean containsAds = XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_CONTAINS_ADS, true); Boolean obeyAps = XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_OBEY_APS, true); Boolean adsFingerprinting = XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_ADS_FINGERPRINTING, true); Boolean securityFingerprinting = XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_SECURITY_FINGERPRINTING, true); String privacyPolicy = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_PRIVACY_POLICY, true); List<String> securityEndpoints = XmlUtils.getOdStringArray(appInfoEle, XmlUtils.OD_NAME_SECURITY_ENDPOINT, true); List<String> firstPartyEndpoints = XmlUtils.getOdStringArray(appInfoEle, XmlUtils.OD_NAME_FIRST_PARTY_ENDPOINT, true); List<String> serviceProviderEndpoints = XmlUtils.getOdStringArray( appInfoEle, XmlUtils.OD_NAME_SERVICE_PROVIDER_ENDPOINT, true); String category = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_CATEGORY, true); String email = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_EMAIL, true); String website = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_WEBSITE, false); return new AppInfo( title, description, containsAds, obeyAps, adsFingerprinting, securityFingerprinting, privacyPolicy, securityEndpoints, firstPartyEndpoints, serviceProviderEndpoints, category, email, website); } }