summaryrefslogtreecommitdiff
path: root/libs/androidfw/tests/DynamicRefTable_test.cpp
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2018-11-05 15:56:15 -0800
committerRyan Mitchell <rtmitchell@google.com>2018-11-07 01:28:53 +0000
commit5db396d5cc780ecf13cdfd25c8af15a220065f14 (patch)
treee7c6092f3b912884637549d3bcaed3bb2d8d0904 /libs/androidfw/tests/DynamicRefTable_test.cpp
parent3d171b2a0f6c78437e2c529f056f405357a462d7 (diff)
Only resolve non-dynamic resource references
Only resolve non-dynamic references and attributes if the package is loaded as a library or if a shared library is attempting to retrieve its own resources. Bug: 116486668 Bug: 116620612 Test: libandroidfw_tests & manual test of broken apps & atest FieldsClassificationTest#testGetAlgorith Change-Id: Icb827796a65072a39452dbe577d5e18f085ea4e2
Diffstat (limited to 'libs/androidfw/tests/DynamicRefTable_test.cpp')
-rw-r--r--libs/androidfw/tests/DynamicRefTable_test.cpp58
1 files changed, 50 insertions, 8 deletions
diff --git a/libs/androidfw/tests/DynamicRefTable_test.cpp b/libs/androidfw/tests/DynamicRefTable_test.cpp
index df44e343b2b4..5acc46a3c0d9 100644
--- a/libs/androidfw/tests/DynamicRefTable_test.cpp
+++ b/libs/androidfw/tests/DynamicRefTable_test.cpp
@@ -40,6 +40,26 @@ TEST(DynamicRefTableTest, LookupSharedLibSelfReferences) {
EXPECT_EQ(value2.data, 0x02010000);
};
+TEST(DynamicRefTableTest, LookupSharedLibSelfAttributes) {
+ // Shared library
+ DynamicRefTable shared_table(0x03, /* appAsLib */ false);
+ shared_table.addMapping(0x00, 0x03);
+ Res_value value;
+ value.dataType = Res_value::TYPE_ATTRIBUTE;
+ value.data = 0x00010000;
+ ASSERT_EQ(shared_table.lookupResourceValue(&value), NO_ERROR);
+ EXPECT_EQ(value.data, 0x03010000);
+
+ // App loaded as a shared library
+ DynamicRefTable shared_app_table(0x04, /* appAsLib */ true);
+ shared_app_table.addMapping(0x7f, 0x04);
+ Res_value value2;
+ value2.dataType = Res_value::TYPE_ATTRIBUTE;
+ value2.data = 0x7f010000;
+ ASSERT_EQ(shared_app_table.lookupResourceValue(&value2), NO_ERROR);
+ EXPECT_EQ(value2.data, 0x04010000);
+};
+
TEST(DynamicRefTableTest, LookupDynamicReferences) {
// Shared library
DynamicRefTable shared_table(0x2, /* appAsLib */ false);
@@ -51,24 +71,46 @@ TEST(DynamicRefTableTest, LookupDynamicReferences) {
ASSERT_EQ(shared_table.lookupResourceValue(&value), NO_ERROR);
EXPECT_EQ(value.data, 0x05010000);
- // App loaded as a shared library
+ // Regular application
+ DynamicRefTable app_table(0x7f, /* appAsLib */ false);
+ app_table.addMapping(0x03, 0x05);
+ Res_value value3;
+ value3.dataType = Res_value::TYPE_DYNAMIC_REFERENCE;
+ value3.data = 0x03010000;
+ ASSERT_EQ(app_table.lookupResourceValue(&value3), NO_ERROR);
+ EXPECT_EQ(value3.data, 0x05010000);
+};
+
+TEST(DynamicRefTableTest, LookupDynamicAttributes) {
+// App loaded as a shared library
DynamicRefTable shared_app_table(0x2, /* appAsLib */ true);
shared_app_table.addMapping(0x03, 0x05);
shared_app_table.addMapping(0x7f, 0x2);
Res_value value2;
- value2.dataType = Res_value::TYPE_DYNAMIC_REFERENCE;
+ value2.dataType = Res_value::TYPE_DYNAMIC_ATTRIBUTE;
value2.data = 0x03010000;
ASSERT_EQ(shared_app_table.lookupResourceValue(&value2), NO_ERROR);
EXPECT_EQ(value2.data, 0x05010000);
+}
+TEST(DynamicRefTableTest, DoNotLookupNonDynamicReferences) {
// Regular application
DynamicRefTable app_table(0x7f, /* appAsLib */ false);
- app_table.addMapping(0x03, 0x05);
- Res_value value3;
- value3.dataType = Res_value::TYPE_REFERENCE;
- value3.data = 0x03010000;
- ASSERT_EQ(app_table.lookupResourceValue(&value3), NO_ERROR);
- EXPECT_EQ(value3.data, 0x05010000);
+ Res_value value;
+ value.dataType = Res_value::TYPE_REFERENCE;
+ value.data = 0x03010000;
+ ASSERT_EQ(app_table.lookupResourceValue(&value), NO_ERROR);
+ EXPECT_EQ(value.data, 0x03010000);
+};
+
+TEST(DynamicRefTableTest, DoNotLookupNonDynamicAttributes) {
+ // App with custom package id
+ DynamicRefTable custom_app_table(0x8f, /* appAsLib */ false);
+ Res_value value2;
+ value2.dataType = Res_value::TYPE_ATTRIBUTE;
+ value2.data = 0x03010000;
+ ASSERT_EQ(custom_app_table.lookupResourceValue(&value2), NO_ERROR);
+ EXPECT_EQ(value2.data, 0x03010000);
};
} // namespace android \ No newline at end of file