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

Commit 16c83afa authored by Jeremy Meyer's avatar Jeremy Meyer
Browse files

Remove flag disabled strings from string pool

Test: Automated
Bug: 329436914
Flag: EXEMPT Aconfig not supported on host tools

Change-Id: I627feff5774f44a398a8337733498ede601d07a4
parent 14bf1787
Loading
Loading
Loading
Loading
+1 −49
Original line number Diff line number Diff line
@@ -22,54 +22,6 @@ package {
    default_team: "trendy_team_android_resources",
}

genrule {
    name: "resource-flagging-test-app-resources-compile",
    tools: ["aapt2"],
    srcs: [
        "flagged_resources_res/values/bools.xml",
    ],
    out: ["values_bools.arsc.flat"],
    cmd: "$(location aapt2) compile $(in) -o $(genDir) " +
        "--feature-flags test.package.falseFlag:ro=false,test.package.trueFlag:ro=true",
}

genrule {
    name: "resource-flagging-test-app-resources-compile2",
    tools: ["aapt2"],
    srcs: [
        "flagged_resources_res/values/bools2.xml",
    ],
    out: ["values_bools2.arsc.flat"],
    cmd: "$(location aapt2) compile $(in) -o $(genDir) " +
        "--feature-flags test.package.falseFlag:ro=false,test.package.trueFlag:ro=true",
}

genrule {
    name: "resource-flagging-test-app-apk",
    tools: ["aapt2"],
    // The first input file in the list must be the manifest
    srcs: [
        "TestAppAndroidManifest.xml",
        ":resource-flagging-test-app-resources-compile",
        ":resource-flagging-test-app-resources-compile2",
    ],
    out: ["resapp.apk"],
    cmd: "$(location aapt2) link -o $(out) --manifest $(in)",
}

java_genrule {
    name: "resource-flagging-apk-as-resource",
    srcs: [
        ":resource-flagging-test-app-apk",
    ],
    out: ["apks_as_resources.res.zip"],
    tools: ["soong_zip"],

    cmd: "mkdir -p $(genDir)/res/raw && " +
        "cp $(in) $(genDir)/res/raw/$$(basename $(in)) && " +
        "$(location soong_zip) -o $(out) -C $(genDir)/res -D $(genDir)/res",
}

android_test {
    name: "ResourceFlaggingTests",
    srcs: [
@@ -82,6 +34,6 @@ android_test {
        "testng",
        "compatibility-device-util-axt",
    ],
    resource_zips: [":resource-flagging-apk-as-resource"],
    resource_zips: [":resource-flagging-test-app-apk-as-resource"],
    test_suites: ["device-tests"],
}
+18 −1
Original line number Diff line number Diff line
@@ -68,12 +68,29 @@ public class ResourceFlaggingTest {
        assertThat(getBoolean("res3")).isTrue();
    }

    @Test
    public void testFlagDisabledNoValue() {
        assertThat(getString("str1")).isEqualTo("");
    }

    private boolean getBoolean(String name) {
        int resId = mResources.getIdentifier(name, "bool", "com.android.intenal.flaggedresources");
        int resId = mResources.getIdentifier(
                name,
                "bool",
                "com.android.intenal.flaggedresources");
        assertThat(resId).isNotEqualTo(0);
        return mResources.getBoolean(resId);
    }

    private String getString(String name) {
        int resId = mResources.getIdentifier(
                name,
                "string",
                "com.android.intenal.flaggedresources");
        assertThat(resId).isNotEqualTo(0);
        return mResources.getString(resId);
    }

    private String extractApkAndGetPath(int id) throws Exception {
        final Resources resources = mContext.getResources();
        try (InputStream is = resources.openRawResource(id)) {
+1 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ cc_test_host {
        "integration-tests/CommandTests/**/*",
        "integration-tests/ConvertTest/**/*",
        "integration-tests/DumpTest/**/*",
        ":resource-flagging-test-app-apk",
    ],
}

+1 −3
Original line number Diff line number Diff line
@@ -690,9 +690,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
        resource_format = item_iter->second.format;
      }

      // Don't bother parsing the item if it is behind a disabled flag
      if (out_resource->flag_status != FlagStatus::Disabled &&
          !ParseItem(parser, out_resource, resource_format)) {
      if (!ParseItem(parser, out_resource, resource_format)) {
        return false;
      }
      return true;
+2 −20
Original line number Diff line number Diff line
@@ -69,13 +69,8 @@ class ResourceParserTest : public ::testing::Test {
    return TestParse(str, ConfigDescription{});
  }

  ::testing::AssertionResult TestParse(StringPiece str, ResourceParserOptions parserOptions) {
    return TestParse(str, ConfigDescription{}, parserOptions);
  }

  ::testing::AssertionResult TestParse(
      StringPiece str, const ConfigDescription& config,
      ResourceParserOptions parserOptions = ResourceParserOptions()) {
  ::testing::AssertionResult TestParse(StringPiece str, const ConfigDescription& config) {
    ResourceParserOptions parserOptions;
    ResourceParser parser(context_->GetDiagnostics(), &table_, android::Source{"test"}, config,
                          parserOptions);

@@ -247,19 +242,6 @@ TEST_F(ResourceParserTest, ParseStringTranslatableAttribute) {
  EXPECT_FALSE(TestParse(R"(<string name="foo4" translatable="yes">Translate</string>)"));
}

TEST_F(ResourceParserTest, ParseStringBehindDisabledFlag) {
  FeatureFlagProperties flag_properties(true, false);
  ResourceParserOptions options;
  options.feature_flag_values = {{"falseFlag", flag_properties}};
  ASSERT_TRUE(TestParse(
      R"(<string name="foo" android:featureFlag="falseFlag"
              xmlns:android="http://schemas.android.com/apk/res/android">foo</string>)",
      options));

  String* str = test::GetValue<String>(&table_, "string/foo");
  ASSERT_THAT(str, IsNull());
}

TEST_F(ResourceParserTest, IgnoreXliffTagsOtherThanG) {
  std::string input = R"(
      <string name="foo" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
Loading