blob: fcec23d16f785d928e14830ea8d849f19496f8fb [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_CONVERT_H
18#define AAPT2_CONVERT_H
19
20#include "Command.h"
21#include "format/binary/TableFlattener.h"
22
23namespace aapt {
24
25class ConvertCommand : public Command {
26 public:
27 explicit ConvertCommand() : Command("convert") {
28 SetDescription("Converts an apk between binary and proto formats.");
29 AddRequiredFlag("-o", "Output path", &output_path_);
30 AddOptionalFlag("--output-format", android::base::StringPrintf("Format of the output. "
31 "Accepted values are '%s' and '%s'. When not set, defaults to '%s'.",
32 kOutputFormatProto, kOutputFormatBinary, kOutputFormatBinary), &output_format_);
33 AddOptionalSwitch("--enable-sparse-encoding",
34 "Enables encoding sparse entries using a binary search tree.\n"
35 "This decreases APK size at the cost of resource retrieval performance.",
36 &options_.use_sparse_entries);
37 AddOptionalSwitch("-v", "Enables verbose logging", &verbose_);
38 }
39
40 int Action(const std::vector<std::string>& args) override;
41
42 private:
43 const static char* kOutputFormatProto;
44 const static char* kOutputFormatBinary;
45
46 TableFlattenerOptions options_;
47 std::string output_path_;
48 Maybe<std::string> output_format_;
49 bool verbose_ = false;
50};
51
52}// namespace aapt
53
54#endif //AAPT2_CONVERT_H