blob: 9ec820d8959644bf88b853d49bea6826f428511d [file] [log] [blame]
Ryan Mitchell833a1a62018-07-10 13:51:36 -07001/*
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 Mitchellfc225b22018-08-21 14:52:51 -070022#include "dump/DumpManifest.h"
Ryan Mitchell833a1a62018-07-10 13:51:36 -070023
24namespace aapt {
25
Ryan Mitchell5d275512018-07-19 14:29:00 -070026/** Command the contents of files generated from the compilation stage. */
27class DumpAPCCommand : public Command {
Ryan Mitchell833a1a62018-07-10 13:51:36 -070028 public:
Ryan Mitchell5d275512018-07-19 14:29:00 -070029 explicit DumpAPCCommand(IDiagnostics* diag) : Command("apc"), diag_(diag) {
30 SetDescription("Print the contents of the AAPT2 Container (APC) generated fom compilation.");
Ryan Mitchell833a1a62018-07-10 13:51:36 -070031 AddOptionalSwitch("--no-values", "Suppresses output of values when displaying resource tables.",
Ryan Mitchell5d275512018-07-19 14:29:00 -070032 &no_values_);
33 AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070034 }
35
36 int Action(const std::vector<std::string>& args) override;
37
38 private:
Ryan Mitchell5d275512018-07-19 14:29:00 -070039 IDiagnostics* diag_;
Ryan Mitchell833a1a62018-07-10 13:51:36 -070040 bool verbose_ = false;
41 bool no_values_ = false;
42};
43
Ryan Mitchell5d275512018-07-19 14:29:00 -070044/** Prints every configuration used by a resource in an APK. */
45class 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. */
58class 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. */
71class 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. */
89class DumpXmlStringsCommand : public Command {
90public:
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
98private:
99 IDiagnostics* diag_;
100 std::vector<std::string> files_;
101};
102
103
104/** Prints the tree of a compiled xml in an APK. */
105class 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 Kennedy908b7fc2018-08-24 10:11:21 -0700119/** Prints the contents of the resource table from the APK. */
120class 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 Mitchell5d275512018-07-19 14:29:00 -0700133class DumpCommand : public Command {
134 public:
135 explicit DumpCommand(IDiagnostics* diag) : Command("dump", "d"), diag_(diag) {
136 AddOptionalSubcommand(util::make_unique<DumpAPCCommand>(diag_));
Ryan Mitchellfc225b22018-08-21 14:52:51 -0700137 AddOptionalSubcommand(util::make_unique<DumpBadgingCommand>(diag_));
Ryan Mitchell5d275512018-07-19 14:29:00 -0700138 AddOptionalSubcommand(util::make_unique<DumpConfigsCommand>(diag_));
Todd Kennedy908b7fc2018-08-24 10:11:21 -0700139 AddOptionalSubcommand(util::make_unique<DumpPackageNameCommand>(diag_));
Ryan Mitchellfc225b22018-08-21 14:52:51 -0700140 AddOptionalSubcommand(util::make_unique<DumpPermissionsCommand>(diag_));
Ryan Mitchell5d275512018-07-19 14:29:00 -0700141 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 Mitchell833a1a62018-07-10 13:51:36 -0700153}// namespace aapt
154
155#endif //AAPT2_DUMP_H