Loading cmds/idmap/scan.cpp +60 −39 Original line number Diff line number Diff line Loading @@ -165,23 +165,16 @@ namespace { delete dataMap; return priority; } } int idmap_scan(const char *overlay_dir, const char *target_package_name, const char *target_apk_path, const char *idmap_dir) const char *target_apk_path, const char *idmap_dir, SortedVector<Overlay>& overlayVector) { String8 filename = String8(idmap_dir); filename.appendPath("overlays.list"); if (unlink(filename.string()) != 0 && errno != ENOENT) { return EXIT_FAILURE; } DIR *dir = opendir(overlay_dir); if (dir == NULL) { return EXIT_FAILURE; } SortedVector<Overlay> overlayVector; struct dirent *dirent; while ((dirent = readdir(dir)) != NULL) { struct stat st; Loading @@ -190,10 +183,19 @@ int idmap_scan(const char *overlay_dir, const char *target_package_name, if (stat(overlay_apk_path, &st) < 0) { continue; } if (!S_ISREG(st.st_mode)) { if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode)) { continue; } if (S_ISDIR(st.st_mode)) { String8 dir_name = String8(overlay_apk_path).getPathLeaf(); if (dir_name == "." || dir_name == "..") { // Skip the "." and ".." dir. continue; } idmap_scan(overlay_apk_path, target_package_name, target_apk_path, idmap_dir, overlayVector); } else { int priority = parse_apk(overlay_apk_path, target_package_name); if (priority < 0) { continue; Loading @@ -203,7 +205,8 @@ int idmap_scan(const char *overlay_dir, const char *target_package_name, idmap_path.appendPath(flatten_path(overlay_apk_path + 1)); idmap_path.append("@idmap"); if (idmap_create_path(target_apk_path, overlay_apk_path, idmap_path.string()) != 0) { if (idmap_create_path(target_apk_path, overlay_apk_path, idmap_path.string()) != 0) { ALOGE("error: failed to create idmap for target=%s overlay=%s idmap=%s\n", target_apk_path, overlay_apk_path, idmap_path.string()); continue; Loading @@ -212,12 +215,30 @@ int idmap_scan(const char *overlay_dir, const char *target_package_name, Overlay overlay(String8(overlay_apk_path), idmap_path, priority); overlayVector.add(overlay); } } closedir(dir); if (!writePackagesList(filename.string(), overlayVector)) { return EXIT_SUCCESS; } } int idmap_scan(const char *overlay_dir, const char *target_package_name, const char *target_apk_path, const char *idmap_dir) { String8 filename = String8(idmap_dir); filename.appendPath("overlays.list"); if (unlink(filename.string()) != 0 && errno != ENOENT) { return EXIT_FAILURE; } SortedVector<Overlay> overlayVector; int res = idmap_scan(overlay_dir, target_package_name, target_apk_path, idmap_dir, overlayVector); if (res == EXIT_FAILURE || !writePackagesList(filename.string(), overlayVector)) { return EXIT_FAILURE; } return EXIT_SUCCESS; return res; } core/java/android/content/res/AssetManager.java +6 −3 Original line number Diff line number Diff line Loading @@ -612,7 +612,9 @@ public final class AssetManager implements AutoCloseable { public final int addAssetPath(String path) { synchronized (this) { int res = addAssetPathNative(path); if (mStringBlocks != null) { makeStringBlocks(mStringBlocks); } return res; } } Loading @@ -627,11 +629,12 @@ public final class AssetManager implements AutoCloseable { * * {@hide} */ public final int addOverlayPath(String idmapPath) { synchronized (this) { int res = addOverlayPathNative(idmapPath); if (mStringBlocks != null) { makeStringBlocks(mStringBlocks); } return res; } } Loading include/androidfw/AssetManager.h +1 −1 Original line number Diff line number Diff line Loading @@ -280,7 +280,7 @@ private: const ResTable* getResTable(bool required = true) const; void setLocaleLocked(const char* locale); void updateResourceParamsLocked() const; bool appendPathToResTable(const asset_path& ap) const; bool appendPathToResTable(const asset_path& ap, size_t* entryIdx) const; Asset* openIdmapLocked(const struct asset_path& ap) const; Loading libs/androidfw/AssetManager.cpp +16 −15 Original line number Diff line number Diff line Loading @@ -224,6 +224,11 @@ bool AssetManager::addAssetPath(const String8& path, int32_t* cookie) mAssetPaths.add(ap); if (mResources != NULL) { size_t index = mAssetPaths.size() - 1; appendPathToResTable(ap, &index); } // new paths are always added at the end if (cookie) { *cookie = static_cast<int32_t>(mAssetPaths.size()); Loading @@ -237,10 +242,6 @@ bool AssetManager::addAssetPath(const String8& path, int32_t* cookie) } #endif if (mResources != NULL) { appendPathToResTable(ap); } return true; } Loading Loading @@ -303,7 +304,8 @@ bool AssetManager::addOverlayPath(const String8& packagePath, int32_t* cookie) *cookie = static_cast<int32_t>(mAssetPaths.size()); if (mResources != NULL) { appendPathToResTable(oap); size_t index = mAssetPaths.size() - 1; appendPathToResTable(oap, &index); } return true; Loading Loading @@ -610,7 +612,7 @@ FileType AssetManager::getFileType(const char* fileName) return kFileTypeRegular; } bool AssetManager::appendPathToResTable(const asset_path& ap) const { bool AssetManager::appendPathToResTable(const asset_path& ap, size_t* entryIdx) const { // skip those ap's that correspond to system overlays if (ap.isSystemOverlay) { return true; Loading @@ -622,17 +624,16 @@ bool AssetManager::appendPathToResTable(const asset_path& ap) const { bool onlyEmptyResources = true; MY_TRACE_BEGIN(ap.path.string()); Asset* idmap = openIdmapLocked(ap); size_t nextEntryIdx = mResources->getTableCount(); ALOGV("Looking for resource asset in '%s'\n", ap.path.string()); if (ap.type != kFileTypeDirectory) { if (nextEntryIdx == 0) { if (*entryIdx == 0) { // The first item is typically the framework resources, // which we want to avoid parsing every time. sharedRes = const_cast<AssetManager*>(this)-> mZipSet.getZipResourceTable(ap.path); if (sharedRes != NULL) { // skip ahead the number of system overlay packages preloaded nextEntryIdx = sharedRes->getTableCount(); *entryIdx += sharedRes->getTableCount() - 1; } } if (sharedRes == NULL) { Loading @@ -650,20 +651,20 @@ bool AssetManager::appendPathToResTable(const asset_path& ap) const { } } if (nextEntryIdx == 0 && ass != NULL) { if (*entryIdx == 0 && ass != NULL) { // If this is the first resource table in the asset // manager, then we are going to cache it so that we // can quickly copy it out for others. ALOGV("Creating shared resources for %s", ap.path.string()); sharedRes = new ResTable(); sharedRes->add(ass, idmap, nextEntryIdx + 1, false); sharedRes->add(ass, idmap, *entryIdx + 1, false); #ifdef HAVE_ANDROID_OS const char* data = getenv("ANDROID_DATA"); LOG_ALWAYS_FATAL_IF(data == NULL, "ANDROID_DATA not set"); String8 overlaysListPath(data); overlaysListPath.appendPath(kResourceCache); overlaysListPath.appendPath("overlays.list"); addSystemOverlays(overlaysListPath.string(), ap.path, sharedRes, nextEntryIdx); addSystemOverlays(overlaysListPath.string(), ap.path, sharedRes, *entryIdx); #endif sharedRes = const_cast<AssetManager*>(this)-> mZipSet.setZipResourceTable(ap.path, sharedRes); Loading @@ -685,7 +686,7 @@ bool AssetManager::appendPathToResTable(const asset_path& ap) const { mResources->add(sharedRes); } else { ALOGV("Parsing resources for %s", ap.path.string()); mResources->add(ass, idmap, nextEntryIdx + 1, !shared); mResources->add(ass, idmap, *entryIdx + 1, !shared); } onlyEmptyResources = false; Loading @@ -694,7 +695,7 @@ bool AssetManager::appendPathToResTable(const asset_path& ap) const { } } else { ALOGV("Installing empty resources in to table %p\n", mResources); mResources->addEmpty(nextEntryIdx + 1); mResources->addEmpty(*entryIdx + 1); } if (idmap != NULL) { Loading Loading @@ -734,7 +735,7 @@ const ResTable* AssetManager::getResTable(bool required) const bool onlyEmptyResources = true; const size_t N = mAssetPaths.size(); for (size_t i=0; i<N; i++) { bool empty = appendPathToResTable(mAssetPaths.itemAt(i)); bool empty = appendPathToResTable(mAssetPaths.itemAt(i), &i); onlyEmptyResources = onlyEmptyResources && empty; } Loading Loading
cmds/idmap/scan.cpp +60 −39 Original line number Diff line number Diff line Loading @@ -165,23 +165,16 @@ namespace { delete dataMap; return priority; } } int idmap_scan(const char *overlay_dir, const char *target_package_name, const char *target_apk_path, const char *idmap_dir) const char *target_apk_path, const char *idmap_dir, SortedVector<Overlay>& overlayVector) { String8 filename = String8(idmap_dir); filename.appendPath("overlays.list"); if (unlink(filename.string()) != 0 && errno != ENOENT) { return EXIT_FAILURE; } DIR *dir = opendir(overlay_dir); if (dir == NULL) { return EXIT_FAILURE; } SortedVector<Overlay> overlayVector; struct dirent *dirent; while ((dirent = readdir(dir)) != NULL) { struct stat st; Loading @@ -190,10 +183,19 @@ int idmap_scan(const char *overlay_dir, const char *target_package_name, if (stat(overlay_apk_path, &st) < 0) { continue; } if (!S_ISREG(st.st_mode)) { if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode)) { continue; } if (S_ISDIR(st.st_mode)) { String8 dir_name = String8(overlay_apk_path).getPathLeaf(); if (dir_name == "." || dir_name == "..") { // Skip the "." and ".." dir. continue; } idmap_scan(overlay_apk_path, target_package_name, target_apk_path, idmap_dir, overlayVector); } else { int priority = parse_apk(overlay_apk_path, target_package_name); if (priority < 0) { continue; Loading @@ -203,7 +205,8 @@ int idmap_scan(const char *overlay_dir, const char *target_package_name, idmap_path.appendPath(flatten_path(overlay_apk_path + 1)); idmap_path.append("@idmap"); if (idmap_create_path(target_apk_path, overlay_apk_path, idmap_path.string()) != 0) { if (idmap_create_path(target_apk_path, overlay_apk_path, idmap_path.string()) != 0) { ALOGE("error: failed to create idmap for target=%s overlay=%s idmap=%s\n", target_apk_path, overlay_apk_path, idmap_path.string()); continue; Loading @@ -212,12 +215,30 @@ int idmap_scan(const char *overlay_dir, const char *target_package_name, Overlay overlay(String8(overlay_apk_path), idmap_path, priority); overlayVector.add(overlay); } } closedir(dir); if (!writePackagesList(filename.string(), overlayVector)) { return EXIT_SUCCESS; } } int idmap_scan(const char *overlay_dir, const char *target_package_name, const char *target_apk_path, const char *idmap_dir) { String8 filename = String8(idmap_dir); filename.appendPath("overlays.list"); if (unlink(filename.string()) != 0 && errno != ENOENT) { return EXIT_FAILURE; } SortedVector<Overlay> overlayVector; int res = idmap_scan(overlay_dir, target_package_name, target_apk_path, idmap_dir, overlayVector); if (res == EXIT_FAILURE || !writePackagesList(filename.string(), overlayVector)) { return EXIT_FAILURE; } return EXIT_SUCCESS; return res; }
core/java/android/content/res/AssetManager.java +6 −3 Original line number Diff line number Diff line Loading @@ -612,7 +612,9 @@ public final class AssetManager implements AutoCloseable { public final int addAssetPath(String path) { synchronized (this) { int res = addAssetPathNative(path); if (mStringBlocks != null) { makeStringBlocks(mStringBlocks); } return res; } } Loading @@ -627,11 +629,12 @@ public final class AssetManager implements AutoCloseable { * * {@hide} */ public final int addOverlayPath(String idmapPath) { synchronized (this) { int res = addOverlayPathNative(idmapPath); if (mStringBlocks != null) { makeStringBlocks(mStringBlocks); } return res; } } Loading
include/androidfw/AssetManager.h +1 −1 Original line number Diff line number Diff line Loading @@ -280,7 +280,7 @@ private: const ResTable* getResTable(bool required = true) const; void setLocaleLocked(const char* locale); void updateResourceParamsLocked() const; bool appendPathToResTable(const asset_path& ap) const; bool appendPathToResTable(const asset_path& ap, size_t* entryIdx) const; Asset* openIdmapLocked(const struct asset_path& ap) const; Loading
libs/androidfw/AssetManager.cpp +16 −15 Original line number Diff line number Diff line Loading @@ -224,6 +224,11 @@ bool AssetManager::addAssetPath(const String8& path, int32_t* cookie) mAssetPaths.add(ap); if (mResources != NULL) { size_t index = mAssetPaths.size() - 1; appendPathToResTable(ap, &index); } // new paths are always added at the end if (cookie) { *cookie = static_cast<int32_t>(mAssetPaths.size()); Loading @@ -237,10 +242,6 @@ bool AssetManager::addAssetPath(const String8& path, int32_t* cookie) } #endif if (mResources != NULL) { appendPathToResTable(ap); } return true; } Loading Loading @@ -303,7 +304,8 @@ bool AssetManager::addOverlayPath(const String8& packagePath, int32_t* cookie) *cookie = static_cast<int32_t>(mAssetPaths.size()); if (mResources != NULL) { appendPathToResTable(oap); size_t index = mAssetPaths.size() - 1; appendPathToResTable(oap, &index); } return true; Loading Loading @@ -610,7 +612,7 @@ FileType AssetManager::getFileType(const char* fileName) return kFileTypeRegular; } bool AssetManager::appendPathToResTable(const asset_path& ap) const { bool AssetManager::appendPathToResTable(const asset_path& ap, size_t* entryIdx) const { // skip those ap's that correspond to system overlays if (ap.isSystemOverlay) { return true; Loading @@ -622,17 +624,16 @@ bool AssetManager::appendPathToResTable(const asset_path& ap) const { bool onlyEmptyResources = true; MY_TRACE_BEGIN(ap.path.string()); Asset* idmap = openIdmapLocked(ap); size_t nextEntryIdx = mResources->getTableCount(); ALOGV("Looking for resource asset in '%s'\n", ap.path.string()); if (ap.type != kFileTypeDirectory) { if (nextEntryIdx == 0) { if (*entryIdx == 0) { // The first item is typically the framework resources, // which we want to avoid parsing every time. sharedRes = const_cast<AssetManager*>(this)-> mZipSet.getZipResourceTable(ap.path); if (sharedRes != NULL) { // skip ahead the number of system overlay packages preloaded nextEntryIdx = sharedRes->getTableCount(); *entryIdx += sharedRes->getTableCount() - 1; } } if (sharedRes == NULL) { Loading @@ -650,20 +651,20 @@ bool AssetManager::appendPathToResTable(const asset_path& ap) const { } } if (nextEntryIdx == 0 && ass != NULL) { if (*entryIdx == 0 && ass != NULL) { // If this is the first resource table in the asset // manager, then we are going to cache it so that we // can quickly copy it out for others. ALOGV("Creating shared resources for %s", ap.path.string()); sharedRes = new ResTable(); sharedRes->add(ass, idmap, nextEntryIdx + 1, false); sharedRes->add(ass, idmap, *entryIdx + 1, false); #ifdef HAVE_ANDROID_OS const char* data = getenv("ANDROID_DATA"); LOG_ALWAYS_FATAL_IF(data == NULL, "ANDROID_DATA not set"); String8 overlaysListPath(data); overlaysListPath.appendPath(kResourceCache); overlaysListPath.appendPath("overlays.list"); addSystemOverlays(overlaysListPath.string(), ap.path, sharedRes, nextEntryIdx); addSystemOverlays(overlaysListPath.string(), ap.path, sharedRes, *entryIdx); #endif sharedRes = const_cast<AssetManager*>(this)-> mZipSet.setZipResourceTable(ap.path, sharedRes); Loading @@ -685,7 +686,7 @@ bool AssetManager::appendPathToResTable(const asset_path& ap) const { mResources->add(sharedRes); } else { ALOGV("Parsing resources for %s", ap.path.string()); mResources->add(ass, idmap, nextEntryIdx + 1, !shared); mResources->add(ass, idmap, *entryIdx + 1, !shared); } onlyEmptyResources = false; Loading @@ -694,7 +695,7 @@ bool AssetManager::appendPathToResTable(const asset_path& ap) const { } } else { ALOGV("Installing empty resources in to table %p\n", mResources); mResources->addEmpty(nextEntryIdx + 1); mResources->addEmpty(*entryIdx + 1); } if (idmap != NULL) { Loading Loading @@ -734,7 +735,7 @@ const ResTable* AssetManager::getResTable(bool required) const bool onlyEmptyResources = true; const size_t N = mAssetPaths.size(); for (size_t i=0; i<N; i++) { bool empty = appendPathToResTable(mAssetPaths.itemAt(i)); bool empty = appendPathToResTable(mAssetPaths.itemAt(i), &i); onlyEmptyResources = onlyEmptyResources && empty; } Loading