| 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 | |
| 20 | #include <string> |
| 21 | |
| 22 | #include "android-base/macros.h" |
| 23 | |
| 24 | #include "process/IResourceTableConsumer.h" |
| 25 | |
| 26 | #include "xml/XmlActionExecutor.h" |
| 27 | #include "xml/XmlDom.h" |
| 28 | |
| 29 | namespace aapt { |
| 30 | |
| 31 | struct ManifestFixerOptions { |
| 32 | // The minimum SDK version to set if no 'android:minSdkVersion' is defined in a <uses-sdk> tag. |
| 33 | std::optional<std::string> min_sdk_version_default; |
| 34 | |
| 35 | // The target SDK version to set if no 'android:targetSdkVersion' is defined in a <uses-sdk> tag. |
| 36 | std::optional<std::string> target_sdk_version_default; |
| 37 | |
| 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. |
| 41 | std::optional<std::string> rename_manifest_package; |
| 42 | |
| 43 | // The Android package to use instead of the one defined in 'android:targetPackage' in |
| 44 | // <instrumentation>. |
| 45 | std::optional<std::string> rename_instrumentation_target_package; |
| 46 | |
| 47 | // The Android package to use instead of the one defined in 'android:targetPackage' in |
| 48 | // <overlay>. |
| 49 | std::optional<std::string> rename_overlay_target_package; |
| 50 | |
| 51 | // The category to use instead of the one defined in 'android:category' in <overlay>. |
| 52 | std::optional<std::string> rename_overlay_category; |
| 53 | |
| 54 | // The version name to set if 'android:versionName' is not defined in <manifest> or if |
| 55 | // replace_version is set. |
| 56 | std::optional<std::string> version_name_default; |
| 57 | |
| 58 | // The version code to set if 'android:versionCode' is not defined in <manifest> or if |
| 59 | // replace_version is set. |
| 60 | std::optional<std::string> version_code_default; |
| 61 | |
| 62 | // The version code to set if 'android:versionCodeMajor' is not defined in <manifest> or if |
| 63 | // replace_version is set. |
| 64 | std::optional<std::string> version_code_major_default; |
| 65 | |
| 66 | // The revision code to set if 'android:revisionCode' is not defined in <manifest> or if |
| 67 | // replace_version is set. |
| 68 | std::optional<std::string> revision_code_default; |
| 69 | |
| 70 | // The version of the framework being compiled against to set for 'android:compileSdkVersion' in |
| 71 | // the <manifest> tag. |
| 72 | std::optional<std::string> compile_sdk_version; |
| 73 | |
| 74 | // The version codename of the framework being compiled against to set for |
| 75 | // 'android:compileSdkVersionCodename' in the <manifest> tag. |
| 76 | std::optional<std::string> compile_sdk_version_codename; |
| 77 | |
| 78 | // Whether validation errors should be treated only as warnings. If this is 'true', then an |
| 79 | // incorrect node will not result in an error, but only as a warning, and the parsing will |
| 80 | // continue. |
| 81 | bool warn_validation = false; |
| 82 | |
| 83 | // Whether to inject the android:debuggable="true" flag into the manifest |
| 84 | bool debug_mode = false; |
| 85 | |
| 86 | // Whether to replace the manifest version with the the command line version |
| 87 | bool replace_version = false; |
| 88 | }; |
| 89 | |
| 90 | // Verifies that the manifest is correctly formed and inserts defaults where specified with |
| 91 | // ManifestFixerOptions. |
| 92 | class ManifestFixer : public IXmlResourceConsumer { |
| 93 | public: |
| 94 | explicit ManifestFixer(const ManifestFixerOptions& options) : options_(options) { |
| 95 | } |
| 96 | |
| 97 | bool Consume(IAaptContext* context, xml::XmlResource* doc) override; |
| 98 | |
| 99 | private: |
| 100 | DISALLOW_COPY_AND_ASSIGN(ManifestFixer); |
| 101 | |
| 102 | bool BuildRules(xml::XmlActionExecutor* executor, IDiagnostics* diag); |
| 103 | |
| 104 | ManifestFixerOptions options_; |
| 105 | }; |
| 106 | |
| 107 | } // namespace aapt |
| 108 | |
| 109 | #endif /* AAPT_LINK_MANIFESTFIXER_H */ |