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

Commit 78e0e6aa authored by Ryan Mitchell's avatar Ryan Mitchell Committed by android-build-merger
Browse files

Merge "AAPT2: Insert platformBuild information" into pi-dev

am: 91d2f87d

Change-Id: Ifa673f17cb3ee1ecb146aaafab7c3c71b47f7154
parents bad3bf6c 91d2f87d
Loading
Loading
Loading
Loading
+17 −0
Original line number Original line Diff line number Diff line
@@ -275,6 +275,23 @@ bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor,
                           options_.version_code_default.value()});
                           options_.version_code_default.value()});
      }
      }
    }
    }

    if (el->FindAttribute("", "platformBuildVersionCode") == nullptr) {
      auto versionCode = el->FindAttribute(xml::kSchemaAndroid, "versionCode");
      if (versionCode != nullptr) {
        el->attributes.push_back(xml::Attribute{"", "platformBuildVersionCode",
                                                versionCode->value});
      }
    }

    if (el->FindAttribute("", "platformBuildVersionName") == nullptr) {
      auto versionName = el->FindAttribute(xml::kSchemaAndroid, "versionName");
      if (versionName != nullptr) {
        el->attributes.push_back(xml::Attribute{"", "platformBuildVersionName",
                                                versionName->value});
      }
    }

    return true;
    return true;
  });
  });


+52 −0
Original line number Original line Diff line number Diff line
@@ -556,6 +556,58 @@ TEST_F(ManifestFixerTest, UnexpectedElementsInManifest) {
  ASSERT_THAT(manifest, IsNull());
  ASSERT_THAT(manifest, IsNull());
}
}


TEST_F(ManifestFixerTest, InsertPlatformBuildVersions) {
  // Test for insertion when versionCode and versionName are included in the manifest
  {
    std::string input = R"(
        <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"
          android:versionCode="27" android:versionName="O"/>)";
    std::unique_ptr<xml::XmlResource> manifest = Verify(input);
    ASSERT_THAT(manifest, NotNull());

    xml::Attribute* attr = manifest->root->FindAttribute("", "platformBuildVersionCode");
    ASSERT_THAT(attr, NotNull());
    EXPECT_THAT(attr->value, StrEq("27"));
    attr = manifest->root->FindAttribute("", "platformBuildVersionName");
    ASSERT_THAT(attr, NotNull());
    EXPECT_THAT(attr->value, StrEq("O"));
  }

  // Test for insertion when versionCode and versionName defaults are specified
  {
    std::string input = R"(
      <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"/>)";
    ManifestFixerOptions options;
    options.version_code_default = {"27"};
    options.version_name_default = {"O"};
    std::unique_ptr<xml::XmlResource> manifest = VerifyWithOptions(input, options);
    ASSERT_THAT(manifest, NotNull());

    xml::Attribute* attr = manifest->root->FindAttribute("", "platformBuildVersionCode");
    ASSERT_THAT(attr, NotNull());
    EXPECT_THAT(attr->value, StrEq("27"));
    attr = manifest->root->FindAttribute("", "platformBuildVersionName");
    ASSERT_THAT(attr, NotNull());
    EXPECT_THAT(attr->value, StrEq("O"));
  }

  // Test that the platform build version attributes are not changed if they are currently present
  {
    std::string input = R"(
        <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"
          android:versionCode="28" android:versionName="P"
          platformBuildVersionCode="27" platformBuildVersionName="O"/>)";
    std::unique_ptr<xml::XmlResource> manifest = Verify(input);
    ASSERT_THAT(manifest, NotNull());

    xml::Attribute* attr = manifest->root->FindAttribute("", "platformBuildVersionCode");
    ASSERT_THAT(attr, NotNull());
    EXPECT_THAT(attr->value, StrEq("27"));
    attr = manifest->root->FindAttribute("", "platformBuildVersionName");
    ASSERT_THAT(attr, NotNull());
    EXPECT_THAT(attr->value, StrEq("O"));
  }
}


TEST_F(ManifestFixerTest, UsesLibraryMustHaveNonEmptyName) {
TEST_F(ManifestFixerTest, UsesLibraryMustHaveNonEmptyName) {
  std::string input = R"(
  std::string input = R"(