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

Commit 8dc2dd5d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Dedup flag disabled values" into main

parents 55acb30c 76e8b9e7
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