summaryrefslogtreecommitdiff
path: root/tools/aapt2/java/ProguardRules_test.cpp
diff options
context:
space:
mode:
authorJake Wharton <jakew@google.com>2018-06-08 17:56:55 -0400
committerJake Wharton <jakew@google.com>2018-06-11 11:33:17 -0400
commitab660a7fde368f30d88af7e4c864b5489dcd44f3 (patch)
tree93863c209d635eca6bb60e97487094e474669e7e /tools/aapt2/java/ProguardRules_test.cpp
parentaa035cf77bad6db95221680654f0cf32c95fd3b9 (diff)
Only keep default constructor of manifest items
Reflection-based instantiation of manifest-declared types is only done on the default (aka no-argument) constructor. While these types are unlikely to have alternate constructors (unlike the others listed in the bug), there's no reason to generate overly keep-y rules for them. Bug: 37123156 Test: make aapt2_tests Change-Id: Ic83a2671a54ea5dd558bfcacf033a60e9568ab8c
Diffstat (limited to 'tools/aapt2/java/ProguardRules_test.cpp')
-rw-r--r--tools/aapt2/java/ProguardRules_test.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/aapt2/java/ProguardRules_test.cpp b/tools/aapt2/java/ProguardRules_test.cpp
index 876c7a76d3f5..bbc6f9f64414 100644
--- a/tools/aapt2/java/ProguardRules_test.cpp
+++ b/tools/aapt2/java/ProguardRules_test.cpp
@@ -34,6 +34,31 @@ std::string GetKeepSetString(const proguard::KeepSet& set) {
return out;
}
+TEST(ProguardRulesTest, ManifestRuleDefaultConstructorOnly) {
+ std::unique_ptr<xml::XmlResource> manifest = test::BuildXmlDom(R"(
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
+ <application android:backupAgent="com.foo.BarBackupAgent">
+ <activity android:name="com.foo.BarActivity"/>
+ <service android:name="com.foo.BarService"/>
+ <receiver android:name="com.foo.BarReceiver"/>
+ <provider android:name="com.foo.BarProvider"/>
+ </application>
+ <instrumentation android:name="com.foo.BarInstrumentation"/>
+ </manifest>)");
+
+ proguard::KeepSet set;
+ ASSERT_TRUE(proguard::CollectProguardRulesForManifest(manifest.get(), &set, false));
+
+ std::string actual = GetKeepSetString(set);
+
+ EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarBackupAgent { <init>(); }"));
+ EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarActivity { <init>(); }"));
+ EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarService { <init>(); }"));
+ EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarReceiver { <init>(); }"));
+ EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarProvider { <init>(); }"));
+ EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarInstrumentation { <init>(); }"));
+}
+
TEST(ProguardRulesTest, FragmentNameRuleIsEmitted) {
std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"(