summaryrefslogtreecommitdiff
path: root/libs/androidfw/AssetManager.cpp
diff options
context:
space:
mode:
authorGuang Zhu <guangzhu@google.com>2017-02-23 07:35:39 +0000
committerGuang Zhu <guangzhu@google.com>2017-02-23 07:35:39 +0000
commit95459806920dec34abb3214ab6e1a9b9213a2a61 (patch)
tree1e4d0a136606788c633f5b823daca0caa4334499 /libs/androidfw/AssetManager.cpp
parent21a3d1ad686dee97b9cf0ed80389ee2ab0d48013 (diff)
Revert "OMS: integrate OverlayManagerService into framework"
Bug: 31052947 Bug: 35697944 This reverts commit 21a3d1ad686dee97b9cf0ed80389ee2ab0d48013. Change-Id: I2d86931020301524c26cf8c8e80d557c97fdd6c3
Diffstat (limited to 'libs/androidfw/AssetManager.cpp')
-rw-r--r--libs/androidfw/AssetManager.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp
index 84111ae0d499..acacd7654cf1 100644
--- a/libs/androidfw/AssetManager.cpp
+++ b/libs/androidfw/AssetManager.cpp
@@ -202,6 +202,15 @@ bool AssetManager::addAssetPath(
*cookie = static_cast<int32_t>(mAssetPaths.size());
}
+#ifdef __ANDROID__
+ // Load overlays, if any
+ asset_path oap;
+ for (size_t idx = 0; mZipSet.getOverlay(ap.path, idx, &oap); idx++) {
+ oap.isSystemAsset = isSystemAsset;
+ mAssetPaths.add(oap);
+ }
+#endif
+
if (mResources != NULL) {
appendPathToResTable(ap, appAsLib);
}
@@ -484,6 +493,11 @@ FileType AssetManager::getFileType(const char* fileName)
}
bool AssetManager::appendPathToResTable(const asset_path& ap, bool appAsLib) const {
+ // skip those ap's that correspond to system overlays
+ if (ap.isSystemOverlay) {
+ return true;
+ }
+
Asset* ass = NULL;
ResTable* sharedRes = NULL;
bool shared = true;
@@ -525,6 +539,14 @@ bool AssetManager::appendPathToResTable(const asset_path& ap, bool appAsLib) con
ALOGV("Creating shared resources for %s", ap.path.string());
sharedRes = new ResTable();
sharedRes->add(ass, idmap, nextEntryIdx + 1, false);
+#ifdef __ANDROID__
+ 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);
+#endif
sharedRes = const_cast<AssetManager*>(this)->
mZipSet.setZipResourceTable(ap.path, sharedRes);
}
@@ -633,6 +655,58 @@ Asset* AssetManager::openIdmapLocked(const struct asset_path& ap) const
return ass;
}
+void AssetManager::addSystemOverlays(const char* pathOverlaysList,
+ const String8& targetPackagePath, ResTable* sharedRes, size_t offset) const
+{
+ FILE* fin = fopen(pathOverlaysList, "r");
+ if (fin == NULL) {
+ return;
+ }
+
+#ifndef _WIN32
+ if (TEMP_FAILURE_RETRY(flock(fileno(fin), LOCK_SH)) != 0) {
+ fclose(fin);
+ return;
+ }
+#endif
+ char buf[1024];
+ while (fgets(buf, sizeof(buf), fin)) {
+ // format of each line:
+ // <path to apk><space><path to idmap><newline>
+ char* space = strchr(buf, ' ');
+ char* newline = strchr(buf, '\n');
+ asset_path oap;
+
+ if (space == NULL || newline == NULL || newline < space) {
+ continue;
+ }
+
+ oap.path = String8(buf, space - buf);
+ oap.type = kFileTypeRegular;
+ oap.idmap = String8(space + 1, newline - space - 1);
+ oap.isSystemOverlay = true;
+
+ Asset* oass = const_cast<AssetManager*>(this)->
+ openNonAssetInPathLocked("resources.arsc",
+ Asset::ACCESS_BUFFER,
+ oap);
+
+ if (oass != NULL) {
+ Asset* oidmap = openIdmapLocked(oap);
+ offset++;
+ sharedRes->add(oass, oidmap, offset + 1, false);
+ const_cast<AssetManager*>(this)->mAssetPaths.add(oap);
+ const_cast<AssetManager*>(this)->mZipSet.addOverlay(targetPackagePath, oap);
+ delete oidmap;
+ }
+ }
+
+#ifndef _WIN32
+ TEMP_FAILURE_RETRY(flock(fileno(fin), LOCK_UN));
+#endif
+ fclose(fin);
+}
+
const ResTable& AssetManager::getResources(bool required) const
{
const ResTable* rt = getResTable(required);
@@ -1372,6 +1446,20 @@ bool AssetManager::SharedZip::isUpToDate()
return mModWhen == modWhen;
}
+void AssetManager::SharedZip::addOverlay(const asset_path& ap)
+{
+ mOverlays.add(ap);
+}
+
+bool AssetManager::SharedZip::getOverlay(size_t idx, asset_path* out) const
+{
+ if (idx >= mOverlays.size()) {
+ return false;
+ }
+ *out = mOverlays[idx];
+ return true;
+}
+
AssetManager::SharedZip::~SharedZip()
{
if (kIsDebug) {
@@ -1490,6 +1578,22 @@ bool AssetManager::ZipSet::isUpToDate()
return true;
}
+void AssetManager::ZipSet::addOverlay(const String8& path, const asset_path& overlay)
+{
+ int idx = getIndex(path);
+ sp<SharedZip> zip = mZipFile[idx];
+ zip->addOverlay(overlay);
+}
+
+bool AssetManager::ZipSet::getOverlay(const String8& path, size_t idx, asset_path* out) const
+{
+ sp<SharedZip> zip = SharedZip::get(path, false);
+ if (zip == NULL) {
+ return false;
+ }
+ return zip->getOverlay(idx, out);
+}
+
/*
* Compute the zip file's index.
*