Merge "Generate "keep" rules for actionProviderClass and actionViewClass"
This commit is contained in:
committed by
Android (Google) Code Review
commit
d5cbd092ab
@@ -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) {
|
||||
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");
|
||||
}
|
||||
// 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");
|
||||
}
|
||||
|
||||
if (attr.namespace_uri == xml::kSchemaAndroid && attr.name == "onClick") {
|
||||
AddMethod(node->line_number, attr.value, "android.view.MenuItem");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"(
|
||||
|
||||
Reference in New Issue
Block a user