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

Commit 668ec5bd authored by Mårten Kongstad's avatar Mårten Kongstad Committed by Todd Kennedy
Browse files

AssetManager2: optionally keep non-matching configs

AssetManager2 maintains a set of configurations [as specified in the
resource blob] compatible with the currently set configuration [as
specified via SetConfiguration]. This helps optimize future resource
lookups by limiting the set of configurations to iterate over.

However, when creating idmaps, all configurations must be considered,
including those not compatible with the currently set configuration. Add
an optional flag to SetApkAssets to disable the optimization described
above.

Test: manual (will be tested by upcoming idmap2 implementation)
Change-Id: I7526a323ddf90e2f2f49c36e8c110a2cec25357e
parent f99eda45
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -67,10 +67,10 @@ AssetManager2::AssetManager2() {
}
}


bool AssetManager2::SetApkAssets(const std::vector<const ApkAssets*>& apk_assets,
bool AssetManager2::SetApkAssets(const std::vector<const ApkAssets*>& apk_assets,
                                 bool invalidate_caches) {
                                 bool invalidate_caches, bool filter_incompatible_configs) {
  apk_assets_ = apk_assets;
  apk_assets_ = apk_assets;
  BuildDynamicRefTable();
  BuildDynamicRefTable();
  RebuildFilterList();
  RebuildFilterList(filter_incompatible_configs);
  if (invalidate_caches) {
  if (invalidate_caches) {
    InvalidateCaches(static_cast<uint32_t>(-1));
    InvalidateCaches(static_cast<uint32_t>(-1));
  }
  }
@@ -825,7 +825,7 @@ uint32_t AssetManager2::GetResourceId(const std::string& resource_name,
  return 0u;
  return 0u;
}
}


void AssetManager2::RebuildFilterList() {
void AssetManager2::RebuildFilterList(bool filter_incompatible_configs) {
  for (PackageGroup& group : package_groups_) {
  for (PackageGroup& group : package_groups_) {
    for (ConfiguredPackage& impl : group.packages_) {
    for (ConfiguredPackage& impl : group.packages_) {
      // Destroy it.
      // Destroy it.
@@ -841,7 +841,7 @@ void AssetManager2::RebuildFilterList() {
        for (auto iter = spec->types; iter != iter_end; ++iter) {
        for (auto iter = spec->types; iter != iter_end; ++iter) {
          ResTable_config this_config;
          ResTable_config this_config;
          this_config.copyFromDtoH((*iter)->config);
          this_config.copyFromDtoH((*iter)->config);
          if (this_config.match(configuration_)) {
          if (!filter_incompatible_configs || this_config.match(configuration_)) {
            group.configurations.push_back(this_config);
            group.configurations.push_back(this_config);
            group.types.push_back(*iter);
            group.types.push_back(*iter);
          }
          }
+7 −2
Original line number Original line Diff line number Diff line
@@ -96,7 +96,12 @@ class AssetManager2 {
  // Only pass invalidate_caches=false when it is known that the structure
  // Only pass invalidate_caches=false when it is known that the structure
  // change in ApkAssets is due to a safe addition of resources with completely
  // change in ApkAssets is due to a safe addition of resources with completely
  // new resource IDs.
  // new resource IDs.
  bool SetApkAssets(const std::vector<const ApkAssets*>& apk_assets, bool invalidate_caches = true);
  //
  // Only pass in filter_incompatible_configs=false when you want to load all
  // configurations (including incompatible ones) such as when constructing an
  // idmap.
  bool SetApkAssets(const std::vector<const ApkAssets*>& apk_assets, bool invalidate_caches = true,
          bool filter_incompatible_configs = true);


  inline const std::vector<const ApkAssets*> GetApkAssets() const {
  inline const std::vector<const ApkAssets*> GetApkAssets() const {
    return apk_assets_;
    return apk_assets_;
@@ -274,7 +279,7 @@ class AssetManager2 {


  // Triggers the re-construction of lists of types that match the set configuration.
  // Triggers the re-construction of lists of types that match the set configuration.
  // This should always be called when mutating the AssetManager's configuration or ApkAssets set.
  // This should always be called when mutating the AssetManager's configuration or ApkAssets set.
  void RebuildFilterList();
  void RebuildFilterList(bool filter_incompatible_configs = true);


  // AssetManager2::GetBag(resid) wraps this function to track which resource ids have already
  // AssetManager2::GetBag(resid) wraps this function to track which resource ids have already
  // been seen while traversing bag parents.
  // been seen while traversing bag parents.