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

Commit 76e8b9e7 authored by Jeremy Meyer's avatar Jeremy Meyer
Browse files

Dedup flag disabled values

It is possible for TableMerger::DoMerge() to get called multiple times
for the same flat file. Regular resource values handled this but the
flag disabled ones didn't. This makes it so that we handle flag disabled
ones the same as regular.

This also adds to the dump output so that we print the flag name if
there is one.

Fixes: 419314745
Test: Automated
Flag: EXEMPT bugfix
Change-Id: I0f12b7b391fedf691cff689b0d43a55bf0419524
parent b3a6b793
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -339,6 +339,14 @@ void Debug::PrintTable(const ResourceTable& table, const DebugPrintTableOptions&
            printer->Print("(");
            printer->Print(value->config.to_string());
            printer->Print(") ");
            if (value->value->GetFlag()) {
              printer->Print("(featureFlag=");
              if (value->value->GetFlag()->negated) {
                printer->Print("!");
              }
              printer->Print(value->value->GetFlag()->name);
              printer->Print(") ");
            }
            value->value->Accept(&headline_printer);
            if (options.show_sources && !value->value->GetSource().path.empty()) {
              printer->Print(" src=");
@@ -355,6 +363,12 @@ void Debug::PrintTable(const ResourceTable& table, const DebugPrintTableOptions&
              printer->Print("(");
              printer->Print(value->config.to_string());
              printer->Print(") ");
              printer->Print("(featureFlag=");
              if (value->value->GetFlag()->negated) {
                printer->Print("!");
              }
              printer->Print(value->value->GetFlag()->name);
              printer->Print(") ");
              value->value->Accept(&headline_printer);
              if (options.show_sources && !value->value->GetSource().path.empty()) {
                printer->Print(" src=");
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ struct FeatureFlagAttribute {
  std::string name;
  bool negated = false;

  std::string ToString() {
  std::string ToString() const {
    return (negated ? "!" : "") + name;
  }

+16 −1
Original line number Diff line number Diff line
@@ -247,6 +247,21 @@ ResourceConfigValue* ResourceEntry::FindOrCreateFlagDisabledValue(
  return newValue;
}

ResourceConfigValue* ResourceEntry::FindFlagDisabledValue(const FeatureFlagAttribute& flag,
                                                          const android::ConfigDescription& config,
                                                          android::StringPiece product) {
  auto iter = std::lower_bound(flag_disabled_values.begin(), flag_disabled_values.end(),
                               ConfigFlagKey{&config, product, flag}, lt_config_flag_key_ref());
  if (iter != flag_disabled_values.end()) {
    ResourceConfigValue* value = iter->get();
    const auto& value_flag = value->value->GetFlag().value();
    if (value_flag == flag && value->config == config && value->product == product) {
      return value;
    }
  }
  return nullptr;
}

bool ResourceEntry::HasDefaultValue() const {
  // The default config should be at the top of the list, since the list is sorted.
  return !values.empty() && values.front()->config == ConfigDescription::DefaultConfig();
@@ -271,7 +286,7 @@ ResourceTable::CollisionResult ResourceTable::ResolveFlagCollision(FlagStatus ex
        case FlagStatus::NoFlag:
          return CollisionResult::kTakeNew;
        case FlagStatus::Disabled:
          return CollisionResult::kKeepOriginal;
          return CollisionResult::kConflict;
        case FlagStatus::Enabled:
          return CollisionResult::kTakeNew;
        default:
+4 −0
Original line number Diff line number Diff line
@@ -154,6 +154,10 @@ class ResourceEntry {
                                         android::StringPiece product);
  std::vector<ResourceConfigValue*> FindAllValues(const android::ConfigDescription& config);

  ResourceConfigValue* FindFlagDisabledValue(const FeatureFlagAttribute& flag,
                                             const android::ConfigDescription& config,
                                             android::StringPiece product = {});

  // Either returns the existing ResourceConfigValue in the disabled list with the given flag,
  // config, and product or creates a new one and returns that. In either case the returned value
  // does not have the flag set on the value so it must be set by the caller.
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ class Value {
    flag_ = val;
  }

  std::optional<FeatureFlagAttribute> GetFlag() const {
  const std::optional<FeatureFlagAttribute>& GetFlag() const {
    return flag_;
  }

Loading