From 2a7084f906021cf5b53d1b6fec762db6ce9ebac8 Mon Sep 17 00:00:00 2001 From: Max Loh Date: Thu, 28 Mar 2024 08:00:16 -0700 Subject: aslgen unit tests Bug: 329902686 Test: Unit tests. Change-Id: I443353c88c18808a4a4491b617bdb8a7f990c908 --- tools/app_metadata_bundles/Android.bp | 3 + .../com/android/asllib/AndroidSafetyLabel.java | 62 ---- .../android/asllib/AndroidSafetyLabelFactory.java | 57 ---- .../src/lib/java/com/android/asllib/AppInfo.java | 143 --------- .../java/com/android/asllib/AppInfoFactory.java | 84 ------ .../lib/java/com/android/asllib/AslConverter.java | 3 + .../java/com/android/asllib/AslMarshallable.java | 28 -- .../com/android/asllib/AslMarshallableFactory.java | 29 -- .../lib/java/com/android/asllib/DataCategory.java | 58 ---- .../com/android/asllib/DataCategoryConstants.java | 74 ----- .../com/android/asllib/DataCategoryFactory.java | 45 --- .../lib/java/com/android/asllib/DataLabels.java | 101 ------- .../java/com/android/asllib/DataLabelsFactory.java | 122 -------- .../src/lib/java/com/android/asllib/DataType.java | 169 ----------- .../java/com/android/asllib/DataTypeConstants.java | 156 ---------- .../java/com/android/asllib/DataTypeFactory.java | 44 --- .../lib/java/com/android/asllib/DeveloperInfo.java | 140 --------- .../com/android/asllib/DeveloperInfoFactory.java | 59 ---- .../lib/java/com/android/asllib/SafetyLabels.java | 57 ---- .../com/android/asllib/SafetyLabelsFactory.java | 46 --- .../com/android/asllib/SystemAppSafetyLabel.java | 47 --- .../asllib/SystemAppSafetyLabelFactory.java | 41 --- .../java/com/android/asllib/TransparencyInfo.java | 58 ---- .../android/asllib/TransparencyInfoFactory.java | 51 ---- .../src/lib/java/com/android/asllib/XmlUtils.java | 308 ------------------- .../asllib/marshallable/AndroidSafetyLabel.java | 64 ++++ .../marshallable/AndroidSafetyLabelFactory.java | 58 ++++ .../com/android/asllib/marshallable/AppInfo.java | 145 +++++++++ .../asllib/marshallable/AppInfoFactory.java | 75 +++++ .../asllib/marshallable/AslMarshallable.java | 28 ++ .../marshallable/AslMarshallableFactory.java | 29 ++ .../android/asllib/marshallable/DataCategory.java | 62 ++++ .../asllib/marshallable/DataCategoryFactory.java | 53 ++++ .../android/asllib/marshallable/DataLabels.java | 103 +++++++ .../asllib/marshallable/DataLabelsFactory.java | 124 ++++++++ .../com/android/asllib/marshallable/DataType.java | 171 +++++++++++ .../asllib/marshallable/DataTypeFactory.java | 54 ++++ .../android/asllib/marshallable/DeveloperInfo.java | 142 +++++++++ .../asllib/marshallable/DeveloperInfoFactory.java | 60 ++++ .../android/asllib/marshallable/SafetyLabels.java | 59 ++++ .../asllib/marshallable/SafetyLabelsFactory.java | 49 +++ .../asllib/marshallable/SystemAppSafetyLabel.java | 49 +++ .../marshallable/SystemAppSafetyLabelFactory.java | 42 +++ .../asllib/marshallable/TransparencyInfo.java | 60 ++++ .../marshallable/TransparencyInfoFactory.java | 52 ++++ .../android/asllib/util/DataCategoryConstants.java | 77 +++++ .../com/android/asllib/util/DataTypeConstants.java | 197 +++++++++++++ .../lib/java/com/android/asllib/util/XmlUtils.java | 327 +++++++++++++++++++++ .../src/test/java/com/android/aslgen/AllTests.java | 26 -- .../test/java/com/android/aslgen/AslgenTests.java | 105 ------- .../src/test/java/com/android/asllib/AllTests.java | 35 +++ .../test/java/com/android/asllib/AslgenTests.java | 72 +++++ .../marshallable/AndroidSafetyLabelTest.java | 97 ++++++ .../android/asllib/marshallable/AppInfoTest.java | 107 +++++++ .../asllib/marshallable/DataCategoryTest.java | 216 ++++++++++++++ .../asllib/marshallable/DataLabelsTest.java | 102 +++++++ .../asllib/marshallable/DeveloperInfoTest.java | 100 +++++++ .../asllib/marshallable/SafetyLabelsTest.java | 77 +++++ .../marshallable/SystemAppSafetyLabelTest.java | 75 +++++ .../asllib/marshallable/TransparencyInfoTest.java | 75 +++++ .../com/android/asllib/testutils/TestUtils.java | 152 ++++++++++ .../android/aslgen/validmappings/contacts/hr.xml | 11 - .../android/aslgen/validmappings/contacts/od.xml | 19 -- .../android/aslgen/validmappings/location/hr.xml | 16 - .../android/aslgen/validmappings/location/od.xml | 27 -- .../androidsafetylabel/hr/missing-version.xml | 3 + .../asllib/androidsafetylabel/hr/valid-empty.xml | 1 + .../androidsafetylabel/hr/with-safety-labels.xml | 4 + .../hr/with-system-app-safety-label.xml | 4 + .../hr/with-transparency-info.xml | 4 + .../asllib/androidsafetylabel/od/valid-empty.xml | 3 + .../androidsafetylabel/od/with-safety-labels.xml | 6 + .../od/with-system-app-safety-label.xml | 6 + .../od/with-transparency-info.xml | 4 + .../android/asllib/appinfo/hr/all-fields-valid.xml | 14 + .../android/asllib/appinfo/od/all-fields-valid.xml | 25 ++ .../hr/data-category-actions-in-app.xml | 17 ++ .../hr/data-category-app-performance.xml | 11 + .../asllib/datacategory/hr/data-category-audio.xml | 11 + .../datacategory/hr/data-category-calendar.xml | 5 + .../datacategory/hr/data-category-contacts.xml | 5 + .../hr/data-category-email-text-message.xml | 11 + .../datacategory/hr/data-category-financial.xml | 14 + .../hr/data-category-health-fitness.xml | 8 + .../datacategory/hr/data-category-identifiers.xml | 5 + .../datacategory/hr/data-category-location.xml | 8 + .../hr/data-category-personal-empty-purpose.xml | 5 + .../hr/data-category-personal-missing-purpose.xml | 4 + .../hr/data-category-personal-partial.xml | 8 + .../data-category-personal-unrecognized-type.xml | 5 + .../datacategory/hr/data-category-personal.xml | 31 ++ .../datacategory/hr/data-category-photo-video.xml | 8 + .../hr/data-category-search-and-browsing.xml | 5 + .../datacategory/hr/data-category-storage.xml | 5 + .../datacategory/hr/data-category-unrecognized.xml | 5 + .../od/data-category-actions-in-app.xml | 27 ++ .../od/data-category-app-performance.xml | 17 ++ .../asllib/datacategory/od/data-category-audio.xml | 17 ++ .../datacategory/od/data-category-calendar.xml | 7 + .../datacategory/od/data-category-contacts.xml | 7 + .../od/data-category-email-text-message.xml | 17 ++ .../datacategory/od/data-category-financial.xml | 22 ++ .../od/data-category-health-fitness.xml | 12 + .../datacategory/od/data-category-identifiers.xml | 7 + .../datacategory/od/data-category-location.xml | 12 + .../od/data-category-personal-partial.xml | 13 + .../datacategory/od/data-category-personal.xml | 50 ++++ .../datacategory/od/data-category-photo-video.xml | 12 + .../od/data-category-search-and-browsing.xml | 7 + .../datacategory/od/data-category-storage.xml | 7 + .../hr/data-labels-accessed-invalid-bool.xml | 7 + .../hr/data-labels-accessed-valid-bool.xml | 6 + .../hr/data-labels-collected-invalid-bool.xml | 7 + .../hr/data-labels-collected-valid-bool.xml | 7 + .../hr/data-labels-shared-invalid-bool.xml | 7 + .../hr/data-labels-shared-valid-bool.xml | 7 + .../od/data-labels-accessed-valid-bool.xml | 12 + .../od/data-labels-collected-valid-bool.xml | 13 + .../od/data-labels-shared-valid-bool.xml | 13 + .../asllib/developerinfo/hr/all-fields-valid.xml | 8 + .../asllib/developerinfo/od/all-fields-valid.xml | 9 + .../asllib/safetylabels/hr/missing-version.xml | 2 + .../android/asllib/safetylabels/hr/valid-empty.xml | 1 + .../asllib/safetylabels/hr/with-data-labels.xml | 9 + .../android/asllib/safetylabels/od/valid-empty.xml | 3 + .../asllib/safetylabels/od/with-data-labels.xml | 16 + .../asllib/systemappsafetylabel/hr/missing-url.xml | 1 + .../asllib/systemappsafetylabel/hr/valid.xml | 1 + .../asllib/systemappsafetylabel/od/valid.xml | 3 + .../asllib/transparencyinfo/hr/valid-empty.xml | 4 + .../asllib/transparencyinfo/hr/with-app-info.xml | 4 + .../transparencyinfo/hr/with-developer-info.xml | 11 + .../asllib/transparencyinfo/od/valid-empty.xml | 1 + .../asllib/transparencyinfo/od/with-app-info.xml | 26 ++ .../transparencyinfo/od/with-developer-info.xml | 11 + .../android/asllib/validmappings/contacts/hr.xml | 11 + .../android/asllib/validmappings/contacts/od.xml | 19 ++ .../android/asllib/validmappings/location/hr.xml | 16 + .../android/asllib/validmappings/location/od.xml | 27 ++ 139 files changed, 3935 insertions(+), 2183 deletions(-) delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/AndroidSafetyLabel.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/AndroidSafetyLabelFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/AppInfo.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/AppInfoFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslMarshallable.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslMarshallableFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategoryConstants.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategoryFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataLabels.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataLabelsFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataType.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataTypeConstants.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataTypeFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DeveloperInfo.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/DeveloperInfoFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/SafetyLabels.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/SafetyLabelsFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/SystemAppSafetyLabel.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/SystemAppSafetyLabelFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/TransparencyInfo.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/TransparencyInfoFactory.java delete mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/XmlUtils.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabel.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabelFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfo.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfoFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AslMarshallable.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AslMarshallableFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataCategory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataCategoryFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataLabels.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataLabelsFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataType.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataTypeFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfo.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfoFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SafetyLabels.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SafetyLabelsFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SystemAppSafetyLabel.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SystemAppSafetyLabelFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/TransparencyInfo.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/TransparencyInfoFactory.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/DataCategoryConstants.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/DataTypeConstants.java create mode 100644 tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/XmlUtils.java delete mode 100644 tools/app_metadata_bundles/src/test/java/com/android/aslgen/AllTests.java delete mode 100644 tools/app_metadata_bundles/src/test/java/com/android/aslgen/AslgenTests.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/AllTests.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/AslgenTests.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/AndroidSafetyLabelTest.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/AppInfoTest.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DataCategoryTest.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DataLabelsTest.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DeveloperInfoTest.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SafetyLabelsTest.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SystemAppSafetyLabelTest.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/TransparencyInfoTest.java create mode 100644 tools/app_metadata_bundles/src/test/java/com/android/asllib/testutils/TestUtils.java delete mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/contacts/hr.xml delete mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/contacts/od.xml delete mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/location/hr.xml delete mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/location/od.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/missing-version.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/valid-empty.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-safety-labels.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-system-app-safety-label.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-transparency-info.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/valid-empty.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-safety-labels.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-system-app-safety-label.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-transparency-info.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/appinfo/hr/all-fields-valid.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/appinfo/od/all-fields-valid.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-actions-in-app.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-app-performance.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-audio.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-calendar.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-contacts.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-email-text-message.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-financial.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-health-fitness.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-identifiers.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-location.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-empty-purpose.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-missing-purpose.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-partial.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-unrecognized-type.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-photo-video.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-search-and-browsing.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-storage.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-unrecognized.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-actions-in-app.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-app-performance.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-audio.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-calendar.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-contacts.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-email-text-message.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-financial.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-health-fitness.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-identifiers.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-location.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-personal-partial.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-personal.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-photo-video.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-search-and-browsing.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-storage.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-accessed-invalid-bool.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-accessed-valid-bool.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-collected-invalid-bool.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-collected-valid-bool.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-shared-invalid-bool.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-shared-valid-bool.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-accessed-valid-bool.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-collected-valid-bool.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-shared-valid-bool.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/developerinfo/hr/all-fields-valid.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/developerinfo/od/all-fields-valid.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/missing-version.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/valid-empty.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-data-labels.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/valid-empty.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-data-labels.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/hr/missing-url.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/hr/valid.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/od/valid.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/valid-empty.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/with-app-info.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/with-developer-info.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/valid-empty.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/with-app-info.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/with-developer-info.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/contacts/hr.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/contacts/od.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/location/hr.xml create mode 100644 tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/location/od.xml diff --git a/tools/app_metadata_bundles/Android.bp b/tools/app_metadata_bundles/Android.bp index a012dca19904..dced50d7ee3b 100644 --- a/tools/app_metadata_bundles/Android.bp +++ b/tools/app_metadata_bundles/Android.bp @@ -13,6 +13,9 @@ java_library_host { srcs: [ "src/lib/java/**/*.java", ], + static_libs: [ + "guava", + ], } java_binary_host { diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AndroidSafetyLabel.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AndroidSafetyLabel.java deleted file mode 100644 index cdb559b52c0e..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AndroidSafetyLabel.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; - -public class AndroidSafetyLabel implements AslMarshallable { - - private final Long mVersion; - private final SystemAppSafetyLabel mSystemAppSafetyLabel; - private final SafetyLabels mSafetyLabels; - private final TransparencyInfo mTransparencyInfo; - - public SafetyLabels getSafetyLabels() { - return mSafetyLabels; - } - - public AndroidSafetyLabel( - Long version, - SystemAppSafetyLabel systemAppSafetyLabel, - SafetyLabels safetyLabels, - TransparencyInfo transparencyInfo) { - this.mVersion = version; - this.mSystemAppSafetyLabel = systemAppSafetyLabel; - this.mSafetyLabels = safetyLabels; - this.mTransparencyInfo = transparencyInfo; - } - - /** Creates an on-device DOM element from an {@link AndroidSafetyLabel} */ - @Override - public List toOdDomElements(Document doc) { - Element aslEle = doc.createElement(XmlUtils.OD_TAG_BUNDLE); - aslEle.appendChild(XmlUtils.createOdLongEle(doc, XmlUtils.OD_NAME_VERSION, mVersion)); - if (mSafetyLabels != null) { - XmlUtils.appendChildren(aslEle, mSafetyLabels.toOdDomElements(doc)); - } - if (mSystemAppSafetyLabel != null) { - XmlUtils.appendChildren(aslEle, mSystemAppSafetyLabel.toOdDomElements(doc)); - } - if (mTransparencyInfo != null) { - XmlUtils.appendChildren(aslEle, mTransparencyInfo.toOdDomElements(doc)); - } - return XmlUtils.listOf(aslEle); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AndroidSafetyLabelFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AndroidSafetyLabelFactory.java deleted file mode 100644 index 3dc725b5452b..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AndroidSafetyLabelFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Element; - -import java.util.List; - -public class AndroidSafetyLabelFactory implements AslMarshallableFactory { - - /** Creates an {@link AndroidSafetyLabel} from human-readable DOM element */ - @Override - public AndroidSafetyLabel createFromHrElements(List appMetadataBundles) - throws MalformedXmlException { - Element appMetadataBundlesEle = XmlUtils.getSingleElement(appMetadataBundles); - long version = XmlUtils.tryGetVersion(appMetadataBundlesEle); - - Element safetyLabelsEle = - XmlUtils.getSingleChildElement( - appMetadataBundlesEle, XmlUtils.HR_TAG_SAFETY_LABELS, false); - SafetyLabels safetyLabels = - new SafetyLabelsFactory().createFromHrElements(XmlUtils.listOf(safetyLabelsEle)); - - Element systemAppSafetyLabelEle = - XmlUtils.getSingleChildElement( - appMetadataBundlesEle, XmlUtils.HR_TAG_SYSTEM_APP_SAFETY_LABEL, false); - SystemAppSafetyLabel systemAppSafetyLabel = - new SystemAppSafetyLabelFactory() - .createFromHrElements(XmlUtils.listOf(systemAppSafetyLabelEle)); - - Element transparencyInfoEle = - XmlUtils.getSingleChildElement( - appMetadataBundlesEle, XmlUtils.HR_TAG_TRANSPARENCY_INFO, false); - TransparencyInfo transparencyInfo = - new TransparencyInfoFactory() - .createFromHrElements(XmlUtils.listOf(transparencyInfoEle)); - - return new AndroidSafetyLabel( - version, systemAppSafetyLabel, safetyLabels, transparencyInfo); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AppInfo.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AppInfo.java deleted file mode 100644 index f94b6591cd10..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AppInfo.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; - -/** AppInfo representation */ -public class AppInfo implements AslMarshallable { - private final String mTitle; - private final String mDescription; - private final Boolean mContainsAds; - private final Boolean mObeyAps; - private final Boolean mAdsFingerprinting; - private final Boolean mSecurityFingerprinting; - private final String mPrivacyPolicy; - private final List mSecurityEndpoints; - private final List mFirstPartyEndpoints; - private final List mServiceProviderEndpoints; - private final String mCategory; - private final String mEmail; - private final String mWebsite; - - public AppInfo( - String title, - String description, - Boolean containsAds, - Boolean obeyAps, - Boolean adsFingerprinting, - Boolean securityFingerprinting, - String privacyPolicy, - List securityEndpoints, - List firstPartyEndpoints, - List serviceProviderEndpoints, - String category, - String email, - String website) { - this.mTitle = title; - this.mDescription = description; - this.mContainsAds = containsAds; - this.mObeyAps = obeyAps; - this.mAdsFingerprinting = adsFingerprinting; - this.mSecurityFingerprinting = securityFingerprinting; - this.mPrivacyPolicy = privacyPolicy; - this.mSecurityEndpoints = securityEndpoints; - this.mFirstPartyEndpoints = firstPartyEndpoints; - this.mServiceProviderEndpoints = serviceProviderEndpoints; - this.mCategory = category; - this.mEmail = email; - this.mWebsite = website; - } - - /** Creates an on-device DOM element from the {@link SafetyLabels}. */ - @Override - public List toOdDomElements(Document doc) { - Element appInfoEle = XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_APP_INFO); - if (this.mTitle != null) { - appInfoEle.appendChild(XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_TITLE, mTitle)); - } - if (this.mDescription != null) { - appInfoEle.appendChild( - XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_DESCRIPTION, mDescription)); - } - if (this.mContainsAds != null) { - appInfoEle.appendChild( - XmlUtils.createOdBooleanEle(doc, XmlUtils.OD_NAME_CONTAINS_ADS, mContainsAds)); - } - if (this.mObeyAps != null) { - appInfoEle.appendChild( - XmlUtils.createOdBooleanEle(doc, XmlUtils.OD_NAME_OBEY_APS, mObeyAps)); - } - if (this.mAdsFingerprinting != null) { - appInfoEle.appendChild( - XmlUtils.createOdBooleanEle( - doc, XmlUtils.OD_NAME_ADS_FINGERPRINTING, mAdsFingerprinting)); - } - if (this.mSecurityFingerprinting != null) { - appInfoEle.appendChild( - XmlUtils.createOdBooleanEle( - doc, - XmlUtils.OD_NAME_SECURITY_FINGERPRINTING, - mSecurityFingerprinting)); - } - if (this.mPrivacyPolicy != null) { - appInfoEle.appendChild( - XmlUtils.createOdStringEle( - doc, XmlUtils.OD_NAME_PRIVACY_POLICY, mPrivacyPolicy)); - } - if (this.mSecurityEndpoints != null) { - appInfoEle.appendChild( - XmlUtils.createOdArray( - doc, - XmlUtils.OD_TAG_STRING_ARRAY, - XmlUtils.OD_NAME_SECURITY_ENDPOINT, - mSecurityEndpoints)); - } - if (this.mFirstPartyEndpoints != null) { - appInfoEle.appendChild( - XmlUtils.createOdArray( - doc, - XmlUtils.OD_TAG_STRING_ARRAY, - XmlUtils.OD_NAME_FIRST_PARTY_ENDPOINT, - mFirstPartyEndpoints)); - } - if (this.mServiceProviderEndpoints != null) { - appInfoEle.appendChild( - XmlUtils.createOdArray( - doc, - XmlUtils.OD_TAG_STRING_ARRAY, - XmlUtils.OD_NAME_SERVICE_PROVIDER_ENDPOINT, - mServiceProviderEndpoints)); - } - if (this.mCategory != null) { - appInfoEle.appendChild( - XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_CATEGORY, this.mCategory)); - } - if (this.mEmail != null) { - appInfoEle.appendChild( - XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_EMAIL, this.mEmail)); - } - if (this.mWebsite != null) { - appInfoEle.appendChild( - XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_WEBSITE, this.mWebsite)); - } - return XmlUtils.listOf(appInfoEle); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AppInfoFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AppInfoFactory.java deleted file mode 100644 index 26d94c16c7f0..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AppInfoFactory.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.AslgenUtil; -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Element; - -import java.util.Arrays; -import java.util.List; - -public class AppInfoFactory implements AslMarshallableFactory { - - /** Creates a {@link AppInfo} from the human-readable DOM element. */ - @Override - public AppInfo createFromHrElements(List elements) throws MalformedXmlException { - Element appInfoEle = XmlUtils.getSingleElement(elements); - if (appInfoEle == null) { - AslgenUtil.logI("No AppInfo found in hr format."); - return null; - } - - String title = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_TITLE); - String description = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_DESCRIPTION); - Boolean containsAds = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_CONTAINS_ADS); - Boolean obeyAps = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_OBEY_APS); - Boolean adsFingerprinting = - XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_ADS_FINGERPRINTING); - Boolean securityFingerprinting = - XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_SECURITY_FINGERPRINTING); - String privacyPolicy = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_PRIVACY_POLICY); - List securityEndpoints = - Arrays.stream( - appInfoEle - .getAttribute(XmlUtils.HR_ATTR_SECURITY_ENDPOINTS) - .split("\\|")) - .toList(); - List firstPartyEndpoints = - Arrays.stream( - appInfoEle - .getAttribute(XmlUtils.HR_ATTR_FIRST_PARTY_ENDPOINTS) - .split("\\|")) - .toList(); - List serviceProviderEndpoints = - Arrays.stream( - appInfoEle - .getAttribute(XmlUtils.HR_ATTR_SERVICE_PROVIDER_ENDPOINTS) - .split("\\|")) - .toList(); - String category = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_CATEGORY); - String email = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_EMAIL); - String website = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_WEBSITE, false); - - return new AppInfo( - title, - description, - containsAds, - obeyAps, - adsFingerprinting, - securityFingerprinting, - privacyPolicy, - securityEndpoints, - firstPartyEndpoints, - serviceProviderEndpoints, - category, - email, - website); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslConverter.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslConverter.java index 9dd55314e844..c1c520e99cac 100644 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslConverter.java +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslConverter.java @@ -16,7 +16,10 @@ package com.android.asllib; +import com.android.asllib.marshallable.AndroidSafetyLabel; +import com.android.asllib.marshallable.AndroidSafetyLabelFactory; import com.android.asllib.util.MalformedXmlException; +import com.android.asllib.util.XmlUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslMarshallable.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslMarshallable.java deleted file mode 100644 index 4e64ab0c53c1..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslMarshallable.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; - -public interface AslMarshallable { - - /** Creates the on-device DOM element from the AslMarshallable Java Object. */ - List toOdDomElements(Document doc); -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslMarshallableFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslMarshallableFactory.java deleted file mode 100644 index b8f9f0ef6235..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/AslMarshallableFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Element; - -import java.util.List; - -public interface AslMarshallableFactory { - - /** Creates an {@link AslMarshallableFactory} from human-readable DOM element */ - T createFromHrElements(List elements) throws MalformedXmlException; -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategory.java deleted file mode 100644 index b9e06fbdfc7e..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategory.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; -import java.util.Map; - -/** - * Data usage category representation containing one or more {@link DataType}. Valid category keys - * are defined in {@link DataCategoryConstants}, each category has a valid set of types {@link - * DataType}, which are mapped in {@link DataTypeConstants} - */ -public class DataCategory implements AslMarshallable { - private final String mCategoryName; - private final Map mDataTypes; - - public DataCategory(String categoryName, Map dataTypes) { - this.mCategoryName = categoryName; - this.mDataTypes = dataTypes; - } - - public String getCategoryName() { - return mCategoryName; - } - - /** Return the type {@link Map} of String type key to {@link DataType} */ - - public Map getDataTypes() { - return mDataTypes; - } - - /** Creates on-device DOM element(s) from the {@link DataCategory}. */ - @Override - public List toOdDomElements(Document doc) { - Element dataCategoryEle = XmlUtils.createPbundleEleWithName(doc, this.getCategoryName()); - for (DataType dataType : mDataTypes.values()) { - XmlUtils.appendChildren(dataCategoryEle, dataType.toOdDomElements(doc)); - } - return XmlUtils.listOf(dataCategoryEle); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategoryConstants.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategoryConstants.java deleted file mode 100644 index b364c8b37194..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategoryConstants.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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; - - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * Constants for determining valid {@link String} data types for usage within {@link SafetyLabels}, - * {@link DataCategory}, and {@link DataType} - */ -public class DataCategoryConstants { - - public static final String CATEGORY_PERSONAL = "personal"; - public static final String CATEGORY_FINANCIAL = "financial"; - public static final String CATEGORY_LOCATION = "location"; - public static final String CATEGORY_EMAIL_TEXT_MESSAGE = "email_text_message"; - public static final String CATEGORY_PHOTO_VIDEO = "photo_video"; - public static final String CATEGORY_AUDIO = "audio"; - public static final String CATEGORY_STORAGE = "storage"; - public static final String CATEGORY_HEALTH_FITNESS = "health_fitness"; - public static final String CATEGORY_CONTACTS = "contacts"; - public static final String CATEGORY_CALENDAR = "calendar"; - public static final String CATEGORY_IDENTIFIERS = "identifiers"; - public static final String CATEGORY_APP_PERFORMANCE = "app_performance"; - public static final String CATEGORY_ACTIONS_IN_APP = "actions_in_app"; - public static final String CATEGORY_SEARCH_AND_BROWSING = "search_and_browsing"; - - /** Set of valid categories */ - public static final Set VALID_CATEGORIES = - Collections.unmodifiableSet( - new HashSet<>( - Arrays.asList( - CATEGORY_PERSONAL, - CATEGORY_FINANCIAL, - CATEGORY_LOCATION, - CATEGORY_EMAIL_TEXT_MESSAGE, - CATEGORY_PHOTO_VIDEO, - CATEGORY_AUDIO, - CATEGORY_STORAGE, - CATEGORY_HEALTH_FITNESS, - CATEGORY_CONTACTS, - CATEGORY_CALENDAR, - CATEGORY_IDENTIFIERS, - CATEGORY_APP_PERFORMANCE, - CATEGORY_ACTIONS_IN_APP, - CATEGORY_SEARCH_AND_BROWSING))); - - /** Returns {@link Set} of valid {@link String} category keys */ - public static Set getValidDataCategories() { - return VALID_CATEGORIES; - } - - private DataCategoryConstants() { - /* do nothing - hide constructor */ - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategoryFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategoryFactory.java deleted file mode 100644 index d2b671271561..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataCategoryFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Element; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public class DataCategoryFactory implements AslMarshallableFactory { - @Override - public DataCategory createFromHrElements(List elements) throws MalformedXmlException { - String categoryName = null; - Map dataTypeMap = new LinkedHashMap(); - for (Element ele : elements) { - categoryName = ele.getAttribute(XmlUtils.HR_ATTR_DATA_CATEGORY); - String dataTypeName = ele.getAttribute(XmlUtils.HR_ATTR_DATA_TYPE); - if (!DataTypeConstants.getValidDataTypes().contains(dataTypeName)) { - throw new MalformedXmlException( - String.format("Unrecognized data type name: %s", dataTypeName)); - } - dataTypeMap.put( - dataTypeName, new DataTypeFactory().createFromHrElements(XmlUtils.listOf(ele))); - } - - return new DataCategory(categoryName, dataTypeMap); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataLabels.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataLabels.java deleted file mode 100644 index 96ec93c28c87..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataLabels.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; -import java.util.Map; - -/** - * Data label representation with data shared and data collected maps containing zero or more {@link - * DataCategory} - */ -public class DataLabels implements AslMarshallable { - private final Map mDataAccessed; - private final Map mDataCollected; - private final Map mDataShared; - - public DataLabels( - Map dataAccessed, - Map dataCollected, - Map dataShared) { - mDataAccessed = dataAccessed; - mDataCollected = dataCollected; - mDataShared = dataShared; - } - - /** - * Returns the data accessed {@link Map} of {@link com.android.asllib.DataCategoryConstants} to - * {@link DataCategory} - */ - public Map getDataAccessed() { - return mDataAccessed; - } - - /** - * Returns the data collected {@link Map} of {@link com.android.asllib.DataCategoryConstants} to - * {@link DataCategory} - */ - public Map getDataCollected() { - return mDataCollected; - } - - /** - * Returns the data shared {@link Map} of {@link com.android.asllib.DataCategoryConstants} to - * {@link DataCategory} - */ - public Map getDataShared() { - return mDataShared; - } - - /** Gets the on-device DOM element for the {@link DataLabels}. */ - @Override - public List toOdDomElements(Document doc) { - Element dataLabelsEle = - XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_DATA_LABELS); - - maybeAppendDataUsages(doc, dataLabelsEle, mDataCollected, XmlUtils.OD_NAME_DATA_ACCESSED); - maybeAppendDataUsages(doc, dataLabelsEle, mDataCollected, XmlUtils.OD_NAME_DATA_COLLECTED); - maybeAppendDataUsages(doc, dataLabelsEle, mDataShared, XmlUtils.OD_NAME_DATA_SHARED); - - return XmlUtils.listOf(dataLabelsEle); - } - - private void maybeAppendDataUsages( - Document doc, - Element dataLabelsEle, - Map dataCategoriesMap, - String dataUsageTypeName) { - if (dataCategoriesMap.isEmpty()) { - return; - } - Element dataUsageEle = XmlUtils.createPbundleEleWithName(doc, dataUsageTypeName); - - for (String dataCategoryName : dataCategoriesMap.keySet()) { - Element dataCategoryEle = XmlUtils.createPbundleEleWithName(doc, dataCategoryName); - DataCategory dataCategory = dataCategoriesMap.get(dataCategoryName); - for (String dataTypeName : dataCategory.getDataTypes().keySet()) { - DataType dataType = dataCategory.getDataTypes().get(dataTypeName); - XmlUtils.appendChildren(dataCategoryEle, dataType.toOdDomElements(doc)); - } - dataUsageEle.appendChild(dataCategoryEle); - } - dataLabelsEle.appendChild(dataUsageEle); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataLabelsFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataLabelsFactory.java deleted file mode 100644 index 79edab7631f0..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataLabelsFactory.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.AslgenUtil; -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class DataLabelsFactory implements AslMarshallableFactory { - - /** Creates a {@link DataLabels} from the human-readable DOM element. */ - @Override - public DataLabels createFromHrElements(List elements) throws MalformedXmlException { - Element ele = XmlUtils.getSingleElement(elements); - if (ele == null) { - AslgenUtil.logI("Found no DataLabels in hr format."); - return null; - } - Map dataAccessed = - getDataCategoriesWithTag(ele, XmlUtils.HR_TAG_DATA_ACCESSED); - Map dataCollected = - getDataCategoriesWithTag(ele, XmlUtils.HR_TAG_DATA_COLLECTED); - Map dataShared = - getDataCategoriesWithTag(ele, XmlUtils.HR_TAG_DATA_SHARED); - - // Validate booleans such as isCollectionOptional, isSharingOptional. - for (DataCategory dataCategory : dataAccessed.values()) { - for (DataType dataType : dataCategory.getDataTypes().values()) { - if (dataType.getIsSharingOptional() != null) { - throw new MalformedXmlException( - String.format( - "isSharingOptional was unexpectedly defined on a DataType" - + " belonging to data accessed: %s", - dataType.getDataTypeName())); - } - if (dataType.getIsCollectionOptional() != null) { - throw new MalformedXmlException( - String.format( - "isCollectionOptional was unexpectedly defined on a DataType" - + " belonging to data accessed: %s", - dataType.getDataTypeName())); - } - } - } - for (DataCategory dataCategory : dataCollected.values()) { - for (DataType dataType : dataCategory.getDataTypes().values()) { - if (dataType.getIsSharingOptional() != null) { - throw new MalformedXmlException( - String.format( - "isSharingOptional was unexpectedly defined on a DataType" - + " belonging to data collected: %s", - dataType.getDataTypeName())); - } - } - } - for (DataCategory dataCategory : dataShared.values()) { - for (DataType dataType : dataCategory.getDataTypes().values()) { - if (dataType.getIsCollectionOptional() != null) { - throw new MalformedXmlException( - String.format( - "isCollectionOptional was unexpectedly defined on a DataType" - + " belonging to data shared: %s", - dataType.getDataTypeName())); - } - } - } - - return new DataLabels(dataAccessed, dataCollected, dataShared); - } - - private static Map getDataCategoriesWithTag( - Element dataLabelsEle, String dataCategoryUsageTypeTag) throws MalformedXmlException { - NodeList dataUsedNodeList = dataLabelsEle.getElementsByTagName(dataCategoryUsageTypeTag); - Map dataCategoryMap = new LinkedHashMap(); - - Set dataCategoryNames = new HashSet(); - for (int i = 0; i < dataUsedNodeList.getLength(); i++) { - Element dataUsedEle = (Element) dataUsedNodeList.item(i); - String dataCategoryName = dataUsedEle.getAttribute(XmlUtils.HR_ATTR_DATA_CATEGORY); - if (!DataCategoryConstants.getValidDataCategories().contains(dataCategoryName)) { - throw new MalformedXmlException( - String.format("Unrecognized category name: %s", dataCategoryName)); - } - dataCategoryNames.add(dataCategoryName); - } - for (String dataCategoryName : dataCategoryNames) { - var dataCategoryElements = - XmlUtils.asElementList(dataUsedNodeList).stream() - .filter( - ele -> - ele.getAttribute(XmlUtils.HR_ATTR_DATA_CATEGORY) - .equals(dataCategoryName)) - .toList(); - DataCategory dataCategory = - new DataCategoryFactory().createFromHrElements(dataCategoryElements); - dataCategoryMap.put(dataCategoryName, dataCategory); - } - return dataCategoryMap; - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataType.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataType.java deleted file mode 100644 index d011cfeef363..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataType.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; -import java.util.Set; - -/** - * Data usage type representation. Types are specific to a {@link DataCategory} and contains - * metadata related to the data usage purpose. - */ -public class DataType implements AslMarshallable { - - public enum Purpose { - APP_FUNCTIONALITY(1), - ANALYTICS(2), - DEVELOPER_COMMUNICATIONS(3), - FRAUD_PREVENTION_SECURITY(4), - ADVERTISING(5), - PERSONALIZATION(6), - ACCOUNT_MANAGEMENT(7); - - private final int mValue; - - Purpose(int value) { - this.mValue = value; - } - - /** Get the int value associated with the Purpose. */ - public int getValue() { - return mValue; - } - - /** Get the Purpose associated with the int value. */ - public static Purpose forValue(int value) { - for (Purpose e : values()) { - if (e.getValue() == value) { - return e; - } - } - throw new IllegalArgumentException("No Purpose enum for value: " + value); - } - - /** Get the Purpose associated with the human-readable String. */ - public static Purpose forString(String s) { - for (Purpose e : values()) { - if (e.toString().equals(s)) { - return e; - } - } - throw new IllegalArgumentException("No Purpose enum for str: " + s); - } - - /** Human-readable String representation of Purpose. */ - public String toString() { - return this.name().toLowerCase(); - } - } - - private final String mDataTypeName; - - private final List mPurposes; - private final Boolean mIsCollectionOptional; - private final Boolean mIsSharingOptional; - private final Boolean mEphemeral; - - public DataType( - String dataTypeName, - List purposes, - Boolean isCollectionOptional, - Boolean isSharingOptional, - Boolean ephemeral) { - this.mDataTypeName = dataTypeName; - this.mPurposes = purposes; - this.mIsCollectionOptional = isCollectionOptional; - this.mIsSharingOptional = isSharingOptional; - this.mEphemeral = ephemeral; - } - - public String getDataTypeName() { - return mDataTypeName; - } - - /** - * Returns {@link Set} of valid {@link Integer} purposes for using the associated data category - * and type - */ - public List getPurposes() { - return mPurposes; - } - - /** - * For data-collected, returns {@code true} if data usage is user optional and {@code false} if - * data usage is required. Should return {@code null} for data-accessed and data-shared. - */ - public Boolean getIsCollectionOptional() { - return mIsCollectionOptional; - } - - /** - * For data-shared, returns {@code true} if data usage is user optional and {@code false} if - * data usage is required. Should return {@code null} for data-accessed and data-collected. - */ - public Boolean getIsSharingOptional() { - return mIsSharingOptional; - } - - /** - * For data-collected, returns {@code true} if data usage is user optional and {@code false} if - * data usage is processed ephemerally. Should return {@code null} for data-shared. - */ - public Boolean getEphemeral() { - return mEphemeral; - } - - @Override - public List toOdDomElements(Document doc) { - Element dataTypeEle = XmlUtils.createPbundleEleWithName(doc, this.getDataTypeName()); - if (!this.getPurposes().isEmpty()) { - dataTypeEle.appendChild( - XmlUtils.createOdArray( - doc, - XmlUtils.OD_TAG_INT_ARRAY, - XmlUtils.OD_NAME_PURPOSES, - this.getPurposes().stream() - .map(p -> String.valueOf(p.getValue())) - .toList())); - } - - maybeAddBoolToOdElement( - doc, - dataTypeEle, - this.getIsCollectionOptional(), - XmlUtils.OD_NAME_IS_COLLECTION_OPTIONAL); - maybeAddBoolToOdElement( - doc, - dataTypeEle, - this.getIsSharingOptional(), - XmlUtils.OD_NAME_IS_SHARING_OPTIONAL); - maybeAddBoolToOdElement(doc, dataTypeEle, this.getEphemeral(), XmlUtils.OD_NAME_EPHEMERAL); - return XmlUtils.listOf(dataTypeEle); - } - - private static void maybeAddBoolToOdElement( - Document doc, Element parentEle, Boolean b, String odName) { - if (b == null) { - return; - } - Element ele = XmlUtils.createOdBooleanEle(doc, odName, b); - parentEle.appendChild(ele); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataTypeConstants.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataTypeConstants.java deleted file mode 100644 index a0a75377e988..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataTypeConstants.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * Constants for determining valid {@link String} data types for usage within {@link SafetyLabels}, - * {@link DataCategory}, and {@link DataType} - */ -public class DataTypeConstants { - /** Data types for {@link DataCategoryConstants.CATEGORY_PERSONAL} */ - public static final String TYPE_NAME = "name"; - - public static final String TYPE_EMAIL_ADDRESS = "email_address"; - public static final String TYPE_PHONE_NUMBER = "phone_number"; - public static final String TYPE_RACE_ETHNICITY = "race_ethnicity"; - public static final String TYPE_POLITICAL_OR_RELIGIOUS_BELIEFS = - "political_or_religious_beliefs"; - public static final String TYPE_SEXUAL_ORIENTATION_OR_GENDER_IDENTITY = - "sexual_orientation_or_gender_identity"; - public static final String TYPE_PERSONAL_IDENTIFIERS = "personal_identifiers"; - public static final String TYPE_OTHER = "other"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_FINANCIAL} */ - public static final String TYPE_CARD_BANK_ACCOUNT = "card_bank_account"; - - public static final String TYPE_PURCHASE_HISTORY = "purchase_history"; - public static final String TYPE_CREDIT_SCORE = "credit_score"; - public static final String TYPE_FINANCIAL_OTHER = "other"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_LOCATION} */ - public static final String TYPE_APPROX_LOCATION = "approx_location"; - - public static final String TYPE_PRECISE_LOCATION = "precise_location"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_EMAIL_TEXT_MESSAGE} */ - public static final String TYPE_EMAILS = "emails"; - - public static final String TYPE_TEXT_MESSAGES = "text_messages"; - public static final String TYPE_EMAIL_TEXT_MESSAGE_OTHER = "other"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_PHOTO_VIDEO} */ - public static final String TYPE_PHOTOS = "photos"; - - public static final String TYPE_VIDEOS = "videos"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_AUDIO} */ - public static final String TYPE_SOUND_RECORDINGS = "sound_recordings"; - - public static final String TYPE_MUSIC_FILES = "music_files"; - public static final String TYPE_AUDIO_OTHER = "other"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_STORAGE} */ - public static final String TYPE_FILES_DOCS = "files_docs"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_HEALTH_FITNESS} */ - public static final String TYPE_HEALTH = "health"; - - public static final String TYPE_FITNESS = "fitness"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_CONTACTS} */ - public static final String TYPE_CONTACTS = "contacts"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_CALENDAR} */ - public static final String TYPE_CALENDAR = "calendar"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_IDENTIFIERS} */ - public static final String TYPE_IDENTIFIERS_OTHER = "other"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_APP_PERFORMANCE} */ - public static final String TYPE_CRASH_LOGS = "crash_logs"; - - public static final String TYPE_PERFORMANCE_DIAGNOSTICS = "performance_diagnostics"; - public static final String TYPE_APP_PERFORMANCE_OTHER = "other"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_ACTIONS_IN_APP} */ - public static final String TYPE_USER_INTERACTION = "user_interaction"; - - public static final String TYPE_IN_APP_SEARCH_HISTORY = "in_app_search_history"; - public static final String TYPE_INSTALLED_APPS = "installed_apps"; - public static final String TYPE_USER_GENERATED_CONTENT = "user_generated_content"; - public static final String TYPE_ACTIONS_IN_APP_OTHER = "other"; - - /** Data types for {@link DataCategoryConstants.CATEGORY_SEARCH_AND_BROWSING} */ - public static final String TYPE_WEB_BROWSING_HISTORY = "web_browsing_history"; - - /** Set of valid categories */ - public static final Set VALID_TYPES = - Collections.unmodifiableSet( - new HashSet<>( - Arrays.asList( - TYPE_NAME, - TYPE_EMAIL_ADDRESS, - TYPE_PHONE_NUMBER, - TYPE_RACE_ETHNICITY, - TYPE_POLITICAL_OR_RELIGIOUS_BELIEFS, - TYPE_SEXUAL_ORIENTATION_OR_GENDER_IDENTITY, - TYPE_PERSONAL_IDENTIFIERS, - TYPE_OTHER, - TYPE_CARD_BANK_ACCOUNT, - TYPE_PURCHASE_HISTORY, - TYPE_CREDIT_SCORE, - TYPE_FINANCIAL_OTHER, - TYPE_APPROX_LOCATION, - TYPE_PRECISE_LOCATION, - TYPE_EMAILS, - TYPE_TEXT_MESSAGES, - TYPE_EMAIL_TEXT_MESSAGE_OTHER, - TYPE_PHOTOS, - TYPE_VIDEOS, - TYPE_SOUND_RECORDINGS, - TYPE_MUSIC_FILES, - TYPE_AUDIO_OTHER, - TYPE_FILES_DOCS, - TYPE_HEALTH, - TYPE_FITNESS, - TYPE_CONTACTS, - TYPE_CALENDAR, - TYPE_IDENTIFIERS_OTHER, - TYPE_CRASH_LOGS, - TYPE_PERFORMANCE_DIAGNOSTICS, - TYPE_APP_PERFORMANCE_OTHER, - TYPE_USER_INTERACTION, - TYPE_IN_APP_SEARCH_HISTORY, - TYPE_INSTALLED_APPS, - TYPE_USER_GENERATED_CONTENT, - TYPE_ACTIONS_IN_APP_OTHER, - TYPE_WEB_BROWSING_HISTORY))); - - /** Returns {@link Set} of valid {@link String} category keys */ - public static Set getValidDataTypes() { - return VALID_TYPES; - } - - private DataTypeConstants() { - /* do nothing - hide constructor */ - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataTypeFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataTypeFactory.java deleted file mode 100644 index 27c1b599fec7..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DataTypeFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Element; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -public class DataTypeFactory implements AslMarshallableFactory { - /** Creates a {@link DataType} from the human-readable DOM element. */ - @Override - public DataType createFromHrElements(List elements) { - Element hrDataTypeEle = XmlUtils.getSingleElement(elements); - String dataTypeName = hrDataTypeEle.getAttribute(XmlUtils.HR_ATTR_DATA_TYPE); - List purposes = - Arrays.stream(hrDataTypeEle.getAttribute(XmlUtils.HR_ATTR_PURPOSES).split("\\|")) - .map(DataType.Purpose::forString) - .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, purposes, isCollectionOptional, isSharingOptional, ephemeral); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DeveloperInfo.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DeveloperInfo.java deleted file mode 100644 index 44a5b129e428..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DeveloperInfo.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; - -/** DeveloperInfo representation */ -public class DeveloperInfo implements AslMarshallable { - public enum DeveloperRelationship { - OEM(0), - ODM(1), - SOC(2), - OTA(3), - CARRIER(4), - AOSP(5), - OTHER(6); - - private final int mValue; - - DeveloperRelationship(int value) { - this.mValue = value; - } - - /** Get the int value associated with the DeveloperRelationship. */ - public int getValue() { - return mValue; - } - - /** Get the DeveloperRelationship associated with the int value. */ - public static DeveloperInfo.DeveloperRelationship forValue(int value) { - for (DeveloperInfo.DeveloperRelationship e : values()) { - if (e.getValue() == value) { - return e; - } - } - throw new IllegalArgumentException("No DeveloperRelationship enum for value: " + value); - } - - /** Get the DeveloperRelationship associated with the human-readable String. */ - public static DeveloperInfo.DeveloperRelationship forString(String s) { - for (DeveloperInfo.DeveloperRelationship e : values()) { - if (e.toString().equals(s)) { - return e; - } - } - throw new IllegalArgumentException("No DeveloperRelationship enum for str: " + s); - } - - /** Human-readable String representation of DeveloperRelationship. */ - public String toString() { - return this.name().toLowerCase(); - } - } - - private final String mName; - private final String mEmail; - private final String mAddress; - private final String mCountryRegion; - private final DeveloperRelationship mDeveloperRelationship; - private final String mWebsite; - private final String mAppDeveloperRegistryId; - - public DeveloperInfo( - String name, - String email, - String address, - String countryRegion, - DeveloperRelationship developerRelationship, - String website, - String appDeveloperRegistryId) { - this.mName = name; - this.mEmail = email; - this.mAddress = address; - this.mCountryRegion = countryRegion; - this.mDeveloperRelationship = developerRelationship; - this.mWebsite = website; - this.mAppDeveloperRegistryId = appDeveloperRegistryId; - } - - /** Creates an on-device DOM element from the {@link SafetyLabels}. */ - @Override - public List toOdDomElements(Document doc) { - Element developerInfoEle = - XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_DEVELOPER_INFO); - if (mName != null) { - developerInfoEle.appendChild( - XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_NAME, mName)); - } - if (mEmail != null) { - developerInfoEle.appendChild( - XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_EMAIL, mEmail)); - } - if (mAddress != null) { - developerInfoEle.appendChild( - XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_ADDRESS, mAddress)); - } - if (mCountryRegion != null) { - developerInfoEle.appendChild( - XmlUtils.createOdStringEle( - doc, XmlUtils.OD_NAME_COUNTRY_REGION, mCountryRegion)); - } - if (mDeveloperRelationship != null) { - developerInfoEle.appendChild( - XmlUtils.createOdLongEle( - doc, - XmlUtils.OD_NAME_DEVELOPER_RELATIONSHIP, - mDeveloperRelationship.getValue())); - } - if (mWebsite != null) { - developerInfoEle.appendChild( - XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_WEBSITE, mWebsite)); - } - if (mAppDeveloperRegistryId != null) { - developerInfoEle.appendChild( - XmlUtils.createOdStringEle( - doc, - XmlUtils.OD_NAME_APP_DEVELOPER_REGISTRY_ID, - mAppDeveloperRegistryId)); - } - - return XmlUtils.listOf(developerInfoEle); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DeveloperInfoFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DeveloperInfoFactory.java deleted file mode 100644 index 4961892b10c3..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/DeveloperInfoFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.AslgenUtil; -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Element; - -import java.util.List; - -public class DeveloperInfoFactory implements AslMarshallableFactory { - - /** Creates a {@link DeveloperInfo} from the human-readable DOM element. */ - @Override - public DeveloperInfo createFromHrElements(List elements) throws MalformedXmlException { - Element developerInfoEle = XmlUtils.getSingleElement(elements); - if (developerInfoEle == null) { - AslgenUtil.logI("No DeveloperInfo found in hr format."); - return null; - } - String name = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_NAME); - String email = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_EMAIL); - String address = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_ADDRESS); - String countryRegion = - XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_COUNTRY_REGION); - DeveloperInfo.DeveloperRelationship developerRelationship = - DeveloperInfo.DeveloperRelationship.forString( - XmlUtils.getStringAttr( - developerInfoEle, XmlUtils.HR_ATTR_DEVELOPER_RELATIONSHIP)); - String website = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_WEBSITE, false); - String appDeveloperRegistryId = - XmlUtils.getStringAttr( - developerInfoEle, XmlUtils.HR_ATTR_APP_DEVELOPER_REGISTRY_ID, false); - - return new DeveloperInfo( - name, - email, - address, - countryRegion, - developerRelationship, - website, - appDeveloperRegistryId); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SafetyLabels.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SafetyLabels.java deleted file mode 100644 index 40ef48dc5334..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SafetyLabels.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; - -/** Safety Label representation containing zero or more {@link DataCategory} for data shared */ -public class SafetyLabels implements AslMarshallable { - - private final Long mVersion; - private final DataLabels mDataLabels; - - public SafetyLabels(Long version, DataLabels dataLabels) { - this.mVersion = version; - this.mDataLabels = dataLabels; - } - - /** Returns the data label for the safety label */ - public DataLabels getDataLabel() { - return mDataLabels; - } - - /** Gets the version of the {@link SafetyLabels}. */ - public Long getVersion() { - return mVersion; - } - - /** Creates an on-device DOM element from the {@link SafetyLabels}. */ - @Override - public List toOdDomElements(Document doc) { - Element safetyLabelsEle = - XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_SAFETY_LABELS); - safetyLabelsEle.appendChild( - XmlUtils.createOdLongEle(doc, XmlUtils.OD_NAME_VERSION, mVersion)); - if (mDataLabels != null) { - XmlUtils.appendChildren(safetyLabelsEle, mDataLabels.toOdDomElements(doc)); - } - return XmlUtils.listOf(safetyLabelsEle); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SafetyLabelsFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SafetyLabelsFactory.java deleted file mode 100644 index ab81b1d56033..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SafetyLabelsFactory.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.AslgenUtil; -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Element; - -import java.util.List; - -public class SafetyLabelsFactory implements AslMarshallableFactory { - - /** Creates a {@link SafetyLabels} from the human-readable DOM element. */ - @Override - public SafetyLabels createFromHrElements(List elements) throws MalformedXmlException { - Element safetyLabelsEle = XmlUtils.getSingleElement(elements); - if (safetyLabelsEle == null) { - AslgenUtil.logI("No SafetyLabels found in hr format."); - return null; - } - long version = XmlUtils.tryGetVersion(safetyLabelsEle); - - DataLabels dataLabels = - new DataLabelsFactory() - .createFromHrElements( - XmlUtils.listOf( - XmlUtils.getSingleChildElement( - safetyLabelsEle, XmlUtils.HR_TAG_DATA_LABELS))); - return new SafetyLabels(version, dataLabels); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SystemAppSafetyLabel.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SystemAppSafetyLabel.java deleted file mode 100644 index 93d9c2b080c5..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SystemAppSafetyLabel.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; - -/** Safety Label representation containing zero or more {@link DataCategory} for data shared */ -public class SystemAppSafetyLabel implements AslMarshallable { - - private final String mUrl; - - public SystemAppSafetyLabel(String url) { - this.mUrl = url; - } - - /** Returns the system app safety label URL. */ - public String getUrl() { - return mUrl; - } - - /** Creates an on-device DOM element from the {@link SystemAppSafetyLabel}. */ - @Override - public List toOdDomElements(Document doc) { - Element systemAppSafetyLabelEle = - XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_SYSTEM_APP_SAFETY_LABEL); - systemAppSafetyLabelEle.appendChild( - XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_URL, mUrl)); - return XmlUtils.listOf(systemAppSafetyLabelEle); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SystemAppSafetyLabelFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SystemAppSafetyLabelFactory.java deleted file mode 100644 index c8c1c7beba24..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/SystemAppSafetyLabelFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.AslgenUtil; -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Element; - -import java.util.List; - -public class SystemAppSafetyLabelFactory implements AslMarshallableFactory { - - /** Creates a {@link SystemAppSafetyLabel} from the human-readable DOM element. */ - @Override - public SystemAppSafetyLabel createFromHrElements(List elements) - throws MalformedXmlException { - Element systemAppSafetyLabelEle = XmlUtils.getSingleElement(elements); - if (systemAppSafetyLabelEle == null) { - AslgenUtil.logI("No SystemAppSafetyLabel found in hr format."); - return null; - } - - String url = XmlUtils.getStringAttr(systemAppSafetyLabelEle, XmlUtils.HR_ATTR_URL); - return new SystemAppSafetyLabel(url); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/TransparencyInfo.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/TransparencyInfo.java deleted file mode 100644 index 88717b9568b8..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/TransparencyInfo.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.List; - -/** TransparencyInfo representation containing {@link DeveloperInfo} and {@link AppInfo} */ -public class TransparencyInfo implements AslMarshallable { - - private final DeveloperInfo mDeveloperInfo; - private final AppInfo mAppInfo; - - public TransparencyInfo(DeveloperInfo developerInfo, AppInfo appInfo) { - this.mDeveloperInfo = developerInfo; - this.mAppInfo = appInfo; - } - - /** Gets the {@link DeveloperInfo} of the {@link TransparencyInfo}. */ - public DeveloperInfo getDeveloperInfo() { - return mDeveloperInfo; - } - - /** Gets the {@link AppInfo} of the {@link TransparencyInfo}. */ - public AppInfo getAppInfo() { - return mAppInfo; - } - - /** Creates an on-device DOM element from the {@link TransparencyInfo}. */ - @Override - public List toOdDomElements(Document doc) { - Element transparencyInfoEle = - XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_TRANSPARENCY_INFO); - if (mDeveloperInfo != null) { - XmlUtils.appendChildren(transparencyInfoEle, mDeveloperInfo.toOdDomElements(doc)); - } - if (mAppInfo != null) { - XmlUtils.appendChildren(transparencyInfoEle, mAppInfo.toOdDomElements(doc)); - } - return XmlUtils.listOf(transparencyInfoEle); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/TransparencyInfoFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/TransparencyInfoFactory.java deleted file mode 100644 index 13a7eb62fedd..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/TransparencyInfoFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.AslgenUtil; -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Element; - -import java.util.List; - -public class TransparencyInfoFactory implements AslMarshallableFactory { - - /** Creates a {@link TransparencyInfo} from the human-readable DOM element. */ - @Override - public TransparencyInfo createFromHrElements(List elements) - throws MalformedXmlException { - Element transparencyInfoEle = XmlUtils.getSingleElement(elements); - if (transparencyInfoEle == null) { - AslgenUtil.logI("No TransparencyInfo found in hr format."); - return null; - } - - Element developerInfoEle = - XmlUtils.getSingleChildElement( - transparencyInfoEle, XmlUtils.HR_TAG_DEVELOPER_INFO, false); - DeveloperInfo developerInfo = - new DeveloperInfoFactory().createFromHrElements(XmlUtils.listOf(developerInfoEle)); - - Element appInfoEle = - XmlUtils.getSingleChildElement( - transparencyInfoEle, XmlUtils.HR_TAG_APP_INFO, false); - AppInfo appInfo = new AppInfoFactory().createFromHrElements(XmlUtils.listOf(appInfoEle)); - - return new TransparencyInfo(developerInfo, appInfo); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/XmlUtils.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/XmlUtils.java deleted file mode 100644 index cc8fe79cb579..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/XmlUtils.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * 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; - -import com.android.asllib.util.MalformedXmlException; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class XmlUtils { - public static final String HR_TAG_APP_METADATA_BUNDLES = "app-metadata-bundles"; - public static final String HR_TAG_SYSTEM_APP_SAFETY_LABEL = "system-app-safety-label"; - public static final String HR_TAG_SAFETY_LABELS = "safety-labels"; - public static final String HR_TAG_TRANSPARENCY_INFO = "transparency-info"; - public static final String HR_TAG_DEVELOPER_INFO = "developer-info"; - public static final String HR_TAG_APP_INFO = "app-info"; - public static final String HR_TAG_DATA_LABELS = "data-labels"; - public static final String HR_TAG_DATA_ACCESSED = "data-accessed"; - public static final String HR_TAG_DATA_COLLECTED = "data-collected"; - public static final String HR_TAG_DATA_SHARED = "data-shared"; - public static final String HR_ATTR_NAME = "name"; - public static final String HR_ATTR_EMAIL = "email"; - public static final String HR_ATTR_ADDRESS = "address"; - public static final String HR_ATTR_COUNTRY_REGION = "countryRegion"; - public static final String HR_ATTR_DEVELOPER_RELATIONSHIP = "relationship"; - public static final String HR_ATTR_WEBSITE = "website"; - public static final String HR_ATTR_APP_DEVELOPER_REGISTRY_ID = "registryId"; - public static final String HR_ATTR_DATA_CATEGORY = "dataCategory"; - public static final String HR_ATTR_DATA_TYPE = "dataType"; - public static final String HR_ATTR_IS_COLLECTION_OPTIONAL = "isCollectionOptional"; - public static final String HR_ATTR_IS_SHARING_OPTIONAL = "isSharingOptional"; - public static final String HR_ATTR_EPHEMERAL = "ephemeral"; - public static final String HR_ATTR_PURPOSES = "purposes"; - public static final String HR_ATTR_VERSION = "version"; - public static final String HR_ATTR_URL = "url"; - public static final String HR_ATTR_TITLE = "title"; - public static final String HR_ATTR_DESCRIPTION = "description"; - public static final String HR_ATTR_CONTAINS_ADS = "containsAds"; - public static final String HR_ATTR_OBEY_APS = "obeyAps"; - public static final String HR_ATTR_ADS_FINGERPRINTING = "adsFingerprinting"; - public static final String HR_ATTR_SECURITY_FINGERPRINTING = "securityFingerprinting"; - public static final String HR_ATTR_PRIVACY_POLICY = "privacyPolicy"; - public static final String HR_ATTR_SECURITY_ENDPOINTS = "securityEndpoints"; - public static final String HR_ATTR_FIRST_PARTY_ENDPOINTS = "firstPartyEndpoints"; - public static final String HR_ATTR_SERVICE_PROVIDER_ENDPOINTS = "serviceProviderEndpoints"; - public static final String HR_ATTR_CATEGORY = "category"; - - public static final String OD_TAG_BUNDLE = "bundle"; - public static final String OD_TAG_PBUNDLE_AS_MAP = "pbundle_as_map"; - public static final String OD_TAG_BOOLEAN = "boolean"; - public static final String OD_TAG_LONG = "long"; - public static final String OD_TAG_STRING = "string"; - public static final String OD_TAG_INT_ARRAY = "int-array"; - public static final String OD_TAG_STRING_ARRAY = "string-array"; - public static final String OD_TAG_ITEM = "item"; - public static final String OD_ATTR_NAME = "name"; - public static final String OD_ATTR_VALUE = "value"; - public static final String OD_ATTR_NUM = "num"; - public static final String OD_NAME_SAFETY_LABELS = "safety_labels"; - public static final String OD_NAME_TRANSPARENCY_INFO = "transparency_info"; - public static final String OD_NAME_DEVELOPER_INFO = "developer_info"; - public static final String OD_NAME_NAME = "name"; - public static final String OD_NAME_EMAIL = "email"; - public static final String OD_NAME_ADDRESS = "address"; - public static final String OD_NAME_COUNTRY_REGION = "country_region"; - public static final String OD_NAME_DEVELOPER_RELATIONSHIP = "relationship"; - public static final String OD_NAME_WEBSITE = "website"; - public static final String OD_NAME_APP_DEVELOPER_REGISTRY_ID = "app_developer_registry_id"; - public static final String OD_NAME_APP_INFO = "app_info"; - public static final String OD_NAME_TITLE = "title"; - public static final String OD_NAME_DESCRIPTION = "description"; - public static final String OD_NAME_CONTAINS_ADS = "contains_ads"; - public static final String OD_NAME_OBEY_APS = "obey_aps"; - public static final String OD_NAME_ADS_FINGERPRINTING = "ads_fingerprinting"; - public static final String OD_NAME_SECURITY_FINGERPRINTING = "security_fingerprinting"; - public static final String OD_NAME_PRIVACY_POLICY = "privacy_policy"; - public static final String OD_NAME_SECURITY_ENDPOINT = "security_endpoint"; - public static final String OD_NAME_FIRST_PARTY_ENDPOINT = "first_party_endpoint"; - public static final String OD_NAME_SERVICE_PROVIDER_ENDPOINT = "service_provider_endpoint"; - public static final String OD_NAME_CATEGORY = "category"; - public static final String OD_NAME_VERSION = "version"; - public static final String OD_NAME_URL = "url"; - public static final String OD_NAME_SYSTEM_APP_SAFETY_LABEL = "system_app_safety_label"; - public static final String OD_NAME_DATA_LABELS = "data_labels"; - public static final String OD_NAME_DATA_ACCESSED = "data_accessed"; - public static final String OD_NAME_DATA_COLLECTED = "data_collected"; - public static final String OD_NAME_DATA_SHARED = "data_shared"; - public static final String OD_NAME_PURPOSES = "purposes"; - public static final String OD_NAME_IS_COLLECTION_OPTIONAL = "is_collection_optional"; - public static final String OD_NAME_IS_SHARING_OPTIONAL = "is_sharing_optional"; - public static final String OD_NAME_EPHEMERAL = "ephemeral"; - - public static final String TRUE_STR = "true"; - public static final String FALSE_STR = "false"; - - /** Gets the single top-level {@link Element} having the {@param tagName}. */ - public static Element getSingleElement(Document doc, String tagName) - throws MalformedXmlException { - var elements = doc.getElementsByTagName(tagName); - return getSingleElement(elements, tagName); - } - - /** - * Gets the single {@link Element} within {@param parentEle} and having the {@param tagName}. - */ - public static Element getSingleChildElement(Element parentEle, String tagName) - throws MalformedXmlException { - var elements = parentEle.getElementsByTagName(tagName); - return getSingleElement(elements, tagName, true); - } - - /** - * Gets the single {@link Element} within {@param parentEle} and having the {@param tagName}. - */ - public static Element getSingleChildElement(Element parentEle, String tagName, boolean required) - throws MalformedXmlException { - var elements = parentEle.getElementsByTagName(tagName); - return getSingleElement(elements, tagName, required); - } - - /** Gets the single {@link Element} from {@param elements} */ - public static Element getSingleElement(NodeList elements, String tagName) - throws MalformedXmlException { - return getSingleElement(elements, tagName, true); - } - - /** Gets the single {@link Element} from {@param elements} */ - public static Element getSingleElement(NodeList elements, String tagName, boolean required) - throws MalformedXmlException { - if (elements.getLength() > 1) { - throw new MalformedXmlException( - String.format( - "Expected 1 element \"%s\" in NodeList but got %s.", - tagName, elements.getLength())); - } else if (elements.getLength() == 0) { - if (required) { - throw new MalformedXmlException( - String.format("Found no element \"%s\" in NodeList.", tagName)); - } else { - return null; - } - } - var elementAsNode = elements.item(0); - if (!(elementAsNode instanceof Element)) { - throw new MalformedXmlException( - String.format("%s was not a valid XML element.", tagName)); - } - return ((Element) elementAsNode); - } - - /** Gets the single {@link Element} within {@param elements}. */ - public static Element getSingleElement(List elements) { - if (elements.size() != 1) { - throw new IllegalStateException( - String.format("Expected 1 element in list but got %s.", elements.size())); - } - return elements.get(0); - } - - /** Converts {@param nodeList} into List of {@link Element}. */ - public static List asElementList(NodeList nodeList) { - List elementList = new ArrayList(); - for (int i = 0; i < nodeList.getLength(); i++) { - var elementAsNode = nodeList.item(i); - if (elementAsNode instanceof Element) { - elementList.add(((Element) elementAsNode)); - } - } - return elementList; - } - - /** Appends {@param children} to the {@param ele}. */ - public static void appendChildren(Element ele, List children) { - for (Element c : children) { - ele.appendChild(c); - } - } - - /** Gets the Boolean from the String value. */ - private static Boolean fromString(String s) { - if (s == null) { - return null; - } - if (s.equals(TRUE_STR)) { - return true; - } else if (s.equals(FALSE_STR)) { - return false; - } - return null; - } - - /** Creates an on-device PBundle DOM Element with the given attribute name. */ - public static Element createPbundleEleWithName(Document doc, String name) { - var ele = doc.createElement(XmlUtils.OD_TAG_PBUNDLE_AS_MAP); - ele.setAttribute(XmlUtils.OD_ATTR_NAME, name); - return ele; - } - - /** Create an on-device Boolean DOM Element with the given attribute name. */ - public static Element createOdBooleanEle(Document doc, String name, boolean b) { - var ele = doc.createElement(XmlUtils.OD_TAG_BOOLEAN); - ele.setAttribute(XmlUtils.OD_ATTR_NAME, name); - ele.setAttribute(XmlUtils.OD_ATTR_VALUE, String.valueOf(b)); - return ele; - } - - /** Create an on-device Long DOM Element with the given attribute name. */ - public static Element createOdLongEle(Document doc, String name, long l) { - var ele = doc.createElement(XmlUtils.OD_TAG_LONG); - ele.setAttribute(XmlUtils.OD_ATTR_NAME, name); - ele.setAttribute(XmlUtils.OD_ATTR_VALUE, String.valueOf(l)); - return ele; - } - - /** Create an on-device Long DOM Element with the given attribute name. */ - public static Element createOdStringEle(Document doc, String name, String val) { - var ele = doc.createElement(XmlUtils.OD_TAG_STRING); - ele.setAttribute(XmlUtils.OD_ATTR_NAME, name); - ele.setAttribute(XmlUtils.OD_ATTR_VALUE, val); - return ele; - } - - /** Create OD style array DOM Element, which can represent any time but is stored as Strings. */ - public static Element createOdArray( - Document doc, String arrayTag, String arrayName, List arrayVals) { - Element arrEle = doc.createElement(arrayTag); - arrEle.setAttribute(XmlUtils.OD_ATTR_NAME, arrayName); - arrEle.setAttribute(XmlUtils.OD_ATTR_NUM, String.valueOf(arrayVals.size())); - for (String s : arrayVals) { - Element itemEle = doc.createElement(XmlUtils.OD_TAG_ITEM); - itemEle.setAttribute(XmlUtils.OD_ATTR_VALUE, s); - arrEle.appendChild(itemEle); - } - return arrEle; - } - - /** Returns whether the String is null or empty. */ - public static boolean isNullOrEmpty(String s) { - return s == null || s.isEmpty(); - } - - /** Tries getting required version attribute and throws exception if it doesn't exist */ - public static Long tryGetVersion(Element ele) { - long version; - try { - version = Long.parseLong(ele.getAttribute(XmlUtils.HR_ATTR_VERSION)); - } catch (Exception e) { - throw new IllegalArgumentException( - String.format( - "Malformed or missing required version in: %s", ele.getTagName())); - } - return version; - } - - /** Gets an optional Boolean attribute. */ - public static Boolean getBoolAttr(Element ele, String attrName) { - return XmlUtils.fromString(ele.getAttribute(attrName)); - } - - /** Gets a required String attribute. */ - public static String getStringAttr(Element ele, String attrName) throws MalformedXmlException { - return getStringAttr(ele, attrName, true); - } - - /** Gets a String attribute; throws exception if required and non-existent. */ - public static String getStringAttr(Element ele, String attrName, boolean required) - throws MalformedXmlException { - String s = ele.getAttribute(attrName); - if (isNullOrEmpty(s)) { - if (required) { - throw new MalformedXmlException( - String.format( - "Malformed or missing required %s in: %s", - attrName, ele.getTagName())); - } else { - return null; - } - } - return s; - } - - /** - * Utility method for making a List from one element, to support easier refactoring if needed. - * For example, List.of() doesn't support null elements. - */ - public static List listOf(Element e) { - return Arrays.asList(e); - } -} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabel.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabel.java new file mode 100644 index 000000000000..112b92c9aebb --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabel.java @@ -0,0 +1,64 @@ +/* + * 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; + +public class AndroidSafetyLabel implements AslMarshallable { + + private final Long mVersion; + private final SystemAppSafetyLabel mSystemAppSafetyLabel; + private final SafetyLabels mSafetyLabels; + private final TransparencyInfo mTransparencyInfo; + + public SafetyLabels getSafetyLabels() { + return mSafetyLabels; + } + + public AndroidSafetyLabel( + Long version, + SystemAppSafetyLabel systemAppSafetyLabel, + SafetyLabels safetyLabels, + TransparencyInfo transparencyInfo) { + this.mVersion = version; + this.mSystemAppSafetyLabel = systemAppSafetyLabel; + this.mSafetyLabels = safetyLabels; + this.mTransparencyInfo = transparencyInfo; + } + + /** Creates an on-device DOM element from an {@link AndroidSafetyLabel} */ + @Override + public List toOdDomElements(Document doc) { + Element aslEle = doc.createElement(XmlUtils.OD_TAG_BUNDLE); + aslEle.appendChild(XmlUtils.createOdLongEle(doc, XmlUtils.OD_NAME_VERSION, mVersion)); + if (mSafetyLabels != null) { + XmlUtils.appendChildren(aslEle, mSafetyLabels.toOdDomElements(doc)); + } + if (mSystemAppSafetyLabel != null) { + XmlUtils.appendChildren(aslEle, mSystemAppSafetyLabel.toOdDomElements(doc)); + } + if (mTransparencyInfo != null) { + XmlUtils.appendChildren(aslEle, mTransparencyInfo.toOdDomElements(doc)); + } + return XmlUtils.listOf(aslEle); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabelFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabelFactory.java new file mode 100644 index 000000000000..b69c30f7f522 --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AndroidSafetyLabelFactory.java @@ -0,0 +1,58 @@ +/* + * 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.MalformedXmlException; +import com.android.asllib.util.XmlUtils; + +import org.w3c.dom.Element; + +import java.util.List; + +public class AndroidSafetyLabelFactory implements AslMarshallableFactory { + + /** Creates an {@link AndroidSafetyLabel} from human-readable DOM element */ + @Override + public AndroidSafetyLabel createFromHrElements(List appMetadataBundles) + throws MalformedXmlException { + Element appMetadataBundlesEle = XmlUtils.getSingleElement(appMetadataBundles); + long version = XmlUtils.tryGetVersion(appMetadataBundlesEle); + + Element safetyLabelsEle = + XmlUtils.getSingleChildElement( + appMetadataBundlesEle, XmlUtils.HR_TAG_SAFETY_LABELS, false); + SafetyLabels safetyLabels = + new SafetyLabelsFactory().createFromHrElements(XmlUtils.listOf(safetyLabelsEle)); + + Element systemAppSafetyLabelEle = + XmlUtils.getSingleChildElement( + appMetadataBundlesEle, XmlUtils.HR_TAG_SYSTEM_APP_SAFETY_LABEL, false); + SystemAppSafetyLabel systemAppSafetyLabel = + new SystemAppSafetyLabelFactory() + .createFromHrElements(XmlUtils.listOf(systemAppSafetyLabelEle)); + + Element transparencyInfoEle = + XmlUtils.getSingleChildElement( + appMetadataBundlesEle, XmlUtils.HR_TAG_TRANSPARENCY_INFO, false); + TransparencyInfo transparencyInfo = + new TransparencyInfoFactory() + .createFromHrElements(XmlUtils.listOf(transparencyInfoEle)); + + return new AndroidSafetyLabel( + version, systemAppSafetyLabel, safetyLabels, transparencyInfo); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfo.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfo.java new file mode 100644 index 000000000000..3f1ddebefe99 --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfo.java @@ -0,0 +1,145 @@ +/* + * 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; + +/** AppInfo representation */ +public class AppInfo implements AslMarshallable { + private final String mTitle; + private final String mDescription; + private final Boolean mContainsAds; + private final Boolean mObeyAps; + private final Boolean mAdsFingerprinting; + private final Boolean mSecurityFingerprinting; + private final String mPrivacyPolicy; + private final List mSecurityEndpoints; + private final List mFirstPartyEndpoints; + private final List mServiceProviderEndpoints; + private final String mCategory; + private final String mEmail; + private final String mWebsite; + + public AppInfo( + String title, + String description, + Boolean containsAds, + Boolean obeyAps, + Boolean adsFingerprinting, + Boolean securityFingerprinting, + String privacyPolicy, + List securityEndpoints, + List firstPartyEndpoints, + List serviceProviderEndpoints, + String category, + String email, + String website) { + this.mTitle = title; + this.mDescription = description; + this.mContainsAds = containsAds; + this.mObeyAps = obeyAps; + this.mAdsFingerprinting = adsFingerprinting; + this.mSecurityFingerprinting = securityFingerprinting; + this.mPrivacyPolicy = privacyPolicy; + this.mSecurityEndpoints = securityEndpoints; + this.mFirstPartyEndpoints = firstPartyEndpoints; + this.mServiceProviderEndpoints = serviceProviderEndpoints; + this.mCategory = category; + this.mEmail = email; + this.mWebsite = website; + } + + /** Creates an on-device DOM element from the {@link SafetyLabels}. */ + @Override + public List toOdDomElements(Document doc) { + Element appInfoEle = XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_APP_INFO); + if (this.mTitle != null) { + appInfoEle.appendChild(XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_TITLE, mTitle)); + } + if (this.mDescription != null) { + appInfoEle.appendChild( + XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_DESCRIPTION, mDescription)); + } + if (this.mContainsAds != null) { + appInfoEle.appendChild( + XmlUtils.createOdBooleanEle(doc, XmlUtils.OD_NAME_CONTAINS_ADS, mContainsAds)); + } + if (this.mObeyAps != null) { + appInfoEle.appendChild( + XmlUtils.createOdBooleanEle(doc, XmlUtils.OD_NAME_OBEY_APS, mObeyAps)); + } + if (this.mAdsFingerprinting != null) { + appInfoEle.appendChild( + XmlUtils.createOdBooleanEle( + doc, XmlUtils.OD_NAME_ADS_FINGERPRINTING, mAdsFingerprinting)); + } + if (this.mSecurityFingerprinting != null) { + appInfoEle.appendChild( + XmlUtils.createOdBooleanEle( + doc, + XmlUtils.OD_NAME_SECURITY_FINGERPRINTING, + mSecurityFingerprinting)); + } + if (this.mPrivacyPolicy != null) { + appInfoEle.appendChild( + XmlUtils.createOdStringEle( + doc, XmlUtils.OD_NAME_PRIVACY_POLICY, mPrivacyPolicy)); + } + if (this.mSecurityEndpoints != null) { + appInfoEle.appendChild( + XmlUtils.createOdArray( + doc, + XmlUtils.OD_TAG_STRING_ARRAY, + XmlUtils.OD_NAME_SECURITY_ENDPOINT, + mSecurityEndpoints)); + } + if (this.mFirstPartyEndpoints != null) { + appInfoEle.appendChild( + XmlUtils.createOdArray( + doc, + XmlUtils.OD_TAG_STRING_ARRAY, + XmlUtils.OD_NAME_FIRST_PARTY_ENDPOINT, + mFirstPartyEndpoints)); + } + if (this.mServiceProviderEndpoints != null) { + appInfoEle.appendChild( + XmlUtils.createOdArray( + doc, + XmlUtils.OD_TAG_STRING_ARRAY, + XmlUtils.OD_NAME_SERVICE_PROVIDER_ENDPOINT, + mServiceProviderEndpoints)); + } + if (this.mCategory != null) { + appInfoEle.appendChild( + XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_CATEGORY, this.mCategory)); + } + if (this.mEmail != null) { + appInfoEle.appendChild( + XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_EMAIL, this.mEmail)); + } + if (this.mWebsite != null) { + appInfoEle.appendChild( + XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_WEBSITE, this.mWebsite)); + } + return XmlUtils.listOf(appInfoEle); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfoFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfoFactory.java new file mode 100644 index 000000000000..59a437d7ece5 --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AppInfoFactory.java @@ -0,0 +1,75 @@ +/* + * 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 AppInfoFactory implements AslMarshallableFactory { + + /** Creates a {@link AppInfo} from the human-readable DOM element. */ + @Override + public AppInfo createFromHrElements(List elements) throws MalformedXmlException { + Element appInfoEle = XmlUtils.getSingleElement(elements); + if (appInfoEle == null) { + AslgenUtil.logI("No AppInfo found in hr format."); + return null; + } + + String title = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_TITLE); + String description = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_DESCRIPTION); + 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); + List securityEndpoints = + XmlUtils.getPipelineSplitAttr( + appInfoEle, XmlUtils.HR_ATTR_SECURITY_ENDPOINTS, true); + List firstPartyEndpoints = + XmlUtils.getPipelineSplitAttr( + appInfoEle, XmlUtils.HR_ATTR_FIRST_PARTY_ENDPOINTS, true); + List 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 website = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_WEBSITE, false); + + return new AppInfo( + title, + description, + containsAds, + obeyAps, + adsFingerprinting, + securityFingerprinting, + privacyPolicy, + securityEndpoints, + firstPartyEndpoints, + serviceProviderEndpoints, + category, + email, + website); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AslMarshallable.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AslMarshallable.java new file mode 100644 index 000000000000..48747ccbcff6 --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AslMarshallable.java @@ -0,0 +1,28 @@ +/* + * 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 org.w3c.dom.Document; +import org.w3c.dom.Element; + +import java.util.List; + +public interface AslMarshallable { + + /** Creates the on-device DOM element from the AslMarshallable Java Object. */ + List toOdDomElements(Document doc); +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AslMarshallableFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AslMarshallableFactory.java new file mode 100644 index 000000000000..a49b3e77155b --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/AslMarshallableFactory.java @@ -0,0 +1,29 @@ +/* + * 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.MalformedXmlException; + +import org.w3c.dom.Element; + +import java.util.List; + +public interface AslMarshallableFactory { + + /** Creates an {@link AslMarshallableFactory} from human-readable DOM element */ + T createFromHrElements(List elements) throws MalformedXmlException; +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataCategory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataCategory.java new file mode 100644 index 000000000000..4d67162b442d --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataCategory.java @@ -0,0 +1,62 @@ +/* + * 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.DataCategoryConstants; +import com.android.asllib.util.DataTypeConstants; +import com.android.asllib.util.XmlUtils; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import java.util.List; +import java.util.Map; + +/** + * Data usage category representation containing one or more {@link DataType}. Valid category keys + * are defined in {@link DataCategoryConstants}, each category has a valid set of types {@link + * DataType}, which are mapped in {@link DataTypeConstants} + */ +public class DataCategory implements AslMarshallable { + private final String mCategoryName; + private final Map mDataTypes; + + public DataCategory(String categoryName, Map dataTypes) { + this.mCategoryName = categoryName; + this.mDataTypes = dataTypes; + } + + public String getCategoryName() { + return mCategoryName; + } + + /** Return the type {@link Map} of String type key to {@link DataType} */ + + public Map getDataTypes() { + return mDataTypes; + } + + /** Creates on-device DOM element(s) from the {@link DataCategory}. */ + @Override + public List toOdDomElements(Document doc) { + Element dataCategoryEle = XmlUtils.createPbundleEleWithName(doc, this.getCategoryName()); + for (DataType dataType : mDataTypes.values()) { + XmlUtils.appendChildren(dataCategoryEle, dataType.toOdDomElements(doc)); + } + return XmlUtils.listOf(dataCategoryEle); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataCategoryFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataCategoryFactory.java new file mode 100644 index 000000000000..37d99e7ef85e --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataCategoryFactory.java @@ -0,0 +1,53 @@ +/* + * 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.DataTypeConstants; +import com.android.asllib.util.MalformedXmlException; +import com.android.asllib.util.XmlUtils; + +import org.w3c.dom.Element; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class DataCategoryFactory implements AslMarshallableFactory { + @Override + public DataCategory createFromHrElements(List elements) throws MalformedXmlException { + String categoryName = null; + Map dataTypeMap = new LinkedHashMap(); + for (Element ele : elements) { + categoryName = XmlUtils.getStringAttr(ele, XmlUtils.HR_ATTR_DATA_CATEGORY, true); + String dataTypeName = XmlUtils.getStringAttr(ele, XmlUtils.HR_ATTR_DATA_TYPE, true); + if (!DataTypeConstants.getValidDataTypes().containsKey(categoryName)) { + throw new MalformedXmlException( + String.format("Unrecognized data category %s", categoryName)); + } + if (!DataTypeConstants.getValidDataTypes().get(categoryName).contains(dataTypeName)) { + throw new MalformedXmlException( + String.format( + "Unrecognized data type name %s for category %s", + dataTypeName, categoryName)); + } + dataTypeMap.put( + dataTypeName, new DataTypeFactory().createFromHrElements(XmlUtils.listOf(ele))); + } + + return new DataCategory(categoryName, dataTypeMap); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataLabels.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataLabels.java new file mode 100644 index 000000000000..7516faf9f77a --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataLabels.java @@ -0,0 +1,103 @@ +/* + * 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.DataCategoryConstants; +import com.android.asllib.util.XmlUtils; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import java.util.List; +import java.util.Map; + +/** + * Data label representation with data shared and data collected maps containing zero or more {@link + * DataCategory} + */ +public class DataLabels implements AslMarshallable { + private final Map mDataAccessed; + private final Map mDataCollected; + private final Map mDataShared; + + public DataLabels( + Map dataAccessed, + Map dataCollected, + Map dataShared) { + mDataAccessed = dataAccessed; + mDataCollected = dataCollected; + mDataShared = dataShared; + } + + /** + * Returns the data accessed {@link Map} of {@link DataCategoryConstants} to {@link + * DataCategory} + */ + public Map getDataAccessed() { + return mDataAccessed; + } + + /** + * Returns the data collected {@link Map} of {@link DataCategoryConstants} to {@link + * DataCategory} + */ + public Map getDataCollected() { + return mDataCollected; + } + + /** + * Returns the data shared {@link Map} of {@link DataCategoryConstants} to {@link DataCategory} + */ + public Map getDataShared() { + return mDataShared; + } + + /** Gets the on-device DOM element for the {@link DataLabels}. */ + @Override + public List toOdDomElements(Document doc) { + Element dataLabelsEle = + XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_DATA_LABELS); + + maybeAppendDataUsages(doc, dataLabelsEle, mDataAccessed, XmlUtils.OD_NAME_DATA_ACCESSED); + maybeAppendDataUsages(doc, dataLabelsEle, mDataCollected, XmlUtils.OD_NAME_DATA_COLLECTED); + maybeAppendDataUsages(doc, dataLabelsEle, mDataShared, XmlUtils.OD_NAME_DATA_SHARED); + + return XmlUtils.listOf(dataLabelsEle); + } + + private void maybeAppendDataUsages( + Document doc, + Element dataLabelsEle, + Map dataCategoriesMap, + String dataUsageTypeName) { + if (dataCategoriesMap.isEmpty()) { + return; + } + Element dataUsageEle = XmlUtils.createPbundleEleWithName(doc, dataUsageTypeName); + + for (String dataCategoryName : dataCategoriesMap.keySet()) { + Element dataCategoryEle = XmlUtils.createPbundleEleWithName(doc, dataCategoryName); + DataCategory dataCategory = dataCategoriesMap.get(dataCategoryName); + for (String dataTypeName : dataCategory.getDataTypes().keySet()) { + DataType dataType = dataCategory.getDataTypes().get(dataTypeName); + XmlUtils.appendChildren(dataCategoryEle, dataType.toOdDomElements(doc)); + } + dataUsageEle.appendChild(dataCategoryEle); + } + dataLabelsEle.appendChild(dataUsageEle); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataLabelsFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataLabelsFactory.java new file mode 100644 index 000000000000..dc77fd08aa53 --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataLabelsFactory.java @@ -0,0 +1,124 @@ +/* + * 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.DataCategoryConstants; +import com.android.asllib.util.MalformedXmlException; +import com.android.asllib.util.XmlUtils; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class DataLabelsFactory implements AslMarshallableFactory { + + /** Creates a {@link DataLabels} from the human-readable DOM element. */ + @Override + public DataLabels createFromHrElements(List elements) throws MalformedXmlException { + Element ele = XmlUtils.getSingleElement(elements); + if (ele == null) { + AslgenUtil.logI("Found no DataLabels in hr format."); + return null; + } + Map dataAccessed = + getDataCategoriesWithTag(ele, XmlUtils.HR_TAG_DATA_ACCESSED); + Map dataCollected = + getDataCategoriesWithTag(ele, XmlUtils.HR_TAG_DATA_COLLECTED); + Map dataShared = + getDataCategoriesWithTag(ele, XmlUtils.HR_TAG_DATA_SHARED); + + // Validate booleans such as isCollectionOptional, isSharingOptional. + for (DataCategory dataCategory : dataAccessed.values()) { + for (DataType dataType : dataCategory.getDataTypes().values()) { + if (dataType.getIsSharingOptional() != null) { + throw new MalformedXmlException( + String.format( + "isSharingOptional was unexpectedly defined on a DataType" + + " belonging to data accessed: %s", + dataType.getDataTypeName())); + } + if (dataType.getIsCollectionOptional() != null) { + throw new MalformedXmlException( + String.format( + "isCollectionOptional was unexpectedly defined on a DataType" + + " belonging to data accessed: %s", + dataType.getDataTypeName())); + } + } + } + for (DataCategory dataCategory : dataCollected.values()) { + for (DataType dataType : dataCategory.getDataTypes().values()) { + if (dataType.getIsSharingOptional() != null) { + throw new MalformedXmlException( + String.format( + "isSharingOptional was unexpectedly defined on a DataType" + + " belonging to data collected: %s", + dataType.getDataTypeName())); + } + } + } + for (DataCategory dataCategory : dataShared.values()) { + for (DataType dataType : dataCategory.getDataTypes().values()) { + if (dataType.getIsCollectionOptional() != null) { + throw new MalformedXmlException( + String.format( + "isCollectionOptional was unexpectedly defined on a DataType" + + " belonging to data shared: %s", + dataType.getDataTypeName())); + } + } + } + + return new DataLabels(dataAccessed, dataCollected, dataShared); + } + + private static Map getDataCategoriesWithTag( + Element dataLabelsEle, String dataCategoryUsageTypeTag) throws MalformedXmlException { + NodeList dataUsedNodeList = dataLabelsEle.getElementsByTagName(dataCategoryUsageTypeTag); + Map dataCategoryMap = new LinkedHashMap(); + + Set dataCategoryNames = new HashSet(); + for (int i = 0; i < dataUsedNodeList.getLength(); i++) { + Element dataUsedEle = (Element) dataUsedNodeList.item(i); + String dataCategoryName = dataUsedEle.getAttribute(XmlUtils.HR_ATTR_DATA_CATEGORY); + if (!DataCategoryConstants.getValidDataCategories().contains(dataCategoryName)) { + throw new MalformedXmlException( + String.format("Unrecognized category name: %s", dataCategoryName)); + } + dataCategoryNames.add(dataCategoryName); + } + for (String dataCategoryName : dataCategoryNames) { + var dataCategoryElements = + XmlUtils.asElementList(dataUsedNodeList).stream() + .filter( + ele -> + ele.getAttribute(XmlUtils.HR_ATTR_DATA_CATEGORY) + .equals(dataCategoryName)) + .toList(); + DataCategory dataCategory = + new DataCategoryFactory().createFromHrElements(dataCategoryElements); + dataCategoryMap.put(dataCategoryName, dataCategory); + } + return dataCategoryMap; + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataType.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataType.java new file mode 100644 index 000000000000..347136237966 --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataType.java @@ -0,0 +1,171 @@ +/* + * 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; +import java.util.Set; + +/** + * Data usage type representation. Types are specific to a {@link DataCategory} and contains + * metadata related to the data usage purpose. + */ +public class DataType implements AslMarshallable { + + public enum Purpose { + APP_FUNCTIONALITY(1), + ANALYTICS(2), + DEVELOPER_COMMUNICATIONS(3), + FRAUD_PREVENTION_SECURITY(4), + ADVERTISING(5), + PERSONALIZATION(6), + ACCOUNT_MANAGEMENT(7); + + private final int mValue; + + Purpose(int value) { + this.mValue = value; + } + + /** Get the int value associated with the Purpose. */ + public int getValue() { + return mValue; + } + + /** Get the Purpose associated with the int value. */ + public static Purpose forValue(int value) { + for (Purpose e : values()) { + if (e.getValue() == value) { + return e; + } + } + throw new IllegalArgumentException("No Purpose enum for value: " + value); + } + + /** Get the Purpose associated with the human-readable String. */ + public static Purpose forString(String s) { + for (Purpose e : values()) { + if (e.toString().equals(s)) { + return e; + } + } + throw new IllegalArgumentException("No Purpose enum for str: " + s); + } + + /** Human-readable String representation of Purpose. */ + public String toString() { + return this.name().toLowerCase(); + } + } + + private final String mDataTypeName; + + private final List mPurposes; + private final Boolean mIsCollectionOptional; + private final Boolean mIsSharingOptional; + private final Boolean mEphemeral; + + public DataType( + String dataTypeName, + List purposes, + Boolean isCollectionOptional, + Boolean isSharingOptional, + Boolean ephemeral) { + this.mDataTypeName = dataTypeName; + this.mPurposes = purposes; + this.mIsCollectionOptional = isCollectionOptional; + this.mIsSharingOptional = isSharingOptional; + this.mEphemeral = ephemeral; + } + + public String getDataTypeName() { + return mDataTypeName; + } + + /** + * Returns {@link Set} of valid {@link Integer} purposes for using the associated data category + * and type + */ + public List getPurposes() { + return mPurposes; + } + + /** + * For data-collected, returns {@code true} if data usage is user optional and {@code false} if + * data usage is required. Should return {@code null} for data-accessed and data-shared. + */ + public Boolean getIsCollectionOptional() { + return mIsCollectionOptional; + } + + /** + * For data-shared, returns {@code true} if data usage is user optional and {@code false} if + * data usage is required. Should return {@code null} for data-accessed and data-collected. + */ + public Boolean getIsSharingOptional() { + return mIsSharingOptional; + } + + /** + * For data-collected, returns {@code true} if data usage is user optional and {@code false} if + * data usage is processed ephemerally. Should return {@code null} for data-shared. + */ + public Boolean getEphemeral() { + return mEphemeral; + } + + @Override + public List toOdDomElements(Document doc) { + Element dataTypeEle = XmlUtils.createPbundleEleWithName(doc, this.getDataTypeName()); + if (!this.getPurposes().isEmpty()) { + dataTypeEle.appendChild( + XmlUtils.createOdArray( + doc, + XmlUtils.OD_TAG_INT_ARRAY, + XmlUtils.OD_NAME_PURPOSES, + this.getPurposes().stream() + .map(p -> String.valueOf(p.getValue())) + .toList())); + } + + maybeAddBoolToOdElement( + doc, + dataTypeEle, + this.getIsCollectionOptional(), + XmlUtils.OD_NAME_IS_COLLECTION_OPTIONAL); + maybeAddBoolToOdElement( + doc, + dataTypeEle, + this.getIsSharingOptional(), + XmlUtils.OD_NAME_IS_SHARING_OPTIONAL); + maybeAddBoolToOdElement(doc, dataTypeEle, this.getEphemeral(), XmlUtils.OD_NAME_EPHEMERAL); + return XmlUtils.listOf(dataTypeEle); + } + + private static void maybeAddBoolToOdElement( + Document doc, Element parentEle, Boolean b, String odName) { + if (b == null) { + return; + } + Element ele = XmlUtils.createOdBooleanEle(doc, odName, b); + parentEle.appendChild(ele); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataTypeFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataTypeFactory.java new file mode 100644 index 000000000000..ed434cda0823 --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DataTypeFactory.java @@ -0,0 +1,54 @@ +/* + * 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.MalformedXmlException; +import com.android.asllib.util.XmlUtils; + +import org.w3c.dom.Element; + +import java.util.HashSet; +import java.util.List; +import java.util.stream.Collectors; + +public class DataTypeFactory implements AslMarshallableFactory { + /** Creates a {@link DataType} from the human-readable DOM element. */ + @Override + public DataType createFromHrElements(List elements) throws MalformedXmlException { + Element hrDataTypeEle = XmlUtils.getSingleElement(elements); + String dataTypeName = hrDataTypeEle.getAttribute(XmlUtils.HR_ATTR_DATA_TYPE); + List purposes = + XmlUtils.getPipelineSplitAttr(hrDataTypeEle, XmlUtils.HR_ATTR_PURPOSES, true) + .stream() + .map(DataType.Purpose::forString) + .collect(Collectors.toList()); + if (purposes.isEmpty()) { + throw new MalformedXmlException(String.format("Found no purpose in: %s", dataTypeName)); + } + if (new HashSet<>(purposes).size() != purposes.size()) { + throw new MalformedXmlException( + String.format("Found non-unique purposes in: %s", dataTypeName)); + } + Boolean isCollectionOptional = + XmlUtils.getBoolAttr(hrDataTypeEle, XmlUtils.HR_ATTR_IS_COLLECTION_OPTIONAL, false); + Boolean isSharingOptional = + XmlUtils.getBoolAttr(hrDataTypeEle, XmlUtils.HR_ATTR_IS_SHARING_OPTIONAL, false); + Boolean ephemeral = XmlUtils.getBoolAttr(hrDataTypeEle, XmlUtils.HR_ATTR_EPHEMERAL, false); + return new DataType( + dataTypeName, purposes, isCollectionOptional, isSharingOptional, ephemeral); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfo.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfo.java new file mode 100644 index 000000000000..382a1f0d0eca --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfo.java @@ -0,0 +1,142 @@ +/* + * 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; + +/** DeveloperInfo representation */ +public class DeveloperInfo implements AslMarshallable { + public enum DeveloperRelationship { + OEM(0), + ODM(1), + SOC(2), + OTA(3), + CARRIER(4), + AOSP(5), + OTHER(6); + + private final int mValue; + + DeveloperRelationship(int value) { + this.mValue = value; + } + + /** Get the int value associated with the DeveloperRelationship. */ + public int getValue() { + return mValue; + } + + /** Get the DeveloperRelationship associated with the int value. */ + public static DeveloperInfo.DeveloperRelationship forValue(int value) { + for (DeveloperInfo.DeveloperRelationship e : values()) { + if (e.getValue() == value) { + return e; + } + } + throw new IllegalArgumentException("No DeveloperRelationship enum for value: " + value); + } + + /** Get the DeveloperRelationship associated with the human-readable String. */ + public static DeveloperInfo.DeveloperRelationship forString(String s) { + for (DeveloperInfo.DeveloperRelationship e : values()) { + if (e.toString().equals(s)) { + return e; + } + } + throw new IllegalArgumentException("No DeveloperRelationship enum for str: " + s); + } + + /** Human-readable String representation of DeveloperRelationship. */ + public String toString() { + return this.name().toLowerCase(); + } + } + + private final String mName; + private final String mEmail; + private final String mAddress; + private final String mCountryRegion; + private final DeveloperRelationship mDeveloperRelationship; + private final String mWebsite; + private final String mAppDeveloperRegistryId; + + public DeveloperInfo( + String name, + String email, + String address, + String countryRegion, + DeveloperRelationship developerRelationship, + String website, + String appDeveloperRegistryId) { + this.mName = name; + this.mEmail = email; + this.mAddress = address; + this.mCountryRegion = countryRegion; + this.mDeveloperRelationship = developerRelationship; + this.mWebsite = website; + this.mAppDeveloperRegistryId = appDeveloperRegistryId; + } + + /** Creates an on-device DOM element from the {@link SafetyLabels}. */ + @Override + public List toOdDomElements(Document doc) { + Element developerInfoEle = + XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_DEVELOPER_INFO); + if (mName != null) { + developerInfoEle.appendChild( + XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_NAME, mName)); + } + if (mEmail != null) { + developerInfoEle.appendChild( + XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_EMAIL, mEmail)); + } + if (mAddress != null) { + developerInfoEle.appendChild( + XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_ADDRESS, mAddress)); + } + if (mCountryRegion != null) { + developerInfoEle.appendChild( + XmlUtils.createOdStringEle( + doc, XmlUtils.OD_NAME_COUNTRY_REGION, mCountryRegion)); + } + if (mDeveloperRelationship != null) { + developerInfoEle.appendChild( + XmlUtils.createOdLongEle( + doc, + XmlUtils.OD_NAME_DEVELOPER_RELATIONSHIP, + mDeveloperRelationship.getValue())); + } + if (mWebsite != null) { + developerInfoEle.appendChild( + XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_WEBSITE, mWebsite)); + } + if (mAppDeveloperRegistryId != null) { + developerInfoEle.appendChild( + XmlUtils.createOdStringEle( + doc, + XmlUtils.OD_NAME_APP_DEVELOPER_REGISTRY_ID, + mAppDeveloperRegistryId)); + } + + return XmlUtils.listOf(developerInfoEle); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfoFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfoFactory.java new file mode 100644 index 000000000000..b5310bac232a --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfoFactory.java @@ -0,0 +1,60 @@ +/* + * 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 DeveloperInfoFactory implements AslMarshallableFactory { + + /** Creates a {@link DeveloperInfo} from the human-readable DOM element. */ + @Override + public DeveloperInfo createFromHrElements(List elements) throws MalformedXmlException { + Element developerInfoEle = XmlUtils.getSingleElement(elements); + if (developerInfoEle == null) { + AslgenUtil.logI("No DeveloperInfo found in hr format."); + return null; + } + String name = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_NAME); + String email = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_EMAIL); + String address = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_ADDRESS); + String countryRegion = + XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_COUNTRY_REGION); + DeveloperInfo.DeveloperRelationship developerRelationship = + DeveloperInfo.DeveloperRelationship.forString( + XmlUtils.getStringAttr( + developerInfoEle, XmlUtils.HR_ATTR_DEVELOPER_RELATIONSHIP)); + String website = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_WEBSITE, false); + String appDeveloperRegistryId = + XmlUtils.getStringAttr( + developerInfoEle, XmlUtils.HR_ATTR_APP_DEVELOPER_REGISTRY_ID, false); + + return new DeveloperInfo( + name, + email, + address, + countryRegion, + developerRelationship, + website, + appDeveloperRegistryId); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SafetyLabels.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SafetyLabels.java new file mode 100644 index 000000000000..22c3fd8f2a1c --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SafetyLabels.java @@ -0,0 +1,59 @@ +/* + * 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; + +/** Safety Label representation containing zero or more {@link DataCategory} for data shared */ +public class SafetyLabels implements AslMarshallable { + + private final Long mVersion; + private final DataLabels mDataLabels; + + public SafetyLabels(Long version, DataLabels dataLabels) { + this.mVersion = version; + this.mDataLabels = dataLabels; + } + + /** Returns the data label for the safety label */ + public DataLabels getDataLabel() { + return mDataLabels; + } + + /** Gets the version of the {@link SafetyLabels}. */ + public Long getVersion() { + return mVersion; + } + + /** Creates an on-device DOM element from the {@link SafetyLabels}. */ + @Override + public List toOdDomElements(Document doc) { + Element safetyLabelsEle = + XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_SAFETY_LABELS); + safetyLabelsEle.appendChild( + XmlUtils.createOdLongEle(doc, XmlUtils.OD_NAME_VERSION, mVersion)); + if (mDataLabels != null) { + XmlUtils.appendChildren(safetyLabelsEle, mDataLabels.toOdDomElements(doc)); + } + return XmlUtils.listOf(safetyLabelsEle); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SafetyLabelsFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SafetyLabelsFactory.java new file mode 100644 index 000000000000..6bf8ef3df32d --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SafetyLabelsFactory.java @@ -0,0 +1,49 @@ +/* + * 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 SafetyLabelsFactory implements AslMarshallableFactory { + + /** Creates a {@link SafetyLabels} from the human-readable DOM element. */ + @Override + public SafetyLabels createFromHrElements(List elements) throws MalformedXmlException { + Element safetyLabelsEle = XmlUtils.getSingleElement(elements); + if (safetyLabelsEle == null) { + AslgenUtil.logI("No SafetyLabels found in hr format."); + return null; + } + long version = XmlUtils.tryGetVersion(safetyLabelsEle); + + DataLabels dataLabels = + new DataLabelsFactory() + .createFromHrElements( + XmlUtils.listOf( + XmlUtils.getSingleChildElement( + safetyLabelsEle, + XmlUtils.HR_TAG_DATA_LABELS, + false))); + return new SafetyLabels(version, dataLabels); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SystemAppSafetyLabel.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SystemAppSafetyLabel.java new file mode 100644 index 000000000000..595d748b59af --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SystemAppSafetyLabel.java @@ -0,0 +1,49 @@ +/* + * 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; + +/** Safety Label representation containing zero or more {@link DataCategory} for data shared */ +public class SystemAppSafetyLabel implements AslMarshallable { + + private final String mUrl; + + public SystemAppSafetyLabel(String url) { + this.mUrl = url; + } + + /** Returns the system app safety label URL. */ + public String getUrl() { + return mUrl; + } + + /** Creates an on-device DOM element from the {@link SystemAppSafetyLabel}. */ + @Override + public List toOdDomElements(Document doc) { + Element systemAppSafetyLabelEle = + XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_SYSTEM_APP_SAFETY_LABEL); + systemAppSafetyLabelEle.appendChild( + XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_URL, mUrl)); + return XmlUtils.listOf(systemAppSafetyLabelEle); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SystemAppSafetyLabelFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SystemAppSafetyLabelFactory.java new file mode 100644 index 000000000000..f99955993d6c --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/SystemAppSafetyLabelFactory.java @@ -0,0 +1,42 @@ +/* + * 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 SystemAppSafetyLabelFactory implements AslMarshallableFactory { + + /** Creates a {@link SystemAppSafetyLabel} from the human-readable DOM element. */ + @Override + public SystemAppSafetyLabel createFromHrElements(List elements) + throws MalformedXmlException { + Element systemAppSafetyLabelEle = XmlUtils.getSingleElement(elements); + if (systemAppSafetyLabelEle == null) { + AslgenUtil.logI("No SystemAppSafetyLabel found in hr format."); + return null; + } + + String url = XmlUtils.getStringAttr(systemAppSafetyLabelEle, XmlUtils.HR_ATTR_URL); + return new SystemAppSafetyLabel(url); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/TransparencyInfo.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/TransparencyInfo.java new file mode 100644 index 000000000000..ddd3557616ca --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/TransparencyInfo.java @@ -0,0 +1,60 @@ +/* + * 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; + +/** TransparencyInfo representation containing {@link DeveloperInfo} and {@link AppInfo} */ +public class TransparencyInfo implements AslMarshallable { + + private final DeveloperInfo mDeveloperInfo; + private final AppInfo mAppInfo; + + public TransparencyInfo(DeveloperInfo developerInfo, AppInfo appInfo) { + this.mDeveloperInfo = developerInfo; + this.mAppInfo = appInfo; + } + + /** Gets the {@link DeveloperInfo} of the {@link TransparencyInfo}. */ + public DeveloperInfo getDeveloperInfo() { + return mDeveloperInfo; + } + + /** Gets the {@link AppInfo} of the {@link TransparencyInfo}. */ + public AppInfo getAppInfo() { + return mAppInfo; + } + + /** Creates an on-device DOM element from the {@link TransparencyInfo}. */ + @Override + public List toOdDomElements(Document doc) { + Element transparencyInfoEle = + XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_TRANSPARENCY_INFO); + if (mDeveloperInfo != null) { + XmlUtils.appendChildren(transparencyInfoEle, mDeveloperInfo.toOdDomElements(doc)); + } + if (mAppInfo != null) { + XmlUtils.appendChildren(transparencyInfoEle, mAppInfo.toOdDomElements(doc)); + } + return XmlUtils.listOf(transparencyInfoEle); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/TransparencyInfoFactory.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/TransparencyInfoFactory.java new file mode 100644 index 000000000000..d9c2af41fcac --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/TransparencyInfoFactory.java @@ -0,0 +1,52 @@ +/* + * 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 TransparencyInfoFactory implements AslMarshallableFactory { + + /** Creates a {@link TransparencyInfo} from the human-readable DOM element. */ + @Override + public TransparencyInfo createFromHrElements(List elements) + throws MalformedXmlException { + Element transparencyInfoEle = XmlUtils.getSingleElement(elements); + if (transparencyInfoEle == null) { + AslgenUtil.logI("No TransparencyInfo found in hr format."); + return null; + } + + Element developerInfoEle = + XmlUtils.getSingleChildElement( + transparencyInfoEle, XmlUtils.HR_TAG_DEVELOPER_INFO, false); + DeveloperInfo developerInfo = + new DeveloperInfoFactory().createFromHrElements(XmlUtils.listOf(developerInfoEle)); + + Element appInfoEle = + XmlUtils.getSingleChildElement( + transparencyInfoEle, XmlUtils.HR_TAG_APP_INFO, false); + AppInfo appInfo = new AppInfoFactory().createFromHrElements(XmlUtils.listOf(appInfoEle)); + + return new TransparencyInfo(developerInfo, appInfo); + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/DataCategoryConstants.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/DataCategoryConstants.java new file mode 100644 index 000000000000..b5ae54c5bc00 --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/DataCategoryConstants.java @@ -0,0 +1,77 @@ +/* + * 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.util; + +import com.android.asllib.marshallable.DataCategory; +import com.android.asllib.marshallable.DataType; +import com.android.asllib.marshallable.SafetyLabels; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * Constants for determining valid {@link String} data types for usage within {@link SafetyLabels}, + * {@link DataCategory}, and {@link DataType} + */ +public class DataCategoryConstants { + + public static final String CATEGORY_PERSONAL = "personal"; + public static final String CATEGORY_FINANCIAL = "financial"; + public static final String CATEGORY_LOCATION = "location"; + public static final String CATEGORY_EMAIL_TEXT_MESSAGE = "email_text_message"; + public static final String CATEGORY_PHOTO_VIDEO = "photo_video"; + public static final String CATEGORY_AUDIO = "audio"; + public static final String CATEGORY_STORAGE = "storage"; + public static final String CATEGORY_HEALTH_FITNESS = "health_fitness"; + public static final String CATEGORY_CONTACTS = "contacts"; + public static final String CATEGORY_CALENDAR = "calendar"; + public static final String CATEGORY_IDENTIFIERS = "identifiers"; + public static final String CATEGORY_APP_PERFORMANCE = "app_performance"; + public static final String CATEGORY_ACTIONS_IN_APP = "actions_in_app"; + public static final String CATEGORY_SEARCH_AND_BROWSING = "search_and_browsing"; + + /** Set of valid categories */ + public static final Set VALID_CATEGORIES = + Collections.unmodifiableSet( + new HashSet<>( + Arrays.asList( + CATEGORY_PERSONAL, + CATEGORY_FINANCIAL, + CATEGORY_LOCATION, + CATEGORY_EMAIL_TEXT_MESSAGE, + CATEGORY_PHOTO_VIDEO, + CATEGORY_AUDIO, + CATEGORY_STORAGE, + CATEGORY_HEALTH_FITNESS, + CATEGORY_CONTACTS, + CATEGORY_CALENDAR, + CATEGORY_IDENTIFIERS, + CATEGORY_APP_PERFORMANCE, + CATEGORY_ACTIONS_IN_APP, + CATEGORY_SEARCH_AND_BROWSING))); + + /** Returns {@link Set} of valid {@link String} category keys */ + public static Set getValidDataCategories() { + return VALID_CATEGORIES; + } + + private DataCategoryConstants() { + /* do nothing - hide constructor */ + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/DataTypeConstants.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/DataTypeConstants.java new file mode 100644 index 000000000000..358d575c1d56 --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/DataTypeConstants.java @@ -0,0 +1,197 @@ +/* + * 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.util; + +import com.android.asllib.marshallable.DataCategory; +import com.android.asllib.marshallable.DataType; +import com.android.asllib.marshallable.SafetyLabels; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +import java.util.Map; +import java.util.Set; + +/** + * Constants for determining valid {@link String} data types for usage within {@link SafetyLabels}, + * {@link DataCategory}, and {@link DataType} + */ +public class DataTypeConstants { + /** Data types for {@link DataCategoryConstants.CATEGORY_PERSONAL} */ + public static final String TYPE_NAME = "name"; + + public static final String TYPE_EMAIL_ADDRESS = "email_address"; + public static final String TYPE_PHYSICAL_ADDRESS = "physical_address"; + public static final String TYPE_PHONE_NUMBER = "phone_number"; + public static final String TYPE_RACE_ETHNICITY = "race_ethnicity"; + public static final String TYPE_POLITICAL_OR_RELIGIOUS_BELIEFS = + "political_or_religious_beliefs"; + public static final String TYPE_SEXUAL_ORIENTATION_OR_GENDER_IDENTITY = + "sexual_orientation_or_gender_identity"; + public static final String TYPE_PERSONAL_IDENTIFIERS = "personal_identifiers"; + public static final String TYPE_OTHER = "other"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_FINANCIAL} */ + public static final String TYPE_CARD_BANK_ACCOUNT = "card_bank_account"; + + public static final String TYPE_PURCHASE_HISTORY = "purchase_history"; + public static final String TYPE_CREDIT_SCORE = "credit_score"; + public static final String TYPE_FINANCIAL_OTHER = "other"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_LOCATION} */ + public static final String TYPE_APPROX_LOCATION = "approx_location"; + + public static final String TYPE_PRECISE_LOCATION = "precise_location"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_EMAIL_TEXT_MESSAGE} */ + public static final String TYPE_EMAILS = "emails"; + + public static final String TYPE_TEXT_MESSAGES = "text_messages"; + public static final String TYPE_EMAIL_TEXT_MESSAGE_OTHER = "other"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_PHOTO_VIDEO} */ + public static final String TYPE_PHOTOS = "photos"; + + public static final String TYPE_VIDEOS = "videos"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_AUDIO} */ + public static final String TYPE_SOUND_RECORDINGS = "sound_recordings"; + + public static final String TYPE_MUSIC_FILES = "music_files"; + public static final String TYPE_AUDIO_OTHER = "other"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_STORAGE} */ + public static final String TYPE_FILES_DOCS = "files_docs"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_HEALTH_FITNESS} */ + public static final String TYPE_HEALTH = "health"; + + public static final String TYPE_FITNESS = "fitness"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_CONTACTS} */ + public static final String TYPE_CONTACTS = "contacts"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_CALENDAR} */ + public static final String TYPE_CALENDAR = "calendar"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_IDENTIFIERS} */ + public static final String TYPE_IDENTIFIERS_OTHER = "other"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_APP_PERFORMANCE} */ + public static final String TYPE_CRASH_LOGS = "crash_logs"; + + public static final String TYPE_PERFORMANCE_DIAGNOSTICS = "performance_diagnostics"; + public static final String TYPE_APP_PERFORMANCE_OTHER = "other"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_ACTIONS_IN_APP} */ + public static final String TYPE_USER_INTERACTION = "user_interaction"; + + public static final String TYPE_IN_APP_SEARCH_HISTORY = "in_app_search_history"; + public static final String TYPE_INSTALLED_APPS = "installed_apps"; + public static final String TYPE_USER_GENERATED_CONTENT = "user_generated_content"; + public static final String TYPE_ACTIONS_IN_APP_OTHER = "other"; + + /** Data types for {@link DataCategoryConstants.CATEGORY_SEARCH_AND_BROWSING} */ + public static final String TYPE_WEB_BROWSING_HISTORY = "web_browsing_history"; + + /** Set of valid categories */ + private static final Map> VALID_DATA_TYPES = + new ImmutableMap.Builder>() + .put( + DataCategoryConstants.CATEGORY_PERSONAL, + ImmutableSet.of( + DataTypeConstants.TYPE_NAME, + DataTypeConstants.TYPE_EMAIL_ADDRESS, + DataTypeConstants.TYPE_PHYSICAL_ADDRESS, + DataTypeConstants.TYPE_PHONE_NUMBER, + DataTypeConstants.TYPE_RACE_ETHNICITY, + DataTypeConstants.TYPE_POLITICAL_OR_RELIGIOUS_BELIEFS, + DataTypeConstants.TYPE_SEXUAL_ORIENTATION_OR_GENDER_IDENTITY, + DataTypeConstants.TYPE_PERSONAL_IDENTIFIERS, + DataTypeConstants.TYPE_OTHER)) + .put( + DataCategoryConstants.CATEGORY_FINANCIAL, + ImmutableSet.of( + DataTypeConstants.TYPE_CARD_BANK_ACCOUNT, + DataTypeConstants.TYPE_PURCHASE_HISTORY, + DataTypeConstants.TYPE_CREDIT_SCORE, + DataTypeConstants.TYPE_OTHER)) + .put( + DataCategoryConstants.CATEGORY_LOCATION, + ImmutableSet.of( + DataTypeConstants.TYPE_APPROX_LOCATION, + DataTypeConstants.TYPE_PRECISE_LOCATION)) + .put( + DataCategoryConstants.CATEGORY_EMAIL_TEXT_MESSAGE, + ImmutableSet.of( + DataTypeConstants.TYPE_EMAILS, + DataTypeConstants.TYPE_TEXT_MESSAGES, + DataTypeConstants.TYPE_OTHER)) + .put( + DataCategoryConstants.CATEGORY_PHOTO_VIDEO, + ImmutableSet.of( + DataTypeConstants.TYPE_PHOTOS, DataTypeConstants.TYPE_VIDEOS)) + .put( + DataCategoryConstants.CATEGORY_AUDIO, + ImmutableSet.of( + DataTypeConstants.TYPE_SOUND_RECORDINGS, + DataTypeConstants.TYPE_MUSIC_FILES, + DataTypeConstants.TYPE_OTHER)) + .put( + DataCategoryConstants.CATEGORY_STORAGE, + ImmutableSet.of(DataTypeConstants.TYPE_FILES_DOCS)) + .put( + DataCategoryConstants.CATEGORY_HEALTH_FITNESS, + ImmutableSet.of( + DataTypeConstants.TYPE_HEALTH, DataTypeConstants.TYPE_FITNESS)) + .put( + DataCategoryConstants.CATEGORY_CONTACTS, + ImmutableSet.of(DataTypeConstants.TYPE_CONTACTS)) + .put( + DataCategoryConstants.CATEGORY_CALENDAR, + ImmutableSet.of(DataTypeConstants.TYPE_CALENDAR)) + .put( + DataCategoryConstants.CATEGORY_IDENTIFIERS, + ImmutableSet.of(DataTypeConstants.TYPE_OTHER)) + .put( + DataCategoryConstants.CATEGORY_APP_PERFORMANCE, + ImmutableSet.of( + DataTypeConstants.TYPE_CRASH_LOGS, + DataTypeConstants.TYPE_PERFORMANCE_DIAGNOSTICS, + DataTypeConstants.TYPE_OTHER)) + .put( + DataCategoryConstants.CATEGORY_ACTIONS_IN_APP, + ImmutableSet.of( + DataTypeConstants.TYPE_USER_INTERACTION, + DataTypeConstants.TYPE_IN_APP_SEARCH_HISTORY, + DataTypeConstants.TYPE_INSTALLED_APPS, + DataTypeConstants.TYPE_USER_GENERATED_CONTENT, + DataTypeConstants.TYPE_OTHER)) + .put( + DataCategoryConstants.CATEGORY_SEARCH_AND_BROWSING, + ImmutableSet.of(DataTypeConstants.TYPE_WEB_BROWSING_HISTORY)) + .buildOrThrow(); + + /** Returns {@link Set} of valid {@link String} category keys */ + public static Map> getValidDataTypes() { + return VALID_DATA_TYPES; + } + + private DataTypeConstants() { + /* do nothing - hide constructor */ + } +} diff --git a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/XmlUtils.java b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/XmlUtils.java new file mode 100644 index 000000000000..691f92fca54b --- /dev/null +++ b/tools/app_metadata_bundles/src/lib/java/com/android/asllib/util/XmlUtils.java @@ -0,0 +1,327 @@ +/* + * 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.util; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class XmlUtils { + public static final String HR_TAG_APP_METADATA_BUNDLES = "app-metadata-bundles"; + public static final String HR_TAG_SYSTEM_APP_SAFETY_LABEL = "system-app-safety-label"; + public static final String HR_TAG_SAFETY_LABELS = "safety-labels"; + public static final String HR_TAG_TRANSPARENCY_INFO = "transparency-info"; + public static final String HR_TAG_DEVELOPER_INFO = "developer-info"; + public static final String HR_TAG_APP_INFO = "app-info"; + public static final String HR_TAG_DATA_LABELS = "data-labels"; + public static final String HR_TAG_DATA_ACCESSED = "data-accessed"; + public static final String HR_TAG_DATA_COLLECTED = "data-collected"; + public static final String HR_TAG_DATA_SHARED = "data-shared"; + public static final String HR_ATTR_NAME = "name"; + public static final String HR_ATTR_EMAIL = "email"; + public static final String HR_ATTR_ADDRESS = "address"; + public static final String HR_ATTR_COUNTRY_REGION = "countryRegion"; + public static final String HR_ATTR_DEVELOPER_RELATIONSHIP = "relationship"; + public static final String HR_ATTR_WEBSITE = "website"; + public static final String HR_ATTR_APP_DEVELOPER_REGISTRY_ID = "registryId"; + public static final String HR_ATTR_DATA_CATEGORY = "dataCategory"; + public static final String HR_ATTR_DATA_TYPE = "dataType"; + public static final String HR_ATTR_IS_COLLECTION_OPTIONAL = "isCollectionOptional"; + public static final String HR_ATTR_IS_SHARING_OPTIONAL = "isSharingOptional"; + public static final String HR_ATTR_EPHEMERAL = "ephemeral"; + public static final String HR_ATTR_PURPOSES = "purposes"; + public static final String HR_ATTR_VERSION = "version"; + public static final String HR_ATTR_URL = "url"; + public static final String HR_ATTR_TITLE = "title"; + public static final String HR_ATTR_DESCRIPTION = "description"; + public static final String HR_ATTR_CONTAINS_ADS = "containsAds"; + public static final String HR_ATTR_OBEY_APS = "obeyAps"; + public static final String HR_ATTR_ADS_FINGERPRINTING = "adsFingerprinting"; + public static final String HR_ATTR_SECURITY_FINGERPRINTING = "securityFingerprinting"; + public static final String HR_ATTR_PRIVACY_POLICY = "privacyPolicy"; + public static final String HR_ATTR_SECURITY_ENDPOINTS = "securityEndpoints"; + public static final String HR_ATTR_FIRST_PARTY_ENDPOINTS = "firstPartyEndpoints"; + public static final String HR_ATTR_SERVICE_PROVIDER_ENDPOINTS = "serviceProviderEndpoints"; + public static final String HR_ATTR_CATEGORY = "category"; + + public static final String OD_TAG_BUNDLE = "bundle"; + public static final String OD_TAG_PBUNDLE_AS_MAP = "pbundle_as_map"; + public static final String OD_TAG_BOOLEAN = "boolean"; + public static final String OD_TAG_LONG = "long"; + public static final String OD_TAG_STRING = "string"; + public static final String OD_TAG_INT_ARRAY = "int-array"; + public static final String OD_TAG_STRING_ARRAY = "string-array"; + public static final String OD_TAG_ITEM = "item"; + public static final String OD_ATTR_NAME = "name"; + public static final String OD_ATTR_VALUE = "value"; + public static final String OD_ATTR_NUM = "num"; + public static final String OD_NAME_SAFETY_LABELS = "safety_labels"; + public static final String OD_NAME_TRANSPARENCY_INFO = "transparency_info"; + public static final String OD_NAME_DEVELOPER_INFO = "developer_info"; + public static final String OD_NAME_NAME = "name"; + public static final String OD_NAME_EMAIL = "email"; + public static final String OD_NAME_ADDRESS = "address"; + public static final String OD_NAME_COUNTRY_REGION = "country_region"; + public static final String OD_NAME_DEVELOPER_RELATIONSHIP = "relationship"; + public static final String OD_NAME_WEBSITE = "website"; + public static final String OD_NAME_APP_DEVELOPER_REGISTRY_ID = "app_developer_registry_id"; + public static final String OD_NAME_APP_INFO = "app_info"; + public static final String OD_NAME_TITLE = "title"; + public static final String OD_NAME_DESCRIPTION = "description"; + public static final String OD_NAME_CONTAINS_ADS = "contains_ads"; + public static final String OD_NAME_OBEY_APS = "obey_aps"; + public static final String OD_NAME_ADS_FINGERPRINTING = "ads_fingerprinting"; + public static final String OD_NAME_SECURITY_FINGERPRINTING = "security_fingerprinting"; + public static final String OD_NAME_PRIVACY_POLICY = "privacy_policy"; + public static final String OD_NAME_SECURITY_ENDPOINT = "security_endpoint"; + public static final String OD_NAME_FIRST_PARTY_ENDPOINT = "first_party_endpoint"; + public static final String OD_NAME_SERVICE_PROVIDER_ENDPOINT = "service_provider_endpoint"; + public static final String OD_NAME_CATEGORY = "category"; + public static final String OD_NAME_VERSION = "version"; + public static final String OD_NAME_URL = "url"; + public static final String OD_NAME_SYSTEM_APP_SAFETY_LABEL = "system_app_safety_label"; + public static final String OD_NAME_DATA_LABELS = "data_labels"; + public static final String OD_NAME_DATA_ACCESSED = "data_accessed"; + public static final String OD_NAME_DATA_COLLECTED = "data_collected"; + public static final String OD_NAME_DATA_SHARED = "data_shared"; + public static final String OD_NAME_PURPOSES = "purposes"; + public static final String OD_NAME_IS_COLLECTION_OPTIONAL = "is_collection_optional"; + public static final String OD_NAME_IS_SHARING_OPTIONAL = "is_sharing_optional"; + public static final String OD_NAME_EPHEMERAL = "ephemeral"; + + public static final String TRUE_STR = "true"; + public static final String FALSE_STR = "false"; + + /** Gets the single top-level {@link Element} having the {@param tagName}. */ + public static Element getSingleElement(Document doc, String tagName) + throws MalformedXmlException { + var elements = doc.getElementsByTagName(tagName); + return getSingleElement(elements, tagName); + } + + /** + * Gets the single {@link Element} within {@param parentEle} and having the {@param tagName}. + */ + public static Element getSingleChildElement(Element parentEle, String tagName) + throws MalformedXmlException { + var elements = parentEle.getElementsByTagName(tagName); + return getSingleElement(elements, tagName, true); + } + + /** + * Gets the single {@link Element} within {@param parentEle} and having the {@param tagName}. + */ + public static Element getSingleChildElement(Element parentEle, String tagName, boolean required) + throws MalformedXmlException { + var elements = parentEle.getElementsByTagName(tagName); + return getSingleElement(elements, tagName, required); + } + + /** Gets the single {@link Element} from {@param elements} */ + public static Element getSingleElement(NodeList elements, String tagName) + throws MalformedXmlException { + return getSingleElement(elements, tagName, true); + } + + /** Gets the single {@link Element} from {@param elements} */ + public static Element getSingleElement(NodeList elements, String tagName, boolean required) + throws MalformedXmlException { + if (elements.getLength() > 1) { + throw new MalformedXmlException( + String.format( + "Expected 1 element \"%s\" in NodeList but got %s.", + tagName, elements.getLength())); + } else if (elements.getLength() == 0) { + if (required) { + throw new MalformedXmlException( + String.format("Found no element \"%s\" in NodeList.", tagName)); + } else { + return null; + } + } + var elementAsNode = elements.item(0); + if (!(elementAsNode instanceof Element)) { + throw new MalformedXmlException( + String.format("%s was not a valid XML element.", tagName)); + } + return ((Element) elementAsNode); + } + + /** Gets the single {@link Element} within {@param elements}. */ + public static Element getSingleElement(List elements) { + if (elements.size() != 1) { + throw new IllegalStateException( + String.format("Expected 1 element in list but got %s.", elements.size())); + } + return elements.get(0); + } + + /** Converts {@param nodeList} into List of {@link Element}. */ + public static List asElementList(NodeList nodeList) { + List elementList = new ArrayList(); + for (int i = 0; i < nodeList.getLength(); i++) { + var elementAsNode = nodeList.item(i); + if (elementAsNode instanceof Element) { + elementList.add(((Element) elementAsNode)); + } + } + return elementList; + } + + /** Appends {@param children} to the {@param ele}. */ + public static void appendChildren(Element ele, List children) { + for (Element c : children) { + ele.appendChild(c); + } + } + + /** Gets the Boolean from the String value. */ + private static Boolean fromString(String s) { + if (s == null) { + return null; + } + if (s.equals(TRUE_STR)) { + return true; + } else if (s.equals(FALSE_STR)) { + return false; + } + return null; + } + + /** Creates an on-device PBundle DOM Element with the given attribute name. */ + public static Element createPbundleEleWithName(Document doc, String name) { + var ele = doc.createElement(XmlUtils.OD_TAG_PBUNDLE_AS_MAP); + ele.setAttribute(XmlUtils.OD_ATTR_NAME, name); + return ele; + } + + /** Create an on-device Boolean DOM Element with the given attribute name. */ + public static Element createOdBooleanEle(Document doc, String name, boolean b) { + var ele = doc.createElement(XmlUtils.OD_TAG_BOOLEAN); + ele.setAttribute(XmlUtils.OD_ATTR_NAME, name); + ele.setAttribute(XmlUtils.OD_ATTR_VALUE, String.valueOf(b)); + return ele; + } + + /** Create an on-device Long DOM Element with the given attribute name. */ + public static Element createOdLongEle(Document doc, String name, long l) { + var ele = doc.createElement(XmlUtils.OD_TAG_LONG); + ele.setAttribute(XmlUtils.OD_ATTR_NAME, name); + ele.setAttribute(XmlUtils.OD_ATTR_VALUE, String.valueOf(l)); + return ele; + } + + /** Create an on-device Long DOM Element with the given attribute name. */ + public static Element createOdStringEle(Document doc, String name, String val) { + var ele = doc.createElement(XmlUtils.OD_TAG_STRING); + ele.setAttribute(XmlUtils.OD_ATTR_NAME, name); + ele.setAttribute(XmlUtils.OD_ATTR_VALUE, val); + return ele; + } + + /** Create OD style array DOM Element, which can represent any time but is stored as Strings. */ + public static Element createOdArray( + Document doc, String arrayTag, String arrayName, List arrayVals) { + Element arrEle = doc.createElement(arrayTag); + arrEle.setAttribute(XmlUtils.OD_ATTR_NAME, arrayName); + arrEle.setAttribute(XmlUtils.OD_ATTR_NUM, String.valueOf(arrayVals.size())); + for (String s : arrayVals) { + Element itemEle = doc.createElement(XmlUtils.OD_TAG_ITEM); + itemEle.setAttribute(XmlUtils.OD_ATTR_VALUE, s); + arrEle.appendChild(itemEle); + } + return arrEle; + } + + /** Returns whether the String is null or empty. */ + public static boolean isNullOrEmpty(String s) { + return s == null || s.isEmpty(); + } + + /** Tries getting required version attribute and throws exception if it doesn't exist */ + public static Long tryGetVersion(Element ele) throws MalformedXmlException { + long version; + try { + version = Long.parseLong(ele.getAttribute(XmlUtils.HR_ATTR_VERSION)); + } catch (Exception e) { + throw new MalformedXmlException( + String.format( + "Malformed or missing required version in: %s", ele.getTagName())); + } + return version; + } + + /** Gets a pipeline-split attribute. */ + public static List getPipelineSplitAttr(Element ele, String attrName, boolean required) + throws MalformedXmlException { + List list = Arrays.stream(ele.getAttribute(attrName).split("\\|")).toList(); + if ((list.isEmpty() || list.get(0).isEmpty()) && required) { + throw new MalformedXmlException( + String.format( + "Delimited string %s was required but missing, in %s.", + attrName, ele.getTagName())); + } + return list; + } + + /** Gets a Boolean attribute. */ + public static Boolean getBoolAttr(Element ele, String attrName, boolean required) + throws MalformedXmlException { + Boolean b = XmlUtils.fromString(ele.getAttribute(attrName)); + if (b == null && required) { + throw new MalformedXmlException( + String.format( + "Boolean %s was required but missing, in %s.", + attrName, ele.getTagName())); + } + return b; + } + + /** Gets a required String attribute. */ + public static String getStringAttr(Element ele, String attrName) throws MalformedXmlException { + return getStringAttr(ele, attrName, true); + } + + /** Gets a String attribute; throws exception if required and non-existent. */ + public static String getStringAttr(Element ele, String attrName, boolean required) + throws MalformedXmlException { + String s = ele.getAttribute(attrName); + if (isNullOrEmpty(s)) { + if (required) { + throw new MalformedXmlException( + String.format( + "Malformed or missing required %s in: %s", + attrName, ele.getTagName())); + } else { + return null; + } + } + return s; + } + + /** + * Utility method for making a List from one element, to support easier refactoring if needed. + * For example, List.of() doesn't support null elements. + */ + public static List listOf(Element e) { + return Arrays.asList(e); + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/aslgen/AllTests.java b/tools/app_metadata_bundles/src/test/java/com/android/aslgen/AllTests.java deleted file mode 100644 index 7ebb7a1c44bf..000000000000 --- a/tools/app_metadata_bundles/src/test/java/com/android/aslgen/AllTests.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2017 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.aslgen; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AslgenTests.class, -}) -public class AllTests {} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/aslgen/AslgenTests.java b/tools/app_metadata_bundles/src/test/java/com/android/aslgen/AslgenTests.java deleted file mode 100644 index 3026f8bec2ed..000000000000 --- a/tools/app_metadata_bundles/src/test/java/com/android/aslgen/AslgenTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2017 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.aslgen; - -import static org.junit.Assert.assertEquals; - -import com.android.asllib.AndroidSafetyLabel; -import com.android.asllib.AslConverter; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -@RunWith(JUnit4.class) -public class AslgenTests { - private static final String VALID_MAPPINGS_PATH = "com/android/aslgen/validmappings"; - private static final List VALID_MAPPINGS_SUBDIRS = List.of("location", "contacts"); - private static final String HR_XML_FILENAME = "hr.xml"; - private static final String OD_XML_FILENAME = "od.xml"; - - /** Logic for setting up tests (empty if not yet needed). */ - public static void main(String[] params) throws Exception {} - - /** Tests valid mappings between HR and OD. */ - @Test - public void testValidMappings() throws Exception { - System.out.println("start testing valid mappings."); - - for (String subdir : VALID_MAPPINGS_SUBDIRS) { - Path hrPath = Paths.get(VALID_MAPPINGS_PATH, subdir, HR_XML_FILENAME); - Path odPath = Paths.get(VALID_MAPPINGS_PATH, subdir, OD_XML_FILENAME); - - System.out.println("hr path: " + hrPath.toString()); - System.out.println("od path: " + odPath.toString()); - - InputStream hrStream = - getClass().getClassLoader().getResourceAsStream(hrPath.toString()); - String hrContents = new String(hrStream.readAllBytes(), StandardCharsets.UTF_8); - InputStream odStream = - getClass().getClassLoader().getResourceAsStream(odPath.toString()); - String odContents = new String(odStream.readAllBytes(), StandardCharsets.UTF_8); - AndroidSafetyLabel asl = - AslConverter.readFromString(hrContents, AslConverter.Format.HUMAN_READABLE); - String out = AslConverter.getXmlAsString(asl, AslConverter.Format.ON_DEVICE); - System.out.println("out: " + out); - - assertEquals(getFormattedXml(out), getFormattedXml(odContents)); - } - } - - private static String getFormattedXml(String xmlStr) - throws ParserConfigurationException, IOException, SAXException, TransformerException { - InputStream stream = new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8)); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - Document document = factory.newDocumentBuilder().parse(stream); - - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); - - ByteArrayOutputStream outStream = new ByteArrayOutputStream(); - StreamResult streamResult = new StreamResult(outStream); // out - DOMSource domSource = new DOMSource(document); - transformer.transform(domSource, streamResult); - - return outStream.toString(StandardCharsets.UTF_8); - } -} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/AllTests.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/AllTests.java new file mode 100644 index 000000000000..03e8ac6d11c0 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/AllTests.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2017 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; + +import com.android.asllib.marshallable.AndroidSafetyLabelTest; +import com.android.asllib.marshallable.DataCategoryTest; +import com.android.asllib.marshallable.DataLabelsTest; +import com.android.asllib.marshallable.DeveloperInfoTest; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + AslgenTests.class, + AndroidSafetyLabelTest.class, + DeveloperInfoTest.class, + DataCategoryTest.class, + DataLabelsTest.class, +}) +public class AllTests {} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/AslgenTests.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/AslgenTests.java new file mode 100644 index 000000000000..5f43008d3dc6 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/AslgenTests.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2017 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; + +import static org.junit.Assert.assertEquals; + +import com.android.asllib.marshallable.AndroidSafetyLabel; +import com.android.asllib.testutils.TestUtils; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +@RunWith(JUnit4.class) +public class AslgenTests { + private static final String VALID_MAPPINGS_PATH = "com/android/asllib/validmappings"; + private static final List VALID_MAPPINGS_SUBDIRS = List.of("location", "contacts"); + private static final String HR_XML_FILENAME = "hr.xml"; + private static final String OD_XML_FILENAME = "od.xml"; + + /** Logic for setting up tests (empty if not yet needed). */ + public static void main(String[] params) throws Exception {} + + /** Tests valid mappings between HR and OD. */ + @Test + public void testValidMappings() throws Exception { + System.out.println("start testing valid mappings."); + + for (String subdir : VALID_MAPPINGS_SUBDIRS) { + Path hrPath = Paths.get(VALID_MAPPINGS_PATH, subdir, HR_XML_FILENAME); + Path odPath = Paths.get(VALID_MAPPINGS_PATH, subdir, OD_XML_FILENAME); + + System.out.println("hr path: " + hrPath.toString()); + System.out.println("od path: " + odPath.toString()); + + InputStream hrStream = + getClass().getClassLoader().getResourceAsStream(hrPath.toString()); + String hrContents = new String(hrStream.readAllBytes(), StandardCharsets.UTF_8); + InputStream odStream = + getClass().getClassLoader().getResourceAsStream(odPath.toString()); + String odContents = new String(odStream.readAllBytes(), StandardCharsets.UTF_8); + AndroidSafetyLabel asl = + AslConverter.readFromString(hrContents, AslConverter.Format.HUMAN_READABLE); + String out = AslConverter.getXmlAsString(asl, AslConverter.Format.ON_DEVICE); + System.out.println("out: " + out); + + assertEquals( + TestUtils.getFormattedXml(out, false), + TestUtils.getFormattedXml(odContents, false)); + } + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/AndroidSafetyLabelTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/AndroidSafetyLabelTest.java new file mode 100644 index 000000000000..013700728e50 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/AndroidSafetyLabelTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 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.testutils.TestUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; + +@RunWith(JUnit4.class) +public class AndroidSafetyLabelTest { + private static final String ANDROID_SAFETY_LABEL_HR_PATH = + "com/android/asllib/androidsafetylabel/hr"; + private static final String ANDROID_SAFETY_LABEL_OD_PATH = + "com/android/asllib/androidsafetylabel/od"; + + private static final String MISSING_VERSION_FILE_NAME = "missing-version.xml"; + private static final String VALID_EMPTY_FILE_NAME = "valid-empty.xml"; + private static final String WITH_SAFETY_LABELS_FILE_NAME = "with-safety-labels.xml"; + private static final String WITH_SYSTEM_APP_SAFETY_LABEL_FILE_NAME = + "with-system-app-safety-label.xml"; + private static final String WITH_TRANSPARENCY_INFO_FILE_NAME = "with-transparency-info.xml"; + + private Document mDoc = null; + + @Before + public void setUp() throws Exception { + System.out.println("set up."); + mDoc = TestUtils.document(); + } + + /** Test for android safety label missing version. */ + @Test + public void testAndroidSafetyLabelMissingVersion() throws Exception { + System.out.println("starting testAndroidSafetyLabelMissingVersion."); + hrToOdExpectException(MISSING_VERSION_FILE_NAME); + } + + /** Test for android safety label valid empty. */ + @Test + public void testAndroidSafetyLabelValidEmptyFile() throws Exception { + System.out.println("starting testAndroidSafetyLabelValidEmptyFile."); + testHrToOdAndroidSafetyLabel(VALID_EMPTY_FILE_NAME); + } + + /** Test for android safety label with safety labels. */ + @Test + public void testAndroidSafetyLabelWithSafetyLabels() throws Exception { + System.out.println("starting testAndroidSafetyLabelWithSafetyLabels."); + testHrToOdAndroidSafetyLabel(WITH_SAFETY_LABELS_FILE_NAME); + } + + /** Test for android safety label with system app safety label. */ + @Test + public void testAndroidSafetyLabelWithSystemAppSafetyLabel() throws Exception { + System.out.println("starting testAndroidSafetyLabelWithSystemAppSafetyLabel."); + testHrToOdAndroidSafetyLabel(WITH_SYSTEM_APP_SAFETY_LABEL_FILE_NAME); + } + + /** Test for android safety label with transparency info. */ + @Test + public void testAndroidSafetyLabelWithTransparencyInfo() throws Exception { + System.out.println("starting testAndroidSafetyLabelWithTransparencyInfo."); + testHrToOdAndroidSafetyLabel(WITH_TRANSPARENCY_INFO_FILE_NAME); + } + + private void hrToOdExpectException(String fileName) { + TestUtils.hrToOdExpectException( + new AndroidSafetyLabelFactory(), ANDROID_SAFETY_LABEL_HR_PATH, fileName); + } + + private void testHrToOdAndroidSafetyLabel(String fileName) throws Exception { + TestUtils.testHrToOd( + mDoc, + new AndroidSafetyLabelFactory(), + ANDROID_SAFETY_LABEL_HR_PATH, + ANDROID_SAFETY_LABEL_OD_PATH, + fileName); + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/AppInfoTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/AppInfoTest.java new file mode 100644 index 000000000000..a015e2eacac5 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/AppInfoTest.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2017 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 static org.junit.Assert.assertThrows; + +import com.android.asllib.testutils.TestUtils; +import com.android.asllib.util.MalformedXmlException; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; + +import java.nio.file.Paths; +import java.util.List; + +@RunWith(JUnit4.class) +public class AppInfoTest { + private static final String APP_INFO_HR_PATH = "com/android/asllib/appinfo/hr"; + private static final String APP_INFO_OD_PATH = "com/android/asllib/appinfo/od"; + public static final List REQUIRED_FIELD_NAMES = + List.of( + "title", + "description", + "containsAds", + "obeyAps", + "adsFingerprinting", + "securityFingerprinting", + "privacyPolicy", + "securityEndpoints", + "firstPartyEndpoints", + "serviceProviderEndpoints", + "category", + "email"); + public static final List OPTIONAL_FIELD_NAMES = List.of("website"); + + private static final String ALL_FIELDS_VALID_FILE_NAME = "all-fields-valid.xml"; + + private Document mDoc = null; + + /** Logic for setting up tests (empty if not yet needed). */ + public static void main(String[] params) throws Exception {} + + @Before + public void setUp() throws Exception { + System.out.println("set up."); + mDoc = TestUtils.document(); + } + + /** Test for all fields valid. */ + @Test + public void testAllFieldsValid() throws Exception { + System.out.println("starting testAllFieldsValid."); + testHrToOdAppInfo(ALL_FIELDS_VALID_FILE_NAME); + } + + /** Tests missing required fields fails. */ + @Test + public void testMissingRequiredFields() throws Exception { + System.out.println("Starting testMissingRequiredFields"); + for (String reqField : REQUIRED_FIELD_NAMES) { + System.out.println("testing missing required field: " + reqField); + var appInfoEle = + TestUtils.getElementsFromResource( + Paths.get(APP_INFO_HR_PATH, ALL_FIELDS_VALID_FILE_NAME)); + appInfoEle.get(0).removeAttribute(reqField); + + assertThrows( + MalformedXmlException.class, + () -> new AppInfoFactory().createFromHrElements(appInfoEle)); + } + } + + /** Tests missing optional fields passes. */ + @Test + public void testMissingOptionalFields() throws Exception { + for (String optField : OPTIONAL_FIELD_NAMES) { + var ele = + TestUtils.getElementsFromResource( + Paths.get(APP_INFO_HR_PATH, ALL_FIELDS_VALID_FILE_NAME)); + ele.get(0).removeAttribute(optField); + AppInfo appInfo = new AppInfoFactory().createFromHrElements(ele); + appInfo.toOdDomElements(mDoc); + } + } + + private void testHrToOdAppInfo(String fileName) throws Exception { + TestUtils.testHrToOd( + mDoc, new AppInfoFactory(), APP_INFO_HR_PATH, APP_INFO_OD_PATH, fileName); + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DataCategoryTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DataCategoryTest.java new file mode 100644 index 000000000000..822f1753f662 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DataCategoryTest.java @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2017 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.testutils.TestUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; + +@RunWith(JUnit4.class) +public class DataCategoryTest { + private static final String DATA_CATEGORY_HR_PATH = "com/android/asllib/datacategory/hr"; + private static final String DATA_CATEGORY_OD_PATH = "com/android/asllib/datacategory/od"; + + private static final String VALID_PERSONAL_FILE_NAME = "data-category-personal.xml"; + private static final String VALID_PARTIAL_PERSONAL_FILE_NAME = + "data-category-personal-partial.xml"; + private static final String VALID_FINANCIAL_FILE_NAME = "data-category-financial.xml"; + private static final String VALID_LOCATION_FILE_NAME = "data-category-location.xml"; + private static final String VALID_EMAIL_TEXT_MESSAGE_FILE_NAME = + "data-category-email-text-message.xml"; + private static final String VALID_PHOTO_VIDEO_FILE_NAME = "data-category-photo-video.xml"; + private static final String VALID_AUDIO_FILE_NAME = "data-category-audio.xml"; + private static final String VALID_STORAGE_FILE_NAME = "data-category-storage.xml"; + private static final String VALID_HEALTH_FITNESS_FILE_NAME = "data-category-health-fitness.xml"; + private static final String VALID_CONTACTS_FILE_NAME = "data-category-contacts.xml"; + private static final String VALID_CALENDAR_FILE_NAME = "data-category-calendar.xml"; + private static final String VALID_IDENTIFIERS_FILE_NAME = "data-category-identifiers.xml"; + private static final String VALID_APP_PERFORMANCE_FILE_NAME = + "data-category-app-performance.xml"; + private static final String VALID_ACTIONS_IN_APP_FILE_NAME = "data-category-actions-in-app.xml"; + private static final String VALID_SEARCH_AND_BROWSING_FILE_NAME = + "data-category-search-and-browsing.xml"; + + private static final String EMPTY_PURPOSE_PERSONAL_FILE_NAME = + "data-category-personal-empty-purpose.xml"; + private static final String MISSING_PURPOSE_PERSONAL_FILE_NAME = + "data-category-personal-missing-purpose.xml"; + private static final String UNRECOGNIZED_TYPE_PERSONAL_FILE_NAME = + "data-category-personal-unrecognized-type.xml"; + private static final String UNRECOGNIZED_CATEGORY_FILE_NAME = "data-category-unrecognized.xml"; + + private Document mDoc = null; + + /** Logic for setting up tests (empty if not yet needed). */ + public static void main(String[] params) throws Exception {} + + @Before + public void setUp() throws Exception { + System.out.println("set up."); + mDoc = TestUtils.document(); + } + + /** Test for data category personal. */ + @Test + public void testDataCategoryPersonal() throws Exception { + System.out.println("starting testDataCategoryPersonal."); + testHrToOdDataCategory(VALID_PERSONAL_FILE_NAME); + } + + /** Test for data category financial. */ + @Test + public void testDataCategoryFinancial() throws Exception { + System.out.println("starting testDataCategoryFinancial."); + testHrToOdDataCategory(VALID_FINANCIAL_FILE_NAME); + } + + /** Test for data category location. */ + @Test + public void testDataCategoryLocation() throws Exception { + System.out.println("starting testDataCategoryLocation."); + testHrToOdDataCategory(VALID_LOCATION_FILE_NAME); + } + + /** Test for data category email text message. */ + @Test + public void testDataCategoryEmailTextMessage() throws Exception { + System.out.println("starting testDataCategoryEmailTextMessage."); + testHrToOdDataCategory(VALID_EMAIL_TEXT_MESSAGE_FILE_NAME); + } + + /** Test for data category photo video. */ + @Test + public void testDataCategoryPhotoVideo() throws Exception { + System.out.println("starting testDataCategoryPhotoVideo."); + testHrToOdDataCategory(VALID_PHOTO_VIDEO_FILE_NAME); + } + + /** Test for data category audio. */ + @Test + public void testDataCategoryAudio() throws Exception { + System.out.println("starting testDataCategoryAudio."); + testHrToOdDataCategory(VALID_AUDIO_FILE_NAME); + } + + /** Test for data category storage. */ + @Test + public void testDataCategoryStorage() throws Exception { + System.out.println("starting testDataCategoryStorage."); + testHrToOdDataCategory(VALID_STORAGE_FILE_NAME); + } + + /** Test for data category health fitness. */ + @Test + public void testDataCategoryHealthFitness() throws Exception { + System.out.println("starting testDataCategoryHealthFitness."); + testHrToOdDataCategory(VALID_HEALTH_FITNESS_FILE_NAME); + } + + /** Test for data category contacts. */ + @Test + public void testDataCategoryContacts() throws Exception { + System.out.println("starting testDataCategoryContacts."); + testHrToOdDataCategory(VALID_CONTACTS_FILE_NAME); + } + + /** Test for data category calendar. */ + @Test + public void testDataCategoryCalendar() throws Exception { + System.out.println("starting testDataCategoryCalendar."); + testHrToOdDataCategory(VALID_CALENDAR_FILE_NAME); + } + + /** Test for data category identifiers. */ + @Test + public void testDataCategoryIdentifiers() throws Exception { + System.out.println("starting testDataCategoryIdentifiers."); + testHrToOdDataCategory(VALID_IDENTIFIERS_FILE_NAME); + } + + /** Test for data category app performance. */ + @Test + public void testDataCategoryAppPerformance() throws Exception { + System.out.println("starting testDataCategoryAppPerformance."); + testHrToOdDataCategory(VALID_APP_PERFORMANCE_FILE_NAME); + } + + /** Test for data category actions in app. */ + @Test + public void testDataCategoryActionsInApp() throws Exception { + System.out.println("starting testDataCategoryActionsInApp."); + testHrToOdDataCategory(VALID_ACTIONS_IN_APP_FILE_NAME); + } + + /** Test for data category search and browsing. */ + @Test + public void testDataCategorySearchAndBrowsing() throws Exception { + System.out.println("starting testDataCategorySearchAndBrowsing."); + testHrToOdDataCategory(VALID_SEARCH_AND_BROWSING_FILE_NAME); + } + + /** Test for data category search and browsing. */ + @Test + public void testMissingOptionalsAllowed() throws Exception { + System.out.println("starting testMissingOptionalsAllowed."); + testHrToOdDataCategory(VALID_PARTIAL_PERSONAL_FILE_NAME); + } + + /** Test for empty purposes. */ + @Test + public void testEmptyPurposesNotAllowed() throws Exception { + System.out.println("starting testEmptyPurposesNotAllowed."); + hrToOdExpectException(EMPTY_PURPOSE_PERSONAL_FILE_NAME); + } + + /** Test for missing purposes. */ + @Test + public void testMissingPurposesNotAllowed() throws Exception { + System.out.println("starting testMissingPurposesNotAllowed."); + hrToOdExpectException(MISSING_PURPOSE_PERSONAL_FILE_NAME); + } + + /** Test for unrecognized type. */ + @Test + public void testUnrecognizedTypeNotAllowed() throws Exception { + System.out.println("starting testUnrecognizedTypeNotAllowed."); + hrToOdExpectException(UNRECOGNIZED_TYPE_PERSONAL_FILE_NAME); + } + + /** Test for unrecognized category. */ + @Test + public void testUnrecognizedCategoryNotAllowed() throws Exception { + System.out.println("starting testUnrecognizedCategoryNotAllowed."); + hrToOdExpectException(UNRECOGNIZED_CATEGORY_FILE_NAME); + } + + private void hrToOdExpectException(String fileName) { + TestUtils.hrToOdExpectException(new DataCategoryFactory(), DATA_CATEGORY_HR_PATH, fileName); + } + + private void testHrToOdDataCategory(String fileName) throws Exception { + TestUtils.testHrToOd( + mDoc, + new DataCategoryFactory(), + DATA_CATEGORY_HR_PATH, + DATA_CATEGORY_OD_PATH, + fileName); + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DataLabelsTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DataLabelsTest.java new file mode 100644 index 000000000000..2be447e182b2 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DataLabelsTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2017 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.testutils.TestUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; + +@RunWith(JUnit4.class) +public class DataLabelsTest { + private static final String DATA_LABELS_HR_PATH = "com/android/asllib/datalabels/hr"; + private static final String DATA_LABELS_OD_PATH = "com/android/asllib/datalabels/od"; + + private static final String ACCESSED_VALID_BOOL_FILE_NAME = + "data-labels-accessed-valid-bool.xml"; + private static final String ACCESSED_INVALID_BOOL_FILE_NAME = + "data-labels-accessed-invalid-bool.xml"; + private static final String COLLECTED_VALID_BOOL_FILE_NAME = + "data-labels-collected-valid-bool.xml"; + private static final String COLLECTED_INVALID_BOOL_FILE_NAME = + "data-labels-collected-invalid-bool.xml"; + private static final String SHARED_VALID_BOOL_FILE_NAME = "data-labels-shared-valid-bool.xml"; + private static final String SHARED_INVALID_BOOL_FILE_NAME = + "data-labels-shared-invalid-bool.xml"; + + private Document mDoc = null; + + @Before + public void setUp() throws Exception { + System.out.println("set up."); + mDoc = TestUtils.document(); + } + + /** Test for data labels accessed valid bool. */ + @Test + public void testDataLabelsAccessedValidBool() throws Exception { + System.out.println("starting testDataLabelsAccessedValidBool."); + testHrToOdDataLabels(ACCESSED_VALID_BOOL_FILE_NAME); + } + + /** Test for data labels accessed invalid bool. */ + @Test + public void testDataLabelsAccessedInvalidBool() throws Exception { + System.out.println("starting testDataLabelsAccessedInvalidBool."); + hrToOdExpectException(ACCESSED_INVALID_BOOL_FILE_NAME); + } + + /** Test for data labels collected valid bool. */ + @Test + public void testDataLabelsCollectedValidBool() throws Exception { + System.out.println("starting testDataLabelsCollectedValidBool."); + testHrToOdDataLabels(COLLECTED_VALID_BOOL_FILE_NAME); + } + + /** Test for data labels collected invalid bool. */ + @Test + public void testDataLabelsCollectedInvalidBool() throws Exception { + System.out.println("starting testDataLabelsCollectedInvalidBool."); + hrToOdExpectException(COLLECTED_INVALID_BOOL_FILE_NAME); + } + + /** Test for data labels shared valid bool. */ + @Test + public void testDataLabelsSharedValidBool() throws Exception { + System.out.println("starting testDataLabelsSharedValidBool."); + testHrToOdDataLabels(SHARED_VALID_BOOL_FILE_NAME); + } + + /** Test for data labels shared invalid bool. */ + @Test + public void testDataLabelsSharedInvalidBool() throws Exception { + System.out.println("starting testDataLabelsSharedInvalidBool."); + hrToOdExpectException(SHARED_INVALID_BOOL_FILE_NAME); + } + + private void hrToOdExpectException(String fileName) { + TestUtils.hrToOdExpectException(new DataLabelsFactory(), DATA_LABELS_HR_PATH, fileName); + } + + private void testHrToOdDataLabels(String fileName) throws Exception { + TestUtils.testHrToOd( + mDoc, new DataLabelsFactory(), DATA_LABELS_HR_PATH, DATA_LABELS_OD_PATH, fileName); + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DeveloperInfoTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DeveloperInfoTest.java new file mode 100644 index 000000000000..ff8346a526ad --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DeveloperInfoTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2017 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 static org.junit.Assert.assertThrows; + +import com.android.asllib.testutils.TestUtils; +import com.android.asllib.util.MalformedXmlException; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; + +import java.nio.file.Paths; +import java.util.List; + +@RunWith(JUnit4.class) +public class DeveloperInfoTest { + private static final String DEVELOPER_INFO_HR_PATH = "com/android/asllib/developerinfo/hr"; + private static final String DEVELOPER_INFO_OD_PATH = "com/android/asllib/developerinfo/od"; + public static final List REQUIRED_FIELD_NAMES = + List.of("address", "countryRegion", "email", "name", "relationship"); + public static final List OPTIONAL_FIELD_NAMES = List.of("website", "registryId"); + + private static final String ALL_FIELDS_VALID_FILE_NAME = "all-fields-valid.xml"; + + private Document mDoc = null; + + /** Logic for setting up tests (empty if not yet needed). */ + public static void main(String[] params) throws Exception {} + + @Before + public void setUp() throws Exception { + System.out.println("set up."); + mDoc = TestUtils.document(); + } + + /** Test for all fields valid. */ + @Test + public void testAllFieldsValid() throws Exception { + System.out.println("starting testAllFieldsValid."); + testHrToOdDeveloperInfo(ALL_FIELDS_VALID_FILE_NAME); + } + + /** Tests missing required fields fails. */ + @Test + public void testMissingRequiredFields() throws Exception { + System.out.println("Starting testMissingRequiredFields"); + for (String reqField : REQUIRED_FIELD_NAMES) { + System.out.println("testing missing required field: " + reqField); + var developerInfoEle = + TestUtils.getElementsFromResource( + Paths.get(DEVELOPER_INFO_HR_PATH, ALL_FIELDS_VALID_FILE_NAME)); + developerInfoEle.get(0).removeAttribute(reqField); + + assertThrows( + MalformedXmlException.class, + () -> new DeveloperInfoFactory().createFromHrElements(developerInfoEle)); + } + } + + /** Tests missing optional fields passes. */ + @Test + public void testMissingOptionalFields() throws Exception { + for (String optField : OPTIONAL_FIELD_NAMES) { + var developerInfoEle = + TestUtils.getElementsFromResource( + Paths.get(DEVELOPER_INFO_HR_PATH, ALL_FIELDS_VALID_FILE_NAME)); + developerInfoEle.get(0).removeAttribute(optField); + DeveloperInfo developerInfo = + new DeveloperInfoFactory().createFromHrElements(developerInfoEle); + developerInfo.toOdDomElements(mDoc); + } + } + + private void testHrToOdDeveloperInfo(String fileName) throws Exception { + TestUtils.testHrToOd( + mDoc, + new DeveloperInfoFactory(), + DEVELOPER_INFO_HR_PATH, + DEVELOPER_INFO_OD_PATH, + fileName); + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SafetyLabelsTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SafetyLabelsTest.java new file mode 100644 index 000000000000..b62620ef417e --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SafetyLabelsTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 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.testutils.TestUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; + +@RunWith(JUnit4.class) +public class SafetyLabelsTest { + private static final String SAFETY_LABELS_HR_PATH = "com/android/asllib/safetylabels/hr"; + private static final String SAFETY_LABELS_OD_PATH = "com/android/asllib/safetylabels/od"; + + private static final String MISSING_VERSION_FILE_NAME = "missing-version.xml"; + private static final String VALID_EMPTY_FILE_NAME = "valid-empty.xml"; + private static final String WITH_DATA_LABELS_FILE_NAME = "with-data-labels.xml"; + + private Document mDoc = null; + + @Before + public void setUp() throws Exception { + System.out.println("set up."); + mDoc = TestUtils.document(); + } + + /** Test for safety labels missing version. */ + @Test + public void testSafetyLabelsMissingVersion() throws Exception { + System.out.println("starting testSafetyLabelsMissingVersion."); + hrToOdExpectException(MISSING_VERSION_FILE_NAME); + } + + /** Test for safety labels valid empty. */ + @Test + public void testSafetyLabelsValidEmptyFile() throws Exception { + System.out.println("starting testSafetyLabelsValidEmptyFile."); + testHrToOdSafetyLabels(VALID_EMPTY_FILE_NAME); + } + + /** Test for safety labels with data labels. */ + @Test + public void testSafetyLabelsWithDataLabels() throws Exception { + System.out.println("starting testSafetyLabelsWithDataLabels."); + testHrToOdSafetyLabels(WITH_DATA_LABELS_FILE_NAME); + } + + private void hrToOdExpectException(String fileName) { + TestUtils.hrToOdExpectException(new SafetyLabelsFactory(), SAFETY_LABELS_HR_PATH, fileName); + } + + private void testHrToOdSafetyLabels(String fileName) throws Exception { + TestUtils.testHrToOd( + mDoc, + new SafetyLabelsFactory(), + SAFETY_LABELS_HR_PATH, + SAFETY_LABELS_OD_PATH, + fileName); + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SystemAppSafetyLabelTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SystemAppSafetyLabelTest.java new file mode 100644 index 000000000000..191091a9e187 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SystemAppSafetyLabelTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2017 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.testutils.TestUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; + +@RunWith(JUnit4.class) +public class SystemAppSafetyLabelTest { + private static final String SYSTEM_APP_SAFETY_LABEL_HR_PATH = + "com/android/asllib/systemappsafetylabel/hr"; + private static final String SYSTEM_APP_SAFETY_LABEL_OD_PATH = + "com/android/asllib/systemappsafetylabel/od"; + + private static final String VALID_FILE_NAME = "valid.xml"; + private static final String MISSING_URL_FILE_NAME = "missing-url.xml"; + + private Document mDoc = null; + + /** Logic for setting up tests (empty if not yet needed). */ + public static void main(String[] params) throws Exception {} + + @Before + public void setUp() throws Exception { + System.out.println("set up."); + mDoc = TestUtils.document(); + } + + /** Test for valid. */ + @Test + public void testValid() throws Exception { + System.out.println("starting testValid."); + testHrToOdSystemAppSafetyLabel(VALID_FILE_NAME); + } + + /** Tests missing url. */ + @Test + public void testMissingUrl() throws Exception { + System.out.println("starting testMissingUrl."); + hrToOdExpectException(MISSING_URL_FILE_NAME); + } + + private void hrToOdExpectException(String fileName) { + TestUtils.hrToOdExpectException( + new SystemAppSafetyLabelFactory(), SYSTEM_APP_SAFETY_LABEL_HR_PATH, fileName); + } + + private void testHrToOdSystemAppSafetyLabel(String fileName) throws Exception { + TestUtils.testHrToOd( + mDoc, + new SystemAppSafetyLabelFactory(), + SYSTEM_APP_SAFETY_LABEL_HR_PATH, + SYSTEM_APP_SAFETY_LABEL_OD_PATH, + fileName); + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/TransparencyInfoTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/TransparencyInfoTest.java new file mode 100644 index 000000000000..56503f7d6c6b --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/TransparencyInfoTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2017 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.testutils.TestUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; + +@RunWith(JUnit4.class) +public class TransparencyInfoTest { + private static final String TRANSPARENCY_INFO_HR_PATH = + "com/android/asllib/transparencyinfo/hr"; + private static final String TRANSPARENCY_INFO_OD_PATH = + "com/android/asllib/transparencyinfo/od"; + + private static final String VALID_EMPTY_FILE_NAME = "valid-empty.xml"; + private static final String WITH_DEVELOPER_INFO_FILE_NAME = "with-developer-info.xml"; + private static final String WITH_APP_INFO_FILE_NAME = "with-app-info.xml"; + + private Document mDoc = null; + + @Before + public void setUp() throws Exception { + System.out.println("set up."); + mDoc = TestUtils.document(); + } + + /** Test for transparency info valid empty. */ + @Test + public void testTransparencyInfoValidEmptyFile() throws Exception { + System.out.println("starting testTransparencyInfoValidEmptyFile."); + testHrToOdTransparencyInfo(VALID_EMPTY_FILE_NAME); + } + + /** Test for transparency info with developer info. */ + @Test + public void testTransparencyInfoWithDeveloperInfo() throws Exception { + System.out.println("starting testTransparencyInfoWithDeveloperInfo."); + testHrToOdTransparencyInfo(WITH_DEVELOPER_INFO_FILE_NAME); + } + + /** Test for transparency info with app info. */ + @Test + public void testTransparencyInfoWithAppInfo() throws Exception { + System.out.println("starting testTransparencyInfoWithAppInfo."); + testHrToOdTransparencyInfo(WITH_APP_INFO_FILE_NAME); + } + + private void testHrToOdTransparencyInfo(String fileName) throws Exception { + TestUtils.testHrToOd( + mDoc, + new TransparencyInfoFactory(), + TRANSPARENCY_INFO_HR_PATH, + TRANSPARENCY_INFO_OD_PATH, + fileName); + } +} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/testutils/TestUtils.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/testutils/TestUtils.java new file mode 100644 index 000000000000..faea340ae7bd --- /dev/null +++ b/tools/app_metadata_bundles/src/test/java/com/android/asllib/testutils/TestUtils.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2017 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.testutils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + +import com.android.asllib.marshallable.AslMarshallable; +import com.android.asllib.marshallable.AslMarshallableFactory; +import com.android.asllib.util.MalformedXmlException; +import com.android.asllib.util.XmlUtils; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +public class TestUtils { + public static final String HOLDER_TAG_NAME = "holder_of_flattened_for_testing"; + + /** Reads a Resource file into a String. */ + public static String readStrFromResource(Path filePath) throws IOException { + InputStream hrStream = + TestUtils.class.getClassLoader().getResourceAsStream(filePath.toString()); + return new String(hrStream.readAllBytes(), StandardCharsets.UTF_8); + } + + /** Gets List of Element from a path to an existing Resource. */ + public static List getElementsFromResource(Path filePath) + throws ParserConfigurationException, IOException, SAXException { + String str = readStrFromResource(filePath); + InputStream stream = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8)); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + Document document = factory.newDocumentBuilder().parse(stream); + Element root = document.getDocumentElement(); + if (root.getTagName().equals(HOLDER_TAG_NAME)) { + String tagName = + XmlUtils.asElementList(root.getChildNodes()).stream() + .findFirst() + .get() + .getTagName(); + return XmlUtils.asElementList(root.getElementsByTagName(tagName)); + } else { + return List.of(root); + } + } + + /** Reads a Document into a String. */ + public static String docToStr(Document doc, boolean omitXmlDeclaration) + throws TransformerException { + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty( + OutputKeys.OMIT_XML_DECLARATION, omitXmlDeclaration ? "yes" : "no"); + + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + StreamResult streamResult = new StreamResult(outStream); // out + DOMSource domSource = new DOMSource(doc); + transformer.transform(domSource, streamResult); + + return outStream.toString(StandardCharsets.UTF_8); + } + + /** + * Gets formatted XML for slightly more robust comparison checking than naive string comparison. + */ + public static String getFormattedXml(String xmlStr, boolean omitXmlDeclaration) + throws ParserConfigurationException, IOException, SAXException, TransformerException { + InputStream stream = new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8)); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + Document document = factory.newDocumentBuilder().parse(stream); + + return docToStr(document, omitXmlDeclaration); + } + + /** Helper for getting a new Document */ + public static Document document() throws ParserConfigurationException { + return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + } + + /** Helper for testing human-readable to on-device conversion expecting exception */ + public static void hrToOdExpectException( + AslMarshallableFactory factory, String hrFolderPath, String fileName) { + assertThrows( + MalformedXmlException.class, + () -> { + factory.createFromHrElements( + TestUtils.getElementsFromResource(Paths.get(hrFolderPath, fileName))); + }); + } + + /** Helper for testing human-readable to on-device conversion */ + public static void testHrToOd( + Document doc, + AslMarshallableFactory factory, + String hrFolderPath, + String odFolderPath, + String fileName) + throws Exception { + AslMarshallable marshallable = + factory.createFromHrElements( + TestUtils.getElementsFromResource(Paths.get(hrFolderPath, fileName))); + + for (var child : marshallable.toOdDomElements(doc)) { + doc.appendChild(child); + } + String converted = TestUtils.docToStr(doc, true); + System.out.println("converted: " + converted); + + String expectedOdContents = + TestUtils.readStrFromResource(Paths.get(odFolderPath, fileName)); + assertEquals( + TestUtils.getFormattedXml(expectedOdContents, true), + TestUtils.getFormattedXml(converted, true)); + } +} diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/contacts/hr.xml b/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/contacts/hr.xml deleted file mode 100644 index b2ff4495a6d2..000000000000 --- a/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/contacts/hr.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/contacts/od.xml b/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/contacts/od.xml deleted file mode 100644 index 81277bf456a4..000000000000 --- a/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/contacts/od.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/location/hr.xml b/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/location/hr.xml deleted file mode 100644 index ac844b3b2767..000000000000 --- a/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/location/hr.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/location/od.xml b/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/location/od.xml deleted file mode 100644 index d0a3bfa7e64f..000000000000 --- a/tools/app_metadata_bundles/src/test/resources/com/android/aslgen/validmappings/location/od.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/missing-version.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/missing-version.xml new file mode 100644 index 000000000000..ec0cd702fd43 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/missing-version.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/valid-empty.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/valid-empty.xml new file mode 100644 index 000000000000..19bfd826f770 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/valid-empty.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-safety-labels.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-safety-labels.xml new file mode 100644 index 000000000000..53794a1d1c80 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-safety-labels.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-system-app-safety-label.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-system-app-safety-label.xml new file mode 100644 index 000000000000..7bcde4547933 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-system-app-safety-label.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-transparency-info.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-transparency-info.xml new file mode 100644 index 000000000000..00bcfa80e9b1 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/hr/with-transparency-info.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/valid-empty.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/valid-empty.xml new file mode 100644 index 000000000000..37bdfad4065f --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/valid-empty.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-safety-labels.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-safety-labels.xml new file mode 100644 index 000000000000..74644ed0413c --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-safety-labels.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-system-app-safety-label.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-system-app-safety-label.xml new file mode 100644 index 000000000000..ef0f549fc46b --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-system-app-safety-label.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-transparency-info.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-transparency-info.xml new file mode 100644 index 000000000000..63c5094333cc --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/androidsafetylabel/od/with-transparency-info.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/appinfo/hr/all-fields-valid.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/appinfo/hr/all-fields-valid.xml new file mode 100644 index 000000000000..883170a2d36f --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/appinfo/hr/all-fields-valid.xml @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/appinfo/od/all-fields-valid.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/appinfo/od/all-fields-valid.xml new file mode 100644 index 000000000000..6e976a3278de --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/appinfo/od/all-fields-valid.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-actions-in-app.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-actions-in-app.xml new file mode 100644 index 000000000000..520e525679b8 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-actions-in-app.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-app-performance.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-app-performance.xml new file mode 100644 index 000000000000..0d08e5b5ae4d --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-app-performance.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-audio.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-audio.xml new file mode 100644 index 000000000000..b1cf3b44fd4a --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-audio.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-calendar.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-calendar.xml new file mode 100644 index 000000000000..a723070c43b7 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-calendar.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-contacts.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-contacts.xml new file mode 100644 index 000000000000..2fe28ffe4940 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-contacts.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-email-text-message.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-email-text-message.xml new file mode 100644 index 000000000000..49a326fc43e5 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-email-text-message.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-financial.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-financial.xml new file mode 100644 index 000000000000..f5de3707ef8a --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-financial.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-health-fitness.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-health-fitness.xml new file mode 100644 index 000000000000..9891f8170bd7 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-health-fitness.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-identifiers.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-identifiers.xml new file mode 100644 index 000000000000..3e74da1ad527 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-identifiers.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-location.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-location.xml new file mode 100644 index 000000000000..4762f16d64db --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-location.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-empty-purpose.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-empty-purpose.xml new file mode 100644 index 000000000000..964e178e4dbd --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-empty-purpose.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-missing-purpose.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-missing-purpose.xml new file mode 100644 index 000000000000..3ce1288fb2c3 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-missing-purpose.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-partial.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-partial.xml new file mode 100644 index 000000000000..68baae30ef4f --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-partial.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-unrecognized-type.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-unrecognized-type.xml new file mode 100644 index 000000000000..921a90a3fde7 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal-unrecognized-type.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal.xml new file mode 100644 index 000000000000..4533773ec9c1 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-personal.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-photo-video.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-photo-video.xml new file mode 100644 index 000000000000..234fb265ae55 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-photo-video.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-search-and-browsing.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-search-and-browsing.xml new file mode 100644 index 000000000000..db851633aec5 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-search-and-browsing.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-storage.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-storage.xml new file mode 100644 index 000000000000..9aad02de8877 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-storage.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-unrecognized.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-unrecognized.xml new file mode 100644 index 000000000000..64b9ea72e05b --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/hr/data-category-unrecognized.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-actions-in-app.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-actions-in-app.xml new file mode 100644 index 000000000000..5b99900b5a8a --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-actions-in-app.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-app-performance.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-app-performance.xml new file mode 100644 index 000000000000..0fe102202be5 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-app-performance.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-audio.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-audio.xml new file mode 100644 index 000000000000..51f1dfd6d823 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-audio.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-calendar.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-calendar.xml new file mode 100644 index 000000000000..326da47a1cb9 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-calendar.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-contacts.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-contacts.xml new file mode 100644 index 000000000000..5d4387d2f906 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-contacts.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-email-text-message.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-email-text-message.xml new file mode 100644 index 000000000000..5ac98f56ace6 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-email-text-message.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-financial.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-financial.xml new file mode 100644 index 000000000000..a66f1a44dcb3 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-financial.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-health-fitness.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-health-fitness.xml new file mode 100644 index 000000000000..8e697b47364c --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-health-fitness.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-identifiers.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-identifiers.xml new file mode 100644 index 000000000000..34b4016e1364 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-identifiers.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-location.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-location.xml new file mode 100644 index 000000000000..db2e6965ff2a --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-location.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-personal-partial.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-personal-partial.xml new file mode 100644 index 000000000000..839922a8bec6 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-personal-partial.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-personal.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-personal.xml new file mode 100644 index 000000000000..43650b6a77fe --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-personal.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-photo-video.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-photo-video.xml new file mode 100644 index 000000000000..2a3178005df3 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-photo-video.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-search-and-browsing.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-search-and-browsing.xml new file mode 100644 index 000000000000..9e654efcc5ab --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-search-and-browsing.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-storage.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-storage.xml new file mode 100644 index 000000000000..9abc37fdb2b9 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datacategory/od/data-category-storage.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-accessed-invalid-bool.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-accessed-invalid-bool.xml new file mode 100644 index 000000000000..bb45f426e083 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-accessed-invalid-bool.xml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-accessed-valid-bool.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-accessed-valid-bool.xml new file mode 100644 index 000000000000..f927bba838fd --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-accessed-valid-bool.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-collected-invalid-bool.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-collected-invalid-bool.xml new file mode 100644 index 000000000000..ba11afbdce5f --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-collected-invalid-bool.xml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-collected-valid-bool.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-collected-valid-bool.xml new file mode 100644 index 000000000000..4b6d39776aeb --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-collected-valid-bool.xml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-shared-invalid-bool.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-shared-invalid-bool.xml new file mode 100644 index 000000000000..7840b9876ad8 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-shared-invalid-bool.xml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-shared-valid-bool.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-shared-valid-bool.xml new file mode 100644 index 000000000000..ccf77b0e03be --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/hr/data-labels-shared-valid-bool.xml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-accessed-valid-bool.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-accessed-valid-bool.xml new file mode 100644 index 000000000000..ddefc18f62e3 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-accessed-valid-bool.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-collected-valid-bool.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-collected-valid-bool.xml new file mode 100644 index 000000000000..252c7282da20 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-collected-valid-bool.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-shared-valid-bool.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-shared-valid-bool.xml new file mode 100644 index 000000000000..d1d4e33e855a --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/datalabels/od/data-labels-shared-valid-bool.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/developerinfo/hr/all-fields-valid.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/developerinfo/hr/all-fields-valid.xml new file mode 100644 index 000000000000..908d8ea2f53e --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/developerinfo/hr/all-fields-valid.xml @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/developerinfo/od/all-fields-valid.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/developerinfo/od/all-fields-valid.xml new file mode 100644 index 000000000000..784ec6156c1d --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/developerinfo/od/all-fields-valid.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/missing-version.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/missing-version.xml new file mode 100644 index 000000000000..762f3bdf7875 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/missing-version.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/valid-empty.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/valid-empty.xml new file mode 100644 index 000000000000..7decfd4865b1 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/valid-empty.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-data-labels.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-data-labels.xml new file mode 100644 index 000000000000..8997f4f30c33 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-data-labels.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/valid-empty.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/valid-empty.xml new file mode 100644 index 000000000000..4f03d88a3bd2 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/valid-empty.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-data-labels.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-data-labels.xml new file mode 100644 index 000000000000..a966fdaf9fe0 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-data-labels.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/hr/missing-url.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/hr/missing-url.xml new file mode 100644 index 000000000000..ff26c05abdb0 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/hr/missing-url.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/hr/valid.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/hr/valid.xml new file mode 100644 index 000000000000..6fe86c33523b --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/hr/valid.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/od/valid.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/od/valid.xml new file mode 100644 index 000000000000..f96535b4b49b --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/systemappsafetylabel/od/valid.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/valid-empty.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/valid-empty.xml new file mode 100644 index 000000000000..254a37fb99e8 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/valid-empty.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/with-app-info.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/with-app-info.xml new file mode 100644 index 000000000000..a7c48fc68cf1 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/with-app-info.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/with-developer-info.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/with-developer-info.xml new file mode 100644 index 000000000000..862bda465b25 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/hr/with-developer-info.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/valid-empty.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/valid-empty.xml new file mode 100644 index 000000000000..af574cf92b3a --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/valid-empty.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/with-app-info.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/with-app-info.xml new file mode 100644 index 000000000000..b813641f74f8 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/with-app-info.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/with-developer-info.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/with-developer-info.xml new file mode 100644 index 000000000000..101c98bd8e60 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/transparencyinfo/od/with-developer-info.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/contacts/hr.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/contacts/hr.xml new file mode 100644 index 000000000000..b2ff4495a6d2 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/contacts/hr.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/contacts/od.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/contacts/od.xml new file mode 100644 index 000000000000..81277bf456a4 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/contacts/od.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/location/hr.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/location/hr.xml new file mode 100644 index 000000000000..ac844b3b2767 --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/location/hr.xml @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/location/od.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/location/od.xml new file mode 100644 index 000000000000..d0a3bfa7e64f --- /dev/null +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/location/od.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3-59-g8ed1b