Only keep methods with correct signature for view/menu click
For View's onClick attribute the method must have a single argument of type android.view.View. For a MenuItem's onClick attribute the method must have a single argument of type android.view.MenuItem. Since these rules match all types and any return type, matching by signature is the only available specificity that can be added.
Bug: 37123156
Test: make aapt2_tests
Change-Id: I4b82f5ef9e62a8ecffaab424e269df627825709e
diff --git a/tools/aapt2/java/ProguardRules.h b/tools/aapt2/java/ProguardRules.h
index 343272e..acaceac 100644
--- a/tools/aapt2/java/ProguardRules.h
+++ b/tools/aapt2/java/ProguardRules.h
@@ -40,6 +40,11 @@
Source source;
};
+struct NameAndSignature {
+ std::string name;
+ std::string signature;
+};
+
class KeepSet {
public:
KeepSet() = default;
@@ -55,8 +60,8 @@
conditional_class_set_[class_name].insert(file);
}
- inline void AddMethod(const UsageLocation& file, const std::string& method_name) {
- method_set_[method_name].insert(file);
+ inline void AddMethod(const UsageLocation& file, const NameAndSignature& name_and_signature) {
+ method_set_[name_and_signature].insert(file);
}
inline void AddReference(const UsageLocation& file, const ResourceName& resource_name) {
@@ -71,7 +76,7 @@
bool conditional_keep_rules_ = false;
std::map<std::string, std::set<UsageLocation>> manifest_class_set_;
- std::map<std::string, std::set<UsageLocation>> method_set_;
+ std::map<NameAndSignature, std::set<UsageLocation>> method_set_;
std::map<std::string, std::set<UsageLocation>> conditional_class_set_;
std::map<ResourceName, std::set<UsageLocation>> reference_set_;
};
@@ -100,6 +105,20 @@
return lhs.name.compare(rhs.name);
}
+//
+// NameAndSignature implementation.
+//
+
+inline bool operator<(const NameAndSignature& lhs, const NameAndSignature& rhs) {
+ if (lhs.name < rhs.name) {
+ return true;
+ }
+ if (lhs.name == rhs.name) {
+ return lhs.signature < rhs.signature;
+ }
+ return false;
+}
+
} // namespace proguard
} // namespace aapt