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

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

Merge "Generate "keep" rules for actionProviderClass and actionViewClass"

parents 5b4ef1be db19f510
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -160,13 +160,19 @@ class MenuVisitor : public BaseVisitor {
  void Visit(xml::Element* node) override {
    if (node->namespace_uri.empty() && node->name == "item") {
      for (const auto& attr : node->attributes) {
        if (attr.namespace_uri == xml::kSchemaAndroid) {
        // AppCompat-v7 defines its own versions of Android attributes if
        // they're defined after SDK 7 (the below are from 11 and 14,
        // respectively), so don't bother checking the XML namespace.
        //
        // Given the names of the containing XML files and the attribute
        // names, it's unlikely that keeping these classes would be wrong.
        if ((attr.name == "actionViewClass" || attr.name == "actionProviderClass") &&
            util::IsJavaClassName(attr.value)) {
          AddClass(node->line_number, attr.value, "android.content.Context");
          } else if (attr.name == "onClick") {
            AddMethod(node->line_number, attr.value, "android.view.MenuItem");
        }

        if (attr.namespace_uri == xml::kSchemaAndroid && attr.name == "onClick") {
          AddMethod(node->line_number, attr.value, "android.view.MenuItem");
        }
      }
    }
+19 −0
Original line number Diff line number Diff line
@@ -326,6 +326,25 @@ TEST(ProguardRulesTest, MenuRulesAreEmitted) {
  EXPECT_THAT(actual, Not(HasSubstr("com.foo.Bat")));
}

TEST(ProguardRulesTest, MenuRulesAreEmittedForActionClasses) {
  std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
  std::unique_ptr<xml::XmlResource> menu = test::BuildXmlDom(R"(
      <menu xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto">
        <item android:id="@+id/my_item"
            app:actionViewClass="com.foo.Bar"
            app:actionProviderClass="com.foo.Baz" />
      </menu>)");
  menu->file.name = test::ParseNameOrDie("menu/foo");

  proguard::KeepSet set;
  ASSERT_TRUE(proguard::CollectProguardRules(context.get(), menu.get(), &set));

  std::string actual = GetKeepSetString(set, /** minimal_rules */ false);
  EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar"));
  EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Baz"));
}

TEST(ProguardRulesTest, TransitionPathMotionRulesAreEmitted) {
  std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
  std::unique_ptr<xml::XmlResource> transition = test::BuildXmlDom(R"(