summaryrefslogtreecommitdiff
path: root/libs/androidfw/tests/AssetManager2_test.cpp
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2020-02-10 13:35:24 -0800
committerRyan Mitchell <rtmitchell@google.com>2020-02-10 14:12:00 -0800
commit155d539634571bcd97f07884f28c61ef18b863c2 (patch)
treede788b2215f2201cf59e2363cef31df120b76e10 /libs/androidfw/tests/AssetManager2_test.cpp
parentdc7efcc2ce8a57ae0a5d57825e08e8d6ad23583f (diff)
Sort bag by attribute key when using libs
When shared libraries are assigned package ids in a different order than compile order, bag resources that use attributes from both multiple libraries will not be sorted in ascending attribute id order. This change detects when the attribute ids are not in order and sorts the bag entries accordingly. The change is designed to be less invasive. Deduping the GetBag logic should probably be spun off in a separate bug. Bug: 147674078 Test: libandroidfw_tests Change-Id: Id8ce8e9c7ef294fcc312b77468136067d392dbd0
Diffstat (limited to 'libs/androidfw/tests/AssetManager2_test.cpp')
-rw-r--r--libs/androidfw/tests/AssetManager2_test.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/libs/androidfw/tests/AssetManager2_test.cpp b/libs/androidfw/tests/AssetManager2_test.cpp
index 2f6f3dfcaf1c..35fea7ab86cb 100644
--- a/libs/androidfw/tests/AssetManager2_test.cpp
+++ b/libs/androidfw/tests/AssetManager2_test.cpp
@@ -285,6 +285,27 @@ TEST_F(AssetManager2Test, FindsBagResourceFromSharedLibrary) {
EXPECT_EQ(0x03, get_package_id(bag->entries[1].key));
}
+TEST_F(AssetManager2Test, FindsBagResourceFromMultipleSharedLibraries) {
+ AssetManager2 assetmanager;
+
+ // libclient is built with lib_one and then lib_two in order.
+ // Reverse the order to test that proper package ID re-assignment is happening.
+ assetmanager.SetApkAssets(
+ {lib_two_assets_.get(), lib_one_assets_.get(), libclient_assets_.get()});
+
+ const ResolvedBag* bag = assetmanager.GetBag(libclient::R::style::ThemeMultiLib);
+ ASSERT_NE(nullptr, bag);
+ ASSERT_EQ(bag->entry_count, 2u);
+
+ // First attribute comes from lib_two.
+ EXPECT_EQ(2, bag->entries[0].cookie);
+ EXPECT_EQ(0x02, get_package_id(bag->entries[0].key));
+
+ // The next two attributes come from lib_one.
+ EXPECT_EQ(2, bag->entries[1].cookie);
+ EXPECT_EQ(0x03, get_package_id(bag->entries[1].key));
+}
+
TEST_F(AssetManager2Test, FindsStyleResourceWithParentFromSharedLibrary) {
AssetManager2 assetmanager;