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