Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e8a3d4f authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Allow passing in a category override to aapt2" am: 8fbb26bf am: d6c031cc

parents aeafc461 d6c031cc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -270,6 +270,8 @@ class LinkCommand : public Command {
        "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);
    AddOptionalFlag("--rename-overlay-category", "Changes the category for the overlay.",
                    &options_.manifest_fixer_options.rename_overlay_category);
    AddOptionalFlagList("-0", "File suffix not to compress.",
        &options_.extensions_to_not_compress);
    AddOptionalSwitch("--no-compress", "Do not compress any resources.",
+11 −6
Original line number Diff line number Diff line
@@ -449,14 +449,19 @@ bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor,
  manifest_action["attribution"]["inherit-from"];
  manifest_action["original-package"];
  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")) {
    if (options_.rename_overlay_target_package) {
      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 = el->FindAttribute(xml::kSchemaAndroid, "category")) {
        attr->value = options_.rename_overlay_category.value();
      } else {
        el->attributes.push_back(xml::Attribute{xml::kSchemaAndroid, "category",
                                                options_.rename_overlay_category.value()});
      }
    }
    return true;
  });
  manifest_action["protected-broadcast"];
+3 −0
Original line number Diff line number Diff line
@@ -48,6 +48,9 @@ struct ManifestFixerOptions {
  // <overlay>.
  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
  // replace_version is set.
  std::optional<std::string> version_name_default;
+48 −0
Original line number Diff line number Diff line
@@ -351,6 +351,54 @@ TEST_F(ManifestFixerTest,
  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) {
  ManifestFixerOptions options;
  options.version_name_default = std::string("Beta");