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

Commit caff40ca authored by Ryan Mitchell's avatar Ryan Mitchell Committed by Automerger Merge Worker
Browse files

Merge "Fix DominatorTree for locale and mcc/mnc config" am: 8f2f4e14

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1481918

Change-Id: Iedf0fcdd24fa9ec3ff5ebb3124f9fd12acbbfeec
parents 76bcea65 8f2f4e14
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -887,13 +887,16 @@ bool ConfigDescription::Dominates(const ConfigDescription& o) const {
  }

  // Locale de-duping is not-trivial, disable for now (b/62409213).
  if (diff(o) & CONFIG_LOCALE) {
  // We must also disable de-duping for all configuration qualifiers with precedence higher than
  // locale (b/171892595)
  if (diff(o) & (CONFIG_LOCALE | CONFIG_MCC | CONFIG_MNC)) {
    return false;
  }

  if (*this == DefaultConfig()) {
    return true;
  }

  return MatchWithDensity(o) && !o.MatchWithDensity(*this) &&
         !isMoreSpecificThan(o) && !o.HasHigherPrecedenceThan(*this);
}
+28 −0
Original line number Diff line number Diff line
@@ -198,5 +198,33 @@ TEST(DominatorTreeTest, NonZeroDensitiesMatch) {
  EXPECT_EQ(expected, printer.ToString(&tree));
}

TEST(DominatorTreeTest, MccMncIsPeertoLocale) {
  const ConfigDescription default_config = {};
  const ConfigDescription de_config = test::ParseConfigOrDie("de");
  const ConfigDescription fr_config = test::ParseConfigOrDie("fr");
  const ConfigDescription mcc_config = test::ParseConfigOrDie("mcc262");
  const ConfigDescription mcc_fr_config = test::ParseConfigOrDie("mcc262-fr");
  const ConfigDescription mnc_config = test::ParseConfigOrDie("mnc2");
  const ConfigDescription mnc_fr_config = test::ParseConfigOrDie("mnc2-fr");
  std::vector<std::unique_ptr<ResourceConfigValue>> configs;
  configs.push_back(util::make_unique<ResourceConfigValue>(default_config, ""));
  configs.push_back(util::make_unique<ResourceConfigValue>(de_config, ""));
  configs.push_back(util::make_unique<ResourceConfigValue>(fr_config, ""));
  configs.push_back(util::make_unique<ResourceConfigValue>(mcc_config, ""));
  configs.push_back(util::make_unique<ResourceConfigValue>(mcc_fr_config, ""));
  configs.push_back(util::make_unique<ResourceConfigValue>(mnc_config, ""));
  configs.push_back(util::make_unique<ResourceConfigValue>(mnc_fr_config, ""));
  DominatorTree tree(configs);
  PrettyPrinter printer;
  std::string expected =
      "<default>\n"
      "de\n"
      "fr\n"
      "mcc262\n"
      "mcc262-fr\n"
      "mnc2\n"
      "mnc2-fr\n";
  EXPECT_EQ(expected, printer.ToString(&tree));
}

}  // namespace aapt
+22 −0
Original line number Diff line number Diff line
@@ -52,9 +52,11 @@ TEST(ResourceDeduperTest, SameValuesAreDeduped) {
          .Build();

  ASSERT_TRUE(ResourceDeduper().Consume(context.get(), table.get()));
  EXPECT_THAT(table, HasValue("android:string/dedupe", default_config));
  EXPECT_THAT(table, Not(HasValue("android:string/dedupe", ldrtl_config)));
  EXPECT_THAT(table, Not(HasValue("android:string/dedupe", land_config)));

  EXPECT_THAT(table, HasValue("android:string/dedupe2", default_config));
  EXPECT_THAT(table, HasValue("android:string/dedupe2", ldrtl_v21_config));
  EXPECT_THAT(table, Not(HasValue("android:string/dedupe2", ldrtl_config)));

@@ -151,4 +153,24 @@ TEST(ResourceDeduperTest, LocalesValuesAreKept) {
  EXPECT_THAT(table, HasValue("android:string/keep", fr_rCA_config));
}

TEST(ResourceDeduperTest, MccMncValuesAreKept) {
  std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
  const ConfigDescription default_config = {};
  const ConfigDescription mcc_config = test::ParseConfigOrDie("mcc262");
  const ConfigDescription mnc_config = test::ParseConfigOrDie("mnc2");

  std::unique_ptr<ResourceTable> table =
      test::ResourceTableBuilder()
          .AddString("android:string/keep", ResourceId{}, default_config, "keep")
          .AddString("android:string/keep", ResourceId{}, mcc_config, "keep")
          .AddString("android:string/keep", ResourceId{}, mnc_config, "keep")
          .Build();

  ASSERT_TRUE(ResourceDeduper().Consume(context.get(), table.get()));
  EXPECT_THAT(table, HasValue("android:string/keep", default_config));
  EXPECT_THAT(table, HasValue("android:string/keep", mcc_config));
  EXPECT_THAT(table, HasValue("android:string/keep", mnc_config));
}


}  // namespace aapt