Merge "aapt2: Add command to rename overlay "targetPackage" attribute" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6839fc74b6
@@ -263,6 +263,10 @@ class LinkCommand : public Command {
|
|||||||
"Changes the name of the target package for instrumentation. Most useful\n"
|
"Changes the name of the target package for instrumentation. Most useful\n"
|
||||||
"when used in conjunction with --rename-manifest-package.",
|
"when used in conjunction with --rename-manifest-package.",
|
||||||
&options_.manifest_fixer_options.rename_instrumentation_target_package);
|
&options_.manifest_fixer_options.rename_instrumentation_target_package);
|
||||||
|
AddOptionalFlag("--rename-overlay-target-package",
|
||||||
|
"Changes the name of the target package for overlay. Most useful\n"
|
||||||
|
"when used in conjunction with --rename-manifest-package.",
|
||||||
|
&options_.manifest_fixer_options.rename_overlay_target_package);
|
||||||
AddOptionalFlagList("-0", "File suffix not to compress.",
|
AddOptionalFlagList("-0", "File suffix not to compress.",
|
||||||
&options_.extensions_to_not_compress);
|
&options_.extensions_to_not_compress);
|
||||||
AddOptionalSwitch("--no-compress", "Do not compress any resources.",
|
AddOptionalSwitch("--no-compress", "Do not compress any resources.",
|
||||||
|
|||||||
@@ -263,6 +263,16 @@ bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options_.rename_overlay_target_package) {
|
||||||
|
if (!util::IsJavaPackageName(options_.rename_overlay_target_package.value())) {
|
||||||
|
diag->Error(DiagMessage()
|
||||||
|
<< "invalid overlay target package override '"
|
||||||
|
<< options_.rename_overlay_target_package.value()
|
||||||
|
<< "'");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Common <intent-filter> actions.
|
// Common <intent-filter> actions.
|
||||||
xml::XmlNodeAction intent_filter_action;
|
xml::XmlNodeAction intent_filter_action;
|
||||||
intent_filter_action["action"].Action(RequiredNameIsNotEmpty);
|
intent_filter_action["action"].Action(RequiredNameIsNotEmpty);
|
||||||
@@ -373,7 +383,17 @@ bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor,
|
|||||||
manifest_action["attribution"];
|
manifest_action["attribution"];
|
||||||
manifest_action["attribution"]["inherit-from"];
|
manifest_action["attribution"]["inherit-from"];
|
||||||
manifest_action["original-package"];
|
manifest_action["original-package"];
|
||||||
manifest_action["overlay"];
|
manifest_action["overlay"].Action([&](xml::Element* el) -> bool {
|
||||||
|
if (!options_.rename_overlay_target_package) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xml::Attribute* attr =
|
||||||
|
el->FindAttribute(xml::kSchemaAndroid, "targetPackage")) {
|
||||||
|
attr->value = options_.rename_overlay_target_package.value();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
manifest_action["protected-broadcast"];
|
manifest_action["protected-broadcast"];
|
||||||
manifest_action["adopt-permissions"];
|
manifest_action["adopt-permissions"];
|
||||||
manifest_action["uses-permission"];
|
manifest_action["uses-permission"];
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ struct ManifestFixerOptions {
|
|||||||
// <instrumentation>.
|
// <instrumentation>.
|
||||||
Maybe<std::string> rename_instrumentation_target_package;
|
Maybe<std::string> rename_instrumentation_target_package;
|
||||||
|
|
||||||
|
// The Android package to use instead of the one defined in 'android:targetPackage' in
|
||||||
|
// <overlay>.
|
||||||
|
Maybe<std::string> rename_overlay_target_package;
|
||||||
|
|
||||||
// The version name to set if 'android:versionName' is not defined in <manifest> or if
|
// The version name to set if 'android:versionName' is not defined in <manifest> or if
|
||||||
// replace_version is set.
|
// replace_version is set.
|
||||||
Maybe<std::string> version_name_default;
|
Maybe<std::string> version_name_default;
|
||||||
|
|||||||
@@ -325,6 +325,32 @@ TEST_F(ManifestFixerTest,
|
|||||||
EXPECT_THAT(attr->value, StrEq("com.android"));
|
EXPECT_THAT(attr->value, StrEq("com.android"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ManifestFixerTest,
|
||||||
|
RenameManifestOverlayPackageAndFullyQualifyTarget) {
|
||||||
|
ManifestFixerOptions options;
|
||||||
|
options.rename_overlay_target_package = std::string("com.android");
|
||||||
|
|
||||||
|
std::unique_ptr<xml::XmlResource> doc = VerifyWithOptions(R"EOF(
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="android">
|
||||||
|
<overlay android:targetName="Customization" android:targetPackage="android" />
|
||||||
|
</manifest>)EOF",
|
||||||
|
options);
|
||||||
|
ASSERT_THAT(doc, NotNull());
|
||||||
|
|
||||||
|
xml::Element* manifest_el = doc->root.get();
|
||||||
|
ASSERT_THAT(manifest_el, NotNull());
|
||||||
|
|
||||||
|
xml::Element* overlay_el =
|
||||||
|
manifest_el->FindChild({}, "overlay");
|
||||||
|
ASSERT_THAT(overlay_el, NotNull());
|
||||||
|
|
||||||
|
xml::Attribute* attr =
|
||||||
|
overlay_el->FindAttribute(xml::kSchemaAndroid, "targetPackage");
|
||||||
|
ASSERT_THAT(attr, NotNull());
|
||||||
|
EXPECT_THAT(attr->value, StrEq("com.android"));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ManifestFixerTest, UseDefaultVersionNameAndCode) {
|
TEST_F(ManifestFixerTest, UseDefaultVersionNameAndCode) {
|
||||||
ManifestFixerOptions options;
|
ManifestFixerOptions options;
|
||||||
options.version_name_default = std::string("Beta");
|
options.version_name_default = std::string("Beta");
|
||||||
|
|||||||
Reference in New Issue
Block a user