Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 1 | /* |
| 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 Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 20 | #include <string> |
Andrei Onea | 7109b70 | 2023-02-23 17:43:25 +0000 | [diff] [blame] | 21 | #include <vector> |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 22 | |
| 23 | #include "android-base/macros.h" |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 24 | #include "process/IResourceTableConsumer.h" |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 25 | #include "xml/XmlActionExecutor.h" |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 26 | #include "xml/XmlDom.h" |
| 27 | |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 28 | namespace aapt { |
| 29 | |
| 30 | struct ManifestFixerOptions { |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 31 | // The minimum SDK version to set if no 'android:minSdkVersion' is defined in a <uses-sdk> tag. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 32 | std::optional<std::string> min_sdk_version_default; |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 33 | |
| 34 | // The target SDK version to set if no 'android:targetSdkVersion' is defined in a <uses-sdk> tag. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 35 | std::optional<std::string> target_sdk_version_default; |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 36 | |
| 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 Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 40 | std::optional<std::string> rename_manifest_package; |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 41 | |
| 42 | // The Android package to use instead of the one defined in 'android:targetPackage' in |
| 43 | // <instrumentation>. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 44 | std::optional<std::string> rename_instrumentation_target_package; |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 45 | |
Roshan Pius | ae12ce4 | 2020-04-25 16:08:55 -0700 | [diff] [blame] | 46 | // The Android package to use instead of the one defined in 'android:targetPackage' in |
| 47 | // <overlay>. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 48 | std::optional<std::string> rename_overlay_target_package; |
Roshan Pius | ae12ce4 | 2020-04-25 16:08:55 -0700 | [diff] [blame] | 49 | |
Jeremy Meyer | 6b05b7d | 2022-09-30 22:22:24 +0000 | [diff] [blame] | 50 | // The category to use instead of the one defined in 'android:category' in <overlay>. |
| 51 | std::optional<std::string> rename_overlay_category; |
| 52 | |
Colin Cross | dcd58c4 | 2018-05-25 22:46:35 -0700 | [diff] [blame] | 53 | // The version name to set if 'android:versionName' is not defined in <manifest> or if |
| 54 | // replace_version is set. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 55 | std::optional<std::string> version_name_default; |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 56 | |
Colin Cross | dcd58c4 | 2018-05-25 22:46:35 -0700 | [diff] [blame] | 57 | // The version code to set if 'android:versionCode' is not defined in <manifest> or if |
| 58 | // replace_version is set. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 59 | std::optional<std::string> version_code_default; |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 60 | |
Ryan Mitchell | 704090e | 2018-07-31 14:59:25 -0700 | [diff] [blame] | 61 | // The version code to set if 'android:versionCodeMajor' is not defined in <manifest> or if |
| 62 | // replace_version is set. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 63 | std::optional<std::string> version_code_major_default; |
Ryan Mitchell | 704090e | 2018-07-31 14:59:25 -0700 | [diff] [blame] | 64 | |
Rhed Jao | b9ccb8a4 | 2020-11-30 21:42:16 +0800 | [diff] [blame] | 65 | // The revision code to set if 'android:revisionCode' is not defined in <manifest> or if |
| 66 | // replace_version is set. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 67 | std::optional<std::string> revision_code_default; |
Rhed Jao | b9ccb8a4 | 2020-11-30 21:42:16 +0800 | [diff] [blame] | 68 | |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 69 | // The version of the framework being compiled against to set for 'android:compileSdkVersion' in |
Alan Viverette | 07287be | 2023-05-02 16:34:27 -0400 | [diff] [blame^] | 70 | // the <manifest> tag. Not used if no_compile_sdk_metadata is set. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 71 | std::optional<std::string> compile_sdk_version; |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 72 | |
| 73 | // The version codename of the framework being compiled against to set for |
Alan Viverette | 07287be | 2023-05-02 16:34:27 -0400 | [diff] [blame^] | 74 | // 'android:compileSdkVersionCodename' in the <manifest> tag. Not used if no_compile_sdk_metadata |
| 75 | // is set. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 76 | std::optional<std::string> compile_sdk_version_codename; |
Izabela Orlowska | ad9e132 | 2017-12-19 16:22:42 +0000 | [diff] [blame] | 77 | |
Andrei Onea | 7109b70 | 2023-02-23 17:43:25 +0000 | [diff] [blame] | 78 | // The fingerprint prefixes to be added to the <install-constraints> tag. |
| 79 | std::vector<std::string> fingerprint_prefixes; |
| 80 | |
Ryan Mitchell | 444f9bb | 2018-03-23 13:35:00 -0700 | [diff] [blame] | 81 | // Whether validation errors should be treated only as warnings. If this is 'true', then an |
Izabela Orlowska | ad9e132 | 2017-12-19 16:22:42 +0000 | [diff] [blame] | 82 | // 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 Mitchell | 444f9bb | 2018-03-23 13:35:00 -0700 | [diff] [blame] | 85 | |
| 86 | // Whether to inject the android:debuggable="true" flag into the manifest |
| 87 | bool debug_mode = false; |
Colin Cross | dcd58c4 | 2018-05-25 22:46:35 -0700 | [diff] [blame] | 88 | |
| 89 | // Whether to replace the manifest version with the the command line version |
| 90 | bool replace_version = false; |
Alan Viverette | 07287be | 2023-05-02 16:34:27 -0400 | [diff] [blame^] | 91 | |
| 92 | // Whether to suppress `android:compileSdkVersion*` and `platformBuildVersion*` attributes. |
| 93 | bool no_compile_sdk_metadata = false; |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 96 | // Verifies that the manifest is correctly formed and inserts defaults where specified with |
| 97 | // ManifestFixerOptions. |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 98 | class ManifestFixer : public IXmlResourceConsumer { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 99 | public: |
Adam Lesinski | c628437 | 2017-12-04 13:46:23 -0800 | [diff] [blame] | 100 | explicit ManifestFixer(const ManifestFixerOptions& options) : options_(options) { |
| 101 | } |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 102 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 103 | bool Consume(IAaptContext* context, xml::XmlResource* doc) override; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 104 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 105 | private: |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 106 | DISALLOW_COPY_AND_ASSIGN(ManifestFixer); |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 107 | |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 108 | bool BuildRules(xml::XmlActionExecutor* executor, android::IDiagnostics* diag); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 109 | |
| 110 | ManifestFixerOptions options_; |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 113 | } // namespace aapt |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 114 | |
| 115 | #endif /* AAPT_LINK_MANIFESTFIXER_H */ |