From 30113131fb958850ef92c6a8f7f2aa2ed92a8ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Fri, 7 Nov 2014 10:52:17 +0100 Subject: [PATCH 1/2] RRO: reintroduce lost ResTable insert of assets With the recent introduction of AssetManager::appendPathToResTable, overlay packages were not properly added to the AssetManager, and once added, were not properly inserted into the ResTable. Bug: 17765434 Change-Id: Ie21f227c654c98730f74a687d0e16ee2b80e747e --- core/java/android/content/res/AssetManager.java | 16 +++++++++++++++- core/jni/android_util_AssetManager.cpp | 2 +- libs/androidfw/AssetManager.cpp | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java index e57882240e567..72f24d3e4ee8c 100644 --- a/core/java/android/content/res/AssetManager.java +++ b/core/java/android/content/res/AssetManager.java @@ -627,7 +627,21 @@ public final class AssetManager implements AutoCloseable { * * {@hide} */ - public native final int addOverlayPath(String idmapPath); + + public final int addOverlayPath(String idmapPath) { + synchronized (this) { + int res = addOverlayPathNative(idmapPath); + makeStringBlocks(mStringBlocks); + return res; + } + } + + /** + * See addOverlayPath. + * + * {@hide} + */ + public native final int addOverlayPathNative(String idmapPath); /** * Add multiple sets of assets to the asset manager at once. See diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp index 4859ee6fb7965..0dd35ea8e76ca 100644 --- a/core/jni/android_util_AssetManager.cpp +++ b/core/jni/android_util_AssetManager.cpp @@ -2001,7 +2001,7 @@ static JNINativeMethod gAssetManagerMethods[] = { (void*) android_content_AssetManager_getAssetRemainingLength }, { "addAssetPathNative", "(Ljava/lang/String;)I", (void*) android_content_AssetManager_addAssetPath }, - { "addOverlayPath", "(Ljava/lang/String;)I", + { "addOverlayPathNative", "(Ljava/lang/String;)I", (void*) android_content_AssetManager_addOverlayPath }, { "isUpToDate", "()Z", (void*) android_content_AssetManager_isUpToDate }, diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp index de6a33cf15e72..a1f78589b8046 100644 --- a/libs/androidfw/AssetManager.cpp +++ b/libs/androidfw/AssetManager.cpp @@ -296,6 +296,10 @@ bool AssetManager::addOverlayPath(const String8& packagePath, int32_t* cookie) mAssetPaths.add(oap); *cookie = static_cast(mAssetPaths.size()); + if (mResources != NULL) { + appendPathToResTable(oap); + } + return true; } From 96198ebae8deab14b434645f628213db492abdbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Fri, 7 Nov 2014 10:56:12 +0100 Subject: [PATCH 2/2] RRO idmap: pad with 0xffffffff, not 0x00000000 In the new idmap format (version 0x1), 0x00000000 no longer represents a non-existing entry: 0xffffffff should be used instead. Bug: 17765434 Change-Id: If2c7e09feba2224eeafe88fd9230e6392d81b9a7 --- libs/androidfw/ResourceTypes.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index 825071a61924c..ebdd1676502f5 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -6080,14 +6080,14 @@ status_t ResTable::createIdmap(const ResTable& overlay, } if (typeMap.entryOffset + typeMap.entryMap.size() < entryIndex) { - // Resize to accomodate this entry and the 0's in between. - if (typeMap.entryMap.resize((entryIndex - typeMap.entryOffset) + 1) < 0) { + // pad with 0xffffffff's (indicating non-existing entries) before adding this entry + size_t index = typeMap.entryMap.size(); + size_t numItems = entryIndex - (typeMap.entryOffset + index); + if (typeMap.entryMap.insertAt(0xffffffff, index, numItems) < 0) { return NO_MEMORY; } - typeMap.entryMap.editTop() = Res_GETENTRY(overlayResID); - } else { - typeMap.entryMap.add(Res_GETENTRY(overlayResID)); } + typeMap.entryMap.add(Res_GETENTRY(overlayResID)); } if (!typeMap.entryMap.isEmpty()) {