• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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 "Resource.h"
26 #include "Source.h"
27 #include "xml/XmlDom.h"
28 
29 namespace aapt {
30 namespace proguard {
31 
32 class KeepSet {
33  public:
AddClass(const Source & source,const std::string & class_name)34   inline void AddClass(const Source& source, const std::string& class_name) {
35     keep_set_[class_name].insert(source);
36   }
37 
AddMethod(const Source & source,const std::string & method_name)38   inline void AddMethod(const Source& source, const std::string& method_name) {
39     keep_method_set_[method_name].insert(source);
40   }
41 
42  private:
43   friend bool WriteKeepSet(std::ostream* out, const KeepSet& keep_set);
44 
45   std::map<std::string, std::set<Source>> keep_set_;
46   std::map<std::string, std::set<Source>> keep_method_set_;
47 };
48 
49 bool CollectProguardRulesForManifest(const Source& source,
50                                      xml::XmlResource* res, KeepSet* keep_set,
51                                      bool main_dex_only = false);
52 bool CollectProguardRules(const Source& source, xml::XmlResource* res,
53                           KeepSet* keep_set);
54 
55 bool WriteKeepSet(std::ostream* out, const KeepSet& keep_set);
56 
57 }  // namespace proguard
58 }  // namespace aapt
59 
60 #endif  // AAPT_PROGUARD_RULES_H
61