From 4afd179a9ad7da51374c6fb0887180976d952001 Mon Sep 17 00:00:00 2001 From: Guang Zhu Date: Wed, 20 Aug 2014 17:40:18 -0700 Subject: [PATCH 1/2] follow up minor fixes for connectivity manager test Change-Id: I8f0606890b21d67130efb3bc02c6825823060139 --- .../connectivitymanagertest/ConnectivityManagerTestBase.java | 2 +- .../functional/WifiAssociationTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java index a35a8ee6be02d..0f9d8e933f53e 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java @@ -520,7 +520,7 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase { * @param length required length of the string * @return */ - protected boolean isHex(String input, int length) { + protected static boolean isHex(String input, int length) { Pattern p = Pattern.compile(String.format("[0-9A-Fa-f]{%d}", length)); return p.matcher(input).matches(); } diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java index afaf801201d03..eb75b0d2be627 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java @@ -136,7 +136,7 @@ public class WifiAssociationTest extends ConnectivityManagerTestBase { config.allowedProtocols.set(Protocol.WPA); config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP); config.allowedGroupCiphers.set(GroupCipher.TKIP); - if (mPassword.matches("[0-9A-Fa-f]{64}")) { + if (isHex(mPassword, 64)) { config.preSharedKey = mPassword; } else { config.preSharedKey = '"' + mPassword + '"'; @@ -150,7 +150,7 @@ public class WifiAssociationTest extends ConnectivityManagerTestBase { config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP); config.allowedGroupCiphers.set(GroupCipher.CCMP); config.allowedProtocols.set(Protocol.RSN); - if (mPassword.matches("[0-9A-Fa-f]{64}")) { + if (isHex(mPassword, 64)) { config.preSharedKey = mPassword; } else { config.preSharedKey = '"' + mPassword + '"'; From 6022debdbcc4498736580640c6287b57872617a2 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Wed, 20 Aug 2014 14:59:19 -0700 Subject: [PATCH 2/2] AAPT: Fix regression generating dynamic ref table for shared libraries AAPT stopped generating dynamic reference tables for shared libraries. Change-Id: Ib0025811bdca1a4756eb21080dd6b6bb3fc1ca3d --- include/androidfw/ResourceTypes.h | 3 ++ libs/androidfw/ResourceTypes.cpp | 74 ++++++++++++++++++++++++++----- tools/aapt/ResourceTable.cpp | 31 ++++++------- 3 files changed, 80 insertions(+), 28 deletions(-) diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h index b56829da49a45..1af497cfb2e48 100644 --- a/include/androidfw/ResourceTypes.h +++ b/include/androidfw/ResourceTypes.h @@ -1459,6 +1459,9 @@ public: // Loads an unmapped reference table from the package. status_t load(const ResTable_lib_header* const header); + // Adds mappings from the other DynamicRefTable + status_t addMappings(const DynamicRefTable& other); + // Creates a mapping from build-time package ID to run-time package ID for // the given package. status_t addMapping(const String16& packageName, uint8_t packageId); diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index 2a4dec089243e..239d682d1c8c2 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -3346,6 +3346,7 @@ status_t ResTable::add(ResTable* src) TypeList& typeList = pg->types.editItemAt(j); typeList.appendVector(srcPg->types[j]); } + pg->dynamicRefTable.addMappings(srcPg->dynamicRefTable); pg->largestTypeId = max(pg->largestTypeId, srcPg->largestTypeId); mPackageGroups.add(pg); } @@ -5604,7 +5605,6 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg, return (mError=NO_MEMORY); } - //printf("Adding new package id %d at index %d\n", id, idx); err = mPackageGroups.add(group); if (err < NO_ERROR) { return (mError=err); @@ -5844,6 +5844,37 @@ status_t DynamicRefTable::load(const ResTable_lib_header* const header) return NO_ERROR; } +status_t DynamicRefTable::addMappings(const DynamicRefTable& other) { + if (mAssignedPackageId != other.mAssignedPackageId) { + return UNKNOWN_ERROR; + } + + const size_t entryCount = other.mEntries.size(); + for (size_t i = 0; i < entryCount; i++) { + ssize_t index = mEntries.indexOfKey(other.mEntries.keyAt(i)); + if (index < 0) { + mEntries.add(other.mEntries.keyAt(i), other.mEntries[i]); + } else { + if (other.mEntries[i] != mEntries[index]) { + return UNKNOWN_ERROR; + } + } + } + + // Merge the lookup table. No entry can conflict + // (value of 0 means not set). + for (size_t i = 0; i < 256; i++) { + if (mLookupTable[i] != other.mLookupTable[i]) { + if (mLookupTable[i] == 0) { + mLookupTable[i] = other.mLookupTable[i]; + } else if (other.mLookupTable[i] != 0) { + return UNKNOWN_ERROR; + } + } + } + return NO_ERROR; +} + status_t DynamicRefTable::addMapping(const String16& packageName, uint8_t packageId) { ssize_t index = mEntries.indexOfKey(packageName); @@ -6216,21 +6247,36 @@ void ResTable::print(bool inclValues) const printf("Package Groups (%d)\n", (int)pgCount); for (size_t pgIndex=0; pgIndexid, (int)pg->packages.size(), String8(pg->name).string()); + const KeyedVector& refEntries = pg->dynamicRefTable.entries(); + const size_t refEntryCount = refEntries.size(); + if (refEntryCount > 0) { + printf(" DynamicRefTable entryCount=%d:\n", (int) refEntryCount); + for (size_t refIndex = 0; refIndex < refEntryCount; refIndex++) { + printf(" 0x%02x -> %s\n", + refEntries.valueAt(refIndex), + String8(refEntries.keyAt(refIndex)).string()); + } + printf("\n"); + } + + int packageId = pg->id; size_t pkgCount = pg->packages.size(); for (size_t pkgIndex=0; pkgIndexpackages[pkgIndex]; - printf(" Package %d id=%d name=%s\n", (int)pkgIndex, + // Use a package's real ID, since the ID may have been assigned + // if this package is a shared library. + packageId = pkg->package->id; + printf(" Package %d id=0x%02x name=%s\n", (int)pkgIndex, pkg->package->id, String8(String16(pkg->package->name)).string()); } for (size_t typeIndex=0; typeIndex < pg->types.size(); typeIndex++) { const TypeList& typeList = pg->types[typeIndex]; if (typeList.isEmpty()) { - //printf(" type %d NULL\n", (int)typeIndex); continue; } const Type* typeConfigs = typeList[0]; @@ -6239,13 +6285,15 @@ void ResTable::print(bool inclValues) const (int)typeIndex, (int)NTC, (int)typeConfigs->entryCount); if (typeConfigs->typeSpecFlags != NULL) { for (size_t entryIndex=0; entryIndexentryCount; entryIndex++) { - uint32_t resID = (0xff000000 & ((pg->id)<<24)) + uint32_t resID = (0xff000000 & ((packageId)<<24)) | (0x00ff0000 & ((typeIndex+1)<<16)) | (0x0000ffff & (entryIndex)); // Since we are creating resID without actually // iterating over them, we have no idea which is a // dynamic reference. We must check. - pg->dynamicRefTable.lookupResourceId(&resID); + if (packageId == 0) { + pg->dynamicRefTable.lookupResourceId(&resID); + } resource_name resName; if (this->getResourceName(resID, true, &resName)) { @@ -6303,10 +6351,12 @@ void ResTable::print(bool inclValues) const continue; } - uint32_t resID = (0xff000000 & ((pg->id)<<24)) + uint32_t resID = (0xff000000 & ((packageId)<<24)) | (0x00ff0000 & ((typeIndex+1)<<16)) | (0x0000ffff & (entryIndex)); - pg->dynamicRefTable.lookupResourceId(&resID); + if (packageId == 0) { + pg->dynamicRefTable.lookupResourceId(&resID); + } resource_name resName; if (this->getResourceName(resID, true, &resName)) { String8 type8; @@ -6387,9 +6437,11 @@ void ResTable::print(bool inclValues) const const ResTable_map* mapPtr = (ResTable_map*)(baseMapPtr+mapOffset); const uint32_t parent = dtohl(bagPtr->parent.ident); uint32_t resolvedParent = parent; - status_t err = pg->dynamicRefTable.lookupResourceId(&resolvedParent); - if (err != NO_ERROR) { - resolvedParent = 0; + if (Res_GETPACKAGE(resolvedParent) + 1 == 0) { + status_t err = pg->dynamicRefTable.lookupResourceId(&resolvedParent); + if (err != NO_ERROR) { + resolvedParent = 0; + } } printf(" Parent=0x%08x(Resolved=0x%08x), Count=%d\n", parent, resolvedParent, N); diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index c98808ff7bf7c..49d8699def1f3 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -2712,6 +2712,16 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp& // The libraries this table references. Vector > libraryPackages; + const ResTable& table = mAssets->getIncludedResources(); + const size_t basePackageCount = table.getBasePackageCount(); + for (size_t i = 0; i < basePackageCount; i++) { + size_t packageId = table.getBasePackageId(i); + String16 packageName(table.getBasePackageName(i)); + if (packageId > 0x01 && packageId != 0x7f && + packageName != String16("android")) { + libraryPackages.add(sp(new Package(packageName, packageId))); + } + } // Iterate through all data, collecting all values (strings, // references, etc). @@ -2720,22 +2730,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp& for (pi=0; pi p = mOrderedPackages.itemAt(pi); if (p->getTypes().size() == 0) { - // Empty, this is an imported package being used as - // a shared library. We do not flatten this package. - if (p->getAssignedId() != 0x01 && p->getName() != String16("android")) { - // This is not the base Android package, and it is a library - // so we must add a reference to the library when flattening. - libraryPackages.add(p); - } continue; - } else if (p->getAssignedId() == 0x00) { - if (mPackageType != SharedLibrary) { - fprintf(stderr, "ERROR: Package %s can not have ID=0x00 unless building a shared library.", - String8(p->getName()).string()); - return UNKNOWN_ERROR; - } - // If this is a shared library, we also include ourselves as an entry. - libraryPackages.add(p); } StringPool typeStrings(useUTF8); @@ -3147,7 +3142,8 @@ status_t ResourceTable::flattenLibraryTable(const sp& dest, const Vect const size_t libStart = dest->getSize(); const size_t count = libs.size(); - ResTable_lib_header* libHeader = (ResTable_lib_header*) dest->editDataInRange(libStart, sizeof(ResTable_lib_header)); + ResTable_lib_header* libHeader = (ResTable_lib_header*) dest->editDataInRange( + libStart, sizeof(ResTable_lib_header)); memset(libHeader, 0, sizeof(*libHeader)); libHeader->header.type = htods(RES_TABLE_LIBRARY_TYPE); @@ -3163,7 +3159,8 @@ status_t ResourceTable::flattenLibraryTable(const sp& dest, const Vect String8(libPackage->getName()).string(), (uint8_t)libPackage->getAssignedId())); - ResTable_lib_entry* entry = (ResTable_lib_entry*) dest->editDataInRange(entryStart, sizeof(ResTable_lib_entry)); + ResTable_lib_entry* entry = (ResTable_lib_entry*) dest->editDataInRange( + entryStart, sizeof(ResTable_lib_entry)); memset(entry, 0, sizeof(*entry)); entry->packageId = htodl(libPackage->getAssignedId()); strcpy16_htod(entry->packageName, libPackage->getName().string());