Merge "Allow passing in a category override to aapt2"
This commit is contained in:
@@ -270,6 +270,8 @@ class LinkCommand : public Command {
|
|||||||
"Changes the name of the target package for overlay. Most useful\n"
|
"Changes the name of the target package for overlay. Most useful\n"
|
||||||
"when used in conjunction with --rename-manifest-package.",
|
"when used in conjunction with --rename-manifest-package.",
|
||||||
&options_.manifest_fixer_options.rename_overlay_target_package);
|
&options_.manifest_fixer_options.rename_overlay_target_package);
|
||||||
|
AddOptionalFlag("--rename-overlay-category", "Changes the category for the overlay.",
|
||||||
|
&options_.manifest_fixer_options.rename_overlay_category);
|
||||||
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.",
|
||||||
|
|||||||
@@ -449,13 +449,18 @@ bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor,
|
|||||||
manifest_action["attribution"]["inherit-from"];
|
manifest_action["attribution"]["inherit-from"];
|
||||||
manifest_action["original-package"];
|
manifest_action["original-package"];
|
||||||
manifest_action["overlay"].Action([&](xml::Element* el) -> bool {
|
manifest_action["overlay"].Action([&](xml::Element* el) -> bool {
|
||||||
if (!options_.rename_overlay_target_package) {
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (options_.rename_overlay_category) {
|
||||||
if (xml::Attribute* attr =
|
if (xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, "category")) {
|
||||||
el->FindAttribute(xml::kSchemaAndroid, "targetPackage")) {
|
attr->value = options_.rename_overlay_category.value();
|
||||||
attr->value = options_.rename_overlay_target_package.value();
|
} else {
|
||||||
|
el->attributes.push_back(xml::Attribute{xml::kSchemaAndroid, "category",
|
||||||
|
options_.rename_overlay_category.value()});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ struct ManifestFixerOptions {
|
|||||||
// <overlay>.
|
// <overlay>.
|
||||||
std::optional<std::string> rename_overlay_target_package;
|
std::optional<std::string> rename_overlay_target_package;
|
||||||
|
|
||||||
|
// The category to use instead of the one defined in 'android:category' in <overlay>.
|
||||||
|
std::optional<std::string> rename_overlay_category;
|
||||||
|
|
||||||
// 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.
|
||||||
std::optional<std::string> version_name_default;
|
std::optional<std::string> version_name_default;
|
||||||
|
|||||||
@@ -351,6 +351,54 @@ TEST_F(ManifestFixerTest,
|
|||||||
EXPECT_THAT(attr->value, StrEq("com.android"));
|
EXPECT_THAT(attr->value, StrEq("com.android"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ManifestFixerTest, AddOverlayCategory) {
|
||||||
|
ManifestFixerOptions options;
|
||||||
|
options.rename_overlay_category = std::string("category");
|
||||||
|
|
||||||
|
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, "category");
|
||||||
|
ASSERT_THAT(attr, NotNull());
|
||||||
|
EXPECT_THAT(attr->value, StrEq("category"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ManifestFixerTest, OverrideOverlayCategory) {
|
||||||
|
ManifestFixerOptions options;
|
||||||
|
options.rename_overlay_category = std::string("category");
|
||||||
|
|
||||||
|
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"
|
||||||
|
android:category="yrogetac"/>
|
||||||
|
</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, "category");
|
||||||
|
ASSERT_THAT(attr, NotNull());
|
||||||
|
EXPECT_THAT(attr->value, StrEq("category"));
|
||||||
|
}
|
||||||
|
|
||||||
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