diff options
author | 2018-02-12 11:03:42 +0000 | |
---|---|---|
committer | 2018-02-13 14:09:00 +0000 | |
commit | d31bc123a06d2ffc2ca1b76a591a07865744ae12 (patch) | |
tree | 5debe4c21d27bb8c66622e4666c621ebe424b1b3 | |
parent | 40ce09581d8ef85ef9d5222d9b7c875429e913d1 (diff) |
AAPT2: normalize Manifest java identifiers.
Currently AAPT2 does not allow permissions which last piece contains the
"-" symbol (since it is an illegal character for a java identifier).
AAPT1 would normalize the last piece, therefore creating a valid java
identifier.
This CL makes AAPT2 behave in a similar way to AAPT1, but instead of
modifying the original value of the permission string, modifies only the
java identifier part, leaving the permission string unchanged.
Fixes: 72980877
Test: updated
Change-Id: Ie44317e07407341ba3e91a84d9b06980547b3448
-rw-r--r-- | tools/aapt2/java/ManifestClassGenerator.cpp | 6 | ||||
-rw-r--r-- | tools/aapt2/java/ManifestClassGenerator_test.cpp | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/tools/aapt2/java/ManifestClassGenerator.cpp b/tools/aapt2/java/ManifestClassGenerator.cpp index c4b36176aa71..be67c9c8c03c 100644 --- a/tools/aapt2/java/ManifestClassGenerator.cpp +++ b/tools/aapt2/java/ManifestClassGenerator.cpp @@ -21,6 +21,7 @@ #include "Source.h" #include "java/AnnotationProcessor.h" #include "java/ClassDefinition.h" +#include "java/JavaClassGenerator.h" #include "text/Unicode.h" #include "util/Maybe.h" #include "xml/XmlDom.h" @@ -38,6 +39,11 @@ static Maybe<StringPiece> ExtractJavaIdentifier(IDiagnostics* diag, const Source result = result.substr(pos + 1); } + // Normalize only the java identifier, leave the original value unchanged. + if (result.contains("-")) { + result = JavaClassGenerator::TransformToFieldName(result); + } + if (result.empty()) { diag->Error(DiagMessage(source) << "empty symbol"); return {}; diff --git a/tools/aapt2/java/ManifestClassGenerator_test.cpp b/tools/aapt2/java/ManifestClassGenerator_test.cpp index f4e10ab2e584..ab7f9a11d971 100644 --- a/tools/aapt2/java/ManifestClassGenerator_test.cpp +++ b/tools/aapt2/java/ManifestClassGenerator_test.cpp @@ -141,6 +141,18 @@ TEST(ManifestClassGeneratorTest, LastSeenPermissionWithSameLeafNameTakesPreceden EXPECT_THAT(actual, Not(HasSubstr("ACCESS_INTERNET=\"com.android.sample.ACCESS_INTERNET\";"))); } +TEST(ManifestClassGeneratorTest, NormalizePermissionNames) { + std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); + std::unique_ptr<xml::XmlResource> manifest = test::BuildXmlDom(R"( + <manifest xmlns:android="http://schemas.android.com/apk/res/android"> + <permission android:name="android.permission.access-internet" /> + </manifest>)"); + + std::string actual; + ASSERT_TRUE(GetManifestClassText(context.get(), manifest.get(), &actual)); + EXPECT_THAT(actual, HasSubstr("access_internet=\"android.permission.access-internet\";")); +} + static ::testing::AssertionResult GetManifestClassText(IAaptContext* context, xml::XmlResource* res, std::string* out_str) { std::unique_ptr<ClassDefinition> manifest_class = |