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