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

Commit 78c43d7b authored by Shane Farmer's avatar Shane Farmer
Browse files

AAPT2: Sort artifacts based on the Play Store rules.

Sort output artifacts so that the updated versionCode manifest entry
will allow correct handling of updates from Play Store. The most
important dimension is Android SDK version. It is important that a split
based on min SDK version will allow a user to get a new APK if they
upgrade the OS on their device to support a new split.

ABI splits need to also be taken into consideration as it is possible
for a device to run in ARM emulation mode and installing an ARM APK over
a x86 APK could cause performance regressions.

The XML file format was updated to give each of the configuration groups
have their own section of the XML file. This allows the sort order to be
determined by a groups ordering. Artifacts can now be added to the
configuration file in an arbitrary order. Since this will be the common
case for developers, it will help reduce errors from inserting a new
artifact in the wrong spot.

The implementation follows the rules outlined at:
https://developer.android.com/google/play/publishing/multiple-apks.html

Test: Unit tests
Test: Manual process XML configuration

Change-Id: I0face862c6d6b9d3cd2d99088afe5b9491be0120
parent 39e474f4
Loading
Loading
Loading
Loading
+129 −146
Original line number Diff line number Diff line
@@ -49,13 +49,15 @@ using ::aapt::configuration::AndroidSdk;
using ::aapt::configuration::ConfiguredArtifact;
using ::aapt::configuration::DeviceFeature;
using ::aapt::configuration::Entry;
using ::aapt::configuration::ExtractConfiguration;
using ::aapt::configuration::GlTexture;
using ::aapt::configuration::Group;
using ::aapt::configuration::Locale;
using ::aapt::configuration::OrderedEntry;
using ::aapt::configuration::OutputArtifact;
using ::aapt::configuration::PostProcessingConfiguration;
using ::aapt::configuration::handler::AbiGroupTagHandler;
using ::aapt::configuration::handler::AndroidSdkGroupTagHandler;
using ::aapt::configuration::handler::AndroidSdkTagHandler;
using ::aapt::configuration::handler::ArtifactFormatTagHandler;
using ::aapt::configuration::handler::ArtifactTagHandler;
using ::aapt::configuration::handler::DeviceFeatureGroupTagHandler;
@@ -130,7 +132,7 @@ bool CopyXmlReferences(const Maybe<std::string>& name, const Group<T>& groups,
    return false;
  }

  for (const T& item : group->second) {
  for (const T& item : group->second.entry) {
    target->push_back(item);
  }
  return true;
@@ -188,61 +190,6 @@ xml::XmlNodeAction::ActionFuncWithDiag Bind(configuration::PostProcessingConfigu
  };
}

/** Returns the binary reprasentation of the XML configuration. */
Maybe<PostProcessingConfiguration> ExtractConfiguration(const std::string& contents,
                                                        IDiagnostics* diag) {
  StringInputStream in(contents);
  std::unique_ptr<xml::XmlResource> doc = xml::Inflate(&in, diag, Source("config.xml"));
  if (!doc) {
    return {};
  }

  // Strip any namespaces from the XML as the XmlActionExecutor ignores anything with a namespace.
  Element* root = doc->root.get();
  if (root == nullptr) {
    diag->Error(DiagMessage() << "Could not find the root element in the XML document");
    return {};
  }

  std::string& xml_ns = root->namespace_uri;
  if (!xml_ns.empty()) {
    if (xml_ns != kAaptXmlNs) {
      diag->Error(DiagMessage() << "Unknown namespace found on root element: " << xml_ns);
      return {};
    }

    xml_ns.clear();
    NamespaceVisitor visitor;
    root->Accept(&visitor);
  }

  XmlActionExecutor executor;
  XmlNodeAction& root_action = executor["post-process"];
  XmlNodeAction& artifacts_action = root_action["artifacts"];
  XmlNodeAction& groups_action = root_action["groups"];

  PostProcessingConfiguration config;

  // Parse the artifact elements.
  artifacts_action["artifact"].Action(Bind(&config, ArtifactTagHandler));
  artifacts_action["artifact-format"].Action(Bind(&config, ArtifactFormatTagHandler));

  // Parse the different configuration groups.
  groups_action["abi-group"].Action(Bind(&config, AbiGroupTagHandler));
  groups_action["screen-density-group"].Action(Bind(&config, ScreenDensityGroupTagHandler));
  groups_action["locale-group"].Action(Bind(&config, LocaleGroupTagHandler));
  groups_action["android-sdk-group"].Action(Bind(&config, AndroidSdkGroupTagHandler));
  groups_action["gl-texture-group"].Action(Bind(&config, GlTextureGroupTagHandler));
  groups_action["device-feature-group"].Action(Bind(&config, DeviceFeatureGroupTagHandler));

  if (!executor.Execute(XmlActionExecutorPolicy::kNone, diag, doc.get())) {
    diag->Error(DiagMessage() << "Could not process XML document");
    return {};
  }

  return {config};
}

