blob: d5d1d1770e1c5103f21a333b80aba05cd0819356 [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"
Ryan Mitchell4382e442021-07-14 12:53:01 -070025
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 Lesinskic6284372017-12-04 13:46:23 -080032 // The minimum SDK version to set if no 'android:minSdkVersion' is defined in a <uses-sdk> tag.
Ryan Mitchell4382e442021-07-14 12:53:01 -070033 std::optional<std::string> min_sdk_version_default;
Adam Lesinskic6284372017-12-04 13:46:23 -080034
35 // The target SDK version to set if no 'android:targetSdkVersion' is defined in a <uses-sdk> tag.
Ryan Mitchell4382e442021-07-14 12:53:01 -070036 std::optional<std::string> target_sdk_version_default;
Adam Lesinskic6284372017-12-04 13:46:23 -080037
38 // The Android package to use instead of the one defined in 'package' in <manifest>.
39 // This also renames all relative package/class names in the manifest to fully qualified
40 // Java names.
Ryan Mitchell4382e442021-07-14 12:53:01 -070041 std::optional<std::string> rename_manifest_package;
Adam Lesinskic6284372017-12-04 13:46:23 -080042
43 // The Android package to use instead of the one defined in 'android:targetPackage' in
44 // <instrumentation>.
Ryan Mitchell4382e442021-07-14 12:53:01 -070045 std::optional<std::string> rename_instrumentation_target_package;
Adam Lesinskic6284372017-12-04 13:46:23 -080046
Roshan Piusae12ce42020-04-25 16:08:55 -070047 // The Android package to use instead of the one defined in 'android:targetPackage' in
48 // <overlay>.
Ryan Mitchell4382e442021-07-14 12:53:01 -070049 std::optional<std::string> rename_overlay_target_package;
Roshan Piusae12ce42020-04-25 16:08:55 -070050
Colin Crossdcd58c42018-05-25 22:46:35 -070051 // The version name to set if 'android:versionName' is not defined in <manifest> or if
52 // replace_version is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070053 std::optional<std::string> version_name_default;
Adam Lesinskic6284372017-12-04 13:46:23 -080054
Colin Crossdcd58c42018-05-25 22:46:35 -070055 // The version code to set if 'android:versionCode' is not defined in <manifest> or if
56 // replace_version is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070057 std::optional<std::string> version_code_default;
Adam Lesinskic6284372017-12-04 13:46:23 -080058
Ryan Mitchell704090e2018-07-31 14:59:25 -070059 // The version code to set if 'android:versionCodeMajor' is not defined in <manifest> or if
60 // replace_version is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070061 std::optional<std::string> version_code_major_default;
Ryan Mitchell704090e2018-07-31 14:59:25 -070062
Rhed Jaob9ccb8a42020-11-30 21:42:16 +080063 // The revision code to set if 'android:revisionCode' is not defined in <manifest> or if
64 // replace_version is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070065 std::optional<std::string> revision_code_default;
Rhed Jaob9ccb8a42020-11-30 21:42:16 +080066
Adam Lesinskic6284372017-12-04 13:46:23 -080067 // The version of the framework being compiled against to set for 'android:compileSdkVersion' in
68 // the <manifest> tag.
Ryan Mitchell4382e442021-07-14 12:53:01 -070069 std::optional<std::string> compile_sdk_version;
Adam Lesinskic6284372017-12-04 13:46:23 -080070
71 // The version codename of the framework being compiled against to set for
72 // 'android:compileSdkVersionCodename' in the <manifest> tag.
Ryan Mitchell4382e442021-07-14 12:53:01 -070073 std::optional<std::string> compile_sdk_version_codename;
Izabela Orlowskaad9e1322017-12-19 16:22:42 +000074
Ryan Mitchell444f9bb2018-03-23 13:35:00 -070075 // Whether validation errors should be treated only as warnings. If this is 'true', then an
Izabela Orlowskaad9e1322017-12-19 16:22:42 +000076 // incorrect node will not result in an error, but only as a warning, and the parsing will
77 // continue.
78 bool warn_validation = false;
Ryan Mitchell444f9bb2018-03-23 13:35:00 -070079
80 // Whether to inject the android:debuggable="true" flag into the manifest
81 bool debug_mode = false;
Colin Crossdcd58c42018-05-25 22:46:35 -070082
83 // Whether to replace the manifest version with the the command line version
84 bool replace_version = false;
Adam Lesinski2ae4a872015-11-02 16:10:55 -080085};
86
Adam Lesinskic6284372017-12-04 13:46:23 -080087// Verifies that the manifest is correctly formed and inserts defaults where specified with
88// ManifestFixerOptions.
Adam Lesinskicc5609d2016-04-05 12:41:07 -070089class ManifestFixer : public IXmlResourceConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070090 public:
Adam Lesinskic6284372017-12-04 13:46:23 -080091 explicit ManifestFixer(const ManifestFixerOptions& options) : options_(options) {
92 }
Adam Lesinski2ae4a872015-11-02 16:10:55 -080093
Adam Lesinskice5e56e2016-10-21 17:56:45 -070094 bool Consume(IAaptContext* context, xml::XmlResource* doc) override;
Adam Lesinskicc5609d2016-04-05 12:41:07 -070095
Adam Lesinskicacb28f2016-10-19 12:18:14 -070096 private:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070097 DISALLOW_COPY_AND_ASSIGN(ManifestFixer);
Adam Lesinskicc5609d2016-04-05 12:41:07 -070098
Adam Lesinskice5e56e2016-10-21 17:56:45 -070099 bool BuildRules(xml::XmlActionExecutor* executor, IDiagnostics* diag);
100
101 ManifestFixerOptions options_;
Adam Lesinski2ae4a872015-11-02 16:10:55 -0800102};
103
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700104} // namespace aapt
Adam Lesinski2ae4a872015-11-02 16:10:55 -0800105
106#endif /* AAPT_LINK_MANIFESTFIXER_H */