diff options
| -rw-r--r-- | libs/androidfw/AssetManager2.cpp | 16 | ||||
| -rw-r--r-- | libs/androidfw/ResourceTypes.cpp | 16 | ||||
| -rw-r--r-- | libs/androidfw/include/androidfw/ResourceTypes.h | 3 | 
3 files changed, 16 insertions, 19 deletions
| diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp index 61e842a359ce..c3d153d56b26 100644 --- a/libs/androidfw/AssetManager2.cpp +++ b/libs/androidfw/AssetManager2.cpp @@ -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 diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index 4a41ab521faa..31516dc58035 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -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)) { diff --git a/libs/androidfw/include/androidfw/ResourceTypes.h b/libs/androidfw/include/androidfw/ResourceTypes.h index 6968977d7d12..52321dad8a5a 100644 --- a/libs/androidfw/include/androidfw/ResourceTypes.h +++ b/libs/androidfw/include/androidfw/ResourceTypes.h @@ -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; |