| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT_PROGUARD_RULES_H |
| 18 |
#define AAPT_PROGUARD_RULES_H |
| 19 |
|
| 20 |
#include <map> |
| 21 |
#include <ostream> |
| 22 |
#include <set> |
| 23 |
#include <string> |
| 24 |
|
| 25 |
#include "androidfw/StringPiece.h" |
| 26 |
|
| 27 |
#include "Resource.h" |
| 28 |
#include "ResourceTable.h" |
| 29 |
#include "Source.h" |
| 30 |
#include "ValueVisitor.h" |
| 31 |
#include "io/Io.h" |
| 32 |
#include "process/IResourceTableConsumer.h" |
| 33 |
#include "xml/XmlDom.h" |
| 34 |
|
| 35 |
namespace aapt { |
| 36 |
namespace proguard { |
| 37 |
|
| 38 |
struct UsageLocation { |
| 39 |
ResourceName name; |
| 40 |
Source source; |
| 41 |
}; |
| 42 |
|
| 43 |
struct NameAndSignature { |
| 44 |
std::string name; |
| 45 |
std::string signature; |
| 46 |
}; |
| 47 |
|
| 48 |
class KeepSet { |
| 49 |
public: |
| 50 |
KeepSet() = default; |
| 51 |
|
| 52 |
explicit KeepSet(bool conditional_keep_rules) : conditional_keep_rules_(conditional_keep_rules) { |
| 53 |
} |
| 54 |
|
| 55 |
inline void AddManifestClass(const UsageLocation& file, const std::string& class_name) { |
| 56 |
manifest_class_set_[class_name].insert(file); |
| 57 |
} |
| 58 |
|
| 59 |
inline void AddConditionalClass(const UsageLocation& file, |
| 60 |
const NameAndSignature& class_and_signature) { |
| 61 |
conditional_class_set_[class_and_signature].insert(file); |
| 62 |
} |
| 63 |
|
| 64 |
inline void AddMethod(const UsageLocation& file, const NameAndSignature& name_and_signature) { |
| 65 |
method_set_[name_and_signature].insert(file); |
| 66 |
} |
| 67 |
|
| 68 |
inline void AddReference(const UsageLocation& file, const ResourceName& resource_name) { |
| 69 |
reference_set_[resource_name].insert(file); |
| 70 |
} |
| 71 |
|
| 72 |
private: |
| 73 |
friend void WriteKeepSet(const KeepSet& keep_set, io::OutputStream* out, bool minimal_keep, |
| 74 |
bool no_location_reference); |
| 75 |
|
| 76 |
friend bool CollectLocations(const UsageLocation& location, const KeepSet& keep_set, |
| 77 |
std::set<UsageLocation>* locations); |
| 78 |
|
| 79 |
bool conditional_keep_rules_ = false; |
| 80 |
std::map<std::string, std::set<UsageLocation>> manifest_class_set_; |
| 81 |
std::map<NameAndSignature, std::set<UsageLocation>> method_set_; |
| 82 |
std::map<NameAndSignature, std::set<UsageLocation>> conditional_class_set_; |
| 83 |
std::map<ResourceName, std::set<UsageLocation>> reference_set_; |
| 84 |
}; |
| 85 |
|
| 86 |
bool CollectProguardRulesForManifest(xml::XmlResource* res, KeepSet* keep_set, |
| 87 |
bool main_dex_only = false); |
| 88 |
|
| 89 |
bool CollectProguardRules(IAaptContext* context, xml::XmlResource* res, KeepSet* keep_set); |
| 90 |
|
| 91 |
bool CollectResourceReferences(IAaptContext* context, ResourceTable* table, KeepSet* keep_set); |
| 92 |
|
| 93 |
void WriteKeepSet(const KeepSet& keep_set, io::OutputStream* out, bool minimal_keep, |
| 94 |
bool no_location_reference); |
| 95 |
|
| 96 |
bool CollectLocations(const UsageLocation& location, const KeepSet& keep_set, |
| 97 |
std::set<UsageLocation>* locations); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
inline bool operator==(const UsageLocation& lhs, const UsageLocation& rhs) { |
| 104 |
|
| 105 |
|
| 106 |
return lhs.name == rhs.name; |
| 107 |
} |
| 108 |
|
| 109 |
inline bool operator<(const UsageLocation& lhs, const UsageLocation& rhs) { |
| 110 |
return lhs.name.compare(rhs.name) < 0; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
inline bool operator<(const NameAndSignature& lhs, const NameAndSignature& rhs) { |
| 118 |
if (lhs.name < rhs.name) { |
| 119 |
return true; |
| 120 |
} |
| 121 |
if (lhs.name == rhs.name) { |
| 122 |
return lhs.signature < rhs.signature; |
| 123 |
} |
| 124 |
return false; |
| 125 |
} |
| 126 |
|
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
#endif |