/** Converts a ConfiguredArtifact into an OutputArtifact. */
Maybe<OutputArtifact> ToOutputArtifact(const ConfiguredArtifact& artifact,
                                       const std::string& apk_name,
@@ -302,11 +249,11 @@ Maybe<OutputArtifact> ToOutputArtifact(const ConfiguredArtifact& artifact,
    has_errors = true;
  }

  if (artifact.android_sdk_group) {
    auto entry = config.android_sdk_groups.find(artifact.android_sdk_group.value());
    if (entry == config.android_sdk_groups.end()) {
  if (artifact.android_sdk) {
    auto entry = config.android_sdks.find(artifact.android_sdk.value());
    if (entry == config.android_sdks.end()) {
      src_diag.Error(DiagMessage() << "Could not lookup required Android SDK version: "
                                   << artifact.android_sdk_group.value());
                                   << artifact.android_sdk.value());
      has_errors = true;
    } else {
      output_artifact.android_sdk = {entry->second};
@@ -323,6 +270,64 @@ Maybe<OutputArtifact> ToOutputArtifact(const ConfiguredArtifact& artifact,

namespace configuration {

/** Returns the binary reprasentation of the XML configuration. */
Maybe<PostProcessingConfiguration> ExtractConfiguration(const std::string& contents,
                                                        const std::string& config_path,
                                                        IDiagnostics* diag) {
  StringInputStream in(contents);
  std::unique_ptr<xml::XmlResource> doc = xml::Inflate(&in, diag, Source(config_path));
  if (!doc) {
    return {};
  }

  // Strip any namespaces from the XML as the XmlActionExecutor ignores anything with a namespace.
  Element* root = doc->root.get();
  if (root == nullptr) {
    diag->Error(DiagMessage() << "Could not find the root element in the XML document");
    return {};
  }

  std::string& xml_ns = root->namespace_uri;
  if (!xml_ns.empty()) {
    if (xml_ns != kAaptXmlNs) {
      diag->Error(DiagMessage() << "Unknown namespace found on root element: " << xml_ns);
      return {};
    }

    xml_ns.clear();
    NamespaceVisitor visitor;
    root->Accept(&visitor);
  }

  XmlActionExecutor executor;
  XmlNodeAction& root_action = executor["post-process"];
  XmlNodeAction& artifacts_action = root_action["artifacts"];

  PostProcessingConfiguration config;

  // Parse the artifact elements.
  artifacts_action["artifact"].Action(Bind(&config, ArtifactTagHandler));
  artifacts_action["artifact-format"].Action(Bind(&config, ArtifactFormatTagHandler));

  // Parse the different configuration groups.
  root_action["abi-groups"]["abi-group"].Action(Bind(&config, AbiGroupTagHandler));
  root_action["screen-density-groups"]["screen-density-group"].Action(
      Bind(&config, ScreenDensityGroupTagHandler));
  root_action["locale-groups"]["locale-group"].Action(Bind(&config, LocaleGroupTagHandler));
  root_action["android-sdks"]["android-sdk"].Action(Bind(&config, AndroidSdkTagHandler));
  root_action["gl-texture-groups"]["gl-texture-group"].Action(
      Bind(&config, GlTextureGroupTagHandler));
  root_action["device-feature-groups"]["device-feature-group"].Action(
      Bind(&config, DeviceFeatureGroupTagHandler));

  if (!executor.Execute(XmlActionExecutorPolicy::kNone, diag, doc.get())) {
    diag->Error(DiagMessage() << "Could not process XML document");
    return {};
  }

  return {config};
}

const StringPiece& AbiToString(Abi abi) {
  return kAbiToStringMap.at(static_cast<size_t>(abi));
}
@@ -383,7 +388,7 @@ Maybe<std::string> ConfiguredArtifact::ToArtifactName(const StringPiece& format,
    return {};
  }

  if (!ReplacePlaceholder("${sdk}", android_sdk_group, &result, diag)) {
  if (!ReplacePlaceholder("${sdk}", android_sdk, &result, diag)) {
    return {};
  }

@@ -414,47 +419,37 @@ Maybe<ConfigurationParser> ConfigurationParser::ForPath(const std::string& path)
  if (!ReadFileToString(path, &contents, true)) {
    return {};
  }
  return ConfigurationParser(contents);
  return ConfigurationParser(contents, path);
}

ConfigurationParser::ConfigurationParser(std::string contents)
    : contents_(std::move(contents)),
      diag_(&noop_) {
ConfigurationParser::ConfigurationParser(std::string contents, const std::string& config_path)
    : contents_(std::move(contents)), config_path_(config_path), diag_(&noop_) {
}

Maybe<std::vector<OutputArtifact>> ConfigurationParser::Parse(
    const android::StringPiece& apk_path) {
  Maybe<PostProcessingConfiguration> maybe_config = ExtractConfiguration(contents_, diag_);
  Maybe<PostProcessingConfiguration> maybe_config =
      ExtractConfiguration(contents_, config_path_, diag_);
  if (!maybe_config) {
    return {};
  }
  const PostProcessingConfiguration& config = maybe_config.value();

  // TODO: Automatically arrange artifacts so that they match Play Store multi-APK requirements.
  // see: https://developer.android.com/google/play/publishing/multiple-apks.html
  //
  // For now, make sure the version codes are unique.
  std::vector<ConfiguredArtifact> artifacts = config.artifacts;
  std::sort(artifacts.begin(), artifacts.end());
  if (std::adjacent_find(artifacts.begin(), artifacts.end()) != artifacts.end()) {
    diag_->Error(DiagMessage() << "Configuration has duplicate versions");
    return {};
  }

  const std::string& apk_name = file::GetFilename(apk_path).to_string();
  const StringPiece ext = file::GetExtension(apk_name);
  const std::string base_name = apk_name.substr(0, apk_name.size() - ext.size());

  // Convert from a parsed configuration to a list of artifacts for processing.
  const std::string& apk_name = file::GetFilename(apk_path).to_string();
  std::vector<OutputArtifact> output_artifacts;
  bool has_errors = false;

  for (const ConfiguredArtifact& artifact : artifacts) {
  PostProcessingConfiguration& config = maybe_config.value();
  config.SortArtifacts();

  int version = 1;
  for (const ConfiguredArtifact& artifact : config.artifacts) {
    Maybe<OutputArtifact> output_artifact = ToOutputArtifact(artifact, apk_name, config, diag_);
    if (!output_artifact) {
      // Defer return an error condition so that all errors are reported.
      has_errors = true;
    } else {
      output_artifact.value().version = version++;
      output_artifacts.push_back(std::move(output_artifact.value()));
    }
  }
@@ -470,24 +465,18 @@ namespace handler {

bool ArtifactTagHandler(PostProcessingConfiguration* config, Element* root_element,
                        IDiagnostics* diag) {
  // This will be incremented later so the first version will always be different to the base APK.
  int current_version = (config->artifacts.empty()) ? 0 : config->artifacts.back().version;

  ConfiguredArtifact artifact{};
  Maybe<int> version;
  for (const auto& attr : root_element->attributes) {
    if (attr.name == "name") {
      artifact.name = attr.value;
    } else if (attr.name == "version") {
      version = std::stoi(attr.value);
    } else if (attr.name == "abi-group") {
      artifact.abi_group = {attr.value};
    } else if (attr.name == "screen-density-group") {
      artifact.screen_density_group = {attr.value};
    } else if (attr.name == "locale-group") {
      artifact.locale_group = {attr.value};
    } else if (attr.name == "android-sdk-group") {
      artifact.android_sdk_group = {attr.value};
    } else if (attr.name == "android-sdk") {
      artifact.android_sdk = {attr.value};
    } else if (attr.name == "gl-texture-group") {
      artifact.gl_texture_group = {attr.value};
    } else if (attr.name == "device-feature-group") {
@@ -497,9 +486,6 @@ bool ArtifactTagHandler(PostProcessingConfiguration* config, Element* root_eleme
                               << attr.value);
    }
  }

  artifact.version = (version) ? version.value() : current_version + 1;

  config->artifacts.push_back(artifact);
  return true;
};
@@ -523,7 +509,7 @@ bool AbiGroupTagHandler(PostProcessingConfiguration* config, Element* root_eleme
    return false;
  }

  auto& group = config->abi_groups[label];
  auto& group = GetOrCreateGroup(label, &config->abi_groups);
  bool valid = true;

  // Special case for empty abi-group tag. Label will be used as the ABI.
@@ -567,7 +553,7 @@ bool ScreenDensityGroupTagHandler(PostProcessingConfiguration* config, Element*
    return false;
  }

  auto& group = config->screen_density_groups[label];
  auto& group = GetOrCreateGroup(label, &config->screen_density_groups);
  bool valid = true;

  // Special case for empty screen-density-group tag. Label will be used as the screen density.
@@ -627,7 +613,7 @@ bool LocaleGroupTagHandler(PostProcessingConfiguration* config, Element* root_el
    return false;
  }

  auto& group = config->locale_groups[label];
  auto& group = GetOrCreateGroup(label, &config->locale_groups);
  bool valid = true;

  // Special case to auto insert a locale for an empty group. Label will be used for locale.
@@ -680,44 +666,48 @@ bool LocaleGroupTagHandler(PostProcessingConfiguration* config, Element* root_el
  return valid;
};

bool AndroidSdkGroupTagHandler(PostProcessingConfiguration* config, Element* root_element,
bool AndroidSdkTagHandler(PostProcessingConfiguration* config, Element* root_element,
                          IDiagnostics* diag) {
  std::string label = GetLabel(root_element, diag);
  if (label.empty()) {
    return false;
  }

  AndroidSdk entry = AndroidSdk::ForMinSdk(-1);
  bool valid = true;
  bool found = false;

  for (auto* child : root_element->GetChildElements()) {
    if (child->name != "android-sdk") {
      diag->Error(DiagMessage() << "Unexpected root_element in ABI group: " << child->name);
      valid = false;
    } else {
      AndroidSdk entry;
      for (const auto& attr : child->attributes) {
        Maybe<int>* target = nullptr;
        if (attr.name == "minSdkVersion") {
          target = &entry.min_sdk_version;
  for (const auto& attr : root_element->attributes) {
    bool valid_attr = false;
    if (attr.name == "label") {
      entry.label = attr.value;
      valid_attr = true;
    } else if (attr.name == "minSdkVersion") {
      Maybe<int> version = ResourceUtils::ParseSdkVersion(attr.value);
      if (version) {
        valid_attr = true;
        entry.min_sdk_version = version.value();
      }
    } else if (attr.name == "targetSdkVersion") {
          target = &entry.target_sdk_version;
      Maybe<int> version = ResourceUtils::ParseSdkVersion(attr.value);
      if (version) {
        valid_attr = true;
        entry.target_sdk_version = version;
      }
    } else if (attr.name == "maxSdkVersion") {
          target = &entry.max_sdk_version;
        } else {
          diag->Warn(DiagMessage() << "Unknown attribute: " << attr.name << " = " << attr.value);
          continue;
      Maybe<int> version = ResourceUtils::ParseSdkVersion(attr.value);
      if (version) {
        valid_attr = true;
        entry.max_sdk_version = version;
      }
    }

        *target = ResourceUtils::ParseSdkVersion(attr.value);
        if (!*target) {
    if (!valid_attr) {
      diag->Error(DiagMessage() << "Invalid attribute: " << attr.name << " = " << attr.value);
      valid = false;
    }
  }

  if (entry.min_sdk_version == -1) {
    diag->Error(DiagMessage() << "android-sdk is missing minSdkVersion attribute");
    valid = false;
  }

  // TODO: Fill in the manifest details when they are finalised.
      for (auto node : child->GetChildElements()) {
  for (auto node : root_element->GetChildElements()) {
    if (node->name == "manifest") {
      if (entry.manifest) {
        diag->Warn(DiagMessage() << "Found multiple manifest tags. Ignoring duplicates.");
@@ -727,14 +717,7 @@ bool AndroidSdkGroupTagHandler(PostProcessingConfiguration* config, Element* roo
    }
  }

      config->android_sdk_groups[label] = entry;
      if (found) {
        valid = false;
      }
      found = true;
    }
  }

  config->android_sdks[entry.label] = entry;
  return valid;
};

@@ -745,7 +728,7 @@ bool GlTextureGroupTagHandler(PostProcessingConfiguration* config, Element* root
    return false;
  }

  auto& group = config->gl_texture_groups[label];
  auto& group = GetOrCreateGroup(label, &config->gl_texture_groups);
  bool valid = true;

  GlTexture result;
@@ -788,7 +771,7 @@ bool DeviceFeatureGroupTagHandler(PostProcessingConfiguration* config, Element*
    return false;
  }

  auto& group = config->device_feature_groups[label];
  auto& group = GetOrCreateGroup(label, &config->device_feature_groups);
  bool valid = true;

  for (auto* child : root_element->GetChildElements()) {
+14 −7
Original line number Diff line number Diff line
@@ -71,7 +71,8 @@ struct AndroidManifest {
};

struct AndroidSdk {
  Maybe<int> min_sdk_version;
  std::string label;
  int min_sdk_version;  // min_sdk_version is mandatory if splitting by SDK.
  Maybe<int> target_sdk_version;
  Maybe<int> max_sdk_version;
  Maybe<AndroidManifest> manifest;
@@ -113,15 +114,19 @@ struct OutputArtifact {
  Maybe<AndroidSdk> android_sdk;
  std::vector<DeviceFeature> features;
  std::vector<GlTexture> textures;

  inline int GetMinSdk(int default_value = -1) const {
    if (!android_sdk) {
      return default_value;
    }
    return android_sdk.value().min_sdk_version;
  }
};

}  // namespace configuration

// Forward declaration of classes used in the API.
struct IDiagnostics;
namespace xml {
class Element;
}

/**
 * XML configuration file parser for the split and optimize commands.
@@ -133,8 +138,8 @@ class ConfigurationParser {
  static Maybe<ConfigurationParser> ForPath(const std::string& path);

  /** Returns a ConfigurationParser for the configuration in the provided file contents. */
  static ConfigurationParser ForContents(const std::string& contents) {
    ConfigurationParser parser{contents};
  static ConfigurationParser ForContents(const std::string& contents, const std::string& path) {
    ConfigurationParser parser{contents, path};
    return parser;
  }

@@ -156,7 +161,7 @@ class ConfigurationParser {
   * diagnostics context. The default diagnostics context can be overridden with a call to
   * WithDiagnostics(IDiagnostics *).
   */
  explicit ConfigurationParser(std::string contents);
  ConfigurationParser(std::string contents, const std::string& config_path);

  /** Returns the current diagnostics context to any subclasses. */
  IDiagnostics* diagnostics() {
@@ -166,6 +171,8 @@ class ConfigurationParser {
 private:
  /** The contents of the configuration file to parse. */
  const std::string contents_;
  /** Path to the input configuration. */
  const std::string config_path_;
  /** The diagnostics context to send messages to. */
  IDiagnostics* diag_;
};
+133 −23
Original line number Diff line number Diff line
@@ -17,35 +17,105 @@
#ifndef AAPT2_CONFIGURATIONPARSER_INTERNAL_H
#define AAPT2_CONFIGURATIONPARSER_INTERNAL_H

#include "configuration/ConfigurationParser.h"

#include <algorithm>
#include <limits>

namespace aapt {

// Forward declaration of classes used in the API.
namespace xml {
class Element;
}

namespace configuration {

template <typename T>
struct OrderedEntry {
  size_t order;
  std::vector<T> entry;
};

/** A mapping of group labels to group of configuration items. */
template <class T>
using Group = std::unordered_map<std::string, std::vector<T>>;
using Group = std::unordered_map<std::string, OrderedEntry<T>>;

/** A mapping of group label to a single configuration item. */
template <class T>
using Entry = std::unordered_map<std::string, T>;

/** Retrieves an entry from the provided Group, creating a new instance if one does not exist. */
template <typename T>
std::vector<T>& GetOrCreateGroup(std::string label, Group<T>* group) {
  OrderedEntry<T>& entry = (*group)[label];
  // If this is a new entry, set the order.
  if (entry.order == 0) {
    entry.order = group->size();
  }
  return entry.entry;
}

/**
 * A ComparisonChain is a grouping of comparisons to perform when sorting groups that have a well
 * defined order of precedence. Comparisons are only made if none of the previous comparisons had a
 * definite result. A comparison has a result if at least one of the items has an entry for that
 * value and that they are not equal.
 */
class ComparisonChain {
 public:
  /**
   * Adds a new comparison of items in a group to the chain. The new comparison is only used if we
   * have not been able to determine the sort order with the previous comparisons.
   */
  template <typename T>
  ComparisonChain& Add(const Group<T>& groups, const Maybe<std::string>& lhs,
                       const Maybe<std::string>& rhs) {
    return Add(GetGroupOrder(groups, lhs), GetGroupOrder(groups, rhs));
  }

  /**
   * Adds a new comparison to the chain. The new comparison is only used if we have not been able to
   * determine the sort order with the previous comparisons.
   */
  ComparisonChain& Add(int lhs, int rhs) {
    if (!has_result_) {
      has_result_ = (lhs != rhs);
      result_ = (lhs < rhs);
    }
    return *this;
  }

  /** Returns true if the left hand side should come before the right hand side. */
  bool Compare() {
    return result_;
  }

 private:
  template <typename T>
  inline size_t GetGroupOrder(const Group<T>& groups, const Maybe<std::string>& label) {
    if (!label) {
      return std::numeric_limits<size_t>::max();
    }
    return groups.at(label.value()).order;
  }

  bool has_result_ = false;
  bool result_ = false;
};

/** Output artifact configuration options. */
struct ConfiguredArtifact {
  /** Name to use for output of processing foo.apk -> foo.<name>.apk. */
  Maybe<std::string> name;
  /**
   * Value to add to the base Android manifest versionCode. If it is not present in the
   * configuration file, it is set to the previous artifact + 1. If the first artifact does not have
   * a value, artifacts are a 1 based index.
   */
  int version;
  /** If present, uses the ABI group with this name. */
  Maybe<std::string> abi_group;
  /** If present, uses the screen density group with this name. */
  Maybe<std::string> screen_density_group;
  /** If present, uses the locale group with this name. */
  Maybe<std::string> locale_group;
  /** If present, uses the Android SDK group with this name. */
  Maybe<std::string> android_sdk_group;
  /** If present, uses the Android SDK with this name. */
  Maybe<std::string> android_sdk;
  /** If present, uses the device feature group with this name. */
  Maybe<std::string> device_feature_group;
  /** If present, uses the OpenGL texture group with this name. */
@@ -57,31 +127,71 @@ struct ConfiguredArtifact {

  /** Convert an artifact name template into a name string based on configuration contents. */
  Maybe<std::string> Name(const android::StringPiece& apk_name, IDiagnostics* diag) const;

  bool operator<(const ConfiguredArtifact& rhs) const {
    // TODO(safarmer): Order by play store multi-APK requirements.
    return version < rhs.version;
  }

  bool operator==(const ConfiguredArtifact& rhs) const {
    return version == rhs.version;
  }
};

/** AAPT2 XML configuration file binary representation. */
struct PostProcessingConfiguration {
  // TODO: Support named artifacts?
  std::vector<ConfiguredArtifact> artifacts;
  Maybe<std::string> artifact_format;

  Group<Abi> abi_groups;
  Group<ConfigDescription> screen_density_groups;
  Group<ConfigDescription> locale_groups;
  Entry<AndroidSdk> android_sdk_groups;
  Group<DeviceFeature> device_feature_groups;
  Group<GlTexture> gl_texture_groups;
  Entry<AndroidSdk> android_sdks;

  /**
   * Sorts the configured artifacts based on the ordering of the groups in the configuration file.
   * The only exception to this rule is Android SDK versions. Larger SDK versions will have a larger
   * versionCode to ensure users get the correct APK when they upgrade their OS.
   */
  void SortArtifacts() {
    std::sort(artifacts.begin(), artifacts.end(), *this);
  }

  /** Comparator that ensures artifacts are in the preferred order for versionCode rewriting. */
  bool operator()(const ConfiguredArtifact& lhs, const ConfiguredArtifact& rhs) {
    // Split dimensions are added in the order of precedence. Items higher in the list result in
    // higher version codes.
    return ComparisonChain()
        // All splits with a minSdkVersion specified must be last to ensure the application will be
        // updated if a user upgrades the version of Android on their device.
        .Add(GetMinSdk(lhs), GetMinSdk(rhs))
        // ABI version is important, especially on x86 phones where they may begin to run in ARM
        // emulation mode on newer Android versions. This allows us to ensure that the x86 version
        // is installed on these devices rather than ARM.
        .Add(abi_groups, lhs.abi_group, rhs.abi_group)
        // The rest are in arbitrary order based on estimated usage.
        .Add(screen_density_groups, lhs.screen_density_group, rhs.screen_density_group)
        .Add(locale_groups, lhs.locale_group, rhs.locale_group)
        .Add(gl_texture_groups, lhs.gl_texture_group, rhs.gl_texture_group)
        .Add(device_feature_groups, lhs.device_feature_group, rhs.device_feature_group)
        .Compare();
  }

 private:
  /**
   * Returns the min_sdk_version from the provided artifact or 0 if none is present. This allows
   * artifacts that have an Android SDK version to have a higher versionCode than those that do not.
   */
  inline int GetMinSdk(const ConfiguredArtifact& artifact) {
    if (!artifact.android_sdk) {
      return 0;
    }
    const auto& entry = android_sdks.find(artifact.android_sdk.value());
    if (entry == android_sdks.end()) {
      return 0;
    }
    return entry->second.min_sdk_version;
  }
};

/** Parses the provided XML document returning the post processing configuration. */
Maybe<PostProcessingConfiguration> ExtractConfiguration(const std::string& contents,
                                                        const std::string& config_path,
                                                        IDiagnostics* diag);

namespace handler {

/** Handler for <artifact> tags. */
@@ -104,9 +214,9 @@ bool ScreenDensityGroupTagHandler(configuration::PostProcessingConfiguration* co
bool LocaleGroupTagHandler(configuration::PostProcessingConfiguration* config,
                           xml::Element* element, IDiagnostics* diag);

/** Handler for <android-sdk-group> tags. */
bool AndroidSdkGroupTagHandler(configuration::PostProcessingConfiguration* config,
                               xml::Element* element, IDiagnostics* diag);
/** Handler for <android-sdk> tags. */
bool AndroidSdkTagHandler(configuration::PostProcessingConfiguration* config, xml::Element* element,
                          IDiagnostics* diag);

/** Handler for <gl-texture-group> tags. */
bool GlTextureGroupTagHandler(configuration::PostProcessingConfiguration* config,
+242 −180

File changed.

Preview size limit exceeded, changes collapsed.

+40 −18

File changed.

Preview size limit exceeded, changes collapsed.

Loading