Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 AAPT2_DUMP_H |
| 18 | #define AAPT2_DUMP_H |
| 19 | |
| 20 | #include "Command.h" |
| 21 | #include "Debug.h" |
Ryan Mitchell | fc225b2 | 2018-08-21 14:52:51 -0700 | [diff] [blame^] | 22 | #include "dump/DumpManifest.h" |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 23 | |
| 24 | namespace aapt { |
| 25 | |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 26 | /** Command the contents of files generated from the compilation stage. */ |
| 27 | class DumpAPCCommand : public Command { |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 28 | public: |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 29 | explicit DumpAPCCommand(IDiagnostics* diag) : Command("apc"), diag_(diag) { |
| 30 | SetDescription("Print the contents of the AAPT2 Container (APC) generated fom compilation."); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 31 | AddOptionalSwitch("--no-values", "Suppresses output of values when displaying resource tables.", |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 32 | &no_values_); |
| 33 | AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | int Action(const std::vector<std::string>& args) override; |
| 37 | |
| 38 | private: |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 39 | IDiagnostics* diag_; |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 40 | bool verbose_ = false; |
| 41 | bool no_values_ = false; |
| 42 | }; |
| 43 | |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 44 | /** Prints every configuration used by a resource in an APK. */ |
| 45 | class DumpConfigsCommand : public Command { |
| 46 | public: |
| 47 | explicit DumpConfigsCommand(IDiagnostics* diag) : Command("configurations"), diag_(diag) { |
| 48 | SetDescription("Print every configuration used by a resource in the APK."); |
| 49 | } |
| 50 | |
| 51 | int Action(const std::vector<std::string>& args) override; |
| 52 | |
| 53 | private: |
| 54 | IDiagnostics* diag_; |
| 55 | }; |
| 56 | |
| 57 | /** Prints the contents of the resource table string pool in the APK. */ |
| 58 | class DumpStringsCommand : public Command { |
| 59 | public: |
| 60 | explicit DumpStringsCommand(IDiagnostics* diag) : Command("strings"), diag_(diag) { |
| 61 | SetDescription("Print the contents of the resource table string pool in the APK."); |
| 62 | } |
| 63 | |
| 64 | int Action(const std::vector<std::string>& args) override; |
| 65 | |
| 66 | private: |
| 67 | IDiagnostics* diag_; |
| 68 | }; |
| 69 | |
| 70 | /** Prints the contents of the resource table from the APK. */ |
| 71 | class DumpTableCommand : public Command { |
| 72 | public: |
| 73 | explicit DumpTableCommand(IDiagnostics* diag) : Command("resources"), diag_(diag) { |
| 74 | SetDescription("Print the contents of the resource table from the APK."); |
| 75 | AddOptionalSwitch("--no-values", "Suppresses output of values when displaying resource tables.", |
| 76 | &no_values_); |
| 77 | AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); |
| 78 | } |
| 79 | |
| 80 | int Action(const std::vector<std::string>& args) override; |
| 81 | |
| 82 | private: |
| 83 | IDiagnostics* diag_; |
| 84 | bool verbose_ = false; |
| 85 | bool no_values_ = false; |
| 86 | }; |
| 87 | |
| 88 | /** Prints the string pool of a compiled xml in an APK. */ |
| 89 | class DumpXmlStringsCommand : public Command { |
| 90 | public: |
| 91 | explicit DumpXmlStringsCommand(IDiagnostics* diag) : Command("xmlstrings"), diag_(diag) { |
| 92 | SetDescription("Print the string pool of a compiled xml in an APK."); |
| 93 | AddRequiredFlagList("--file", "A compiled xml file to print", &files_); |
| 94 | } |
| 95 | |
| 96 | int Action(const std::vector<std::string>& args) override; |
| 97 | |
| 98 | private: |
| 99 | IDiagnostics* diag_; |
| 100 | std::vector<std::string> files_; |
| 101 | }; |
| 102 | |
| 103 | |
| 104 | /** Prints the tree of a compiled xml in an APK. */ |
| 105 | class DumpXmlTreeCommand : public Command { |
| 106 | public: |
| 107 | explicit DumpXmlTreeCommand(IDiagnostics* diag) : Command("xmltree"), diag_(diag) { |
| 108 | SetDescription("Print the tree of a compiled xml in an APK."); |
| 109 | AddRequiredFlagList("--file", "A compiled xml file to print", &files_); |
| 110 | } |
| 111 | |
| 112 | int Action(const std::vector<std::string>& args) override; |
| 113 | |
| 114 | private: |
| 115 | IDiagnostics* diag_; |
| 116 | std::vector<std::string> files_; |
| 117 | }; |
| 118 | |
Todd Kennedy | 908b7fc | 2018-08-24 10:11:21 -0700 | [diff] [blame] | 119 | /** Prints the contents of the resource table from the APK. */ |
| 120 | class DumpPackageNameCommand : public Command { |
| 121 | public: |
| 122 | explicit DumpPackageNameCommand(IDiagnostics* diag) : Command("packagename"), diag_(diag) { |
| 123 | SetDescription("Print the package name of the APK."); |
| 124 | } |
| 125 | |
| 126 | int Action(const std::vector<std::string>& args) override; |
| 127 | |
| 128 | private: |
| 129 | IDiagnostics* diag_; |
| 130 | }; |
| 131 | |
| 132 | /** The default dump command. Performs no action because a subcommand is required. */ |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 133 | class DumpCommand : public Command { |
| 134 | public: |
| 135 | explicit DumpCommand(IDiagnostics* diag) : Command("dump", "d"), diag_(diag) { |
| 136 | AddOptionalSubcommand(util::make_unique<DumpAPCCommand>(diag_)); |
Ryan Mitchell | fc225b2 | 2018-08-21 14:52:51 -0700 | [diff] [blame^] | 137 | AddOptionalSubcommand(util::make_unique<DumpBadgingCommand>(diag_)); |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 138 | AddOptionalSubcommand(util::make_unique<DumpConfigsCommand>(diag_)); |
Todd Kennedy | 908b7fc | 2018-08-24 10:11:21 -0700 | [diff] [blame] | 139 | AddOptionalSubcommand(util::make_unique<DumpPackageNameCommand>(diag_)); |
Ryan Mitchell | fc225b2 | 2018-08-21 14:52:51 -0700 | [diff] [blame^] | 140 | AddOptionalSubcommand(util::make_unique<DumpPermissionsCommand>(diag_)); |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 141 | AddOptionalSubcommand(util::make_unique<DumpStringsCommand>(diag_)); |
| 142 | AddOptionalSubcommand(util::make_unique<DumpTableCommand>(diag_)); |
| 143 | AddOptionalSubcommand(util::make_unique<DumpXmlStringsCommand>(diag_)); |
| 144 | AddOptionalSubcommand(util::make_unique<DumpXmlTreeCommand>(diag_)); |
| 145 | } |
| 146 | |
| 147 | int Action(const std::vector<std::string>& args) override; |
| 148 | |
| 149 | private: |
| 150 | IDiagnostics* diag_; |
| 151 | }; |
| 152 | |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 153 | }// namespace aapt |
| 154 | |
| 155 | #endif //AAPT2_DUMP_H |