blob: 748a82858175b31038fe1770659e35687f6a2f34 [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>
Andrei Onea7109b702023-02-23 17:43:25 +000021#include <vector>
Adam Lesinskice5e56e2016-10-21 17:56:45 -070022
23#include "android-base/macros.h"
Adam Lesinski2ae4a872015-11-02 16:10:55 -080024#include "process/IResourceTableConsumer.h"
Adam Lesinskicc5609d2016-04-05 12:41:07 -070025#include "xml/XmlActionExecutor.h"
Adam Lesinski467f1712015-11-16 17:35:44 -080026#include "xml/XmlDom.h"
27
Adam Lesinski2ae4a872015-11-02 16:10:55 -080028namespace aapt {
29
30struct ManifestFixerOptions {
Adam Lesinskic6284372017-12-04 13:46:23 -080031 // The minimum SDK version to set if no 'android:minSdkVersion' is defined in a <uses-sdk> tag.
Ryan Mitchell4382e442021-07-14 12:53:01 -070032 std::optional<std::string> min_sdk_version_default;
Adam Lesinskic6284372017-12-04 13:46:23 -080033
34 // The target SDK version to set if no 'android:targetSdkVersion' is defined in a <uses-sdk> tag.
Ryan Mitchell4382e442021-07-14 12:53:01 -070035 std::optional<std::string> target_sdk_version_default;
Adam Lesinskic6284372017-12-04 13:46:23 -080036
37 // The Android package to use instead of the one defined in 'package' in <manifest>.
38 // This also renames all relative package/class names in the manifest to fully qualified
39 // Java names.
Ryan Mitchell4382e442021-07-14 12:53:01 -070040 std::optional<std::string> rename_manifest_package;
Adam Lesinskic6284372017-12-04 13:46:23 -080041
42 // The Android package to use instead of the one defined in 'android:targetPackage' in
43 // <instrumentation>.
Ryan Mitchell4382e442021-07-14 12:53:01 -070044 std::optional<std::string> rename_instrumentation_target_package;
Adam Lesinskic6284372017-12-04 13:46:23 -080045
Roshan Piusae12ce42020-04-25 16:08:55 -070046 // The Android package to use instead of the one defined in 'android:targetPackage' in
47 // <overlay>.
Ryan Mitchell4382e442021-07-14 12:53:01 -070048 std::optional<std::string> rename_overlay_target_package;
Roshan Piusae12ce42020-04-25 16:08:55 -070049
Jeremy Meyer6b05b7d2022-09-30 22:22:24 +000050 // The category to use instead of the one defined in 'android:category' in <overlay>.
51 std::optional<std::string> rename_overlay_category;
52
Colin Crossdcd58c42018-05-25 22:46:35 -070053 // The version name to set if 'android:versionName' is not defined in <manifest> or if
54 // replace_version is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070055 std::optional<std::string> version_name_default;
Adam Lesinskic6284372017-12-04 13:46:23 -080056
Colin Crossdcd58c42018-05-25 22:46:35 -070057 // The version code to set if 'android:versionCode' is not defined in <manifest> or if
58 // replace_version is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070059 std::optional<std::string> version_code_default;
Adam Lesinskic6284372017-12-04 13:46:23 -080060
Ryan Mitchell704090e2018-07-31 14:59:25 -070061 // The version code to set if 'android:versionCodeMajor' is not defined in <manifest> or if
62 // replace_version is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070063 std::optional<std::string> version_code_major_default;
Ryan Mitchell704090e2018-07-31 14:59:25 -070064
Rhed Jaob9ccb8a42020-11-30 21:42:16 +080065 // The revision code to set if 'android:revisionCode' is not defined in <manifest> or if
66 // replace_version is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070067 std::optional<std::string> revision_code_default;
Rhed Jaob9ccb8a42020-11-30 21:42:16 +080068
Adam Lesinskic6284372017-12-04 13:46:23 -080069 // The version of the framework being compiled against to set for 'android:compileSdkVersion' in
Alan Viverette07287be2023-05-02 16:34:27 -040070 // the <manifest> tag. Not used if no_compile_sdk_metadata is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070071 std::optional<std::string> compile_sdk_version;
Adam Lesinskic6284372017-12-04 13:46:23 -080072
73 // The version codename of the framework being compiled against to set for
Alan Viverette07287be2023-05-02 16:34:27 -040074 // 'android:compileSdkVersionCodename' in the <manifest> tag. Not used if no_compile_sdk_metadata
75 // is set.
Ryan Mitchell4382e442021-07-14 12:53:01 -070076 std::optional<std::string> compile_sdk_version_codename;
Izabela Orlowskaad9e1322017-12-19 16:22:42 +000077
Andrei Onea7109b702023-02-23 17:43:25 +000078 // The fingerprint prefixes to be added to the <install-constraints> tag.
79 std::vector<std::string> fingerprint_prefixes;
80
Ryan Mitchell444f9bb2018-03-23 13:35:00 -070081 // Whether validation errors should be treated only as warnings. If this is 'true', then an
Izabela Orlowskaad9e1322017-12-19 16:22:42 +000082 // incorrect node will not result in an error, but only as a warning, and the parsing will
83 // continue.
84 bool warn_validation = false;
Ryan Mitchell444f9bb2018-03-23 13:35:00 -070085
86 // Whether to inject the android:debuggable="true" flag into the manifest
87 bool debug_mode = false;
Colin Crossdcd58c42018-05-25 22:46:35 -070088
89 // Whether to replace the manifest version with the the command line version
90 bool replace_version = false;
Alan Viverette07287be2023-05-02 16:34:27 -040091
92 // Whether to suppress `android:compileSdkVersion*` and `platformBuildVersion*` attributes.
93 bool no_compile_sdk_metadata = false;
Mark Punzalancc694e52024-04-02 20:43:23 +000094
95 // Whether to mark the app as a non-updatable system app. This adds `updatableSystem="false"` to
96 // the <manifest> tag. Not used if a version code is set either explicitly in the manifest or
97 // through version_code_default.
98 bool non_updatable_system = false;
Adam Lesinski2ae4a872015-11-02 16:10:55 -080099};
100
Adam Lesinskic6284372017-12-04 13:46:23 -0800101// Verifies that the manifest is correctly formed and inserts defaults where specified with
102// ManifestFixerOptions.
Adam Lesinskicc5609d2016-04-05 12:41:07 -0700103class ManifestFixer : public IXmlResourceConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700104 public:
Adam Lesinskic6284372017-12-04 13:46:23 -0800105 explicit ManifestFixer(const ManifestFixerOptions& options) : options_(options) {
106 }
Adam Lesinski2ae4a872015-11-02 16:10:55 -0800107
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700108 bool Consume(IAaptContext* context, xml::XmlResource* doc) override;
Adam Lesinskicc5609d2016-04-05 12:41:07 -0700109
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700110 private:
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700111 DISALLOW_COPY_AND_ASSIGN(ManifestFixer);
Adam Lesinskicc5609d2016-04-05 12:41:07 -0700112
Brandon Liu7de701f2024-06-11 18:51:39 +0000113 bool BuildRules(xml::XmlActionExecutor* executor, IAaptContext* context);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700114
115 ManifestFixerOptions options_;
Adam Lesinski2ae4a872015-11-02 16:10:55 -0800116};
117
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700118} // namespace aapt
Adam Lesinski2ae4a872015-11-02 16:10:55 -0800119
120#endif /* AAPT_LINK_MANIFESTFIXER_H */