summaryrefslogtreecommitdiff
path: root/libs/androidfw/Asset.cpp
diff options
context:
space:
mode:
authorWinson <chiuwinson@google.com>2019-08-16 10:20:39 -0700
committerWinson <chiuwinson@google.com>2019-10-10 15:41:03 -0700
commit9947f1e4fa6b1e58ca38bfe0ed440a8ab4f66465 (patch)
tree79b14d3da22669b9c574252a5b74503d17a07bb7 /libs/androidfw/Asset.cpp
parent98bfc275494411c7888d806f307ae193f09c4e9e (diff)
Add ResourceLoader API with .apk and .arsc support
ResourceLoaders allow inserting another .apk/.arsc into AssetManager's resource resolution search. The effect is similar to overlays, where a entry of >= config later in the path list will return that ApkAsset's resource value instead. Because loading from an .arsc is supported, which doesn't contain any actual files, ResourceLoader exposes loadDrawable and loadXmlResourceParser to allow an application load those files from anywhere or create them in code. The data being loaded is either pushed into an .apk or .arsc that mocks itself as the package being "overlaid" and is passed in through ResourcesProvider, an interface with static methods that supports loading from a readable path on disk or a FileDescriptor. The APIs are accessed through a Context's getResources(), which has been changed to be unique per "Context-scope", which is usually the lifetime of the Java object. The exception is that Activities who get their Resources object persisted across recreations maintain that logic for persisting ResourceLoaders. Bug: 135270223 Test: atest FrameworksResourceLoaderTests Change-Id: I6929f0828629ad39a21fa155e7fec73bd75eec7d
Diffstat (limited to 'libs/androidfw/Asset.cpp')
-rw-r--r--libs/androidfw/Asset.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/libs/androidfw/Asset.cpp b/libs/androidfw/Asset.cpp
index 92125c9da8bb..c132f343713f 100644
--- a/libs/androidfw/Asset.cpp
+++ b/libs/androidfw/Asset.cpp
@@ -133,14 +133,24 @@ Asset::Asset(void)
*/
/*static*/ Asset* Asset::createFromFile(const char* fileName, AccessMode mode)
{
+ return createFromFd(open(fileName, O_RDONLY | O_BINARY), fileName, mode);
+}
+
+/*
+ * Create a new Asset from a file on disk. There is a fair chance that
+ * the file doesn't actually exist.
+ *
+ * We can use "mode" to decide how we want to go about it.
+ */
+/*static*/ Asset* Asset::createFromFd(const int fd, const char* fileName, AccessMode mode)
+{
+ if (fd < 0) {
+ return NULL;
+ }
+
_FileAsset* pAsset;
status_t result;
off64_t length;
- int fd;
-
- fd = open(fileName, O_RDONLY | O_BINARY);
- if (fd < 0)
- return NULL;
/*
* Under Linux, the lseek fails if we actually opened a directory. To