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

Commit 63fd970b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[res] AliasMap - use sorted vector instead of map"

parents c477d737 e3f9be67
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ void AssetManager2::BuildDynamicRefTable() {
  // A mapping from path of apk assets that could be target packages of overlays to the runtime
  // package id of its first loaded package. Overlays currently can only override resources in the
  // first package in the target resource table.
  std::unordered_map<std::string, uint8_t> target_assets_package_ids;
  std::unordered_map<std::string_view, uint8_t> target_assets_package_ids;

  // Overlay resources are not directly referenced by an application so their resource ids
  // can change throughout the application's lifetime. Assign overlay package ids last.
@@ -135,7 +135,7 @@ void AssetManager2::BuildDynamicRefTable() {
    if (auto loaded_idmap = apk_assets->GetLoadedIdmap(); loaded_idmap != nullptr) {
      // The target package must precede the overlay package in the apk assets paths in order
      // to take effect.
      auto iter = target_assets_package_ids.find(std::string(loaded_idmap->TargetApkPath()));
      auto iter = target_assets_package_ids.find(loaded_idmap->TargetApkPath());
      if (iter == target_assets_package_ids.end()) {
         LOG(INFO) << "failed to find target package for overlay "
                   << loaded_idmap->OverlayApkPath();
@@ -180,7 +180,7 @@ void AssetManager2::BuildDynamicRefTable() {
        if (overlay_ref_table != nullptr) {
          // If this package is from an overlay, use a dynamic reference table that can rewrite
          // overlay resource ids to their corresponding target resource ids.
          new_group.dynamic_ref_table = overlay_ref_table;
          new_group.dynamic_ref_table = std::move(overlay_ref_table);
        }

        DynamicRefTable* ref_table = new_group.dynamic_ref_table.get();
@@ -188,9 +188,9 @@ void AssetManager2::BuildDynamicRefTable() {
        ref_table->mAppAsLib = package->IsDynamic() && package->GetPackageId() == 0x7f;
      }

      // Add the package and to the set of packages with the same ID.
      // Add the package to the set of packages with the same ID.
      PackageGroup* package_group = &package_groups_[idx];
      package_group->packages_.push_back(ConfiguredPackage{package.get(), {}});
      package_group->packages_.emplace_back().loaded_package_ = package.get();
      package_group->cookies_.push_back(apk_assets_cookies[apk_assets]);

      // Add the package name -> build time ID mappings.
@@ -202,7 +202,7 @@ void AssetManager2::BuildDynamicRefTable() {

      if (auto apk_assets_path = apk_assets->GetPath()) {
        // Overlay target ApkAssets must have been created using path based load apis.
        target_assets_package_ids.insert(std::make_pair(std::string(*apk_assets_path), package_id));
        target_assets_package_ids.emplace(*apk_assets_path, package_id);
      }
    }
  }
@@ -219,11 +219,13 @@ void AssetManager2::BuildDynamicRefTable() {

    for (const auto& package : group.packages_) {
      const auto& package_aliases = package.loaded_package_->GetAliasResourceIdMap();
      aliases.insert(package_aliases.begin(), package_aliases.end());
      aliases.insert(aliases.end(), package_aliases.begin(), package_aliases.end());
    }
  }

  if (!aliases.empty()) {
    std::sort(aliases.begin(), aliases.end(), [](auto&& l, auto&& r) { return l.first < r.first; });

    // Add the alias resources to the dynamic reference table of every package group. Since
    // staging aliases can only be defined by the framework package (which is not a shared
    // library), the compile-time package id of the framework is the same across all packages
+6 −10
Original line number Diff line number Diff line
@@ -7001,11 +7001,10 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg,
DynamicRefTable::DynamicRefTable() : DynamicRefTable(0, false) {}

DynamicRefTable::DynamicRefTable(uint8_t packageId, bool appAsLib)
    : mAssignedPackageId(packageId)
    : mLookupTable()
    , mAssignedPackageId(packageId)
    , mAppAsLib(appAsLib)
{
    memset(mLookupTable, 0, sizeof(mLookupTable));

    // Reserved package ids
    mLookupTable[APP_PACKAGE_ID] = APP_PACKAGE_ID;
    mLookupTable[SYS_PACKAGE_ID] = SYS_PACKAGE_ID;
@@ -7086,10 +7085,6 @@ void DynamicRefTable::addMapping(uint8_t buildPackageId, uint8_t runtimePackageI
    mLookupTable[buildPackageId] = runtimePackageId;
}

void DynamicRefTable::addAlias(uint32_t stagedId, uint32_t finalizedId) {
    mAliasId[stagedId] = finalizedId;
}

status_t DynamicRefTable::lookupResourceId(uint32_t* resId) const {
    uint32_t res = *resId;
    size_t packageId = Res_GETPACKAGE(res) + 1;
@@ -7099,11 +7094,12 @@ status_t DynamicRefTable::lookupResourceId(uint32_t* resId) const {
        return NO_ERROR;
    }

    auto alias_id = mAliasId.find(res);
    if (alias_id != mAliasId.end()) {
    const auto alias_it = std::lower_bound(mAliasId.begin(), mAliasId.end(), res,
        [](const AliasMap::value_type& pair, uint32_t val) { return pair.first < val; });
    if (alias_it != mAliasId.end() && alias_it->first == res) {
      // Rewrite the resource id to its alias resource id. Since the alias resource id is a
      // compile-time id, it still needs to be resolved further.
      res = alias_id->second;
      res = alias_it->second;
    }

    if (packageId == SYS_PACKAGE_ID || (packageId == APP_PACKAGE_ID && !mAppAsLib)) {
+1 −2
Original line number Diff line number Diff line
@@ -1885,11 +1885,10 @@ public:

    void addMapping(uint8_t buildPackageId, uint8_t runtimePackageId);

    using AliasMap = std::map<uint32_t, uint32_t>;
    using AliasMap = std::vector<std::pair<uint32_t, uint32_t>>;
    void setAliases(AliasMap aliases) {
        mAliasId = std::move(aliases);
    }
    void addAlias(uint32_t stagedId, uint32_t finalizedId);

    // Returns whether or not the value must be looked up.
    bool requiresLookup(const Res_value* value) const;