diff options
Diffstat (limited to 'tools')
64 files changed, 894 insertions, 1189 deletions
diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp index 6a17ef85a755..df1d51e37660 100644 --- a/tools/aapt2/Debug.cpp +++ b/tools/aapt2/Debug.cpp @@ -763,10 +763,35 @@ class ChunkPrinter { pool->setTo(chunk, android::util::DeviceToHost32( (reinterpret_cast<const ResChunk_header*>(chunk))->size)); - printer_->Print("\n"); + printer_->Print(StringPrintf(" strings: %zd styles %zd flags: %s|%s\n", pool->size(), + pool->styleCount(), pool->isUTF8() ? "UTF-8" : "UTF-16", + pool->isSorted() ? "SORTED" : "NON-SORTED")); for (size_t i = 0; i < pool->size(); i++) { printer_->Print(StringPrintf("#%zd : %s\n", i, android::util::GetString(*pool, i).c_str())); + if (i < pool->styleCount()) { + printer_->Print(" [Style] "); + auto maybe_style = pool->styleAt(i); + if (!maybe_style) { + printer_->Print("??? missing\n"); + } else { + std::vector<const ResStringPool_span*> spans; + for (auto style = maybe_style.value().unsafe_ptr(); + style->name.index != android::ResStringPool_span::END; ++style) { + spans.push_back(style); + } + printer_->Print(StringPrintf("(%zd)", spans.size())); + if (!spans.empty()) { + printer_->Print(" :"); + for (const auto& span : spans) { + printer_->Print(StringPrintf( + " %s:%u,%u", android::util::GetString(*pool, span->name.index).c_str(), + span->firstChar, span->lastChar)); + } + printer_->Print("\n"); + } + } + } } } diff --git a/tools/aapt2/ResourceValues_test.cpp b/tools/aapt2/ResourceValues_test.cpp index d788e3fd5fc7..b30348ddd4b4 100644 --- a/tools/aapt2/ResourceValues_test.cpp +++ b/tools/aapt2/ResourceValues_test.cpp @@ -184,6 +184,35 @@ TEST(ResourcesValuesTest, StringClones) { EXPECT_THAT(pool_b.strings()[0]->value, StrEq("hello")); } +TEST(ResourcesValuesTest, StringEquals) { + android::StringPool pool; + + String str(pool.MakeRef("hello", android::StringPool::Context(test::ParseConfigOrDie("en")))); + String str2(pool.MakeRef("hello")); + EXPECT_TRUE(str.Equals(&str2)); + EXPECT_TRUE(str2.Equals(&str)); + + String str3(pool.MakeRef("how are you")); + EXPECT_FALSE(str.Equals(&str3)); +} + +TEST(ResourcesValuesTest, StyledStringEquals) { + android::StringPool pool; + + StyledString ss(pool.MakeRef(android::StyleString{"hello", {{"b", 0, 1}, {"u", 2, 4}}})); + StyledString ss2(pool.MakeRef(android::StyleString{"hello", {{"b", 0, 1}, {"u", 2, 4}}})); + StyledString ss3(pool.MakeRef(android::StyleString{"hi", {{"b", 0, 1}, {"u", 2, 4}}})); + StyledString ss4(pool.MakeRef(android::StyleString{"hello", {{"b", 0, 1}}})); + StyledString ss5(pool.MakeRef(android::StyleString{"hello", {{"b", 0, 1}, {"u", 3, 4}}})); + StyledString ss6(pool.MakeRef(android::StyleString{"hello", {{"b", 0, 1}, {"s", 2, 4}}})); + EXPECT_TRUE(ss.Equals(&ss2)); + EXPECT_TRUE(ss2.Equals(&ss)); + EXPECT_FALSE(ss.Equals(&ss3)); + EXPECT_FALSE(ss.Equals(&ss4)); + EXPECT_FALSE(ss.Equals(&ss5)); + EXPECT_FALSE(ss.Equals(&ss6)); +} + TEST(ResourceValuesTest, StyleMerges) { android::StringPool pool_a; android::StringPool pool_b; diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp index 031dd5bb139c..9b8c3b3d549c 100644 --- a/tools/aapt2/cmd/Compile.cpp +++ b/tools/aapt2/cmd/Compile.cpp @@ -836,6 +836,28 @@ int CompileCommand::Action(const std::vector<std::string>& args) { return 1; } + // Parse the feature flag values. An argument that starts with '@' points to a file to read flag + // values from. + std::vector<std::string> all_feature_flags_args; + for (const std::string& arg : feature_flags_args_) { + if (util::StartsWith(arg, "@")) { + const std::string path = arg.substr(1, arg.size() - 1); + std::string error; + if (!file::AppendArgsFromFile(path, &all_feature_flags_args, &error)) { + context.GetDiagnostics()->Error(android::DiagMessage(path) << error); + return 1; + } + } else { + all_feature_flags_args.push_back(arg); + } + } + + for (const std::string& arg : all_feature_flags_args) { + if (!ParseFeatureFlagsParameter(arg, context.GetDiagnostics(), &options_.feature_flag_values)) { + return 1; + } + } + return Compile(&context, file_collection.get(), archive_writer.get(), options_); } diff --git a/tools/aapt2/cmd/Compile.h b/tools/aapt2/cmd/Compile.h index 61c5b60adb76..70c8791524c8 100644 --- a/tools/aapt2/cmd/Compile.h +++ b/tools/aapt2/cmd/Compile.h @@ -24,6 +24,7 @@ #include "Command.h" #include "ResourceTable.h" #include "androidfw/IDiagnostics.h" +#include "cmd/Util.h" #include "format/Archive.h" #include "process/IResourceTableConsumer.h" @@ -45,6 +46,7 @@ struct CompileOptions { bool preserve_visibility_of_styleables = false; bool verbose = false; std::optional<std::string> product_; + FeatureFlagValues feature_flag_values; }; /** Parses flags and compiles resources to be used in linking. */ @@ -92,6 +94,12 @@ class CompileCommand : public Command { "Leave only resources specific to the given product. All " "other resources (including defaults) are removed.", &options_.product_); + AddOptionalFlagList("--feature-flags", + "Specify the values of feature flags. The pairs in the argument\n" + "are separated by ',' the name is separated from the value by '='.\n" + "The name can have a suffix of ':ro' to indicate it is read only." + "Example: \"flag1=true,flag2:ro=false,flag3=\" (flag3 has no given value).", + &feature_flags_args_); } int Action(const std::vector<std::string>& args) override; @@ -101,6 +109,7 @@ class CompileCommand : public Command { CompileOptions options_; std::optional<std::string> visibility_; std::optional<std::string> trace_folder_; + std::vector<std::string> feature_flags_args_; }; int Compile(IAaptContext* context, io::IFileCollection* inputs, IArchiveWriter* output_writer, diff --git a/tools/aapt2/cmd/Diff.cpp b/tools/aapt2/cmd/Diff.cpp index 5bfc73233bfe..6da3176b2bee 100644 --- a/tools/aapt2/cmd/Diff.cpp +++ b/tools/aapt2/cmd/Diff.cpp @@ -106,7 +106,7 @@ static bool EmitResourceConfigValueDiff( if (!value_a->Equals(value_b)) { std::stringstream str_stream; str_stream << "value " << pkg_a.name << ":" << type_a.named_type << "/" << entry_a.name - << " config=" << config_value_a->config << " does not match:\n"; + << " config='" << config_value_a->config << "' does not match:\n"; value_a->Print(&str_stream); str_stream << "\n vs \n"; value_b->Print(&str_stream); diff --git a/tools/aapt2/cmd/Link.h b/tools/aapt2/cmd/Link.h index 8fe414f4f660..2f17853718ec 100644 --- a/tools/aapt2/cmd/Link.h +++ b/tools/aapt2/cmd/Link.h @@ -332,8 +332,9 @@ class LinkCommand : public Command { AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); AddOptionalFlagList("--feature-flags", "Specify the values of feature flags. The pairs in the argument\n" - "are separated by ',' and the name is separated from the value by '='.\n" - "Example: \"flag1=true,flag2=false,flag3=\" (flag3 has no given value).", + "are separated by ',' the name is separated from the value by '='.\n" + "The name can have a suffix of ':ro' to indicate it is read only." + "Example: \"flag1=true,flag2:ro=false,flag3=\" (flag3 has no given value).", &feature_flags_args_); AddOptionalSwitch("--non-updatable-system", "Mark the app as a non-updatable system app. This inserts\n" diff --git a/tools/aapt2/cmd/Util.cpp b/tools/aapt2/cmd/Util.cpp index 678d84628015..e839fc1ceb0f 100644 --- a/tools/aapt2/cmd/Util.cpp +++ b/tools/aapt2/cmd/Util.cpp @@ -128,7 +128,7 @@ bool ParseFeatureFlagsParameter(StringPiece arg, android::IDiagnostics* diag, if (parts.size() > 2) { diag->Error(android::DiagMessage() << "Invalid feature flag and optional value '" << flag_and_value - << "'. Must be in the format 'flag_name[=true|false]"); + << "'. Must be in the format 'flag_name[:ro][=true|false]"); return false; } @@ -137,6 +137,25 @@ bool ParseFeatureFlagsParameter(StringPiece arg, android::IDiagnostics* diag, diag->Error(android::DiagMessage() << "No name given for one or more flags in: " << arg); return false; } + std::vector<std::string> name_parts = util::Split(flag_name, ':'); + if (name_parts.size() > 2) { + diag->Error(android::DiagMessage() + << "Invalid feature flag and optional value '" << flag_and_value + << "'. Must be in the format 'flag_name[:ro][=true|false]"); + return false; + } + flag_name = name_parts[0]; + bool read_only = false; + if (name_parts.size() == 2) { + if (name_parts[1] == "ro") { + read_only = true; + } else { + diag->Error(android::DiagMessage() + << "Invalid feature flag and optional value '" << flag_and_value + << "'. Must be in the format 'flag_name[:ro][=true|false]"); + return false; + } + } std::optional<bool> flag_value = {}; if (parts.size() == 2) { @@ -151,13 +170,13 @@ bool ParseFeatureFlagsParameter(StringPiece arg, android::IDiagnostics* diag, } } - if (auto [it, inserted] = - out_feature_flag_values->try_emplace(std::string(flag_name), flag_value); + auto ffp = FeatureFlagProperties{read_only, flag_value}; + if (auto [it, inserted] = out_feature_flag_values->try_emplace(std::string(flag_name), ffp); !inserted) { // We are allowing the same flag to appear multiple times, last value wins. diag->Note(android::DiagMessage() << "Value for feature flag '" << flag_name << "' was given more than once"); - it->second = flag_value; + it->second = ffp; } } return true; diff --git a/tools/aapt2/cmd/Util.h b/tools/aapt2/cmd/Util.h index 9ece5dd4d720..6b8813b34082 100644 --- a/tools/aapt2/cmd/Util.h +++ b/tools/aapt2/cmd/Util.h @@ -37,7 +37,17 @@ namespace aapt { -using FeatureFlagValues = std::map<std::string, std::optional<bool>, std::less<>>; +struct FeatureFlagProperties { + bool read_only; + std::optional<bool> enabled; + + FeatureFlagProperties(bool ro, std::optional<bool> e) : read_only(ro), enabled(e) { + } + + bool operator==(const FeatureFlagProperties&) const = default; +}; + +using FeatureFlagValues = std::map<std::string, FeatureFlagProperties, std::less<>>; // Parses a configuration density (ex. hdpi, xxhdpi, 234dpi, anydpi, etc). // Returns Nothing and logs a human friendly error message if the string was not legal. diff --git a/tools/aapt2/cmd/Util_test.cpp b/tools/aapt2/cmd/Util_test.cpp index 723d87ed0af3..35bc63714e58 100644 --- a/tools/aapt2/cmd/Util_test.cpp +++ b/tools/aapt2/cmd/Util_test.cpp @@ -383,21 +383,25 @@ TEST(UtilTest, ParseFeatureFlagsParameter_InvalidValue) { TEST(UtilTest, ParseFeatureFlagsParameter_DuplicateFlag) { auto diagnostics = test::ContextBuilder().Build()->GetDiagnostics(); FeatureFlagValues feature_flag_values; - ASSERT_TRUE( - ParseFeatureFlagsParameter("foo=true,bar=true,foo=false", diagnostics, &feature_flag_values)); - EXPECT_THAT(feature_flag_values, UnorderedElementsAre(Pair("foo", std::optional<bool>(false)), - Pair("bar", std::optional<bool>(true)))); + ASSERT_TRUE(ParseFeatureFlagsParameter("foo=true,bar=true,foo:ro=false", diagnostics, + &feature_flag_values)); + EXPECT_THAT( + feature_flag_values, + UnorderedElementsAre(Pair("foo", FeatureFlagProperties{true, std::optional<bool>(false)}), + Pair("bar", FeatureFlagProperties{false, std::optional<bool>(true)}))); } TEST(UtilTest, ParseFeatureFlagsParameter_Valid) { auto diagnostics = test::ContextBuilder().Build()->GetDiagnostics(); FeatureFlagValues feature_flag_values; - ASSERT_TRUE(ParseFeatureFlagsParameter("foo= true, bar =FALSE,baz=, quux", diagnostics, + ASSERT_TRUE(ParseFeatureFlagsParameter("foo= true, bar:ro =FALSE,baz=, quux", diagnostics, &feature_flag_values)); - EXPECT_THAT(feature_flag_values, - UnorderedElementsAre(Pair("foo", std::optional<bool>(true)), - Pair("bar", std::optional<bool>(false)), - Pair("baz", std::nullopt), Pair("quux", std::nullopt))); + EXPECT_THAT( + feature_flag_values, + UnorderedElementsAre(Pair("foo", FeatureFlagProperties{false, std::optional<bool>(true)}), + Pair("bar", FeatureFlagProperties{true, std::optional<bool>(false)}), + Pair("baz", FeatureFlagProperties{false, std::nullopt}), + Pair("quux", FeatureFlagProperties{false, std::nullopt}))); } TEST (UtilTest, AdjustSplitConstraintsForMinSdk) { diff --git a/tools/aapt2/link/FeatureFlagsFilter.cpp b/tools/aapt2/link/FeatureFlagsFilter.cpp index fdf3f74d4e18..9d40db521e13 100644 --- a/tools/aapt2/link/FeatureFlagsFilter.cpp +++ b/tools/aapt2/link/FeatureFlagsFilter.cpp @@ -63,12 +63,11 @@ class FlagsVisitor : public xml::Visitor { flag_name = flag_name.substr(1); } - if (auto it = feature_flag_values_.find(std::string(flag_name)); - it != feature_flag_values_.end()) { - if (it->second.has_value()) { + if (auto it = feature_flag_values_.find(flag_name); it != feature_flag_values_.end()) { + if (it->second.enabled.has_value()) { if (options_.remove_disabled_elements) { // Remove if flag==true && attr=="!flag" (negated) OR flag==false && attr=="flag" - return *it->second == negated; + return *it->second.enabled == negated; } } else if (options_.flags_must_have_value) { diagnostics_->Error(android::DiagMessage(node->line_number) diff --git a/tools/aapt2/link/FeatureFlagsFilter_test.cpp b/tools/aapt2/link/FeatureFlagsFilter_test.cpp index 53086cc30f18..2db2899e716c 100644 --- a/tools/aapt2/link/FeatureFlagsFilter_test.cpp +++ b/tools/aapt2/link/FeatureFlagsFilter_test.cpp @@ -48,7 +48,7 @@ TEST(FeatureFlagsFilterTest, NoFeatureFlagAttributes) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" /> </manifest>)EOF", - {{"flag", false}}); + {{"flag", FeatureFlagProperties{false, false}}}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); @@ -60,7 +60,7 @@ TEST(FeatureFlagsFilterTest, RemoveElementWithDisabledFlag) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" android:featureFlag="flag" /> </manifest>)EOF", - {{"flag", false}}); + {{"flag", FeatureFlagProperties{false, false}}}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); @@ -73,7 +73,7 @@ TEST(FeatureFlagsFilterTest, RemoveElementWithNegatedEnabledFlag) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" android:featureFlag="!flag" /> </manifest>)EOF", - {{"flag", true}}); + {{"flag", FeatureFlagProperties{false, true}}}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); @@ -86,7 +86,7 @@ TEST(FeatureFlagsFilterTest, KeepElementWithEnabledFlag) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" android:featureFlag="flag" /> </manifest>)EOF", - {{"flag", true}}); + {{"flag", FeatureFlagProperties{false, true}}}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); @@ -102,7 +102,7 @@ TEST(FeatureFlagsFilterTest, SideBySideEnabledAndDisabled) { <permission android:name="FOO" android:featureFlag="flag" android:protectionLevel="dangerous" /> </manifest>)EOF", - {{"flag", true}}); + {{"flag", FeatureFlagProperties{false, true}}}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); @@ -123,7 +123,7 @@ TEST(FeatureFlagsFilterTest, RemoveDeeplyNestedElement) { </activity> </application> </manifest>)EOF", - {{"flag", true}}); + {{"flag", FeatureFlagProperties{false, true}}}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); @@ -145,7 +145,7 @@ TEST(FeatureFlagsFilterTest, KeepDeeplyNestedElement) { </activity> </application> </manifest>)EOF", - {{"flag", true}}); + {{"flag", FeatureFlagProperties{false, true}}}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); @@ -162,7 +162,7 @@ TEST(FeatureFlagsFilterTest, FailOnEmptyFeatureFlagAttribute) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" android:featureFlag=" " /> </manifest>)EOF", - {{"flag", false}}); + {{"flag", FeatureFlagProperties{false, false}}}); ASSERT_THAT(doc, IsNull()); } @@ -171,7 +171,7 @@ TEST(FeatureFlagsFilterTest, FailOnFlagWithNoGivenValue) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" android:featureFlag="flag" /> </manifest>)EOF", - {{"flag", std::nullopt}}); + {{"flag", FeatureFlagProperties{false, std::nullopt}}}); ASSERT_THAT(doc, IsNull()); } @@ -180,7 +180,7 @@ TEST(FeatureFlagsFilterTest, FailOnUnrecognizedFlag) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" android:featureFlag="unrecognized" /> </manifest>)EOF", - {{"flag", true}}); + {{"flag", FeatureFlagProperties{false, true}}}); ASSERT_THAT(doc, IsNull()); } @@ -190,7 +190,7 @@ TEST(FeatureFlagsFilterTest, FailOnMultipleValidationErrors) { <permission android:name="FOO" android:featureFlag="bar" /> <permission android:name="FOO" android:featureFlag="unrecognized" /> </manifest>)EOF", - {{"flag", std::nullopt}}); + {{"flag", FeatureFlagProperties{false, std::nullopt}}}); ASSERT_THAT(doc, IsNull()); } @@ -199,7 +199,8 @@ TEST(FeatureFlagsFilterTest, OptionRemoveDisabledElementsIsFalse) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" android:featureFlag="flag" /> </manifest>)EOF", - {{"flag", false}}, {.remove_disabled_elements = false}); + {{"flag", FeatureFlagProperties{false, false}}}, + {.remove_disabled_elements = false}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); @@ -212,7 +213,8 @@ TEST(FeatureFlagsFilterTest, OptionFlagsMustHaveValueIsFalse) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" android:featureFlag="flag" /> </manifest>)EOF", - {{"flag", std::nullopt}}, {.flags_must_have_value = false}); + {{"flag", FeatureFlagProperties{false, std::nullopt}}}, + {.flags_must_have_value = false}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); @@ -225,7 +227,8 @@ TEST(FeatureFlagsFilterTest, OptionFailOnUnrecognizedFlagsIsFalse) { <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"> <permission android:name="FOO" android:featureFlag="unrecognized" /> </manifest>)EOF", - {{"flag", true}}, {.fail_on_unrecognized_flags = false}); + {{"flag", FeatureFlagProperties{false, true}}}, + {.fail_on_unrecognized_flags = false}); ASSERT_THAT(doc, NotNull()); auto root = doc->root.get(); ASSERT_THAT(root, NotNull()); diff --git a/tools/aapt2/test/Fixture.h b/tools/aapt2/test/Fixture.h index ba4a734e03bb..14298d1678f0 100644 --- a/tools/aapt2/test/Fixture.h +++ b/tools/aapt2/test/Fixture.h @@ -127,4 +127,4 @@ struct LinkCommandBuilder { } // namespace aapt -#endif // AAPT_TEST_FIXTURE_H
\ No newline at end of file +#endif // AAPT_TEST_FIXTURE_H diff --git a/tools/aapt2/xml/XmlPullParser.cpp b/tools/aapt2/xml/XmlPullParser.cpp index 203832d2dbe8..8abc26d67c1f 100644 --- a/tools/aapt2/xml/XmlPullParser.cpp +++ b/tools/aapt2/xml/XmlPullParser.cpp @@ -14,11 +14,13 @@ * limitations under the License. */ -#include <iostream> +#include "xml/XmlPullParser.h" + +#include <algorithm> #include <string> +#include <tuple> #include "util/Util.h" -#include "xml/XmlPullParser.h" #include "xml/XmlUtil.h" using ::android::InputStream; @@ -325,5 +327,18 @@ std::optional<StringPiece> FindNonEmptyAttribute(const XmlPullParser* parser, St return {}; } +XmlPullParser::const_iterator XmlPullParser::FindAttribute(android::StringPiece namespace_uri, + android::StringPiece name) const { + const auto end_iter = end_attributes(); + const auto iter = std::lower_bound(begin_attributes(), end_iter, std::tuple(namespace_uri, name), + [](const Attribute& attr, const auto& rhs) { + return std::tie(attr.namespace_uri, attr.name) < rhs; + }); + if (iter != end_iter && namespace_uri == iter->namespace_uri && name == iter->name) { + return iter; + } + return end_iter; +} + } // namespace xml } // namespace aapt diff --git a/tools/aapt2/xml/XmlPullParser.h b/tools/aapt2/xml/XmlPullParser.h index 655e6dc93e75..64274d032c61 100644 --- a/tools/aapt2/xml/XmlPullParser.h +++ b/tools/aapt2/xml/XmlPullParser.h @@ -19,8 +19,7 @@ #include <expat.h> -#include <algorithm> -#include <istream> +#include <optional> #include <ostream> #include <queue> #include <stack> @@ -302,31 +301,6 @@ inline bool XmlPullParser::Attribute::operator!=(const Attribute& rhs) const { return compare(rhs) != 0; } -inline XmlPullParser::const_iterator XmlPullParser::FindAttribute( - android::StringPiece namespace_uri, android::StringPiece name) const { - const auto end_iter = end_attributes(); - const auto iter = std::lower_bound( - begin_attributes(), end_iter, - std::pair<android::StringPiece, android::StringPiece>(namespace_uri, name), - [](const Attribute& attr, - const std::pair<android::StringPiece, android::StringPiece>& rhs) -> bool { - int cmp = attr.namespace_uri.compare( - 0, attr.namespace_uri.size(), rhs.first.data(), rhs.first.size()); - if (cmp < 0) return true; - if (cmp > 0) return false; - cmp = attr.name.compare(0, attr.name.size(), rhs.second.data(), - rhs.second.size()); - if (cmp < 0) return true; - return false; - }); - - if (iter != end_iter && namespace_uri == iter->namespace_uri && - name == iter->name) { - return iter; - } - return end_iter; -} - } // namespace xml } // namespace aapt 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 index 129733ebc1b6..f39722589a96 100644 --- 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 @@ -25,99 +25,42 @@ 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 Boolean mApsCompliant; private final String mPrivacyPolicy; - private final List<String> mSecurityEndpoints; private final List<String> mFirstPartyEndpoints; private final List<String> 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, + Boolean apsCompliant, String privacyPolicy, - List<String> securityEndpoints, List<String> firstPartyEndpoints, - List<String> 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; + List<String> serviceProviderEndpoints) { + this.mApsCompliant = apsCompliant; 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<Element> 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) { + if (this.mApsCompliant != 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)); + doc, XmlUtils.OD_NAME_APS_COMPLIANT, mApsCompliant)); } 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, + XmlUtils.OD_NAME_FIRST_PARTY_ENDPOINTS, mFirstPartyEndpoints)); } if (this.mServiceProviderEndpoints != null) { @@ -125,21 +68,9 @@ public class AppInfo implements AslMarshallable { XmlUtils.createOdArray( doc, XmlUtils.OD_TAG_STRING_ARRAY, - XmlUtils.OD_NAME_SERVICE_PROVIDER_ENDPOINT, + XmlUtils.OD_NAME_SERVICE_PROVIDER_ENDPOINTS, 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); } @@ -147,54 +78,28 @@ public class AppInfo implements AslMarshallable { @Override public List<Element> toHrDomElements(Document doc) { Element appInfoEle = doc.createElement(XmlUtils.HR_TAG_APP_INFO); - if (this.mTitle != null) { - appInfoEle.setAttribute(XmlUtils.HR_ATTR_TITLE, this.mTitle); - } - if (this.mDescription != null) { - appInfoEle.setAttribute(XmlUtils.HR_ATTR_DESCRIPTION, this.mDescription); - } - if (this.mContainsAds != null) { - appInfoEle.setAttribute( - XmlUtils.HR_ATTR_CONTAINS_ADS, String.valueOf(this.mContainsAds)); - } - if (this.mObeyAps != null) { - appInfoEle.setAttribute(XmlUtils.HR_ATTR_OBEY_APS, String.valueOf(this.mObeyAps)); - } - if (this.mAdsFingerprinting != null) { + if (this.mApsCompliant != null) { appInfoEle.setAttribute( - XmlUtils.HR_ATTR_ADS_FINGERPRINTING, String.valueOf(this.mAdsFingerprinting)); - } - if (this.mSecurityFingerprinting != null) { - appInfoEle.setAttribute( - XmlUtils.HR_ATTR_SECURITY_FINGERPRINTING, - String.valueOf(this.mSecurityFingerprinting)); + XmlUtils.HR_ATTR_APS_COMPLIANT, String.valueOf(this.mApsCompliant)); } if (this.mPrivacyPolicy != null) { appInfoEle.setAttribute(XmlUtils.HR_ATTR_PRIVACY_POLICY, this.mPrivacyPolicy); } - if (this.mSecurityEndpoints != null) { - appInfoEle.setAttribute( - XmlUtils.HR_ATTR_SECURITY_ENDPOINTS, String.join("|", this.mSecurityEndpoints)); - } + if (this.mFirstPartyEndpoints != null) { - appInfoEle.setAttribute( - XmlUtils.HR_ATTR_FIRST_PARTY_ENDPOINTS, - String.join("|", this.mFirstPartyEndpoints)); + appInfoEle.appendChild( + XmlUtils.createHrArray( + doc, XmlUtils.HR_TAG_FIRST_PARTY_ENDPOINTS, mFirstPartyEndpoints)); } + if (this.mServiceProviderEndpoints != null) { - appInfoEle.setAttribute( - XmlUtils.HR_ATTR_SERVICE_PROVIDER_ENDPOINTS, - String.join("|", this.mServiceProviderEndpoints)); - } - if (this.mCategory != null) { - appInfoEle.setAttribute(XmlUtils.HR_ATTR_CATEGORY, this.mCategory); - } - if (this.mEmail != null) { - appInfoEle.setAttribute(XmlUtils.HR_ATTR_EMAIL, this.mEmail); - } - if (this.mWebsite != null) { - appInfoEle.setAttribute(XmlUtils.HR_ATTR_WEBSITE, this.mWebsite); + appInfoEle.appendChild( + XmlUtils.createHrArray( + doc, + XmlUtils.HR_TAG_SERVICE_PROVIDER_ENDPOINTS, + mServiceProviderEndpoints)); } + 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 index c5069619e069..6ad202765218 100644 --- 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 @@ -35,43 +35,19 @@ public class AppInfoFactory implements AslMarshallableFactory<AppInfo> { return null; } - String title = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_TITLE, true); - String description = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_DESCRIPTION, true); - Boolean containsAds = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_CONTAINS_ADS, true); - Boolean obeyAps = XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_OBEY_APS, true); - Boolean adsFingerprinting = - XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_ADS_FINGERPRINTING, true); - Boolean securityFingerprinting = - XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_SECURITY_FINGERPRINTING, true); + Boolean apsCompliant = + XmlUtils.getBoolAttr(appInfoEle, XmlUtils.HR_ATTR_APS_COMPLIANT, true); String privacyPolicy = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_PRIVACY_POLICY, true); - List<String> securityEndpoints = - XmlUtils.getPipelineSplitAttr( - appInfoEle, XmlUtils.HR_ATTR_SECURITY_ENDPOINTS, true); List<String> firstPartyEndpoints = - XmlUtils.getPipelineSplitAttr( - appInfoEle, XmlUtils.HR_ATTR_FIRST_PARTY_ENDPOINTS, true); + XmlUtils.getHrItemsAsStrings( + appInfoEle, XmlUtils.HR_TAG_FIRST_PARTY_ENDPOINTS, true); List<String> serviceProviderEndpoints = - XmlUtils.getPipelineSplitAttr( - appInfoEle, XmlUtils.HR_ATTR_SERVICE_PROVIDER_ENDPOINTS, true); - String category = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_CATEGORY, true); - String email = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_EMAIL, true); - String website = XmlUtils.getStringAttr(appInfoEle, XmlUtils.HR_ATTR_WEBSITE, false); + XmlUtils.getHrItemsAsStrings( + appInfoEle, XmlUtils.HR_TAG_SERVICE_PROVIDER_ENDPOINTS, true); return new AppInfo( - title, - description, - containsAds, - obeyAps, - adsFingerprinting, - securityFingerprinting, - privacyPolicy, - securityEndpoints, - firstPartyEndpoints, - serviceProviderEndpoints, - category, - email, - website); + apsCompliant, privacyPolicy, firstPartyEndpoints, serviceProviderEndpoints); } /** Creates an {@link AslMarshallableFactory} from on-device DOM elements */ @@ -83,42 +59,17 @@ public class AppInfoFactory implements AslMarshallableFactory<AppInfo> { return null; } - String title = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_TITLE, true); - String description = - XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_DESCRIPTION, true); - Boolean containsAds = - XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_CONTAINS_ADS, true); - Boolean obeyAps = XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_OBEY_APS, true); - Boolean adsFingerprinting = - XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_ADS_FINGERPRINTING, true); - Boolean securityFingerprinting = - XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_SECURITY_FINGERPRINTING, true); + Boolean apsCompliant = + XmlUtils.getOdBoolEle(appInfoEle, XmlUtils.OD_NAME_APS_COMPLIANT, true); String privacyPolicy = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_PRIVACY_POLICY, true); - List<String> securityEndpoints = - XmlUtils.getOdStringArray(appInfoEle, XmlUtils.OD_NAME_SECURITY_ENDPOINT, true); List<String> firstPartyEndpoints = - XmlUtils.getOdStringArray(appInfoEle, XmlUtils.OD_NAME_FIRST_PARTY_ENDPOINT, true); + XmlUtils.getOdStringArray(appInfoEle, XmlUtils.OD_NAME_FIRST_PARTY_ENDPOINTS, true); List<String> serviceProviderEndpoints = XmlUtils.getOdStringArray( - appInfoEle, XmlUtils.OD_NAME_SERVICE_PROVIDER_ENDPOINT, true); - String category = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_CATEGORY, true); - String email = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_EMAIL, true); - String website = XmlUtils.getOdStringEle(appInfoEle, XmlUtils.OD_NAME_WEBSITE, false); + appInfoEle, XmlUtils.OD_NAME_SERVICE_PROVIDER_ENDPOINTS, true); return new AppInfo( - title, - description, - containsAds, - obeyAps, - adsFingerprinting, - securityFingerprinting, - privacyPolicy, - securityEndpoints, - firstPartyEndpoints, - serviceProviderEndpoints, - category, - email, - website); + apsCompliant, privacyPolicy, firstPartyEndpoints, serviceProviderEndpoints); } } 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 index ba0e3db52027..3c93c88cd060 100644 --- 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 @@ -24,6 +24,7 @@ import org.w3c.dom.Element; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * Data label representation with data shared and data collected maps containing zero or more {@link @@ -138,7 +139,7 @@ public class DataLabels implements AslMarshallable { "|", dataType.getPurposes().stream() .map(DataType.Purpose::toString) - .toList())); + .collect(Collectors.toList()))); dataLabelsEle.appendChild(hrDataTypeEle); } } 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 index d2326d10e176..284a4b804435 100644 --- 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 @@ -25,6 +25,7 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; /** * Data usage type representation. Types are specific to a {@link DataCategory} and contains @@ -182,7 +183,7 @@ public class DataType implements AslMarshallable { XmlUtils.OD_NAME_PURPOSES, this.getPurposes().stream() .map(p -> String.valueOf(p.getValue())) - .toList())); + .collect(Collectors.toList()))); } maybeAddBoolToOdElement( 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 deleted file mode 100644 index 94fad9607880..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfo.java +++ /dev/null @@ -1,173 +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.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<Element> 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); - } - - /** Creates the human-readable DOM elements from the AslMarshallable Java Object. */ - @Override - public List<Element> toHrDomElements(Document doc) { - Element developerInfoEle = doc.createElement(XmlUtils.HR_TAG_DEVELOPER_INFO); - if (mName != null) { - developerInfoEle.setAttribute(XmlUtils.HR_ATTR_NAME, mName); - } - if (mEmail != null) { - developerInfoEle.setAttribute(XmlUtils.HR_ATTR_EMAIL, mEmail); - } - if (mAddress != null) { - developerInfoEle.setAttribute(XmlUtils.HR_ATTR_ADDRESS, mAddress); - } - if (mCountryRegion != null) { - developerInfoEle.setAttribute(XmlUtils.HR_ATTR_COUNTRY_REGION, mCountryRegion); - } - if (mDeveloperRelationship != null) { - developerInfoEle.setAttribute( - XmlUtils.HR_ATTR_DEVELOPER_RELATIONSHIP, mDeveloperRelationship.toString()); - } - if (mWebsite != null) { - developerInfoEle.setAttribute(XmlUtils.HR_ATTR_WEBSITE, mWebsite); - } - if (mAppDeveloperRegistryId != null) { - developerInfoEle.setAttribute( - XmlUtils.HR_ATTR_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 deleted file mode 100644 index 0f3b41cd5d1a..000000000000 --- a/tools/app_metadata_bundles/src/lib/java/com/android/asllib/marshallable/DeveloperInfoFactory.java +++ /dev/null @@ -1,96 +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.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<DeveloperInfo> { - - /** Creates a {@link DeveloperInfo} from the human-readable DOM element. */ - @Override - public DeveloperInfo createFromHrElements(List<Element> 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, true); - String email = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_EMAIL, true); - String address = XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_ADDRESS, true); - String countryRegion = - XmlUtils.getStringAttr(developerInfoEle, XmlUtils.HR_ATTR_COUNTRY_REGION, true); - DeveloperInfo.DeveloperRelationship developerRelationship = - DeveloperInfo.DeveloperRelationship.forString( - XmlUtils.getStringAttr( - developerInfoEle, XmlUtils.HR_ATTR_DEVELOPER_RELATIONSHIP, true)); - 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); - } - - /** Creates an {@link AslMarshallableFactory} from on-device DOM elements */ - @Override - public DeveloperInfo createFromOdElements(List<Element> elements) throws MalformedXmlException { - Element developerInfoEle = XmlUtils.getSingleElement(elements); - if (developerInfoEle == null) { - AslgenUtil.logI("No DeveloperInfo found in od format."); - return null; - } - String name = XmlUtils.getOdStringEle(developerInfoEle, XmlUtils.OD_NAME_NAME, true); - String email = XmlUtils.getOdStringEle(developerInfoEle, XmlUtils.OD_NAME_EMAIL, true); - String address = XmlUtils.getOdStringEle(developerInfoEle, XmlUtils.OD_NAME_ADDRESS, true); - String countryRegion = - XmlUtils.getOdStringEle(developerInfoEle, XmlUtils.OD_NAME_COUNTRY_REGION, true); - DeveloperInfo.DeveloperRelationship developerRelationship = - DeveloperInfo.DeveloperRelationship.forValue( - (int) - (long) - XmlUtils.getOdLongEle( - developerInfoEle, - XmlUtils.OD_NAME_DEVELOPER_RELATIONSHIP, - true)); - String website = XmlUtils.getOdStringEle(developerInfoEle, XmlUtils.OD_NAME_WEBSITE, false); - String appDeveloperRegistryId = - XmlUtils.getOdStringEle( - developerInfoEle, XmlUtils.OD_NAME_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 index 6af80715f7c1..2a4e130981af 100644 --- 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 @@ -25,21 +25,10 @@ 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; - private final SecurityLabels mSecurityLabels; - private final ThirdPartyVerification mThirdPartyVerification; - public SafetyLabels( - Long version, - DataLabels dataLabels, - SecurityLabels securityLabels, - ThirdPartyVerification thirdPartyVerification) { - this.mVersion = version; + public SafetyLabels(DataLabels dataLabels) { this.mDataLabels = dataLabels; - this.mSecurityLabels = securityLabels; - this.mThirdPartyVerification = thirdPartyVerification; } /** Returns the data label for the safety label */ @@ -47,27 +36,14 @@ public class SafetyLabels implements AslMarshallable { 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<Element> 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)); } - if (mSecurityLabels != null) { - XmlUtils.appendChildren(safetyLabelsEle, mSecurityLabels.toOdDomElements(doc)); - } - if (mThirdPartyVerification != null) { - XmlUtils.appendChildren(safetyLabelsEle, mThirdPartyVerification.toOdDomElements(doc)); - } return XmlUtils.listOf(safetyLabelsEle); } @@ -75,17 +51,10 @@ public class SafetyLabels implements AslMarshallable { @Override public List<Element> toHrDomElements(Document doc) { Element safetyLabelsEle = doc.createElement(XmlUtils.HR_TAG_SAFETY_LABELS); - safetyLabelsEle.setAttribute(XmlUtils.HR_ATTR_VERSION, String.valueOf(mVersion)); if (mDataLabels != null) { XmlUtils.appendChildren(safetyLabelsEle, mDataLabels.toHrDomElements(doc)); } - if (mSecurityLabels != null) { - XmlUtils.appendChildren(safetyLabelsEle, mSecurityLabels.toHrDomElements(doc)); - } - if (mThirdPartyVerification != null) { - XmlUtils.appendChildren(safetyLabelsEle, mThirdPartyVerification.toHrDomElements(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 index 2644b435311b..2738337b7080 100644 --- 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 @@ -34,7 +34,6 @@ public class SafetyLabelsFactory implements AslMarshallableFactory<SafetyLabels> AslgenUtil.logI("No SafetyLabels found in hr format."); return null; } - long version = XmlUtils.tryGetVersion(safetyLabelsEle); DataLabels dataLabels = new DataLabelsFactory() @@ -44,23 +43,7 @@ public class SafetyLabelsFactory implements AslMarshallableFactory<SafetyLabels> safetyLabelsEle, XmlUtils.HR_TAG_DATA_LABELS, false))); - SecurityLabels securityLabels = - new SecurityLabelsFactory() - .createFromHrElements( - XmlUtils.listOf( - XmlUtils.getSingleChildElement( - safetyLabelsEle, - XmlUtils.HR_TAG_SECURITY_LABELS, - false))); - ThirdPartyVerification thirdPartyVerification = - new ThirdPartyVerificationFactory() - .createFromHrElements( - XmlUtils.listOf( - XmlUtils.getSingleChildElement( - safetyLabelsEle, - XmlUtils.HR_TAG_THIRD_PARTY_VERIFICATION, - false))); - return new SafetyLabels(version, dataLabels, securityLabels, thirdPartyVerification); + return new SafetyLabels(dataLabels); } /** Creates an {@link AslMarshallableFactory} from on-device DOM elements */ @@ -71,7 +54,6 @@ public class SafetyLabelsFactory implements AslMarshallableFactory<SafetyLabels> AslgenUtil.logI("No SafetyLabels found in od format."); return null; } - Long version = XmlUtils.getOdLongEle(safetyLabelsEle, XmlUtils.OD_NAME_VERSION, true); DataLabels dataLabels = new DataLabelsFactory() @@ -81,22 +63,7 @@ public class SafetyLabelsFactory implements AslMarshallableFactory<SafetyLabels> safetyLabelsEle, XmlUtils.OD_NAME_DATA_LABELS, false))); - SecurityLabels securityLabels = - new SecurityLabelsFactory() - .createFromOdElements( - XmlUtils.listOf( - XmlUtils.getOdPbundleWithName( - safetyLabelsEle, - XmlUtils.OD_NAME_SECURITY_LABELS, - false))); - ThirdPartyVerification thirdPartyVerification = - new ThirdPartyVerificationFactory() - .createFromOdElements( - XmlUtils.listOf( - XmlUtils.getOdPbundleWithName( - safetyLabelsEle, - XmlUtils.OD_NAME_THIRD_PARTY_VERIFICATION, - false))); - return new SafetyLabels(version, dataLabels, securityLabels, thirdPartyVerification); + + return new SafetyLabels(dataLabels); } } 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 index 6a8700a10d3f..9f789f0b9c1c 100644 --- 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 @@ -23,22 +23,14 @@ import org.w3c.dom.Element; import java.util.List; -/** TransparencyInfo representation containing {@link DeveloperInfo} and {@link AppInfo} */ +/** TransparencyInfo representation containing {@link AppInfo} */ public class TransparencyInfo implements AslMarshallable { - - private final DeveloperInfo mDeveloperInfo; private final AppInfo mAppInfo; - public TransparencyInfo(DeveloperInfo developerInfo, AppInfo appInfo) { - this.mDeveloperInfo = developerInfo; + public TransparencyInfo(AppInfo appInfo) { 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; @@ -49,9 +41,6 @@ public class TransparencyInfo implements AslMarshallable { public List<Element> 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)); } @@ -62,9 +51,6 @@ public class TransparencyInfo implements AslMarshallable { @Override public List<Element> toHrDomElements(Document doc) { Element transparencyInfoEle = doc.createElement(XmlUtils.HR_TAG_TRANSPARENCY_INFO); - if (mDeveloperInfo != null) { - XmlUtils.appendChildren(transparencyInfoEle, mDeveloperInfo.toHrDomElements(doc)); - } if (mAppInfo != null) { XmlUtils.appendChildren(transparencyInfoEle, mAppInfo.toHrDomElements(doc)); } 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 index 94c564087918..40f2872e4380 100644 --- 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 @@ -36,18 +36,11 @@ public class TransparencyInfoFactory implements AslMarshallableFactory<Transpare 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); + XmlUtils.getSingleChildElement(transparencyInfoEle, XmlUtils.HR_TAG_APP_INFO, true); AppInfo appInfo = new AppInfoFactory().createFromHrElements(XmlUtils.listOf(appInfoEle)); - return new TransparencyInfo(developerInfo, appInfo); + return new TransparencyInfo(appInfo); } /** Creates an {@link AslMarshallableFactory} from on-device DOM elements */ @@ -60,17 +53,10 @@ public class TransparencyInfoFactory implements AslMarshallableFactory<Transpare return null; } - Element developerInfoEle = - XmlUtils.getOdPbundleWithName( - transparencyInfoEle, XmlUtils.OD_NAME_DEVELOPER_INFO, false); - DeveloperInfo developerInfo = - new DeveloperInfoFactory().createFromOdElements(XmlUtils.listOf(developerInfoEle)); - Element appInfoEle = - XmlUtils.getOdPbundleWithName( - transparencyInfoEle, XmlUtils.OD_NAME_APP_INFO, false); + XmlUtils.getOdPbundleWithName(transparencyInfoEle, XmlUtils.OD_NAME_APP_INFO, true); AppInfo appInfo = new AppInfoFactory().createFromOdElements(XmlUtils.listOf(appInfoEle)); - return new TransparencyInfo(developerInfo, appInfo); + return new TransparencyInfo(appInfo); } } 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 index 97cbc3950490..2c1517bdf8ab 100644 --- 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 @@ -25,6 +25,7 @@ import org.w3c.dom.NodeList; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; public class XmlUtils { public static final String DATA_TYPE_SEPARATOR = "_data_type_"; @@ -42,6 +43,7 @@ public class XmlUtils { public static final String HR_TAG_DATA_COLLECTED = "data-collected"; public static final String HR_TAG_DATA_COLLECTED_EPHEMERAL = "data-collected-ephemeral"; public static final String HR_TAG_DATA_SHARED = "data-shared"; + public static final String HR_TAG_ITEM = "item"; public static final String HR_ATTR_NAME = "name"; public static final String HR_ATTR_EMAIL = "email"; public static final String HR_ATTR_ADDRESS = "address"; @@ -64,12 +66,13 @@ public class XmlUtils { 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_APS_COMPLIANT = "apsCompliant"; 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_TAG_FIRST_PARTY_ENDPOINTS = "first-party-endpoints"; + public static final String HR_TAG_SERVICE_PROVIDER_ENDPOINTS = "service-provider-endpoints"; public static final String HR_ATTR_CATEGORY = "category"; public static final String OD_TAG_BUNDLE = "bundle"; @@ -98,12 +101,13 @@ public class XmlUtils { 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_APS_COMPLIANT = "aps_compliant"; 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_SECURITY_ENDPOINT = "security_endpoints"; + public static final String OD_NAME_FIRST_PARTY_ENDPOINTS = "first_party_endpoints"; + public static final String OD_NAME_SERVICE_PROVIDER_ENDPOINTS = "service_provider_endpoints"; public static final String OD_NAME_CATEGORY = "category"; public static final String OD_NAME_VERSION = "version"; public static final String OD_NAME_URL = "url"; @@ -128,7 +132,9 @@ public class XmlUtils { /** Gets the top-level children with the tag name.. */ public static List<Element> getChildrenByTagName(Node parentEle, String tagName) { var elements = XmlUtils.asElementList(parentEle.getChildNodes()); - return elements.stream().filter(e -> e.getTagName().equals(tagName)).toList(); + return elements.stream() + .filter(e -> e.getTagName().equals(tagName)) + .collect(Collectors.toList()); } /** @@ -237,7 +243,18 @@ public class XmlUtils { return ele; } - /** Create OD style array DOM Element, which can represent any time but is stored as Strings. */ + /** Create HR style array DOM Element. */ + public static Element createHrArray(Document doc, String arrayTagName, List<String> arrayVals) { + Element arrEle = doc.createElement(arrayTagName); + for (String s : arrayVals) { + Element itemEle = doc.createElement(XmlUtils.HR_TAG_ITEM); + itemEle.setTextContent(s); + arrEle.appendChild(itemEle); + } + return arrEle; + } + + /** Create OD style array DOM Element, which can represent any type but is stored as Strings. */ public static Element createOdArray( Document doc, String arrayTag, String arrayName, List<String> arrayVals) { Element arrEle = doc.createElement(arrayTag); @@ -272,7 +289,8 @@ public class XmlUtils { /** Gets a pipeline-split attribute. */ public static List<String> getPipelineSplitAttr(Element ele, String attrName, boolean required) throws MalformedXmlException { - List<String> list = Arrays.stream(ele.getAttribute(attrName).split("\\|")).toList(); + List<String> list = + Arrays.stream(ele.getAttribute(attrName).split("\\|")).collect(Collectors.toList()); if ((list.isEmpty() || list.get(0).isEmpty()) && required) { throw new MalformedXmlException( String.format( @@ -301,7 +319,7 @@ public class XmlUtils { List<Element> boolEles = XmlUtils.getChildrenByTagName(ele, XmlUtils.OD_TAG_BOOLEAN).stream() .filter(e -> e.getAttribute(XmlUtils.OD_ATTR_NAME).equals(nameName)) - .toList(); + .collect(Collectors.toList()); if (boolEles.size() > 1) { throw new MalformedXmlException( String.format( @@ -332,7 +350,7 @@ public class XmlUtils { List<Element> longEles = XmlUtils.getChildrenByTagName(ele, XmlUtils.OD_TAG_LONG).stream() .filter(e -> e.getAttribute(XmlUtils.OD_ATTR_NAME).equals(nameName)) - .toList(); + .collect(Collectors.toList()); if (longEles.size() > 1) { throw new MalformedXmlException( String.format( @@ -363,7 +381,7 @@ public class XmlUtils { List<Element> eles = XmlUtils.getChildrenByTagName(ele, XmlUtils.OD_TAG_STRING).stream() .filter(e -> e.getAttribute(XmlUtils.OD_ATTR_NAME).equals(nameName)) - .toList(); + .collect(Collectors.toList()); if (eles.size() > 1) { throw new MalformedXmlException( String.format( @@ -391,7 +409,7 @@ public class XmlUtils { List<Element> eles = XmlUtils.getChildrenByTagName(ele, XmlUtils.OD_TAG_PBUNDLE_AS_MAP).stream() .filter(e -> e.getAttribute(XmlUtils.OD_ATTR_NAME).equals(nameName)) - .toList(); + .collect(Collectors.toList()); if (eles.size() > 1) { throw new MalformedXmlException( String.format( @@ -435,7 +453,7 @@ public class XmlUtils { List<Element> intArrayEles = XmlUtils.getChildrenByTagName(ele, XmlUtils.OD_TAG_INT_ARRAY).stream() .filter(e -> e.getAttribute(XmlUtils.OD_ATTR_NAME).equals(nameName)) - .toList(); + .collect(Collectors.toList()); if (intArrayEles.size() > 1) { throw new MalformedXmlException( String.format("Found more than one %s in %s.", nameName, ele.getTagName())); @@ -456,13 +474,39 @@ public class XmlUtils { return ints; } + /** Gets human-readable style String array. */ + public static List<String> getHrItemsAsStrings( + Element parent, String elementName, boolean required) throws MalformedXmlException { + + List<Element> arrayEles = XmlUtils.getChildrenByTagName(parent, elementName); + if (arrayEles.size() > 1) { + throw new MalformedXmlException( + String.format( + "Found more than one %s in %s.", elementName, parent.getTagName())); + } + if (arrayEles.isEmpty()) { + if (required) { + throw new MalformedXmlException( + String.format("Found no %s in %s.", elementName, parent.getTagName())); + } + return null; + } + Element arrayEle = arrayEles.get(0); + List<Element> itemEles = XmlUtils.getChildrenByTagName(arrayEle, XmlUtils.HR_TAG_ITEM); + List<String> strs = new ArrayList<String>(); + for (Element itemEle : itemEles) { + strs.add(itemEle.getTextContent()); + } + return strs; + } + /** Gets on-device style String array. */ public static List<String> getOdStringArray(Element ele, String nameName, boolean required) throws MalformedXmlException { List<Element> arrayEles = XmlUtils.getChildrenByTagName(ele, XmlUtils.OD_TAG_STRING_ARRAY).stream() .filter(e -> e.getAttribute(XmlUtils.OD_ATTR_NAME).equals(nameName)) - .toList(); + .collect(Collectors.toList()); if (arrayEles.size() > 1) { throw new MalformedXmlException( String.format( 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 index dbeeb496144a..14e65e5e5b2b 100644 --- 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 @@ -20,11 +20,8 @@ import com.android.asllib.marshallable.AndroidSafetyLabelTest; import com.android.asllib.marshallable.AppInfoTest; import com.android.asllib.marshallable.DataLabelsTest; import com.android.asllib.marshallable.DataTypeEqualityTest; -import com.android.asllib.marshallable.DeveloperInfoTest; import com.android.asllib.marshallable.SafetyLabelsTest; -import com.android.asllib.marshallable.SecurityLabelsTest; import com.android.asllib.marshallable.SystemAppSafetyLabelTest; -import com.android.asllib.marshallable.ThirdPartyVerificationTest; import com.android.asllib.marshallable.TransparencyInfoTest; import org.junit.runner.RunWith; @@ -35,14 +32,10 @@ import org.junit.runners.Suite; AslgenTests.class, AndroidSafetyLabelTest.class, AppInfoTest.class, - // DataCategoryTest.class, DataLabelsTest.class, DataTypeEqualityTest.class, - DeveloperInfoTest.class, SafetyLabelsTest.class, - SecurityLabelsTest.class, SystemAppSafetyLabelTest.class, - ThirdPartyVerificationTest.class, TransparencyInfoTest.class }) public class AllTests {} 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 index 9e91c6f22641..d823c482adfe 100644 --- 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 @@ -20,6 +20,7 @@ import static org.junit.Assert.assertThrows; import com.android.asllib.testutils.TestUtils; import com.android.asllib.util.MalformedXmlException; +import com.android.asllib.util.XmlUtils; import org.junit.Before; import org.junit.Test; @@ -34,35 +35,15 @@ 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<String> REQUIRED_FIELD_NAMES = - List.of( - "title", - "description", - "containsAds", - "obeyAps", - "adsFingerprinting", - "securityFingerprinting", - "privacyPolicy", - "securityEndpoints", - "firstPartyEndpoints", - "serviceProviderEndpoints", - "category", - "email"); + List.of("apsCompliant", "privacyPolicy"); public static final List<String> REQUIRED_FIELD_NAMES_OD = - List.of( - "title", - "description", - "contains_ads", - "obey_aps", - "ads_fingerprinting", - "security_fingerprinting", - "privacy_policy", - "security_endpoint", - "first_party_endpoint", - "service_provider_endpoint", - "category", - "email"); - public static final List<String> OPTIONAL_FIELD_NAMES = List.of("website"); - public static final List<String> OPTIONAL_FIELD_NAMES_OD = List.of("website"); + List.of("aps_compliant", "privacy_policy"); + public static final List<String> REQUIRED_CHILD_NAMES = + List.of("first-party-endpoints", "service-provider-endpoints"); + public static final List<String> REQUIRED_CHILD_NAMES_OD = + List.of("first_party_endpoints", "service_provider_endpoints"); + public static final List<String> OPTIONAL_FIELD_NAMES = List.of(); + public static final List<String> OPTIONAL_FIELD_NAMES_OD = List.of(); private static final String ALL_FIELDS_VALID_FILE_NAME = "all-fields-valid.xml"; @@ -110,6 +91,34 @@ public class AppInfoTest { } } + /** Tests missing required child fails. */ + @Test + public void testMissingRequiredChild() throws Exception { + System.out.println("Starting testMissingRequiredFields"); + for (String reqChildName : REQUIRED_CHILD_NAMES) { + System.out.println("testing missing required child hr: " + reqChildName); + var appInfoEle = + TestUtils.getElementsFromResource( + Paths.get(APP_INFO_HR_PATH, ALL_FIELDS_VALID_FILE_NAME)); + var child = XmlUtils.getChildrenByTagName(appInfoEle.get(0), reqChildName).get(0); + appInfoEle.get(0).removeChild(child); + assertThrows( + MalformedXmlException.class, + () -> new AppInfoFactory().createFromHrElements(appInfoEle)); + } + + for (String reqField : REQUIRED_CHILD_NAMES_OD) { + System.out.println("testing missing required child od: " + reqField); + var appInfoEle = + TestUtils.getElementsFromResource( + Paths.get(APP_INFO_OD_PATH, ALL_FIELDS_VALID_FILE_NAME)); + TestUtils.removeOdChildEleWithName(appInfoEle.get(0), reqField); + assertThrows( + MalformedXmlException.class, + () -> new AppInfoFactory().createFromOdElements(appInfoEle)); + } + } + /** Tests missing optional fields passes. */ @Test public void testMissingOptionalFields() throws Exception { 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 deleted file mode 100644 index 72e8d654b542..000000000000 --- a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/DeveloperInfoTest.java +++ /dev/null @@ -1,132 +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.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 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<String> REQUIRED_FIELD_NAMES = - List.of("address", "countryRegion", "email", "name", "relationship"); - public static final List<String> REQUIRED_FIELD_NAMES_OD = - List.of("address", "country_region", "email", "name", "relationship"); - public static final List<String> OPTIONAL_FIELD_NAMES = List.of("website", "registryId"); - public static final List<String> OPTIONAL_FIELD_NAMES_OD = - List.of("website", "app_developer_registry_id"); - - private static final String ALL_FIELDS_VALID_FILE_NAME = "all-fields-valid.xml"; - - /** 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."); - } - - /** Test for all fields valid. */ - @Test - public void testAllFieldsValid() throws Exception { - System.out.println("starting testAllFieldsValid."); - testHrToOdDeveloperInfo(ALL_FIELDS_VALID_FILE_NAME); - testOdToHrDeveloperInfo(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)); - } - - for (String reqField : REQUIRED_FIELD_NAMES_OD) { - System.out.println("testing missing required field od: " + reqField); - var developerInfoEle = - TestUtils.getElementsFromResource( - Paths.get(DEVELOPER_INFO_OD_PATH, ALL_FIELDS_VALID_FILE_NAME)); - TestUtils.removeOdChildEleWithName(developerInfoEle.get(0), reqField); - - assertThrows( - MalformedXmlException.class, - () -> new DeveloperInfoFactory().createFromOdElements(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(TestUtils.document()); - } - - for (String optField : OPTIONAL_FIELD_NAMES_OD) { - var developerInfoEle = - TestUtils.getElementsFromResource( - Paths.get(DEVELOPER_INFO_OD_PATH, ALL_FIELDS_VALID_FILE_NAME)); - TestUtils.removeOdChildEleWithName(developerInfoEle.get(0), optField); - DeveloperInfo developerInfo = - new DeveloperInfoFactory().createFromOdElements(developerInfoEle); - developerInfo.toHrDomElements(TestUtils.document()); - } - } - - private void testHrToOdDeveloperInfo(String fileName) throws Exception { - TestUtils.testHrToOd( - TestUtils.document(), - new DeveloperInfoFactory(), - DEVELOPER_INFO_HR_PATH, - DEVELOPER_INFO_OD_PATH, - fileName); - } - - private void testOdToHrDeveloperInfo(String fileName) throws Exception { - TestUtils.testOdToHr( - TestUtils.document(), - new DeveloperInfoFactory(), - DEVELOPER_INFO_OD_PATH, - DEVELOPER_INFO_HR_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 index bba6b548beaf..19d1626f7054 100644 --- 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 @@ -28,26 +28,14 @@ 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 static final String WITH_SECURITY_LABELS_FILE_NAME = "with-security-labels.xml"; - private static final String WITH_THIRD_PARTY_VERIFICATION_FILE_NAME = - "with-third-party-verification.xml"; @Before public void setUp() throws Exception { System.out.println("set up."); } - /** Test for safety labels missing version. */ - @Test - public void testSafetyLabelsMissingVersion() throws Exception { - System.out.println("starting testSafetyLabelsMissingVersion."); - hrToOdExpectException(MISSING_VERSION_FILE_NAME); - odToHrExpectException(MISSING_VERSION_FILE_NAME); - } - /** Test for safety labels valid empty. */ @Test public void testSafetyLabelsValidEmptyFile() throws Exception { @@ -64,22 +52,6 @@ public class SafetyLabelsTest { testOdToHrSafetyLabels(WITH_DATA_LABELS_FILE_NAME); } - /** Test for safety labels with security labels. */ - @Test - public void testSafetyLabelsWithSecurityLabels() throws Exception { - System.out.println("starting testSafetyLabelsWithSecurityLabels."); - testHrToOdSafetyLabels(WITH_SECURITY_LABELS_FILE_NAME); - testOdToHrSafetyLabels(WITH_SECURITY_LABELS_FILE_NAME); - } - - /** Test for safety labels with third party verification. */ - @Test - public void testSafetyLabelsWithThirdPartyVerification() throws Exception { - System.out.println("starting testSafetyLabelsWithThirdPartyVerification."); - testHrToOdSafetyLabels(WITH_THIRD_PARTY_VERIFICATION_FILE_NAME); - testOdToHrSafetyLabels(WITH_THIRD_PARTY_VERIFICATION_FILE_NAME); - } - private void hrToOdExpectException(String fileName) { TestUtils.hrToOdExpectException(new SafetyLabelsFactory(), SAFETY_LABELS_HR_PATH, fileName); } diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SecurityLabelsTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SecurityLabelsTest.java deleted file mode 100644 index a940bc63c685..000000000000 --- a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/SecurityLabelsTest.java +++ /dev/null @@ -1,96 +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.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 java.nio.file.Paths; -import java.util.List; - -@RunWith(JUnit4.class) -public class SecurityLabelsTest { - private static final String SECURITY_LABELS_HR_PATH = "com/android/asllib/securitylabels/hr"; - private static final String SECURITY_LABELS_OD_PATH = "com/android/asllib/securitylabels/od"; - - public static final List<String> OPTIONAL_FIELD_NAMES = - List.of("isDataDeletable", "isDataEncrypted"); - public static final List<String> OPTIONAL_FIELD_NAMES_OD = - List.of("is_data_deletable", "is_data_encrypted"); - - private static final String ALL_FIELDS_VALID_FILE_NAME = "all-fields-valid.xml"; - - /** 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."); - } - - /** Test for all fields valid. */ - @Test - public void testAllFieldsValid() throws Exception { - System.out.println("starting testAllFieldsValid."); - testHrToOdSecurityLabels(ALL_FIELDS_VALID_FILE_NAME); - testOdToHrSecurityLabels(ALL_FIELDS_VALID_FILE_NAME); - } - - /** Tests missing optional fields passes. */ - @Test - public void testMissingOptionalFields() throws Exception { - for (String optField : OPTIONAL_FIELD_NAMES) { - var ele = - TestUtils.getElementsFromResource( - Paths.get(SECURITY_LABELS_HR_PATH, ALL_FIELDS_VALID_FILE_NAME)); - ele.get(0).removeAttribute(optField); - SecurityLabels securityLabels = new SecurityLabelsFactory().createFromHrElements(ele); - securityLabels.toOdDomElements(TestUtils.document()); - } - for (String optField : OPTIONAL_FIELD_NAMES_OD) { - var ele = - TestUtils.getElementsFromResource( - Paths.get(SECURITY_LABELS_OD_PATH, ALL_FIELDS_VALID_FILE_NAME)); - TestUtils.removeOdChildEleWithName(ele.get(0), optField); - SecurityLabels securityLabels = new SecurityLabelsFactory().createFromOdElements(ele); - securityLabels.toHrDomElements(TestUtils.document()); - } - } - - private void testHrToOdSecurityLabels(String fileName) throws Exception { - TestUtils.testHrToOd( - TestUtils.document(), - new SecurityLabelsFactory(), - SECURITY_LABELS_HR_PATH, - SECURITY_LABELS_OD_PATH, - fileName); - } - - private void testOdToHrSecurityLabels(String fileName) throws Exception { - TestUtils.testOdToHr( - TestUtils.document(), - new SecurityLabelsFactory(), - SECURITY_LABELS_OD_PATH, - SECURITY_LABELS_HR_PATH, - fileName); - } -} diff --git a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/ThirdPartyVerificationTest.java b/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/ThirdPartyVerificationTest.java deleted file mode 100644 index ec86d0f863af..000000000000 --- a/tools/app_metadata_bundles/src/test/java/com/android/asllib/marshallable/ThirdPartyVerificationTest.java +++ /dev/null @@ -1,87 +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.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; - -@RunWith(JUnit4.class) -public class ThirdPartyVerificationTest { - private static final String THIRD_PARTY_VERIFICATION_HR_PATH = - "com/android/asllib/thirdpartyverification/hr"; - private static final String THIRD_PARTY_VERIFICATION_OD_PATH = - "com/android/asllib/thirdpartyverification/od"; - - private static final String VALID_FILE_NAME = "valid.xml"; - private static final String MISSING_URL_FILE_NAME = "missing-url.xml"; - - /** 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."); - } - - /** Test for valid. */ - @Test - public void testValid() throws Exception { - System.out.println("starting testValid."); - testHrToOdThirdPartyVerification(VALID_FILE_NAME); - testOdToHrThirdPartyVerification(VALID_FILE_NAME); - } - - /** Tests missing url. */ - @Test - public void testMissingUrl() throws Exception { - System.out.println("starting testMissingUrl."); - hrToOdExpectException(MISSING_URL_FILE_NAME); - odToHrExpectException(MISSING_URL_FILE_NAME); - } - - private void hrToOdExpectException(String fileName) { - TestUtils.hrToOdExpectException( - new ThirdPartyVerificationFactory(), THIRD_PARTY_VERIFICATION_HR_PATH, fileName); - } - - private void odToHrExpectException(String fileName) { - TestUtils.odToHrExpectException( - new ThirdPartyVerificationFactory(), THIRD_PARTY_VERIFICATION_OD_PATH, fileName); - } - - private void testHrToOdThirdPartyVerification(String fileName) throws Exception { - TestUtils.testHrToOd( - TestUtils.document(), - new ThirdPartyVerificationFactory(), - THIRD_PARTY_VERIFICATION_HR_PATH, - THIRD_PARTY_VERIFICATION_OD_PATH, - fileName); - } - - private void testOdToHrThirdPartyVerification(String fileName) throws Exception { - TestUtils.testOdToHr( - TestUtils.document(), - new ThirdPartyVerificationFactory(), - THIRD_PARTY_VERIFICATION_OD_PATH, - THIRD_PARTY_VERIFICATION_HR_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 index f49424061427..8a0b35eac7c8 100644 --- 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 @@ -29,9 +29,6 @@ public class TransparencyInfoTest { "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"; @Before @@ -39,22 +36,6 @@ public class TransparencyInfoTest { System.out.println("set up."); } - /** Test for transparency info valid empty. */ - @Test - public void testTransparencyInfoValidEmptyFile() throws Exception { - System.out.println("starting testTransparencyInfoValidEmptyFile."); - testHrToOdTransparencyInfo(VALID_EMPTY_FILE_NAME); - testOdToHrTransparencyInfo(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); - testOdToHrTransparencyInfo(WITH_DEVELOPER_INFO_FILE_NAME); - } - /** Test for transparency info with app info. */ @Test public void testTransparencyInfoWithAppInfo() throws Exception { 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 index 53794a1d1c80..03e71d28f4cc 100644 --- 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 @@ -1,4 +1,4 @@ <app-metadata-bundles version="123456"> - <safety-labels version="12345"> + <safety-labels> </safety-labels> </app-metadata-bundles>
\ 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 index 00bcfa80e9b1..a00ef6565cf4 100644 --- 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 @@ -1,4 +1,15 @@ <app-metadata-bundles version="123456"> -<transparency-info> -</transparency-info> + <transparency-info> + <app-info + apsCompliant="false" + privacyPolicy="www.example.com"> + <first-party-endpoints> + <item>url1</item> + </first-party-endpoints> + <service-provider-endpoints> + <item>url55</item> + <item>url56</item> + </service-provider-endpoints> + </app-info> + </transparency-info> </app-metadata-bundles>
\ 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 index 74644ed0413c..f00fb26bf1ee 100644 --- 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 @@ -1,6 +1,5 @@ <bundle> <long name="version" value="123456"/> <pbundle_as_map name="safety_labels"> - <long name="version" value="12345"/> </pbundle_as_map> </bundle> 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 index 63c5094333cc..d0c8668564bd 100644 --- 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 @@ -1,4 +1,16 @@ <bundle> <long name="version" value="123456"/> - <pbundle_as_map name="transparency_info"/> + <pbundle_as_map name="transparency_info"> + <pbundle_as_map name="app_info"> + <boolean name="aps_compliant" value="false"/> + <string name="privacy_policy" value="www.example.com"/> + <string-array name="first_party_endpoints" num="1"> + <item value="url1"/> + </string-array> + <string-array name="service_provider_endpoints" num="2"> + <item value="url55"/> + <item value="url56"/> + </string-array> + </pbundle_as_map> + </pbundle_as_map> </bundle>
\ 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 index 883170a2d36f..0d15efc4eac3 100644 --- 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 @@ -1,14 +1,11 @@ <app-info - title="beervision" - description="a beer app" - containsAds="true" - obeyAps="false" - adsFingerprinting="false" - securityFingerprinting="false" - privacyPolicy="www.example.com" - securityEndpoints="url1|url2|url3" - firstPartyEndpoints="url1" - serviceProviderEndpoints="url55|url56" - category="Food and drink" - email="max@maxloh.com" - website="www.example.com" />
\ No newline at end of file + apsCompliant="false" + privacyPolicy="www.example.com"> + <first-party-endpoints> + <item>url1</item> + </first-party-endpoints> + <service-provider-endpoints> + <item>url55</item> + <item>url56</item> + </service-provider-endpoints> +</app-info>
\ 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 index 6e976a3278de..bce51799c7ff 100644 --- 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 @@ -1,25 +1,12 @@ <pbundle_as_map name="app_info"> - <string name="title" value="beervision"/> - <string name="description" value="a beer app"/> - <boolean name="contains_ads" value="true"/> - <boolean name="obey_aps" value="false"/> - <boolean name="ads_fingerprinting" value="false"/> - <boolean name="security_fingerprinting" value="false"/> + <boolean name="aps_compliant" value="false"/> <string name="privacy_policy" value="www.example.com"/> - <string-array name="security_endpoint" num="3"> + <string-array name="first_party_endpoints" num="1"> <item value="url1"/> - <item value="url2"/> - <item value="url3"/> </string-array> - <string-array name="first_party_endpoint" num="1"> - <item value="url1"/> - </string-array> - <string-array name="service_provider_endpoint" num="2"> + <string-array name="service_provider_endpoints" num="2"> <item value="url55"/> <item value="url56"/> </string-array> - <string name="category" value="Food and drink"/> - <string name="email" value="max@maxloh.com"/> - <string name="website" value="www.example.com"/> </pbundle_as_map>
\ 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 deleted file mode 100644 index 762f3bdf7875..000000000000 --- a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/missing-version.xml +++ /dev/null @@ -1,2 +0,0 @@ -<safety-labels> -</safety-labels>
\ 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 index 7decfd4865b1..92d10ca0349b 100644 --- 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 @@ -1 +1 @@ -<safety-labels version="12345"></safety-labels>
\ No newline at end of file +<safety-labels></safety-labels>
\ 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 index 84456daedbd5..ca3d9f066129 100644 --- 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 @@ -1,4 +1,4 @@ -<safety-labels version="12345"> +<safety-labels> <data-labels> <data-shared dataType="location_data_type_approx_location" isSharingOptional="false" diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-security-labels.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-security-labels.xml index 940e48a68ce8..c96278554865 100644 --- a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-security-labels.xml +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-security-labels.xml @@ -1,4 +1,4 @@ -<safety-labels version="12345"> +<safety-labels> <security-labels isDataDeletable="true" isDataEncrypted="false" diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-third-party-verification.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-third-party-verification.xml index bfbc5ae70974..08052904e8e5 100644 --- a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-third-party-verification.xml +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/hr/with-third-party-verification.xml @@ -1,4 +1,4 @@ -<safety-labels version="12345"> +<safety-labels> <third-party-verification url="www.example.com"> </third-party-verification> </safety-labels>
\ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/missing-version.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/missing-version.xml deleted file mode 100644 index 3fbe3599cd82..000000000000 --- a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/missing-version.xml +++ /dev/null @@ -1,2 +0,0 @@ -<pbundle_as_map name="safety_labels"> -</pbundle_as_map>
\ 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 index 4f03d88a3bd2..3fbe3599cd82 100644 --- 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 @@ -1,3 +1,2 @@ <pbundle_as_map name="safety_labels"> - <long name="version" value="12345"/> </pbundle_as_map>
\ 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 index fa2a3f841e09..db92e0291ee8 100644 --- 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 @@ -1,5 +1,4 @@ <pbundle_as_map name="safety_labels"> - <long name="version" value="12345"/> <pbundle_as_map name="data_labels"> <pbundle_as_map name="data_shared"> <pbundle_as_map name="location"> diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-security-labels.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-security-labels.xml index b39c562b30d0..924618087b4f 100644 --- a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-security-labels.xml +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-security-labels.xml @@ -1,5 +1,4 @@ <pbundle_as_map name="safety_labels"> - <long name="version" value="12345"/> <pbundle_as_map name="security_labels"> <boolean name="is_data_deletable" value="true" /> <boolean name="is_data_encrypted" value="false" /> diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-third-party-verification.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-third-party-verification.xml index 10653ff5027b..fd435c550a54 100644 --- a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-third-party-verification.xml +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/safetylabels/od/with-third-party-verification.xml @@ -1,5 +1,4 @@ <pbundle_as_map name="safety_labels"> - <long name="version" value="12345"/> <pbundle_as_map name="third_party_verification"> <string name="url" value="www.example.com"/> </pbundle_as_map> 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 index a7c48fc68cf1..2512ca415d55 100644 --- 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 @@ -1,4 +1,14 @@ <transparency-info> - <app-info title="beervision" description="a beer app" containsAds="true" obeyAps="false" adsFingerprinting="false" securityFingerprinting="false" privacyPolicy="www.example.com" securityEndpoints="url1|url2|url3" firstPartyEndpoints="url1" serviceProviderEndpoints="url55|url56" category="Food and drink" email="max@maxloh.com" /> + <app-info + apsCompliant="false" + privacyPolicy="www.example.com"> + <first-party-endpoints> + <item>url1</item> + </first-party-endpoints> + <service-provider-endpoints> + <item>url55</item> + <item>url56</item> + </service-provider-endpoints> + </app-info> </transparency-info>
\ 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 index b813641f74f8..c7bdd97a356c 100644 --- 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 @@ -1,26 +1,14 @@ <pbundle_as_map name="transparency_info"> <pbundle_as_map name="app_info"> - <string name="title" value="beervision"/> - <string name="description" value="a beer app"/> - <boolean name="contains_ads" value="true"/> - <boolean name="obey_aps" value="false"/> - <boolean name="ads_fingerprinting" value="false"/> - <boolean name="security_fingerprinting" value="false"/> + <boolean name="aps_compliant" value="false"/> <string name="privacy_policy" value="www.example.com"/> - <string-array name="security_endpoint" num="3"> + <string-array name="first_party_endpoints" num="1"> <item value="url1"/> - <item value="url2"/> - <item value="url3"/> </string-array> - <string-array name="first_party_endpoint" num="1"> - <item value="url1"/> - </string-array> - <string-array name="service_provider_endpoint" num="2"> + <string-array name="service_provider_endpoints" num="2"> <item value="url55"/> <item value="url56"/> </string-array> - <string name="category" value="Food and drink"/> - <string name="email" value="max@maxloh.com"/> </pbundle_as_map> </pbundle_as_map>
\ 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 index b2ff4495a6d2..cadf213c3e2e 100644 --- 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 @@ -1,5 +1,5 @@ <app-metadata-bundles version="123"> - <safety-labels version="12345"> + <safety-labels> <data-labels> <data-shared dataCategory="contacts" dataType="contacts" 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 index 81277bf456a4..7aafd2346846 100644 --- 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 @@ -1,7 +1,6 @@ <bundle> <long name="version" value="123"/> <pbundle_as_map name="safety_labels"> - <long name="version" value="12345"/> <pbundle_as_map name="data_labels"> <pbundle_as_map name="data_shared"> <pbundle_as_map name="contacts"> diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/general/hr.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/general/hr.xml index 41b32b5ed7b0..592307937896 100644 --- a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/general/hr.xml +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/general/hr.xml @@ -1,5 +1,5 @@ <app-metadata-bundles version="123"> - <safety-labels version="12345"> + <safety-labels> <data-labels> <data-shared dataType="location_data_type_approx_location" @@ -10,24 +10,18 @@ isSharingOptional="true" purposes="app_functionality|analytics" /> </data-labels> - <security-labels - isDataDeletable="true" - isDataEncrypted="false" - /> - <third-party-verification url="www.example.com"> - </third-party-verification> </safety-labels> <system-app-safety-label declaration="true"> </system-app-safety-label> <transparency-info> - <developer-info - name="max" - email="max@example.com" - address="111 blah lane" - countryRegion="US" - relationship="aosp" - website="example.com" - registryId="registry_id" /> - <app-info title="beervision" description="a beer app" containsAds="true" obeyAps="false" adsFingerprinting="false" securityFingerprinting="false" privacyPolicy="www.example.com" securityEndpoints="url1|url2|url3" firstPartyEndpoints="url1" serviceProviderEndpoints="url55|url56" category="Food and drink" email="max@maxloh.com" /> + <app-info apsCompliant="false" privacyPolicy="www.example.com"> + <first-party-endpoints> + <item>url1</item> + </first-party-endpoints> + <service-provider-endpoints> + <item>url55</item> + <item>url56</item> + </service-provider-endpoints> + </app-info> </transparency-info> </app-metadata-bundles>
\ No newline at end of file diff --git a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/general/od.xml b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/general/od.xml index c11ac4359ecd..c24087e483b6 100644 --- a/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/general/od.xml +++ b/tools/app_metadata_bundles/src/test/resources/com/android/asllib/validmappings/general/od.xml @@ -1,7 +1,6 @@ <bundle> <long name="version" value="123"/> <pbundle_as_map name="safety_labels"> - <long name="version" value="12345"/> <pbundle_as_map name="data_labels"> <pbundle_as_map name="data_shared"> <pbundle_as_map name="location"> @@ -21,49 +20,21 @@ </pbundle_as_map> </pbundle_as_map> </pbundle_as_map> - <pbundle_as_map name="security_labels"> - <boolean name="is_data_deletable" value="true"/> - <boolean name="is_data_encrypted" value="false"/> - </pbundle_as_map> - <pbundle_as_map name="third_party_verification"> - <string name="url" value="www.example.com"/> - </pbundle_as_map> </pbundle_as_map> <pbundle_as_map name="system_app_safety_label"> <boolean name="declaration" value="true"/> </pbundle_as_map> <pbundle_as_map name="transparency_info"> - <pbundle_as_map name="developer_info"> - <string name="name" value="max"/> - <string name="email" value="max@example.com"/> - <string name="address" value="111 blah lane"/> - <string name="country_region" value="US"/> - <long name="relationship" value="5"/> - <string name="website" value="example.com"/> - <string name="app_developer_registry_id" value="registry_id"/> - </pbundle_as_map> <pbundle_as_map name="app_info"> - <string name="title" value="beervision"/> - <string name="description" value="a beer app"/> - <boolean name="contains_ads" value="true"/> - <boolean name="obey_aps" value="false"/> - <boolean name="ads_fingerprinting" value="false"/> - <boolean name="security_fingerprinting" value="false"/> + <boolean name="aps_compliant" value="false"/> <string name="privacy_policy" value="www.example.com"/> - <string-array name="security_endpoint" num="3"> - <item value="url1"/> - <item value="url2"/> - <item value="url3"/> - </string-array> - <string-array name="first_party_endpoint" num="1"> + <string-array name="first_party_endpoints" num="1"> <item value="url1"/> </string-array> - <string-array name="service_provider_endpoint" num="2"> + <string-array name="service_provider_endpoints" num="2"> <item value="url55"/> <item value="url56"/> </string-array> - <string name="category" value="Food and drink"/> - <string name="email" value="max@maxloh.com"/> </pbundle_as_map> </pbundle_as_map> </bundle>
\ 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 index ac844b3b2767..a4242d06fb15 100644 --- 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 @@ -1,5 +1,5 @@ <app-metadata-bundles version="123"> - <safety-labels version="12345"> + <safety-labels> <data-labels> <data-shared dataCategory="location" dataType="precise_location" 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 index d0a3bfa7e64f..79afaf7d70d5 100644 --- 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 @@ -1,7 +1,6 @@ <bundle> <long name="version" value="123"/> <pbundle_as_map name="safety_labels"> - <long name="version" value="12345"/> <pbundle_as_map name="data_labels"> <pbundle_as_map name="data_shared"> <pbundle_as_map name="location"> diff --git a/tools/lint/framework/checks/src/main/java/com/google/android/lint/AndroidFrameworkIssueRegistry.kt b/tools/lint/framework/checks/src/main/java/com/google/android/lint/AndroidFrameworkIssueRegistry.kt index 624a1987638e..5c6469706e18 100644 --- a/tools/lint/framework/checks/src/main/java/com/google/android/lint/AndroidFrameworkIssueRegistry.kt +++ b/tools/lint/framework/checks/src/main/java/com/google/android/lint/AndroidFrameworkIssueRegistry.kt @@ -41,6 +41,7 @@ class AndroidFrameworkIssueRegistry : IssueRegistry() { PermissionAnnotationDetector.ISSUE_MISSING_PERMISSION_ANNOTATION, PermissionMethodDetector.ISSUE_PERMISSION_METHOD_USAGE, PermissionMethodDetector.ISSUE_CAN_BE_PERMISSION_METHOD, + FeatureAutomotiveDetector.ISSUE, ) override val api: Int diff --git a/tools/lint/framework/checks/src/main/java/com/google/android/lint/FeatureAutomotiveDetector.kt b/tools/lint/framework/checks/src/main/java/com/google/android/lint/FeatureAutomotiveDetector.kt new file mode 100644 index 000000000000..972b0c98eb94 --- /dev/null +++ b/tools/lint/framework/checks/src/main/java/com/google/android/lint/FeatureAutomotiveDetector.kt @@ -0,0 +1,90 @@ +/* + * 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.google.android.lint + +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.ConstantEvaluator +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import com.android.tools.lint.detector.api.SourceCodeScanner +import com.intellij.psi.PsiMethod +import java.util.EnumSet +import org.jetbrains.uast.UCallExpression +import org.jetbrains.uast.ULiteralExpression +import org.jetbrains.uast.UReferenceExpression + +/** + * A detector to check the usage of PackageManager.hasSystemFeature(" + * android.hardware.type.automotive") in CTS tests. + */ +class FeatureAutomotiveDetector : Detector(), SourceCodeScanner { + + companion object { + + val EXPLANATION = + """ + This class uses PackageManager.hasSystemFeature(\"android.hardware.type.automotive\") \ + or other equivalent methods. \ + If it is used to make a CTS test behave differently on AAOS, you should use \ + @RequireAutomotive or @RequireNotAutomotive instead; otherwise, please ignore this \ + warning. See https://g3doc.corp.google.com/wireless/android/partner/compatibility/\ + g3doc/dev/write-a-test/index.md#write-a-test-that-behaves-differently-on-aaos + """ + + val ISSUE: Issue = + Issue.create( + id = "UsingFeatureAutomotiveInCTS", + briefDescription = + "PackageManager.hasSystemFeature(\"" + + " android.hardware.type.automotive\") is used in CTS tests", + explanation = EXPLANATION, + category = Category.TESTING, + priority = 8, + severity = Severity.WARNING, + implementation = + Implementation( + FeatureAutomotiveDetector::class.java, + EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES) + ) + ) + } + + override fun getApplicableMethodNames() = + listOf("hasSystemFeature", "hasFeature", "hasDeviceFeature", "bypassTestForFeatures") + + override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) { + node.valueArguments.forEach { + val value = + when (it) { + is ULiteralExpression -> it.value + is UReferenceExpression -> ConstantEvaluator.evaluate(context, it) + else -> null + } + if (value is String && value == "android.hardware.type.automotive") { + context.report( + issue = ISSUE, + location = context.getNameLocation(method), + message = EXPLANATION + ) + } + } + } +} diff --git a/tools/lint/framework/checks/src/test/java/com/google/android/lint/FeatureAutomotiveDetectorTest.kt b/tools/lint/framework/checks/src/test/java/com/google/android/lint/FeatureAutomotiveDetectorTest.kt new file mode 100644 index 000000000000..b5e2c00965f5 --- /dev/null +++ b/tools/lint/framework/checks/src/test/java/com/google/android/lint/FeatureAutomotiveDetectorTest.kt @@ -0,0 +1,366 @@ +/* + * 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.google.android.lint + +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.checks.infrastructure.TestFile +import com.android.tools.lint.checks.infrastructure.TestLintTask +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Issue +import org.junit.Test + +@Suppress("UnstableApiUsage") +class FeatureAutomotiveDetectorTest : LintDetectorTest() { + val explanation = + FeatureAutomotiveDetector.EXPLANATION.replace("\\", "").replace("\n ", "") + + " [UsingFeatureAutomotiveInCTS]" + + override fun getDetector(): Detector = FeatureAutomotiveDetector() + override fun getIssues(): List<Issue> = listOf(FeatureAutomotiveDetector.ISSUE) + override fun lint(): TestLintTask = super.lint().allowMissingSdk(true) + + @Test + fun testWarning1() { + lint() + .files( + java( + """ + import android.content.pm.PackageManager; + + public class Foo { + + private void fun() { + PackageManager.getInstance().hasSystemFeature( + "android.hardware.type.automotive"); + } + } + """ + ) + .indented(), + *stubs + ) + .issues(FeatureAutomotiveDetector.ISSUE) + .run() + .expect( + """ + src/android/content/pm/PackageManager.java:13: Warning: $explanation + public boolean hasSystemFeature(String feature) { + ~~~~~~~~~~~~~~~~ + 0 errors, 1 warnings + """ + ) + } + + @Test + fun testWarning2() { + lint() + .files( + java( + """ + import android.content.pm.PackageManager; + + public class Foo { + + private void fun() { + String featureName = "android.hardware.type.automotive"; + PackageManager.getInstance().hasSystemFeature(featureName); + } + } + """ + ) + .indented(), + *stubs + ) + .issues(FeatureAutomotiveDetector.ISSUE) + .run() + .expect( + """ + src/android/content/pm/PackageManager.java:13: Warning: $explanation + public boolean hasSystemFeature(String feature) { + ~~~~~~~~~~~~~~~~ + 0 errors, 1 warnings + """ + ) + } + + @Test + fun testWarning3() { + lint() + .files( + java( + """ + import android.content.pm.PackageManager; + + public class Foo { + + private void fun() { + PackageManager.getInstance().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); + } + } + """ + ) + .indented(), + *stubs + ) + .issues(FeatureAutomotiveDetector.ISSUE) + .run() + .expect( + """ + src/android/content/pm/PackageManager.java:13: Warning: $explanation + public boolean hasSystemFeature(String feature) { + ~~~~~~~~~~~~~~~~ + 0 errors, 1 warnings + """ + ) + } + + @Test + fun testWarning4() { + lint() + .files( + java( + """ + import android.content.pm.PackageManager; + + public class Foo { + + private void fun() { + String featureName = PackageManager.FEATURE_AUTOMOTIVE; + PackageManager.getInstance().hasSystemFeature(featureName); + } + } + """ + ) + .indented(), + *stubs + ) + .issues(FeatureAutomotiveDetector.ISSUE) + .run() + .expect( + """ + src/android/content/pm/PackageManager.java:13: Warning: $explanation + public boolean hasSystemFeature(String feature) { + ~~~~~~~~~~~~~~~~ + 0 errors, 1 warnings + """ + ) + } + + @Test + fun testWarning5() { + lint() + .files( + java( + """ + import com.android.example.Utils; + + public class Foo { + + private void fun() { + Utils.hasFeature("android.hardware.type.automotive"); + } + } + """ + ) + .indented(), + *stubs + ) + .issues(FeatureAutomotiveDetector.ISSUE) + .run() + .expect( + """ + src/com/android/example/Utils.java:7: Warning: $explanation + public static boolean hasFeature(String feature) { + ~~~~~~~~~~ + 0 errors, 1 warnings + """ + ) + } + + @Test + fun testWarning6() { + lint() + .files( + java( + """ + import com.android.example.Utils; + + public class Foo { + + private void fun() { + Utils.hasDeviceFeature("android.hardware.type.automotive"); + } + } + """ + ) + .indented(), + *stubs + ) + .issues(FeatureAutomotiveDetector.ISSUE) + .run() + .expect( + """ + src/com/android/example/Utils.java:11: Warning: $explanation + public static boolean hasDeviceFeature(String feature) { + ~~~~~~~~~~~~~~~~ + 0 errors, 1 warnings + """ + ) + } + + @Test + fun testWarning7() { + lint() + .files( + java( + """ + import com.android.example.Utils; + + public class Foo { + + private void fun() { + Utils.hasFeature(new Object(), "android.hardware.type.automotive"); + } + } + """ + ) + .indented(), + *stubs + ) + .issues(FeatureAutomotiveDetector.ISSUE) + .run() + .expect( + """ + src/com/android/example/Utils.java:15: Warning: $explanation + public static boolean hasFeature(Object object, String feature) { + ~~~~~~~~~~ + 0 errors, 1 warnings + """ + ) + } + + @Test + fun testWarning8() { + lint() + .files( + java( + """ + import com.android.example.Utils; + + public class Foo { + + private void fun() { + Utils.bypassTestForFeatures("android.hardware.type.automotive"); + } + } + """ + ) + .indented(), + *stubs + ) + .issues(FeatureAutomotiveDetector.ISSUE) + .run() + .expect( + """ + src/com/android/example/Utils.java:19: Warning: $explanation + public static boolean bypassTestForFeatures(String feature) { + ~~~~~~~~~~~~~~~~~~~~~ + 0 errors, 1 warnings + """ + ) + } + + @Test + fun testNoWarning() { + lint() + .files( + java( + """ + import android.content.pm.PackageManager; + + public class Foo { + private void fun() { + String featureName1 = "android.hardware.type.automotive"; + String featureName2 = PackageManager.FEATURE_AUTOMOTIVE; + String notFeatureName = "FEATURE_AUTOMOTIVE"; + PackageManager.getInstance().hasSystemFeature(notFeatureName); + /* + PackageManager.getInstance().hasSystemFeature( + "android.hardware.type.automotive"); + */ + } + } + """ + ) + .indented(), + *stubs + ) + .issues(FeatureAutomotiveDetector.ISSUE) + .run() + .expectClean() + } + + private val pmStub: TestFile = + java( + """ + package android.content.pm; + + import java.lang.String; + + public class PackageManager { + public static final String FEATURE_AUTOMOTIVE = "android.hardware.type.automotive"; + + public static PackageManager getInstance() { + return new PackageManager(); + } + + public boolean hasSystemFeature(String feature) { + return true; + } + } + """ + ) + + private val exampleStub: TestFile = + java( + """ + package com.android.example; + + import java.lang.String; + + public class Utils { + public static boolean hasFeature(String feature) { + return true; + } + + public static boolean hasDeviceFeature(String feature) { + return true; + } + + public static boolean hasFeature(Object object, String feature) { + return true; + } + + public static boolean bypassTestForFeatures(String feature) { + return true; + } + } + """ + ) + + private val stubs = arrayOf(pmStub, exampleStub) +} diff --git a/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessorImpl.kt b/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessorImpl.kt index 1087ae6ee41d..3c99e68cd6a0 100644 --- a/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessorImpl.kt +++ b/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessorImpl.kt @@ -120,6 +120,8 @@ class ProtoLogCallProcessorImpl( logCallVisitor?.processCall(call, messageString, getLevelForMethodName( call.name.toString(), call, context), groupMap.getValue(groupName)) + } else if (call.name.id == "initialize") { + // No processing } else { // Process non-log message calls otherCallVisitor?.processCall(call) diff --git a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt index 0f1373c34ce6..aa530050741b 100644 --- a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt +++ b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt @@ -17,7 +17,6 @@ package com.android.protolog.tool import com.android.internal.protolog.common.LogLevel -import com.android.internal.protolog.common.ProtoLog import com.android.internal.protolog.common.ProtoLogToolInjected import com.android.protolog.tool.CommandOptions.Companion.USAGE import com.github.javaparser.ParseProblemException @@ -61,6 +60,8 @@ object ProtoLogTool { const val PROTOLOG_IMPL_SRC_PATH = "frameworks/base/core/java/com/android/internal/protolog/ProtoLogImpl.java" + private const val PROTOLOG_CLASS_NAME = "ProtoLog"; // ProtoLog::class.java.simpleName + data class LogCall( val messageString: String, val logLevel: LogLevel, @@ -124,7 +125,7 @@ object ProtoLogTool { val text = injector.readText(file) val outSrc = try { val code = tryParse(text, path) - if (containsProtoLogText(text, ProtoLog::class.java.simpleName)) { + if (containsProtoLogText(text, PROTOLOG_CLASS_NAME)) { transformer.processClass(text, path, packagePath(file, code), code) } else { text @@ -442,10 +443,10 @@ object ProtoLogTool { val command = CommandOptions(args) invoke(command) } catch (ex: InvalidCommandException) { - println("\n${ex.message}\n") + println("InvalidCommandException: \n${ex.message}\n") showHelpAndExit() } catch (ex: CodeProcessingException) { - println("\n${ex.message}\n") + println("CodeProcessingException: \n${ex.message}\n") exitProcess(1) } } diff --git a/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt b/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt index 6a8a0717b2f1..c478f5844de6 100644 --- a/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt +++ b/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt @@ -130,28 +130,27 @@ class SourceTransformer( val hash = CodeUtils.hash(packagePath, messageString, level, group) val newCall = call.clone() - if (!group.textEnabled) { - // Remove message string if text logging is not enabled by default. - // Out: ProtoLog.e(GROUP, null, arg) - newCall.arguments[1].replace(NameExpr("null")) - } + // Remove message string. + // Out: ProtoLog.e(GROUP, args) + newCall.arguments.removeAt(1) // Insert message string hash as a second argument. - // Out: ProtoLog.e(GROUP, 1234, null, arg) + // Out: ProtoLog.e(GROUP, 1234, args) newCall.arguments.add(1, LongLiteralExpr("" + hash + "L")) val argTypes = LogDataType.parseFormatString(messageString) val typeMask = LogDataType.logDataTypesToBitMask(argTypes) // Insert bitmap representing which Number parameters are to be considered as // floating point numbers. - // Out: ProtoLog.e(GROUP, 1234, 0, null, arg) + // Out: ProtoLog.e(GROUP, 1234, 0, args) newCall.arguments.add(2, IntegerLiteralExpr(typeMask)) // Replace call to a stub method with an actual implementation. - // Out: ProtoLogImpl.e(GROUP, 1234, null, arg) + // Out: ProtoLogImpl.e(GROUP, 1234, 0, args) newCall.setScope(protoLogImplClassNode) if (argTypes.size != call.arguments.size - 2) { throw InvalidProtoLogCallException( "Number of arguments (${argTypes.size} does not match format" + " string in: $call", ParsingContext(path, call)) } + val argsOffset = 3 val blockStmt = BlockStmt() if (argTypes.isNotEmpty()) { // Assign every argument to a variable to check its type in compile time @@ -160,9 +159,9 @@ class SourceTransformer( argTypes.forEachIndexed { idx, type -> val varName = "protoLogParam$idx" val declaration = VariableDeclarator(getASTTypeForDataType(type), varName, - getConversionForType(type)(newCall.arguments[idx + 4].clone())) + getConversionForType(type)(newCall.arguments[idx + argsOffset].clone())) blockStmt.addStatement(ExpressionStmt(VariableDeclarationExpr(declaration))) - newCall.setArgument(idx + 4, NameExpr(SimpleName(varName))) + newCall.setArgument(idx + argsOffset, NameExpr(SimpleName(varName))) } } else { // Assign (Object[])null as the vararg parameter to prevent allocating an empty diff --git a/tools/protologtool/tests/com/android/protolog/tool/EndToEndTest.kt b/tools/protologtool/tests/com/android/protolog/tool/EndToEndTest.kt index 822118cc5343..0cbbd483fe59 100644 --- a/tools/protologtool/tests/com/android/protolog/tool/EndToEndTest.kt +++ b/tools/protologtool/tests/com/android/protolog/tool/EndToEndTest.kt @@ -35,7 +35,7 @@ class EndToEndTest { val output = run( srcs = mapOf("frameworks/base/org/example/Example.java" to """ package org.example; - import com.android.internal.protolog.common.ProtoLog; + import com.android.internal.protolog.ProtoLog; import static com.android.internal.protolog.ProtoLogGroup.GROUP; class Example { @@ -48,7 +48,7 @@ class EndToEndTest { """.trimIndent()), logGroup = LogGroup("GROUP", true, false, "TAG_GROUP"), commandOptions = CommandOptions(arrayOf("transform-protolog-calls", - "--protolog-class", "com.android.internal.protolog.common.ProtoLog", + "--protolog-class", "com.android.internal.protolog.ProtoLog", "--loggroups-class", "com.android.internal.protolog.ProtoLogGroup", "--loggroups-jar", "not_required.jar", "--viewer-config-file-path", "not_required.pb", @@ -60,7 +60,7 @@ class EndToEndTest { .containsMatch(Pattern.compile("\\{ String protoLogParam0 = " + "String\\.valueOf\\(argString\\); long protoLogParam1 = argInt; " + "com\\.android\\.internal\\.protolog.ProtoLogImpl_.*\\.d\\(" + - "GROUP, -6872339441335321086L, 4, null, protoLogParam0, protoLogParam1" + + "GROUP, -6872339441335321086L, 4, protoLogParam0, protoLogParam1" + "\\); \\}")) } @@ -69,7 +69,7 @@ class EndToEndTest { val output = run( srcs = mapOf("frameworks/base/org/example/Example.java" to """ package org.example; - import com.android.internal.protolog.common.ProtoLog; + import com.android.internal.protolog.ProtoLog; import static com.android.internal.protolog.ProtoLogGroup.GROUP; class Example { @@ -82,7 +82,7 @@ class EndToEndTest { """.trimIndent()), logGroup = LogGroup("GROUP", true, false, "TAG_GROUP"), commandOptions = CommandOptions(arrayOf("generate-viewer-config", - "--protolog-class", "com.android.internal.protolog.common.ProtoLog", + "--protolog-class", "com.android.internal.protolog.ProtoLog", "--loggroups-class", "com.android.internal.protolog.ProtoLogGroup", "--loggroups-jar", "not_required.jar", "--viewer-config-type", "json", diff --git a/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt b/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt index 82aa93da613b..6cde7a72db53 100644 --- a/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt +++ b/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt @@ -76,7 +76,7 @@ class SourceTransformerTest { class Test { void test() { - if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, "test %d %f", protoLogParam0, protoLogParam1); } + if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, protoLogParam0, protoLogParam1); } } } """.trimIndent() @@ -86,7 +86,7 @@ class SourceTransformerTest { class Test { void test() { - if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; String protoLogParam2 = String.valueOf("test"); org.example.ProtoLogImpl.w(TEST_GROUP, -4447034859795564700L, 9, "test %d %f " + "abc %s\n test", protoLogParam0, protoLogParam1, protoLogParam2); + if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; String protoLogParam2 = String.valueOf("test"); org.example.ProtoLogImpl.w(TEST_GROUP, -4447034859795564700L, 9, protoLogParam0, protoLogParam1, protoLogParam2); } } @@ -98,8 +98,8 @@ class SourceTransformerTest { class Test { void test() { - if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, "test %d %f", protoLogParam0, protoLogParam1); } /* ProtoLog.w(TEST_GROUP, "test %d %f", 100, 0.1); */ if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, "test %d %f", protoLogParam0, protoLogParam1); } - if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, "test %d %f", protoLogParam0, protoLogParam1); } + if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, protoLogParam0, protoLogParam1); } /* ProtoLog.w(TEST_GROUP, "test %d %f", 100, 0.1); */ if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, protoLogParam0, protoLogParam1); } + if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, protoLogParam0, protoLogParam1); } } } """.trimIndent() @@ -109,7 +109,7 @@ class SourceTransformerTest { class Test { void test() { - if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { org.example.ProtoLogImpl.w(TEST_GROUP, 3218600869538902408L, 0, "test", (Object[]) null); } + if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { org.example.ProtoLogImpl.w(TEST_GROUP, 3218600869538902408L, 0, (Object[]) null); } } } """.trimIndent() @@ -119,7 +119,7 @@ class SourceTransformerTest { class Test { void test() { - if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, null, protoLogParam0, protoLogParam1); } + if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; org.example.ProtoLogImpl.w(TEST_GROUP, -1473209266730422156L, 9, protoLogParam0, protoLogParam1); } } } """.trimIndent() @@ -129,7 +129,7 @@ class SourceTransformerTest { class Test { void test() { - if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; String protoLogParam2 = String.valueOf("test"); org.example.ProtoLogImpl.w(TEST_GROUP, -4447034859795564700L, 9, null, protoLogParam0, protoLogParam1, protoLogParam2); + if (org.example.ProtoLogImpl.Cache.TEST_GROUP_enabled[3]) { long protoLogParam0 = 100; double protoLogParam1 = 0.1; String protoLogParam2 = String.valueOf("test"); org.example.ProtoLogImpl.w(TEST_GROUP, -4447034859795564700L, 9, protoLogParam0, protoLogParam1, protoLogParam2); } } @@ -172,13 +172,12 @@ class SourceTransformerTest { Truth.assertThat(protoLogCalls).hasSize(1) val methodCall = protoLogCalls[0] as MethodCallExpr assertEquals("w", methodCall.name.asString()) - assertEquals(6, methodCall.arguments.size) + assertEquals(5, methodCall.arguments.size) assertEquals("TEST_GROUP", methodCall.arguments[0].toString()) assertEquals("-1473209266730422156L", methodCall.arguments[1].toString()) assertEquals(0b1001.toString(), methodCall.arguments[2].toString()) - assertEquals("\"test %d %f\"", methodCall.arguments[3].toString()) - assertEquals("protoLogParam0", methodCall.arguments[4].toString()) - assertEquals("protoLogParam1", methodCall.arguments[5].toString()) + assertEquals("protoLogParam0", methodCall.arguments[3].toString()) + assertEquals("protoLogParam1", methodCall.arguments[4].toString()) assertEquals(TRANSFORMED_CODE_TEXT_ENABLED, out) } @@ -214,13 +213,12 @@ class SourceTransformerTest { Truth.assertThat(protoLogCalls).hasSize(3) val methodCall = protoLogCalls[0] as MethodCallExpr assertEquals("w", methodCall.name.asString()) - assertEquals(6, methodCall.arguments.size) + assertEquals(5, methodCall.arguments.size) assertEquals("TEST_GROUP", methodCall.arguments[0].toString()) assertEquals("-1473209266730422156L", methodCall.arguments[1].toString()) assertEquals(0b1001.toString(), methodCall.arguments[2].toString()) - assertEquals("\"test %d %f\"", methodCall.arguments[3].toString()) - assertEquals("protoLogParam0", methodCall.arguments[4].toString()) - assertEquals("protoLogParam1", methodCall.arguments[5].toString()) + assertEquals("protoLogParam0", methodCall.arguments[3].toString()) + assertEquals("protoLogParam1", methodCall.arguments[4].toString()) assertEquals(TRANSFORMED_CODE_MULTICALL_TEXT, out) } @@ -252,13 +250,13 @@ class SourceTransformerTest { Truth.assertThat(protoLogCalls).hasSize(1) val methodCall = protoLogCalls[0] as MethodCallExpr assertEquals("w", methodCall.name.asString()) - assertEquals(7, methodCall.arguments.size) + assertEquals(6, methodCall.arguments.size) assertEquals("TEST_GROUP", methodCall.arguments[0].toString()) assertEquals("-4447034859795564700L", methodCall.arguments[1].toString()) assertEquals(0b001001.toString(), methodCall.arguments[2].toString()) - assertEquals("protoLogParam0", methodCall.arguments[4].toString()) - assertEquals("protoLogParam1", methodCall.arguments[5].toString()) - assertEquals("protoLogParam2", methodCall.arguments[6].toString()) + assertEquals("protoLogParam0", methodCall.arguments[3].toString()) + assertEquals("protoLogParam1", methodCall.arguments[4].toString()) + assertEquals("protoLogParam2", methodCall.arguments[5].toString()) assertEquals(TRANSFORMED_CODE_MULTILINE_TEXT_ENABLED, out) } @@ -289,7 +287,7 @@ class SourceTransformerTest { Truth.assertThat(protoLogCalls).hasSize(1) val methodCall = protoLogCalls[0] as MethodCallExpr assertEquals("w", methodCall.name.asString()) - assertEquals(5, methodCall.arguments.size) + assertEquals(4, methodCall.arguments.size) assertEquals("TEST_GROUP", methodCall.arguments[0].toString()) assertEquals("3218600869538902408L", methodCall.arguments[1].toString()) assertEquals(0.toString(), methodCall.arguments[2].toString()) @@ -323,13 +321,12 @@ class SourceTransformerTest { Truth.assertThat(protoLogCalls).hasSize(1) val methodCall = protoLogCalls[0] as MethodCallExpr assertEquals("w", methodCall.name.asString()) - assertEquals(6, methodCall.arguments.size) + assertEquals(5, methodCall.arguments.size) assertEquals("TEST_GROUP", methodCall.arguments[0].toString()) assertEquals("-1473209266730422156L", methodCall.arguments[1].toString()) assertEquals(0b1001.toString(), methodCall.arguments[2].toString()) - assertEquals("null", methodCall.arguments[3].toString()) - assertEquals("protoLogParam0", methodCall.arguments[4].toString()) - assertEquals("protoLogParam1", methodCall.arguments[5].toString()) + assertEquals("protoLogParam0", methodCall.arguments[3].toString()) + assertEquals("protoLogParam1", methodCall.arguments[4].toString()) assertEquals(TRANSFORMED_CODE_TEXT_DISABLED, out) } @@ -361,14 +358,13 @@ class SourceTransformerTest { Truth.assertThat(protoLogCalls).hasSize(1) val methodCall = protoLogCalls[0] as MethodCallExpr assertEquals("w", methodCall.name.asString()) - assertEquals(7, methodCall.arguments.size) + assertEquals(6, methodCall.arguments.size) assertEquals("TEST_GROUP", methodCall.arguments[0].toString()) assertEquals("-4447034859795564700L", methodCall.arguments[1].toString()) assertEquals(0b001001.toString(), methodCall.arguments[2].toString()) - assertEquals("null", methodCall.arguments[3].toString()) - assertEquals("protoLogParam0", methodCall.arguments[4].toString()) - assertEquals("protoLogParam1", methodCall.arguments[5].toString()) - assertEquals("protoLogParam2", methodCall.arguments[6].toString()) + assertEquals("protoLogParam0", methodCall.arguments[3].toString()) + assertEquals("protoLogParam1", methodCall.arguments[4].toString()) + assertEquals("protoLogParam2", methodCall.arguments[5].toString()) assertEquals(TRANSFORMED_CODE_MULTILINE_TEXT_DISABLED, out) } } |