blob: 470f65eb01c48e5afa52306d7a6a1af089e00fc7 [file] [log] [blame]
Adam Lesinski2ae4a872015-11-02 16:10:55 -08001/*
2 * Copyright (C) 2015 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 AAPT_LINK_MANIFESTFIXER_H
18#define AAPT_LINK_MANIFESTFIXER_H
19
Adam Lesinskice5e56e2016-10-21 17:56:45 -070020#include <string>
21
22#include "android-base/macros.h"
23
Adam Lesinski2ae4a872015-11-02 16:10:55 -080024#include "process/IResourceTableConsumer.h"
Adam Lesinski467f1712015-11-16 17:35:44 -080025#include "util/Maybe.h"
Adam Lesinskicc5609d2016-04-05 12:41:07 -070026#include "xml/XmlActionExecutor.h"
Adam Lesinski467f1712015-11-16 17:35:44 -080027#include "xml/XmlDom.h"
28
Adam Lesinski2ae4a872015-11-02 16:10:55 -080029namespace aapt {
30
31struct ManifestFixerOptions {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070032 Maybe<std::string> min_sdk_version_default;
33 Maybe<std::string> target_sdk_version_default;
34 Maybe<std::string> rename_manifest_package;
35 Maybe<std::string> rename_instrumentation_target_package;
36 Maybe<std::string> version_name_default;
37 Maybe<std::string> version_code_default;
Adam Lesinski2ae4a872015-11-02 16:10:55 -080038};
39
40/**
41 * Verifies that the manifest is correctly formed and inserts defaults
42 * where specified with ManifestFixerOptions.
43 */
Adam Lesinskicc5609d2016-04-05 12:41:07 -070044class ManifestFixer : public IXmlResourceConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070045 public:
46 explicit ManifestFixer(const ManifestFixerOptions& options)
Adam Lesinskice5e56e2016-10-21 17:56:45 -070047 : options_(options) {}
Adam Lesinski2ae4a872015-11-02 16:10:55 -080048
Adam Lesinskice5e56e2016-10-21 17:56:45 -070049 bool Consume(IAaptContext* context, xml::XmlResource* doc) override;
Adam Lesinskicc5609d2016-04-05 12:41:07 -070050
Adam Lesinskicacb28f2016-10-19 12:18:14 -070051 private:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070052 DISALLOW_COPY_AND_ASSIGN(ManifestFixer);
Adam Lesinskicc5609d2016-04-05 12:41:07 -070053
Adam Lesinskice5e56e2016-10-21 17:56:45 -070054 bool BuildRules(xml::XmlActionExecutor* executor, IDiagnostics* diag);
55
56 ManifestFixerOptions options_;
Adam Lesinski2ae4a872015-11-02 16:10:55 -080057};
58
Adam Lesinskicacb28f2016-10-19 12:18:14 -070059} // namespace aapt
Adam Lesinski2ae4a872015-11-02 16:10:55 -080060
61#endif /* AAPT_LINK_MANIFESTFIXER_H */