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 | #include "ResourceUtils.h" |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 18 | #include "link/ManifestFixer.h" |
| 19 | #include "util/Util.h" |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 20 | #include "xml/XmlActionExecutor.h" |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 21 | #include "xml/XmlDom.h" |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 22 | |
Adam Lesinski | 71965e8 | 2016-07-07 17:12:12 -0700 | [diff] [blame] | 23 | #include <unordered_set> |
| 24 | |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 25 | namespace aapt { |
| 26 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 27 | /** |
| 28 | * This is how PackageManager builds class names from AndroidManifest.xml entries. |
| 29 | */ |
| 30 | static bool nameIsJavaClassName(xml::Element* el, xml::Attribute* attr, |
| 31 | SourcePathDiagnostics* diag) { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 32 | // We allow unqualified class names (ie: .HelloActivity) |
| 33 | // Since we don't know the package name, we can just make a fake one here and |
| 34 | // the test will be identical as long as the real package name is valid too. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 35 | Maybe<std::string> fullyQualifiedClassName = |
| 36 | util::getFullyQualifiedClassName("a", attr->value); |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 37 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 38 | StringPiece qualifiedClassName = fullyQualifiedClassName |
Adam Lesinski | 71965e8 | 2016-07-07 17:12:12 -0700 | [diff] [blame] | 39 | ? fullyQualifiedClassName.value() : attr->value; |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 40 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 41 | if (!util::isJavaClassName(qualifiedClassName)) { |
| 42 | diag->error(DiagMessage(el->lineNumber) |
| 43 | << "attribute 'android:name' in <" |
| 44 | << el->name << "> tag must be a valid Java class name"); |
| 45 | return false; |
| 46 | } |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | static bool optionalNameIsJavaClassName(xml::Element* el, SourcePathDiagnostics* diag) { |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 51 | if (xml::Attribute* attr = el->findAttribute(xml::kSchemaAndroid, "name")) { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 52 | return nameIsJavaClassName(el, attr, diag); |
| 53 | } |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | static bool requiredNameIsJavaClassName(xml::Element* el, SourcePathDiagnostics* diag) { |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 58 | if (xml::Attribute* attr = el->findAttribute(xml::kSchemaAndroid, "name")) { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 59 | return nameIsJavaClassName(el, attr, diag); |
| 60 | } |
| 61 | diag->error(DiagMessage(el->lineNumber) |
| 62 | << "<" << el->name << "> is missing attribute 'android:name'"); |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 63 | return false; |
| 64 | } |
| 65 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 66 | static bool verifyManifest(xml::Element* el, SourcePathDiagnostics* diag) { |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 67 | xml::Attribute* attr = el->findAttribute({}, "package"); |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 68 | if (!attr) { |
| 69 | diag->error(DiagMessage(el->lineNumber) << "<manifest> tag is missing 'package' attribute"); |
| 70 | return false; |
| 71 | } else if (ResourceUtils::isReference(attr->value)) { |
| 72 | diag->error(DiagMessage(el->lineNumber) |
| 73 | << "attribute 'package' in <manifest> tag must not be a reference"); |
| 74 | return false; |
| 75 | } else if (!util::isJavaPackageName(attr->value)) { |
| 76 | diag->error(DiagMessage(el->lineNumber) |
| 77 | << "attribute 'package' in <manifest> tag is not a valid Java package name: '" |
| 78 | << attr->value << "'"); |
| 79 | return false; |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 80 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 81 | return true; |
| 82 | } |
| 83 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 84 | bool ManifestFixer::buildRules(xml::XmlActionExecutor* executor, IDiagnostics* diag) { |
| 85 | // First verify some options. |
| 86 | if (mOptions.renameManifestPackage) { |
| 87 | if (!util::isJavaPackageName(mOptions.renameManifestPackage.value())) { |
| 88 | diag->error(DiagMessage() << "invalid manifest package override '" |
| 89 | << mOptions.renameManifestPackage.value() << "'"); |
| 90 | return false; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | if (mOptions.renameInstrumentationTargetPackage) { |
| 95 | if (!util::isJavaPackageName(mOptions.renameInstrumentationTargetPackage.value())) { |
| 96 | diag->error(DiagMessage() << "invalid instrumentation target package override '" |
| 97 | << mOptions.renameInstrumentationTargetPackage.value() << "'"); |
| 98 | return false; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // Common intent-filter actions. |
| 103 | xml::XmlNodeAction intentFilterAction; |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 104 | intentFilterAction["action"]; |
| 105 | intentFilterAction["category"]; |
| 106 | intentFilterAction["data"]; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 107 | |
| 108 | // Common meta-data actions. |
| 109 | xml::XmlNodeAction metaDataAction; |
| 110 | |
| 111 | // Manifest actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 112 | xml::XmlNodeAction& manifestAction = (*executor)["manifest"]; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 113 | manifestAction.action(verifyManifest); |
| 114 | manifestAction.action([&](xml::Element* el) -> bool { |
| 115 | if (mOptions.versionNameDefault) { |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 116 | if (el->findAttribute(xml::kSchemaAndroid, "versionName") == nullptr) { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 117 | el->attributes.push_back(xml::Attribute{ |
| 118 | xml::kSchemaAndroid, |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 119 | "versionName", |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 120 | mOptions.versionNameDefault.value() }); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if (mOptions.versionCodeDefault) { |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 125 | if (el->findAttribute(xml::kSchemaAndroid, "versionCode") == nullptr) { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 126 | el->attributes.push_back(xml::Attribute{ |
| 127 | xml::kSchemaAndroid, |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 128 | "versionCode", |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 129 | mOptions.versionCodeDefault.value() }); |
| 130 | } |
| 131 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 132 | return true; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 133 | }); |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 134 | |
Adam Lesinski | 5ff3ad6 | 2016-04-13 20:30:45 -0700 | [diff] [blame] | 135 | // Meta tags. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 136 | manifestAction["eat-comment"]; |
Adam Lesinski | 5ff3ad6 | 2016-04-13 20:30:45 -0700 | [diff] [blame] | 137 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 138 | // Uses-sdk actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 139 | manifestAction["uses-sdk"].action([&](xml::Element* el) -> bool { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 140 | if (mOptions.minSdkVersionDefault && |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 141 | el->findAttribute(xml::kSchemaAndroid, "minSdkVersion") == nullptr) { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 142 | // There was no minSdkVersion defined and we have a default to assign. |
| 143 | el->attributes.push_back(xml::Attribute{ |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 144 | xml::kSchemaAndroid, "minSdkVersion", |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 145 | mOptions.minSdkVersionDefault.value() }); |
| 146 | } |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 147 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 148 | if (mOptions.targetSdkVersionDefault && |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 149 | el->findAttribute(xml::kSchemaAndroid, "targetSdkVersion") == nullptr) { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 150 | // There was no targetSdkVersion defined and we have a default to assign. |
| 151 | el->attributes.push_back(xml::Attribute{ |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 152 | xml::kSchemaAndroid, "targetSdkVersion", |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 153 | mOptions.targetSdkVersionDefault.value() }); |
| 154 | } |
| 155 | return true; |
| 156 | }); |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 157 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 158 | // Instrumentation actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 159 | manifestAction["instrumentation"].action([&](xml::Element* el) -> bool { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 160 | if (!mOptions.renameInstrumentationTargetPackage) { |
| 161 | return true; |
| 162 | } |
| 163 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 164 | if (xml::Attribute* attr = el->findAttribute(xml::kSchemaAndroid, "targetPackage")) { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 165 | attr->value = mOptions.renameInstrumentationTargetPackage.value(); |
| 166 | } |
| 167 | return true; |
| 168 | }); |
| 169 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 170 | manifestAction["original-package"]; |
| 171 | manifestAction["protected-broadcast"]; |
| 172 | manifestAction["uses-permission"]; |
| 173 | manifestAction["permission"]; |
| 174 | manifestAction["permission-tree"]; |
| 175 | manifestAction["permission-group"]; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 176 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 177 | manifestAction["uses-configuration"]; |
| 178 | manifestAction["uses-feature"]; |
| 179 | manifestAction["supports-screens"]; |
| 180 | manifestAction["compatible-screens"]; |
| 181 | manifestAction["supports-gl-texture"]; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 182 | |
| 183 | // Application actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 184 | xml::XmlNodeAction& applicationAction = manifestAction["application"]; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 185 | applicationAction.action(optionalNameIsJavaClassName); |
| 186 | |
Adam Lesinski | fee32d4 | 2016-05-31 15:07:20 -0700 | [diff] [blame] | 187 | // Uses library actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 188 | applicationAction["uses-library"]; |
Adam Lesinski | fee32d4 | 2016-05-31 15:07:20 -0700 | [diff] [blame] | 189 | |
Adam Lesinski | 5d84ad5 | 2016-06-23 13:18:16 -0700 | [diff] [blame] | 190 | // Meta-data. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 191 | applicationAction["meta-data"] = metaDataAction; |
Adam Lesinski | 5d84ad5 | 2016-06-23 13:18:16 -0700 | [diff] [blame] | 192 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 193 | // Activity actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 194 | applicationAction["activity"].action(requiredNameIsJavaClassName); |
| 195 | applicationAction["activity"]["intent-filter"] = intentFilterAction; |
| 196 | applicationAction["activity"]["meta-data"] = metaDataAction; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 197 | |
| 198 | // Activity alias actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 199 | applicationAction["activity-alias"]["intent-filter"] = intentFilterAction; |
| 200 | applicationAction["activity-alias"]["meta-data"] = metaDataAction; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 201 | |
| 202 | // Service actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 203 | applicationAction["service"].action(requiredNameIsJavaClassName); |
| 204 | applicationAction["service"]["intent-filter"] = intentFilterAction; |
| 205 | applicationAction["service"]["meta-data"] = metaDataAction; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 206 | |
| 207 | // Receiver actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 208 | applicationAction["receiver"].action(requiredNameIsJavaClassName); |
| 209 | applicationAction["receiver"]["intent-filter"] = intentFilterAction; |
| 210 | applicationAction["receiver"]["meta-data"] = metaDataAction; |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 211 | |
| 212 | // Provider actions. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 213 | applicationAction["provider"].action(requiredNameIsJavaClassName); |
Adam Lesinski | bb5a390 | 2016-08-01 15:01:08 -0700 | [diff] [blame^] | 214 | applicationAction["provider"]["intent-filter"] = intentFilterAction; |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 215 | applicationAction["provider"]["meta-data"] = metaDataAction; |
Adam Lesinski | bb5a390 | 2016-08-01 15:01:08 -0700 | [diff] [blame^] | 216 | applicationAction["provider"]["grant-uri-permissions"]; |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 217 | applicationAction["provider"]["path-permissions"]; |
Adam Lesinski | bb5a390 | 2016-08-01 15:01:08 -0700 | [diff] [blame^] | 218 | |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 219 | return true; |
| 220 | } |
| 221 | |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 222 | class FullyQualifiedClassNameVisitor : public xml::Visitor { |
| 223 | public: |
| 224 | using xml::Visitor::visit; |
| 225 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 226 | explicit FullyQualifiedClassNameVisitor(const StringPiece& package) : mPackage(package) { |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void visit(xml::Element* el) override { |
| 230 | for (xml::Attribute& attr : el->attributes) { |
Adam Lesinski | 71965e8 | 2016-07-07 17:12:12 -0700 | [diff] [blame] | 231 | if (attr.namespaceUri == xml::kSchemaAndroid |
| 232 | && mClassAttributes.find(attr.name) != mClassAttributes.end()) { |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 233 | if (Maybe<std::string> newValue = |
Adam Lesinski | 71965e8 | 2016-07-07 17:12:12 -0700 | [diff] [blame] | 234 | util::getFullyQualifiedClassName(mPackage, attr.value)) { |
| 235 | attr.value = std::move(newValue.value()); |
| 236 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
| 240 | // Super implementation to iterate over the children. |
| 241 | xml::Visitor::visit(el); |
| 242 | } |
| 243 | |
| 244 | private: |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 245 | StringPiece mPackage; |
| 246 | std::unordered_set<StringPiece> mClassAttributes = { "name" }; |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 247 | }; |
| 248 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 249 | static bool renameManifestPackage(const StringPiece& packageOverride, xml::Element* manifestEl) { |
| 250 | xml::Attribute* attr = manifestEl->findAttribute({}, "package"); |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 251 | |
| 252 | // We've already verified that the manifest element is present, with a package name specified. |
| 253 | assert(attr); |
| 254 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 255 | std::string originalPackage = std::move(attr->value); |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 256 | attr->value = packageOverride.toString(); |
| 257 | |
| 258 | FullyQualifiedClassNameVisitor visitor(originalPackage); |
| 259 | manifestEl->accept(&visitor); |
| 260 | return true; |
| 261 | } |
| 262 | |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 263 | bool ManifestFixer::consume(IAaptContext* context, xml::XmlResource* doc) { |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 264 | xml::Element* root = xml::findRootElement(doc->root.get()); |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 265 | if (!root || !root->namespaceUri.empty() || root->name != "manifest") { |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 266 | context->getDiagnostics()->error(DiagMessage(doc->file.source) |
| 267 | << "root tag must be <manifest>"); |
| 268 | return false; |
| 269 | } |
| 270 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 271 | if ((mOptions.minSdkVersionDefault || mOptions.targetSdkVersionDefault) |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 272 | && root->findChild({}, "uses-sdk") == nullptr) { |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 273 | // Auto insert a <uses-sdk> element. |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 274 | std::unique_ptr<xml::Element> usesSdk = util::make_unique<xml::Element>(); |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 275 | usesSdk->name = "uses-sdk"; |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 276 | root->addChild(std::move(usesSdk)); |
| 277 | } |
| 278 | |
Adam Lesinski | cc5609d | 2016-04-05 12:41:07 -0700 | [diff] [blame] | 279 | xml::XmlActionExecutor executor; |
| 280 | if (!buildRules(&executor, context->getDiagnostics())) { |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | if (!executor.execute(xml::XmlActionExecutorPolicy::Whitelist, context->getDiagnostics(), |
| 285 | doc)) { |
| 286 | return false; |
| 287 | } |
| 288 | |
| 289 | if (mOptions.renameManifestPackage) { |
| 290 | // Rename manifest package outside of the XmlActionExecutor. |
| 291 | // We need to extract the old package name and FullyQualify all class names. |
| 292 | if (!renameManifestPackage(mOptions.renameManifestPackage.value(), root)) { |
| 293 | return false; |
| 294 | } |
| 295 | } |
Adam Lesinski | 2ae4a87 | 2015-11-02 16:10:55 -0800 | [diff] [blame] | 296 | return true; |
| 297 | } |
| 298 | |
| 299 | } // namespace aapt |