| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT2_CONVERT_H |
| 18 |
#define AAPT2_CONVERT_H |
| 19 |
|
| 20 |
#include <optional> |
| 21 |
|
| 22 |
#include "Command.h" |
| 23 |
#include "LoadedApk.h" |
| 24 |
#include "format/binary/TableFlattener.h" |
| 25 |
#include "format/binary/XmlFlattener.h" |
| 26 |
|
| 27 |
namespace aapt { |
| 28 |
|
| 29 |
class ConvertCommand : public Command { |
| 30 |
public: |
| 31 |
explicit ConvertCommand() : Command("convert") { |
| 32 |
SetDescription("Converts an apk between binary and proto formats."); |
| 33 |
AddRequiredFlag("-o", "Output path", &output_path_, Command::kPath); |
| 34 |
AddOptionalFlag("--output-format", android::base::StringPrintf("Format of the output. " |
| 35 |
"Accepted values are '%s' and '%s'. When not set, defaults to '%s'.", |
| 36 |
kOutputFormatProto, kOutputFormatBinary, kOutputFormatBinary), &output_format_); |
| 37 |
AddOptionalSwitch("--enable-sparse-encoding", |
| 38 |
"Enables encoding sparse entries using a binary search tree.\n" |
| 39 |
"This decreases APK size at the cost of resource retrieval performance.", |
| 40 |
&table_flattener_options_.use_sparse_entries); |
| 41 |
AddOptionalSwitch("--keep-raw-values", |
| 42 |
android::base::StringPrintf("Preserve raw attribute values in xml files when using the" |
| 43 |
" '%s' output format", kOutputFormatBinary), |
| 44 |
&xml_flattener_options_.keep_raw_values); |
| 45 |
AddOptionalSwitch("-v", "Enables verbose logging", &verbose_); |
| 46 |
} |
| 47 |
|
| 48 |
int Action(const std::vector<std::string>& args) override; |
| 49 |
|
| 50 |
private: |
| 51 |
const static char* kOutputFormatProto; |
| 52 |
const static char* kOutputFormatBinary; |
| 53 |
|
| 54 |
TableFlattenerOptions table_flattener_options_; |
| 55 |
XmlFlattenerOptions xml_flattener_options_; |
| 56 |
std::string output_path_; |
| 57 |
std::optional<std::string> output_format_; |
| 58 |
bool verbose_ = false; |
| 59 |
}; |
| 60 |
|
| 61 |
int Convert(IAaptContext* context, LoadedApk* input, IArchiveWriter* output_writer, |
| 62 |
ApkFormat output_format,TableFlattenerOptions table_flattener_options, |
| 63 |
XmlFlattenerOptions xml_flattener_options); |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
#endif |