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

Commit 3ac786d2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "AAPT2: normalize Manifest java identifiers."

parents 29ff057e d31bc123
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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 {};
+12 −0
Original line number Diff line number Diff line
@@ -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 =