summaryrefslogtreecommitdiff
path: root/libs/androidfw/AssetManager2.cpp
diff options
context:
space:
mode:
author Ryan Mitchell <rtmitchell@google.com> 2020-02-12 10:31:44 -0800
committer Ryan Mitchell <rtmitchell@google.com> 2020-03-23 18:05:40 -0700
commitb894c274d01f47911770a44151732a0139d81873 (patch)
treea1ff971e0355d44c940c2c55344800f4044e3d51 /libs/androidfw/AssetManager2.cpp
parent393c9121cea9e03762b3e5460d523b9d5393f6f7 (diff)
Revert "Assign shared libraries stable package ids"
This change must be reverted because it broke packages with the same package name but different package ids loaded at once. Bug: 146685730 Test: MultiSplitInstallTest This reverts commit fe50d739f75e13ebf64c010bf6ef504bcc81d860. Change-Id: If6364fd660c76284452f77e7d4f09a3df9dede1d
Diffstat (limited to 'libs/androidfw/AssetManager2.cpp')
-rw-r--r--libs/androidfw/AssetManager2.cpp72
1 files changed, 19 insertions, 53 deletions
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp
index f20e18453f8b..803828fc16c5 100644
--- a/libs/androidfw/AssetManager2.cpp
+++ b/libs/androidfw/AssetManager2.cpp
@@ -25,7 +25,6 @@
#include "android-base/logging.h"
#include "android-base/stringprintf.h"
-#include "androidfw/DynamicLibManager.h"
#include "androidfw/ResourceUtils.h"
#include "androidfw/Util.h"
#include "utils/ByteOrder.h"
@@ -67,12 +66,7 @@ struct FindEntryResult {
StringPoolRef entry_string_ref;
};
-AssetManager2::AssetManager2() : dynamic_lib_manager_(std::make_unique<DynamicLibManager>()) {
- memset(&configuration_, 0, sizeof(configuration_));
-}
-
-AssetManager2::AssetManager2(DynamicLibManager* dynamic_lib_manager)
- : dynamic_lib_manager_(dynamic_lib_manager) {
+AssetManager2::AssetManager2() {
memset(&configuration_, 0, sizeof(configuration_));
}
@@ -91,44 +85,24 @@ void AssetManager2::BuildDynamicRefTable() {
package_groups_.clear();
package_ids_.fill(0xff);
- // 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.
- std::vector<const ApkAssets*> sorted_apk_assets(apk_assets_);
- std::stable_partition(sorted_apk_assets.begin(), sorted_apk_assets.end(), [](const ApkAssets* a) {
- return !a->IsOverlay();
- });
-
+ // A mapping from apk assets path to the runtime package id of its first loaded package.
std::unordered_map<std::string, uint8_t> apk_assets_package_ids;
- std::unordered_map<std::string, uint8_t> package_name_package_ids;
-
- // Assign stable package ids to application packages.
- uint8_t next_available_package_id = 0U;
- for (const auto& apk_assets : sorted_apk_assets) {
- for (const auto& package : apk_assets->GetLoadedArsc()->GetPackages()) {
- uint8_t package_id = package->GetPackageId();
- if (package->IsOverlay()) {
- package_id = GetDynamicLibManager()->FindUnassignedId(next_available_package_id);
- next_available_package_id = package_id + 1;
- } else if (package->IsDynamic()) {
- package_id = GetDynamicLibManager()->GetAssignedId(package->GetPackageName());
- }
-
- // Map the path of the apk assets to the package id of its first loaded package.
- apk_assets_package_ids[apk_assets->GetPath()] = package_id;
- // Map the package name of the package to the first loaded package with that package id.
- package_name_package_ids[package->GetPackageName()] = package_id;
- }
- }
+ // 0x01 is reserved for the android package.
+ int next_package_id = 0x02;
+ const size_t apk_assets_count = apk_assets_.size();
+ for (size_t i = 0; i < apk_assets_count; i++) {
+ const ApkAssets* apk_assets = apk_assets_[i];
+ const LoadedArsc* loaded_arsc = apk_assets->GetLoadedArsc();
- const int apk_assets_count = apk_assets_.size();
- for (int i = 0; i < apk_assets_count; i++) {
- const auto& apk_assets = apk_assets_[i];
- for (const auto& package : apk_assets->GetLoadedArsc()->GetPackages()) {
- const auto package_id_entry = package_name_package_ids.find(package->GetPackageName());
- CHECK(package_id_entry != package_name_package_ids.end())
- << "no package id assgined to package " << package->GetPackageName();
- const uint8_t package_id = package_id_entry->second;
+ for (const std::unique_ptr<const LoadedPackage>& package : loaded_arsc->GetPackages()) {
+ // Get the package ID or assign one if a shared library.
+ int package_id;
+ if (package->IsDynamic()) {
+ package_id = next_package_id++;
+ } else {
+ package_id = package->GetPackageId();
+ }
// Add the mapping for package ID to index if not present.
uint8_t idx = package_ids_[package_id];
@@ -152,7 +126,7 @@ void AssetManager2::BuildDynamicRefTable() {
PackageGroup& target_package_group = package_groups_[target_idx];
- // Create a special dynamic reference table for the overlay to rewrite references to
+ // Create a special dynamic reference table for the overlay to rewite references to
// overlay resources as references to the target resources they overlay.
auto overlay_table = std::make_shared<OverlayDynamicRefTable>(
loaded_idmap->GetOverlayDynamicRefTable(target_package_id));
@@ -182,6 +156,8 @@ void AssetManager2::BuildDynamicRefTable() {
package_group->dynamic_ref_table->mEntries.replaceValueFor(
package_name, static_cast<uint8_t>(entry.package_id));
}
+
+ apk_assets_package_ids.insert(std::make_pair(apk_assets->GetPath(), package_id));
}
}
@@ -1329,16 +1305,6 @@ uint8_t AssetManager2::GetAssignedPackageId(const LoadedPackage* package) const
return 0;
}
-DynamicLibManager* AssetManager2::GetDynamicLibManager() const {
- auto dynamic_lib_manager =
- std::get_if<std::unique_ptr<DynamicLibManager>>(&dynamic_lib_manager_);
- if (dynamic_lib_manager) {
- return (*dynamic_lib_manager).get();
- } else {
- return *std::get_if<DynamicLibManager*>(&dynamic_lib_manager_);
- }
-}
-
std::unique_ptr<Theme> AssetManager2::NewTheme() {
return std::unique_ptr<Theme>(new Theme(this));
}